From nobody Tue Apr 30 19:20:28 2024 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 149859084593650.72915870587212; Tue, 27 Jun 2017 12:14:05 -0700 (PDT) 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 6CF097CE12; Tue, 27 Jun 2017 19:14:02 +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 33BA591486; Tue, 27 Jun 2017 19:14:02 +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 6A98F41F78; Tue, 27 Jun 2017 19:14:01 +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 v5RJDetf010549 for ; Tue, 27 Jun 2017 15:13:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id E194717C7F; Tue, 27 Jun 2017 19:13:40 +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 DA4EC17C65 for ; Tue, 27 Jun 2017 19:13:39 +0000 (UTC) Received: from mail-qt0-f181.google.com (mail-qt0-f181.google.com [209.85.216.181]) (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 9DE3BFEF0C for ; Tue, 27 Jun 2017 19:13:37 +0000 (UTC) Received: by mail-qt0-f181.google.com with SMTP id f92so32660979qtb.2 for ; Tue, 27 Jun 2017 12:13:37 -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.34 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Jun 2017 12:13:35 -0700 (PDT) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6CF097CE12 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=datto.com Authentication-Results: ext-mx04.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 6CF097CE12 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="nLCSsBwS" DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9DE3BFEF0C 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 9DE3BFEF0C 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=qjpAJ1O8SQcI5NfYU0sfgcxDj8ORNuPlqmNbmJTO/8M=; b=nLCSsBwSCMCLtZ6l2AcVN2Mfwr7fbdFpvVWtugMpRsNtc+rCq8PBJwhQaoJ8jAWZmz GMYErpKluJRQ8999jD7Wov2IWSKlzc1fRe9PBs2ooTvOR5IJMeyVWVojsYoIODVtvsBt GjOGKASALcbelT0R1Fmlefa9VcLkyzFxcma1W0cZpG9RpvM6kp1EL5b0IvsBZlje9PNG a2fB/w4WHAyjAL0ycyAbYyMvk2iSpid3fzcJtjUT51V8C1jINp7VhZSGMZS+IG0rosDD Lic6J+etVMhbJle3sSybj0F5bB2zm9MEf3qZDf7LUZTszFzc0O+ZiB9oZUdOIx/9TjDY fX9w== 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=qjpAJ1O8SQcI5NfYU0sfgcxDj8ORNuPlqmNbmJTO/8M=; b=CDOCEAB/ieWlxTrac5VkK0VkOgZXEY50p5OZ2YSRk7IcwIV8gMWM2/bwZU/INBxmnE y5CWNRN4t+9IaBjEZK/5lxNQeagfSlYFtvePCpgibFRrBEHcRrDUnhqGYLMpGgEYw1WF 5lbXnA2xnylwKg2a4c5uja9Sg9PcCnTv4gtzWXpwNntEDgid0eZn7pwP2tdxlOvxFLat ZeQoriT7S9GyNwMGoTGMfqOpLSakwBCqX+/clOZgnDP5hQlH+BA+cfPctiPNR9nW3lhy e7kVGUZO3MtqxSiR9Uw0J01vdjM2+MrNNo2/lh5BLJicdhNRIb8hV5Zq0+6UUc8ARz+7 BulQ== X-Gm-Message-State: AKS2vOzonh9y2AS3XZOUQImPAE6eSonK30tJQAa7NEvUe3J9EHrU5uQ2 i3VfINAQD28u1we/2r4= X-Received: by 10.200.38.142 with SMTP id 14mr8576056qto.237.1498590816282; Tue, 27 Jun 2017 12:13:36 -0700 (PDT) From: Sri Ramanujam To: libvir-list@redhat.com Date: Tue, 27 Jun 2017 15:13:23 -0400 Message-Id: <20170627191328.31072-2-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:37 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 27 Jun 2017 19:13:37 +0000 (UTC) for IP:'209.85.216.181' DOMAIN:'mail-qt0-f181.google.com' HELO:'mail-qt0-f181.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.181 mail-qt0-f181.google.com 209.85.216.181 mail-qt0-f181.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.38 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v7 1/6] hyperv: Functions to work with invocation parameters. 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 27 Jun 2017 19:14:03 +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 introduces functionality for creating and working with invoke parameters. This commit does not include any code for serializing and actually performing the method invocations; it merely defines the functions and API for using invocation parameters in driver code. HYPERV_DEFAULT_PARAM_COUNT was chosen because almost no method invocations have more than 4 parameters. Functions added: * hypervInitInvokeParamsList * hypervFreeInvokeParams * hypervAddSimpleParam * hypervAddEprParam * hypervCreateEmbeddedParam * hypervSetEmbeddedProperty * hypervAddEmbeddedParam * hypervFreeEmbeddedParam --- src/hyperv/hyperv_wmi.c | 262 ++++++++++++++++++++++++++++++++++++++++++++= ++++ src/hyperv/hyperv_wmi.h | 79 ++++++++++++++- 2 files changed, 340 insertions(+), 1 deletion(-) diff --git a/src/hyperv/hyperv_wmi.c b/src/hyperv/hyperv_wmi.c index a3c7dc0..2732db3 100644 --- a/src/hyperv/hyperv_wmi.c +++ b/src/hyperv/hyperv_wmi.c @@ -2,6 +2,7 @@ * hyperv_wmi.c: general WMI over WSMAN related functions and structures f= or * managing Microsoft Hyper-V hosts * + * Copyright (C) 2017 Datto Inc * Copyright (C) 2014 Red Hat, Inc. * Copyright (C) 2011 Matthias Bolte * Copyright (C) 2009 Michael Sievers @@ -142,6 +143,267 @@ hypervVerifyResponse(WsManClient *client, WsXmlDocH r= esponse, } =20 =20 +/* + * Methods to work with method invocation parameters + */ + +/* + * hypervCreateInvokeParamsList: + * @priv: hypervPrivate object associated with the connection. + * @method: The name of the method you are calling + * @selector: The selector for the object you are invoking the method on + * @obj: The WmiInfo of the object class you are invoking the method on. + * + * Create a new InvokeParamsList object for the method call. + * + * Returns a pointer to the newly instantiated object on success, which sh= ould + * be freed by hypervInvokeMethod. Otherwise returns NULL. + */ +hypervInvokeParamsListPtr +hypervCreateInvokeParamsList(hypervPrivate *priv, const char *method, + const char *selector, hypervWmiClassInfoListPtr obj) +{ + hypervInvokeParamsListPtr params =3D NULL; + hypervWmiClassInfoPtr info =3D NULL; + + if (hypervGetWmiClassInfo(priv, obj, &info) < 0) + goto cleanup; + + if (VIR_ALLOC(params) < 0) + goto cleanup; + + if (VIR_ALLOC_N(params->params, + HYPERV_DEFAULT_PARAM_COUNT) < 0) { + VIR_FREE(params); + goto cleanup; + } + + params->method =3D method; + params->ns =3D info->rootUri; + params->resourceUri =3D info->resourceUri; + params->selector =3D selector; + params->nbParams =3D 0; + params->nbAvailParams =3D HYPERV_DEFAULT_PARAM_COUNT; + + cleanup: + return params; +} + +/* + * hypervFreeInvokeParams: + * @params: Params object to be freed + * + */ +void +hypervFreeInvokeParams(hypervInvokeParamsListPtr params) +{ + hypervParamPtr p =3D NULL; + size_t i =3D 0; + + if (params =3D=3D NULL) + return; + + for (i =3D 0; i < params->nbParams; i++) { + p =3D &(params->params[i]); + + switch (p->type) { + case HYPERV_SIMPLE_PARAM: + break; + case HYPERV_EPR_PARAM: + virBufferFreeAndReset(p->epr.query); + break; + case HYPERV_EMBEDDED_PARAM: + hypervFreeEmbeddedParam(p->embedded.table); + break; + default: + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Invalid parameter type passed to free")); + } + } + + VIR_DISPOSE_N(params->params, params->nbAvailParams); + VIR_FREE(params); +} + +static inline int +hypervCheckParams(hypervInvokeParamsListPtr params) +{ + if (params->nbParams + 1 > params->nbAvailParams) { + if (VIR_EXPAND_N(params->params, params->nbAvailParams, 5) < 0) + return -1; + } + + return 0; +} + +/* + * hypervAddSimpleParam: + * @params: Params object to add to + * @name: Name of the parameter + * @value: Value of the parameter + * + * Add a param of type HYPERV_SIMPLE_PARAM, which is essentially a seriali= zed + * key/value pair. + * + * Returns -1 on failure, 0 on success. + */ +int +hypervAddSimpleParam(hypervInvokeParamsListPtr params, const char *name, + const char *value) +{ + int result =3D -1; + hypervParamPtr p =3D NULL; + + if (hypervCheckParams(params) < 0) + goto cleanup; + + p =3D ¶ms->params[params->nbParams]; + p->type =3D HYPERV_SIMPLE_PARAM; + + p->simple.name =3D name; + p->simple.value =3D value; + + params->nbParams++; + + result =3D 0; + + cleanup: + return result; +} + +/* + * hypervAddEprParam: + * @params: Params object to add to + * @name: Parameter name + * @priv: hypervPrivate object associated with the connection + * @query: WQL filter + * @eprInfo: WmiInfo of the object being filtered + * + * Adds an EPR param to the params list. Returns -1 on failure, 0 on succe= ss. + */ +int +hypervAddEprParam(hypervInvokeParamsListPtr params, const char *name, + hypervPrivate *priv, virBufferPtr query, + hypervWmiClassInfoListPtr eprInfo) +{ + hypervParamPtr p =3D NULL; + hypervWmiClassInfoPtr classInfo =3D NULL; + + if (hypervGetWmiClassInfo(priv, eprInfo, &classInfo) < 0 || + hypervCheckParams(params) < 0) + return -1; + + p =3D ¶ms->params[params->nbParams]; + p->type =3D HYPERV_EPR_PARAM; + p->epr.name =3D name; + p->epr.query =3D query; + p->epr.info =3D classInfo; + params->nbParams++; + + return 0; +} + +/* + * hypervCreateEmbeddedParam: + * @priv: hypervPrivate object associated with the connection + * @info: WmiInfo of the object type to serialize + * + * Instantiates a virHashTable pre-filled with all the properties pre-added + * a key/value pairs set to NULL. The user then sets only those properties= that + * they wish to serialize, and passes the table via hypervAddEmbeddedParam. + * + * Returns a pointer to the virHashTable on success, otherwise NULL. + */ +virHashTablePtr +hypervCreateEmbeddedParam(hypervPrivate *priv, hypervWmiClassInfoListPtr i= nfo) +{ + size_t i; + int count =3D 0; + virHashTablePtr table =3D NULL; + XmlSerializerInfo *typeinfo =3D NULL; + XmlSerializerInfo *item =3D NULL; + hypervWmiClassInfoPtr classInfo =3D NULL; + + /* Get the typeinfo out of the class info list */ + if (hypervGetWmiClassInfo(priv, info, &classInfo) < 0) + goto error; + + typeinfo =3D classInfo->serializerInfo; + + /* loop through the items to find out how many fields there are */ + for (i =3D 0; typeinfo[i].name !=3D NULL; i++) {} + count =3D i; + + table =3D virHashCreate(count, NULL); + if (table =3D=3D NULL) + goto error; + + for (i =3D 0; typeinfo[i].name !=3D NULL; i++) { + item =3D &typeinfo[i]; + + if (virHashAddEntry(table, item->name, NULL) < 0) + goto error; + } + + return table; + + error: + virHashFree(table); + return NULL; +} + +int +hypervSetEmbeddedProperty(virHashTablePtr table, const char *name, char *v= alue) +{ + return virHashUpdateEntry(table, name, value); +} + +/* + * hypervAddEmbeddedParam: + * @params: Params list to add to + * @priv: hypervPrivate object associated with the connection + * @name: Name of the parameter + * @table: table of properties to add + * @info: WmiInfo of the object to serialize + * + * Add a virHashTable containing object properties as an embedded param to + * an invocation list. Returns -1 on failure, 0 on success. + */ +int +hypervAddEmbeddedParam(hypervInvokeParamsListPtr params, hypervPrivate *pr= iv, + const char *name, virHashTablePtr table, hypervWmiClassInfoListPtr= info) +{ + hypervParamPtr p =3D NULL; + hypervWmiClassInfoPtr classInfo =3D NULL; + + if (hypervCheckParams(params) < 0) + return -1; + + /* Get the typeinfo out of the class info list */ + if (hypervGetWmiClassInfo(priv, info, &classInfo) < 0) + return -1; + + p =3D ¶ms->params[params->nbParams]; + p->type =3D HYPERV_EMBEDDED_PARAM; + p->embedded.name =3D name; + p->embedded.table =3D table; + p->embedded.info =3D classInfo; + params->nbParams++; + + return 0; +} + +/* + * hypervFreeEmbeddedParam: + * @param: Pointer to embedded param to free + * + * Free the embedded param hash table. + */ +void +hypervFreeEmbeddedParam(virHashTablePtr p) +{ + virHashFree(p); +} =20 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *= * * * Object diff --git a/src/hyperv/hyperv_wmi.h b/src/hyperv/hyperv_wmi.h index edb8efa..54ce5b1 100644 --- a/src/hyperv/hyperv_wmi.h +++ b/src/hyperv/hyperv_wmi.h @@ -28,11 +28,13 @@ # include "hyperv_private.h" # include "hyperv_wmi_classes.h" # include "openwsman.h" - +# include "virhash.h" =20 =20 # define HYPERV_WQL_QUERY_INITIALIZER { NULL, NULL } =20 +# define HYPERV_DEFAULT_PARAM_COUNT 5 + int hypervVerifyResponse(WsManClient *client, WsXmlDocH response, const char *detail); =20 @@ -74,7 +76,82 @@ int hypervEnumAndPull(hypervPrivate *priv, hypervWqlQuer= yPtr wqlQuery, void hypervFreeObject(hypervPrivate *priv, hypervObject *object); =20 =20 +/* + * Invoke + */ + +typedef enum { + HYPERV_SIMPLE_PARAM, + HYPERV_EPR_PARAM, + HYPERV_EMBEDDED_PARAM +} hypervStorageType; + +struct _hypervSimpleParam { + const char *name; + const char *value; +}; +typedef struct _hypervSimpleParam hypervSimpleParam; + +struct _hypervEprParam { + const char *name; + virBufferPtr query; + hypervWmiClassInfoPtr info; // info of the object this param represents +}; +typedef struct _hypervEprParam hypervEprParam; + +struct _hypervEmbeddedParam { + const char *name; + virHashTablePtr table; + hypervWmiClassInfoPtr info; // info of the object this param represents +}; +typedef struct _hypervEmbeddedParam hypervEmbeddedParam; + +struct _hypervParam { + hypervStorageType type; + union { + hypervSimpleParam simple; + hypervEprParam epr; + hypervEmbeddedParam embedded; + }; +}; +typedef struct _hypervParam hypervParam; +typedef hypervParam *hypervParamPtr; + +struct _hypervInvokeParamsList { + const char *method; + const char *ns; + const char *resourceUri; + const char *selector; + hypervParamPtr params; + size_t nbParams; + size_t nbAvailParams; +}; +typedef struct _hypervInvokeParamsList hypervInvokeParamsList; +typedef hypervInvokeParamsList *hypervInvokeParamsListPtr; + + +hypervInvokeParamsListPtr hypervCreateInvokeParamsList(hypervPrivate *priv, + const char *method, const char *selector, hypervWmiClassInfoListPt= r obj); + +void hypervFreeInvokeParams(hypervInvokeParamsListPtr params); + +int hypervAddSimpleParam(hypervInvokeParamsListPtr params, const char *nam= e, + const char *value); + +int hypervAddEprParam(hypervInvokeParamsListPtr params, const char *name, + hypervPrivate *priv, virBufferPtr query, + hypervWmiClassInfoListPtr eprInfo); + +virHashTablePtr hypervCreateEmbeddedParam(hypervPrivate *priv, + hypervWmiClassInfoListPtr info); + +int hypervSetEmbeddedProperty(virHashTablePtr table, const char *name, + char *value); + +int hypervAddEmbeddedParam(hypervInvokeParamsListPtr params, hypervPrivate= *priv, + const char *name, virHashTablePtr table, hypervWmiClassInfoListPtr= info); =20 +void hypervFreeEmbeddedParam(virHashTablePtr p); /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *= * * * CIM/Msvm_ReturnCode */ --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue Apr 30 19:20:28 2024 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 1498590829224157.9126364829948; Tue, 27 Jun 2017 12:13:49 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DFB4D40F11; Tue, 27 Jun 2017 19:13:45 +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 720AC60E3D; Tue, 27 Jun 2017 19:13:45 +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 86A761804753; Tue, 27 Jun 2017 19:13:44 +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 v5RJDeJl010550 for ; Tue, 27 Jun 2017 15:13:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id EE1C25DC1F; Tue, 27 Jun 2017 19:13:40 +0000 (UTC) Received: from mx1.redhat.com (ext-mx08.extmail.prod.ext.phx2.redhat.com [10.5.110.32]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E789D17C65 for ; Tue, 27 Jun 2017 19:13:39 +0000 (UTC) Received: from mail-qt0-f171.google.com (mail-qt0-f171.google.com [209.85.216.171]) (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 8EA31C045761 for ; Tue, 27 Jun 2017 19:13:38 +0000 (UTC) Received: by mail-qt0-f171.google.com with SMTP id f92so32661335qtb.2 for ; Tue, 27 Jun 2017 12:13:38 -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.36 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Jun 2017 12:13:36 -0700 (PDT) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com DFB4D40F11 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=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com DFB4D40F11 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="IXq/ZFQl" DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8EA31C045761 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=datto.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=sramanujam@datto.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 8EA31C045761 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=qhA1Hr+npMd3f3nUn2qa2+WtR08MPmAaFvExmWjDrig=; b=IXq/ZFQlT6UHLbah+HRYqWDX34xCTjFXUDK+s/fNDJVheuYv3yAs1kNM1UY58bmBvN 8mB4No+mM+8Cl1ke0z2lZJKfBJhZkc7XzXCOVORb2SUMgUoZ7KbekOsVqGbi/JtFvN6D Y6gAdqjKAAKNyTjgRuAAtxDOz/ltlgOcSxIFikpC+xa3zxDLh6dytrPhQyO8uw9mPN5r jrFZwTzSozXXr2eXhzd6DiydkuVyrxz2vxvLONlLpLtEHrEehIWvLGpAjeUpVO2OT0Qg yc9hFfNr3U0Cr8UirQNIQBUPyL7kG9jVQhHKnsY2rDxJBGxVpOiMpuCpw6stMZ88GD5n dElw== 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=qhA1Hr+npMd3f3nUn2qa2+WtR08MPmAaFvExmWjDrig=; b=bVP9eAkxSn/ZFwUAv06Qkg17fd0WCt+Qphxs4Csw/NZOY4UL8gw0fwUzkdByluXGoB eYV120idP99ekrbdyqvSr6SX7I2VCAnrd9NbTVRvIG8cO09OwuuCFrzwtX/0PgdABWcR HKrN8f8RIV+pJ7RcgdpDSsWiuAy7F2FQ4DVeaq9YA7JltBS6kQFcN4TJjiubaSBlmMNo T3fLcHiiRQpVawppTBRsPNaPOZvijL4mNsPGn+bNe8CWzDuE+ZCCV6B1Amq/ryMBjaU0 Ml6fgkrVa+4uOx6Du61SglmVvn9ZIEqf2u+hm955RP8/EL7GxqKuFKyD4H/GA6uOvzMh YEIw== X-Gm-Message-State: AKS2vOw1U2znWm9tQyw1FxqPhjXfsJoOAy7QkoNTHLgZ0rLBnDC7gP1F lY+miTFHrUMXOZajkOA= X-Received: by 10.200.38.244 with SMTP id 49mr124299qtp.236.1498590817501; Tue, 27 Jun 2017 12:13:37 -0700 (PDT) From: Sri Ramanujam To: libvir-list@redhat.com Date: Tue, 27 Jun 2017 15:13:24 -0400 Message-Id: <20170627191328.31072-3-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.32]); Tue, 27 Jun 2017 19:13:38 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 27 Jun 2017 19:13:38 +0000 (UTC) for IP:'209.85.216.171' DOMAIN:'mail-qt0-f171.google.com' HELO:'mail-qt0-f171.google.com' FROM:'sramanujam@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.171 mail-qt0-f171.google.com 209.85.216.171 mail-qt0-f171.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.32 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v7 2/6] hyperv: Generate object property type information. 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 27 Jun 2017 19:13:46 +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" Update the generator to generate basic property type information for each CIM object representation. Right now, it generates arrays of hypervCimType structs: struct _hypervCimType { const char *name; const char *type; bool isArray; }; --- src/hyperv/hyperv_wmi_classes.h | 19 +++++++++++++++++++ src/hyperv/hyperv_wmi_generator.py | 15 ++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/hyperv/hyperv_wmi_classes.h b/src/hyperv/hyperv_wmi_classe= s.h index f7d596f..ce4643e 100644 --- a/src/hyperv/hyperv_wmi_classes.h +++ b/src/hyperv/hyperv_wmi_classes.h @@ -1,6 +1,7 @@ /* * hyperv_wmi_classes.h: WMI classes for managing Microsoft Hyper-V hosts * + * Copyright (C) 2017 Datto Inc * Copyright (C) 2011 Matthias Bolte * Copyright (C) 2009 Michael Sievers * @@ -23,6 +24,7 @@ #ifndef __HYPERV_WMI_CLASSES_H__ # define __HYPERV_WMI_CLASSES_H__ =20 +# include "internal.h" # include "openwsman.h" =20 # include "hyperv_wmi_classes.generated.typedef" @@ -96,6 +98,21 @@ enum _Msvm_ConcreteJob_JobState { }; =20 =20 +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *= * * + * WMI + */ + +typedef struct _hypervCimType hypervCimType; +typedef hypervCimType *hypervCimTypePtr; +struct _hypervCimType { + /* Parameter name */ + const char *name; + /* Parameter type */ + const char *type; + /* whether parameter is an array type */ + bool isArray; +}; + typedef struct _hypervWmiClassInfo hypervWmiClassInfo; typedef hypervWmiClassInfo *hypervWmiClassInfoPtr; struct _hypervWmiClassInfo { @@ -109,6 +126,8 @@ struct _hypervWmiClassInfo { const char *resourceUri; /* The wsman serializer info - one of the *_TypeInfo structs */ XmlSerializerInfo *serializerInfo; + /* Property type information */ + hypervCimTypePtr propertyInfo; }; =20 =20 diff --git a/src/hyperv/hyperv_wmi_generator.py b/src/hyperv/hyperv_wmi_gen= erator.py index 9aee0b9..9c0acce 100755 --- a/src/hyperv/hyperv_wmi_generator.py +++ b/src/hyperv/hyperv_wmi_generator.py @@ -122,6 +122,14 @@ class WmiClass: =20 source +=3D "SER_END_ITEMS(%s_Data);\n\n" % cls.name =20 + # also generate typemap data while we're here + source +=3D "hypervCimType %s_Typemap[] =3D {\n" % cls.name + + for property in cls.properties: + source +=3D property.generate_typemap() + source +=3D ' { "", "", 0 },\n' # null terminated + source +=3D '};\n\n' + =20 source +=3D self._define_WmiInfo_struct() source +=3D "\n\n" @@ -222,7 +230,8 @@ class WmiClass: source +=3D " .version =3D NULL,\n" source +=3D " .rootUri =3D %s,\n" % cls.uri_info.ro= otUri source +=3D " .resourceUri =3D %s_RESOURCE_URI,\n" = % cls.name.upper() - source +=3D " .serializerInfo =3D %s_Data_TypeInfo\= n" % cls.name + source +=3D " .serializerInfo =3D %s_Data_TypeInfo,= \n" % cls.name + source +=3D " .propertyInfo =3D %s_Typemap\n" % cls= .name source +=3D " },\n" =20 source +=3D " }\n" @@ -374,6 +383,10 @@ class Property: % (Property.typemap[self.type], class_name.upper(), sel= f.name) =20 =20 + def generate_typemap(self): + return ' { "%s", "%s", %s },\n' % (self.name, self.type.lower()= , str(self.is_array).lower()) + + =20 def open_and_print(filename): if filename.startswith("./"): --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue Apr 30 19:20:28 2024 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 1498590854120598.908952418257; Tue, 27 Jun 2017 12:14:14 -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 1F88EB9ABF; Tue, 27 Jun 2017 19:14:11 +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 DFC43176C4; Tue, 27 Jun 2017 19:14:10 +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 9733D1841C41; Tue, 27 Jun 2017 19:14:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v5RJDjqj010622 for ; Tue, 27 Jun 2017 15:13:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id B8DA781D27; Tue, 27 Jun 2017 19:13:45 +0000 (UTC) Received: from mx1.redhat.com (ext-mx10.extmail.prod.ext.phx2.redhat.com [10.5.110.39]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AEE1F81D23 for ; Tue, 27 Jun 2017 19:13:42 +0000 (UTC) Received: from mail-qt0-f177.google.com (mail-qt0-f177.google.com [209.85.216.177]) (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 3B99661BAA for ; Tue, 27 Jun 2017 19:13:40 +0000 (UTC) Received: by mail-qt0-f177.google.com with SMTP id 32so32768076qtv.1 for ; Tue, 27 Jun 2017 12:13:40 -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.37 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Jun 2017 12:13:37 -0700 (PDT) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1F88EB9ABF Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=datto.com Authentication-Results: ext-mx02.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 1F88EB9ABF 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="zS2zpR1j" DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3B99661BAA Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=datto.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=sramanujam@datto.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 3B99661BAA 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=tHuYRSodg/gelNxYSYq9dzS4mAxg8IA5tju9/asKWSw=; b=zS2zpR1ji3f5UR8d8fffHqdLhYhAtBn6g39TPf/rz5ejnJw8yVnE+W+/gk6txU3Tri kBRrjsF6LM2/rFsXddlffEKSzVPkxnSBduh9ClGmywnHLXkQi4r+v9qFVu22T6bOykqw jsNkwAgo5TF8yiI2EA6gSVMhgh41IhcNFdjM6tFAxOdWx7hzJkRMUpmBnMR1yZsvG7o6 almCXTjXGjYYap3Ia+r34ePj9VPr3nGkxcxpuCE3iWgLawimuHUoiL4EzWm/8F6PzFVJ O7svfsSFIav0zkbz0TvVGA7x5EJhA+WY4SbnMwSS41+dBAmTyEAJi1fxsVgovboiKBLd KiAQ== 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=tHuYRSodg/gelNxYSYq9dzS4mAxg8IA5tju9/asKWSw=; b=IzHhD8aXWBXZXv4drGUMr7J4ZjUcYtcUKWHrcaxilO6JwJPICVCwB/K0drgzRyhTkD d6kZ0MMQILpYWwClG0vDtm1Jnbu5Iq7XB4AJUkHgj+abCl/lz6+7hBN2OBsHQy/K2LBK EiYxy+CYTnJU/QviYmgafdo9NozUAQwJIuk4THH2s2dqn9NSuiWvWOETU/5yVER0bjrb vTdDKyVDZzKZpo0VfW4DaqUMUXUKW//C3nrh2kV96EbWeA0UFjb8/HRvKGKx2IFowccC +jYy4e480nlPxOcWwA+tWOD127CnjZNE5ihrMIjYOJb6yTVGaRaAygOBs/FyKYLCKfxU UFFg== X-Gm-Message-State: AKS2vOz8+zdYVhLw9YyD955NVVffYJ1sQEHg6GT3RYq4M2FcXqTR0qwp ZkeBDazDzNBC2a8nsno= X-Received: by 10.237.37.174 with SMTP id x43mr8793157qtc.133.1498590818786; Tue, 27 Jun 2017 12:13:38 -0700 (PDT) From: Sri Ramanujam To: libvir-list@redhat.com Date: Tue, 27 Jun 2017 15:13:25 -0400 Message-Id: <20170627191328.31072-4-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.39]); Tue, 27 Jun 2017 19:13:40 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 27 Jun 2017 19:13:40 +0000 (UTC) for IP:'209.85.216.177' DOMAIN:'mail-qt0-f177.google.com' HELO:'mail-qt0-f177.google.com' FROM:'sramanujam@datto.com' RCPT:'' X-RedHat-Spam-Score: 1.969 * (BAYES_50, DCC_CHECK, 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.177 mail-qt0-f177.google.com 209.85.216.177 mail-qt0-f177.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.39 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v7 3/6] hyperv: add hypervInvokeMethod 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.26]); Tue, 27 Jun 2017 19:14:11 +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 invoking methods on remote objects via hypervInvokeMethod. --- src/hyperv/hyperv_wmi.c | 590 ++++++++++++++++++++++++++++++++++++++++++++= ++++ src/hyperv/hyperv_wmi.h | 8 +- src/hyperv/openwsman.h | 4 + 3 files changed, 600 insertions(+), 2 deletions(-) diff --git a/src/hyperv/hyperv_wmi.c b/src/hyperv/hyperv_wmi.c index 2732db3..f944b14 100644 --- a/src/hyperv/hyperv_wmi.c +++ b/src/hyperv/hyperv_wmi.c @@ -24,6 +24,7 @@ */ =20 #include +#include =20 #include "internal.h" #include "virerror.h" @@ -34,11 +35,16 @@ #include "hyperv_private.h" #include "hyperv_wmi.h" #include "virstring.h" +#include "openwsman.h" +#include "virlog.h" =20 #define WS_SERIALIZER_FREE_MEM_WORKS 0 =20 #define VIR_FROM_THIS VIR_FROM_HYPERV =20 +#define HYPERV_JOB_TIMEOUT_MS 5000 + +VIR_LOG_INIT("hyperv.hyperv_wmi"); =20 static int hypervGetWmiClassInfo(hypervPrivate *priv, hypervWmiClassInfoListPtr list, @@ -405,6 +411,590 @@ hypervFreeEmbeddedParam(virHashTablePtr p) virHashFree(p); } =20 +/* + * Serializing parameters to XML and invoking methods + */ + +static int +hypervGetCimTypeInfo(hypervCimTypePtr typemap, const char *name, + hypervCimTypePtr *property) +{ + size_t i =3D 0; + while (typemap[i].name[0] !=3D '\0') { + if (STREQ(typemap[i].name, name)) { + *property =3D &typemap[i]; + return 0; + } + i++; + } + + return -1; +} + + +static int +hypervCreateInvokeXmlDoc(hypervInvokeParamsListPtr params, WsXmlDocH *docR= oot) +{ + int result =3D -1; + char *method =3D NULL; + WsXmlNodeH xmlNodeMethod =3D NULL; + + if (virAsprintf(&method, "%s_INPUT", params->method) < 0) + goto cleanup; + + *docRoot =3D ws_xml_create_doc(NULL, method); + if (*docRoot =3D=3D NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Could not instantiate XML document")); + goto cleanup; + } + + xmlNodeMethod =3D xml_parser_get_root(*docRoot); + if (xmlNodeMethod =3D=3D NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Could not get root node of XML document")); + goto cleanup; + } + + /* add resource URI as namespace */ + ws_xml_set_ns(xmlNodeMethod, params->resourceUri, "p"); + + result =3D 0; + + cleanup: + if (result < 0 && *docRoot !=3D NULL) { + ws_xml_destroy_doc(*docRoot); + *docRoot =3D NULL; + } + VIR_FREE(method); + return result; +} + +static int +hypervSerializeSimpleParam(hypervParamPtr p, const char *resourceUri, + WsXmlNodeH *methodNode) +{ + WsXmlNodeH xmlNodeParam =3D NULL; + + xmlNodeParam =3D ws_xml_add_child(*methodNode, resourceUri, + p->simple.name, p->simple.value); + if (xmlNodeParam =3D=3D NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Could not create simple param")); + return -1; + } + + return 0; +} + +static int +hypervSerializeEprParam(hypervParamPtr p, hypervPrivate *priv, + const char *resourceUri, WsXmlDocH doc, WsXmlNodeH *methodNode) +{ + int result =3D -1; + WsXmlNodeH xmlNodeParam =3D NULL, + xmlNodeTemp =3D NULL, + xmlNodeAddr =3D NULL, + xmlNodeRef =3D NULL; + xmlNodePtr xmlNodeAddrPtr =3D NULL, + xmlNodeRefPtr =3D NULL; + WsXmlDocH xmlDocResponse =3D NULL; + xmlDocPtr docPtr =3D (xmlDocPtr) doc->parserDoc; + WsXmlNsH ns =3D NULL; + client_opt_t *options =3D NULL; + filter_t *filter =3D NULL; + char *enumContext =3D NULL; + char *query_string =3D NULL; + + /* init and set up options */ + options =3D wsmc_options_init(); + if (!options) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not init opt= ions")); + goto cleanup; + } + wsmc_set_action_option(options, FLAG_ENUMERATION_ENUM_EPR); + + /* Get query and create filter based on it */ + if (virBufferCheckError(p->epr.query) < 0) { + virBufferFreeAndReset(p->epr.query); + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid query")); + goto cleanup; + } + query_string =3D virBufferContentAndReset(p->epr.query); + + filter =3D filter_create_simple(WSM_WQL_FILTER_DIALECT, query_string); + if (!filter) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not create W= QL filter")); + goto cleanup; + } + + /* enumerate based on the filter from this query */ + xmlDocResponse =3D wsmc_action_enumerate(priv->client, p->epr.info->ro= otUri, + options, filter); + if (hypervVerifyResponse(priv->client, xmlDocResponse, "enumeration") = < 0) + goto cleanup; + + /* Get context */ + enumContext =3D wsmc_get_enum_context(xmlDocResponse); + ws_xml_destroy_doc(xmlDocResponse); + + /* Pull using filter and enum context */ + xmlDocResponse =3D wsmc_action_pull(priv->client, resourceUri, options, + filter, enumContext); + + if (hypervVerifyResponse(priv->client, xmlDocResponse, "pull") < 0) + goto cleanup; + + /* drill down and extract EPR node children */ + if (!(xmlNodeTemp =3D ws_xml_get_soap_body(xmlDocResponse))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not get SOAP= body")); + goto cleanup; + } + + if (!(xmlNodeTemp =3D ws_xml_get_child(xmlNodeTemp, 0, XML_NS_ENUMERAT= ION, + WSENUM_PULL_RESP))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not get resp= onse")); + goto cleanup; + } + + if (!(xmlNodeTemp =3D ws_xml_get_child(xmlNodeTemp, 0, XML_NS_ENUMERAT= ION, WSENUM_ITEMS))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not get resp= onse items")); + goto cleanup; + } + + if (!(xmlNodeTemp =3D ws_xml_get_child(xmlNodeTemp, 0, XML_NS_ADDRESSI= NG, WSA_EPR))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not get EPR = items")); + goto cleanup; + } + + if (!(xmlNodeAddr =3D ws_xml_get_child(xmlNodeTemp, 0, XML_NS_ADDRESSI= NG, + WSA_ADDRESS))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not get EPR = address")); + goto cleanup; + } + + if (!(xmlNodeAddrPtr =3D xmlDocCopyNode((xmlNodePtr) xmlNodeAddr, docP= tr, 1))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not copy EPR= address")); + goto cleanup; + } + + if (!(xmlNodeRef =3D ws_xml_get_child(xmlNodeTemp, 0, XML_NS_ADDRESSIN= G, + WSA_REFERENCE_PARAMETERS))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Could not lookup EPR item reference parameters")); + goto cleanup; + } + + if (!(xmlNodeRefPtr =3D xmlDocCopyNode((xmlNodePtr) xmlNodeRef, docPtr= , 1))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Could not copy EPR item reference parameters")); + goto cleanup; + } + + /* now build a new xml doc with the EPR node children */ + if (!(xmlNodeParam =3D ws_xml_add_child(*methodNode, resourceUri, + p->epr.name, NULL))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Could not add child node to xmlNodeParam")); + goto cleanup; + } + + if (!(ns =3D ws_xml_ns_add(xmlNodeParam, + "http://schemas.xmlsoap.org/ws/2004/08/addressing", "a= "))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Could not set namespace address for xmlNodeParam")); + goto cleanup; + } + + if (!(ns =3D ws_xml_ns_add(xmlNodeParam, + "http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd", "w")= )) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Could not set wsman namespace address for xmlNodeParam"= )); + goto cleanup; + } + + if (xmlAddChild((xmlNodePtr) *methodNode, (xmlNodePtr) xmlNodeParam) = =3D=3D NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Could not add child to xml parent node")); + goto cleanup; + } + + if (xmlAddChild((xmlNodePtr) xmlNodeParam, xmlNodeAddrPtr) =3D=3D NULL= ) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Could not add child to xml parent node")); + goto cleanup; + } + + if (xmlAddChild((xmlNodePtr) xmlNodeParam, xmlNodeRefPtr) =3D=3D NULL)= { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Could not add child to xml parent node")); + goto cleanup; + } + + /* we did it! */ + result =3D 0; + + cleanup: + if (options !=3D NULL) + wsmc_options_destroy(options); + if (filter !=3D NULL) + filter_destroy(filter); + ws_xml_destroy_doc(xmlDocResponse); + VIR_FREE(enumContext); + VIR_FREE(query_string); + return result; +} + +static int +hypervSerializeEmbeddedParam(hypervParamPtr p, const char *resourceUri, + WsXmlNodeH *methodNode) +{ + int result =3D -1; + WsXmlNodeH xmlNodeInstance =3D NULL, + xmlNodeProperty =3D NULL, + xmlNodeParam =3D NULL, + xmlNodeArray =3D NULL; + WsXmlDocH xmlDocTemp =3D NULL, + xmlDocCdata =3D NULL; + xmlBufferPtr xmlBufferNode =3D NULL; + const xmlChar *xmlCharCdataContent =3D NULL; + xmlNodePtr xmlNodeCdata =3D NULL; + hypervWmiClassInfoPtr classInfo =3D p->embedded.info; + virHashKeyValuePairPtr items =3D NULL; + hypervCimTypePtr property =3D NULL; + ssize_t numKeys =3D -1; + int len =3D 0, i =3D 0; + + if (!(xmlNodeParam =3D ws_xml_add_child(*methodNode, resourceUri, p->e= mbedded.name, + NULL))) { + virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not add child node= %s"), + p->embedded.name); + goto cleanup; + } + + /* create the temp xml doc */ + + /* start with the INSTANCE node */ + if (!(xmlDocTemp =3D ws_xml_create_doc(NULL, "INSTANCE"))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Could not create temporary xml doc")); + goto cleanup; + } + + if (!(xmlNodeInstance =3D xml_parser_get_root(xmlDocTemp))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Could not get temp xml doc root")); + goto cleanup; + } + + /* add CLASSNAME node to INSTANCE node */ + if (!(ws_xml_add_node_attr(xmlNodeInstance, NULL, "CLASSNAME", + classInfo->name))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Could not add attribute to node")); + goto cleanup; + } + + /* retrieve parameters out of hash table */ + numKeys =3D virHashSize(p->embedded.table); + items =3D virHashGetItems(p->embedded.table, NULL); + if (!items) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Could not read embedded param hash table")); + goto cleanup; + } + + /* Add the parameters */ + for (i =3D 0; i < numKeys; i++) { + const char *name =3D items[i].key; + const char *value =3D items[i].value; + + if (value !=3D NULL) { + if (hypervGetCimTypeInfo(classInfo->propertyInfo, name, + &property) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Could not read type information")); + goto cleanup; + } + + if (!(xmlNodeProperty =3D ws_xml_add_child(xmlNodeInstance, NU= LL, + property->isArray ? "PROPERTY.ARRAY" : "PROPER= TY", + NULL))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Could not add child to XML node")); + goto cleanup; + } + + if (!(ws_xml_add_node_attr(xmlNodeProperty, NULL, "NAME", name= ))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Could not add attribute to XML node")); + goto cleanup; + } + + if (!(ws_xml_add_node_attr(xmlNodeProperty, NULL, "TYPE", prop= erty->type))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Could not add attribute to XML node")); + goto cleanup; + } + + /* If this attribute is an array, add VALUE.ARRAY node */ + if (property->isArray) { + if (!(xmlNodeArray =3D ws_xml_add_child(xmlNodeProperty, N= ULL, + "VALUE.ARRAY", NULL))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Could not add child to XML node")); + goto cleanup; + } + } + + /* add the child */ + if (!(ws_xml_add_child(property->isArray ? xmlNodeArray : xmlN= odeProperty, + NULL, "VALUE", value))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Could not add child to XML node")); + goto cleanup; + } + + xmlNodeArray =3D NULL; + xmlNodeProperty =3D NULL; + } + } + + /* create CDATA node */ + xmlBufferNode =3D xmlBufferCreate(); + if (xmlNodeDump(xmlBufferNode, (xmlDocPtr) xmlDocTemp->parserDoc, + (xmlNodePtr) xmlNodeInstance, 0, 0) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Could not get root of temp XML doc")); + goto cleanup; + } + + len =3D xmlBufferLength(xmlBufferNode); + xmlCharCdataContent =3D xmlBufferContent(xmlBufferNode); + if (!(xmlNodeCdata =3D xmlNewCDataBlock((xmlDocPtr) xmlDocCdata, + xmlCharCdataContent, len))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Could not create CDATA element")); + goto cleanup; + } + + /* Add CDATA node to the doc root */ + if (!(xmlAddChild((xmlNodePtr) xmlNodeParam, xmlNodeCdata))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Could not add CDATA to doc root")); + goto cleanup; + } + + /* we did it! */ + result =3D 0; + + cleanup: + VIR_FREE(items); + ws_xml_destroy_doc(xmlDocCdata); + ws_xml_destroy_doc(xmlDocTemp); + if (xmlBufferNode) + xmlBufferFree(xmlBufferNode); + return result; +} + + +/* + * hypervInvokeMethod: + * @priv: hypervPrivate object associated with the connection + * @params: object containing the all necessary information for method + * invocation + * @res: Optional out parameter to contain the response XML. + * + * Performs an invocation described by @params, and optionally returns the + * XML containing the result. Returns -1 on failure, 0 on success. + */ +int +hypervInvokeMethod(hypervPrivate *priv, hypervInvokeParamsListPtr params, + WsXmlDocH *res) +{ + int result =3D -1; + size_t i =3D 0; + int returnCode; + WsXmlDocH paramsDocRoot =3D NULL; + client_opt_t *options =3D NULL; + WsXmlDocH response =3D NULL; + WsXmlNodeH methodNode =3D NULL; + char *returnValue_xpath =3D NULL; + char *jobcode_instance_xpath =3D NULL; + char *returnValue =3D NULL; + char *instanceID =3D NULL; + bool completed =3D false; + virBuffer query =3D VIR_BUFFER_INITIALIZER; + Msvm_ConcreteJob *job =3D NULL; + int jobState =3D -1; + hypervParamPtr p =3D NULL; + int timeout =3D HYPERV_JOB_TIMEOUT_MS; + + if (hypervCreateInvokeXmlDoc(params, ¶msDocRoot) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Could not create XML document")); + goto cleanup; + } + + methodNode =3D xml_parser_get_root(paramsDocRoot); + if (!methodNode) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Could not get root of XML document")); + goto cleanup; + } + + /* Serialize parameters */ + for (i =3D 0; i < params->nbParams; i++) { + p =3D &(params->params[i]); + + switch (p->type) { + case HYPERV_SIMPLE_PARAM: + if (hypervSerializeSimpleParam(p, params->resourceUri, + &methodNode) < 0) + goto cleanup; + break; + case HYPERV_EPR_PARAM: + if (hypervSerializeEprParam(p, priv, params->resourceUri, + paramsDocRoot, &methodNode) < 0) + goto cleanup; + break; + case HYPERV_EMBEDDED_PARAM: + if (hypervSerializeEmbeddedParam(p, params->resourceUri, + &methodNode) < 0) + goto cleanup; + break; + default: + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Unknown parameter type")); + goto cleanup; + } + } + + /* Invoke the method and get the response */ + + options =3D wsmc_options_init(); + if (!options) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not init opt= ions")); + goto cleanup; + } + wsmc_add_selectors_from_str(options, params->selector); + + /* do the invoke */ + response =3D wsmc_action_invoke(priv->client, params->resourceUri, opt= ions, + params->method, paramsDocRoot); + + /* check return code of invocation */ + if (virAsprintf(&returnValue_xpath, "/s:Envelope/s:Body/p:%s_OUTPUT/p:= ReturnValue", + params->method) < 0) + goto cleanup; + + returnValue =3D ws_xml_get_xpath_value(response, returnValue_xpath); + if (!returnValue) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Could not get return value for %s invocation"), + params->method); + goto cleanup; + } + + if (virStrToLong_i(returnValue, NULL, 10, &returnCode) < 0) + goto cleanup; + + if (returnCode =3D=3D CIM_RETURNCODE_TRANSITION_STARTED) { + if (virAsprintf(&jobcode_instance_xpath, + "/s:Envelope/s:Body/p:%s_OUTPUT/p:Job/a:ReferenceParam= eters/" + "w:SelectorSet/w:Selector[@Name=3D'InstanceID']", + params->method) < 0) { + goto cleanup; + } + + instanceID =3D ws_xml_get_xpath_value(response, jobcode_instance_x= path); + if (!instanceID) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Could not get instance ID for %s invocation"= ), + params->method); + goto cleanup; + } + + /* + * Poll Hyper-V about the job until either the job completes or fa= ils, + * or 5 minutes have elapsed. + * + * Windows has its own timeout on running WMI method calls (it cal= ls + * these "jobs"), by default set to 1 minute. The administrator can + * change this to whatever they want, however, so we can't rely on= it. + * + * Therefore, to avoid waiting in this loop for a very long-runnin= g job + * to complete, we instead bail after 5 minutes no matter what. NO= TE that + * this does not mean that the remote job has terminated on the Wi= ndows + * side! That is up to Windows to control, we don't do anything ab= out it. + */ + while (!completed && timeout >=3D 0) { + virBufferAddLit(&query, MSVM_CONCRETEJOB_WQL_SELECT); + virBufferAsprintf(&query, "where InstanceID =3D \"%s\"", insta= nceID); + + if (hypervGetMsvmConcreteJobList(priv, &query, &job) < 0 + || job =3D=3D NULL) + goto cleanup; + + jobState =3D job->data.common->JobState; + switch (jobState) { + case MSVM_CONCRETEJOB_JOBSTATE_NEW: + case MSVM_CONCRETEJOB_JOBSTATE_STARTING: + case MSVM_CONCRETEJOB_JOBSTATE_RUNNING: + case MSVM_CONCRETEJOB_JOBSTATE_SHUTTING_DOWN: + hypervFreeObject(priv, (hypervObject *) job); + job =3D NULL; + usleep(100 * 1000); /* sleep 100 ms */ + timeout -=3D 100; + continue; + case MSVM_CONCRETEJOB_JOBSTATE_COMPLETED: + completed =3D true; + break; + case MSVM_CONCRETEJOB_JOBSTATE_TERMINATED: + case MSVM_CONCRETEJOB_JOBSTATE_KILLED: + case MSVM_CONCRETEJOB_JOBSTATE_EXCEPTION: + case MSVM_CONCRETEJOB_JOBSTATE_SERVICE: + goto cleanup; + default: + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Unknown invocation state")); + goto cleanup; + } + } + if (!completed && timeout < 0) { + virReportError(VIR_ERR_OPERATION_TIMEOUT, + _("Timeout waiting for %s invocation"), params->method= ); + goto cleanup; + } + } else if (returnCode !=3D CIM_RETURNCODE_COMPLETED_WITH_NO_ERROR) { + virReportError(VIR_ERR_INTERNAL_ERROR, _("Invocation of %s returne= d an error: %s (%d)"), + params->method, hypervReturnCodeToString(returnCode), + returnCode); + goto cleanup; + } + + if (res) + *res =3D response; + + result =3D 0; + + cleanup: + if (options) + wsmc_options_destroy(options); + if (response && (!res)) + ws_xml_destroy_doc(response); + if (paramsDocRoot) + ws_xml_destroy_doc(paramsDocRoot); + VIR_FREE(returnValue_xpath); + VIR_FREE(jobcode_instance_xpath); + VIR_FREE(returnValue); + VIR_FREE(instanceID); + virBufferFreeAndReset(&query); + hypervFreeObject(priv, (hypervObject *) job); + hypervFreeInvokeParams(params); + return result; +} + /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *= * * * Object */ diff --git a/src/hyperv/hyperv_wmi.h b/src/hyperv/hyperv_wmi.h index 54ce5b1..25cc470 100644 --- a/src/hyperv/hyperv_wmi.h +++ b/src/hyperv/hyperv_wmi.h @@ -95,14 +95,14 @@ typedef struct _hypervSimpleParam hypervSimpleParam; struct _hypervEprParam { const char *name; virBufferPtr query; - hypervWmiClassInfoPtr info; // info of the object this param represents + hypervWmiClassInfoPtr info; /* info of the object this param represent= s */ }; typedef struct _hypervEprParam hypervEprParam; =20 struct _hypervEmbeddedParam { const char *name; virHashTablePtr table; - hypervWmiClassInfoPtr info; // info of the object this param represents + hypervWmiClassInfoPtr info; /* info of the object this param represent= s */ }; typedef struct _hypervEmbeddedParam hypervEmbeddedParam; =20 @@ -152,6 +152,10 @@ int hypervAddEmbeddedParam(hypervInvokeParamsListPtr p= arams, hypervPrivate *priv const char *name, virHashTablePtr table, hypervWmiClassInfoListPtr= info); =20 void hypervFreeEmbeddedParam(virHashTablePtr p); + +int hypervInvokeMethod(hypervPrivate *priv, hypervInvokeParamsListPtr para= ms, + WsXmlDocH *res); + /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *= * * * CIM/Msvm_ReturnCode */ diff --git a/src/hyperv/openwsman.h b/src/hyperv/openwsman.h index f66ed86..fc2958f 100644 --- a/src/hyperv/openwsman.h +++ b/src/hyperv/openwsman.h @@ -43,4 +43,8 @@ # define SER_NS_INT64(ns, n, x) SER_NS_INT64_FLAGS(ns, n, x, 0) # endif =20 +/* wsman-xml.h */ +WsXmlDocH ws_xml_create_doc(const char *rootNsUri, const char *rootName); +WsXmlNodeH xml_parser_get_root(WsXmlDocH doc); + #endif /* __OPENWSMAN_H__ */ --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue Apr 30 19:20:28 2024 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 From nobody Tue Apr 30 19:20:28 2024 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 1498590844328711.585069738721; Tue, 27 Jun 2017 12:14:04 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 54D2F3D96D; Tue, 27 Jun 2017 19:14:02 +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 ECEF25C6F3; Tue, 27 Jun 2017 19:14:01 +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 679061853E31; Tue, 27 Jun 2017 19:14:01 +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 v5RJDiIp010601 for ; Tue, 27 Jun 2017 15:13:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1498517C7F; Tue, 27 Jun 2017 19:13:44 +0000 (UTC) Received: from mx1.redhat.com (ext-mx02.extmail.prod.ext.phx2.redhat.com [10.5.110.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0D2E417C65 for ; Tue, 27 Jun 2017 19:13:44 +0000 (UTC) Received: from mail-qk0-f178.google.com (mail-qk0-f178.google.com [209.85.220.178]) (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 A41E5A022B for ; Tue, 27 Jun 2017 19:13:42 +0000 (UTC) Received: by mail-qk0-f178.google.com with SMTP id d78so33464258qkb.1 for ; Tue, 27 Jun 2017 12:13:42 -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.40 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Jun 2017 12:13:40 -0700 (PDT) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 54D2F3D96D 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=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 54D2F3D96D 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="wTB3vpqu" DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A41E5A022B Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=datto.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=sramanujam@datto.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A41E5A022B 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=MLbpwPEFAZIWbNeeT8DV+GURaL0aTxzz9ck33E3hcSQ=; b=wTB3vpqupHMAA4sqngrjPwsszfhQq1RU1fQtE2Gcjs/k8ptZfI9j5bMf+nu6rmH67d PezDz1mhUpdrnXwxAJ4kg/H9gkdDlfImnLflZiZzgg8F2M5Tu7EBS+QUHqgWjcYynqiV WSTGU9mFW0U5d9Wq+yjhZceGM9ra5IBTLUrD61ETf4EtuHG2ImeKc6IVfsrxiA6rGnB5 hLjXHiZjz0WcC4M9e/ehPuTQEa0DMZ+EQH2o/KUiWo80oRbqsnurpBRLnfn8xq53uGZD dciTGuGOeJxgenB5aI055H5nk7r5jJsTBSutn6cr9TVV043TXCF7AUO5e78dKQwWhmE3 48hg== 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=MLbpwPEFAZIWbNeeT8DV+GURaL0aTxzz9ck33E3hcSQ=; b=oxuV+TqwsiU9Q4y+rBNhElA0JTtvMsBaxo6i1J6MhEcYCoYJW8DZfSFbwly1c3U27y lZDgzQVasFuoU65shMRCqX2GgXe/cj0XrRaWWVo2oK6gyMIp418sJXiiGmCikQ/DDdUu 2awZn+ekpQqKdcLwj0+vchPRPFgPPvZE8Li7oJxfykgFIDU9+x2hXX6dw6W3pMBE4fWg RsOZKgdeN5sYpw/NaMBC1FQ2PC1nMBs6vXbSIB6F1hLgpIrxJX7V6T9rml7zhZtiS5x8 dq/DZwrk7Nw8KmY+pRaoETQldmejx5ebi9oZxuiPoBnbPmrYrIXgH24h5LNArNMQ1jYn 58Lw== X-Gm-Message-State: AKS2vOzy7ZrTQycAA9FIiHVM8XKM3kFl+sSY3Y1XTuoXNEtcVNo8ySPo Ha9L3VT4QrnLm/u83sE= X-Received: by 10.233.235.201 with SMTP id b192mr8682836qkg.138.1498590821511; Tue, 27 Jun 2017 12:13:41 -0700 (PDT) From: Sri Ramanujam To: libvir-list@redhat.com Date: Tue, 27 Jun 2017 15:13:27 -0400 Message-Id: <20170627191328.31072-6-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.26]); Tue, 27 Jun 2017 19:13:42 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 27 Jun 2017 19:13:42 +0000 (UTC) for IP:'209.85.220.178' DOMAIN:'mail-qk0-f178.google.com' HELO:'mail-qk0-f178.google.com' FROM:'sramanujam@datto.com' RCPT:'' X-RedHat-Spam-Score: 1.969 * (BAYES_50, DCC_CHECK, 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.220.178 mail-qk0-f178.google.com 209.85.220.178 mail-qk0-f178.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.26 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v7 5/6] hyperv: Add support for virDomainSetMemory 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 27 Jun 2017 19:14:03 +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" Introduces support for virDomainSetMemory. This also serves an an example for how to use the new method invocation API with a more complicated method, this time including an EPR and embedded param. --- src/hyperv/hyperv_driver.c | 114 ++++++++++++++++++++++++++++++= ++++ src/hyperv/hyperv_wmi.c | 51 +++++++++++++++ src/hyperv/hyperv_wmi.h | 11 ++++ src/hyperv/hyperv_wmi_generator.input | 30 +++++++++ 4 files changed, 206 insertions(+) diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c index 7ee3d9a..a069afd 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -1497,6 +1497,118 @@ hypervDomainSendKey(virDomainPtr domain, unsigned i= nt codeset, } =20 =20 +static int +hypervDomainSetMemoryFlags(virDomainPtr domain, unsigned long memory, + unsigned int flags) +{ + int result =3D -1; + char uuid_string[VIR_UUID_STRING_BUFLEN]; + hypervPrivate *priv =3D domain->conn->privateData; + char *memory_str =3D NULL; + hypervInvokeParamsListPtr params =3D NULL; + unsigned long memory_mb =3D VIR_ROUND_UP(VIR_DIV_UP(memory, 1024), 2); + Msvm_VirtualSystemSettingData *vssd =3D NULL; + Msvm_MemorySettingData *memsd =3D NULL; + virBuffer eprQuery =3D VIR_BUFFER_INITIALIZER; + virHashTablePtr memResource =3D NULL; + + virCheckFlags(0, -1); + + if (virAsprintf(&memory_str, "%lu", memory_mb) < 0) + goto cleanup; + + virUUIDFormat(domain->uuid, uuid_string); + + if (hypervGetMsvmVirtualSystemSettingDataFromUUID(priv, uuid_string, &= vssd) < 0) + goto cleanup; + + if (hypervGetMsvmMemorySettingDataFromVSSD(priv, vssd->data.common->In= stanceID, + &memsd) < 0) + goto cleanup; + + if (priv->wmiVersion =3D=3D HYPERV_WMI_VERSION_V1) { + params =3D hypervCreateInvokeParamsList(priv, "ModifyVirtualSystem= Resources", + MSVM_VIRTUALSYSTEMMANAGEMENTSERVICE_SELECTOR, + Msvm_VirtualSystemManagementService_WmiInfo); + + if (!params) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not crea= te params")); + goto cleanup; + } + + virBufferAddLit(&eprQuery, MSVM_COMPUTERSYSTEM_WQL_SELECT); + virBufferAsprintf(&eprQuery, "where Name =3D \"%s\"", uuid_string); + + if (hypervAddEprParam(params, "ComputerSystem", priv, &eprQuery, + Msvm_ComputerSystem_WmiInfo) < 0) + goto params_cleanup; + } else if (priv->wmiVersion =3D=3D HYPERV_WMI_VERSION_V2) { + params =3D hypervCreateInvokeParamsList(priv, "ModifyResourceSetti= ngs", + MSVM_VIRTUALSYSTEMMANAGEMENTSERVICE_SELECTOR, + Msvm_VirtualSystemManagementService_WmiInfo); + + if (!params) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not crea= te params")); + goto cleanup; + } + } + + memResource =3D hypervCreateEmbeddedParam(priv, Msvm_MemorySettingData= _WmiInfo); + if (!memResource) + goto params_cleanup; + + if (hypervSetEmbeddedProperty(memResource, "VirtualQuantity", memory_s= tr) < 0) { + hypervFreeEmbeddedParam(memResource); + goto params_cleanup; + } + + if (hypervSetEmbeddedProperty(memResource, "InstanceID", + memsd->data.common->InstanceID) < 0) { + hypervFreeEmbeddedParam(memResource); + goto params_cleanup; + } + + if (priv->wmiVersion =3D=3D HYPERV_WMI_VERSION_V1) { + if (hypervAddEmbeddedParam(params, priv, "ResourceSettingData", + memResource, Msvm_MemorySettingData_WmiInfo) < 0) { + hypervFreeEmbeddedParam(memResource); + goto params_cleanup; + } + + } else if (priv->wmiVersion =3D=3D HYPERV_WMI_VERSION_V2) { + if (hypervAddEmbeddedParam(params, priv, "ResourceSettings", + memResource, Msvm_MemorySettingData_WmiInfo) < 0) { + hypervFreeEmbeddedParam(memResource); + goto params_cleanup; + } + } + + if (hypervInvokeMethod(priv, params, NULL) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not set memo= ry")); + goto cleanup; + } + + result =3D 0; + goto cleanup; + + params_cleanup: + hypervFreeInvokeParams(params); + virBufferFreeAndReset(&eprQuery); + cleanup: + VIR_FREE(memory_str); + hypervFreeObject(priv, (hypervObject *) vssd); + hypervFreeObject(priv, (hypervObject *) memsd); + return result; +} + + +static int +hypervDomainSetMemory(virDomainPtr domain, unsigned long memory) +{ + return hypervDomainSetMemoryFlags(domain, memory, 0); +} + + static virHypervisorDriver hypervHypervisorDriver =3D { .name =3D "Hyper-V", .connectOpen =3D hypervConnectOpen, /* 0.9.5 */ @@ -1531,6 +1643,8 @@ static virHypervisorDriver hypervHypervisorDriver =3D= { .domainHasManagedSaveImage =3D hypervDomainHasManagedSaveImage, /* 0.9= .5 */ .domainManagedSaveRemove =3D hypervDomainManagedSaveRemove, /* 0.9.5 */ .domainSendKey =3D hypervDomainSendKey, /* TODO: version */ + .domainSetMemory =3D hypervDomainSetMemory, /* TODO: version */ + .domainSetMemoryFlags =3D hypervDomainSetMemoryFlags, /* TODO: version= */ .connectIsAlive =3D hypervConnectIsAlive, /* 0.9.8 */ }; =20 diff --git a/src/hyperv/hyperv_wmi.c b/src/hyperv/hyperv_wmi.c index 36d3c2e..8a61703 100644 --- a/src/hyperv/hyperv_wmi.c +++ b/src/hyperv/hyperv_wmi.c @@ -1635,3 +1635,54 @@ hypervMsvmComputerSystemFromDomain(virDomainPtr doma= in, =20 return 0; } + + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *= * * + * Msvm_VirtualSystemSettingData + */ + +int +hypervGetMsvmVirtualSystemSettingDataFromUUID(hypervPrivate *priv, + const char *uuid_string, Msvm_VirtualSystemSettingData **list) +{ + virBuffer query =3D VIR_BUFFER_INITIALIZER; + + virBufferAsprintf(&query, + "associators of " + "{Msvm_ComputerSystem.CreationClassName=3D\"Msvm_ComputerSyste= m\"," + "Name=3D\"%s\"} " + "where AssocClass =3D Msvm_SettingsDefineState " + "ResultClass =3D Msvm_VirtualSystemSettingData", + uuid_string); + + if (hypervGetWmiClassList(priv, Msvm_VirtualSystemSettingData_WmiInfo,= &query, + (hypervObject **) list) < 0 || *list =3D=3D NULL) + return -1; + + return 0; +} + + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *= * * + * Msvm_MemorySettingData + */ + +int +hypervGetMsvmMemorySettingDataFromVSSD(hypervPrivate *priv, + const char *vssd_instanceid, Msvm_MemorySettingData **list) +{ + virBuffer query =3D VIR_BUFFER_INITIALIZER; + + virBufferAsprintf(&query, + "associators of " + "{Msvm_VirtualSystemSettingData.InstanceID=3D\"%s\"} " + "where AssocClass =3D Msvm_VirtualSystemSettingDataComponent " + "ResultClass =3D Msvm_MemorySettingData", + vssd_instanceid); + + if (hypervGetWmiClassList(priv, Msvm_MemorySettingData_WmiInfo, &query, + (hypervObject **) list) < 0 || *list =3D=3D NULL) + return -1; + + return 0; +} diff --git a/src/hyperv/hyperv_wmi.h b/src/hyperv/hyperv_wmi.h index 5c9da04..cc53078 100644 --- a/src/hyperv/hyperv_wmi.h +++ b/src/hyperv/hyperv_wmi.h @@ -35,6 +35,9 @@ =20 # define HYPERV_DEFAULT_PARAM_COUNT 5 =20 +# define MSVM_VIRTUALSYSTEMMANAGEMENTSERVICE_SELECTOR \ + "CreationClassName=3DMsvm_VirtualSystemManagementService" + int hypervVerifyResponse(WsManClient *client, WsXmlDocH response, const char *detail); =20 @@ -212,6 +215,10 @@ int hypervGetMsvmVirtualSystemSettingDataList(hypervPr= ivate *priv, virBufferPtr query, Msvm_VirtualSystemSettingDat= a **list); =20 +int hypervGetMsvmVirtualSystemSettingDataFromUUID(hypervPrivate *priv, + const char *uuid_string, + Msvm_VirtualSystemSettin= gData **list); + int hypervGetMsvmProcessorSettingDataList(hypervPrivate *priv, virBufferPtr query, Msvm_ProcessorSettingData **list= ); @@ -219,6 +226,10 @@ int hypervGetMsvmProcessorSettingDataList(hypervPrivat= e *priv, int hypervGetMsvmMemorySettingDataList(hypervPrivate *priv, virBufferPtr q= uery, Msvm_MemorySettingData **list); =20 +int hypervGetMsvmMemorySettingDataFromVSSD(hypervPrivate *priv, + const char *vssd_instanceid, + Msvm_MemorySettingData **list); + int hypervGetMsvmKeyboardList(hypervPrivate *priv, virBufferPtr query, Msvm_Keyboard **list); =20 diff --git a/src/hyperv/hyperv_wmi_generator.input b/src/hyperv/hyperv_wmi_= generator.input index 4ccda04..da19765 100644 --- a/src/hyperv/hyperv_wmi_generator.input +++ b/src/hyperv/hyperv_wmi_generator.input @@ -787,6 +787,36 @@ class Msvm_VirtualSystemManagementService boolean Started end =20 +class v2/Msvm_VirtualSystemManagementService + 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 PrimaryOwnerName + string PrimaryOwnerContact + string StartMode + boolean Started +end =20 class Msvm_VirtualSystemGlobalSettingData string Caption --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue Apr 30 19:20:28 2024 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 1498590829574305.0246948129052; Tue, 27 Jun 2017 12:13:49 -0700 (PDT) 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 434D714287C; Tue, 27 Jun 2017 19:13:47 +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 EE45F95348; Tue, 27 Jun 2017 19:13:46 +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 9CB8241F63; Tue, 27 Jun 2017 19:13:46 +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 v5RJDieW010612 for ; Tue, 27 Jun 2017 15:13:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id D30C35DC1F; Tue, 27 Jun 2017 19:13:44 +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 CE9E317C7F for ; Tue, 27 Jun 2017 19:13:44 +0000 (UTC) Received: from mail-qt0-f171.google.com (mail-qt0-f171.google.com [209.85.216.171]) (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 0AD6B40F14 for ; Tue, 27 Jun 2017 19:13:44 +0000 (UTC) Received: by mail-qt0-f171.google.com with SMTP id f92so32663304qtb.2 for ; Tue, 27 Jun 2017 12:13:43 -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.41 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Jun 2017 12:13:41 -0700 (PDT) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 434D714287C Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=datto.com Authentication-Results: ext-mx10.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 434D714287C 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="kewEsWt7" DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0AD6B40F14 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=sramanujam@datto.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 0AD6B40F14 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=PXSd/M2T087v+dXgb1WJNblH27V/aJYGkcvrzERTJtw=; b=kewEsWt7Mw0+BDkc8SrjNeCC2VK3SzmbFYA3XdKLixjyoXHskp2JmzB8OVZg9KUjQR 3Vp3aVu7flpbxzrnI1LfAleiWMMQl8d3SHptrnqZiMUriXGWNIuYHL/hcnE/oqEF4bmT HzQv7aoA1L/DmpEkn9oV1AR3cQd0JJgZ2LttkAo3osuwC9bMyscC/cGqx+t7ZTXPsW5y 4603IxVPT6yxf63Nas4DNSAJCmrXRPvBwXmPjGaIArkp4EG4SIotULCYQYD4QdYJrQ9x a/9LzK6X1aExGskwLHXSmwWcHKOg1Zmv9yfJYzSqBSofVtmPqOPDwEjj2U2aPSzFA1PB kVDw== 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=PXSd/M2T087v+dXgb1WJNblH27V/aJYGkcvrzERTJtw=; b=TCt1DAjPe4TqhEMcSgiF3s3EvqLMHU3gGNSwsni6mDZyIum9w44PliByyZT3yB2d9l SLK93f1V49CcmiMRINabbGuOEvnCOa9A1M1DWCRvLvbxPnolgnkF2IweoZzxbXtV/Sju N90ZzLFqQaMt66+UdvY6E2XuNSJGTzhBXIlgkiHol7ry9wVcb4j6Ms22g2wIdi6iA396 /1+lKXL6pHUHciJx81c336sJ/3BMMIzKBvf1r1+Vph0wGG246IQ37sGvKvwqO3Gm+Uap EO1KB7D5PeTH4GtyNf8Mnw02AOqPcRleHoE+/XGGL4qtFinU0JZ53ZrckFoWvZRqmOMO 0w8A== X-Gm-Message-State: AKS2vOwVhU1H8r3Pq3KqENgR/5w/oGwIYNyx42DXNvS77ddEUN3q3Eyw VHa29T8wIL45s294KXY= X-Received: by 10.200.36.70 with SMTP id d6mr1238992qtd.42.1498590823040; Tue, 27 Jun 2017 12:13:43 -0700 (PDT) From: Sri Ramanujam To: libvir-list@redhat.com Date: Tue, 27 Jun 2017 15:13:28 -0400 Message-Id: <20170627191328.31072-7-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.30]); Tue, 27 Jun 2017 19:13:44 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 27 Jun 2017 19:13:44 +0000 (UTC) for IP:'209.85.216.171' DOMAIN:'mail-qt0-f171.google.com' HELO:'mail-qt0-f171.google.com' FROM:'sramanujam@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.171 mail-qt0-f171.google.com 209.85.216.171 mail-qt0-f171.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.30 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v7 6/6] news: Update news for new Hyper-V APIs 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 27 Jun 2017 19:13:48 +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" --- docs/news.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/news.xml b/docs/news.xml index 27562e1..77d167c 100644 --- a/docs/news.xml +++ b/docs/news.xml @@ -48,6 +48,11 @@
+ + + hyperv: Implement virDomainSetMemory and virDomainSendKey APIs + +
--=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list