From nobody Tue Feb 10 04:02:42 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; dkim=fail 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 1490892687698555.265430702889; Thu, 30 Mar 2017 09:51:27 -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 3FDB02E6040; Thu, 30 Mar 2017 16:51:26 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0FE5B8764B; Thu, 30 Mar 2017 16:51: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 A93AB5EC60; Thu, 30 Mar 2017 16:51: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 v2UGldUS016970 for ; Thu, 30 Mar 2017 12:47:39 -0400 Received: by smtp.corp.redhat.com (Postfix) id 867AD5B829; Thu, 30 Mar 2017 16:47:39 +0000 (UTC) Received: from mx1.redhat.com (ext-mx07.extmail.prod.ext.phx2.redhat.com [10.5.110.31]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7DBBA7EA37 for ; Thu, 30 Mar 2017 16:47:37 +0000 (UTC) Received: from mail-qk0-f172.google.com (mail-qk0-f172.google.com [209.85.220.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8228FC034E78 for ; Thu, 30 Mar 2017 16:47:36 +0000 (UTC) Received: by mail-qk0-f172.google.com with SMTP id p22so45129920qka.3 for ; Thu, 30 Mar 2017 09:47:36 -0700 (PDT) Received: from dawid-fedora.datto.lan ([47.19.105.250]) by smtp.gmail.com with ESMTPSA id j1sm1730322qkf.57.2017.03.30.09.47.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Mar 2017 09:47:35 -0700 (PDT) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3FDB02E6040 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=datto.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 3FDB02E6040 Authentication-Results: mx1.redhat.com; dkim=fail reason="signature verification failed" (2048-bit key) header.d=datto-com.20150623.gappssmtp.com header.i=@datto-com.20150623.gappssmtp.com header.b="0lpbT6ku" DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8228FC034E78 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=datto.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=dzamirski@datto.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 8228FC034E78 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=datto-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=D8p9vNNUtmo6lI1CYiZDJuKlQ/a2jvTbY3nojzB7P8g=; b=0lpbT6kuVzSvsGBy9KkBEQyRHvuJ5p3DXgdc0m9djSdj6VxG6tjwWnsgOR547Gkquj jewSIaq9bM3RGJuP6tlEzXYWtGwV2lJIyaL5eS9JzKdy64Xvwbg5xBUQ3njFlr/bdtel Ld8KfjmgIAPMm0jZNp86qit5Qv/I9Yc0RF6X9S1VJL+b0X3pFQscRlO9yzvcYqpn4J+q wGMcFahG1t1Si7pgZm8mVKVmqZ2hys9CdoauKzHuW6fMdxJ2E3jnSo5gZkdNzBAF/Mfh n5s96qRqd1rqC/A5+iwfh9FyOtsPSlmXX8M6sNstK3kJwsXEA7ZZfYT6H7Pv+DcDQaFo 3dbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=D8p9vNNUtmo6lI1CYiZDJuKlQ/a2jvTbY3nojzB7P8g=; b=uCHhHrUraChWAIW8JHnJ1sJSBTvfDbvdHBC4+gNnyWOMbTc+N1qUHMzPIcXXxTEJJw kjZMAj5W+bT0NDuoKKmvxXv16cXiLnQqwgWOC7wZ8D6DSz12cdWrsGv0LeR5Cojqq0r+ l4WHb/CkPj49Udn2WlywQJhjSTFhykGivmE2eGkp6GDUSSjtwivwGeERs3glIGksHvvv 2lqEkZa/ymUAtKKqny30gElppQjlyXI0aXWsMVnm1LxyDT1cSyeIsqJ9fd7ySz0Ps4zA uSW51V0VEpis/cGValbo//AFgq/OHq8AHLgr569jsm4mJ1omdDyyJAz7ystXNwBHij1z 6jDw== X-Gm-Message-State: AFeK/H0hf/Kfzit5UkhhUEU7SLRc33SjNaQHR8hpmFkCyo0g8PK/MYIpFbbZP+Qlb8D5E8/a X-Received: by 10.55.7.149 with SMTP id 143mr661146qkh.186.1490892455604; Thu, 30 Mar 2017 09:47:35 -0700 (PDT) From: Dawid Zamirski To: libvir-list@redhat.com Date: Thu, 30 Mar 2017 12:47:28 -0400 Message-Id: <20170330164728.32215-12-dzamirski@datto.com> In-Reply-To: <20170330164728.32215-1-dzamirski@datto.com> References: <20170330164728.32215-1-dzamirski@datto.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 30 Mar 2017 16:47:36 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 30 Mar 2017 16:47:36 +0000 (UTC) for IP:'209.85.220.172' DOMAIN:'mail-qk0-f172.google.com' HELO:'mail-qk0-f172.google.com' FROM:'dzamirski@datto.com' RCPT:'' X-RedHat-Spam-Score: -1.911 (BAYES_50, DCC_REPUT_00_12, DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, RCVD_IN_SORBS_SPAM, SPF_PASS) 209.85.220.172 mail-qk0-f172.google.com 209.85.220.172 mail-qk0-f172.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.31 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Sri Ramanujam Subject: [libvirt] [PATCH 11/11] hyperv: add hypervInitConnection. 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.29]); Thu, 30 Mar 2017 16:51:27 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This function detects hyperv version by issuing a simple query using "v2" namespace and falling back to "v1". --- src/hyperv/hyperv_driver.c | 92 ++++++++++++++++++++++++++++--------------= ---- 1 file changed, 56 insertions(+), 36 deletions(-) diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c index 5d01c1f..0913517 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -55,7 +55,62 @@ hypervFreePrivate(hypervPrivate **priv) VIR_FREE(*priv); } =20 +static int +hypervInitConnection(virConnectPtr conn, hypervPrivate *priv, + char *username, char *password) +{ + virBuffer buf =3D VIR_BUFFER_INITIALIZER; + hypervWqlQuery query =3D HYPERV_WQL_QUERY_INITIALIZER; + hypervObject *computerSystem =3D NULL; + int ret =3D -1; =20 + /* Initialize the openwsman connection */ + priv->client =3D wsmc_create(conn->uri->server, conn->uri->port, "/wsm= an", + priv->parsedUri->transport, username, passw= ord); + + if (priv->client =3D=3D NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Could not create openwsman client")); + goto cleanup; + } + + if (wsmc_transport_init(priv->client, NULL) !=3D 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Could not initialize openwsman transport")); + goto cleanup; + } + + /* FIXME: Currently only basic authentication is supported */ + wsman_transport_set_auth_method(priv->client, "basic"); + + virBufferAddLit(&buf, MSVM_COMPUTERSYSTEM_WQL_SELECT); + virBufferAddLit(&buf, "WHERE "); + virBufferAddLit(&buf, MSVM_COMPUTERSYSTEM_WQL_PHYSICAL); + + query.query =3D virBufferContentAndReset(&buf); + query.info =3D Msvm_ComputerSystem_WmiInfo; + + /* try query using V2 namespace (for Hyperv 2012+) */ + priv->wmiVersion =3D HYPERV_WMI_VERSION_V2; + + if (hypervEnumAndPull(priv, &query, &computerSystem) < 0) { + /* fall back to V1 namespace (for Hyper-v 2008) */ + priv->wmiVersion =3D HYPERV_WMI_VERSION_V1; + + if (hypervEnumAndPull(priv, &query, &computerSystem) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("%s is not a Hyper-V server"), conn->uri->ser= ver); + goto cleanup; + } + } + + ret =3D 0; + + cleanup: + hypervFreeObject(priv, computerSystem); + + return ret; +} =20 static virDrvOpenStatus hypervConnectOpen(virConnectPtr conn, virConnectAuthPtr auth, @@ -67,8 +122,6 @@ hypervConnectOpen(virConnectPtr conn, virConnectAuthPtr = auth, hypervPrivate *priv =3D NULL; char *username =3D NULL; char *password =3D NULL; - virBuffer query =3D VIR_BUFFER_INITIALIZER; - Msvm_ComputerSystem *computerSystem =3D NULL; =20 virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); =20 @@ -147,41 +200,9 @@ hypervConnectOpen(virConnectPtr conn, virConnectAuthPt= r auth, goto cleanup; } =20 - /* Initialize the openwsman connection */ - priv->client =3D wsmc_create(conn->uri->server, conn->uri->port, "/wsm= an", - priv->parsedUri->transport, username, passw= ord); - - if (priv->client =3D=3D NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Could not create openwsman client")); - goto cleanup; - } - - if (wsmc_transport_init(priv->client, NULL) !=3D 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Could not initialize openwsman transport")); - goto cleanup; - } - - /* FIXME: Currently only basic authentication is supported */ - wsman_transport_set_auth_method(priv->client, "basic"); - - /* Check if the connection can be established and if the server has the - * Hyper-V role installed. If the call to hypervGetMsvmComputerSystemL= ist - * succeeds than the connection has been established. If the returned = list - * is empty than the server isn't a Hyper-V server. */ - virBufferAddLit(&query, MSVM_COMPUTERSYSTEM_WQL_SELECT); - virBufferAddLit(&query, "where "); - virBufferAddLit(&query, MSVM_COMPUTERSYSTEM_WQL_PHYSICAL); - - if (hypervGetMsvmComputerSystemList(priv, &query, &computerSystem) < 0) - goto cleanup; =20 - if (computerSystem =3D=3D NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("%s is not a Hyper-V server"), conn->uri->server); + if (hypervInitConnection(conn, priv, username, password) < 0) goto cleanup; - } =20 conn->privateData =3D priv; priv =3D NULL; @@ -191,7 +212,6 @@ hypervConnectOpen(virConnectPtr conn, virConnectAuthPtr= auth, hypervFreePrivate(&priv); VIR_FREE(username); VIR_FREE(password); - hypervFreeObject(priv, (hypervObject *)computerSystem); =20 return result; } --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list