From nobody Mon Feb 9 03:11:13 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 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=1573821786; cv=none; d=zoho.com; s=zohoarc; b=mnqLJ39o22MogJcbKO2oOElVT9mtkCV5wwdhbReO7sJqEof0+yXtalEClW/60gfF1S1dgniT2ZOgtfCjm+IXam1Oca4Bf5eCeHuTtmkFBCCgxAwYreakYeJ9iG9yY1oFutZoXfyakr+bDDvWIMb8dPVjjsNbJzxKMfnktQZarKk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573821786; 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=AvJdwRImq+HNxu6jNtmqUrktkqLVDSxXXeCyTrbilSQ=; b=JVtpvpQSJCSJnLywYwqG5KXjxSD4fZ7sCBGpqixpRTMc/aODiCp+5o8GYI+lodaAKBfkmcg4sBNWm2MdDeWWeQmWng+IgXsVZO5QIn8wuQ9iHThgYSBIMxm2Hbpv9TgBhi4V33RA66OmrwtXXQb9qeaXvNYJOhG0XxY6EBXMxlc= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 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-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1573821786423238.91470757507318; Fri, 15 Nov 2019 04:43: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-uHXG1LgrPAis4N84rI5_cw-1; Fri, 15 Nov 2019 07:41:26 -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 9B122107ACFA; Fri, 15 Nov 2019 12:41:19 +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 6302C5F78C; Fri, 15 Nov 2019 12:41:19 +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 1F8D84E56C; Fri, 15 Nov 2019 12:41:19 +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 xAFCf2Sn026974 for ; Fri, 15 Nov 2019 07:41:02 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2563C5ED2D; Fri, 15 Nov 2019 12:41:02 +0000 (UTC) Received: from lindworm.usersys.redhat.com (unknown [10.43.2.118]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7EC9B5DC1B for ; Fri, 15 Nov 2019 12:41:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573821785; 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=AvJdwRImq+HNxu6jNtmqUrktkqLVDSxXXeCyTrbilSQ=; b=YNrIHGKfP4uIgTNiCrlIwhYP24d1Q6F+V0ArydlPxduqAOrPhISjhPSD6bmcb3/9QkhPo1 P8fqsb7Qe40WzVtyBm8lbFmBNZTQcCUKAnM9kHdivXfDO/w75Kvsa5Os7as4le2jVr5WYp 6YbaUdaNj7qbtfLuQoQCPWrzj0GmaFQ= From: Pino Toscano To: libvir-list@redhat.com Date: Fri, 15 Nov 2019 13:40:43 +0100 Message-Id: <20191115124051.989-5-ptoscano@redhat.com> In-Reply-To: <20191115124051.989-1-ptoscano@redhat.com> References: <20191115124051.989-1-ptoscano@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 04/12] esx: implement connectListAllStoragePools 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 X-MC-Unique: uHXG1LgrPAis4N84rI5_cw-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Implement the .connectListAllStoragePools storage API in the esx storage driver, and in all its subdrivers. Signed-off-by: Pino Toscano Reviewed-by: J=C3=A1n Tomko --- src/esx/esx_storage_backend_iscsi.c | 72 +++++++++++++++++++++ src/esx/esx_storage_backend_vmfs.c | 98 +++++++++++++++++++++++++++++ src/esx/esx_storage_driver.c | 68 ++++++++++++++++++++ 3 files changed, 238 insertions(+) diff --git a/src/esx/esx_storage_backend_iscsi.c b/src/esx/esx_storage_back= end_iscsi.c index 72ab0d3cb0..4f5d8e5e24 100644 --- a/src/esx/esx_storage_backend_iscsi.c +++ b/src/esx/esx_storage_backend_iscsi.c @@ -779,6 +779,77 @@ esxStorageVolGetPath(virStorageVolPtr volume) =20 =20 =20 +#define MATCH(FLAG) (flags & (FLAG)) +static int +esxConnectListAllStoragePools(virConnectPtr conn, + virStoragePoolPtr **pools, + unsigned int flags) +{ + bool success =3D false; + size_t count =3D 0; + esxPrivate *priv =3D conn->privateData; + esxVI_HostInternetScsiHba *hostInternetScsiHba =3D NULL; + esxVI_HostInternetScsiHbaStaticTarget *target; + size_t i; + + /* this driver provides only iSCSI pools */ + if (MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_POOL_TYPE) && + !(MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_ISCSI))) + return 0; + + if (esxVI_LookupHostInternetScsiHba(priv->primary, + &hostInternetScsiHba) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Unable to obtain iSCSI adapter")); + goto cleanup; + } + + /* FIXME: code looks for software iSCSI adapter only */ + if (!hostInternetScsiHba) { + /* iSCSI adapter may not be enabled for this host */ + return 0; + } + + /* + * ESX has two kind of targets: + * 1. staticIscsiTargets + * 2. dynamicIscsiTargets + * For each dynamic target if its reachable a static target is added. + * return iSCSI names for all static targets to avoid duplicate names. + */ + for (target =3D hostInternetScsiHba->configuredStaticTarget; + target; target =3D target->_next) { + virStoragePoolPtr pool; + + pool =3D targetToStoragePool(conn, target->iScsiName, target); + if (!pool) + goto cleanup; + + if (VIR_APPEND_ELEMENT(*pools, count, pool) < 0) + goto cleanup; + } + + success =3D true; + + cleanup: + if (! success) { + if (*pools) { + for (i =3D 0; i < count; ++i) + VIR_FREE((*pools)[i]); + VIR_FREE(*pools); + } + + count =3D -1; + } + + esxVI_HostInternetScsiHba_Free(&hostInternetScsiHba); + + return count; +} +#undef MATCH + + + virStorageDriver esxStorageBackendISCSI =3D { .connectNumOfStoragePools =3D esxConnectNumOfStoragePools, /* 1.0.1 */ .connectListStoragePools =3D esxConnectListStoragePools, /* 1.0.1 */ @@ -799,4 +870,5 @@ virStorageDriver esxStorageBackendISCSI =3D { .storageVolDelete =3D esxStorageVolDelete, /* 1.0.1 */ .storageVolWipe =3D esxStorageVolWipe, /* 1.0.1 */ .storageVolGetPath =3D esxStorageVolGetPath, /* 1.0.1 */ + .connectListAllStoragePools =3D esxConnectListAllStoragePools, /* 5.10= .0 */ }; diff --git a/src/esx/esx_storage_backend_vmfs.c b/src/esx/esx_storage_backe= nd_vmfs.c index b890825a40..05b273aed7 100644 --- a/src/esx/esx_storage_backend_vmfs.c +++ b/src/esx/esx_storage_backend_vmfs.c @@ -1460,6 +1460,103 @@ esxStorageVolGetPath(virStorageVolPtr volume) =20 =20 =20 +#define MATCH(FLAG) (flags & (FLAG)) +static int +esxConnectListAllStoragePools(virConnectPtr conn, + virStoragePoolPtr **pools, + unsigned int flags) +{ + bool success =3D false; + esxPrivate *priv =3D conn->privateData; + esxVI_String *propertyNameList =3D NULL; + esxVI_DynamicProperty *dynamicProperty =3D NULL; + esxVI_ObjectContent *datastoreList =3D NULL; + esxVI_ObjectContent *datastore =3D NULL; + size_t count =3D 0; + size_t i; + virStoragePoolPtr pool; + const bool checkPoolType =3D MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_FILT= ERS_POOL_TYPE); + + if (esxVI_String_AppendValueToList(&propertyNameList, + "summary.name") < 0) { + goto cleanup; + } + + if (checkPoolType && + esxVI_String_AppendValueToList(&propertyNameList, + "info") < 0) { + goto cleanup; + } + + if (esxVI_LookupDatastoreList(priv->primary, propertyNameList, + &datastoreList) < 0) { + goto cleanup; + } + + for (datastore =3D datastoreList; datastore; + datastore =3D datastore->_next) { + const char *name =3D NULL; + + for (dynamicProperty =3D datastore->propSet; dynamicProperty; + dynamicProperty =3D dynamicProperty->_next) { + if (STREQ(dynamicProperty->name, "summary.name")) { + if (esxVI_AnyType_ExpectType(dynamicProperty->val, + esxVI_Type_String) < 0) { + goto cleanup; + } + + name =3D dynamicProperty->val->string; + } + } + + if (!name) + goto cleanup; + + if (checkPoolType) { + int poolType; + + if (datastorePoolType(datastore, &poolType) < 0) + goto cleanup; + + if (!((MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_DIR) && + (poolType =3D=3D VIR_STORAGE_POOL_DIR)) || + (MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_FS) && + (poolType =3D=3D VIR_STORAGE_POOL_FS)) || + (MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_NETFS) && + (poolType =3D=3D VIR_STORAGE_POOL_NETFS)))) + continue; + } + + pool =3D datastoreToStoragePoolPtr(conn, name, datastore); + if (!pool) + goto cleanup; + + if (VIR_APPEND_ELEMENT(*pools, count, pool) < 0) + goto cleanup; + } + + success =3D true; + + cleanup: + if (! success) { + if (*pools) { + for (i =3D 0; i < count; ++i) + VIR_FREE((*pools)[i]); + VIR_FREE(*pools); + } + + count =3D -1; + } + + esxVI_String_Free(&propertyNameList); + esxVI_ObjectContent_Free(&datastoreList); + + return count; +} +#undef MATCH + + + virStorageDriver esxStorageBackendVMFS =3D { .connectNumOfStoragePools =3D esxConnectNumOfStoragePools, /* 0.8.2 */ .connectListStoragePools =3D esxConnectListStoragePools, /* 0.8.2 */ @@ -1480,4 +1577,5 @@ virStorageDriver esxStorageBackendVMFS =3D { .storageVolGetInfo =3D esxStorageVolGetInfo, /* 0.8.4 */ .storageVolGetXMLDesc =3D esxStorageVolGetXMLDesc, /* 0.8.4 */ .storageVolGetPath =3D esxStorageVolGetPath, /* 0.8.4 */ + .connectListAllStoragePools =3D esxConnectListAllStoragePools, /* 5.10= .0 */ }; diff --git a/src/esx/esx_storage_driver.c b/src/esx/esx_storage_driver.c index 8a34732b45..6d17ac28ea 100644 --- a/src/esx/esx_storage_driver.c +++ b/src/esx/esx_storage_driver.c @@ -517,6 +517,73 @@ esxStoragePoolIsPersistent(virStoragePoolPtr pool G_GN= UC_UNUSED) =20 =20 =20 +#define MATCH(FLAG) (flags & (FLAG)) +static int +esxConnectListAllStoragePools(virConnectPtr conn, + virStoragePoolPtr **pools, + unsigned int flags) +{ + bool success =3D false; + esxPrivate *priv =3D conn->privateData; + size_t count =3D 0; + size_t i, j; + int tmp; + + virCheckFlags(VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_ALL, -1); + + /* + * ESX storage pools are always active, persistent, and + * autostarted, so return zero elements in case we are asked + * for pools different than that. + * + * Filtering by type will be done by each backend. + */ + if (MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_ACTIVE) && + !(MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE))) + return 0; + if (MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_PERSISTENT) && + !(MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_PERSISTENT))) + return 0; + if (MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_AUTOSTART) && + !(MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_AUTOSTART))) + return 0; + + if (esxVI_EnsureSession(priv->primary) < 0) + return -1; + + for (i =3D 0; i < LAST_BACKEND; ++i) { + virStoragePoolPtr *new_pools =3D 0; + tmp =3D backends[i]->connectListAllStoragePools(conn, &new_pools, = flags); + + if (tmp < 0) + goto cleanup; + + for (j =3D 0; j < tmp; ++j) { + if (VIR_APPEND_ELEMENT(*pools, count, new_pools[j]) < 0) + goto cleanup; + } + VIR_FREE(new_pools); + } + + success =3D true; + + cleanup: + if (! success) { + if (*pools) { + for (i =3D 0; i < count; ++i) + VIR_FREE((*pools)[i]); + VIR_FREE(*pools); + } + + count =3D -1; + } + + return count; +} +#undef MATCH + + + virStorageDriver esxStorageDriver =3D { .connectNumOfStoragePools =3D esxConnectNumOfStoragePools, /* 0.8.2 */ .connectListStoragePools =3D esxConnectListStoragePools, /* 0.8.2 */ @@ -544,4 +611,5 @@ virStorageDriver esxStorageDriver =3D { .storageVolGetPath =3D esxStorageVolGetPath, /* 0.8.4 */ .storagePoolIsActive =3D esxStoragePoolIsActive, /* 0.8.2 */ .storagePoolIsPersistent =3D esxStoragePoolIsPersistent, /* 0.8.2 */ + .connectListAllStoragePools =3D esxConnectListAllStoragePools, /* 5.10= .0 */ }; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list