From nobody Tue May 7 18:46:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1611590744; cv=none; d=zohomail.com; s=zohoarc; b=gtIqdYFvItyk6sjYVMu1b/3YuaoYVifFk9QUanj3fTTcX04l6wcNb1gB62CP9IxRz10xU1Uk0MRYT1wN3Awu6KPZ68DY6fcFW1JN5txmgwERfxk+2/dFVw5YfXe1KAzwL3KRymCfSgoPfFUnL/2/5hk7WshL2mQAPtTC1usSIXQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611590744; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=urc9h6Uvst5XpzoqiBD9j2i11rJUTyFKUr7E6+afcsk=; b=g+A3HW0GW0jo8AZTGF4jz9hcOdFwj3GwlOFoVBXy759d+isnhzqOy/CSRuBFXbE+VqjG2au8JSmNYNKGAzCSyNWVQbRc4hXi2ZOorx4fOOjfTi6dGVbwAgAm3nrgwP7iAVRCuhn5ohb74QwJs/pcK3aOqjMd+zKK5Xs0fw09IhE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1611590744485168.7862008074436; Mon, 25 Jan 2021 08:05: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-479-9ciNhKuJNISaaVE-y8PFBw-1; Mon, 25 Jan 2021 11:05:40 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 47C5580362A; Mon, 25 Jan 2021 16:05:34 +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 EF8D65C1C5; Mon, 25 Jan 2021 16:05:33 +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 C2CC418095FF; Mon, 25 Jan 2021 16:05:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 10PG5Ull018181 for ; Mon, 25 Jan 2021 11:05:30 -0500 Received: by smtp.corp.redhat.com (Postfix) id 740C05D9DB; Mon, 25 Jan 2021 16:05:30 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id BAC6B5D9DC for ; Mon, 25 Jan 2021 16:05:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611590742; 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=urc9h6Uvst5XpzoqiBD9j2i11rJUTyFKUr7E6+afcsk=; b=N9uUqmgNnNXBnJThir3arr71NPQhyBhaJfkS0f0NgwI9dpWkQKCG/TjCog48qLRCxJo4e7 HkPg4c3TjOz0CKKdc2hI1L9InBlvYf4CrXns5Tw+A/BXY4pgfI9pxqs/qHfdigZTBNj5sA q866YHGgutF3JTRJllsy+Lh5feBEFbE= X-MC-Unique: 9ciNhKuJNISaaVE-y8PFBw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 01/12] virStorageSourceGetBackingStoreStr: Move the function earlier Date: Mon, 25 Jan 2021 17:05:13 +0100 Message-Id: <14c92845cfbdb6485560def31279b410a830feb7.1611590679.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com 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 it together with virStorageSourceGetRelativeBackingPath which is the main reason why it exists. Upcoming patch will modify the comment and arguments refering to virStorageSourceGetRelativeBackingPath so it's better if they are together. Signed-off-by: Peter Krempa Reviewed-by: Pavel Hrdina --- src/storage_file/storage_source.c | 100 +++++++++++++++--------------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/src/storage_file/storage_source.c b/src/storage_file/storage_s= ource.c index 85734d9275..430e3214c4 100644 --- a/src/storage_file/storage_source.c +++ b/src/storage_file/storage_source.c @@ -1880,6 +1880,56 @@ virStorageSourceGetRelativeBackingPath(virStorageSou= rcePtr top, } +/** + * virStorageSourceGetBackingStoreStr: + * @src: storage object + * + * Extracts the backing store string as stored in the storage volume descr= ibed + * by @src and returns it to the user. Caller is responsible for freeing i= t. + * In case when the string can't be retrieved or does not exist NULL is + * returned. + */ +int +virStorageSourceGetBackingStoreStr(virStorageSourcePtr src, + char **backing) +{ + ssize_t headerLen; + int rv; + g_autofree char *buf =3D NULL; + g_autoptr(virStorageSource) tmp =3D NULL; + + *backing =3D NULL; + + /* exit if we can't load information about the current image */ + if (!virStorageSourceSupportsBackingChainTraversal(src)) + return 0; + + rv =3D virStorageSourceAccess(src, F_OK); + if (rv =3D=3D -2) + return 0; + if (rv < 0) { + virStorageSourceReportBrokenChain(errno, src, src); + return -1; + } + + if ((headerLen =3D virStorageSourceRead(src, 0, VIR_STORAGE_MAX_HEADER, + &buf)) < 0) { + if (headerLen =3D=3D -2) + return 0; + return -1; + } + + if (!(tmp =3D virStorageSourceCopy(src, false))) + return -1; + + if (virStorageFileProbeGetMetadata(tmp, buf, headerLen) < 0) + return -1; + + *backing =3D g_steal_pointer(&tmp->backingStoreRaw); + return 0; +} + + static bool virStorageSourceIsInitialized(const virStorageSource *src) { @@ -2562,53 +2612,3 @@ virStorageSourceGetMetadata(virStorageSourcePtr src, virHashFree(cycle); return ret; } - - -/** - * virStorageSourceGetBackingStoreStr: - * @src: storage object - * - * Extracts the backing store string as stored in the storage volume descr= ibed - * by @src and returns it to the user. Caller is responsible for freeing i= t. - * In case when the string can't be retrieved or does not exist NULL is - * returned. - */ -int -virStorageSourceGetBackingStoreStr(virStorageSourcePtr src, - char **backing) -{ - ssize_t headerLen; - int rv; - g_autofree char *buf =3D NULL; - g_autoptr(virStorageSource) tmp =3D NULL; - - *backing =3D NULL; - - /* exit if we can't load information about the current image */ - if (!virStorageSourceSupportsBackingChainTraversal(src)) - return 0; - - rv =3D virStorageSourceAccess(src, F_OK); - if (rv =3D=3D -2) - return 0; - if (rv < 0) { - virStorageSourceReportBrokenChain(errno, src, src); - return -1; - } - - if ((headerLen =3D virStorageSourceRead(src, 0, VIR_STORAGE_MAX_HEADER, - &buf)) < 0) { - if (headerLen =3D=3D -2) - return 0; - return -1; - } - - if (!(tmp =3D virStorageSourceCopy(src, false))) - return -1; - - if (virStorageFileProbeGetMetadata(tmp, buf, headerLen) < 0) - return -1; - - *backing =3D g_steal_pointer(&tmp->backingStoreRaw); - return 0; -} --=20 2.29.2 From nobody Tue May 7 18:46:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1611590763; cv=none; d=zohomail.com; s=zohoarc; b=XBR3omIKaf0VF3W8SlKaaLihf6Xn6zdBehDd4I6tvsQUo8XXADBpUiMBTxTV4Reaabow824Q7L7wILjuB8NFAYEVXKop2cZjDWVWUGBk7ZZ+a5HaehZDiszR5SeB/xmYJwXxbKKd89ChJWptR/PVUYqub35UpDiwfCQ58xgrL/0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611590763; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=q+/Z8EfuhjUhqv/htJArCB4yTml2n5i9JWqlnnj0Q7I=; b=UBlgft7hf+EaYdZQbmpKc6UOKkH1k9WblP7Z8KrJdP6SLUWOAKqm6yJrTnP3h+5ToiqC6GQp9ZjqC5+KdgGTgoPfkEoV/e7IxT/ZpiBcFqkv7ltS74Gf9Fu+3xEuQBqrqfP96/ZzKYGGJXvFgsSjH4ZkclM2bcBnfSERVuNw04E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1611590763875201.71398238209997; Mon, 25 Jan 2021 08:06:03 -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-142-NEvERpYINm25exeboozJ5A-1; Mon, 25 Jan 2021 11:05:52 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2247019611A4; Mon, 25 Jan 2021 16:05:45 +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 F149D5D9E4; Mon, 25 Jan 2021 16:05:44 +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 BB6024E590; Mon, 25 Jan 2021 16:05:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 10PG5Vxh018200 for ; Mon, 25 Jan 2021 11:05:31 -0500 Received: by smtp.corp.redhat.com (Postfix) id 976AB5D9DC; Mon, 25 Jan 2021 16:05:31 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id EF9D35D9DB for ; Mon, 25 Jan 2021 16:05:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611590762; 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=q+/Z8EfuhjUhqv/htJArCB4yTml2n5i9JWqlnnj0Q7I=; b=RiPNH0LOq9NcBWUmNuomrqy8vn91qe+LPKBb/zObj7QU2F2ujKxjo+3rcRw/lkxcpsJizK SZwc4sJfobQi4cP7PRJp/yUmGbFm3J2y1DjwJvLlOKQk/+1Z9R00+QdjWyNC85JuQCbTeP YhwzSOdUMoivCDg0PlURwQv5xpedKTU= X-MC-Unique: NEvERpYINm25exeboozJ5A-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 02/12] virStorageSourceGetBackingStoreStr: Return relative paths only Date: Mon, 25 Jan 2021 17:05:14 +0100 Message-Id: <391f76a0e87db8e5fb839fa2cca27995a9bb73d2.1611590679.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com 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" Rename the function to virStorageSourceFetchRelativeBackingPath and return relative paths only. The function is only used to restore the relative relationship between images so there's no need for it to be universal. Signed-off-by: Peter Krempa Reviewed-by: Pavel Hrdina --- src/libvirt_private.syms | 2 +- src/qemu/qemu_block.c | 6 +----- src/qemu/qemu_snapshot.c | 13 +++---------- src/storage_file/storage_source.c | 22 +++++++++++++--------- src/storage_file/storage_source.h | 4 ++-- 5 files changed, 20 insertions(+), 27 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index fbaf16704b..c03b769c37 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1691,7 +1691,7 @@ virStorageSourceChainLookup; virStorageSourceChown; virStorageSourceCreate; virStorageSourceDeinit; -virStorageSourceGetBackingStoreStr; +virStorageSourceFetchRelativeBackingPath; virStorageSourceGetMetadata; virStorageSourceGetMetadataFromBuf; virStorageSourceGetMetadataFromFD; diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index d845a3312d..6456100170 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -3420,7 +3420,6 @@ qemuBlockUpdateRelativeBacking(virDomainObjPtr vm, virStorageSourcePtr n; for (n =3D src; virStorageSourceHasBacking(n); n =3D n->backingStore) { - g_autofree char *backingStoreStr =3D NULL; int rc; if (n->backingStore->relPath) @@ -3432,15 +3431,12 @@ qemuBlockUpdateRelativeBacking(virDomainObjPtr vm, if (qemuDomainStorageFileInit(driver, vm, n, topsrc) < 0) return -1; - rc =3D virStorageSourceGetBackingStoreStr(n, &backingStoreStr); + rc =3D virStorageSourceFetchRelativeBackingPath(n, &n->backingStor= e->relPath); virStorageSourceDeinit(n); if (rc < 0) return rc; - - if (backingStoreStr && virStorageIsRelative(backingStoreStr)) - n->backingStore->relPath =3D g_steal_pointer(&backingStoreStr); } return 0; diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index bfc5a1a46b..39445738a2 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -1088,16 +1088,9 @@ qemuSnapshotDiskPrepareOne(virDomainObjPtr vm, dd->initialized =3D true; if (reuse) { - if (updateRelativeBacking) { - g_autofree char *backingStoreStr =3D NULL; - - if (virStorageSourceGetBackingStoreStr(dd->src, &backingSt= oreStr) < 0) - return -1; - if (backingStoreStr !=3D NULL) { - if (virStorageIsRelative(backingStoreStr)) - dd->relPath =3D g_steal_pointer(&backingStoreStr); - } - } + if (updateRelativeBacking && + virStorageSourceFetchRelativeBackingPath(dd->src, &dd->rel= Path) < 0) + return -1; } else { /* pre-create the image file so that we can label it before ha= nding it to qemu */ if (supportsCreate && dd->src->type !=3D VIR_STORAGE_TYPE_BLOC= K) { diff --git a/src/storage_file/storage_source.c b/src/storage_file/storage_s= ource.c index 430e3214c4..23d36507ea 100644 --- a/src/storage_file/storage_source.c +++ b/src/storage_file/storage_source.c @@ -1881,24 +1881,26 @@ virStorageSourceGetRelativeBackingPath(virStorageSo= urcePtr top, /** - * virStorageSourceGetBackingStoreStr: + * virStorageSourceFetchRelativeBackingPath: * @src: storage object + * @relPath: filled with the relative path to the backing image of @src if + * the metadata of @src refer to it as relative. * - * Extracts the backing store string as stored in the storage volume descr= ibed - * by @src and returns it to the user. Caller is responsible for freeing i= t. - * In case when the string can't be retrieved or does not exist NULL is - * returned. + * Fetches the backing store definition of @src by updating the metadata f= rom + * disk and fills 'relPath' if the backing store string is relative. The d= ata + * is used by virStorageSourceGetRelativeBackingPath to establish the rela= tive + * path between two images. */ int -virStorageSourceGetBackingStoreStr(virStorageSourcePtr src, - char **backing) +virStorageSourceFetchRelativeBackingPath(virStorageSourcePtr src, + char **relPath) { ssize_t headerLen; int rv; g_autofree char *buf =3D NULL; g_autoptr(virStorageSource) tmp =3D NULL; - *backing =3D NULL; + g_clear_pointer(relPath, g_free); /* exit if we can't load information about the current image */ if (!virStorageSourceSupportsBackingChainTraversal(src)) @@ -1925,7 +1927,9 @@ virStorageSourceGetBackingStoreStr(virStorageSourcePt= r src, if (virStorageFileProbeGetMetadata(tmp, buf, headerLen) < 0) return -1; - *backing =3D g_steal_pointer(&tmp->backingStoreRaw); + if (virStorageIsRelative(tmp->backingStoreRaw)) + *relPath =3D g_steal_pointer(&tmp->backingStoreRaw); + return 0; } diff --git a/src/storage_file/storage_source.h b/src/storage_file/storage_s= ource.h index 480333d37a..58f88a3c01 100644 --- a/src/storage_file/storage_source.h +++ b/src/storage_file/storage_source.h @@ -138,8 +138,8 @@ virStorageSourceGetMetadata(virStorageSourcePtr src, ATTRIBUTE_NONNULL(1); int -virStorageSourceGetBackingStoreStr(virStorageSourcePtr src, - char **backing) +virStorageSourceFetchRelativeBackingPath(virStorageSourcePtr src, + char **relPath) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); void --=20 2.29.2 From nobody Tue May 7 18:46:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1611590766; cv=none; d=zohomail.com; s=zohoarc; b=QukRrFxOCsvY8u9UbJGPwxyeaAuL8h7HAwzAAdg4lqy5UnyE+gHHuWMsMzvWt+qa8dltHaRndwIvJj7/ELkJrR0OB5YXNA5yCqDN9GPuo2bEuTlZq+0fKcx/3z9t4HwJvt9VccY+EwvRfcx7WQR/S/5Y7WVgi0EVsS2EDy5h3lg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611590766; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=G9+VZ2MnlbRyMfMAJc9gwqwNyEPKmoHGfptv8XsvLx8=; b=QCdEsWEV2o5bgXfIP2a2VXhH8d5eXh1Cu6A7w+B+KoXpwuBh9MuEmYWurK/7Sgdyq3E4N2qdBhxiq3LErPpcxi5y5Rv1CjFfz82pQCIBoONKWDe6mLVTjmm2gNgD8b7Hol95FCP+Ejbud07qWD0KaC2+RVLDMqmYDc27FHENS8A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1611590766021442.48889455085987; Mon, 25 Jan 2021 08:06:06 -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-8-KDJNJ0T6OmKmVtnVxH7UKA-1; Mon, 25 Jan 2021 11:05:52 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1FA9C19611A6; Mon, 25 Jan 2021 16:05:45 +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 EFFAD5D9DE; Mon, 25 Jan 2021 16:05:44 +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 BCF701809CA4; Mon, 25 Jan 2021 16:05:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 10PG5WTh018208 for ; Mon, 25 Jan 2021 11:05:32 -0500 Received: by smtp.corp.redhat.com (Postfix) id A69C85D9DC; Mon, 25 Jan 2021 16:05:32 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 072445D9DB for ; Mon, 25 Jan 2021 16:05:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611590765; 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=G9+VZ2MnlbRyMfMAJc9gwqwNyEPKmoHGfptv8XsvLx8=; b=XYr/RBfKbM+fgDnKIoEzqkoulvyDf4JvS3ehI/RbuZPxTlVbHO+ng7dj5ZtXP66cOS/Fl1 zDQoAy0c4nCpOglv/Nuz6icZL9XcqJ2ZuSj1YlgdJ3B44son43hvO0bfEcjBathU6aJMR1 zyQ5D2y2kyYcFOlBZoKbSDT+HvIksaQ= X-MC-Unique: KDJNJ0T6OmKmVtnVxH7UKA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 03/12] util: virstoragefile: Move virStorageIs[File|Relative] to storage_source Date: Mon, 25 Jan 2021 17:05:15 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com 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 are no other files using it. Move it and make the functions static. Signed-off-by: Peter Krempa Reviewed-by: Pavel Hrdina --- src/libvirt_private.syms | 2 -- src/storage_file/storage_source.c | 42 ++++++++++++++++++++++++++++--- src/util/virstoragefile.c | 34 ------------------------- src/util/virstoragefile.h | 3 --- 4 files changed, 38 insertions(+), 43 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index c03b769c37..0a2a54dfdf 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3218,8 +3218,6 @@ virStorageFileGetNPIVKey; virStorageFileGetSCSIKey; virStorageFileParseBackingStoreStr; virStorageFileParseChainIndex; -virStorageIsFile; -virStorageIsRelative; # util/virstring.h diff --git a/src/storage_file/storage_source.c b/src/storage_file/storage_s= ource.c index 23d36507ea..df9fb6c055 100644 --- a/src/storage_file/storage_source.c +++ b/src/storage_file/storage_source.c @@ -45,6 +45,40 @@ VIR_LOG_INIT("storage_source"); +static bool +virStorageSourceBackinStoreStringIsFile(const char *backing) +{ + char *colon; + char *slash; + + if (!backing) + return false; + + colon =3D strchr(backing, ':'); + slash =3D strchr(backing, '/'); + + /* Reject anything that looks like a protocol (such as nbd: or + * rbd:); if someone really does want a relative file name that + * includes ':', they can always prefix './'. */ + if (colon && (!slash || colon < slash)) + return false; + return true; +} + + +static bool +virStorageSourceBackinStoreStringIsRelative(const char *backing) +{ + if (backing[0] =3D=3D '/') + return false; + + if (!virStorageSourceBackinStoreStringIsFile(backing)) + return false; + + return true; +} + + static virStorageSourcePtr virStorageSourceMetadataNew(const char *path, int format) @@ -185,7 +219,7 @@ virStorageSourceChainLookup(virStorageSourcePtr chain, { virStorageSourcePtr prev; const char *start =3D chain->path; - bool nameIsFile =3D virStorageIsFile(name); + bool nameIsFile =3D virStorageSourceBackinStoreStringIsFile(name); if (!parent) parent =3D &prev; @@ -1532,7 +1566,7 @@ virStorageSourceNewFromBackingAbsolute(const char *pa= th, *src =3D NULL; - if (virStorageIsFile(path)) { + if (virStorageSourceBackinStoreStringIsFile(path)) { def->type =3D VIR_STORAGE_TYPE_FILE; def->path =3D g_strdup(path); @@ -1604,7 +1638,7 @@ virStorageSourceNewFromChild(virStorageSourcePtr pare= nt, *child =3D NULL; - if (virStorageIsRelative(parentRaw)) { + if (virStorageSourceBackinStoreStringIsRelative(parentRaw)) { if (!(def =3D virStorageSourceNewFromBackingRelative(parent, paren= tRaw))) return -1; } else { @@ -1927,7 +1961,7 @@ virStorageSourceFetchRelativeBackingPath(virStorageSo= urcePtr src, if (virStorageFileProbeGetMetadata(tmp, buf, headerLen) < 0) return -1; - if (virStorageIsRelative(tmp->backingStoreRaw)) + if (virStorageSourceBackinStoreStringIsRelative(tmp->backingStoreRaw)) *relPath =3D g_steal_pointer(&tmp->backingStoreRaw); return 0; diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 85ccd9f52c..d1e56db708 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -37,40 +37,6 @@ VIR_LOG_INIT("util.storagefile"); -bool -virStorageIsFile(const char *backing) -{ - char *colon; - char *slash; - - if (!backing) - return false; - - colon =3D strchr(backing, ':'); - slash =3D strchr(backing, '/'); - - /* Reject anything that looks like a protocol (such as nbd: or - * rbd:); if someone really does want a relative file name that - * includes ':', they can always prefix './'. */ - if (colon && (!slash || colon < slash)) - return false; - return true; -} - - -bool -virStorageIsRelative(const char *backing) -{ - if (backing[0] =3D=3D '/') - return false; - - if (!virStorageIsFile(backing)) - return false; - - return true; -} - - #ifdef WITH_UDEV /* virStorageFileGetSCSIKey * @path: Path to the SCSI device diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index 2c1a250f20..455a978a8d 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -33,9 +33,6 @@ int virStorageFileParseBackingStoreStr(const char *str, unsigned int *chainIndex) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3); -bool virStorageIsFile(const char *path); -bool virStorageIsRelative(const char *backing); - int virStorageFileGetSCSIKey(const char *path, char **key, bool ignoreError); --=20 2.29.2 From nobody Tue May 7 18:46:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1611590751; cv=none; d=zohomail.com; s=zohoarc; b=h9e1qWFP/S8b8uSQcK4qAS8xAVA+UakMHC1vldgjvHdTe9DZomiasrmjLqrypNkUNqQ99VO9pZSOepWz4oP9ktcVMy60KXIiJ3JCCIJvYioHKqN+RBfgXfUFc6UvcM1oMeCgIEq1hdgdujO4/2m6N65tai7WXvbTAly9oHiSw3k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611590751; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=B0YMvCKvXkF3B1TGv3sLHSNY8hZW9ej8WR/INZV5C3M=; b=PBn/sJNpIeD4q5dS0XHW6dKFdd2ZQDpJRW3rpHlz5MNQhr7Y12Na+ZGuNIs9QJjquz3JSZGkY7p7s8Ai6ngJrnQQ9IFHdIjM+nfWUiGrMpyf98pwFTi2l3OV4lZPzsBOVfP2V59OHyIWPNK4Cb7DDxhL6mX1e/xCaFJzoAMSZs4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1611590751275599.7046289958515; Mon, 25 Jan 2021 08:05:51 -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-465-8UbfUtuPMRO_fNn7dolAfw-1; Mon, 25 Jan 2021 11:05:46 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6E5B31005504; Mon, 25 Jan 2021 16:05:38 +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 467545D9E4; Mon, 25 Jan 2021 16:05: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 EBCB01809CA0; Mon, 25 Jan 2021 16:05:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 10PG5YXx018226 for ; Mon, 25 Jan 2021 11:05:34 -0500 Received: by smtp.corp.redhat.com (Postfix) id A61185D9DC; Mon, 25 Jan 2021 16:05:34 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 287FC5D9DB for ; Mon, 25 Jan 2021 16:05:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611590750; 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=B0YMvCKvXkF3B1TGv3sLHSNY8hZW9ej8WR/INZV5C3M=; b=Wc2CaCi7jdaRbjvBSQ9elB4W5sedZFShlXDhKNvlFNvMHYA74My98JWiED8hAmzWkXqzzO 6WXcR6qt01TpaEQWGfXHtWM2qfd420ibyXpSMHDjGgSwWYOOmuNseTr5aHH62paG1CYhUX fGOXgw+O6uaB7Vo3ZBGc2JcLhiaC1YE= X-MC-Unique: 8UbfUtuPMRO_fNn7dolAfw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 04/12] storage_source: Move backing store parsers into new file Date: Mon, 25 Jan 2021 17:05:16 +0100 Message-Id: <21b4db97f726d4893f2b8f2a5fdeae7abddfa526.1611590679.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com 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 parsers for the backing store strings are relatively self-contained and rather massive piece of code. Move them to a new module called storage_source_backingstore. Signed-off-by: Peter Krempa Reviewed-by: Pavel Hrdina --- po/POTFILES.in | 1 + src/storage_file/meson.build | 1 + src/storage_file/storage_source.c | 1207 +--------------- .../storage_source_backingstore.c | 1240 +++++++++++++++++ .../storage_source_backingstore.h | 40 + 5 files changed, 1283 insertions(+), 1206 deletions(-) create mode 100644 src/storage_file/storage_source_backingstore.c create mode 100644 src/storage_file/storage_source_backingstore.h diff --git a/po/POTFILES.in b/po/POTFILES.in index a2c46dd239..b09e58f14a 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -230,6 +230,7 @@ @SRCDIR@src/storage_file/storage_file_backend_gluster.c @SRCDIR@src/storage_file/storage_file_probe.c @SRCDIR@src/storage_file/storage_source.c +@SRCDIR@src/storage_file/storage_source_backingstore.c @SRCDIR@src/test/test_driver.c @SRCDIR@src/util/iohelper.c @SRCDIR@src/util/viralloc.c diff --git a/src/storage_file/meson.build b/src/storage_file/meson.build index 4f8068848c..d40e98befa 100644 --- a/src/storage_file/meson.build +++ b/src/storage_file/meson.build @@ -1,5 +1,6 @@ storage_file_sources =3D [ 'storage_source.c', + 'storage_source_backingstore.c', 'storage_file_backend.c', 'storage_file_probe.c', ] diff --git a/src/storage_file/storage_source.c b/src/storage_file/storage_s= ource.c index df9fb6c055..9d3761f5bd 100644 --- a/src/storage_file/storage_source.c +++ b/src/storage_file/storage_source.c @@ -28,16 +28,15 @@ #include "storage_file_backend.h" #include "storage_file_probe.h" #include "storage_source.h" +#include "storage_source_backingstore.h" #include "viralloc.h" #include "virerror.h" #include "virfile.h" #include "virhash.h" -#include "virjson.h" #include "virlog.h" #include "virobject.h" #include "virstoragefile.h" #include "virstring.h" -#include "viruri.h" #include "virutil.h" #define VIR_FROM_THIS VIR_FROM_STORAGE @@ -341,1210 +340,6 @@ virStorageSourceNewFromBackingRelative(virStorageSou= rcePtr parent, } -static int -virStorageSourceParseBackingURI(virStorageSourcePtr src, - const char *uristr) -{ - g_autoptr(virURI) uri =3D NULL; - const char *path =3D NULL; - g_auto(GStrv) scheme =3D NULL; - - if (!(uri =3D virURIParse(uristr))) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("failed to parse backing file location '%s'"), - uristr); - return -1; - } - - src->hosts =3D g_new0(virStorageNetHostDef, 1); - src->nhosts =3D 1; - - if (!(scheme =3D virStringSplit(uri->scheme, "+", 2))) - return -1; - - if (!scheme[0] || - (src->protocol =3D virStorageNetProtocolTypeFromString(scheme[0]))= < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("invalid backing protocol '%s'"), - NULLSTR(scheme[0])); - return -1; - } - - if (scheme[1] && - (src->hosts->transport =3D virStorageNetHostTransportTypeFromStrin= g(scheme[1])) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("invalid protocol transport type '%s'"), - scheme[1]); - return -1; - } - - if (uri->query) { - if (src->protocol =3D=3D VIR_STORAGE_NET_PROTOCOL_HTTP || - src->protocol =3D=3D VIR_STORAGE_NET_PROTOCOL_HTTPS) { - src->query =3D g_strdup(uri->query); - } else { - /* handle socket stored as a query */ - if (STRPREFIX(uri->query, "socket=3D")) - src->hosts->socket =3D g_strdup(STRSKIP(uri->query, "socke= t=3D")); - } - } - - /* uri->path is NULL if the URI does not contain slash after host: - * transport://host:port */ - if (uri->path) - path =3D uri->path; - else - path =3D ""; - - /* possibly skip the leading slash */ - if (path[0] =3D=3D '/') - path++; - - /* NBD allows empty export name (path) */ - if (src->protocol =3D=3D VIR_STORAGE_NET_PROTOCOL_NBD && - path[0] =3D=3D '\0') - path =3D NULL; - - src->path =3D g_strdup(path); - - if (src->protocol =3D=3D VIR_STORAGE_NET_PROTOCOL_GLUSTER) { - char *tmp; - - if (!src->path) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("missing volume name and path for gluster vol= ume")); - return -1; - } - - if (!(tmp =3D strchr(src->path, '/')) || - tmp =3D=3D src->path) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("missing volume name or file name in " - "gluster source path '%s'"), src->path); - return -1; - } - - src->volume =3D src->path; - - src->path =3D g_strdup(tmp + 1); - - tmp[0] =3D '\0'; - } - - src->hosts->port =3D uri->port; - - src->hosts->name =3D g_strdup(uri->server); - - /* Libvirt doesn't handle inline authentication. Make the caller aware= . */ - if (uri->user) - return 1; - - return 0; -} - - -static int -virStorageSourceRBDAddHost(virStorageSourcePtr src, - char *hostport) -{ - char *port; - size_t skip; - g_auto(GStrv) parts =3D NULL; - - if (VIR_EXPAND_N(src->hosts, src->nhosts, 1) < 0) - return -1; - - if ((port =3D strchr(hostport, ']'))) { - /* ipv6, strip brackets */ - hostport +=3D 1; - skip =3D 3; - } else { - port =3D strstr(hostport, "\\:"); - skip =3D 2; - } - - if (port) { - *port =3D '\0'; - port +=3D skip; - if (virStringParsePort(port, &src->hosts[src->nhosts - 1].port) < = 0) - goto error; - } - - parts =3D virStringSplit(hostport, "\\:", 0); - if (!parts) - goto error; - src->hosts[src->nhosts-1].name =3D virStringListJoin((const char **)pa= rts, ":"); - if (!src->hosts[src->nhosts-1].name) - goto error; - - src->hosts[src->nhosts-1].transport =3D VIR_STORAGE_NET_HOST_TRANS_TCP; - src->hosts[src->nhosts-1].socket =3D NULL; - - return 0; - - error: - VIR_FREE(src->hosts[src->nhosts-1].name); - return -1; -} - - -int -virStorageSourceParseRBDColonString(const char *rbdstr, - virStorageSourcePtr src) -{ - char *p, *e, *next; - g_autofree char *options =3D NULL; - g_autoptr(virStorageAuthDef) authdef =3D NULL; - - /* optionally skip the "rbd:" prefix if provided */ - if (STRPREFIX(rbdstr, "rbd:")) - rbdstr +=3D strlen("rbd:"); - - src->path =3D g_strdup(rbdstr); - - p =3D strchr(src->path, ':'); - if (p) { - options =3D g_strdup(p + 1); - *p =3D '\0'; - } - - /* snapshot name */ - if ((p =3D strchr(src->path, '@'))) { - src->snapshot =3D g_strdup(p + 1); - *p =3D '\0'; - } - - /* pool vs. image name */ - if ((p =3D strchr(src->path, '/'))) { - src->volume =3D g_steal_pointer(&src->path); - src->path =3D g_strdup(p + 1); - *p =3D '\0'; - } - - /* options */ - if (!options) - return 0; /* all done */ - - p =3D options; - while (*p) { - /* find : delimiter or end of string */ - for (e =3D p; *e && *e !=3D ':'; ++e) { - if (*e =3D=3D '\\') { - e++; - if (*e =3D=3D '\0') - break; - } - } - if (*e =3D=3D '\0') { - next =3D e; /* last kv pair */ - } else { - next =3D e + 1; - *e =3D '\0'; - } - - if (STRPREFIX(p, "id=3D")) { - /* formulate authdef for src->auth */ - if (src->auth) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("duplicate 'id' found in '%s'"), src->pat= h); - return -1; - } - - authdef =3D g_new0(virStorageAuthDef, 1); - - authdef->username =3D g_strdup(p + strlen("id=3D")); - - authdef->secrettype =3D g_strdup(virSecretUsageTypeToString(VI= R_SECRET_USAGE_TYPE_CEPH)); - src->auth =3D g_steal_pointer(&authdef); - - /* Cannot formulate a secretType (eg, usage or uuid) given - * what is provided. - */ - } - if (STRPREFIX(p, "mon_host=3D")) { - char *h, *sep; - - h =3D p + strlen("mon_host=3D"); - while (h < e) { - for (sep =3D h; sep < e; ++sep) { - if (*sep =3D=3D '\\' && (sep[1] =3D=3D ',' || - sep[1] =3D=3D ';' || - sep[1] =3D=3D ' ')) { - *sep =3D '\0'; - sep +=3D 2; - break; - } - } - - if (virStorageSourceRBDAddHost(src, h) < 0) - return -1; - - h =3D sep; - } - } - - if (STRPREFIX(p, "conf=3D")) - src->configFile =3D g_strdup(p + strlen("conf=3D")); - - p =3D next; - } - return 0; -} - - -static int -virStorageSourceParseNBDColonString(const char *nbdstr, - virStorageSourcePtr src) -{ - g_autofree char *nbd =3D g_strdup(nbdstr); - char *export_name; - char *host_spec; - char *unixpath; - char *port; - - src->hosts =3D g_new0(virStorageNetHostDef, 1); - src->nhosts =3D 1; - - /* We extract the parameters in a similar way qemu does it */ - - /* format: [] denotes optional sections, uppercase are variable strings - * nbd:unix:/PATH/TO/SOCKET[:exportname=3DEXPORTNAME] - * nbd:HOSTNAME:PORT[:exportname=3DEXPORTNAME] - */ - - /* first look for ':exportname=3D' and cut it off */ - if ((export_name =3D strstr(nbd, ":exportname=3D"))) { - src->path =3D g_strdup(export_name + strlen(":exportname=3D")); - export_name[0] =3D '\0'; - } - - /* Verify the prefix and contents. Note that we require a - * "host_spec" part to be present. */ - if (!(host_spec =3D STRSKIP(nbd, "nbd:")) || host_spec[0] =3D=3D '\0') - goto malformed; - - if ((unixpath =3D STRSKIP(host_spec, "unix:"))) { - src->hosts->transport =3D VIR_STORAGE_NET_HOST_TRANS_UNIX; - - if (unixpath[0] =3D=3D '\0') - goto malformed; - - src->hosts->socket =3D g_strdup(unixpath); - } else { - src->hosts->transport =3D VIR_STORAGE_NET_HOST_TRANS_TCP; - - if (host_spec[0] =3D=3D ':') { - /* no host given */ - goto malformed; - } else if (host_spec[0] =3D=3D '[') { - host_spec++; - /* IPv6 addr */ - if (!(port =3D strstr(host_spec, "]:"))) - goto malformed; - - port[0] =3D '\0'; - port +=3D 2; - - if (host_spec[0] =3D=3D '\0') - goto malformed; - } else { - if (!(port =3D strchr(host_spec, ':'))) - goto malformed; - - port[0] =3D '\0'; - port++; - } - - if (virStringParsePort(port, &src->hosts->port) < 0) - return -1; - - src->hosts->name =3D g_strdup(host_spec); - } - - return 0; - - malformed: - virReportError(VIR_ERR_INTERNAL_ERROR, - _("malformed nbd string '%s'"), nbdstr); - return -1; -} - - -static int -virStorageSourceParseBackingColon(virStorageSourcePtr src, - const char *path) -{ - const char *p; - g_autofree char *protocol =3D NULL; - - if (!(p =3D strchr(path, ':'))) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("invalid backing protocol string '%s'"), - path); - return -1; - } - - protocol =3D g_strndup(path, p - path); - - if ((src->protocol =3D virStorageNetProtocolTypeFromString(protocol)) = < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("invalid backing protocol '%s'"), - protocol); - return -1; - } - - switch ((virStorageNetProtocol) src->protocol) { - case VIR_STORAGE_NET_PROTOCOL_NBD: - if (virStorageSourceParseNBDColonString(path, src) < 0) - return -1; - break; - - case VIR_STORAGE_NET_PROTOCOL_RBD: - if (virStorageSourceParseRBDColonString(path, src) < 0) - return -1; - break; - - case VIR_STORAGE_NET_PROTOCOL_SHEEPDOG: - case VIR_STORAGE_NET_PROTOCOL_LAST: - case VIR_STORAGE_NET_PROTOCOL_NONE: - virReportError(VIR_ERR_INTERNAL_ERROR, - _("backing store parser is not implemented for prot= ocol %s"), - protocol); - return -1; - - case VIR_STORAGE_NET_PROTOCOL_HTTP: - case VIR_STORAGE_NET_PROTOCOL_HTTPS: - case VIR_STORAGE_NET_PROTOCOL_FTP: - case VIR_STORAGE_NET_PROTOCOL_FTPS: - case VIR_STORAGE_NET_PROTOCOL_TFTP: - case VIR_STORAGE_NET_PROTOCOL_ISCSI: - case VIR_STORAGE_NET_PROTOCOL_GLUSTER: - case VIR_STORAGE_NET_PROTOCOL_SSH: - case VIR_STORAGE_NET_PROTOCOL_VXHS: - case VIR_STORAGE_NET_PROTOCOL_NFS: - virReportError(VIR_ERR_INTERNAL_ERROR, - _("malformed backing store path for protocol %s"), - protocol); - return -1; - } - - return 0; -} - - -static int -virStorageSourceParseBackingJSONInternal(virStorageSourcePtr src, - virJSONValuePtr json, - const char *jsonstr, - bool allowformat); - - -static int -virStorageSourceParseBackingJSONPath(virStorageSourcePtr src, - virJSONValuePtr json, - const char *jsonstr G_GNUC_UNUSED, - int type) -{ - const char *path; - - if (!(path =3D virJSONValueObjectGetString(json, "filename"))) { - virReportError(VIR_ERR_INVALID_ARG, "%s", - _("missing 'filename' field in JSON backing volume " - "definition")); - return -1; - } - - src->path =3D g_strdup(path); - - src->type =3D type; - return 0; -} - - -static int -virStorageSourceParseBackingJSONUriStr(virStorageSourcePtr src, - const char *uri, - int protocol) -{ - int rc; - - if ((rc =3D virStorageSourceParseBackingURI(src, uri)) < 0) - return -1; - - if (src->protocol !=3D protocol) { - virReportError(VIR_ERR_INVALID_ARG, - _("expected protocol '%s' but got '%s' in URI JSON = volume " - "definition"), - virStorageNetProtocolTypeToString(protocol), - virStorageNetProtocolTypeToString(src->protocol)); - return -1; - } - - return rc; -} - - -static int -virStorageSourceParseBackingJSONUriCookies(virStorageSourcePtr src, - virJSONValuePtr json, - const char *jsonstr) -{ - const char *cookiestr; - g_auto(GStrv) cookies =3D NULL; - size_t ncookies =3D 0; - size_t i; - - if (!virJSONValueObjectHasKey(json, "cookie")) - return 0; - - if (!(cookiestr =3D virJSONValueObjectGetString(json, "cookie"))) { - virReportError(VIR_ERR_INVALID_ARG, - _("wrong format of 'cookie' field in backing store = definition '%s'"), - jsonstr); - return -1; - } - - if (!(cookies =3D virStringSplitCount(cookiestr, ";", 0, &ncookies))) - return -1; - - src->cookies =3D g_new0(virStorageNetCookieDefPtr, ncookies); - src->ncookies =3D ncookies; - - for (i =3D 0; i < ncookies; i++) { - char *cookiename =3D cookies[i]; - char *cookievalue; - - virSkipSpaces((const char **) &cookiename); - - if (!(cookievalue =3D strchr(cookiename, '=3D'))) { - virReportError(VIR_ERR_INVALID_ARG, - _("malformed http cookie '%s' in backing store = definition '%s'"), - cookies[i], jsonstr); - return -1; - } - - *cookievalue =3D '\0'; - cookievalue++; - - src->cookies[i] =3D g_new0(virStorageNetCookieDef, 1); - src->cookies[i]->name =3D g_strdup(cookiename); - src->cookies[i]->value =3D g_strdup(cookievalue); - } - - return 0; -} - - -static int -virStorageSourceParseBackingJSONUri(virStorageSourcePtr src, - virJSONValuePtr json, - const char *jsonstr, - int protocol) -{ - const char *uri; - - if (!(uri =3D virJSONValueObjectGetString(json, "url"))) { - virReportError(VIR_ERR_INVALID_ARG, "%s", - _("missing 'url' in JSON backing volume definition"= )); - return -1; - } - - if (protocol =3D=3D VIR_STORAGE_NET_PROTOCOL_HTTPS || - protocol =3D=3D VIR_STORAGE_NET_PROTOCOL_FTPS) { - if (virJSONValueObjectHasKey(json, "sslverify")) { - const char *tmpstr; - bool tmp; - - /* libguestfs still uses undocumented legacy value of 'off' */ - if ((tmpstr =3D virJSONValueObjectGetString(json, "sslverify")= ) && - STREQ(tmpstr, "off")) { - src->sslverify =3D VIR_TRISTATE_BOOL_NO; - } else { - if (virJSONValueObjectGetBoolean(json, "sslverify", &tmp) = < 0) { - virReportError(VIR_ERR_INVALID_ARG, - _("malformed 'sslverify' field in backi= ng store definition '%s'"), - jsonstr); - return -1; - } - - src->sslverify =3D virTristateBoolFromBool(tmp); - } - } - } - - if (protocol =3D=3D VIR_STORAGE_NET_PROTOCOL_HTTPS || - protocol =3D=3D VIR_STORAGE_NET_PROTOCOL_HTTP) { - if (virStorageSourceParseBackingJSONUriCookies(src, json, jsonstr)= < 0) - return -1; - } - - if (virJSONValueObjectHasKey(json, "readahead") && - virJSONValueObjectGetNumberUlong(json, "readahead", &src->readahea= d) < 0) { - virReportError(VIR_ERR_INVALID_ARG, - _("malformed 'readahead' field in backing store def= inition '%s'"), - jsonstr); - return -1; - } - - if (virJSONValueObjectHasKey(json, "timeout") && - virJSONValueObjectGetNumberUlong(json, "timeout", &src->timeout) <= 0) { - virReportError(VIR_ERR_INVALID_ARG, - _("malformed 'timeout' field in backing store defin= ition '%s'"), - jsonstr); - return -1; - } - - return virStorageSourceParseBackingJSONUriStr(src, uri, protocol); -} - - -static int -virStorageSourceParseBackingJSONInetSocketAddress(virStorageNetHostDefPtr = host, - virJSONValuePtr json) -{ - const char *hostname; - const char *port; - - if (!json) { - virReportError(VIR_ERR_INVALID_ARG, "%s", - _("missing remote server specification in JSON " - "backing volume definition")); - return -1; - } - - hostname =3D virJSONValueObjectGetString(json, "host"); - port =3D virJSONValueObjectGetString(json, "port"); - - if (!hostname) { - virReportError(VIR_ERR_INVALID_ARG, "%s", - _("missing hostname for tcp backing server in " - "JSON backing volume definition")); - return -1; - } - - host->transport =3D VIR_STORAGE_NET_HOST_TRANS_TCP; - host->name =3D g_strdup(hostname); - - if (virStringParsePort(port, &host->port) < 0) - return -1; - - return 0; -} - - -static int -virStorageSourceParseBackingJSONSocketAddress(virStorageNetHostDefPtr host, - virJSONValuePtr json) -{ - const char *type; - const char *socket; - - if (!json) { - virReportError(VIR_ERR_INVALID_ARG, "%s", - _("missing remote server specification in JSON " - "backing volume definition")); - return -1; - } - - if (!(type =3D virJSONValueObjectGetString(json, "type"))) { - virReportError(VIR_ERR_INVALID_ARG, "%s", - _("missing socket address type in " - "JSON backing volume definition")); - return -1; - } - - if (STREQ(type, "tcp") || STREQ(type, "inet")) { - return virStorageSourceParseBackingJSONInetSocketAddress(host, jso= n); - - } else if (STREQ(type, "unix")) { - host->transport =3D VIR_STORAGE_NET_HOST_TRANS_UNIX; - - socket =3D virJSONValueObjectGetString(json, "path"); - - /* check for old spelling for gluster protocol */ - if (!socket) - socket =3D virJSONValueObjectGetString(json, "socket"); - - if (!socket) { - virReportError(VIR_ERR_INVALID_ARG, "%s", - _("missing socket path for udp backing server i= n " - "JSON backing volume definition")); - return -1; - } - - host->socket =3D g_strdup(socket); - } else { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("backing store protocol '%s' is not yet supported= "), - type); - return -1; - } - - return 0; -} - - -static int -virStorageSourceParseBackingJSONGluster(virStorageSourcePtr src, - virJSONValuePtr json, - const char *jsonstr G_GNUC_UNUSED, - int opaque G_GNUC_UNUSED) -{ - const char *uri =3D virJSONValueObjectGetString(json, "filename"); - const char *volume =3D virJSONValueObjectGetString(json, "volume"); - const char *path =3D virJSONValueObjectGetString(json, "path"); - virJSONValuePtr server =3D virJSONValueObjectGetArray(json, "server"); - size_t nservers; - size_t i; - - /* legacy URI based syntax passed via 'filename' option */ - if (uri) - return virStorageSourceParseBackingJSONUriStr(src, uri, - VIR_STORAGE_NET_PROT= OCOL_GLUSTER); - - if (!volume || !path || !server) { - virReportError(VIR_ERR_INVALID_ARG, "%s", - _("missing 'volume', 'path' or 'server' attribute i= n " - "JSON backing definition for gluster volume")); - return -1; - } - - src->type =3D VIR_STORAGE_TYPE_NETWORK; - src->protocol =3D VIR_STORAGE_NET_PROTOCOL_GLUSTER; - - src->volume =3D g_strdup(volume); - src->path =3D g_strdup(path); - - nservers =3D virJSONValueArraySize(server); - if (nservers =3D=3D 0) { - virReportError(VIR_ERR_INVALID_ARG, "%s", - _("at least 1 server is necessary in " - "JSON backing definition for gluster volume")); - - return -1; - } - - src->hosts =3D g_new0(virStorageNetHostDef, nservers); - src->nhosts =3D nservers; - - for (i =3D 0; i < nservers; i++) { - if (virStorageSourceParseBackingJSONSocketAddress(src->hosts + i, - virJSONValueArra= yGet(server, i)) < 0) - return -1; - } - - return 0; -} - - -static int -virStorageSourceParseBackingJSONiSCSI(virStorageSourcePtr src, - virJSONValuePtr json, - const char *jsonstr G_GNUC_UNUSED, - int opaque G_GNUC_UNUSED) -{ - const char *transport =3D virJSONValueObjectGetString(json, "transport= "); - const char *portal =3D virJSONValueObjectGetString(json, "portal"); - const char *target =3D virJSONValueObjectGetString(json, "target"); - const char *lun =3D virJSONValueObjectGetStringOrNumber(json, "lun"); - const char *uri; - char *port; - - /* legacy URI based syntax passed via 'filename' option */ - if ((uri =3D virJSONValueObjectGetString(json, "filename"))) - return virStorageSourceParseBackingJSONUriStr(src, uri, - VIR_STORAGE_NET_PROT= OCOL_ISCSI); - - src->type =3D VIR_STORAGE_TYPE_NETWORK; - src->protocol =3D VIR_STORAGE_NET_PROTOCOL_ISCSI; - - if (!lun) - lun =3D "0"; - - src->hosts =3D g_new0(virStorageNetHostDef, 1); - src->nhosts =3D 1; - - if (STRNEQ_NULLABLE(transport, "tcp")) { - virReportError(VIR_ERR_INVALID_ARG, "%s", - _("only TCP transport is supported for iSCSI volume= s")); - return -1; - } - - src->hosts->transport =3D VIR_STORAGE_NET_HOST_TRANS_TCP; - - if (!portal) { - virReportError(VIR_ERR_INVALID_ARG, "%s", - _("missing 'portal' address in iSCSI backing defini= tion")); - return -1; - } - - if (!target) { - virReportError(VIR_ERR_INVALID_ARG, "%s", - _("missing 'target' in iSCSI backing definition")); - return -1; - } - - src->hosts->name =3D g_strdup(portal); - - if ((port =3D strrchr(src->hosts->name, ':')) && - !strchr(port, ']')) { - if (virStringParsePort(port + 1, &src->hosts->port) < 0) - return -1; - - *port =3D '\0'; - } - - src->path =3D g_strdup_printf("%s/%s", target, lun); - - /* Libvirt doesn't handle inline authentication. Make the caller aware= . */ - if (virJSONValueObjectGetString(json, "user") || - virJSONValueObjectGetString(json, "password")) - return 1; - - return 0; -} - - -static int -virStorageSourceParseBackingJSONNbd(virStorageSourcePtr src, - virJSONValuePtr json, - const char *jsonstr G_GNUC_UNUSED, - int opaque G_GNUC_UNUSED) -{ - const char *path =3D virJSONValueObjectGetString(json, "path"); - const char *host =3D virJSONValueObjectGetString(json, "host"); - const char *port =3D virJSONValueObjectGetString(json, "port"); - const char *export =3D virJSONValueObjectGetString(json, "export"); - virJSONValuePtr server =3D virJSONValueObjectGetObject(json, "server"); - - if (!path && !host && !server) { - virReportError(VIR_ERR_INVALID_ARG, "%s", - _("missing host specification of NBD server in JSON= " - "backing volume definition")); - return -1; - } - - src->type =3D VIR_STORAGE_TYPE_NETWORK; - src->protocol =3D VIR_STORAGE_NET_PROTOCOL_NBD; - - src->path =3D g_strdup(export); - - src->hosts =3D g_new0(virStorageNetHostDef, 1); - src->nhosts =3D 1; - - if (server) { - if (virStorageSourceParseBackingJSONSocketAddress(src->hosts, serv= er) < 0) - return -1; - } else { - if (path) { - src->hosts[0].transport =3D VIR_STORAGE_NET_HOST_TRANS_UNIX; - src->hosts[0].socket =3D g_strdup(path); - } else { - src->hosts[0].transport =3D VIR_STORAGE_NET_HOST_TRANS_TCP; - src->hosts[0].name =3D g_strdup(host); - - if (virStringParsePort(port, &src->hosts[0].port) < 0) - return -1; - } - } - - return 0; -} - - -static int -virStorageSourceParseBackingJSONSheepdog(virStorageSourcePtr src, - virJSONValuePtr json, - const char *jsonstr G_GNUC_UNUSED, - int opaque G_GNUC_UNUSED) -{ - const char *filename; - const char *vdi =3D virJSONValueObjectGetString(json, "vdi"); - virJSONValuePtr server =3D virJSONValueObjectGetObject(json, "server"); - - /* legacy URI based syntax passed via 'filename' option */ - if ((filename =3D virJSONValueObjectGetString(json, "filename"))) { - if (strstr(filename, "://")) - return virStorageSourceParseBackingJSONUriStr(src, filename, - VIR_STORAGE_NET_= PROTOCOL_SHEEPDOG); - - /* libvirt doesn't implement a parser for the legacy non-URI synta= x */ - virReportError(VIR_ERR_INVALID_ARG, "%s", - _("missing sheepdog URI in JSON backing volume defi= nition")); - return -1; - } - - src->type =3D VIR_STORAGE_TYPE_NETWORK; - src->protocol =3D VIR_STORAGE_NET_PROTOCOL_SHEEPDOG; - - if (!vdi) { - virReportError(VIR_ERR_INVALID_ARG, "%s", _("missing sheepdog vdi = name")); - return -1; - } - - src->path =3D g_strdup(vdi); - - src->hosts =3D g_new0(virStorageNetHostDef, 1); - src->nhosts =3D 1; - - if (virStorageSourceParseBackingJSONSocketAddress(src->hosts, server) = < 0) - return -1; - - return 0; -} - - -static int -virStorageSourceParseBackingJSONSSH(virStorageSourcePtr src, - virJSONValuePtr json, - const char *jsonstr G_GNUC_UNUSED, - int opaque G_GNUC_UNUSED) -{ - const char *path =3D virJSONValueObjectGetString(json, "path"); - const char *host =3D virJSONValueObjectGetString(json, "host"); - const char *port =3D virJSONValueObjectGetString(json, "port"); - const char *user =3D virJSONValueObjectGetString(json, "user"); - const char *host_key_check =3D virJSONValueObjectGetString(json, "host= _key_check"); - virJSONValuePtr server =3D virJSONValueObjectGetObject(json, "server"); - - if (!(host || server) || !path) { - virReportError(VIR_ERR_INVALID_ARG, "%s", - _("missing host/server or path of SSH JSON backing " - "volume definition")); - return -1; - } - - src->type =3D VIR_STORAGE_TYPE_NETWORK; - src->protocol =3D VIR_STORAGE_NET_PROTOCOL_SSH; - - src->path =3D g_strdup(path); - - src->hosts =3D g_new0(virStorageNetHostDef, 1); - src->nhosts =3D 1; - - if (server) { - if (virStorageSourceParseBackingJSONInetSocketAddress(src->hosts, - server) < 0) - return -1; - } else { - src->hosts[0].transport =3D VIR_STORAGE_NET_HOST_TRANS_TCP; - src->hosts[0].name =3D g_strdup(host); - - if (virStringParsePort(port, &src->hosts[0].port) < 0) - return -1; - } - - /* these two are parsed just to be passed back as we don't model them = yet */ - src->ssh_user =3D g_strdup(user); - if (STREQ_NULLABLE(host_key_check, "no")) - src->ssh_host_key_check_disabled =3D true; - - return 0; -} - - -static int -virStorageSourceParseBackingJSONRBD(virStorageSourcePtr src, - virJSONValuePtr json, - const char *jsonstr G_GNUC_UNUSED, - int opaque G_GNUC_UNUSED) -{ - const char *filename; - const char *pool =3D virJSONValueObjectGetString(json, "pool"); - const char *image =3D virJSONValueObjectGetString(json, "image"); - const char *conf =3D virJSONValueObjectGetString(json, "conf"); - const char *snapshot =3D virJSONValueObjectGetString(json, "snapshot"); - virJSONValuePtr servers =3D virJSONValueObjectGetArray(json, "server"); - size_t nservers; - size_t i; - - src->type =3D VIR_STORAGE_TYPE_NETWORK; - src->protocol =3D VIR_STORAGE_NET_PROTOCOL_RBD; - - /* legacy syntax passed via 'filename' option */ - if ((filename =3D virJSONValueObjectGetString(json, "filename"))) - return virStorageSourceParseRBDColonString(filename, src); - - if (!pool || !image) { - virReportError(VIR_ERR_INVALID_ARG, "%s", - _("missing pool or image name in ceph backing volum= e " - "JSON specification")); - return -1; - } - - src->volume =3D g_strdup(pool); - src->path =3D g_strdup(image); - src->snapshot =3D g_strdup(snapshot); - src->configFile =3D g_strdup(conf); - - if (servers) { - nservers =3D virJSONValueArraySize(servers); - - src->hosts =3D g_new0(virStorageNetHostDef, nservers); - src->nhosts =3D nservers; - - for (i =3D 0; i < nservers; i++) { - if (virStorageSourceParseBackingJSONInetSocketAddress(src->hos= ts + i, - virJSONV= alueArrayGet(servers, i)) < 0) - return -1; - } - } - - return 0; -} - -static int -virStorageSourceParseBackingJSONRaw(virStorageSourcePtr src, - virJSONValuePtr json, - const char *jsonstr, - int opaque G_GNUC_UNUSED) -{ - bool has_offset =3D virJSONValueObjectHasKey(json, "offset"); - bool has_size =3D virJSONValueObjectHasKey(json, "size"); - virJSONValuePtr file; - - if (has_offset || has_size) { - src->sliceStorage =3D g_new0(virStorageSourceSlice, 1); - - if (has_offset && - virJSONValueObjectGetNumberUlong(json, "offset", &src->sliceSt= orage->offset) < 0) { - virReportError(VIR_ERR_INVALID_ARG, "%s", - _("malformed 'offset' property of 'raw' driver"= )); - return -1; - } - - if (has_size && - virJSONValueObjectGetNumberUlong(json, "size", &src->sliceStor= age->size) < 0) { - virReportError(VIR_ERR_INVALID_ARG, "%s", - _("malformed 'size' property of 'raw' driver")); - return -1; - } - } - - /* 'raw' is a format driver so it can have protocol driver children */ - if (!(file =3D virJSONValueObjectGetObject(json, "file"))) { - virReportError(VIR_ERR_INVALID_ARG, - _("JSON backing volume definition '%s' lacks 'file'= object"), - jsonstr); - return -1; - } - - return virStorageSourceParseBackingJSONInternal(src, file, jsonstr, fa= lse); -} - - -static int -virStorageSourceParseBackingJSONVxHS(virStorageSourcePtr src, - virJSONValuePtr json, - const char *jsonstr G_GNUC_UNUSED, - int opaque G_GNUC_UNUSED) -{ - const char *vdisk_id =3D virJSONValueObjectGetString(json, "vdisk-id"); - virJSONValuePtr server =3D virJSONValueObjectGetObject(json, "server"); - - if (!vdisk_id || !server) { - virReportError(VIR_ERR_INVALID_ARG, "%s", - _("missing 'vdisk-id' or 'server' attribute in " - "JSON backing definition for VxHS volume")); - return -1; - } - - src->type =3D VIR_STORAGE_TYPE_NETWORK; - src->protocol =3D VIR_STORAGE_NET_PROTOCOL_VXHS; - - src->path =3D g_strdup(vdisk_id); - - src->hosts =3D g_new0(virStorageNetHostDef, 1); - src->nhosts =3D 1; - - if (virStorageSourceParseBackingJSONInetSocketAddress(src->hosts, - server) < 0) - return -1; - - return 0; -} - - -static int -virStorageSourceParseBackingJSONNFS(virStorageSourcePtr src, - virJSONValuePtr json, - const char *jsonstr G_GNUC_UNUSED, - int opaque G_GNUC_UNUSED) -{ - virJSONValuePtr server =3D virJSONValueObjectGetObject(json, "server"); - int uidStore =3D -1; - int gidStore =3D -1; - int gotUID =3D virJSONValueObjectGetNumberInt(json, "user", &uidStore); - int gotGID =3D virJSONValueObjectGetNumberInt(json, "group", &gidStore= ); - - if (!server) { - virReportError(VIR_ERR_INVALID_ARG, "%s", - _("missing 'server' attribute in JSON backing defin= ition for NFS volume")); - return -1; - } - - if (gotUID < 0 || gotGID < 0) { - virReportError(VIR_ERR_INVALID_ARG, "%s", - _("missing 'user' or 'group' attribute in JSON back= ing definition for NFS volume")); - return -1; - } - - src->path =3D g_strdup(virJSONValueObjectGetString(json, "path")); - if (!src->path) { - virReportError(VIR_ERR_INVALID_ARG, "%s", - _("missing 'path' attribute in JSON backing definit= ion for NFS volume")); - return -1; - } - - src->nfs_user =3D g_strdup_printf("+%d", uidStore); - src->nfs_group =3D g_strdup_printf("+%d", gidStore); - - src->type =3D VIR_STORAGE_TYPE_NETWORK; - src->protocol =3D VIR_STORAGE_NET_PROTOCOL_NFS; - - src->hosts =3D g_new0(virStorageNetHostDef, 1); - src->nhosts =3D 1; - - if (virStorageSourceParseBackingJSONInetSocketAddress(src->hosts, - server) < 0) - return -1; - - return 0; -} - - -static int -virStorageSourceParseBackingJSONNVMe(virStorageSourcePtr src, - virJSONValuePtr json, - const char *jsonstr G_GNUC_UNUSED, - int opaque G_GNUC_UNUSED) -{ - g_autoptr(virStorageSourceNVMeDef) nvme =3D g_new0(virStorageSourceNVM= eDef, 1); - const char *device =3D virJSONValueObjectGetString(json, "device"); - - if (!device || virPCIDeviceAddressParse((char *) device, &nvme->pciAdd= r) < 0) { - virReportError(VIR_ERR_INVALID_ARG, "%s", - _("missing or malformed 'device' field of 'nvme' st= orage")); - return -1; - } - - if (virJSONValueObjectGetNumberUlong(json, "namespace", &nvme->namespc= ) < 0 || - nvme->namespc =3D=3D 0) { - virReportError(VIR_ERR_INVALID_ARG, "%s", - _("missing or malformed 'namespace' field of 'nvme'= storage")); - return -1; - } - - src->type =3D VIR_STORAGE_TYPE_NVME; - src->nvme =3D g_steal_pointer(&nvme); - - return 0; -} - - -struct virStorageSourceJSONDriverParser { - const char *drvname; - bool formatdriver; - /** - * The callback gets a pre-allocated storage source @src and the JSON - * object to parse. The callback shall return -1 on error and report e= rror - * 0 on success and 1 in cases when the configuration itself is valid,= but - * can't be converted to libvirt's configuration (e.g. inline authenti= cation - * credentials are present). - */ - int (*func)(virStorageSourcePtr src, virJSONValuePtr json, const char = *jsonstr, int opaque); - int opaque; -}; - -static const struct virStorageSourceJSONDriverParser jsonParsers[] =3D { - {"file", false, virStorageSourceParseBackingJSONPath, VIR_STORAGE_TYPE= _FILE}, - {"host_device", false, virStorageSourceParseBackingJSONPath, VIR_STORA= GE_TYPE_BLOCK}, - {"host_cdrom", false, virStorageSourceParseBackingJSONPath, VIR_STORAG= E_TYPE_BLOCK}, - {"http", false, virStorageSourceParseBackingJSONUri, VIR_STORAGE_NET_P= ROTOCOL_HTTP}, - {"https", false, virStorageSourceParseBackingJSONUri, VIR_STORAGE_NET_= PROTOCOL_HTTPS}, - {"ftp", false, virStorageSourceParseBackingJSONUri, VIR_STORAGE_NET_PR= OTOCOL_FTP}, - {"ftps", false, virStorageSourceParseBackingJSONUri, VIR_STORAGE_NET_P= ROTOCOL_FTPS}, - {"tftp", false, virStorageSourceParseBackingJSONUri, VIR_STORAGE_NET_P= ROTOCOL_TFTP}, - {"gluster", false, virStorageSourceParseBackingJSONGluster, 0}, - {"iscsi", false, virStorageSourceParseBackingJSONiSCSI, 0}, - {"nbd", false, virStorageSourceParseBackingJSONNbd, 0}, - {"sheepdog", false, virStorageSourceParseBackingJSONSheepdog, 0}, - {"ssh", false, virStorageSourceParseBackingJSONSSH, 0}, - {"rbd", false, virStorageSourceParseBackingJSONRBD, 0}, - {"raw", true, virStorageSourceParseBackingJSONRaw, 0}, - {"nfs", false, virStorageSourceParseBackingJSONNFS, 0}, - {"vxhs", false, virStorageSourceParseBackingJSONVxHS, 0}, - {"nvme", false, virStorageSourceParseBackingJSONNVMe, 0}, -}; - - - -static int -virStorageSourceParseBackingJSONInternal(virStorageSourcePtr src, - virJSONValuePtr json, - const char *jsonstr, - bool allowformat) -{ - const char *drvname; - size_t i; - - if (!(drvname =3D virJSONValueObjectGetString(json, "driver"))) { - virReportError(VIR_ERR_INVALID_ARG, - _("JSON backing volume definition '%s' lacks driver= name"), - jsonstr); - return -1; - } - - for (i =3D 0; i < G_N_ELEMENTS(jsonParsers); i++) { - if (STRNEQ(drvname, jsonParsers[i].drvname)) - continue; - - if (jsonParsers[i].formatdriver && !allowformat) { - virReportError(VIR_ERR_INVALID_ARG, - _("JSON backing volume definition '%s' must not= have nested format drivers"), - jsonstr); - return -1; - } - - return jsonParsers[i].func(src, json, jsonstr, jsonParsers[i].opaq= ue); - } - - virReportError(VIR_ERR_INTERNAL_ERROR, - _("missing parser implementation for JSON backing volum= e " - "driver '%s'"), drvname); - return -1; -} - - -static int -virStorageSourceParseBackingJSON(virStorageSourcePtr src, - const char *json) -{ - g_autoptr(virJSONValue) root =3D NULL; - g_autoptr(virJSONValue) deflattened =3D NULL; - virJSONValuePtr file =3D NULL; - - if (!(root =3D virJSONValueFromString(json))) - return -1; - - if (!(deflattened =3D virJSONValueObjectDeflatten(root))) - return -1; - - /* There are 2 possible syntaxes: - * 1) json:{"file":{"driver":...}} - * 2) json:{"driver":...} - * Remove the 'file' wrapper object in case 1. - */ - if (!virJSONValueObjectHasKey(deflattened, "driver")) - file =3D virJSONValueObjectGetObject(deflattened, "file"); - - if (!file) - file =3D deflattened; - - return virStorageSourceParseBackingJSONInternal(src, file, json, true); -} - - /** * virStorageSourceNewFromBackingAbsolute * @path: string representing absolute location of a storage source diff --git a/src/storage_file/storage_source_backingstore.c b/src/storage_f= ile/storage_source_backingstore.c new file mode 100644 index 0000000000..bbcc720af1 --- /dev/null +++ b/src/storage_file/storage_source_backingstore.c @@ -0,0 +1,1240 @@ +/* + * storage_source_backingstore.c: helpers for parsing backing store strings + * + * Copyright (C) 2007-2017 Red Hat, Inc. + * Copyright (C) 2007-2008 Daniel P. Berrange + * + * 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 "internal.h" + +#include "storage_source_backingstore.h" + +#include "viruri.h" +#include "virstring.h" +#include "virjson.h" +#include "virlog.h" +#include "viralloc.h" + +#define VIR_FROM_THIS VIR_FROM_STORAGE + +VIR_LOG_INIT("storage_source_backingstore"); + + +int +virStorageSourceParseBackingURI(virStorageSourcePtr src, + const char *uristr) +{ + g_autoptr(virURI) uri =3D NULL; + const char *path =3D NULL; + g_auto(GStrv) scheme =3D NULL; + + if (!(uri =3D virURIParse(uristr))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("failed to parse backing file location '%s'"), + uristr); + return -1; + } + + src->hosts =3D g_new0(virStorageNetHostDef, 1); + src->nhosts =3D 1; + + if (!(scheme =3D virStringSplit(uri->scheme, "+", 2))) + return -1; + + if (!scheme[0] || + (src->protocol =3D virStorageNetProtocolTypeFromString(scheme[0]))= < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("invalid backing protocol '%s'"), + NULLSTR(scheme[0])); + return -1; + } + + if (scheme[1] && + (src->hosts->transport =3D virStorageNetHostTransportTypeFromStrin= g(scheme[1])) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("invalid protocol transport type '%s'"), + scheme[1]); + return -1; + } + + if (uri->query) { + if (src->protocol =3D=3D VIR_STORAGE_NET_PROTOCOL_HTTP || + src->protocol =3D=3D VIR_STORAGE_NET_PROTOCOL_HTTPS) { + src->query =3D g_strdup(uri->query); + } else { + /* handle socket stored as a query */ + if (STRPREFIX(uri->query, "socket=3D")) + src->hosts->socket =3D g_strdup(STRSKIP(uri->query, "socke= t=3D")); + } + } + + /* uri->path is NULL if the URI does not contain slash after host: + * transport://host:port */ + if (uri->path) + path =3D uri->path; + else + path =3D ""; + + /* possibly skip the leading slash */ + if (path[0] =3D=3D '/') + path++; + + /* NBD allows empty export name (path) */ + if (src->protocol =3D=3D VIR_STORAGE_NET_PROTOCOL_NBD && + path[0] =3D=3D '\0') + path =3D NULL; + + src->path =3D g_strdup(path); + + if (src->protocol =3D=3D VIR_STORAGE_NET_PROTOCOL_GLUSTER) { + char *tmp; + + if (!src->path) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("missing volume name and path for gluster vol= ume")); + return -1; + } + + if (!(tmp =3D strchr(src->path, '/')) || + tmp =3D=3D src->path) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("missing volume name or file name in " + "gluster source path '%s'"), src->path); + return -1; + } + + src->volume =3D src->path; + + src->path =3D g_strdup(tmp + 1); + + tmp[0] =3D '\0'; + } + + src->hosts->port =3D uri->port; + + src->hosts->name =3D g_strdup(uri->server); + + /* Libvirt doesn't handle inline authentication. Make the caller aware= . */ + if (uri->user) + return 1; + + return 0; +} + + +static int +virStorageSourceRBDAddHost(virStorageSourcePtr src, + char *hostport) +{ + char *port; + size_t skip; + g_auto(GStrv) parts =3D NULL; + + if (VIR_EXPAND_N(src->hosts, src->nhosts, 1) < 0) + return -1; + + if ((port =3D strchr(hostport, ']'))) { + /* ipv6, strip brackets */ + hostport +=3D 1; + skip =3D 3; + } else { + port =3D strstr(hostport, "\\:"); + skip =3D 2; + } + + if (port) { + *port =3D '\0'; + port +=3D skip; + if (virStringParsePort(port, &src->hosts[src->nhosts - 1].port) < = 0) + goto error; + } + + parts =3D virStringSplit(hostport, "\\:", 0); + if (!parts) + goto error; + src->hosts[src->nhosts-1].name =3D virStringListJoin((const char **)pa= rts, ":"); + if (!src->hosts[src->nhosts-1].name) + goto error; + + src->hosts[src->nhosts-1].transport =3D VIR_STORAGE_NET_HOST_TRANS_TCP; + src->hosts[src->nhosts-1].socket =3D NULL; + + return 0; + + error: + VIR_FREE(src->hosts[src->nhosts-1].name); + return -1; +} + + +int +virStorageSourceParseRBDColonString(const char *rbdstr, + virStorageSourcePtr src) +{ + char *p, *e, *next; + g_autofree char *options =3D NULL; + g_autoptr(virStorageAuthDef) authdef =3D NULL; + + /* optionally skip the "rbd:" prefix if provided */ + if (STRPREFIX(rbdstr, "rbd:")) + rbdstr +=3D strlen("rbd:"); + + src->path =3D g_strdup(rbdstr); + + p =3D strchr(src->path, ':'); + if (p) { + options =3D g_strdup(p + 1); + *p =3D '\0'; + } + + /* snapshot name */ + if ((p =3D strchr(src->path, '@'))) { + src->snapshot =3D g_strdup(p + 1); + *p =3D '\0'; + } + + /* pool vs. image name */ + if ((p =3D strchr(src->path, '/'))) { + src->volume =3D g_steal_pointer(&src->path); + src->path =3D g_strdup(p + 1); + *p =3D '\0'; + } + + /* options */ + if (!options) + return 0; /* all done */ + + p =3D options; + while (*p) { + /* find : delimiter or end of string */ + for (e =3D p; *e && *e !=3D ':'; ++e) { + if (*e =3D=3D '\\') { + e++; + if (*e =3D=3D '\0') + break; + } + } + if (*e =3D=3D '\0') { + next =3D e; /* last kv pair */ + } else { + next =3D e + 1; + *e =3D '\0'; + } + + if (STRPREFIX(p, "id=3D")) { + /* formulate authdef for src->auth */ + if (src->auth) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("duplicate 'id' found in '%s'"), src->pat= h); + return -1; + } + + authdef =3D g_new0(virStorageAuthDef, 1); + + authdef->username =3D g_strdup(p + strlen("id=3D")); + + authdef->secrettype =3D g_strdup(virSecretUsageTypeToString(VI= R_SECRET_USAGE_TYPE_CEPH)); + src->auth =3D g_steal_pointer(&authdef); + + /* Cannot formulate a secretType (eg, usage or uuid) given + * what is provided. + */ + } + if (STRPREFIX(p, "mon_host=3D")) { + char *h, *sep; + + h =3D p + strlen("mon_host=3D"); + while (h < e) { + for (sep =3D h; sep < e; ++sep) { + if (*sep =3D=3D '\\' && (sep[1] =3D=3D ',' || + sep[1] =3D=3D ';' || + sep[1] =3D=3D ' ')) { + *sep =3D '\0'; + sep +=3D 2; + break; + } + } + + if (virStorageSourceRBDAddHost(src, h) < 0) + return -1; + + h =3D sep; + } + } + + if (STRPREFIX(p, "conf=3D")) + src->configFile =3D g_strdup(p + strlen("conf=3D")); + + p =3D next; + } + return 0; +} + + +static int +virStorageSourceParseNBDColonString(const char *nbdstr, + virStorageSourcePtr src) +{ + g_autofree char *nbd =3D g_strdup(nbdstr); + char *export_name; + char *host_spec; + char *unixpath; + char *port; + + src->hosts =3D g_new0(virStorageNetHostDef, 1); + src->nhosts =3D 1; + + /* We extract the parameters in a similar way qemu does it */ + + /* format: [] denotes optional sections, uppercase are variable strings + * nbd:unix:/PATH/TO/SOCKET[:exportname=3DEXPORTNAME] + * nbd:HOSTNAME:PORT[:exportname=3DEXPORTNAME] + */ + + /* first look for ':exportname=3D' and cut it off */ + if ((export_name =3D strstr(nbd, ":exportname=3D"))) { + src->path =3D g_strdup(export_name + strlen(":exportname=3D")); + export_name[0] =3D '\0'; + } + + /* Verify the prefix and contents. Note that we require a + * "host_spec" part to be present. */ + if (!(host_spec =3D STRSKIP(nbd, "nbd:")) || host_spec[0] =3D=3D '\0') + goto malformed; + + if ((unixpath =3D STRSKIP(host_spec, "unix:"))) { + src->hosts->transport =3D VIR_STORAGE_NET_HOST_TRANS_UNIX; + + if (unixpath[0] =3D=3D '\0') + goto malformed; + + src->hosts->socket =3D g_strdup(unixpath); + } else { + src->hosts->transport =3D VIR_STORAGE_NET_HOST_TRANS_TCP; + + if (host_spec[0] =3D=3D ':') { + /* no host given */ + goto malformed; + } else if (host_spec[0] =3D=3D '[') { + host_spec++; + /* IPv6 addr */ + if (!(port =3D strstr(host_spec, "]:"))) + goto malformed; + + port[0] =3D '\0'; + port +=3D 2; + + if (host_spec[0] =3D=3D '\0') + goto malformed; + } else { + if (!(port =3D strchr(host_spec, ':'))) + goto malformed; + + port[0] =3D '\0'; + port++; + } + + if (virStringParsePort(port, &src->hosts->port) < 0) + return -1; + + src->hosts->name =3D g_strdup(host_spec); + } + + return 0; + + malformed: + virReportError(VIR_ERR_INTERNAL_ERROR, + _("malformed nbd string '%s'"), nbdstr); + return -1; +} + + +int +virStorageSourceParseBackingColon(virStorageSourcePtr src, + const char *path) +{ + const char *p; + g_autofree char *protocol =3D NULL; + + if (!(p =3D strchr(path, ':'))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("invalid backing protocol string '%s'"), + path); + return -1; + } + + protocol =3D g_strndup(path, p - path); + + if ((src->protocol =3D virStorageNetProtocolTypeFromString(protocol)) = < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("invalid backing protocol '%s'"), + protocol); + return -1; + } + + switch ((virStorageNetProtocol) src->protocol) { + case VIR_STORAGE_NET_PROTOCOL_NBD: + if (virStorageSourceParseNBDColonString(path, src) < 0) + return -1; + break; + + case VIR_STORAGE_NET_PROTOCOL_RBD: + if (virStorageSourceParseRBDColonString(path, src) < 0) + return -1; + break; + + case VIR_STORAGE_NET_PROTOCOL_SHEEPDOG: + case VIR_STORAGE_NET_PROTOCOL_LAST: + case VIR_STORAGE_NET_PROTOCOL_NONE: + virReportError(VIR_ERR_INTERNAL_ERROR, + _("backing store parser is not implemented for prot= ocol %s"), + protocol); + return -1; + + case VIR_STORAGE_NET_PROTOCOL_HTTP: + case VIR_STORAGE_NET_PROTOCOL_HTTPS: + case VIR_STORAGE_NET_PROTOCOL_FTP: + case VIR_STORAGE_NET_PROTOCOL_FTPS: + case VIR_STORAGE_NET_PROTOCOL_TFTP: + case VIR_STORAGE_NET_PROTOCOL_ISCSI: + case VIR_STORAGE_NET_PROTOCOL_GLUSTER: + case VIR_STORAGE_NET_PROTOCOL_SSH: + case VIR_STORAGE_NET_PROTOCOL_VXHS: + case VIR_STORAGE_NET_PROTOCOL_NFS: + virReportError(VIR_ERR_INTERNAL_ERROR, + _("malformed backing store path for protocol %s"), + protocol); + return -1; + } + + return 0; +} + + +static int +virStorageSourceParseBackingJSONInternal(virStorageSourcePtr src, + virJSONValuePtr json, + const char *jsonstr, + bool allowformat); + + +static int +virStorageSourceParseBackingJSONPath(virStorageSourcePtr src, + virJSONValuePtr json, + const char *jsonstr G_GNUC_UNUSED, + int type) +{ + const char *path; + + if (!(path =3D virJSONValueObjectGetString(json, "filename"))) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("missing 'filename' field in JSON backing volume " + "definition")); + return -1; + } + + src->path =3D g_strdup(path); + + src->type =3D type; + return 0; +} + + +static int +virStorageSourceParseBackingJSONUriStr(virStorageSourcePtr src, + const char *uri, + int protocol) +{ + int rc; + + if ((rc =3D virStorageSourceParseBackingURI(src, uri)) < 0) + return -1; + + if (src->protocol !=3D protocol) { + virReportError(VIR_ERR_INVALID_ARG, + _("expected protocol '%s' but got '%s' in URI JSON = volume " + "definition"), + virStorageNetProtocolTypeToString(protocol), + virStorageNetProtocolTypeToString(src->protocol)); + return -1; + } + + return rc; +} + + +static int +virStorageSourceParseBackingJSONUriCookies(virStorageSourcePtr src, + virJSONValuePtr json, + const char *jsonstr) +{ + const char *cookiestr; + g_auto(GStrv) cookies =3D NULL; + size_t ncookies =3D 0; + size_t i; + + if (!virJSONValueObjectHasKey(json, "cookie")) + return 0; + + if (!(cookiestr =3D virJSONValueObjectGetString(json, "cookie"))) { + virReportError(VIR_ERR_INVALID_ARG, + _("wrong format of 'cookie' field in backing store = definition '%s'"), + jsonstr); + return -1; + } + + if (!(cookies =3D virStringSplitCount(cookiestr, ";", 0, &ncookies))) + return -1; + + src->cookies =3D g_new0(virStorageNetCookieDefPtr, ncookies); + src->ncookies =3D ncookies; + + for (i =3D 0; i < ncookies; i++) { + char *cookiename =3D cookies[i]; + char *cookievalue; + + virSkipSpaces((const char **) &cookiename); + + if (!(cookievalue =3D strchr(cookiename, '=3D'))) { + virReportError(VIR_ERR_INVALID_ARG, + _("malformed http cookie '%s' in backing store = definition '%s'"), + cookies[i], jsonstr); + return -1; + } + + *cookievalue =3D '\0'; + cookievalue++; + + src->cookies[i] =3D g_new0(virStorageNetCookieDef, 1); + src->cookies[i]->name =3D g_strdup(cookiename); + src->cookies[i]->value =3D g_strdup(cookievalue); + } + + return 0; +} + + +static int +virStorageSourceParseBackingJSONUri(virStorageSourcePtr src, + virJSONValuePtr json, + const char *jsonstr, + int protocol) +{ + const char *uri; + + if (!(uri =3D virJSONValueObjectGetString(json, "url"))) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("missing 'url' in JSON backing volume definition"= )); + return -1; + } + + if (protocol =3D=3D VIR_STORAGE_NET_PROTOCOL_HTTPS || + protocol =3D=3D VIR_STORAGE_NET_PROTOCOL_FTPS) { + if (virJSONValueObjectHasKey(json, "sslverify")) { + const char *tmpstr; + bool tmp; + + /* libguestfs still uses undocumented legacy value of 'off' */ + if ((tmpstr =3D virJSONValueObjectGetString(json, "sslverify")= ) && + STREQ(tmpstr, "off")) { + src->sslverify =3D VIR_TRISTATE_BOOL_NO; + } else { + if (virJSONValueObjectGetBoolean(json, "sslverify", &tmp) = < 0) { + virReportError(VIR_ERR_INVALID_ARG, + _("malformed 'sslverify' field in backi= ng store definition '%s'"), + jsonstr); + return -1; + } + + src->sslverify =3D virTristateBoolFromBool(tmp); + } + } + } + + if (protocol =3D=3D VIR_STORAGE_NET_PROTOCOL_HTTPS || + protocol =3D=3D VIR_STORAGE_NET_PROTOCOL_HTTP) { + if (virStorageSourceParseBackingJSONUriCookies(src, json, jsonstr)= < 0) + return -1; + } + + if (virJSONValueObjectHasKey(json, "readahead") && + virJSONValueObjectGetNumberUlong(json, "readahead", &src->readahea= d) < 0) { + virReportError(VIR_ERR_INVALID_ARG, + _("malformed 'readahead' field in backing store def= inition '%s'"), + jsonstr); + return -1; + } + + if (virJSONValueObjectHasKey(json, "timeout") && + virJSONValueObjectGetNumberUlong(json, "timeout", &src->timeout) <= 0) { + virReportError(VIR_ERR_INVALID_ARG, + _("malformed 'timeout' field in backing store defin= ition '%s'"), + jsonstr); + return -1; + } + + return virStorageSourceParseBackingJSONUriStr(src, uri, protocol); +} + + +static int +virStorageSourceParseBackingJSONInetSocketAddress(virStorageNetHostDefPtr = host, + virJSONValuePtr json) +{ + const char *hostname; + const char *port; + + if (!json) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("missing remote server specification in JSON " + "backing volume definition")); + return -1; + } + + hostname =3D virJSONValueObjectGetString(json, "host"); + port =3D virJSONValueObjectGetString(json, "port"); + + if (!hostname) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("missing hostname for tcp backing server in " + "JSON backing volume definition")); + return -1; + } + + host->transport =3D VIR_STORAGE_NET_HOST_TRANS_TCP; + host->name =3D g_strdup(hostname); + + if (virStringParsePort(port, &host->port) < 0) + return -1; + + return 0; +} + + +static int +virStorageSourceParseBackingJSONSocketAddress(virStorageNetHostDefPtr host, + virJSONValuePtr json) +{ + const char *type; + const char *socket; + + if (!json) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("missing remote server specification in JSON " + "backing volume definition")); + return -1; + } + + if (!(type =3D virJSONValueObjectGetString(json, "type"))) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("missing socket address type in " + "JSON backing volume definition")); + return -1; + } + + if (STREQ(type, "tcp") || STREQ(type, "inet")) { + return virStorageSourceParseBackingJSONInetSocketAddress(host, jso= n); + + } else if (STREQ(type, "unix")) { + host->transport =3D VIR_STORAGE_NET_HOST_TRANS_UNIX; + + socket =3D virJSONValueObjectGetString(json, "path"); + + /* check for old spelling for gluster protocol */ + if (!socket) + socket =3D virJSONValueObjectGetString(json, "socket"); + + if (!socket) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("missing socket path for udp backing server i= n " + "JSON backing volume definition")); + return -1; + } + + host->socket =3D g_strdup(socket); + } else { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("backing store protocol '%s' is not yet supported= "), + type); + return -1; + } + + return 0; +} + + +static int +virStorageSourceParseBackingJSONGluster(virStorageSourcePtr src, + virJSONValuePtr json, + const char *jsonstr G_GNUC_UNUSED, + int opaque G_GNUC_UNUSED) +{ + const char *uri =3D virJSONValueObjectGetString(json, "filename"); + const char *volume =3D virJSONValueObjectGetString(json, "volume"); + const char *path =3D virJSONValueObjectGetString(json, "path"); + virJSONValuePtr server =3D virJSONValueObjectGetArray(json, "server"); + size_t nservers; + size_t i; + + /* legacy URI based syntax passed via 'filename' option */ + if (uri) + return virStorageSourceParseBackingJSONUriStr(src, uri, + VIR_STORAGE_NET_PROT= OCOL_GLUSTER); + + if (!volume || !path || !server) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("missing 'volume', 'path' or 'server' attribute i= n " + "JSON backing definition for gluster volume")); + return -1; + } + + src->type =3D VIR_STORAGE_TYPE_NETWORK; + src->protocol =3D VIR_STORAGE_NET_PROTOCOL_GLUSTER; + + src->volume =3D g_strdup(volume); + src->path =3D g_strdup(path); + + nservers =3D virJSONValueArraySize(server); + if (nservers =3D=3D 0) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("at least 1 server is necessary in " + "JSON backing definition for gluster volume")); + + return -1; + } + + src->hosts =3D g_new0(virStorageNetHostDef, nservers); + src->nhosts =3D nservers; + + for (i =3D 0; i < nservers; i++) { + if (virStorageSourceParseBackingJSONSocketAddress(src->hosts + i, + virJSONValueArra= yGet(server, i)) < 0) + return -1; + } + + return 0; +} + + +static int +virStorageSourceParseBackingJSONiSCSI(virStorageSourcePtr src, + virJSONValuePtr json, + const char *jsonstr G_GNUC_UNUSED, + int opaque G_GNUC_UNUSED) +{ + const char *transport =3D virJSONValueObjectGetString(json, "transport= "); + const char *portal =3D virJSONValueObjectGetString(json, "portal"); + const char *target =3D virJSONValueObjectGetString(json, "target"); + const char *lun =3D virJSONValueObjectGetStringOrNumber(json, "lun"); + const char *uri; + char *port; + + /* legacy URI based syntax passed via 'filename' option */ + if ((uri =3D virJSONValueObjectGetString(json, "filename"))) + return virStorageSourceParseBackingJSONUriStr(src, uri, + VIR_STORAGE_NET_PROT= OCOL_ISCSI); + + src->type =3D VIR_STORAGE_TYPE_NETWORK; + src->protocol =3D VIR_STORAGE_NET_PROTOCOL_ISCSI; + + if (!lun) + lun =3D "0"; + + src->hosts =3D g_new0(virStorageNetHostDef, 1); + src->nhosts =3D 1; + + if (STRNEQ_NULLABLE(transport, "tcp")) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("only TCP transport is supported for iSCSI volume= s")); + return -1; + } + + src->hosts->transport =3D VIR_STORAGE_NET_HOST_TRANS_TCP; + + if (!portal) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("missing 'portal' address in iSCSI backing defini= tion")); + return -1; + } + + if (!target) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("missing 'target' in iSCSI backing definition")); + return -1; + } + + src->hosts->name =3D g_strdup(portal); + + if ((port =3D strrchr(src->hosts->name, ':')) && + !strchr(port, ']')) { + if (virStringParsePort(port + 1, &src->hosts->port) < 0) + return -1; + + *port =3D '\0'; + } + + src->path =3D g_strdup_printf("%s/%s", target, lun); + + /* Libvirt doesn't handle inline authentication. Make the caller aware= . */ + if (virJSONValueObjectGetString(json, "user") || + virJSONValueObjectGetString(json, "password")) + return 1; + + return 0; +} + + +static int +virStorageSourceParseBackingJSONNbd(virStorageSourcePtr src, + virJSONValuePtr json, + const char *jsonstr G_GNUC_UNUSED, + int opaque G_GNUC_UNUSED) +{ + const char *path =3D virJSONValueObjectGetString(json, "path"); + const char *host =3D virJSONValueObjectGetString(json, "host"); + const char *port =3D virJSONValueObjectGetString(json, "port"); + const char *export =3D virJSONValueObjectGetString(json, "export"); + virJSONValuePtr server =3D virJSONValueObjectGetObject(json, "server"); + + if (!path && !host && !server) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("missing host specification of NBD server in JSON= " + "backing volume definition")); + return -1; + } + + src->type =3D VIR_STORAGE_TYPE_NETWORK; + src->protocol =3D VIR_STORAGE_NET_PROTOCOL_NBD; + + src->path =3D g_strdup(export); + + src->hosts =3D g_new0(virStorageNetHostDef, 1); + src->nhosts =3D 1; + + if (server) { + if (virStorageSourceParseBackingJSONSocketAddress(src->hosts, serv= er) < 0) + return -1; + } else { + if (path) { + src->hosts[0].transport =3D VIR_STORAGE_NET_HOST_TRANS_UNIX; + src->hosts[0].socket =3D g_strdup(path); + } else { + src->hosts[0].transport =3D VIR_STORAGE_NET_HOST_TRANS_TCP; + src->hosts[0].name =3D g_strdup(host); + + if (virStringParsePort(port, &src->hosts[0].port) < 0) + return -1; + } + } + + return 0; +} + + +static int +virStorageSourceParseBackingJSONSheepdog(virStorageSourcePtr src, + virJSONValuePtr json, + const char *jsonstr G_GNUC_UNUSED, + int opaque G_GNUC_UNUSED) +{ + const char *filename; + const char *vdi =3D virJSONValueObjectGetString(json, "vdi"); + virJSONValuePtr server =3D virJSONValueObjectGetObject(json, "server"); + + /* legacy URI based syntax passed via 'filename' option */ + if ((filename =3D virJSONValueObjectGetString(json, "filename"))) { + if (strstr(filename, "://")) + return virStorageSourceParseBackingJSONUriStr(src, filename, + VIR_STORAGE_NET_= PROTOCOL_SHEEPDOG); + + /* libvirt doesn't implement a parser for the legacy non-URI synta= x */ + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("missing sheepdog URI in JSON backing volume defi= nition")); + return -1; + } + + src->type =3D VIR_STORAGE_TYPE_NETWORK; + src->protocol =3D VIR_STORAGE_NET_PROTOCOL_SHEEPDOG; + + if (!vdi) { + virReportError(VIR_ERR_INVALID_ARG, "%s", _("missing sheepdog vdi = name")); + return -1; + } + + src->path =3D g_strdup(vdi); + + src->hosts =3D g_new0(virStorageNetHostDef, 1); + src->nhosts =3D 1; + + if (virStorageSourceParseBackingJSONSocketAddress(src->hosts, server) = < 0) + return -1; + + return 0; +} + + +static int +virStorageSourceParseBackingJSONSSH(virStorageSourcePtr src, + virJSONValuePtr json, + const char *jsonstr G_GNUC_UNUSED, + int opaque G_GNUC_UNUSED) +{ + const char *path =3D virJSONValueObjectGetString(json, "path"); + const char *host =3D virJSONValueObjectGetString(json, "host"); + const char *port =3D virJSONValueObjectGetString(json, "port"); + const char *user =3D virJSONValueObjectGetString(json, "user"); + const char *host_key_check =3D virJSONValueObjectGetString(json, "host= _key_check"); + virJSONValuePtr server =3D virJSONValueObjectGetObject(json, "server"); + + if (!(host || server) || !path) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("missing host/server or path of SSH JSON backing " + "volume definition")); + return -1; + } + + src->type =3D VIR_STORAGE_TYPE_NETWORK; + src->protocol =3D VIR_STORAGE_NET_PROTOCOL_SSH; + + src->path =3D g_strdup(path); + + src->hosts =3D g_new0(virStorageNetHostDef, 1); + src->nhosts =3D 1; + + if (server) { + if (virStorageSourceParseBackingJSONInetSocketAddress(src->hosts, + server) < 0) + return -1; + } else { + src->hosts[0].transport =3D VIR_STORAGE_NET_HOST_TRANS_TCP; + src->hosts[0].name =3D g_strdup(host); + + if (virStringParsePort(port, &src->hosts[0].port) < 0) + return -1; + } + + /* these two are parsed just to be passed back as we don't model them = yet */ + src->ssh_user =3D g_strdup(user); + if (STREQ_NULLABLE(host_key_check, "no")) + src->ssh_host_key_check_disabled =3D true; + + return 0; +} + + +static int +virStorageSourceParseBackingJSONRBD(virStorageSourcePtr src, + virJSONValuePtr json, + const char *jsonstr G_GNUC_UNUSED, + int opaque G_GNUC_UNUSED) +{ + const char *filename; + const char *pool =3D virJSONValueObjectGetString(json, "pool"); + const char *image =3D virJSONValueObjectGetString(json, "image"); + const char *conf =3D virJSONValueObjectGetString(json, "conf"); + const char *snapshot =3D virJSONValueObjectGetString(json, "snapshot"); + virJSONValuePtr servers =3D virJSONValueObjectGetArray(json, "server"); + size_t nservers; + size_t i; + + src->type =3D VIR_STORAGE_TYPE_NETWORK; + src->protocol =3D VIR_STORAGE_NET_PROTOCOL_RBD; + + /* legacy syntax passed via 'filename' option */ + if ((filename =3D virJSONValueObjectGetString(json, "filename"))) + return virStorageSourceParseRBDColonString(filename, src); + + if (!pool || !image) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("missing pool or image name in ceph backing volum= e " + "JSON specification")); + return -1; + } + + src->volume =3D g_strdup(pool); + src->path =3D g_strdup(image); + src->snapshot =3D g_strdup(snapshot); + src->configFile =3D g_strdup(conf); + + if (servers) { + nservers =3D virJSONValueArraySize(servers); + + src->hosts =3D g_new0(virStorageNetHostDef, nservers); + src->nhosts =3D nservers; + + for (i =3D 0; i < nservers; i++) { + if (virStorageSourceParseBackingJSONInetSocketAddress(src->hos= ts + i, + virJSONV= alueArrayGet(servers, i)) < 0) + return -1; + } + } + + return 0; +} + +static int +virStorageSourceParseBackingJSONRaw(virStorageSourcePtr src, + virJSONValuePtr json, + const char *jsonstr, + int opaque G_GNUC_UNUSED) +{ + bool has_offset =3D virJSONValueObjectHasKey(json, "offset"); + bool has_size =3D virJSONValueObjectHasKey(json, "size"); + virJSONValuePtr file; + + if (has_offset || has_size) { + src->sliceStorage =3D g_new0(virStorageSourceSlice, 1); + + if (has_offset && + virJSONValueObjectGetNumberUlong(json, "offset", &src->sliceSt= orage->offset) < 0) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("malformed 'offset' property of 'raw' driver"= )); + return -1; + } + + if (has_size && + virJSONValueObjectGetNumberUlong(json, "size", &src->sliceStor= age->size) < 0) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("malformed 'size' property of 'raw' driver")); + return -1; + } + } + + /* 'raw' is a format driver so it can have protocol driver children */ + if (!(file =3D virJSONValueObjectGetObject(json, "file"))) { + virReportError(VIR_ERR_INVALID_ARG, + _("JSON backing volume definition '%s' lacks 'file'= object"), + jsonstr); + return -1; + } + + return virStorageSourceParseBackingJSONInternal(src, file, jsonstr, fa= lse); +} + + +static int +virStorageSourceParseBackingJSONVxHS(virStorageSourcePtr src, + virJSONValuePtr json, + const char *jsonstr G_GNUC_UNUSED, + int opaque G_GNUC_UNUSED) +{ + const char *vdisk_id =3D virJSONValueObjectGetString(json, "vdisk-id"); + virJSONValuePtr server =3D virJSONValueObjectGetObject(json, "server"); + + if (!vdisk_id || !server) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("missing 'vdisk-id' or 'server' attribute in " + "JSON backing definition for VxHS volume")); + return -1; + } + + src->type =3D VIR_STORAGE_TYPE_NETWORK; + src->protocol =3D VIR_STORAGE_NET_PROTOCOL_VXHS; + + src->path =3D g_strdup(vdisk_id); + + src->hosts =3D g_new0(virStorageNetHostDef, 1); + src->nhosts =3D 1; + + if (virStorageSourceParseBackingJSONInetSocketAddress(src->hosts, + server) < 0) + return -1; + + return 0; +} + + +static int +virStorageSourceParseBackingJSONNFS(virStorageSourcePtr src, + virJSONValuePtr json, + const char *jsonstr G_GNUC_UNUSED, + int opaque G_GNUC_UNUSED) +{ + virJSONValuePtr server =3D virJSONValueObjectGetObject(json, "server"); + int uidStore =3D -1; + int gidStore =3D -1; + int gotUID =3D virJSONValueObjectGetNumberInt(json, "user", &uidStore); + int gotGID =3D virJSONValueObjectGetNumberInt(json, "group", &gidStore= ); + + if (!server) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("missing 'server' attribute in JSON backing defin= ition for NFS volume")); + return -1; + } + + if (gotUID < 0 || gotGID < 0) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("missing 'user' or 'group' attribute in JSON back= ing definition for NFS volume")); + return -1; + } + + src->path =3D g_strdup(virJSONValueObjectGetString(json, "path")); + if (!src->path) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("missing 'path' attribute in JSON backing definit= ion for NFS volume")); + return -1; + } + + src->nfs_user =3D g_strdup_printf("+%d", uidStore); + src->nfs_group =3D g_strdup_printf("+%d", gidStore); + + src->type =3D VIR_STORAGE_TYPE_NETWORK; + src->protocol =3D VIR_STORAGE_NET_PROTOCOL_NFS; + + src->hosts =3D g_new0(virStorageNetHostDef, 1); + src->nhosts =3D 1; + + if (virStorageSourceParseBackingJSONInetSocketAddress(src->hosts, + server) < 0) + return -1; + + return 0; +} + + +static int +virStorageSourceParseBackingJSONNVMe(virStorageSourcePtr src, + virJSONValuePtr json, + const char *jsonstr G_GNUC_UNUSED, + int opaque G_GNUC_UNUSED) +{ + g_autoptr(virStorageSourceNVMeDef) nvme =3D g_new0(virStorageSourceNVM= eDef, 1); + const char *device =3D virJSONValueObjectGetString(json, "device"); + + if (!device || virPCIDeviceAddressParse((char *) device, &nvme->pciAdd= r) < 0) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("missing or malformed 'device' field of 'nvme' st= orage")); + return -1; + } + + if (virJSONValueObjectGetNumberUlong(json, "namespace", &nvme->namespc= ) < 0 || + nvme->namespc =3D=3D 0) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("missing or malformed 'namespace' field of 'nvme'= storage")); + return -1; + } + + src->type =3D VIR_STORAGE_TYPE_NVME; + src->nvme =3D g_steal_pointer(&nvme); + + return 0; +} + + +struct virStorageSourceJSONDriverParser { + const char *drvname; + bool formatdriver; + /** + * The callback gets a pre-allocated storage source @src and the JSON + * object to parse. The callback shall return -1 on error and report e= rror + * 0 on success and 1 in cases when the configuration itself is valid,= but + * can't be converted to libvirt's configuration (e.g. inline authenti= cation + * credentials are present). + */ + int (*func)(virStorageSourcePtr src, virJSONValuePtr json, const char = *jsonstr, int opaque); + int opaque; +}; + +static const struct virStorageSourceJSONDriverParser jsonParsers[] =3D { + {"file", false, virStorageSourceParseBackingJSONPath, VIR_STORAGE_TYPE= _FILE}, + {"host_device", false, virStorageSourceParseBackingJSONPath, VIR_STORA= GE_TYPE_BLOCK}, + {"host_cdrom", false, virStorageSourceParseBackingJSONPath, VIR_STORAG= E_TYPE_BLOCK}, + {"http", false, virStorageSourceParseBackingJSONUri, VIR_STORAGE_NET_P= ROTOCOL_HTTP}, + {"https", false, virStorageSourceParseBackingJSONUri, VIR_STORAGE_NET_= PROTOCOL_HTTPS}, + {"ftp", false, virStorageSourceParseBackingJSONUri, VIR_STORAGE_NET_PR= OTOCOL_FTP}, + {"ftps", false, virStorageSourceParseBackingJSONUri, VIR_STORAGE_NET_P= ROTOCOL_FTPS}, + {"tftp", false, virStorageSourceParseBackingJSONUri, VIR_STORAGE_NET_P= ROTOCOL_TFTP}, + {"gluster", false, virStorageSourceParseBackingJSONGluster, 0}, + {"iscsi", false, virStorageSourceParseBackingJSONiSCSI, 0}, + {"nbd", false, virStorageSourceParseBackingJSONNbd, 0}, + {"sheepdog", false, virStorageSourceParseBackingJSONSheepdog, 0}, + {"ssh", false, virStorageSourceParseBackingJSONSSH, 0}, + {"rbd", false, virStorageSourceParseBackingJSONRBD, 0}, + {"raw", true, virStorageSourceParseBackingJSONRaw, 0}, + {"nfs", false, virStorageSourceParseBackingJSONNFS, 0}, + {"vxhs", false, virStorageSourceParseBackingJSONVxHS, 0}, + {"nvme", false, virStorageSourceParseBackingJSONNVMe, 0}, +}; + + + +static int +virStorageSourceParseBackingJSONInternal(virStorageSourcePtr src, + virJSONValuePtr json, + const char *jsonstr, + bool allowformat) +{ + const char *drvname; + size_t i; + + if (!(drvname =3D virJSONValueObjectGetString(json, "driver"))) { + virReportError(VIR_ERR_INVALID_ARG, + _("JSON backing volume definition '%s' lacks driver= name"), + jsonstr); + return -1; + } + + for (i =3D 0; i < G_N_ELEMENTS(jsonParsers); i++) { + if (STRNEQ(drvname, jsonParsers[i].drvname)) + continue; + + if (jsonParsers[i].formatdriver && !allowformat) { + virReportError(VIR_ERR_INVALID_ARG, + _("JSON backing volume definition '%s' must not= have nested format drivers"), + jsonstr); + return -1; + } + + return jsonParsers[i].func(src, json, jsonstr, jsonParsers[i].opaq= ue); + } + + virReportError(VIR_ERR_INTERNAL_ERROR, + _("missing parser implementation for JSON backing volum= e " + "driver '%s'"), drvname); + return -1; +} + + +int +virStorageSourceParseBackingJSON(virStorageSourcePtr src, + const char *json) +{ + g_autoptr(virJSONValue) root =3D NULL; + g_autoptr(virJSONValue) deflattened =3D NULL; + virJSONValuePtr file =3D NULL; + + if (!(root =3D virJSONValueFromString(json))) + return -1; + + if (!(deflattened =3D virJSONValueObjectDeflatten(root))) + return -1; + + /* There are 2 possible syntaxes: + * 1) json:{"file":{"driver":...}} + * 2) json:{"driver":...} + * Remove the 'file' wrapper object in case 1. + */ + if (!virJSONValueObjectHasKey(deflattened, "driver")) + file =3D virJSONValueObjectGetObject(deflattened, "file"); + + if (!file) + file =3D deflattened; + + return virStorageSourceParseBackingJSONInternal(src, file, json, true); +} diff --git a/src/storage_file/storage_source_backingstore.h b/src/storage_f= ile/storage_source_backingstore.h new file mode 100644 index 0000000000..e51063e9e2 --- /dev/null +++ b/src/storage_file/storage_source_backingstore.h @@ -0,0 +1,40 @@ +/* + * storage_source_backingstore.h: helpers for parsing backing store strings + * + * Copyright (C) 2007-2009, 2012-2016 Red Hat, Inc. + * Copyright (C) 2007-2008 Daniel P. Berrange + * + * 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 + * . + */ + +#pragma once + +#include "storage_source_conf.h" + +int +virStorageSourceParseBackingURI(virStorageSourcePtr src, + const char *uristr); + +int +virStorageSourceParseRBDColonString(const char *rbdstr, + virStorageSourcePtr src); + +int +virStorageSourceParseBackingColon(virStorageSourcePtr src, + const char *path); + +int +virStorageSourceParseBackingJSON(virStorageSourcePtr src, + const char *json); --=20 2.29.2 From nobody Tue May 7 18:46:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1611590760; cv=none; d=zohomail.com; s=zohoarc; b=aJdcOUI5uDMnUAuGt4VlKLH2bez4gQQFf77JDvLcMn/wSq5mGv1+Fq+v/XNruudPKJbSVTzryFvDvorizI9EJ4smo8LXndOKVjsimCNEM9dGumw+lXDRwQUrXZMKzR9hxBhIR54DD3Le60ovayNlbfwiH48uVksGwBeWoRg/PCA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611590760; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=GkdHP0/qVQIZkAPMf1NuExvd/TfnQxmLokrjCyIULzI=; b=k4z0TvDn1YiZM/yEHNLz5luZslFCAjEH1iPcInFPW75Q2bRiL1+ddZyiSezNcr6+2O0aFBFurh8Y409QWeKJfs/07Nq9rRb2tXikVarUQzLRuAI4p+H/6Iypx+lq1QZ/Fd7/Nya8qwgljKHuMfSpw/8h43JSnQv2tJ0yqufk30g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1611590760689933.3952210717728; Mon, 25 Jan 2021 08:06:00 -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-388-4Wcc65lcPjG6fl3MXYOGJw-1; Mon, 25 Jan 2021 11:05:55 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 31704107ACF8; Mon, 25 Jan 2021 16:05:48 +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 10EC45C1C5; Mon, 25 Jan 2021 16:05:48 +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 CA23D1809CA6; Mon, 25 Jan 2021 16:05:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 10PG5Z5b018237 for ; Mon, 25 Jan 2021 11:05:35 -0500 Received: by smtp.corp.redhat.com (Postfix) id ED0945D9DC; Mon, 25 Jan 2021 16:05:35 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 258635D9DB for ; Mon, 25 Jan 2021 16:05:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611590759; 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=GkdHP0/qVQIZkAPMf1NuExvd/TfnQxmLokrjCyIULzI=; b=XlmjUUgDJrZKPbqzp/pD2MoxJfzezOOVYsRVpiv30SoIzLxTZmUHvPmwdjHAZj5+dRRhqD lYd1Y3yWYQ6zz8wRD53Dq+5Gd/BXcTtRh3LXTxBfCFXKXe81sIJPkvTq8tJEyIVoW0AF8E hq313k3aXLjGieemtIVutw8ioCUxFsc= X-MC-Unique: 4Wcc65lcPjG6fl3MXYOGJw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 05/12] virStorageSourceGetMetadata: Refactor cleanup Date: Mon, 25 Jan 2021 17:05:17 +0100 Message-Id: <31928faf8f72b451d5ea0a8ae643dc18e8d8cb2c.1611590679.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com 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" Use g_autoptr for the hash table and remove the 'ret' variable. Signed-off-by: Peter Krempa Reviewed-by: Pavel Hrdina --- src/storage_file/storage_source.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/storage_file/storage_source.c b/src/storage_file/storage_s= ource.c index 9d3761f5bd..51f97b13ef 100644 --- a/src/storage_file/storage_source.c +++ b/src/storage_file/storage_source.c @@ -1421,17 +1421,13 @@ virStorageSourceGetMetadata(virStorageSourcePtr src, uid_t uid, gid_t gid, bool report_broken) { - GHashTable *cycle =3D NULL; + g_autoptr(GHashTable) cycle =3D virHashNew(NULL); virStorageType actualType =3D virStorageSourceGetActualType(src); - int ret =3D -1; VIR_DEBUG("path=3D%s format=3D%d uid=3D%u gid=3D%u report_broken=3D%d", src->path, src->format, (unsigned int)uid, (unsigned int)gid, report_broken); - if (!(cycle =3D virHashNew(NULL))) - return -1; - if (src->format <=3D VIR_STORAGE_FILE_NONE) { if (actualType =3D=3D VIR_STORAGE_TYPE_DIR) src->format =3D VIR_STORAGE_FILE_DIR; @@ -1439,9 +1435,6 @@ virStorageSourceGetMetadata(virStorageSourcePtr src, src->format =3D VIR_STORAGE_FILE_RAW; } - ret =3D virStorageSourceGetMetadataRecurse(src, src, uid, gid, - report_broken, cycle, 1); - - virHashFree(cycle); - return ret; + return virStorageSourceGetMetadataRecurse(src, src, uid, gid, + report_broken, cycle, 1); } --=20 2.29.2 From nobody Tue May 7 18:46:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1611590827; cv=none; d=zohomail.com; s=zohoarc; b=EGnaYvaaJTLwzaGbd+T1p4QNsL+6lzJPXXPkpSpOvA4WZU4+l+lwFIZ4//XNQg5u4+6w9f7pLx7g04mvUe5qrATu7M4JMbUqXEQovAQHxrG8kD04i3g/sAY+elbPVbuQ9r860rztAbnewgwtUXUuQV6GboIGBB1VsMLGpqk5s5s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611590827; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=BvCFsDvIom7+4sFDJQhJ2zKQx16QQd1j0lgHEbhwlk0=; b=IhJPtC60SW6GVlgxUIGz+dGk+UCcHUAyscdBypvHaM9EVogqhfRiw6LUjQxx1Xg3Dn87MtR81L0O/Hf5XoCwPlJ5+p+4OVhQpxiLtvL/8/dE294kimBgRgrPt+eLSEEyNlwN43uAVvc/jT6C5zgIYdfJLHv0rPmJAVpvS6Ry1Ps= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1611590827829779.7398402948428; Mon, 25 Jan 2021 08:07: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-470-lL9hz5iIMfeUNpZFnrdExg-1; Mon, 25 Jan 2021 11:06:01 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 26C8C84E246; Mon, 25 Jan 2021 16:05:51 +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 0424B7086D; Mon, 25 Jan 2021 16:05:51 +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 BF35050035; Mon, 25 Jan 2021 16:05:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 10PG5b9M018244 for ; Mon, 25 Jan 2021 11:05:37 -0500 Received: by smtp.corp.redhat.com (Postfix) id 0E6C95D9DB; Mon, 25 Jan 2021 16:05:37 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5F55B5D9DC for ; Mon, 25 Jan 2021 16:05:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611590826; 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=BvCFsDvIom7+4sFDJQhJ2zKQx16QQd1j0lgHEbhwlk0=; b=KwMyM3YOjYIrdj8a+ZkGlORTUFeDfTjh/AvbszWkf5p2+bDUCBztlDieDWzQrKnkOL0EYV CqEPyRhkDvh1yzfaKtrjsk85c3XYdTe3LAOtCKZe/+lPUcFUqyum1OIVREkRs86Oj1Ls/K P08uHMZ3ugKEAECQ5xpZoklSGE/UOEY= X-MC-Unique: lL9hz5iIMfeUNpZFnrdExg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 06/12] virt-aa-helper: Use proper check for empty disk in 'get_files' Date: Mon, 25 Jan 2021 17:05:18 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com 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" 'virDomainDiskGetSource' returns src->path effectively. Checking whether a disk is empty is done via 'virStorageSourceIsEmpty'. Signed-off-by: Peter Krempa Reviewed-by: Pavel Hrdina --- src/security/virt-aa-helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index f71fe6f23b..d3abe37a8c 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -933,7 +933,7 @@ get_files(vahControl * ctl) for (i =3D 0; i < ctl->def->ndisks; i++) { virDomainDiskDefPtr disk =3D ctl->def->disks[i]; - if (!virDomainDiskGetSource(disk)) + if (virStorageSourceIsEmpty(disk->src)) continue; /* XXX - if we knew the qemu user:group here we could send it in * so that the open could be re-tried as that user:group. --=20 2.29.2 From nobody Tue May 7 18:46:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1611590761; cv=none; d=zohomail.com; s=zohoarc; b=ERpnzwugAa853nFKRhe/kZcebWD0F3bD2cPxPU0UXlvcul2Z0pLJT+Wub3rXGboXOdAkM+I+fXOrEfBDd6QEuI3p67Yi2eOCEqraDfw8B+Ra7BDzYzCXN1xejLJSft1oYKPa/p9Hzml2fPMXbIQ/E3agk03IROtWnppYXOs6uIQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611590761; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=YMzSMmND8ylD3sBJcb8cNRtYBOUPiy+doDsdZ6UpMdU=; b=YzJKRMsc/7FuGQpXGh7PJWKiNCp7JCDz2ejEqk91ZXyn8beAWGtMaWYCJ4GEb+HsxpDpo+JJptUorQw5qcq+3ulEovxMPDxO6YLj9kqfqN6QvGFTVIcLC89+lqtl2Iu4Qyr7/t0iy6qGtjiXKSK6264cTnnxEn8ahf69lWSre/A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1611590761073809.3535969187566; Mon, 25 Jan 2021 08:06:01 -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-116-l2C7L621M2ygV5h6dqYddw-1; Mon, 25 Jan 2021 11:05:54 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 63CD9107ACF9; Mon, 25 Jan 2021 16:05:48 +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 40F6B5F9AC; Mon, 25 Jan 2021 16:05:48 +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 F014F4BB7B; Mon, 25 Jan 2021 16:05:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 10PG5cE9018266 for ; Mon, 25 Jan 2021 11:05:38 -0500 Received: by smtp.corp.redhat.com (Postfix) id 5C6315D9DE; Mon, 25 Jan 2021 16:05:38 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8C3D55D9DB for ; Mon, 25 Jan 2021 16:05:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611590760; 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=YMzSMmND8ylD3sBJcb8cNRtYBOUPiy+doDsdZ6UpMdU=; b=eqClgtH5g0zfswNvZBnuzg1dDjHM2lOI+y+V+jN8R3qQJfEdCaObN/V9HaRvlmcRHGSRx7 LlkI8BcKW4GFgF17LqWj67ugRk5gRPnM6XXVFjou/6rAKtR/mOJcTrLR3uDyi0BbCD5e7+ yknEQdsiLZ9iA+jjbdgGFfs7HElw6kQ= X-MC-Unique: l2C7L621M2ygV5h6dqYddw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 07/12] virt-aa-helper: Don't probe image metadata for terminated chains Date: Mon, 25 Jan 2021 17:05:19 +0100 Message-Id: <5eefadaa094b3bd862b096c5665982c8f7278f47.1611590679.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com 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" A terminated chain has a virStorageSource with type =3D=3D VIR_STORAGE_TYPE_NONE at the end. Since virStorageSourceHasBacking is explicitly returning false in that case we'd probe the chain needlessly. Just check whether src->backingStore is non-NULL. Signed-off-by: Peter Krempa Reviewed-by: Pavel Hrdina --- src/security/virt-aa-helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index d3abe37a8c..d33bacde5d 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -938,7 +938,7 @@ get_files(vahControl * ctl) /* XXX - if we knew the qemu user:group here we could send it in * so that the open could be re-tried as that user:group. */ - if (!virStorageSourceHasBacking(disk->src)) + if (!disk->src->backingStore) virStorageSourceGetMetadata(disk->src, -1, -1, false); /* XXX should handle open errors more careful than just ignoring = them. --=20 2.29.2 From nobody Tue May 7 18:46:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1611590765; cv=none; d=zohomail.com; s=zohoarc; b=Jgyk9ovrpD51KvNJ7LBvWMzGpRrfqxneMTd+Ro7KKHmjg6pVhshydGlOPq75azLjPK9aAjIzqC8Ip6NmXkN44+j/biI14TIdglKv9k4/Nhd2cJIEJCrgI/UbIqZYlNape1oHhg+pEEGu3eauKVRTCuyDiPM+SkEm37v/s7V2DTE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611590765; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=N20/5kpCrTk5Gsa0vX91LgtNQnK3wF9oEy+fTA9oDEk=; b=Vkc8FvVBDLk8N4QKRBerX3fLG3fg2zvbke0TpNCCFujpEXzEamND0toXd6b9ArQvOPbeIhz9T08Qh1hieeWextqxDs5uw9K1zZfms9xMf23Rj2kUZUCnY9N082A8fIvfUX9zjRRt1wQcLQ5089yBGUm+rcqexlb7GsGETJ1BvDk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1611590765820591.253630218043; Mon, 25 Jan 2021 08:06: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-159-DVd9kw3-MSKYIsBm27x7pQ-1; Mon, 25 Jan 2021 11:06:01 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4AD08100E321; Mon, 25 Jan 2021 16:05:51 +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 291706F996; Mon, 25 Jan 2021 16:05:51 +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 E5BCD50036; Mon, 25 Jan 2021 16:05:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 10PG5d0x018279 for ; Mon, 25 Jan 2021 11:05:39 -0500 Received: by smtp.corp.redhat.com (Postfix) id 6DC095D9DC; Mon, 25 Jan 2021 16:05:39 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id BB06D5D9DB for ; Mon, 25 Jan 2021 16:05:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611590764; 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=N20/5kpCrTk5Gsa0vX91LgtNQnK3wF9oEy+fTA9oDEk=; b=IX/GwZTZYoJg315WzoBcqNKWeXENtlvZQ3V3FeI676U3dtfSkiH1RcsyP8MRAi4og9xpGt 8QhOEXZYp21xNGX15esMmgEUpmrI2EOAK6anE/+1fM3L1kPvIQ3SPykgU1sfxySlL+8+Dc hkzQ/1hPPbxc367ocxlDS22llxqzkzo= X-MC-Unique: DVd9kw3-MSKYIsBm27x7pQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 08/12] virStorageSourceChainLookup: Don't break error message strings Date: Mon, 25 Jan 2021 17:05:20 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com 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" Put them on one line for greppability. Signed-off-by: Peter Krempa Reviewed-by: Pavel Hrdina --- src/storage_file/storage_source.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/storage_file/storage_source.c b/src/storage_file/storage_s= ource.c index 51f97b13ef..52edb91112 100644 --- a/src/storage_file/storage_source.c +++ b/src/storage_file/storage_source.c @@ -276,15 +276,13 @@ virStorageSourceChainLookup(virStorageSourcePtr chain, error: if (idx) { virReportError(VIR_ERR_INVALID_ARG, - _("could not find backing store index %u in chain " - "for '%s'"), + _("could not find backing store index '%u' in chain= for '%s'"), idx, NULLSTR(start)); } else if (name) { if (startFrom) virReportError(VIR_ERR_INVALID_ARG, - _("could not find image '%s' beneath '%s' in " - "chain for '%s'"), name, NULLSTR(startFrom->p= ath), - NULLSTR(start)); + _("could not find image '%s' beneath '%s' in ch= ain for '%s'"), + name, NULLSTR(startFrom->path), NULLSTR(start)); else virReportError(VIR_ERR_INVALID_ARG, _("could not find image '%s' in chain for '%s'"= ), --=20 2.29.2 From nobody Tue May 7 18:46:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1611590765; cv=none; d=zohomail.com; s=zohoarc; b=jS0v2RJPBX2kFMZ/yHUufiH7M/uYoS7Vpz8s24sRncuR18g8LUSCAMtagQ6vO/KJkT8G6pBtH/dXoNHcCYiOV4s8RL344ZFp5DRJwpZPOO5Slngq62RFaBMyy8Fjcp3wpPbWkpNVRnx2w4mZ3kU7Tez2ViQnILHB5cH0ppJgtA4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611590765; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=9XRloNB+gX/7QF7mexNbhAGaCdH+4UMd3wqeGhaKKhA=; b=cl4xMsM8Ji02vAKS/AsmHQqDiQ6g8QMRq318znc+sfmciDP7400aSeX9Iy53Qrodxg17n4YKQu2Al4qIxBl0sIBjKWGf2gQQp+P/f4DUZjDSlFyAqMGvm8TwkWUuWPXfHXyFVKptjK6w9PNudL1PClVPdHxz57hTgmBQ/qCm3Gw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1611590765727235.50226558548445; Mon, 25 Jan 2021 08:06: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-324-hChn-du8NUG2xWsPXZ2HNg-1; Mon, 25 Jan 2021 11:06:02 -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 78BB6803625; Mon, 25 Jan 2021 16:05:56 +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 5553060C47; Mon, 25 Jan 2021 16:05:56 +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 DB6DD1809CAD; Mon, 25 Jan 2021 16:05:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 10PG5eXk018293 for ; Mon, 25 Jan 2021 11:05:40 -0500 Received: by smtp.corp.redhat.com (Postfix) id 9FC095D9DC; Mon, 25 Jan 2021 16:05:40 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id E229C5D9DB for ; Mon, 25 Jan 2021 16:05:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611590764; 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=9XRloNB+gX/7QF7mexNbhAGaCdH+4UMd3wqeGhaKKhA=; b=PjoZk3bAa4agP7Qan0mr19O5XnW73Rs98L0p5llh4hk0fI/g0ClWRkXZdSzeZtxafmqANv aDImAjlDx4GQDNeE+PCfPMFi0/ipgccn9ILP+2/ku5bt1hdTMsToDLU7GUHWnE+ReqNoJC aJnHw/rXRFG1CkvoVEHVBe1Xivx7Jfw= X-MC-Unique: hChn-du8NUG2xWsPXZ2HNg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 09/12] test: storage: Remove double testing in testStorageLookup Date: Mon, 25 Jan 2021 17:05:21 +0100 Message-Id: <5c2c27dc3c76a109417d526ef06779f0b0369be7.1611590679.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com 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 function attempts two calls to virStorageSourceChainLookup to see whether the function handles NULL correctly. This isn't very useful and additionally upcoming patch will remove the 'idx' parameter thus the test becomes obsolete. Remove it. Signed-off-by: Peter Krempa Reviewed-by: Pavel Hrdina --- tests/virstoragetest.c | 34 ++-------------------------------- 1 file changed, 2 insertions(+), 32 deletions(-) diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c index 0e168ce730..99007dd662 100644 --- a/tests/virstoragetest.c +++ b/tests/virstoragetest.c @@ -365,36 +365,6 @@ testStorageLookup(const void *args) ret =3D -1; } - /* Test twice to ensure optional parameter doesn't cause NULL deref. = */ - result =3D virStorageSourceChainLookup(data->chain, data->from, - idx ? NULL : data->name, - idx, NULL); - - if (!data->expResult) { - if (virGetLastErrorCode() =3D=3D VIR_ERR_OK) { - fprintf(stderr, "call should have failed\n"); - ret =3D -1; - } - virResetLastError(); - } else { - if (virGetLastErrorCode()) { - fprintf(stderr, "call should not have warned\n"); - ret =3D -1; - } - } - - if (!result) { - if (data->expResult) { - fprintf(stderr, "result 1: expected %s, got NULL\n", - data->expResult); - ret =3D -1; - } - } else if (STRNEQ_NULLABLE(data->expResult, result->path)) { - fprintf(stderr, "result 1: expected %s, got %s\n", - NULLSTR(data->expResult), NULLSTR(result->path)); - ret =3D -1; - } - result =3D virStorageSourceChainLookup(data->chain, data->from, data->name, idx, &actualParent); if (!data->expResult) @@ -402,12 +372,12 @@ testStorageLookup(const void *args) if (!result) { if (data->expResult) { - fprintf(stderr, "result 2: expected %s, got NULL\n", + fprintf(stderr, "result: expected %s, got NULL\n", data->expResult); ret =3D -1; } } else if (STRNEQ_NULLABLE(data->expResult, result->path)) { - fprintf(stderr, "result 2: expected %s, got %s\n", + fprintf(stderr, "result: expected %s, got %s\n", NULLSTR(data->expResult), NULLSTR(result->path)); ret =3D -1; } --=20 2.29.2 From nobody Tue May 7 18:46:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1611590757; cv=none; d=zohomail.com; s=zohoarc; b=TXB6thpnIt7pmXLa60BYVFApeyO/zM6GUyg2G/wU9PlttiNQRrIrFiHGwmq4a7yVJ8J/oSa9T9dGBuaL30nMPhqDjDSBasD/ySBXaiQ52iK/avpfSln4DnNQrRzONWHHiY9gtXxkgKmbdPB8hHlAK64Wy9fsZPqys0D9F0cnF9A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611590757; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=7ZD1JFcAKSF51TnonKxKdcFAYukgCUGdDBfaR1zJop8=; b=nEa0OTgPYB1OHIk7Mm/XV6k9U3kp4jD1i4aAOd0oqrBWkdgs+URpSWxXpibqy8ff0RxU/R/HJSzYAyiy5h/rQTdIr4+/YZtOuKnfEVxbO9eQtaoLWkSAEoHjhJPkHLulitsJ7RSqubjxPrKtO7MywjuKp5RnBDnTjVW8KYqMnxE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1611590757450481.65896065733875; Mon, 25 Jan 2021 08:05:57 -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-142-4u6BovnnMTacFsgOnWyFdg-1; Mon, 25 Jan 2021 11:05:51 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 22FC1AFA81; Mon, 25 Jan 2021 16:05:45 +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 F32655D72F; Mon, 25 Jan 2021 16:05:44 +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 BEC504EBC6; Mon, 25 Jan 2021 16:05:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 10PG5fGb018303 for ; Mon, 25 Jan 2021 11:05:41 -0500 Received: by smtp.corp.redhat.com (Postfix) id CA0BC5D9DE; Mon, 25 Jan 2021 16:05:41 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1684E5D9DB for ; Mon, 25 Jan 2021 16:05:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611590755; 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=7ZD1JFcAKSF51TnonKxKdcFAYukgCUGdDBfaR1zJop8=; b=Xu0NP2pE9/PsvhwqFokerVTXipH3ZLaV9QTYvY6zz22cItPTSmOd77CbvO+MPXyLMJQJH/ RIlEIPX2ZDdr1TxYcYK/8kXUewNYLGW1bniF/II17iX7Lx8vDZpG25kzq8wTxPemaCWRXY wDA4jDV/KIEXGGH3XOx1W31oD7WNP0w= X-MC-Unique: 4u6BovnnMTacFsgOnWyFdg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 10/12] virStorageSourceChainLookup: Handle names like 'vda[4]' internally Date: Mon, 25 Jan 2021 17:05:22 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com 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" All callers of this function called virStorageFileParseChainIndex before. Internalize the logic of that function to prevent multiple calls and passing around unnecessary temporary variables. This is achieved by calling virStorageFileParseBackingStoreStr and using it to fill the values internally. Signed-off-by: Peter Krempa Reviewed-by: Pavel Hrdina --- src/qemu/qemu_driver.c | 19 ++++-------- src/storage_file/storage_source.c | 49 ++++++++++++++++++++++++------- src/storage_file/storage_source.h | 2 +- tests/virstoragetest.c | 2 +- 4 files changed, 46 insertions(+), 26 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index ed966cf7e3..b3e663c9d5 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -14412,7 +14412,6 @@ qemuDomainBlockPullCommon(virDomainObjPtr vm, const char *jobname =3D NULL; virDomainDiskDefPtr disk; virStorageSourcePtr baseSource =3D NULL; - unsigned int baseIndex =3D 0; g_autofree char *basePath =3D NULL; g_autofree char *backingPath =3D NULL; unsigned long long speed =3D bandwidth; @@ -14448,9 +14447,8 @@ qemuDomainBlockPullCommon(virDomainObjPtr vm, goto endjob; if (base && - (virStorageFileParseChainIndex(disk->dst, base, &baseIndex) < 0 || - !(baseSource =3D virStorageSourceChainLookup(disk->src, disk->src, - base, baseIndex, NULL)= ))) + !(baseSource =3D virStorageSourceChainLookup(disk->src, disk->src, + base, disk->dst, NULL))) goto endjob; if (baseSource) { @@ -15465,9 +15463,7 @@ qemuDomainBlockCommit(virDomainPtr dom, int ret =3D -1; virDomainDiskDefPtr disk =3D NULL; virStorageSourcePtr topSource; - unsigned int topIndex =3D 0; virStorageSourcePtr baseSource =3D NULL; - unsigned int baseIndex =3D 0; virStorageSourcePtr top_parent =3D NULL; bool clean_access =3D false; g_autofree char *topPath =3D NULL; @@ -15540,10 +15536,8 @@ qemuDomainBlockCommit(virDomainPtr dom, if (!top || STREQ(top, disk->dst)) topSource =3D disk->src; - else if (virStorageFileParseChainIndex(disk->dst, top, &topIndex) < 0 = || - !(topSource =3D virStorageSourceChainLookup(disk->src, NULL, - top, topIndex, - &top_parent))) + else if (!(topSource =3D virStorageSourceChainLookup(disk->src, NULL, = top, + disk->dst, &top_par= ent))) goto endjob; if (topSource =3D=3D disk->src) { @@ -15575,9 +15569,8 @@ qemuDomainBlockCommit(virDomainPtr dom, if (!base && (flags & VIR_DOMAIN_BLOCK_COMMIT_SHALLOW)) baseSource =3D topSource->backingStore; - else if (virStorageFileParseChainIndex(disk->dst, base, &baseIndex) < = 0 || - !(baseSource =3D virStorageSourceChainLookup(disk->src, topSo= urce, - base, baseIndex, N= ULL))) + else if (!(baseSource =3D virStorageSourceChainLookup(disk->src, topSo= urce, + base, disk->dst, N= ULL))) goto endjob; if ((flags & VIR_DOMAIN_BLOCK_COMMIT_SHALLOW) && diff --git a/src/storage_file/storage_source.c b/src/storage_file/storage_s= ource.c index 52edb91112..4b46cc4e84 100644 --- a/src/storage_file/storage_source.c +++ b/src/storage_file/storage_source.c @@ -198,32 +198,59 @@ virStorageSourceGetMetadataFromFD(const char *path, } -/* Given a @chain, look for the backing store @name that is a backing file - * of @startFrom (or any member of @chain if @startFrom is NULL) and return - * that location within the chain. @chain must always point to the top of - * the chain. Pass NULL for @name and 0 for @idx to find the base of the - * chain. Pass nonzero @idx to find the backing source according to its - * position in the backing chain. If @parent is not NULL, set *@parent to - * the preferred name of the parent (or to NULL if @name matches the start - * of the chain). Since the results point within @chain, they must not be - * independently freed. Reports an error and returns NULL if @name is not - * found. +/** + * virStorageSourceChainLookup: + * @chain: chain top to look in + * @startFrom: move the starting point of @chain if non-NULL + * @name: name of the file to look for in @chain + * @diskTarget: optional disk target to validate against + * @parent: Filled with parent virStorageSource of the returned value if n= on-NULL. + * + * Looks up a storage source definition corresponding to @name in @chain a= nd + * returns the corresponding virStorageSource. If @startFrom is non-NULL, = the + * lookup starts from that virStorageSource. + * + * @name can be: + * - NULL: the end of the source chain is returned + * - "vda[4]": Storage source with 'id' =3D=3D 4 is returned. If @diskTar= get is + * non-NULL it's also validated that the part before the squa= re + * bracket matches the requested target + * - "/path/to/file": Literal path is matched. Symlink resolution is atte= mpted + * if the filename doesn't string-match with the path. */ virStorageSourcePtr virStorageSourceChainLookup(virStorageSourcePtr chain, virStorageSourcePtr startFrom, const char *name, - unsigned int idx, + const char *diskTarget, virStorageSourcePtr *parent) { virStorageSourcePtr prev; const char *start =3D chain->path; bool nameIsFile =3D virStorageSourceBackinStoreStringIsFile(name); + g_autofree char *target =3D NULL; + unsigned int idx =3D 0; + + if (diskTarget) + start =3D diskTarget; if (!parent) parent =3D &prev; *parent =3D NULL; + /* parse the "vda[4]" type string */ + if (name && + virStorageFileParseBackingStoreStr(name, &target, &idx) =3D=3D 0) { + if (diskTarget && + idx !=3D 0 && + STRNEQ(diskTarget, target)) { + virReportError(VIR_ERR_INVALID_ARG, + _("requested target '%s' does not match target = '%s'"), + target, diskTarget); + return NULL; + } + } + if (startFrom) { while (virStorageSourceIsBacking(chain) && chain !=3D startFrom->backingStore) diff --git a/src/storage_file/storage_source.h b/src/storage_file/storage_s= ource.h index 58f88a3c01..6eb795b301 100644 --- a/src/storage_file/storage_source.h +++ b/src/storage_file/storage_source.h @@ -43,7 +43,7 @@ virStorageSourcePtr virStorageSourceChainLookup(virStorageSourcePtr chain, virStorageSourcePtr startFrom, const char *name, - unsigned int idx, + const char *diskTarget, virStorageSourcePtr *parent) ATTRIBUTE_NONNULL(1); diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c index 99007dd662..c976a1c0d0 100644 --- a/tests/virstoragetest.c +++ b/tests/virstoragetest.c @@ -366,7 +366,7 @@ testStorageLookup(const void *args) } result =3D virStorageSourceChainLookup(data->chain, data->from, - data->name, idx, &actualParent); + data->name, data->target, &actual= Parent); if (!data->expResult) virResetLastError(); --=20 2.29.2 From nobody Tue May 7 18:46:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1611590793; cv=none; d=zohomail.com; s=zohoarc; b=dh93Kmb8JqLqELSWoOH6bm4dmrbJ16JWnKwNYFlPG3kYQq14mD5/6ceJGznXrWH2qQ6/DDeGbmhwPOWb92ERe/SJ1WbjkUQKXF9Q++eFKUSzYHBY4a90FTdsORpxTkZwZH1ZI6RK111jvpaDUsJ1ig8aPuulu0XUnDmLa1ekrbE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611590793; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=W1bLfA4ra6/P4etCKC1/qPccheMbIrhJkYUhoF/ys8c=; b=FEjGw6nyGTSQHnOmhPqalwOM4FZmisC4gI6co9/D/gMrsdhVEik+YFBN2N30efzlEcNhliReLpbdo3oLUMZSZJi2tNLZaauHbkqaQtUi3uaHNIDemFeli9Cw4ZkW0YKlDkrTHDwCuZzaXxFc6v+HUCeFWtFISsSD+EBzKLt9WTA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1611590793058239.86453519871088; Mon, 25 Jan 2021 08:06:33 -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-442-9BQ0dHwHN7-tHcBAcl7aUA-1; Mon, 25 Jan 2021 11:05:55 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4F6C019611A1; Mon, 25 Jan 2021 16:05:48 +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 2E26D5D9DE; Mon, 25 Jan 2021 16:05:48 +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 E9FDC1809CA7; Mon, 25 Jan 2021 16:05:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 10PG5glt018308 for ; Mon, 25 Jan 2021 11:05:42 -0500 Received: by smtp.corp.redhat.com (Postfix) id DBC475D9DE; Mon, 25 Jan 2021 16:05:42 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 382865D9DB for ; Mon, 25 Jan 2021 16:05:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611590792; 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=W1bLfA4ra6/P4etCKC1/qPccheMbIrhJkYUhoF/ys8c=; b=ZY/F09cRnKBy6HOb9mJ3uwSOnX3pLYDj8wWWkd8Pprj3rHvkNwiCWxqo6ZEMLTlX6GO42m jhR4YhwJf2twcFqzEdGtTslBdys6322xQeEdzbiR7cgc2FVH4Lzu/5lpRyFBM9FBimZc+C J5dEEU21aJ9m3Vl79EiotUbrPU2U5og= X-MC-Unique: 9BQ0dHwHN7-tHcBAcl7aUA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 11/12] tests: storage: Replace index testing in testStorageLookup Date: Mon, 25 Jan 2021 17:05:23 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com 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" Test the actual index in the returned virStorageSource rather than the parsed one. Some tests need to be adapted as they were on failed lookup. Signed-off-by: Peter Krempa Reviewed-by: Pavel Hrdina --- tests/virstoragetest.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c index c976a1c0d0..762328df9a 100644 --- a/tests/virstoragetest.c +++ b/tests/virstoragetest.c @@ -353,17 +353,6 @@ testStorageLookup(const void *args) int ret =3D 0; virStorageSourcePtr result; virStorageSourcePtr actualParent; - unsigned int idx; - - if (virStorageFileParseChainIndex(data->target, data->name, &idx) < 0 = && - data->expIndex) { - fprintf(stderr, "call should not have failed\n"); - ret =3D -1; - } - if (idx !=3D data->expIndex) { - fprintf(stderr, "index: expected %u, got %u\n", data->expIndex, id= x); - ret =3D -1; - } result =3D virStorageSourceChainLookup(data->chain, data->from, data->name, data->target, &actual= Parent); @@ -386,6 +375,17 @@ testStorageLookup(const void *args) data->expMeta, result); ret =3D -1; } + if (data->expIndex > 0) { + if (!result) { + fprintf(stderr, "index: resulting lookup is empty, can't match= index\n"); + ret =3D -1; + } else { + if (result->id !=3D data->expIndex) { + fprintf(stderr, "index: expected %u, got %u\n", data->expI= ndex, result->id); + ret =3D -1; + } + } + } if (data->expParent !=3D actualParent) { fprintf(stderr, "parent: expected %s, got %s\n", NULLSTR(data->expParent ? data->expParent->path : NULL), @@ -1077,13 +1077,13 @@ mymain(void) TEST_LOOKUP_TARGET(72, "vda", NULL, "vda[0]", 0, NULL, NULL, NULL); TEST_LOOKUP_TARGET(73, "vda", NULL, "vda[1]", 1, chain2->path, chain2,= chain); TEST_LOOKUP_TARGET(74, "vda", chain, "vda[1]", 1, chain2->path, chain2= , chain); - TEST_LOOKUP_TARGET(75, "vda", chain2, "vda[1]", 1, NULL, NULL, NULL); - TEST_LOOKUP_TARGET(76, "vda", chain3, "vda[1]", 1, NULL, NULL, NULL); + TEST_LOOKUP_TARGET(75, "vda", chain2, "vda[1]", 0, NULL, NULL, NULL); + TEST_LOOKUP_TARGET(76, "vda", chain3, "vda[1]", 0, NULL, NULL, NULL); TEST_LOOKUP_TARGET(77, "vda", NULL, "vda[2]", 2, chain3->path, chain3,= chain2); TEST_LOOKUP_TARGET(78, "vda", chain, "vda[2]", 2, chain3->path, chain3= , chain2); TEST_LOOKUP_TARGET(79, "vda", chain2, "vda[2]", 2, chain3->path, chain= 3, chain2); - TEST_LOOKUP_TARGET(80, "vda", chain3, "vda[2]", 2, NULL, NULL, NULL); - TEST_LOOKUP_TARGET(81, "vda", NULL, "vda[3]", 3, NULL, NULL, NULL); + TEST_LOOKUP_TARGET(80, "vda", chain3, "vda[2]", 0, NULL, NULL, NULL); + TEST_LOOKUP_TARGET(81, "vda", NULL, "vda[3]", 0, NULL, NULL, NULL); #define TEST_PATH_CANONICALIZE(id, PATH, EXPECT) \ do { \ --=20 2.29.2 From nobody Tue May 7 18:46:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1611590846; cv=none; d=zohomail.com; s=zohoarc; b=jd/vzqKiG3iH9kUypLdvybaO+e02GgJsR3R6jRZS0cltQbDoQFR5a4HDu9MH4FT1OawdqccKJGRA52SrslZ7Y9XKDxd4NJ/udG01LkqQnap7rfxjAJ+f37UDafhgrm7AK4KMzfg3fXF/HKysjoyvlTvPFunltA0S4RZXPD6bbPc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611590846; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Xv0yOKQ/9SlIMqNhF+noihJLAcoyJnXhKzJ+y3b5qbY=; b=BNKXywMTDdbp3yLfQ9uR+DPZn07BKJx2oSEwS45FhCCD9f/BDnPVq633ZPcH5UwoQxUtMzrvuNdu6GkdnwWcc0uPLaUHnZq0WG4k3mezzOvSyT8jus0JqFnBAySMfYdjVLKBHHwEeuQaxy8nr2wPCRZepPazxKJfPSlJdfBgPHE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1611590846117238.10019777810794; Mon, 25 Jan 2021 08:07:26 -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-439-AitXvhpwP7O0KxPgNQrUnQ-1; Mon, 25 Jan 2021 11:07:21 -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 D3EA310054FF; Mon, 25 Jan 2021 16:07:15 +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 B0AB560C62; Mon, 25 Jan 2021 16:07:15 +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 7D2694A7C6; Mon, 25 Jan 2021 16:07:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 10PG5i5h018323 for ; Mon, 25 Jan 2021 11:05:44 -0500 Received: by smtp.corp.redhat.com (Postfix) id 0D2BA5D9DB; Mon, 25 Jan 2021 16:05:44 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5ED965D9DE for ; Mon, 25 Jan 2021 16:05:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611590845; 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=Xv0yOKQ/9SlIMqNhF+noihJLAcoyJnXhKzJ+y3b5qbY=; b=MT0wxPoia4J/EE/n3gr+7iuCuIAA2f3ToEwptAlkoBL4Afw5+VMzGBEt5D3C6PiS24MvIE CzsrY/47DbzuaPtO1+zifL2LnsVhr9mD7KKxG+eYBx2FzQGQ0TIv7p9P7r6alUkQFgTOHu z30RGFYgwu/mXpxDAA/Xzcb/hFVyMAg= X-MC-Unique: AitXvhpwP7O0KxPgNQrUnQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 12/12] util: Remove unused 'virStorageFileParseChainIndex' Date: Mon, 25 Jan 2021 17:05:24 +0100 Message-Id: <7da5ecfb52db28812c5f9bf145ed4c531879893d.1611590679.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com 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" Signed-off-by: Peter Krempa Reviewed-by: Pavel Hrdina --- src/libvirt_private.syms | 1 - src/util/virstoragefile.c | 32 -------------------------------- src/util/virstoragefile.h | 5 ----- 3 files changed, 38 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 0a2a54dfdf..4b6fca63d4 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3217,7 +3217,6 @@ virStorageFileCanonicalizePath; virStorageFileGetNPIVKey; virStorageFileGetSCSIKey; virStorageFileParseBackingStoreStr; -virStorageFileParseChainIndex; # util/virstring.h diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index d1e56db708..9df891b57c 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -216,38 +216,6 @@ virStorageFileParseBackingStoreStr(const char *str, } -int -virStorageFileParseChainIndex(const char *diskTarget, - const char *name, - unsigned int *chainIndex) -{ - unsigned int idx =3D 0; - g_autofree char *target =3D NULL; - - *chainIndex =3D 0; - - if (!name || !diskTarget) - return 0; - - if (virStorageFileParseBackingStoreStr(name, &target, &idx) < 0) - return 0; - - if (idx =3D=3D 0) - return 0; - - if (STRNEQ(diskTarget, target)) { - virReportError(VIR_ERR_INVALID_ARG, - _("requested target '%s' does not match target '%s'= "), - target, diskTarget); - return -1; - } - - *chainIndex =3D idx; - - return 0; -} - - static char * virStorageFileCanonicalizeFormatPath(char **components, size_t ncomponents, diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index 455a978a8d..6b198858cc 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -23,11 +23,6 @@ #include "internal.h" -int virStorageFileParseChainIndex(const char *diskTarget, - const char *name, - unsigned int *chainIndex) - ATTRIBUTE_NONNULL(3); - int virStorageFileParseBackingStoreStr(const char *str, char **target, unsigned int *chainIndex) --=20 2.29.2