From nobody Mon Feb 9 09:15:30 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1565952007; cv=none; d=zoho.com; s=zohoarc; b=X/jZ34xZdQrsqfwt0VPWoTsSe0dqM4dTNQRPQP0381CSesWGZklJ/d+mK3xZzJZRLQQ8cWvpdzz1T8bziw8ROCLSul4cjfDFMrTDtfa2EUSv0ndwlIuFCiEH5SLh3dQX1+8zBbc9/PCSqLaagwCz+emjuPPxDYE/bdKec2TtFzg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565952007; 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:ARC-Authentication-Results; bh=FXHPK/5VwRH7+tCN1NJ542oMAHjZEUJRlRAnAZRndfY=; b=eRrWCMoD+CM0t0AIjejv7ZJJw52HujA3ZWJcJTNl8DmY7lPtjsV9VL5ESXuKkDGQXqGpHjc+wE5UTgs3NX7E05hXH1qx8RZWHROWscdKtjMbWIVOjJSkaXvGh/QTSkr2MZZ2CcKF7NcH5BApK/XXr+fIJTGf+FmcXItsC6Sx0Q8= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 156595200766566.49854330355936; Fri, 16 Aug 2019 03:40:07 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 227DB301A62E; Fri, 16 Aug 2019 10:40:06 +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 E216C173C5; Fri, 16 Aug 2019 10:40:05 +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 83C0B180BAA1; Fri, 16 Aug 2019 10:40:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7GAdmtN021553 for ; Fri, 16 Aug 2019 06:39:48 -0400 Received: by smtp.corp.redhat.com (Postfix) id A33E060C5D; Fri, 16 Aug 2019 10:39:48 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2DC669F6B for ; Fri, 16 Aug 2019 10:39:46 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 16 Aug 2019 12:39:28 +0200 Message-Id: <48920eb4cddf99012dd814b40316ab87ec6d8036.1565951850.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 07/14] util: storage: Modify return value of virStorageSourceNewFromBacking 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Fri, 16 Aug 2019 10:40:07 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Return the storage source definition via a pointer in the arguments and document the returned values. This will simplify the possibility to ignore certain backing store types which are not representable by libvirt. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/storage/storage_util.c | 2 +- src/util/virstoragefile.c | 59 ++++++++++++++++++++++++-------------- src/util/virstoragefile.h | 4 ++- 3 files changed, 41 insertions(+), 24 deletions(-) diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index 62f857f9ea..24c5918aa3 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -3391,7 +3391,7 @@ storageBackendProbeTarget(virStorageSourcePtr target, return -1; if (meta->backingStoreRaw) { - if (!(target->backingStore =3D virStorageSourceNewFromBacking(meta= ))) + if (virStorageSourceNewFromBacking(meta, &target->backingStore) < = 0) return -1; target->backingStore->format =3D backingStoreFormat; diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 6fff013e3a..4e57a0438e 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -3679,42 +3679,57 @@ virStorageSourceNewFromBackingAbsolute(const char *= path) } -virStorageSourcePtr -virStorageSourceNewFromBacking(virStorageSourcePtr parent) +/** + * virStorageSourceNewFromBacking: + * @parent: storage source parent + * @backing: returned backing store definition + * + * Creates a storage source which describes the backing image of @parent a= nd + * fills it into @backing depending on the 'backingStoreRaw' property of @= parent + * and other data. Note that for local storage this function interrogates = the + * actual type of the backing store. + * + * Returns 0 and fills @backing, or -1 on error (with appropriate error re= ported). + */ +int +virStorageSourceNewFromBacking(virStorageSourcePtr parent, + virStorageSourcePtr *backing) { struct stat st; - virStorageSourcePtr ret =3D NULL; VIR_AUTOUNREF(virStorageSourcePtr) def =3D NULL; + *backing =3D NULL; + if (virStorageIsRelative(parent->backingStoreRaw)) def =3D virStorageSourceNewFromBackingRelative(parent, parent->backingStoreR= aw); else def =3D virStorageSourceNewFromBackingAbsolute(parent->backingStor= eRaw); - if (def) { - /* possibly update local type */ - if (def->type =3D=3D VIR_STORAGE_TYPE_FILE) { - if (stat(def->path, &st) =3D=3D 0) { - if (S_ISDIR(st.st_mode)) { - def->type =3D VIR_STORAGE_TYPE_DIR; - def->format =3D VIR_STORAGE_FILE_DIR; - } else if (S_ISBLK(st.st_mode)) { - def->type =3D VIR_STORAGE_TYPE_BLOCK; - } + if (!def) + return -1; + + /* possibly update local type */ + if (def->type =3D=3D VIR_STORAGE_TYPE_FILE) { + if (stat(def->path, &st) =3D=3D 0) { + if (S_ISDIR(st.st_mode)) { + def->type =3D VIR_STORAGE_TYPE_DIR; + def->format =3D VIR_STORAGE_FILE_DIR; + } else if (S_ISBLK(st.st_mode)) { + def->type =3D VIR_STORAGE_TYPE_BLOCK; } } + } - /* copy parent's labelling and other top level stuff */ - if (virStorageSourceInitChainElement(def, parent, true) < 0) - return NULL; + /* copy parent's labelling and other top level stuff */ + if (virStorageSourceInitChainElement(def, parent, true) < 0) + return -1; - def->readonly =3D true; - def->detected =3D true; - } + def->readonly =3D true; + def->detected =3D true; - VIR_STEAL_PTR(ret, def); - return ret; + VIR_STEAL_PTR(*backing, def); + return 0; } @@ -4899,7 +4914,7 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr = src, goto cleanup; if (src->backingStoreRaw) { - if (!(backingStore =3D virStorageSourceNewFromBacking(src))) + if (virStorageSourceNewFromBacking(src, &backingStore) < 0) goto cleanup; if (backingFormat =3D=3D VIR_STORAGE_FILE_AUTO) diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index 2882bacf3e..3a72c62ad7 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -444,7 +444,9 @@ int virStorageSourceUpdateCapacity(virStorageSourcePtr = src, char *buf, ssize_t len, bool probe); -virStorageSourcePtr virStorageSourceNewFromBacking(virStorageSourcePtr par= ent); +int virStorageSourceNewFromBacking(virStorageSourcePtr parent, + virStorageSourcePtr *backing); + virStorageSourcePtr virStorageSourceCopy(const virStorageSource *src, bool backingChain) ATTRIBUTE_NONNULL(1); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list