From nobody Wed May 14 22:01:57 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1516873147427515.2753901851833; Thu, 25 Jan 2018 01:39:07 -0800 (PST) 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 718DC8FAC1; Thu, 25 Jan 2018 09:39:06 +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 41CC860BF9; Thu, 25 Jan 2018 09:39:06 +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 003B35FBE7; Thu, 25 Jan 2018 09:39:05 +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 w0P9d33N003260 for ; Thu, 25 Jan 2018 04:39:03 -0500 Received: by smtp.corp.redhat.com (Postfix) id 99A876056B; Thu, 25 Jan 2018 09:39:03 +0000 (UTC) Received: from t460.redhat.com (unknown [10.33.36.85]) by smtp.corp.redhat.com (Postfix) with ESMTP id 788BE605DC; Thu, 25 Jan 2018 09:39:00 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 25 Jan 2018 09:38:21 +0000 Message-Id: <20180125093825.5834-11-berrange@redhat.com> In-Reply-To: <20180125093825.5834-1-berrange@redhat.com> References: <20180125093825.5834-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 10/14] storage: export virStoragePoolLookupByTargetPath as a public API 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-Type: text/plain; charset="utf-8" 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.27]); Thu, 25 Jan 2018 09:39:07 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 The storagePoolLookupByTargetPath() method in the storage driver is used by the QEMU driver during block migration. If there's a valid use case for this in the QEMU driver, then external apps likely have similar needs. Exposing it in the public API removes the direct dependancy from the QEMU driver to the storage driver. Signed-off-by: Daniel P. Berrang=C3=A9 --- include/libvirt/libvirt-storage.h | 2 ++ src/driver-storage.h | 5 +++++ src/libvirt-storage.c | 40 +++++++++++++++++++++++++++++++++++= ++++ src/libvirt_public.syms | 6 ++++++ src/qemu/qemu_migration.c | 2 +- src/remote/remote_driver.c | 1 + src/remote/remote_protocol.x | 17 ++++++++++++++++- src/remote_protocol-structs | 7 +++++++ src/storage/storage_driver.c | 5 +++++ 9 files changed, 83 insertions(+), 2 deletions(-) diff --git a/include/libvirt/libvirt-storage.h b/include/libvirt/libvirt-st= orage.h index 736e2e3b80..413d9f6c4c 100644 --- a/include/libvirt/libvirt-storage.h +++ b/include/libvirt/libvirt-storage.h @@ -264,6 +264,8 @@ virStoragePoolPtr virStoragePoolLookupByUUID = (virConnectPtr conn, virStoragePoolPtr virStoragePoolLookupByUUIDString(virConnectPtr con= n, const char *uuid); virStoragePoolPtr virStoragePoolLookupByVolume (virStorageVolPtr = vol); +virStoragePoolPtr virStoragePoolLookupByTargetPath(virConnectPtr con= n, + const char *path); =20 /* * Creating/destroying pools diff --git a/src/driver-storage.h b/src/driver-storage.h index 48e588a546..146eb88b2c 100644 --- a/src/driver-storage.h +++ b/src/driver-storage.h @@ -63,6 +63,10 @@ typedef virStoragePoolPtr typedef virStoragePoolPtr (*virDrvStoragePoolLookupByVolume)(virStorageVolPtr vol); =20 +typedef virStoragePoolPtr +(*virDrvStoragePoolLookupByTargetPath)(virConnectPtr conn, + const char *path); + typedef virStoragePoolPtr (*virDrvStoragePoolCreateXML)(virConnectPtr conn, const char *xmlDesc, @@ -236,6 +240,7 @@ struct _virStorageDriver { virDrvStoragePoolLookupByName storagePoolLookupByName; virDrvStoragePoolLookupByUUID storagePoolLookupByUUID; virDrvStoragePoolLookupByVolume storagePoolLookupByVolume; + virDrvStoragePoolLookupByTargetPath storagePoolLookupByTargetPath; virDrvStoragePoolCreateXML storagePoolCreateXML; virDrvStoragePoolDefineXML storagePoolDefineXML; virDrvStoragePoolBuild storagePoolBuild; diff --git a/src/libvirt-storage.c b/src/libvirt-storage.c index e4646cb80f..3845a5d55e 100644 --- a/src/libvirt-storage.c +++ b/src/libvirt-storage.c @@ -497,6 +497,46 @@ virStoragePoolLookupByVolume(virStorageVolPtr vol) } =20 =20 +/** + * virStoragePoolLookupByTargetPath: + * @conn: pointer to hypervisor connection + * @path: path at which the pool is exposed + * + * Fetch a storage pool which maps to a particular target directory. + * If more than one pool maps to the path, it is undefined which + * will be returned first. + * + * virStoragePoolFree should be used to free the resources after the + * storage pool object is no longer needed. + * + * Returns a virStoragePoolPtr object, or NULL if no matching pool is found + */ +virStoragePoolPtr +virStoragePoolLookupByTargetPath(virConnectPtr conn, + const char *path) +{ + VIR_DEBUG("conn=3D%p, path=3D%s", conn, NULLSTR(path)); + + virResetLastError(); + + virCheckConnectReturn(conn, NULL); + virCheckNonNullArgGoto(path, error); + + if (conn->storageDriver && conn->storageDriver->storagePoolLookupByTar= getPath) { + virStoragePoolPtr ret; + ret =3D conn->storageDriver->storagePoolLookupByTargetPath(conn, p= ath); + if (!ret) + goto error; + return ret; + } + + virReportUnsupportedError(); + + error: + virDispatchError(conn); + return NULL; +} + /** * virStoragePoolCreateXML: * @conn: pointer to hypervisor connection diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index 0efde25a7f..7bb8b3dd16 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -779,4 +779,10 @@ LIBVIRT_3.9.0 { global: virDomainSetLifecycleAction; } LIBVIRT_3.7.0; + +LIBVIRT_4.1.0 { + global: + virStoragePoolLookupByTargetPath; +} LIBVIRT_3.9.0; + # .... define new API here using predicted next version number .... diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 1854900c9a..8301c76a19 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -329,7 +329,7 @@ qemuMigrationPrecreateDisk(virConnectPtr conn, *volName =3D '\0'; volName++; =20 - if (!(pool =3D storagePoolLookupByTargetPath(conn, basePath))) + if (!(pool =3D virStoragePoolLookupByTargetPath(conn, basePath))) goto cleanup; format =3D virStorageFileFormatTypeToString(disk->src->format); if (disk->src->format =3D=3D VIR_STORAGE_FILE_QCOW2) diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index f8fa64af99..9ea726dc45 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -8556,6 +8556,7 @@ static virStorageDriver storage_driver =3D { .storagePoolLookupByName =3D remoteStoragePoolLookupByName, /* 0.4.1 */ .storagePoolLookupByUUID =3D remoteStoragePoolLookupByUUID, /* 0.4.1 */ .storagePoolLookupByVolume =3D remoteStoragePoolLookupByVolume, /* 0.4= .1 */ + .storagePoolLookupByTargetPath =3D remoteStoragePoolLookupByTargetPath= , /* 4.1.0 */ .storagePoolCreateXML =3D remoteStoragePoolCreateXML, /* 0.4.1 */ .storagePoolDefineXML =3D remoteStoragePoolDefineXML, /* 0.4.1 */ .storagePoolBuild =3D remoteStoragePoolBuild, /* 0.4.1 */ diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index 0aed25220d..9dbd497b2f 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -1761,6 +1761,14 @@ struct remote_storage_pool_lookup_by_volume_ret { remote_nonnull_storage_pool pool; }; =20 +struct remote_storage_pool_lookup_by_target_path_args { + remote_nonnull_string path; +}; + +struct remote_storage_pool_lookup_by_target_path_ret { + remote_nonnull_storage_pool pool; +}; + struct remote_storage_pool_create_xml_args { remote_nonnull_string xml; unsigned int flags; @@ -6120,5 +6128,12 @@ enum remote_procedure { * @generate: both * @acl: domain:write */ - REMOTE_PROC_DOMAIN_SET_LIFECYCLE_ACTION =3D 390 + REMOTE_PROC_DOMAIN_SET_LIFECYCLE_ACTION =3D 390, + + /** + * @generate: both + * @priority: high + * @acl: storage_pool:getattr + */ + REMOTE_PROC_STORAGE_POOL_LOOKUP_BY_TARGET_PATH =3D 391 }; diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs index 59b0acec69..f45aba27a2 100644 --- a/src/remote_protocol-structs +++ b/src/remote_protocol-structs @@ -1330,6 +1330,12 @@ struct remote_storage_pool_lookup_by_volume_args { struct remote_storage_pool_lookup_by_volume_ret { remote_nonnull_storage_pool pool; }; +struct remote_storage_pool_lookup_by_target_path_args { + remote_nonnull_string path; +}; +struct remote_storage_pool_lookup_by_target_path_ret { + remote_nonnull_storage_pool pool; +}; struct remote_storage_pool_create_xml_args { remote_nonnull_string xml; u_int flags; @@ -3262,4 +3268,5 @@ enum remote_procedure { REMOTE_PROC_DOMAIN_MANAGED_SAVE_GET_XML_DESC =3D 388, REMOTE_PROC_DOMAIN_MANAGED_SAVE_DEFINE_XML =3D 389, REMOTE_PROC_DOMAIN_SET_LIFECYCLE_ACTION =3D 390, + REMOTE_PROC_STORAGE_POOL_LOOKUP_BY_TARGET_PATH =3D 391, }; diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index 25e563e8d6..d43ad1826c 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -1628,6 +1628,9 @@ storagePoolLookupByTargetPath(virConnectPtr conn, storagePoolLookupByTargetPathCa= llback, cleanpath))) { def =3D virStoragePoolObjGetDef(obj); + if (virStoragePoolLookupByTargetPathEnsureACL(conn, def) < 0) + goto cleanup; + pool =3D virGetStoragePool(conn, def->name, def->uuid, NULL, NULL); virStoragePoolObjEndAPI(&obj); } @@ -1644,6 +1647,7 @@ storagePoolLookupByTargetPath(virConnectPtr conn, } } =20 + cleanup: VIR_FREE(cleanpath); return pool; } @@ -2701,6 +2705,7 @@ static virStorageDriver storageDriver =3D { .storagePoolLookupByName =3D storagePoolLookupByName, /* 0.4.0 */ .storagePoolLookupByUUID =3D storagePoolLookupByUUID, /* 0.4.0 */ .storagePoolLookupByVolume =3D storagePoolLookupByVolume, /* 0.4.0 */ + .storagePoolLookupByTargetPath =3D storagePoolLookupByTargetPath, /* 4= .1.0 */ .storagePoolCreateXML =3D storagePoolCreateXML, /* 0.4.0 */ .storagePoolDefineXML =3D storagePoolDefineXML, /* 0.4.0 */ .storagePoolBuild =3D storagePoolBuild, /* 0.4.0 */ --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list