From nobody Tue Feb 10 07:40:29 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 1491344810562267.56214543287376; Tue, 4 Apr 2017 15:26:50 -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 100AA15567; Tue, 4 Apr 2017 22:26:49 +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 D2DEA9D05E; Tue, 4 Apr 2017 22:26:48 +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 8995F18523CE; Tue, 4 Apr 2017 22:26:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v34MQPpH020686 for ; Tue, 4 Apr 2017 18:26:25 -0400 Received: by smtp.corp.redhat.com (Postfix) id B74299AB62; Tue, 4 Apr 2017 22:26:25 +0000 (UTC) Received: from mx1.redhat.com (ext-mx06.extmail.prod.ext.phx2.redhat.com [10.5.110.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B0E769AB5C for ; Tue, 4 Apr 2017 22:26:25 +0000 (UTC) Received: from mail-qt0-f172.google.com (mail-qt0-f172.google.com [209.85.216.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 C3460445C3 for ; Tue, 4 Apr 2017 22:26:24 +0000 (UTC) Received: by mail-qt0-f172.google.com with SMTP id i34so151729822qtc.0 for ; Tue, 04 Apr 2017 15:26:24 -0700 (PDT) Received: from dawid-fedora.datto.lan ([47.19.105.250]) by smtp.gmail.com with ESMTPSA id d142sm9590549qkc.32.2017.04.04.15.26.23 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Apr 2017 15:26:23 -0700 (PDT) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 100AA15567 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 100AA15567 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="ozVXrkEO" DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C3460445C3 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=datto.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=dzamirski@datto.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com C3460445C3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=datto-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=+d2yUZNmImMrvsV3aieOVDIgyobBzUma7mGtqG4Tjgc=; b=ozVXrkEOPE2m+KxfmirK9Lkih2sbGyMi006qRHS+ftSjDT+lpsR4CB3Qo4il66AQnF qwVoIh4fRJPPPQP4ch3Jd8Bv0mwWv0wslNbCNLxwT5X/6OaZBws6/ZTarp+yN5yutiv7 rVx0OI5H2uyWsNpdu6ySMnMz+3UwfwNiS+aQUwJtaObmyIfHcADvtk1HpqWMdXwU8Oaz OyttcXRc98WKQS25YJqaoLK8oukx2s89BH/Utw/nDwatlXKxBN8YfbBzhlUSqmUECRg3 MQENHHzbLr/GzSyNc2ntPXD14oHJaW/y1nv3waJDT5LduTt4qF8luLZORmjDHY46RSXn U1nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=+d2yUZNmImMrvsV3aieOVDIgyobBzUma7mGtqG4Tjgc=; b=IlgutvfdmTHx90bMJF+tgTOARQVZlg4F72DFcnI5zecITOb92QX/gGRx2uG1S32p6W bGUZNs8gZJiTyBtPkjnSLw9GNIm703P5ZfNKRpxw15a95t7/CsLOAXYMBoKAX8QQAqIu D9vCP9eR+yEz52mWzMsnCrrmT5YT40C5VpEoHRuHH4pIynxijTg2iZjBs3RaSNCnOuZy 35piGyisfBildW7I6u5UaycVHcUto8HRZRcwTTWW1BN+uT/jy0+XpaeJA5Xr12o3P4r/ LBkiscMJF39B5GG/mtD6d/XqBxJ8fcbwty7Ky5hySLkWFvabgufCInFHnIK84te3G1kd MBiw== X-Gm-Message-State: AFeK/H2C3DmwXthH+fqqtOryJSfmCXNgoCS63FgaEF0q+BhPHDumcHW7CSd056XnO2EuCx0U X-Received: by 10.237.37.71 with SMTP id w7mr25102826qtc.34.1491344783656; Tue, 04 Apr 2017 15:26:23 -0700 (PDT) From: Dawid Zamirski To: libvir-list@redhat.com Date: Tue, 4 Apr 2017 18:26:14 -0400 Message-Id: <20170404222616.15382-11-dzamirski@datto.com> In-Reply-To: <20170404222616.15382-1-dzamirski@datto.com> References: <20170404222616.15382-1-dzamirski@datto.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 04 Apr 2017 22:26:25 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 04 Apr 2017 22:26:25 +0000 (UTC) for IP:'209.85.216.172' DOMAIN:'mail-qt0-f172.google.com' HELO:'mail-qt0-f172.google.com' FROM:'dzamirski@datto.com' RCPT:'' X-RedHat-Spam-Score: 0.869 (BAYES_50, DCC_REPUT_00_12, DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_SPAM, SPF_PASS) 209.85.216.172 mail-qt0-f172.google.com 209.85.216.172 mail-qt0-f172.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.30 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 10/12] 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 04 Apr 2017 22:26:49 +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 | 90 +++++++++++++++++++++++++++---------------= ---- 1 file changed, 54 insertions(+), 36 deletions(-) diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c index 5d01c1f..34e7f82 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -55,7 +55,60 @@ hypervFreePrivate(hypervPrivate **priv) VIR_FREE(*priv); } =20 +static int +hypervInitConnection(virConnectPtr conn, hypervPrivate *priv, + char *username, char *password) +{ + hypervWqlQuery wqlQuery =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(&wqlQuery.query, MSVM_COMPUTERSYSTEM_WQL_SELECT); + virBufferAddLit(&wqlQuery.query, "WHERE "); + virBufferAddLit(&wqlQuery.query, MSVM_COMPUTERSYSTEM_WQL_PHYSICAL); + + wqlQuery.info =3D Msvm_ComputerSystem_WmiInfo; + + /* try query using V2 namespace (for Hyperv 2012+) */ + priv->wmiVersion =3D HYPERV_WMI_VERSION_V2; + + if (hypervEnumAndPull(priv, &wqlQuery, &computerSystem) < 0) { + /* fall back to V1 namespace (for Hyper-v 2008) */ + priv->wmiVersion =3D HYPERV_WMI_VERSION_V1; + + if (hypervEnumAndPull(priv, &wqlQuery, &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 +120,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 +198,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 +210,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