From nobody Fri May 16 13:03:10 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.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 1498590849441582.5935764167938; Tue, 27 Jun 2017 12:14:09 -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 E61BE3024A3; Tue, 27 Jun 2017 19:14: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 B96E581D2E; Tue, 27 Jun 2017 19:14: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 56D5041F79; Tue, 27 Jun 2017 19:14:06 +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 v5RJDijh010607 for ; Tue, 27 Jun 2017 15:13:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id BCBA518A7D; Tue, 27 Jun 2017 19:13:44 +0000 (UTC) Received: from mx1.redhat.com (ext-mx09.extmail.prod.ext.phx2.redhat.com [10.5.110.38]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B818518A60 for ; Tue, 27 Jun 2017 19:13:42 +0000 (UTC) Received: from mail-qt0-f180.google.com (mail-qt0-f180.google.com [209.85.216.180]) (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 30FAC333C7 for ; Tue, 27 Jun 2017 19:13:41 +0000 (UTC) Received: by mail-qt0-f180.google.com with SMTP id f92so32662300qtb.2 for ; Tue, 27 Jun 2017 12:13:41 -0700 (PDT) Received: from silas.datto.lan ([47.19.105.250]) by smtp.gmail.com with ESMTPSA id g6sm34445qkb.33.2017.06.27.12.13.38 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Jun 2017 12:13:39 -0700 (PDT) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E61BE3024A3 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 E61BE3024A3 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="RoZHMQNA" DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 30FAC333C7 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=datto.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=sramanujam@datto.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 30FAC333C7 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=DN05uN4qldl26vEeYQu3ewlTOuIwRnhP5yx7EgJDcHM=; b=RoZHMQNApFs7jHEEEus+DsZByP1PdNAKlXIDU3yos01Cr/h++n9ghTf1V1HAHA0F9k 79LLbR/DqBKqe21SC4WJfKBOpsZl/oHXe1ihQcd+lUHxC8/5Lgy/443uy2BFVg2dO7Zl Ye0+s9eDyXGw3f7VBBzi+VWuw88fh91nREzxd6Z5PRWwewROw10dt+zOw+Lc6m/JWpL4 FZ1vDqdTCbJrghis8OeMa2UpeI9GoZWZ2RsiGFryueEKE4MzOjZaJbL77XIYyy9HxL7d lG8AifEYo6OH6W3ACFCVt/ftpUF0YqiIrjrx8Z5r4cFfnzbHyCNhmF4sikl47yHIEP+k UElw== 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=DN05uN4qldl26vEeYQu3ewlTOuIwRnhP5yx7EgJDcHM=; b=D9kEzQXKCILlwt5/sUGlmKD1rCHE9RgcqepYVYYu5F+deu2FWC0osp2DkEa8xQ9MmM otnnVvQZV0TtdCaR/EIZvLUtbrqtUlxMgC1lkNwqiBLHwIgHvMFQENDCDtq1urIUkZj3 KKTlzRrbcplz7Pr+w3l5Fld+r8yuREXILihfHat3iJ3KXqBpKsfvQL+PbTJZl00HVHDa yoXiuwpogsq3AeeeVnT7hj7bi0z+8bw6maIBrghWMuSd4/am3P3Vd2hnMLw/+4k+axcQ ZhVxxLXU/w060pSOZ/M4ncKvrHutzy2NG+CbriPhN1C7hrkj8AA9efDmJ+dN0hyvXYgS tFiA== X-Gm-Message-State: AKS2vOweDL9e45N2Q/qILJpWXyD68vPbVUeMhCBWbFxG703+g2+e6njU qC504weNbN+Ifc3+XcU= X-Received: by 10.200.51.172 with SMTP id c41mr8208449qtb.71.1498590820086; Tue, 27 Jun 2017 12:13:40 -0700 (PDT) From: Sri Ramanujam To: libvir-list@redhat.com Date: Tue, 27 Jun 2017 15:13:26 -0400 Message-Id: <20170627191328.31072-5-sramanujam@datto.com> In-Reply-To: <20170627191328.31072-1-sramanujam@datto.com> References: <20170627191328.31072-1-sramanujam@datto.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 27 Jun 2017 19:13:41 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 27 Jun 2017 19:13:41 +0000 (UTC) for IP:'209.85.216.180' DOMAIN:'mail-qt0-f180.google.com' HELO:'mail-qt0-f180.google.com' FROM:'sramanujam@datto.com' RCPT:'' X-RedHat-Spam-Score: 1.279 * (BAYES_50, DCC_CHECK, DCC_REPUT_00_12, DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_SPAM, SPF_PASS) 209.85.216.180 mail-qt0-f180.google.com 209.85.216.180 mail-qt0-f180.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.38 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v7 4/6] hyperv: support virDomainSendKey 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]); Tue, 27 Jun 2017 19:14:07 +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 commit adds support for virDomainSendKey. It also serves as an example of how to use the new method invocation APIs with a single "simple" type parameter. --- src/hyperv/hyperv_driver.c | 123 ++++++++++++++++++++++++++++++= ++++ src/hyperv/hyperv_wmi.c | 7 ++ src/hyperv/hyperv_wmi.h | 3 +- src/hyperv/hyperv_wmi_generator.input | 86 ++++++++++++++++++++++++ 4 files changed, 218 insertions(+), 1 deletion(-) diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c index 0ca5971..7ee3d9a 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -35,6 +35,8 @@ #include "hyperv_wmi.h" #include "openwsman.h" #include "virstring.h" +#include "virkeycode.h" +#include "intprops.h" =20 #define VIR_FROM_THIS VIR_FROM_HYPERV =20 @@ -1373,6 +1375,126 @@ hypervConnectListAllDomains(virConnectPtr conn, #undef MATCH =20 =20 +static int +hypervDomainSendKey(virDomainPtr domain, unsigned int codeset, + unsigned int holdtime, unsigned int *keycodes, int nkeycodes, + unsigned int flags) +{ + int result =3D -1; + size_t i =3D 0; + int keycode =3D 0; + int *translatedKeycodes =3D NULL; + hypervPrivate *priv =3D domain->conn->privateData; + char uuid_string[VIR_UUID_STRING_BUFLEN]; + char *selector =3D NULL; + Msvm_ComputerSystem *computerSystem =3D NULL; + Msvm_Keyboard *keyboard =3D NULL; + virBuffer query =3D VIR_BUFFER_INITIALIZER; + hypervInvokeParamsListPtr params =3D NULL; + char keycodeStr[INT_BUFSIZE_BOUND(int)]; + + virCheckFlags(0, -1); + + virUUIDFormat(domain->uuid, uuid_string); + + if (hypervMsvmComputerSystemFromDomain(domain, &computerSystem) < 0) + goto cleanup; + + virBufferAsprintf(&query, + "associators of " + "{Msvm_ComputerSystem.CreationClassName=3D\"Msvm_ComputerSyste= m\"," + "Name=3D\"%s\"} " + "where ResultClass =3D Msvm_Keyboard", + uuid_string); + + if (hypervGetMsvmKeyboardList(priv, &query, &keyboard) < 0) + goto cleanup; + + if (VIR_ALLOC_N(translatedKeycodes, nkeycodes) < 0) + goto cleanup; + + /* translate keycodes to win32 and generate keyup scancodes. */ + for (i =3D 0; i < nkeycodes; i++) { + if (codeset !=3D VIR_KEYCODE_SET_WIN32) { + keycode =3D virKeycodeValueTranslate(codeset, VIR_KEYCODE_SET_= WIN32, + keycodes[i]); + + if (keycode < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Could not translate keycode")); + goto cleanup; + } + translatedKeycodes[i] =3D keycode; + } + } + + if (virAsprintf(&selector, + "CreationClassName=3DMsvm_Keyboard&DeviceID=3D%s&" + "SystemCreationClassName=3DMsvm_ComputerSystem&" + "SystemName=3D%s", keyboard->data.common->DeviceID, uuid_s= tring) < 0) + goto cleanup; + + /* press the keys */ + for (i =3D 0; i < nkeycodes; i++) { + snprintf(keycodeStr, sizeof(keycodeStr), "%d", translatedKeycodes[= i]); + + params =3D hypervCreateInvokeParamsList(priv, "PressKey", selector, + Msvm_Keyboard_WmiInfo); + + if (!params) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not crea= te param")); + goto cleanup; + } + + if (hypervAddSimpleParam(params, "keyCode", keycodeStr) < 0) { + hypervFreeInvokeParams(params); + goto cleanup; + } + + if (hypervInvokeMethod(priv, params, NULL) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not press key = %d"), + translatedKeycodes[i]); + goto cleanup; + } + } + + /* simulate holdtime by sleeping */ + if (holdtime > 0) + usleep(holdtime * 1000); + + /* release the keys */ + for (i =3D 0; i < nkeycodes; i++) { + snprintf(keycodeStr, sizeof(keycodeStr), "%d", translatedKeycodes[= i]); + params =3D hypervCreateInvokeParamsList(priv, "ReleaseKey", select= or, + Msvm_Keyboard_WmiInfo); + + if (!params) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not crea= te param")); + goto cleanup; + } + + if (hypervAddSimpleParam(params, "keyCode", keycodeStr) < 0) { + hypervFreeInvokeParams(params); + goto cleanup; + } + + if (hypervInvokeMethod(priv, params, NULL) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not release ke= y %s"), + keycodeStr); + goto cleanup; + } + } + + result =3D 0; + + cleanup: + VIR_FREE(translatedKeycodes); + VIR_FREE(selector); + hypervFreeObject(priv, (hypervObject *) keyboard); + hypervFreeObject(priv, (hypervObject *) computerSystem); + virBufferFreeAndReset(&query); + return result; +} =20 =20 static virHypervisorDriver hypervHypervisorDriver =3D { @@ -1408,6 +1530,7 @@ static virHypervisorDriver hypervHypervisorDriver =3D= { .domainManagedSave =3D hypervDomainManagedSave, /* 0.9.5 */ .domainHasManagedSaveImage =3D hypervDomainHasManagedSaveImage, /* 0.9= .5 */ .domainManagedSaveRemove =3D hypervDomainManagedSaveRemove, /* 0.9.5 */ + .domainSendKey =3D hypervDomainSendKey, /* TODO: version */ .connectIsAlive =3D hypervConnectIsAlive, /* 0.9.8 */ }; =20 diff --git a/src/hyperv/hyperv_wmi.c b/src/hyperv/hyperv_wmi.c index f944b14..36d3c2e 100644 --- a/src/hyperv/hyperv_wmi.c +++ b/src/hyperv/hyperv_wmi.c @@ -1342,6 +1342,13 @@ hypervGetMsvmMemorySettingDataList(hypervPrivate *pr= iv, virBufferPtr query, (hypervObject **) list); } =20 +int hypervGetMsvmKeyboardList(hypervPrivate *priv, virBufferPtr query, + Msvm_Keyboard **list) +{ + return hypervGetWmiClassList(priv, Msvm_Keyboard_WmiInfo, query, + (hypervObject **) list); +} + =20 =20 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *= * * diff --git a/src/hyperv/hyperv_wmi.h b/src/hyperv/hyperv_wmi.h index 25cc470..5c9da04 100644 --- a/src/hyperv/hyperv_wmi.h +++ b/src/hyperv/hyperv_wmi.h @@ -219,7 +219,8 @@ int hypervGetMsvmProcessorSettingDataList(hypervPrivate= *priv, int hypervGetMsvmMemorySettingDataList(hypervPrivate *priv, virBufferPtr q= uery, Msvm_MemorySettingData **list); =20 - +int hypervGetMsvmKeyboardList(hypervPrivate *priv, virBufferPtr query, + Msvm_Keyboard **list); =20 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *= * * * Msvm_ComputerSystem diff --git a/src/hyperv/hyperv_wmi_generator.input b/src/hyperv/hyperv_wmi_= generator.input index d7f819e..4ccda04 100644 --- a/src/hyperv/hyperv_wmi_generator.input +++ b/src/hyperv/hyperv_wmi_generator.input @@ -956,3 +956,89 @@ class Msvm_VirtualHardDiskSettingData uint32 PhysicalSectorSize string VirtualDiskId end + +class Msvm_Keyboard + string Caption + string Description + string ElementName + datetime InstallDate + string Name + uint16 OperationalStatus[] + string StatusDescriptions[] + string Status + uint16 HealthState + uint16 EnabledState + string OtherEnabledState + uint16 RequestedState + uint16 EnabledDefault + datetime TimeOfLastStateChange + string SystemCreationClassName + string SystemName + string CreationClassName + string DeviceID + boolean PowerManagementSupported + uint16 PowerManagementCapabilities[] + uint16 Availability + uint16 StatusInfo + uint32 LastErrorCode + string ErrorDescription + boolean ErrorCleared + string OtherIdentifyingInfo[] + uint64 PowerOnHours + uint64 TotalPowerOnHours + string IdentifyingDescriptions[] + uint16 AdditionalAvailability[] + uint64 MaxQuiesceTime + uint16 LocationIndicator + boolean IsLocked + string Layout + uint16 NumberOfFunctionKeys + uint16 Password +end + + +class v2/Msvm_Keyboard + string InstanceID + string Caption + string Description + string ElementName + datetime InstallDate + string Name + uint16 OperationalStatus[] + string StatusDescriptions[] + string Status + uint16 HealthState + uint16 CommunicationStatus + uint16 DetailedStatus + uint16 OperatingStatus + uint16 PrimaryStatus + uint16 EnabledState + string OtherEnabledState + uint16 RequestedState + uint16 EnabledDefault + datetime TimeOfLastStateChange + uint16 AvailableRequestedStates[] + uint16 TransitioningToState + string SystemCreationClassName + string SystemName + string CreationClassName + string DeviceID + boolean PowerManagementSupported + uint16 PowerManagementCapabilities[] + uint16 Availability + uint16 StatusInfo + uint32 LastErrorCode + string ErrorDescription + boolean ErrorCleared + string OtherIdentifyingInfo[] + uint64 PowerOnHours + uint64 TotalPowerOnHours + string IdentifyingDescriptions[] + uint16 AdditionalAvailability[] + uint64 MaxQuiesceTime + boolean IsLocked + string Layout + uint16 NumberOfFunctionKeys + uint16 Password + boolean UnicodeSupported +end --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list