From nobody Fri May 3 06:03:13 2024 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.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; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1498225332341163.38782153681393; Fri, 23 Jun 2017 06:42:12 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id C8FFA659A8; Fri, 23 Jun 2017 13:42:09 +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 010496EC78; Fri, 23 Jun 2017 13:42:09 +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 1010A1800C8E; Fri, 23 Jun 2017 13:42:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v5NDXFSk025088 for ; Fri, 23 Jun 2017 09:33:15 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3881A6C40F; Fri, 23 Jun 2017 13:33:15 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.201]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7E0406C403; Fri, 23 Jun 2017 13:33:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C8FFA659A8 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com C8FFA659A8 From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 23 Jun 2017 15:33:13 +0200 Message-Id: <47cd6a2b52919a3f04834e08e141025c3dbfdcea.1498224715.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 1/6] lib: Remove misplaced and redundant comments X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 23 Jun 2017 13:42:10 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" It's obvious that unsigned long long is 64 bit and also our web page generator would misplace the comment after the return value due to the way it's parsing them. Reviewed-by: John Ferlan --- src/libvirt-domain.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index 9bda3c204..4033ae8e6 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -5820,7 +5820,7 @@ virDomainMemoryStats(virDomainPtr dom, virDomainMemor= yStatPtr stats, int virDomainBlockPeek(virDomainPtr dom, const char *disk, - unsigned long long offset /* really 64 bits */, + unsigned long long offset, size_t size, void *buffer, unsigned int flags) @@ -5956,7 +5956,7 @@ virDomainBlockResize(virDomainPtr dom, */ int virDomainMemoryPeek(virDomainPtr dom, - unsigned long long start /* really 64 bits */, + unsigned long long start, size_t size, void *buffer, unsigned int flags) --=20 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 06:03:13 2024 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.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; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 149822481259766.5192059385447; Fri, 23 Jun 2017 06:33:32 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 6A0937D0F2; Fri, 23 Jun 2017 13:33:26 +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 3FAB81754A; Fri, 23 Jun 2017 13:33:26 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id EA250184383F; Fri, 23 Jun 2017 13:33:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v5NDXGb5025121 for ; Fri, 23 Jun 2017 09:33:16 -0400 Received: by smtp.corp.redhat.com (Postfix) id 42F7B6C40E; Fri, 23 Jun 2017 13:33:16 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.201]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8A3C66C403; Fri, 23 Jun 2017 13:33:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6A0937D0F2 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 6A0937D0F2 From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 23 Jun 2017 15:33:14 +0200 Message-Id: <0af6974c700c02274da05d37b2032d4f42222b06.1498224715.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 2/6] tests: storage: Fully register storage driver X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 23 Jun 2017 13:33:27 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Use the full storage driver registration method that also fails if one of the storage backends is not present. This makes the test fail if a submodule fails registration, which is useful for testing. Additionally return EXIT_FAILURE as usual in tests rather than -1. Reviewed-by: John Ferlan --- tests/virstoragetest.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c index f34408395..a73c53839 100644 --- a/tests/virstoragetest.c +++ b/tests/virstoragetest.c @@ -32,7 +32,6 @@ #include "dirname.h" #include "storage/storage_driver.h" -#include "storage/storage_backend.h" #define VIR_FROM_THIS VIR_FROM_NONE @@ -732,8 +731,8 @@ mymain(void) virStorageSourcePtr chain2; /* short for chain->backingStore */ virStorageSourcePtr chain3; /* short for chain2->backingStore */ - if (virStorageBackendDriversRegister(false) < 0) - return -1; + if (storageRegisterAll() < 0) + return EXIT_FAILURE; /* Prep some files with qemu-img; if that is not found on PATH, or * if it lacks support for qcow2 and qed, skip this test. */ --=20 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 06:03:13 2024 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.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; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 14982248046811020.6827330337261; Fri, 23 Jun 2017 06:33:24 -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 1D992652D; Fri, 23 Jun 2017 13:33:21 +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 E5DEF6FB7E; Fri, 23 Jun 2017 13:33:20 +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 9DBD84E985; Fri, 23 Jun 2017 13:33:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v5NDXJvO025148 for ; Fri, 23 Jun 2017 09:33:19 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3C0486C40F; Fri, 23 Jun 2017 13:33:19 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.201]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2E7786C41F; Fri, 23 Jun 2017 13:33:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1D992652D Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 1D992652D From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 23 Jun 2017 15:33:15 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 3/6] storage: Split out virStorageSource accessors to separate file X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 23 Jun 2017 13:33:21 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The helper methods for actually accessing the storage objects don't really belong to the main storage driver implementation file. Split them out. Reviewed-by: John Ferlan --- po/POTFILES.in | 1 + src/Makefile.am | 1 + src/qemu/qemu_domain.c | 1 + src/qemu/qemu_driver.c | 1 + src/security/virt-aa-helper.c | 2 +- src/storage/storage_driver.c | 551 +-------------------------------------- src/storage/storage_driver.h | 28 -- src/storage/storage_source.c | 585 ++++++++++++++++++++++++++++++++++++++= ++++ src/storage/storage_source.h | 53 ++++ tests/virstoragetest.c | 1 + 10 files changed, 645 insertions(+), 579 deletions(-) create mode 100644 src/storage/storage_source.c create mode 100644 src/storage/storage_source.h diff --git a/po/POTFILES.in b/po/POTFILES.in index 275df1f29..87634d228 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -185,6 +185,7 @@ src/storage/storage_backend_sheepdog.c src/storage/storage_backend_vstorage.c src/storage/storage_backend_zfs.c src/storage/storage_driver.c +src/storage/storage_source.c src/storage/storage_util.c src/test/test_driver.c src/uml/uml_conf.c diff --git a/src/Makefile.am b/src/Makefile.am index eae32dc58..399d031dd 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1053,6 +1053,7 @@ STORAGE_DRIVER_BACKEND_SOURCES =3D \ STORAGE_DRIVER_SOURCES =3D \ storage/storage_driver.h storage/storage_driver.c \ + storage/storage_source.h storage/storage_source.c \ $(STORAGE_DRIVER_BACKEND_SOURCES) \ storage/storage_util.h storage/storage_util.c diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 8e7404da6..bc3a85ca2 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -54,6 +54,7 @@ #include "locking/domain_lock.h" #include "storage/storage_driver.h" +#include "storage/storage_source.h" #ifdef MAJOR_IN_MKDEV # include diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index e91663ca9..052c7f0fc 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -100,6 +100,7 @@ #include "viraccessapicheck.h" #include "viraccessapicheckqemu.h" #include "storage/storage_driver.h" +#include "storage/storage_source.h" #include "virhostdev.h" #include "domain_capabilities.h" #include "vircgroup.h" diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index 7f3b7ad08..695272076 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -55,7 +55,7 @@ #include "virstring.h" #include "virgettext.h" -#include "storage/storage_driver.h" +#include "storage/storage_source.h" #define VIR_FROM_THIS VIR_FROM_SECURITY diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index ab1dc8f36..ffffd5a37 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -50,7 +50,7 @@ #include "configmake.h" #include "virstring.h" #include "viraccessapicheck.h" -#include "dirname.h" +//#include "dirname.h" #include "storage_util.h" #define VIR_FROM_THIS VIR_FROM_STORAGE @@ -2758,555 +2758,6 @@ storageRegisterAll(void) } -/* ----------- file handlers cooperating with storage driver -------------= -- */ -static bool -virStorageFileIsInitialized(const virStorageSource *src) -{ - return src && src->drv; -} - - -static bool -virStorageFileSupportsBackingChainTraversal(virStorageSourcePtr src) -{ - int actualType; - virStorageFileBackendPtr backend; - - if (!src) - return false; - actualType =3D virStorageSourceGetActualType(src); - - if (src->drv) { - backend =3D src->drv->backend; - } else { - if (!(backend =3D virStorageFileBackendForTypeInternal(actualType, - src->protocol, - false))) - return false; - } - - return backend->storageFileGetUniqueIdentifier && - backend->storageFileReadHeader && - backend->storageFileAccess; -} - - -/** - * virStorageFileSupportsSecurityDriver: - * - * @src: a storage file structure - * - * Check if a storage file supports operations needed by the security - * driver to perform labelling - */ -bool -virStorageFileSupportsSecurityDriver(const virStorageSource *src) -{ - int actualType; - virStorageFileBackendPtr backend; - - if (!src) - return false; - actualType =3D virStorageSourceGetActualType(src); - - if (src->drv) { - backend =3D src->drv->backend; - } else { - if (!(backend =3D virStorageFileBackendForTypeInternal(actualType, - src->protocol, - false))) - return false; - } - - return !!backend->storageFileChown; -} - - -void -virStorageFileDeinit(virStorageSourcePtr src) -{ - if (!virStorageFileIsInitialized(src)) - return; - - if (src->drv->backend && - src->drv->backend->backendDeinit) - src->drv->backend->backendDeinit(src); - - VIR_FREE(src->drv); -} - - -/** - * virStorageFileInitAs: - * - * @src: storage source definition - * @uid: uid used to access the file, or -1 for current uid - * @gid: gid used to access the file, or -1 for current gid - * - * Initialize a storage source to be used with storage driver. Use the pro= vided - * uid and gid if possible for the operations. - * - * Returns 0 if the storage file was successfully initialized, -1 if the - * initialization failed. Libvirt error is reported. - */ -int -virStorageFileInitAs(virStorageSourcePtr src, - uid_t uid, gid_t gid) -{ - int actualType =3D virStorageSourceGetActualType(src); - if (VIR_ALLOC(src->drv) < 0) - return -1; - - if (uid =3D=3D (uid_t) -1) - src->drv->uid =3D geteuid(); - else - src->drv->uid =3D uid; - - if (gid =3D=3D (gid_t) -1) - src->drv->gid =3D getegid(); - else - src->drv->gid =3D gid; - - if (!(src->drv->backend =3D virStorageFileBackendForType(actualType, - src->protocol))) - goto error; - - if (src->drv->backend->backendInit && - src->drv->backend->backendInit(src) < 0) - goto error; - - return 0; - - error: - VIR_FREE(src->drv); - return -1; -} - - -/** - * virStorageFileInit: - * - * See virStorageFileInitAs. The file is initialized to be accessed by the - * current user. - */ -int -virStorageFileInit(virStorageSourcePtr src) -{ - return virStorageFileInitAs(src, -1, -1); -} - - -/** - * virStorageFileCreate: Creates an empty storage file via storage driver - * - * @src: file structure pointing to the file - * - * Returns 0 on success, -2 if the function isn't supported by the backend, - * -1 on other failure. Errno is set in case of failure. - */ -int -virStorageFileCreate(virStorageSourcePtr src) -{ - int ret; - - if (!virStorageFileIsInitialized(src) || - !src->drv->backend->storageFileCreate) { - errno =3D ENOSYS; - return -2; - } - - ret =3D src->drv->backend->storageFileCreate(src); - - VIR_DEBUG("created storage file %p: ret=3D%d, errno=3D%d", - src, ret, errno); - - return ret; -} - - -/** - * virStorageFileUnlink: Unlink storage file via storage driver - * - * @src: file structure pointing to the file - * - * Unlinks the file described by the @file structure. - * - * Returns 0 on success, -2 if the function isn't supported by the backend, - * -1 on other failure. Errno is set in case of failure. - */ -int -virStorageFileUnlink(virStorageSourcePtr src) -{ - int ret; - - if (!virStorageFileIsInitialized(src) || - !src->drv->backend->storageFileUnlink) { - errno =3D ENOSYS; - return -2; - } - - ret =3D src->drv->backend->storageFileUnlink(src); - - VIR_DEBUG("unlinked storage file %p: ret=3D%d, errno=3D%d", - src, ret, errno); - - return ret; -} - - -/** - * virStorageFileStat: returns stat struct of a file via storage driver - * - * @src: file structure pointing to the file - * @stat: stat structure to return data - * - * Returns 0 on success, -2 if the function isn't supported by the backend, - * -1 on other failure. Errno is set in case of failure. -*/ -int -virStorageFileStat(virStorageSourcePtr src, - struct stat *st) -{ - int ret; - - if (!virStorageFileIsInitialized(src) || - !src->drv->backend->storageFileStat) { - errno =3D ENOSYS; - return -2; - } - - ret =3D src->drv->backend->storageFileStat(src, st); - - VIR_DEBUG("stat of storage file %p: ret=3D%d, errno=3D%d", - src, ret, errno); - - return ret; -} - - -/** - * virStorageFileReadHeader: read the beginning bytes of a file into a buf= fer - * - * @src: file structure pointing to the file - * @max_len: maximum number of bytes read from the storage file - * @buf: buffer to read the data into. buffer shall be freed by caller) - * - * Returns the count of bytes read on success and -1 on failure, -2 if the - * function isn't supported by the backend. - * Libvirt error is reported on failure. - */ -ssize_t -virStorageFileReadHeader(virStorageSourcePtr src, - ssize_t max_len, - char **buf) -{ - ssize_t ret; - - if (!virStorageFileIsInitialized(src)) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("storage file backend not initialized")); - return -1; - } - - if (!src->drv->backend->storageFileReadHeader) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("storage file header reading is not supported for= " - "storage type %s (protocol: %s)"), - virStorageTypeToString(src->type), - virStorageNetProtocolTypeToString(src->protocol)); - return -2; - } - - ret =3D src->drv->backend->storageFileReadHeader(src, max_len, buf); - - VIR_DEBUG("read of storage header %p: ret=3D%zd", src, ret); - - return ret; -} - - -/* - * virStorageFileGetUniqueIdentifier: Get a unique string describing the v= olume - * - * @src: file structure pointing to the file - * - * Returns a string uniquely describing a single volume (canonical path). - * The string shall not be freed and is valid until the storage file is - * deinitialized. Returns NULL on error and sets a libvirt error code */ -const char * -virStorageFileGetUniqueIdentifier(virStorageSourcePtr src) -{ - if (!virStorageFileIsInitialized(src)) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("storage file backend not initialized")); - return NULL; - } - - if (!src->drv->backend->storageFileGetUniqueIdentifier) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unique storage file identifier not implemented f= or " - "storage type %s (protocol: %s)'"), - virStorageTypeToString(src->type), - virStorageNetProtocolTypeToString(src->protocol)); - return NULL; - } - - return src->drv->backend->storageFileGetUniqueIdentifier(src); -} - - -/** - * virStorageFileAccess: Check accessibility of a storage file - * - * @src: storage file to check access permissions - * @mode: accessibility check options (see man 2 access) - * - * Returns 0 on success, -1 on error and sets errno. No libvirt - * error is reported. Returns -2 if the operation isn't supported - * by libvirt storage backend. - */ -int -virStorageFileAccess(virStorageSourcePtr src, - int mode) -{ - if (!virStorageFileIsInitialized(src) || - !src->drv->backend->storageFileAccess) { - errno =3D ENOSYS; - return -2; - } - - return src->drv->backend->storageFileAccess(src, mode); -} - - -/** - * virStorageFileChown: Change owner of a storage file - * - * @src: storage file to change owner of - * @uid: new owner id - * @gid: new group id - * - * Returns 0 on success, -1 on error and sets errno. No libvirt - * error is reported. Returns -2 if the operation isn't supported - * by libvirt storage backend. - */ -int -virStorageFileChown(const virStorageSource *src, - uid_t uid, - gid_t gid) -{ - if (!virStorageFileIsInitialized(src) || - !src->drv->backend->storageFileChown) { - errno =3D ENOSYS; - return -2; - } - - VIR_DEBUG("chown of storage file %p to %u:%u", - src, (unsigned int)uid, (unsigned int)gid); - - return src->drv->backend->storageFileChown(src, uid, gid); -} - - -/* Recursive workhorse for virStorageFileGetMetadata. */ -static int -virStorageFileGetMetadataRecurse(virStorageSourcePtr src, - virStorageSourcePtr parent, - uid_t uid, gid_t gid, - bool allow_probe, - bool report_broken, - virHashTablePtr cycle) -{ - int ret =3D -1; - const char *uniqueName; - char *buf =3D NULL; - ssize_t headerLen; - virStorageSourcePtr backingStore =3D NULL; - int backingFormat; - - VIR_DEBUG("path=3D%s format=3D%d uid=3D%u gid=3D%u probe=3D%d", - src->path, src->format, - (unsigned int)uid, (unsigned int)gid, allow_probe); - - /* exit if we can't load information about the current image */ - if (!virStorageFileSupportsBackingChainTraversal(src)) - return 0; - - if (virStorageFileInitAs(src, uid, gid) < 0) - return -1; - - if (virStorageFileAccess(src, F_OK) < 0) { - if (src =3D=3D parent) { - virReportSystemError(errno, - _("Cannot access storage file '%s' " - "(as uid:%u, gid:%u)"), - src->path, (unsigned int)uid, - (unsigned int)gid); - } else { - virReportSystemError(errno, - _("Cannot access backing file '%s' " - "of storage file '%s' (as uid:%u, gid:%= u)"), - src->path, parent->path, - (unsigned int)uid, (unsigned int)gid); - } - - goto cleanup; - } - - if (!(uniqueName =3D virStorageFileGetUniqueIdentifier(src))) - goto cleanup; - - if (virHashLookup(cycle, uniqueName)) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("backing store for %s (%s) is self-referential"), - src->path, uniqueName); - goto cleanup; - } - - if (virHashAddEntry(cycle, uniqueName, (void *)1) < 0) - goto cleanup; - - if ((headerLen =3D virStorageFileReadHeader(src, VIR_STORAGE_MAX_HEADE= R, - &buf)) < 0) - goto cleanup; - - if (virStorageFileGetMetadataInternal(src, buf, headerLen, - &backingFormat) < 0) - goto cleanup; - - /* check whether we need to go deeper */ - if (!src->backingStoreRaw) { - ret =3D 0; - goto cleanup; - } - - if (!(backingStore =3D virStorageSourceNewFromBacking(src))) - goto cleanup; - - if (backingFormat =3D=3D VIR_STORAGE_FILE_AUTO && !allow_probe) - backingStore->format =3D VIR_STORAGE_FILE_RAW; - else if (backingFormat =3D=3D VIR_STORAGE_FILE_AUTO_SAFE) - backingStore->format =3D VIR_STORAGE_FILE_AUTO; - else - backingStore->format =3D backingFormat; - - if ((ret =3D virStorageFileGetMetadataRecurse(backingStore, parent, - uid, gid, - allow_probe, report_broken, - cycle)) < 0) { - if (report_broken) - goto cleanup; - - /* if we fail somewhere midway, just accept and return a - * broken chain */ - ret =3D 0; - goto cleanup; - } - - src->backingStore =3D backingStore; - backingStore =3D NULL; - ret =3D 0; - - cleanup: - VIR_FREE(buf); - virStorageFileDeinit(src); - virStorageSourceFree(backingStore); - return ret; -} - - -/** - * virStorageFileGetMetadata: - * - * Extract metadata about the storage volume with the specified - * image format. If image format is VIR_STORAGE_FILE_AUTO, it - * will probe to automatically identify the format. Recurses through - * the entire chain. - * - * Open files using UID and GID (or pass -1 for the current user/group). - * Treat any backing files without explicit type as raw, unless ALLOW_PROB= E. - * - * Callers are advised never to use VIR_STORAGE_FILE_AUTO as a - * format, since a malicious guest can turn a raw file into any - * other non-raw format at will. - * - * If @report_broken is true, the whole function fails with a possibly sane - * error instead of just returning a broken chain. - * - * Caller MUST free result after use via virStorageSourceFree. - */ -int -virStorageFileGetMetadata(virStorageSourcePtr src, - uid_t uid, gid_t gid, - bool allow_probe, - bool report_broken) -{ - VIR_DEBUG("path=3D%s format=3D%d uid=3D%u gid=3D%u probe=3D%d, report_= broken=3D%d", - src->path, src->format, (unsigned int)uid, (unsigned int)gid, - allow_probe, report_broken); - - virHashTablePtr cycle =3D NULL; - int ret =3D -1; - - if (!(cycle =3D virHashCreate(5, NULL))) - return -1; - - if (src->format <=3D VIR_STORAGE_FILE_NONE) - src->format =3D allow_probe ? - VIR_STORAGE_FILE_AUTO : VIR_STORAGE_FILE_RAW; - - ret =3D virStorageFileGetMetadataRecurse(src, src, uid, gid, - allow_probe, report_broken, cyc= le); - - virHashFree(cycle); - return ret; -} - - -/** - * virStorageFileGetBackingStoreStr: - * @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. - */ -char * -virStorageFileGetBackingStoreStr(virStorageSourcePtr src) -{ - virStorageSourcePtr tmp =3D NULL; - char *buf =3D NULL; - ssize_t headerLen; - char *ret =3D NULL; - - /* exit if we can't load information about the current image */ - if (!virStorageFileSupportsBackingChainTraversal(src)) - return NULL; - - if (virStorageFileAccess(src, F_OK) < 0) - return NULL; - - if ((headerLen =3D virStorageFileReadHeader(src, VIR_STORAGE_MAX_HEADE= R, - &buf)) < 0) - return NULL; - - if (!(tmp =3D virStorageSourceCopy(src, false))) - goto cleanup; - - if (virStorageFileGetMetadataInternal(tmp, buf, headerLen, NULL) < 0) - goto cleanup; - - VIR_STEAL_PTR(ret, tmp->backingStoreRaw); - - cleanup: - VIR_FREE(buf); - virStorageSourceFree(tmp); - - return ret; -} - - static int virStorageAddISCSIPoolSourceHost(virDomainDiskDefPtr def, virStoragePoolDefPtr pooldef) diff --git a/src/storage/storage_driver.h b/src/storage/storage_driver.h index ade05f715..8b913a1b8 100644 --- a/src/storage/storage_driver.h +++ b/src/storage/storage_driver.h @@ -28,34 +28,6 @@ # include "domain_conf.h" # include "virstorageobj.h" -# include "virstoragefile.h" - -int virStorageFileInit(virStorageSourcePtr src); -int virStorageFileInitAs(virStorageSourcePtr src, - uid_t uid, gid_t gid); -void virStorageFileDeinit(virStorageSourcePtr src); - -int virStorageFileCreate(virStorageSourcePtr src); -int virStorageFileUnlink(virStorageSourcePtr src); -int virStorageFileStat(virStorageSourcePtr src, - struct stat *stat); -ssize_t virStorageFileReadHeader(virStorageSourcePtr src, - ssize_t max_len, - char **buf); -const char *virStorageFileGetUniqueIdentifier(virStorageSourcePtr src); -int virStorageFileAccess(virStorageSourcePtr src, int mode); -int virStorageFileChown(const virStorageSource *src, uid_t uid, gid_t gid); - -bool virStorageFileSupportsSecurityDriver(const virStorageSource *src); - -int virStorageFileGetMetadata(virStorageSourcePtr src, - uid_t uid, gid_t gid, - bool allow_probe, - bool report_broken) - ATTRIBUTE_NONNULL(1); - -char *virStorageFileGetBackingStoreStr(virStorageSourcePtr src) - ATTRIBUTE_NONNULL(1); int virStorageTranslateDiskSourcePool(virConnectPtr conn, virDomainDiskDefPtr def); diff --git a/src/storage/storage_source.c b/src/storage/storage_source.c new file mode 100644 index 000000000..c91d629c8 --- /dev/null +++ b/src/storage/storage_source.c @@ -0,0 +1,585 @@ +/* + * storage_source.c: Storage source object accessors to real storage + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#include + +#include +#include + +#include +#include + +#include "virerror.h" +#include "storage_source.h" +#include "storage_backend.h" +#include "viralloc.h" +#include "virlog.h" +#include "virstring.h" +#include "virhash.h" + +#define VIR_FROM_THIS VIR_FROM_STORAGE + +VIR_LOG_INIT("storage.storage_source"); + + +static bool +virStorageFileIsInitialized(const virStorageSource *src) +{ + return src && src->drv; +} + + +static bool +virStorageFileSupportsBackingChainTraversal(virStorageSourcePtr src) +{ + int actualType; + virStorageFileBackendPtr backend; + + if (!src) + return false; + actualType =3D virStorageSourceGetActualType(src); + + if (src->drv) { + backend =3D src->drv->backend; + } else { + if (!(backend =3D virStorageFileBackendForTypeInternal(actualType, + src->protocol, + false))) + return false; + } + + return backend->storageFileGetUniqueIdentifier && + backend->storageFileReadHeader && + backend->storageFileAccess; +} + + +/** + * virStorageFileSupportsSecurityDriver: + * + * @src: a storage file structure + * + * Check if a storage file supports operations needed by the security + * driver to perform labelling + */ +bool +virStorageFileSupportsSecurityDriver(const virStorageSource *src) +{ + int actualType; + virStorageFileBackendPtr backend; + + if (!src) + return false; + actualType =3D virStorageSourceGetActualType(src); + + if (src->drv) { + backend =3D src->drv->backend; + } else { + if (!(backend =3D virStorageFileBackendForTypeInternal(actualType, + src->protocol, + false))) + return false; + } + + return !!backend->storageFileChown; +} + + +void +virStorageFileDeinit(virStorageSourcePtr src) +{ + if (!virStorageFileIsInitialized(src)) + return; + + if (src->drv->backend && + src->drv->backend->backendDeinit) + src->drv->backend->backendDeinit(src); + + VIR_FREE(src->drv); +} + + +/** + * virStorageFileInitAs: + * + * @src: storage source definition + * @uid: uid used to access the file, or -1 for current uid + * @gid: gid used to access the file, or -1 for current gid + * + * Initialize a storage source to be used with storage driver. Use the pro= vided + * uid and gid if possible for the operations. + * + * Returns 0 if the storage file was successfully initialized, -1 if the + * initialization failed. Libvirt error is reported. + */ +int +virStorageFileInitAs(virStorageSourcePtr src, + uid_t uid, gid_t gid) +{ + int actualType =3D virStorageSourceGetActualType(src); + if (VIR_ALLOC(src->drv) < 0) + return -1; + + if (uid =3D=3D (uid_t) -1) + src->drv->uid =3D geteuid(); + else + src->drv->uid =3D uid; + + if (gid =3D=3D (gid_t) -1) + src->drv->gid =3D getegid(); + else + src->drv->gid =3D gid; + + if (!(src->drv->backend =3D virStorageFileBackendForType(actualType, + src->protocol))) + goto error; + + if (src->drv->backend->backendInit && + src->drv->backend->backendInit(src) < 0) + goto error; + + return 0; + + error: + VIR_FREE(src->drv); + return -1; +} + + +/** + * virStorageFileInit: + * + * See virStorageFileInitAs. The file is initialized to be accessed by the + * current user. + */ +int +virStorageFileInit(virStorageSourcePtr src) +{ + return virStorageFileInitAs(src, -1, -1); +} + + +/** + * virStorageFileCreate: Creates an empty storage file via storage driver + * + * @src: file structure pointing to the file + * + * Returns 0 on success, -2 if the function isn't supported by the backend, + * -1 on other failure. Errno is set in case of failure. + */ +int +virStorageFileCreate(virStorageSourcePtr src) +{ + int ret; + + if (!virStorageFileIsInitialized(src) || + !src->drv->backend->storageFileCreate) { + errno =3D ENOSYS; + return -2; + } + + ret =3D src->drv->backend->storageFileCreate(src); + + VIR_DEBUG("created storage file %p: ret=3D%d, errno=3D%d", + src, ret, errno); + + return ret; +} + + +/** + * virStorageFileUnlink: Unlink storage file via storage driver + * + * @src: file structure pointing to the file + * + * Unlinks the file described by the @file structure. + * + * Returns 0 on success, -2 if the function isn't supported by the backend, + * -1 on other failure. Errno is set in case of failure. + */ +int +virStorageFileUnlink(virStorageSourcePtr src) +{ + int ret; + + if (!virStorageFileIsInitialized(src) || + !src->drv->backend->storageFileUnlink) { + errno =3D ENOSYS; + return -2; + } + + ret =3D src->drv->backend->storageFileUnlink(src); + + VIR_DEBUG("unlinked storage file %p: ret=3D%d, errno=3D%d", + src, ret, errno); + + return ret; +} + + +/** + * virStorageFileStat: returns stat struct of a file via storage driver + * + * @src: file structure pointing to the file + * @stat: stat structure to return data + * + * Returns 0 on success, -2 if the function isn't supported by the backend, + * -1 on other failure. Errno is set in case of failure. +*/ +int +virStorageFileStat(virStorageSourcePtr src, + struct stat *st) +{ + int ret; + + if (!virStorageFileIsInitialized(src) || + !src->drv->backend->storageFileStat) { + errno =3D ENOSYS; + return -2; + } + + ret =3D src->drv->backend->storageFileStat(src, st); + + VIR_DEBUG("stat of storage file %p: ret=3D%d, errno=3D%d", + src, ret, errno); + + return ret; +} + + +/** + * virStorageFileReadHeader: read the beginning bytes of a file into a buf= fer + * + * @src: file structure pointing to the file + * @max_len: maximum number of bytes read from the storage file + * @buf: buffer to read the data into. buffer shall be freed by caller) + * + * Returns the count of bytes read on success and -1 on failure, -2 if the + * function isn't supported by the backend. + * Libvirt error is reported on failure. + */ +ssize_t +virStorageFileReadHeader(virStorageSourcePtr src, + ssize_t max_len, + char **buf) +{ + ssize_t ret; + + if (!virStorageFileIsInitialized(src)) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("storage file backend not initialized")); + return -1; + } + + if (!src->drv->backend->storageFileReadHeader) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("storage file header reading is not supported for= " + "storage type %s (protocol: %s)"), + virStorageTypeToString(src->type), + virStorageNetProtocolTypeToString(src->protocol)); + return -2; + } + + ret =3D src->drv->backend->storageFileReadHeader(src, max_len, buf); + + VIR_DEBUG("read of storage header %p: ret=3D%zd", src, ret); + + return ret; +} + + +/* + * virStorageFileGetUniqueIdentifier: Get a unique string describing the v= olume + * + * @src: file structure pointing to the file + * + * Returns a string uniquely describing a single volume (canonical path). + * The string shall not be freed and is valid until the storage file is + * deinitialized. Returns NULL on error and sets a libvirt error code */ +const char * +virStorageFileGetUniqueIdentifier(virStorageSourcePtr src) +{ + if (!virStorageFileIsInitialized(src)) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("storage file backend not initialized")); + return NULL; + } + + if (!src->drv->backend->storageFileGetUniqueIdentifier) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unique storage file identifier not implemented f= or " + "storage type %s (protocol: %s)'"), + virStorageTypeToString(src->type), + virStorageNetProtocolTypeToString(src->protocol)); + return NULL; + } + + return src->drv->backend->storageFileGetUniqueIdentifier(src); +} + + +/** + * virStorageFileAccess: Check accessibility of a storage file + * + * @src: storage file to check access permissions + * @mode: accessibility check options (see man 2 access) + * + * Returns 0 on success, -1 on error and sets errno. No libvirt + * error is reported. Returns -2 if the operation isn't supported + * by libvirt storage backend. + */ +int +virStorageFileAccess(virStorageSourcePtr src, + int mode) +{ + if (!virStorageFileIsInitialized(src) || + !src->drv->backend->storageFileAccess) { + errno =3D ENOSYS; + return -2; + } + + return src->drv->backend->storageFileAccess(src, mode); +} + + +/** + * virStorageFileChown: Change owner of a storage file + * + * @src: storage file to change owner of + * @uid: new owner id + * @gid: new group id + * + * Returns 0 on success, -1 on error and sets errno. No libvirt + * error is reported. Returns -2 if the operation isn't supported + * by libvirt storage backend. + */ +int +virStorageFileChown(const virStorageSource *src, + uid_t uid, + gid_t gid) +{ + if (!virStorageFileIsInitialized(src) || + !src->drv->backend->storageFileChown) { + errno =3D ENOSYS; + return -2; + } + + VIR_DEBUG("chown of storage file %p to %u:%u", + src, (unsigned int)uid, (unsigned int)gid); + + return src->drv->backend->storageFileChown(src, uid, gid); +} + + +/* Recursive workhorse for virStorageFileGetMetadata. */ +static int +virStorageFileGetMetadataRecurse(virStorageSourcePtr src, + virStorageSourcePtr parent, + uid_t uid, gid_t gid, + bool allow_probe, + bool report_broken, + virHashTablePtr cycle) +{ + int ret =3D -1; + const char *uniqueName; + char *buf =3D NULL; + ssize_t headerLen; + virStorageSourcePtr backingStore =3D NULL; + int backingFormat; + + VIR_DEBUG("path=3D%s format=3D%d uid=3D%u gid=3D%u probe=3D%d", + src->path, src->format, + (unsigned int)uid, (unsigned int)gid, allow_probe); + + /* exit if we can't load information about the current image */ + if (!virStorageFileSupportsBackingChainTraversal(src)) + return 0; + + if (virStorageFileInitAs(src, uid, gid) < 0) + return -1; + + if (virStorageFileAccess(src, F_OK) < 0) { + if (src =3D=3D parent) { + virReportSystemError(errno, + _("Cannot access storage file '%s' " + "(as uid:%u, gid:%u)"), + src->path, (unsigned int)uid, + (unsigned int)gid); + } else { + virReportSystemError(errno, + _("Cannot access backing file '%s' " + "of storage file '%s' (as uid:%u, gid:%= u)"), + src->path, parent->path, + (unsigned int)uid, (unsigned int)gid); + } + + goto cleanup; + } + + if (!(uniqueName =3D virStorageFileGetUniqueIdentifier(src))) + goto cleanup; + + if (virHashLookup(cycle, uniqueName)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("backing store for %s (%s) is self-referential"), + src->path, uniqueName); + goto cleanup; + } + + if (virHashAddEntry(cycle, uniqueName, (void *)1) < 0) + goto cleanup; + + if ((headerLen =3D virStorageFileReadHeader(src, VIR_STORAGE_MAX_HEADE= R, + &buf)) < 0) + goto cleanup; + + if (virStorageFileGetMetadataInternal(src, buf, headerLen, + &backingFormat) < 0) + goto cleanup; + + /* check whether we need to go deeper */ + if (!src->backingStoreRaw) { + ret =3D 0; + goto cleanup; + } + + if (!(backingStore =3D virStorageSourceNewFromBacking(src))) + goto cleanup; + + if (backingFormat =3D=3D VIR_STORAGE_FILE_AUTO && !allow_probe) + backingStore->format =3D VIR_STORAGE_FILE_RAW; + else if (backingFormat =3D=3D VIR_STORAGE_FILE_AUTO_SAFE) + backingStore->format =3D VIR_STORAGE_FILE_AUTO; + else + backingStore->format =3D backingFormat; + + if ((ret =3D virStorageFileGetMetadataRecurse(backingStore, parent, + uid, gid, + allow_probe, report_broken, + cycle)) < 0) { + if (report_broken) + goto cleanup; + + /* if we fail somewhere midway, just accept and return a + * broken chain */ + ret =3D 0; + goto cleanup; + } + + src->backingStore =3D backingStore; + backingStore =3D NULL; + ret =3D 0; + + cleanup: + VIR_FREE(buf); + virStorageFileDeinit(src); + virStorageSourceFree(backingStore); + return ret; +} + + +/** + * virStorageFileGetMetadata: + * + * Extract metadata about the storage volume with the specified + * image format. If image format is VIR_STORAGE_FILE_AUTO, it + * will probe to automatically identify the format. Recurses through + * the entire chain. + * + * Open files using UID and GID (or pass -1 for the current user/group). + * Treat any backing files without explicit type as raw, unless ALLOW_PROB= E. + * + * Callers are advised never to use VIR_STORAGE_FILE_AUTO as a + * format, since a malicious guest can turn a raw file into any + * other non-raw format at will. + * + * If @report_broken is true, the whole function fails with a possibly sane + * error instead of just returning a broken chain. + * + * Caller MUST free result after use via virStorageSourceFree. + */ +int +virStorageFileGetMetadata(virStorageSourcePtr src, + uid_t uid, gid_t gid, + bool allow_probe, + bool report_broken) +{ + VIR_DEBUG("path=3D%s format=3D%d uid=3D%u gid=3D%u probe=3D%d, report_= broken=3D%d", + src->path, src->format, (unsigned int)uid, (unsigned int)gid, + allow_probe, report_broken); + + virHashTablePtr cycle =3D NULL; + int ret =3D -1; + + if (!(cycle =3D virHashCreate(5, NULL))) + return -1; + + if (src->format <=3D VIR_STORAGE_FILE_NONE) + src->format =3D allow_probe ? + VIR_STORAGE_FILE_AUTO : VIR_STORAGE_FILE_RAW; + + ret =3D virStorageFileGetMetadataRecurse(src, src, uid, gid, + allow_probe, report_broken, cyc= le); + + virHashFree(cycle); + return ret; +} + + +/** + * virStorageFileGetBackingStoreStr: + * @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. + */ +char * +virStorageFileGetBackingStoreStr(virStorageSourcePtr src) +{ + virStorageSourcePtr tmp =3D NULL; + char *buf =3D NULL; + ssize_t headerLen; + char *ret =3D NULL; + + /* exit if we can't load information about the current image */ + if (!virStorageFileSupportsBackingChainTraversal(src)) + return NULL; + + if (virStorageFileAccess(src, F_OK) < 0) + return NULL; + + if ((headerLen =3D virStorageFileReadHeader(src, VIR_STORAGE_MAX_HEADE= R, + &buf)) < 0) + return NULL; + + if (!(tmp =3D virStorageSourceCopy(src, false))) + goto cleanup; + + if (virStorageFileGetMetadataInternal(tmp, buf, headerLen, NULL) < 0) + goto cleanup; + + VIR_STEAL_PTR(ret, tmp->backingStoreRaw); + + cleanup: + VIR_FREE(buf); + virStorageSourceFree(tmp); + + return ret; +} diff --git a/src/storage/storage_source.h b/src/storage/storage_source.h new file mode 100644 index 000000000..6b3362244 --- /dev/null +++ b/src/storage/storage_source.h @@ -0,0 +1,53 @@ +/* + * storage_source.h: Storage source accessors to real storaget + * + * 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 + * . + */ + +#ifndef __VIR_STORAGE_SOURCE_H__ +# define __VIR_STORAGE_SOURCE_H__ + +# include + +# include "virstoragefile.h" + +int virStorageFileInit(virStorageSourcePtr src); +int virStorageFileInitAs(virStorageSourcePtr src, + uid_t uid, gid_t gid); +void virStorageFileDeinit(virStorageSourcePtr src); + +int virStorageFileCreate(virStorageSourcePtr src); +int virStorageFileUnlink(virStorageSourcePtr src); +int virStorageFileStat(virStorageSourcePtr src, + struct stat *stat); +ssize_t virStorageFileReadHeader(virStorageSourcePtr src, + ssize_t max_len, + char **buf); +const char *virStorageFileGetUniqueIdentifier(virStorageSourcePtr src); +int virStorageFileAccess(virStorageSourcePtr src, int mode); +int virStorageFileChown(const virStorageSource *src, uid_t uid, gid_t gid); + +bool virStorageFileSupportsSecurityDriver(const virStorageSource *src); + +int virStorageFileGetMetadata(virStorageSourcePtr src, + uid_t uid, gid_t gid, + bool allow_probe, + bool report_broken) + ATTRIBUTE_NONNULL(1); + +char *virStorageFileGetBackingStoreStr(virStorageSourcePtr src) + ATTRIBUTE_NONNULL(1); + +#endif /* __VIR_STORAGE_SOURCE_H__ */ diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c index a73c53839..d630a213f 100644 --- a/tests/virstoragetest.c +++ b/tests/virstoragetest.c @@ -32,6 +32,7 @@ #include "dirname.h" #include "storage/storage_driver.h" +#include "storage/storage_source.h" #define VIR_FROM_THIS VIR_FROM_NONE --=20 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 06:03:13 2024 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.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; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1498225338668147.511295253046; Fri, 23 Jun 2017 06:42:18 -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 93C4FB8153; Fri, 23 Jun 2017 13:42: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 647CD6FB82; Fri, 23 Jun 2017 13:42: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 171D6262; Fri, 23 Jun 2017 13:42:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v5NDXKae025155 for ; Fri, 23 Jun 2017 09:33:20 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4A35E6C40E; Fri, 23 Jun 2017 13:33:20 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.201]) by smtp.corp.redhat.com (Postfix) with ESMTP id 92A356C41C; Fri, 23 Jun 2017 13:33:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 93C4FB8153 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 93C4FB8153 From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 23 Jun 2017 15:33:16 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 4/6] storage: Make virStorageFileReadHeader more universal X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 23 Jun 2017 13:42:16 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Allow specifying offset to read an arbitrary position in the file. This warrants a rename to virStorageFileRead. Reviewed-by: John Ferlan --- src/qemu/qemu_driver.c | 3 +-- src/storage/storage_backend.h | 9 +++++---- src/storage/storage_backend_fs.c | 20 +++++++++++++------ src/storage/storage_backend_gluster.c | 37 ++++++++++++++++++++++---------= ---- src/storage/storage_source.c | 30 +++++++++++++++------------- src/storage/storage_source.h | 7 ++++--- 6 files changed, 63 insertions(+), 43 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 052c7f0fc..4c4a6a036 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -11584,8 +11584,7 @@ qemuStorageLimitsRefresh(virQEMUDriverPtr driver, goto cleanup; } } else { - if ((len =3D virStorageFileReadHeader(src, VIR_STORAGE_MAX_HEADER, - &buf)) < 0) + if ((len =3D virStorageFileRead(src, 0, VIR_STORAGE_MAX_HEADER, &b= uf)) < 0) goto cleanup; } diff --git a/src/storage/storage_backend.h b/src/storage/storage_backend.h index 21ac84552..193cf134d 100644 --- a/src/storage/storage_backend.h +++ b/src/storage/storage_backend.h @@ -154,9 +154,10 @@ typedef int struct stat *st); typedef ssize_t -(*virStorageFileBackendReadHeader)(virStorageSourcePtr src, - ssize_t max_len, - char **buf); +(*virStorageFileBackendRead)(virStorageSourcePtr src, + size_t offset, + size_t len, + char **buf); typedef const char * (*virStorageFileBackendGetUniqueIdentifier)(virStorageSourcePtr src); @@ -186,7 +187,7 @@ struct _virStorageFileBackend { * error on failure. */ virStorageFileBackendInit backendInit; virStorageFileBackendDeinit backendDeinit; - virStorageFileBackendReadHeader storageFileReadHeader; + virStorageFileBackendRead storageFileRead; virStorageFileBackendGetUniqueIdentifier storageFileGetUniqueIdentifie= r; /* The following group of callbacks is expected to set errno diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend= _fs.c index bf1d7de43..847dbc9e0 100644 --- a/src/storage/storage_backend_fs.c +++ b/src/storage/storage_backend_fs.c @@ -779,9 +779,10 @@ virStorageFileBackendFileStat(virStorageSourcePtr src, static ssize_t -virStorageFileBackendFileReadHeader(virStorageSourcePtr src, - ssize_t max_len, - char **buf) +virStorageFileBackendFileRead(virStorageSourcePtr src, + size_t offset, + size_t len, + char **buf) { int fd =3D -1; ssize_t ret =3D -1; @@ -793,7 +794,14 @@ virStorageFileBackendFileReadHeader(virStorageSourcePt= r src, return -1; } - if ((ret =3D virFileReadHeaderFD(fd, max_len, buf)) < 0) { + if (offset > 0) { + if (lseek(fd, offset, SEEK_SET) =3D=3D (off_t) -1) { + virReportSystemError(errno, _("cannot seek into '%s'"), src->p= ath); + goto cleanup; + } + } + + if ((ret =3D virFileReadHeaderFD(fd, len, buf)) < 0) { virReportSystemError(errno, _("cannot read header '%s'"), src->path); goto cleanup; @@ -850,7 +858,7 @@ virStorageFileBackend virStorageFileBackendFile =3D { .storageFileCreate =3D virStorageFileBackendFileCreate, .storageFileUnlink =3D virStorageFileBackendFileUnlink, .storageFileStat =3D virStorageFileBackendFileStat, - .storageFileReadHeader =3D virStorageFileBackendFileReadHeader, + .storageFileRead =3D virStorageFileBackendFileRead, .storageFileAccess =3D virStorageFileBackendFileAccess, .storageFileChown =3D virStorageFileBackendFileChown, @@ -865,7 +873,7 @@ virStorageFileBackend virStorageFileBackendBlock =3D { .backendDeinit =3D virStorageFileBackendFileDeinit, .storageFileStat =3D virStorageFileBackendFileStat, - .storageFileReadHeader =3D virStorageFileBackendFileReadHeader, + .storageFileRead =3D virStorageFileBackendFileRead, .storageFileAccess =3D virStorageFileBackendFileAccess, .storageFileChown =3D virStorageFileBackendFileChown, diff --git a/src/storage/storage_backend_gluster.c b/src/storage/storage_ba= ckend_gluster.c index 93dce4042..8ea7e603c 100644 --- a/src/storage/storage_backend_gluster.c +++ b/src/storage/storage_backend_gluster.c @@ -151,20 +151,20 @@ virStorageBackendGlusterOpen(virStoragePoolObjPtr poo= l) static ssize_t -virStorageBackendGlusterReadHeader(glfs_fd_t *fd, - const char *name, - ssize_t maxlen, - char **buf) +virStorageBackendGlusterRead(glfs_fd_t *fd, + const char *name, + size_t len, + char **buf) { char *s; size_t nread =3D 0; - if (VIR_ALLOC_N(*buf, maxlen) < 0) + if (VIR_ALLOC_N(*buf, len) < 0) return -1; s =3D *buf; - while (maxlen) { - ssize_t r =3D glfs_read(fd, s, maxlen, 0); + while (len) { + ssize_t r =3D glfs_read(fd, s, len, 0); if (r < 0 && errno =3D=3D EINTR) continue; if (r < 0) { @@ -175,7 +175,7 @@ virStorageBackendGlusterReadHeader(glfs_fd_t *fd, if (r =3D=3D 0) return nread; s +=3D r; - maxlen -=3D r; + len -=3D r; nread +=3D r; } return nread; @@ -292,7 +292,7 @@ virStorageBackendGlusterRefreshVol(virStorageBackendGlu= sterStatePtr state, goto cleanup; } - if ((len =3D virStorageBackendGlusterReadHeader(fd, name, len, &header= )) < 0) + if ((len =3D virStorageBackendGlusterRead(fd, name, len, &header)) < 0) goto cleanup; if (!(meta =3D virStorageFileGetMetadataFromBuf(name, header, len, @@ -721,9 +721,10 @@ virStorageFileBackendGlusterStat(virStorageSourcePtr s= rc, static ssize_t -virStorageFileBackendGlusterReadHeader(virStorageSourcePtr src, - ssize_t max_len, - char **buf) +virStorageFileBackendGlusterRead(virStorageSourcePtr src, + size_t offset, + size_t len, + char **buf) { virStorageFileBackendGlusterPrivPtr priv =3D src->drv->priv; glfs_fd_t *fd =3D NULL; @@ -737,8 +738,16 @@ virStorageFileBackendGlusterReadHeader(virStorageSourc= ePtr src, return -1; } - ret =3D virStorageBackendGlusterReadHeader(fd, src->path, max_len, buf= ); + if (offset > 0) { + if (glfs_lseek(fd, offset, SEEK_SET) =3D=3D (off_t) -1) { + virReportSystemError(errno, _("cannot seek into '%s'"), src->p= ath); + goto cleanup; + } + } + + ret =3D virStorageBackendGlusterRead(fd, src->path, len, buf); + cleanup: if (fd) glfs_close(fd); @@ -851,7 +860,7 @@ virStorageFileBackend virStorageFileBackendGluster =3D { .storageFileCreate =3D virStorageFileBackendGlusterCreate, .storageFileUnlink =3D virStorageFileBackendGlusterUnlink, .storageFileStat =3D virStorageFileBackendGlusterStat, - .storageFileReadHeader =3D virStorageFileBackendGlusterReadHeader, + .storageFileRead =3D virStorageFileBackendGlusterRead, .storageFileAccess =3D virStorageFileBackendGlusterAccess, .storageFileChown =3D virStorageFileBackendGlusterChown, diff --git a/src/storage/storage_source.c b/src/storage/storage_source.c index c91d629c8..130c2d2f3 100644 --- a/src/storage/storage_source.c +++ b/src/storage/storage_source.c @@ -64,7 +64,7 @@ virStorageFileSupportsBackingChainTraversal(virStorageSou= rcePtr src) } return backend->storageFileGetUniqueIdentifier && - backend->storageFileReadHeader && + backend->storageFileRead && backend->storageFileAccess; } @@ -263,10 +263,11 @@ virStorageFileStat(virStorageSourcePtr src, /** - * virStorageFileReadHeader: read the beginning bytes of a file into a buf= fer + * virStorageFileRead: read the beginning bytes of a file into a buffer * * @src: file structure pointing to the file - * @max_len: maximum number of bytes read from the storage file + * @offset: number of bytes to skip in the storage file + * @len: maximum number of bytes read from the storage file * @buf: buffer to read the data into. buffer shall be freed by caller) * * Returns the count of bytes read on success and -1 on failure, -2 if the @@ -274,9 +275,10 @@ virStorageFileStat(virStorageSourcePtr src, * Libvirt error is reported on failure. */ ssize_t -virStorageFileReadHeader(virStorageSourcePtr src, - ssize_t max_len, - char **buf) +virStorageFileRead(virStorageSourcePtr src, + size_t offset, + size_t len, + char **buf) { ssize_t ret; @@ -286,18 +288,18 @@ virStorageFileReadHeader(virStorageSourcePtr src, return -1; } - if (!src->drv->backend->storageFileReadHeader) { + if (!src->drv->backend->storageFileRead) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("storage file header reading is not supported for= " + _("storage file reading is not supported for " "storage type %s (protocol: %s)"), virStorageTypeToString(src->type), virStorageNetProtocolTypeToString(src->protocol)); return -2; } - ret =3D src->drv->backend->storageFileReadHeader(src, max_len, buf); + ret =3D src->drv->backend->storageFileRead(src, offset, len, buf); - VIR_DEBUG("read of storage header %p: ret=3D%zd", src, ret); + VIR_DEBUG("read of storage %p: ret=3D%zd", src, ret); return ret; } @@ -444,8 +446,8 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr sr= c, if (virHashAddEntry(cycle, uniqueName, (void *)1) < 0) goto cleanup; - if ((headerLen =3D virStorageFileReadHeader(src, VIR_STORAGE_MAX_HEADE= R, - &buf)) < 0) + if ((headerLen =3D virStorageFileRead(src, 0, VIR_STORAGE_MAX_HEADER, + &buf)) < 0) goto cleanup; if (virStorageFileGetMetadataInternal(src, buf, headerLen, @@ -565,8 +567,8 @@ virStorageFileGetBackingStoreStr(virStorageSourcePtr sr= c) if (virStorageFileAccess(src, F_OK) < 0) return NULL; - if ((headerLen =3D virStorageFileReadHeader(src, VIR_STORAGE_MAX_HEADE= R, - &buf)) < 0) + if ((headerLen =3D virStorageFileRead(src, 0, VIR_STORAGE_MAX_HEADER, + &buf)) < 0) return NULL; if (!(tmp =3D virStorageSourceCopy(src, false))) diff --git a/src/storage/storage_source.h b/src/storage/storage_source.h index 6b3362244..6462baf6a 100644 --- a/src/storage/storage_source.h +++ b/src/storage/storage_source.h @@ -32,9 +32,10 @@ int virStorageFileCreate(virStorageSourcePtr src); int virStorageFileUnlink(virStorageSourcePtr src); int virStorageFileStat(virStorageSourcePtr src, struct stat *stat); -ssize_t virStorageFileReadHeader(virStorageSourcePtr src, - ssize_t max_len, - char **buf); +ssize_t virStorageFileRead(virStorageSourcePtr src, + size_t offset, + size_t len, + char **buf); const char *virStorageFileGetUniqueIdentifier(virStorageSourcePtr src); int virStorageFileAccess(virStorageSourcePtr src, int mode); int virStorageFileChown(const virStorageSource *src, uid_t uid, gid_t gid); --=20 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 06:03:13 2024 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.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; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1498224811084847.9086122283144; Fri, 23 Jun 2017 06:33:31 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D889C7F419; Fri, 23 Jun 2017 13:33:27 +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 5B03153C61; Fri, 23 Jun 2017 13:33:27 +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 1BEFC4E987; Fri, 23 Jun 2017 13:33:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v5NDXLq0025161 for ; Fri, 23 Jun 2017 09:33:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id 698FC6C418; Fri, 23 Jun 2017 13:33:21 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.201]) by smtp.corp.redhat.com (Postfix) with ESMTP id A91FD6C410; Fri, 23 Jun 2017 13:33:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D889C7F419 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com D889C7F419 From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 23 Jun 2017 15:33:17 +0200 Message-Id: <160b4094429a525877b5a4768349c3528a8b3584.1498224715.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 5/6] qemu: Use storage driver APIs in qemuDomainBlockPeek X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 23 Jun 2017 13:33:28 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Refactor the access to storage driver usage along with qemuDomainStorageFileInit which ensures that we access the file with correct DAC uid/gid. Reviewed-by: John Ferlan --- src/qemu/qemu_driver.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 4c4a6a036..115368d1d 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -11309,9 +11309,9 @@ qemuDomainBlockPeek(virDomainPtr dom, unsigned int flags) { virQEMUDriverPtr driver =3D dom->conn->privateData; + virDomainDiskDefPtr disk =3D NULL; virDomainObjPtr vm; - int fd =3D -1, ret =3D -1; - const char *actual; + int ret =3D -1; virCheckFlags(0, -1); @@ -11322,32 +11322,23 @@ qemuDomainBlockPeek(virDomainPtr dom, goto cleanup; /* Check the path belongs to this domain. */ - if (!(actual =3D virDomainDiskPathByName(vm->def, path))) { + if (!(disk =3D virDomainDiskByName(vm->def, path, true))) { virReportError(VIR_ERR_INVALID_ARG, - _("invalid path '%s'"), path); + _("invalid disk or path '%s'"), path); goto cleanup; } - path =3D actual; - fd =3D qemuOpenFile(driver, vm, path, O_RDONLY, NULL, NULL); - if (fd < 0) + if (qemuDomainStorageFileInit(driver, vm, disk->src) < 0) goto cleanup; - /* Seek and read. */ - /* NB. Because we configure with AC_SYS_LARGEFILE, off_t should - * be 64 bits on all platforms. - */ - if (lseek(fd, offset, SEEK_SET) =3D=3D (off_t) -1 || - saferead(fd, buffer, size) =3D=3D (ssize_t) -1) { - virReportSystemError(errno, - _("%s: failed to seek or read"), path); + if (virStorageFileRead(disk->src, offset, size, buffer) < 0) goto cleanup; - } ret =3D 0; cleanup: - VIR_FORCE_CLOSE(fd); + if (disk) + virStorageFileDeinit(disk->src); virDomainObjEndAPI(&vm); return ret; } --=20 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 06:03:13 2024 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.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; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1498224812989525.6589099828628; Fri, 23 Jun 2017 06:33:32 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BAD4130C454; Fri, 23 Jun 2017 13:33:30 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 95A956C413; Fri, 23 Jun 2017 13:33:30 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 52910184383F; Fri, 23 Jun 2017 13:33:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v5NDXMTp025172 for ; Fri, 23 Jun 2017 09:33:22 -0400 Received: by smtp.corp.redhat.com (Postfix) id 747736C403; Fri, 23 Jun 2017 13:33:22 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.201]) by smtp.corp.redhat.com (Postfix) with ESMTP id BC6146C410; Fri, 23 Jun 2017 13:33:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com BAD4130C454 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com BAD4130C454 From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 23 Jun 2017 15:33:18 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 6/6] qemu: Support only raw volumes in qemuDomainBlockPeek X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 23 Jun 2017 13:33:31 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The API documents that it peeks into the VM disk. We can't do that currently for non raw images so report an error. Reviewed-by: John Ferlan --- src/qemu/qemu_driver.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 115368d1d..53655749b 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -11328,6 +11328,12 @@ qemuDomainBlockPeek(virDomainPtr dom, goto cleanup; } + if (disk->src->format !=3D VIR_STORAGE_FILE_RAW) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("peeking is supported only for RAW disks")); + goto cleanup; + } + if (qemuDomainStorageFileInit(driver, vm, disk->src) < 0) goto cleanup; --=20 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list