From nobody Sat Apr 27 18:58:27 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 1492468593952172.38123524194168; Mon, 17 Apr 2017 15:36:33 -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 1DD3E8124D; Mon, 17 Apr 2017 22:36:31 +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 4CFDD176A8; Mon, 17 Apr 2017 22:36:30 +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 A1F5B18523C6; Mon, 17 Apr 2017 22:36:28 +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 v3HMaQZg017989 for ; Mon, 17 Apr 2017 18:36:26 -0400 Received: by smtp.corp.redhat.com (Postfix) id CC43817D22; Mon, 17 Apr 2017 22:36:26 +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 C44C05DC19 for ; Mon, 17 Apr 2017 22:36:25 +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 CE70461BAD for ; Mon, 17 Apr 2017 22:36:22 +0000 (UTC) Received: by mail-qt0-f171.google.com with SMTP id c45so112103768qtb.1 for ; Mon, 17 Apr 2017 15:36:22 -0700 (PDT) Received: from silas.datto.lan ([47.19.105.250]) by smtp.gmail.com with ESMTPSA id m62sm5751088qte.5.2017.04.17.15.36.21 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Apr 2017 15:36:21 -0700 (PDT) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1DD3E8124D Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=datto.com Authentication-Results: ext-mx01.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 1DD3E8124D 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="iYgPygej" DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CE70461BAD 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 CE70461BAD 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=dhOviQvszTRipDYJQ4N683F6c0kfy2Kd25BRpie1h10=; b=iYgPygej573gqzmIdmo1aTbswMkAX1OkMtdsILaHEa9o1MFkROYSoDai2nTBEcN218 ZTsQjTIpXKwodOLI8b9MkEPzRCAET67tPoZyC0BwTUdgkRHb4Ep9hUa41UMEhN5pZZXf oDFw6vPa786hmGjOAUI0nkF5dDEDPOdPeB13q5K/II41FLHWhV4N8jvF1E1x//8aV6rb m/NbJSL4gMRHdT8t9r2PDqNGhHSHS+SHgcHLEGXJKGdDhE7GUM8snNnI6vbKdnQSTHzB 972hYj0g1BhE+pirOPR5B9wPtS3ZvZbh+kml7OHtYO9YVil7A7tFLuIV3eOz9MKlfaSf Ydmw== 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=dhOviQvszTRipDYJQ4N683F6c0kfy2Kd25BRpie1h10=; b=DEwWw9RQaCyu3dlXMeyj0LShivIiqHs/dh/b+EzfQslEtE5mLC1/XO4gULiEwQmmF8 bAagbOYmSq14k4vH3guRwDhSiS7lf04TP9BB4EjLW2dTBa8jA2FXq0Am8zHArrNUrZ+z CqjkWpzWh9F1faJ+el21JQ0CIZOQSe2JWz4XOgB5Hqdo/ZdNjtf/8R/GMHgFEYyMSvHx UlZl0QlShWiUnfhxSBRrti8Isfansp4nMMm59K6Zb9U2gcd3LerDKG5No9wZ0d8Hj2TM Dmfm4CFTZ0OckQpjWs3B6E2uM2NiRXmBPopNtTHP8Yzo/6skyEezwbHKxHWfuA80aMRP BCMg== X-Gm-Message-State: AN3rC/4bylzKEhsnnaFffZh2kFpAebX/uwpF5rkvw4FgP7E2cW0YFs+p huc8SQ/W8wJ1SXl55SE= X-Received: by 10.200.51.132 with SMTP id c4mr11153661qtb.13.1492468581820; Mon, 17 Apr 2017 15:36:21 -0700 (PDT) From: Sri Ramanujam To: libvir-list@redhat.com Date: Mon, 17 Apr 2017 18:36:10 -0400 Message-Id: <20170417223615.20817-2-sramanujam@datto.com> In-Reply-To: <20170417223615.20817-1-sramanujam@datto.com> References: <20170417223615.20817-1-sramanujam@datto.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 17 Apr 2017 22:36:23 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 17 Apr 2017 22:36:23 +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.39 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 17 Apr 2017 22:36:31 +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 --- src/hyperv/hyperv_wmi.c | 246 ++++++++++++++++++++++++++++++++++++++++++++= ++++ src/hyperv/hyperv_wmi.h | 78 ++++++++++++++- 2 files changed, 323 insertions(+), 1 deletion(-) diff --git a/src/hyperv/hyperv_wmi.c b/src/hyperv/hyperv_wmi.c index a3c7dc0..c9a7666 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,251 @@ hypervVerifyResponse(WsManClient *client, WsXmlDocH r= esponse, } =20 =20 +/* + * Methods to work with method invocation parameters + */ + +/* + * hypervInitInvokeParamsList: + * @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 +hypervInitInvokeParamsList(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) +{ + if (params =3D=3D NULL) + return; + + VIR_DISPOSE_N(params->params, params->nbAvailParams); + VIR_FREE(params); + + return; +} + +static inline int +hypervCheckParams(hypervInvokeParamsListPtr params) +{ + int result =3D -1; + + if (params->nbParams + 1 > params->nbAvailParams) { + if (VIR_EXPAND_N(params->params, params->nbAvailParams, 5) < 0) + goto cleanup; + } + + result =3D 0; + cleanup: + return result; +} + +/* + * 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 objec 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) +{ + int result =3D -1; + hypervParamPtr p =3D NULL; + hypervWmiClassInfoPtr classInfo =3D NULL; + + if (hypervGetWmiClassInfo(priv, eprInfo, &classInfo) < 0) + goto cleanup; + + if (hypervCheckParams(params) < 0) + goto cleanup; + + 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++; + + result =3D 0; + cleanup: + return result; +} + +/* + * 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; + char *tmp =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 err; + typeinfo =3D classInfo->serializerInfo; + + /* loop through the items to find out how many fields there are */ + for (i =3D 0; typeinfo[i+1].name !=3D NULL; i++) {} + + count =3D i + 1; + table =3D virHashCreate(count, virHashValueFree); + + for (i =3D 0; typeinfo[i+1].name !=3D NULL; i++) { + item =3D &typeinfo[i]; + if (VIR_STRDUP(tmp, item->name) < 0) + goto err; + + if (virHashAddEntry(table, tmp, NULL) < 0) + goto err; + + VIR_FREE(tmp); + } + + goto success; + + err: + virHashFree(table); + success: + return table; +} + +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) +{ + int result =3D -1; + hypervParamPtr p =3D NULL; + hypervWmiClassInfoPtr classInfo =3D NULL; + + if (hypervCheckParams(params) < 0) + goto cleanup; + + /* Get the typeinfo out of the class info list */ + if (hypervGetWmiClassInfo(priv, info, &classInfo) < 0) + goto cleanup; + + 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++; + + result =3D 0; + + cleanup: + return result; +} + + =20 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *= * * * Object diff --git a/src/hyperv/hyperv_wmi.h b/src/hyperv/hyperv_wmi.h index edb8efa..c2a0592 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,6 +76,80 @@ 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 hypervInitInvokeParamsList(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 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *= * * * CIM/Msvm_ReturnCode --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 27 18:58:27 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 14924686156311002.4952354186152; Mon, 17 Apr 2017 15:36:55 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B83284AEB6; Mon, 17 Apr 2017 22:36:53 +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 8C30918E51; Mon, 17 Apr 2017 22:36:53 +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 38E7E18523CC; Mon, 17 Apr 2017 22:36:53 +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 v3HMaPMj017825 for ; Mon, 17 Apr 2017 18:36:25 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5E2555C48E; Mon, 17 Apr 2017 22:36:25 +0000 (UTC) Received: from mx1.redhat.com (ext-mx03.extmail.prod.ext.phx2.redhat.com [10.5.110.27]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 558C96046B for ; Mon, 17 Apr 2017 22:36:25 +0000 (UTC) Received: from mail-qt0-f182.google.com (mail-qt0-f182.google.com [209.85.216.182]) (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 43E6980F8E for ; Mon, 17 Apr 2017 22:36:23 +0000 (UTC) Received: by mail-qt0-f182.google.com with SMTP id y33so29146996qta.2 for ; Mon, 17 Apr 2017 15:36:23 -0700 (PDT) Received: from silas.datto.lan ([47.19.105.250]) by smtp.gmail.com with ESMTPSA id m62sm5751088qte.5.2017.04.17.15.36.21 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Apr 2017 15:36:21 -0700 (PDT) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B83284AEB6 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 B83284AEB6 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="z1fPRuw7" DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 43E6980F8E Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=datto.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=sramanujam@datto.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 43E6980F8E 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=9WkoJftcmSJw63lhAcGSWLMEPpu2QW7jdP07Of5wW60=; b=z1fPRuw7og0xhwPZFh2ciF8lhJG51970UMRQN3DQg+pcrkbq3gh/O5xZOgnwSPq7Cl UMqdntnWoIAFAxn61AYnAfWzT3eL72AE2FWkbnbeqTP/aqUqji9+LecLT42D52cI1O/z aO9wbpcdY8AzCK6PmRqeLDiYZDnFANJZ3AcjZ4M0fm+FImS9j+NdMxwjurIub+2MzkDr 7dSkXFVTEqpZibnxMA7adTqTH7Y6QgEmLSc3kdNYusQycDfwt+g3lEyq75qxtEZ94G4P V89O4FIsvEYnhMG7yD1xrDgiLHCBsSOguCLnhcQAmKoPHxPfkH3ORSpWQ4q5MAWiVIGE a89A== 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=9WkoJftcmSJw63lhAcGSWLMEPpu2QW7jdP07Of5wW60=; b=GxuZFpkyktwSUbx3k02mnpKwM+GfRz5KNkFs4K+Vq8m9lWmnto5+Vt0jkDng25Ikyp SslYxcvwG8lLfEyBSs+nS2YLfzBfvUKWYVzGq1RYumdOed9NvCnOT1fKppZWXBuuvrVf fGSYnK8CbiPdOK4nMGK8P78VAiiihhQ1J28jiHTNMTsqMAell7z40s4CvfsBjF3oD202 7en91Lnu7HX7vO+1Qir9AJcX76nTPhRuSqb8jmZQyH1eOLJ/penHfV0Oc4XqRAL+n3s2 JBC6F92KRMtY9OFsCnmanlpsrGmvKF6Lo/d1eLGbDRWoNXm4gfXyE6XHJDShIJjhHcNd d4zA== X-Gm-Message-State: AN3rC/6PLOR7tJVrmRsNofaXewd0V5M28UZIbnom39iWFWiFzeo5WQg/ pA77r2+yXzPXg6xHVnM= X-Received: by 10.200.35.80 with SMTP id b16mr10687697qtb.205.1492468582384; Mon, 17 Apr 2017 15:36:22 -0700 (PDT) From: Sri Ramanujam To: libvir-list@redhat.com Date: Mon, 17 Apr 2017 18:36:11 -0400 Message-Id: <20170417223615.20817-3-sramanujam@datto.com> In-Reply-To: <20170417223615.20817-1-sramanujam@datto.com> References: <20170417223615.20817-1-sramanujam@datto.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 17 Apr 2017 22:36:23 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 17 Apr 2017 22:36:23 +0000 (UTC) for IP:'209.85.216.182' DOMAIN:'mail-qt0-f182.google.com' HELO:'mail-qt0-f182.google.com' FROM:'sramanujam@datto.com' RCPT:'' X-RedHat-Spam-Score: 0.179 (BAYES_50, 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.182 mail-qt0-f182.google.com 209.85.216.182 mail-qt0-f182.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.27 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 17 Apr 2017 22:36:54 +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 c15d97a..a51c151 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.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 27 18:58:27 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 1492468594570461.5134403548101; Mon, 17 Apr 2017 15:36:34 -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 69443C059725; Mon, 17 Apr 2017 22:36:32 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 381C56046B; Mon, 17 Apr 2017 22:36:32 +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 A26755EC67; Mon, 17 Apr 2017 22:36:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v3HMaSUB018033 for ; Mon, 17 Apr 2017 18:36:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id 58EF21758B; Mon, 17 Apr 2017 22:36:28 +0000 (UTC) Received: from mx1.redhat.com (ext-mx01.extmail.prod.ext.phx2.redhat.com [10.5.110.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4EA6D17149 for ; Mon, 17 Apr 2017 22:36:26 +0000 (UTC) Received: from mail-qt0-f175.google.com (mail-qt0-f175.google.com [209.85.216.175]) (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 2C84E81235 for ; Mon, 17 Apr 2017 22:36:24 +0000 (UTC) Received: by mail-qt0-f175.google.com with SMTP id g60so46219591qtd.3 for ; Mon, 17 Apr 2017 15:36:24 -0700 (PDT) Received: from silas.datto.lan ([47.19.105.250]) by smtp.gmail.com with ESMTPSA id m62sm5751088qte.5.2017.04.17.15.36.22 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Apr 2017 15:36:22 -0700 (PDT) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 69443C059725 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=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 69443C059725 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="mI08iJFR" DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2C84E81235 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=datto.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=sramanujam@datto.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 2C84E81235 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=vUPZRLVIte+kiffJJc+MT/f5aGwbHXzC5yRJnP1P/u0=; b=mI08iJFRlV7A5KOPRv/3lJ6BwwlvDovfMMQifFAa/GMNvRFutBlOeUBL3iv68aWjD9 ikN9J1hwZcA1WdXtxjFu41h/p7KglsIEzT6VH6UJ2nD56LnzG1KYjj5fSg3+5ogpKD3z 8YLd7KoA2dSyL2+KaOV87IVjX3l3t1V2P7DmKmoXko57Uo0ZAOEqjO9huwHn9W5LqzFa G6F3TmpyDWUDpg87ekw5o6wuQ2M202EYNnpszEuqpG2KF4XhVV5hlnJL5PE6ODsZ14vn Z5idau8fCJKqYmv0h9/ZHJQYfA9OC7tJlMZ9APqcDklat+yrKIv3ybGzS1nsj5BiVlwN aTng== 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=vUPZRLVIte+kiffJJc+MT/f5aGwbHXzC5yRJnP1P/u0=; b=l2vJ2Vim1GQPsTX5khCybZsPwr86DuXt5/w0olaWat0QyE1WPMQPRt48bBDUyLFBQO qHDG+iSnEfouydRuznaB/oWSC5bxsRJviLxnNF4ZUhYHw8lyl0TFhAIv/MUv954RE4Zn 846cWxCYwyWk0doBCOyAoL0MPQ9JkvchSlnTsgYSwnieIDKxJSM7pxcIv0oM2rIaA3Um EDuysCpDQNlsW8E7EcxcTPACq6QP1gyYxxebgcKOSZoicT7PN48ZY71mdaWVOKuLdO6o QZ/6ZmlGEgDiIHpq6boVCimR+XUeNNkmwjzjxBm4ACssj+RvkqUB2k/6FRs0wLs5ShaS TrRQ== X-Gm-Message-State: AN3rC/7Qwts2ljjIr0ru+sFa7NexFTNR8uB7I9GL30OmTjv9dvzoXozi X2ugcei/tSzOBSW+0e0= X-Received: by 10.200.34.242 with SMTP id g47mr3621510qta.109.1492468583079; Mon, 17 Apr 2017 15:36:23 -0700 (PDT) From: Sri Ramanujam To: libvir-list@redhat.com Date: Mon, 17 Apr 2017 18:36:12 -0400 Message-Id: <20170417223615.20817-4-sramanujam@datto.com> In-Reply-To: <20170417223615.20817-1-sramanujam@datto.com> References: <20170417223615.20817-1-sramanujam@datto.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 17 Apr 2017 22:36:24 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 17 Apr 2017 22:36:24 +0000 (UTC) for IP:'209.85.216.175' DOMAIN:'mail-qt0-f175.google.com' HELO:'mail-qt0-f175.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.175 mail-qt0-f175.google.com 209.85.216.175 mail-qt0-f175.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.25 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 17 Apr 2017 22:36:33 +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 | 566 ++++++++++++++++++++++++++++++++++++++++++++= ++++ src/hyperv/hyperv_wmi.h | 3 + src/hyperv/openwsman.h | 4 + 3 files changed, 573 insertions(+) diff --git a/src/hyperv/hyperv_wmi.c b/src/hyperv/hyperv_wmi.c index c9a7666..cbbe028 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,14 @@ #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 +VIR_LOG_INIT("hyperv.hyperv_wmi"); =20 static int hypervGetWmiClassInfo(hypervPrivate *priv, hypervWmiClassInfoListPtr list, @@ -388,6 +392,568 @@ hypervAddEmbeddedParam(hypervInvokeParamsListPtr para= ms, hypervPrivate *priv, } =20 =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 err; + + *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 err; + } + + 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 err; + } + + /* add resource URI as namespace */ + ws_xml_set_ns(xmlNodeMethod, params->resourceUri, "p"); + + result =3D 0; + goto cleanup; + + err: + if (*docRoot !=3D NULL) { + ws_xml_destroy_doc(*docRoot); + *docRoot =3D NULL; + } + cleanup: + VIR_FREE(method); + return result; +} + +static int +hypervSerializeSimpleParam(hypervParamPtr p, const char *resourceUri, + WsXmlNodeH *methodNode) +{ + int result =3D -1; + 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")); + goto cleanup; + } + + result =3D 0; + + cleanup: + return result; +} + +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 */ + 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; + } + + ns =3D NULL; + 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; + int 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) =3D=3D NULL) { + 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 */ + if (numKeys > 0) { + 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= , NULL, + property->isArray ? "PROPERTY.ARRAY" : "PR= OPERTY", + 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", na= me) =3D=3D NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Could not add attribute to XML node")); + goto cleanup; + } + + if (ws_xml_add_node_attr(xmlNodeProperty, NULL, "TYPE", pr= operty->type) =3D=3D NULL) { + 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(xmlNodePropert= y, NULL, + "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 : xm= lNodeProperty, + NULL, "VALUE", value) =3D=3D NULL) { + 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) =3D=3D NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Could not add CDATA to doc root")); + goto cleanup; + } + + /* we did it! */ + result =3D 0; + + cleanup: + 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; + + 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 =3D=3D NULL) + 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); + } + + 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 every 100 ms until the job completes or fails */ + while (!completed) { + 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 */ + 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; + } + } + } 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 !=3D NULL) + *res =3D response; + + result =3D 0; + + cleanup: + if (options) + wsmc_options_destroy(options); + if (response && (res =3D=3D NULL)) + ws_xml_destroy_doc(response); + 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; +} =20 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *= * * * Object diff --git a/src/hyperv/hyperv_wmi.h b/src/hyperv/hyperv_wmi.h index c2a0592..ac86ae0 100644 --- a/src/hyperv/hyperv_wmi.h +++ b/src/hyperv/hyperv_wmi.h @@ -151,6 +151,9 @@ int hypervSetEmbeddedProperty(virHashTablePtr table, co= nst char *name, int hypervAddEmbeddedParam(hypervInvokeParamsListPtr params, hypervPrivate= *priv, const char *name, virHashTablePtr table, hypervWmiClassInfoListPtr= info); =20 +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.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 27 18:58:27 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 1492468621371213.36139198624915; Mon, 17 Apr 2017 15:37:01 -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 64D60104CF; Mon, 17 Apr 2017 22:36:59 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3AABB5C893; Mon, 17 Apr 2017 22:36:59 +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 E69F45EC6A; Mon, 17 Apr 2017 22:36:58 +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 v3HMaRLG018004 for ; Mon, 17 Apr 2017 18:36:27 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8117217156; Mon, 17 Apr 2017 22:36:27 +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 753DA5C54B for ; Mon, 17 Apr 2017 22:36:25 +0000 (UTC) Received: from mail-qt0-f174.google.com (mail-qt0-f174.google.com [209.85.216.174]) (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 9A4317D0C2 for ; Mon, 17 Apr 2017 22:36:24 +0000 (UTC) Received: by mail-qt0-f174.google.com with SMTP id m36so112225786qtb.0 for ; Mon, 17 Apr 2017 15:36:24 -0700 (PDT) Received: from silas.datto.lan ([47.19.105.250]) by smtp.gmail.com with ESMTPSA id m62sm5751088qte.5.2017.04.17.15.36.23 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Apr 2017 15:36:23 -0700 (PDT) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 64D60104CF 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=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 64D60104CF 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="bgRmXL6c" DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9A4317D0C2 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 9A4317D0C2 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=YbRnN1YERb0Jfe1isYn2Khk45gbNSTa36+tFDxSdZfE=; b=bgRmXL6cwAceY1QPmIIRPycfKxbF2zgRuYBVGHXtTnmY24eW5bgQsMjo9jV+r0uCi0 eQHakLqr92kBYjmh6mSu/zcJcga9MSm3B45fnDRVRD3CP5O+cG79xcsQhMioMccwrqzx gpFOyGyZEEnx4b7H+IiiyXLlJBSmx/eBYD9My1LTMuwJz6p8Rph6QHW6cLQxD0dABInD +oX7WgFiTHyBOFudqRroFhCXMnxPp36VJ/ISzvM0uDCVORgKNTvsJ0V5av7ed6oNLCpV EzwTm4a3NxaikRkj34HopdbFs8kjx4GYxr0Ew1UCHIVVzdhtPHu0ZGuiUUpXQyTND+cL Xx3A== 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=YbRnN1YERb0Jfe1isYn2Khk45gbNSTa36+tFDxSdZfE=; b=mf5BRHr85La+NJ1vNMtAUX/2cQN/g9M5qMFgujQ/nZQq+dO2uyrxj9eZF4y87FlNy8 rcTfqC4VwRhja+J2rPN6/0v+kkkjt2D7+a5I2yhP3PDhpfWol1V9AuBMYp6gz0M+5Z4U TbjC3cwuHExL+JUelp/o2LdxGZAKoy1dWJocH4N1R/MwWItomQEd9Z7uNTKwZe4bGtRs tUJQwSmCXnwItNzZ0cBafvYm5fqk/sWr1kTEutMT3Xn3QsRvEbzkLns5O5yzbn0R5Ay+ EswDBTbq9K7F/HLPPYrS1bGW81d89VUo4qDPTQpRHXEFDd+RkqUiz60rAF5Iep6DoUO7 ahPw== X-Gm-Message-State: AN3rC/6DN6rv5Z6TTrXo4vo5+ikFD6uaaX2KFgqyO1OR/1l879WFCiVE ZXnndxw7R3HGb/BANrw= X-Received: by 10.237.45.39 with SMTP id h36mr10868089qtd.211.1492468583710; Mon, 17 Apr 2017 15:36:23 -0700 (PDT) From: Sri Ramanujam To: libvir-list@redhat.com Date: Mon, 17 Apr 2017 18:36:13 -0400 Message-Id: <20170417223615.20817-5-sramanujam@datto.com> In-Reply-To: <20170417223615.20817-1-sramanujam@datto.com> References: <20170417223615.20817-1-sramanujam@datto.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 17 Apr 2017 22:36:24 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 17 Apr 2017 22:36:24 +0000 (UTC) for IP:'209.85.216.174' DOMAIN:'mail-qt0-f174.google.com' HELO:'mail-qt0-f174.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.174 mail-qt0-f174.google.com 209.85.216.174 mail-qt0-f174.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.26 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 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.38]); Mon, 17 Apr 2017 22:37:00 +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 | 85 +++++++++++++++++++++++++++++++= +++ src/hyperv/hyperv_wmi.c | 7 +++ src/hyperv/hyperv_wmi.h | 3 +- src/hyperv/hyperv_wmi_generator.input | 86 +++++++++++++++++++++++++++++++= ++++ 4 files changed, 180 insertions(+), 1 deletion(-) diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c index 090ea24..1c8c436 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -35,6 +35,7 @@ #include "hyperv_wmi.h" #include "openwsman.h" #include "virstring.h" +#include "virkeycode.h" =20 #define VIR_FROM_THIS VIR_FROM_HYPERV =20 @@ -1350,6 +1351,89 @@ hypervConnectListAllDomains(virConnectPtr conn, #undef MATCH =20 =20 +static int +hypervDomainSendKey(virDomainPtr domain, unsigned int codeset, + unsigned int holdtime ATTRIBUTE_UNUSED, 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; + + 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; + + /* translate keycodes to xt and generate keyup scancodes. */ + translatedKeycodes =3D (int *) keycodes; + for (i =3D 0; i < nkeycodes; i++) { + if (codeset !=3D VIR_KEYCODE_SET_WIN32) { + keycode =3D virKeycodeValueTranslate(codeset, VIR_KEYCODE_SET_= WIN32, + translatedKeycodes[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; + + /* type the keys */ + for (i =3D 0; i < nkeycodes; i++) { + char keycodeStr[sizeof(int) * 3 + 2]; + snprintf(keycodeStr, sizeof(keycodeStr), "%d", translatedKeycodes[= i]); + + /* params obj takes ownership of selector */ + params =3D hypervInitInvokeParamsList(priv, "TypeKey", selector, + Msvm_Keyboard_WmiInfo); + if (hypervAddSimpleParam(params, "keyCode", keycodeStr) < 0) + goto cleanup; + + if (hypervInvokeMethod(priv, params, NULL) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not press key = %d"), + translatedKeycodes[i]); + goto cleanup; + } + } + + result =3D 0; + + cleanup: + hypervFreeObject(priv, (hypervObject *) keyboard); + hypervFreeObject(priv, (hypervObject *) computerSystem); + virBufferFreeAndReset(&query); + return result; +} =20 =20 static virHypervisorDriver hypervHypervisorDriver =3D { @@ -1385,6 +1469,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 cbbe028..8025371 100644 --- a/src/hyperv/hyperv_wmi.c +++ b/src/hyperv/hyperv_wmi.c @@ -1302,6 +1302,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 ac86ae0..5ff80f8 100644 --- a/src/hyperv/hyperv_wmi.h +++ b/src/hyperv/hyperv_wmi.h @@ -217,7 +217,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.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 27 18:58:27 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 1492468624651846.104983175596; Mon, 17 Apr 2017 15:37:04 -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 C9188C04B940; Mon, 17 Apr 2017 22:37:02 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9C7F75C54F; Mon, 17 Apr 2017 22:37: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 5698C5EC6B; Mon, 17 Apr 2017 22:37:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v3HMaRbk018016 for ; Mon, 17 Apr 2017 18:36:27 -0400 Received: by smtp.corp.redhat.com (Postfix) id E79DF78372; Mon, 17 Apr 2017 22:36:27 +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 E035117962 for ; Mon, 17 Apr 2017 22:36:26 +0000 (UTC) Received: from mail-qt0-f178.google.com (mail-qt0-f178.google.com [209.85.216.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 6026E4E8AB for ; Mon, 17 Apr 2017 22:36:25 +0000 (UTC) Received: by mail-qt0-f178.google.com with SMTP id y33so29147451qta.2 for ; Mon, 17 Apr 2017 15:36:25 -0700 (PDT) Received: from silas.datto.lan ([47.19.105.250]) by smtp.gmail.com with ESMTPSA id m62sm5751088qte.5.2017.04.17.15.36.23 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Apr 2017 15:36:23 -0700 (PDT) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C9188C04B940 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=datto.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com C9188C04B940 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="V8GOJPGb" DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6026E4E8AB 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 6026E4E8AB 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=w1DLtqYmn5in9+0B8lcImFyiIh2DVyTBUSmZrZQS/zE=; b=V8GOJPGb704q/mCXAfzJcdNxlx02/z/Q/H5reod9fMz8yQ7dZnGF+CXXC7t1b3RTIi Ix525MUcTvZxISLY9B16cTnwxb6CMuSWJ5CjFN3Q8xfGL7lMwUiAen/VtDE2A98FNOv7 bE7lZf6kEUJ9DSv2406XlV8fO93UHJxtRl82ZLo8vXty+vxcNarbcAwMnhWiWPRGWjGn 0QrYV5d2vbRU2fubE8DE4mdpq/kJ3klFPweb/A61Vf1+q46HNtj4VfKL8xvHquyZKM1T rHoSE+H3MOoHmBUKESbbDqJluQlLUDwTLHrqoHvxXILKXc6qbXAmIpUttPkmBRhhBMBE igrg== 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=w1DLtqYmn5in9+0B8lcImFyiIh2DVyTBUSmZrZQS/zE=; b=oXkOhMmCEd9jP3xVmJImePX+IwTIqpRlMpXqkNGo4NfaxIk66RWHFO0dAVCjAOhTih dSbstCm5ur4tWkomQQYR99HLZPX866vdt4HK3I0olLJpGBwqm4cELalqAa9KA8joKlkH a9pwRZvljiDC2ZvF72DnnBSSEsBB8ZpUunilECEm2uM7f1vTC9D+Idvo8k6uG0wmYcQc fT9j3+bjoJhQ2T+1OOjy3Ty55RcxBYCVpN9CM1ito0HwIi5BlRiOT17fjmx342CH9gdM ZqqLtTqHeKRk6Iu278qg649uvMcSy4drpPlRlRu+cIVY/JVoaOJb3DrBFJwJzkTJQlS1 dMMw== X-Gm-Message-State: AN3rC/5D9qN343hl6xRvl8yzm+cPjewkKhNs0FFaRzkenlWY8E/00mDD 8xAAjSUSd/QPwT0Rxk4= X-Received: by 10.200.57.18 with SMTP id s18mr10730198qtb.1.1492468584508; Mon, 17 Apr 2017 15:36:24 -0700 (PDT) From: Sri Ramanujam To: libvir-list@redhat.com Date: Mon, 17 Apr 2017 18:36:14 -0400 Message-Id: <20170417223615.20817-6-sramanujam@datto.com> In-Reply-To: <20170417223615.20817-1-sramanujam@datto.com> References: <20170417223615.20817-1-sramanujam@datto.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 17 Apr 2017 22:36:25 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 17 Apr 2017 22:36:25 +0000 (UTC) for IP:'209.85.216.178' DOMAIN:'mail-qt0-f178.google.com' HELO:'mail-qt0-f178.google.com' FROM:'sramanujam@datto.com' RCPT:'' X-RedHat-Spam-Score: 0.179 (BAYES_50, 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.178 mail-qt0-f178.google.com 209.85.216.178 mail-qt0-f178.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.38 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 5/6] util: add virNumToStr 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.31]); Mon, 17 Apr 2017 22:37: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" Add virNumToStr(), which safely converts numbers into their string representation. Functions added: * virNumToStr_l * virNumToStr_ul --- src/util/virstring.c | 34 ++++++++++++++++++++++++++++++++++ src/util/virstring.h | 8 ++++++++ 2 files changed, 42 insertions(+) diff --git a/src/util/virstring.c b/src/util/virstring.c index 69abc26..f0d9e19 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -536,6 +536,40 @@ virStrToDouble(char const *s, return 0; } =20 +/** + * Converts signed number to string representation. The caller is responsi= ble + * for freeing the result. + */ +int +virNumToStr_l(long num, char **dst) +{ + int sz; + + sz =3D snprintf(NULL, 0, "%ld", num); + if (sz > 0 && VIR_ALLOC_N(*dst, sz + 1) < 0) + return -1; + + snprintf(*dst, sz + 1, "%ld", num); + return 0; +} + +/** + * Converts unsigned number to string representation. The caller is respon= sible + * for freeing the result. + */ +int +virNumToStr_ul(unsigned long num, char **dst) +{ + int sz; + + sz =3D snprintf(NULL, 0, "%lu", num); + if (sz > 0 && VIR_ALLOC_N(*dst, sz + 1) < 0) + return -1; + + snprintf(*dst, sz + 1, "%lu", num); + return 0; +} + int virVasprintfInternal(bool report, int domcode, diff --git a/src/util/virstring.h b/src/util/virstring.h index 603650a..9918e07 100644 --- a/src/util/virstring.h +++ b/src/util/virstring.h @@ -109,6 +109,13 @@ int virStrToDouble(char const *s, double *result) ATTRIBUTE_RETURN_CHECK; =20 +int virNumToStr_l(long num, + char **dst) + ATTRIBUTE_RETURN_CHECK; +int virnumToStr_ul(unsigned long num, + char **dst) + ATTRIBUTE_RETURN_CHECK; + void virSkipSpaces(const char **str) ATTRIBUTE_NONNULL(1); void virSkipSpacesAndBackslash(const char **str) ATTRIBUTE_NONNULL(1); void virTrimSpaces(char *str, char **endp) ATTRIBUTE_NONNULL(1); @@ -288,6 +295,7 @@ bool virStringBufferIsPrintable(const uint8_t *buf, siz= e_t buflen); =20 char *virStringEncodeBase64(const uint8_t *buf, size_t buflen); =20 + static inline void virStringTrimOptionalNewline(char *str) { --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 27 18:58:27 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 1492468615792944.9812936804748; Mon, 17 Apr 2017 15:36:55 -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 DA40A7D0C4; Mon, 17 Apr 2017 22:36:53 +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 AD5FA1758B; Mon, 17 Apr 2017 22:36:53 +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 5E05B18523CD; Mon, 17 Apr 2017 22:36:53 +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 v3HMaREd017997 for ; Mon, 17 Apr 2017 18:36:27 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2AD8E17D22; Mon, 17 Apr 2017 22:36:27 +0000 (UTC) Received: from mx1.redhat.com (ext-mx03.extmail.prod.ext.phx2.redhat.com [10.5.110.27]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2439618E51 for ; Mon, 17 Apr 2017 22:36:27 +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 17F6980F8E for ; Mon, 17 Apr 2017 22:36:26 +0000 (UTC) Received: by mail-qt0-f171.google.com with SMTP id c45so112104499qtb.1 for ; Mon, 17 Apr 2017 15:36:26 -0700 (PDT) Received: from silas.datto.lan ([47.19.105.250]) by smtp.gmail.com with ESMTPSA id m62sm5751088qte.5.2017.04.17.15.36.24 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Apr 2017 15:36:24 -0700 (PDT) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com DA40A7D0C4 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 DA40A7D0C4 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="LLghE+EG" DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 17F6980F8E Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=datto.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=sramanujam@datto.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 17F6980F8E 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=GkGn7kfvaCvSm1HiznYFswxS3fzG8ckCeI+m4Xz3srs=; b=LLghE+EGMuYNJmO2exU9NzC67LvmlOvuITWpH1CjIWWace6npC+rmbXnsA+Tmy+zKe H///MSbx8yRLowYF/3Xvl9p57UarDYA0HW+LJpDpNByUXIUaSNohpDkGxGO+BX0wlY0T 09Elnzk+lVsCZF0BOSVEc5MnTctRI3QdBc8q+lqfVBHJaQ32T5Z+4Yj7n2l+rk8TMhDU uXKt+kLrkqtI32xyAr57fQTkmqMlI2ZwEYfemgoXWQqOeC6224HdTLVl257E8vS0T3Ku Wh49CMx6tOsVufXhHgxXXtYgrUrlczQ3doMDOn2x+qjFL/I70Gn0SW43M+zfMkgF62mW NJIg== 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=GkGn7kfvaCvSm1HiznYFswxS3fzG8ckCeI+m4Xz3srs=; b=nuUqqbn+PG/9/FtBlWXw9V2RekXm1uET+UQLYuZlYyC+P2IfukD+b9mok7i/IX6lKa YPB0yF78cLEAZ+7px7ERTfHz0XidKd6Wt5fzT9JGdeaNOJPJiZlkjNtjVJjTsOfOR9wA hJChwOzNEnJT6kGDN4cYxJ6leSdIsMUYRI26rYO4RIsvrQFIFrtLxO7+7GN7PWpdfi5g jQRRHbPmKGBs6imbfuZ3LeMa8W/BhOm9FLK5SjkcQojZlT7LA4uH+PnsROMKcU8vi3G2 bjOH4sxR5WW0P7G1RwoEVNmdwMN0NE6sAPwYONAZfywuQbR5dV7A02DB7ziFW1L7htAh 4+3Q== X-Gm-Message-State: AN3rC/5gKx0y6vqeOLi+E6ZXhS+P1uwJvlWXGDIc2O+lW4EHipetabS7 1rQebKmHORhQ8mMbYdM= X-Received: by 10.200.52.85 with SMTP id v21mr11509066qtb.155.1492468585157; Mon, 17 Apr 2017 15:36:25 -0700 (PDT) From: Sri Ramanujam To: libvir-list@redhat.com Date: Mon, 17 Apr 2017 18:36:15 -0400 Message-Id: <20170417223615.20817-7-sramanujam@datto.com> In-Reply-To: <20170417223615.20817-1-sramanujam@datto.com> References: <20170417223615.20817-1-sramanujam@datto.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 17 Apr 2017 22:36:26 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 17 Apr 2017 22:36:26 +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.27 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 6/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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 17 Apr 2017 22:36:54 +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 | 97 +++++++++++++++++++++++++++++++= ++++ src/hyperv/hyperv_wmi.c | 60 ++++++++++++++++++++++ src/hyperv/hyperv_wmi.h | 11 ++++ src/hyperv/hyperv_wmi_generator.input | 30 +++++++++++ 4 files changed, 198 insertions(+) diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c index 1c8c436..254612b 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -1436,6 +1436,101 @@ 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 memory / 1024; + Msvm_VirtualSystemSettingData *vssd =3D NULL; + Msvm_MemorySettingData *memsd =3D NULL; + virBuffer eprQuery =3D VIR_BUFFER_INITIALIZER; + virHashTablePtr memResource =3D NULL; + + virCheckFlags(0, -1); + + /* memory has to be a multiple of 2; round up if necessary */ + if (memory_mb % 2) memory_mb++; + + if (virNumToStr_ul(memory_mb, &memory_str) < 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 hypervInitInvokeParamsList(priv, "ModifyVirtualSystemRe= sources", + MSVM_VIRTUALSYSTEMMANAGEMENTSERVICE_SELECTOR, + Msvm_VirtualSystemManagementService_WmiInfo); + + 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 cleanup; + + } else if (priv->wmiVersion =3D=3D HYPERV_WMI_VERSION_V2) { + params =3D hypervInitInvokeParamsList(priv, "ModifyResourceSetting= s", + MSVM_VIRTUALSYSTEMMANAGEMENTSERVICE_SELECTOR, + Msvm_VirtualSystemManagementService_WmiInfo); + } + + memResource =3D hypervCreateEmbeddedParam(priv, Msvm_MemorySettingData= _WmiInfo); + if (memResource =3D=3D NULL) + goto cleanup; + + if (hypervSetEmbeddedProperty(memResource, "VirtualQuantity", memory_s= tr) < 0) + goto cleanup; + + if (hypervSetEmbeddedProperty(memResource, "InstanceID", + memsd->data.common->InstanceID) < 0) + goto cleanup; + + + if (priv->wmiVersion =3D=3D HYPERV_WMI_VERSION_V1) { + if (hypervAddEmbeddedParam(params, priv, "ResourceSettingData", + memResource, Msvm_MemorySettingData_WmiInfo) < 0) + goto cleanup; + + } else if (priv->wmiVersion =3D=3D HYPERV_WMI_VERSION_V2) { + if (hypervAddEmbeddedParam(params, priv, "ResourceSettings", + memResource, Msvm_MemorySettingData_WmiInfo) < 0) + goto cleanup; + } + + if (hypervInvokeMethod(priv, params, NULL) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not set memo= ry")); + goto cleanup; + } + + result =3D 0; + cleanup: + VIR_FREE(memory_str); + hypervFreeObject(priv, (hypervObject *) vssd); + hypervFreeObject(priv, (hypervObject *) memsd); + virBufferFreeAndReset(&eprQuery); + 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 */ @@ -1470,6 +1565,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 8025371..0c46566 100644 --- a/src/hyperv/hyperv_wmi.c +++ b/src/hyperv/hyperv_wmi.c @@ -1595,3 +1595,63 @@ hypervMsvmComputerSystemFromDomain(virDomainPtr doma= in, =20 return 0; } + + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *= * * + * Msvm_VirtualSystemSettingData + */ + +int +hypervGetMsvmVirtualSystemSettingDataFromUUID(hypervPrivate *priv, + const char *uuid_string, Msvm_VirtualSystemSettingData **list) +{ + int result =3D -1; + 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) + goto cleanup; + + result =3D 0; + + cleanup: + virBufferFreeAndReset(&query); + return result; +} + + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *= * * + * Msvm_MemorySettingData + */ + +int +hypervGetMsvmMemorySettingDataFromVSSD(hypervPrivate *priv, + const char *vssd_instanceid, Msvm_MemorySettingData **list) +{ + int result =3D -1; + 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) + goto cleanup; + + result =3D 0; + cleanup: + virBufferFreeAndReset(&query); + return result; +} diff --git a/src/hyperv/hyperv_wmi.h b/src/hyperv/hyperv_wmi.h index 5ff80f8..59b6bcc 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 @@ -210,6 +213,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= ); @@ -217,6 +224,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.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list