From nobody Thu May 15 20:37:24 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; 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 1503925027796678.9429764292239; Mon, 28 Aug 2017 05:57:07 -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 B7B441F561; Mon, 28 Aug 2017 12:57:05 +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 4ED4F8186B; Mon, 28 Aug 2017 12:57:05 +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 E83371806101; Mon, 28 Aug 2017 12:57:03 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v7SCuweh011324 for ; Mon, 28 Aug 2017 08:56:58 -0400 Received: by smtp.corp.redhat.com (Postfix) id 77F3B78DFE; Mon, 28 Aug 2017 12:56:58 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 047F3784A7 for ; Mon, 28 Aug 2017 12:56:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B7B441F561 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Date: Mon, 28 Aug 2017 14:56:50 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/5] conf: introduce reconnect element for chardev source 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]); Mon, 28 Aug 2017 12:57:06 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- docs/formatdomain.html.in | 11 ++++ docs/schemas/domaincommon.rng | 12 +++++ src/conf/domain_conf.c | 119 ++++++++++++++++++++++++++++++++++++++= +--- src/conf/domain_conf.h | 11 ++++ 4 files changed, 145 insertions(+), 8 deletions(-) diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index fba8cfc6f3..205122f28e 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -6298,6 +6298,17 @@ qemu-kvm -net nic,model=3D? /dev/null slot.

=20 +

+ For character device with type unix or tcp + the source has an optional element reconnect + which configures reconnect timeout if the connection is lost. + There are two attributes, enabled where possible + values are yes and no and timeout + which is in seconds. The reconnect attribute is valid o= nly + for connect mode. + Since 3.7.0 (QEMU driver only). +

+
Guest interface
=20

diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index 3f56d8f45b..06c5a91b3d 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -3634,6 +3634,18 @@ + + + + + + + + + + + + diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 5bad3976cf..e291d13ac5 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -5130,6 +5130,12 @@ virDomainChrSourceDefValidate(const virDomainChrSour= ceDef *def, _("Missing source service attribute for char de= vice")); return -1; } + + if (def->data.tcp.listen && def->data.tcp.reconnect.enabled) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("chardev reconnect is possible only for conne= ct mode")); + return -1; + } break; =20 case VIR_DOMAIN_CHR_TYPE_UDP: @@ -5150,6 +5156,12 @@ virDomainChrSourceDefValidate(const virDomainChrSour= ceDef *def, _("Missing source path attribute for char devic= e")); return -1; } + + if (def->data.nix.listen && def->data.nix.reconnect.enabled) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("chardev reconnect is possible only for conne= ct mode")); + return -1; + } break; =20 case VIR_DOMAIN_CHR_TYPE_SPICEPORT: @@ -11115,6 +11127,56 @@ virDomainChrDefParseTargetXML(virDomainChrDefPtr d= ef, return ret; } =20 +static int +virDomainChrSourceReconnectDefParseXML(virDomainChrSourceReconnectDefPtr d= ef, + xmlNodePtr node, + xmlXPathContextPtr ctxt) +{ + int ret =3D -1; + int tmpVal; + char *tmp =3D NULL; + xmlNodePtr saveNode =3D ctxt->node; + xmlNodePtr cur; + + ctxt->node =3D node; + + if ((cur =3D virXPathNode("./reconnect", ctxt))) { + if ((tmp =3D virXMLPropString(cur, "enabled"))) { + if ((tmpVal =3D virTristateBoolTypeFromString(tmp)) < 0) { + virReportError(VIR_ERR_XML_ERROR, + _("invalid reconnect enabled value: '%s'"), + tmp); + goto cleanup; + } + def->enabled =3D tmpVal; + VIR_FREE(tmp); + } + + if (def->enabled =3D=3D VIR_TRISTATE_BOOL_YES) { + if ((tmp =3D virXMLPropString(cur, "timeout"))) { + if (virStrToLong_ui(tmp, NULL, 10, &def->timeout) < 0) { + virReportError(VIR_ERR_XML_ERROR, + _("invalid reconnect enabled value: '%s= '"), + tmp); + goto cleanup; + } + VIR_FREE(tmp); + } else { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("missing timeout for chardev with " + "reconnect enabled")); + goto cleanup; + } + } + } + + ret =3D 0; + cleanup: + ctxt->node =3D saveNode; + VIR_FREE(tmp); + return ret; +} + =20 typedef enum { VIR_DOMAIN_CHR_SOURCE_MODE_CONNECT, @@ -11152,6 +11214,7 @@ virDomainChrSourceDefParseMode(xmlNodePtr source) static int virDomainChrSourceDefParseTCP(virDomainChrSourceDefPtr def, xmlNodePtr source, + xmlXPathContextPtr ctxt, unsigned int flags) { int mode; @@ -11187,6 +11250,12 @@ virDomainChrSourceDefParseTCP(virDomainChrSourceDe= fPtr def, VIR_FREE(tmp); } =20 + if (virDomainChrSourceReconnectDefParseXML(&def->data.tcp.reconnect, + source, + ctxt) < 0) { + goto error; + } + return 0; =20 error: @@ -11220,7 +11289,8 @@ virDomainChrSourceDefParseUDP(virDomainChrSourceDef= Ptr def, =20 static int virDomainChrSourceDefParseUnix(virDomainChrSourceDefPtr def, - xmlNodePtr source) + xmlNodePtr source, + xmlXPathContextPtr ctxt) { =20 int mode; @@ -11231,6 +11301,12 @@ virDomainChrSourceDefParseUnix(virDomainChrSourceD= efPtr def, def->data.nix.listen =3D mode =3D=3D VIR_DOMAIN_CHR_SOURCE_MODE_BIND; def->data.nix.path =3D virXMLPropString(source, "path"); =20 + if (virDomainChrSourceReconnectDefParseXML(&def->data.nix.reconnect, + source, + ctxt) < 0) { + return -1; + } + return 0; } =20 @@ -11359,7 +11435,7 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDef= Ptr def, break; =20 case VIR_DOMAIN_CHR_TYPE_UNIX: - if (virDomainChrSourceDefParseUnix(def, cur) < 0) + if (virDomainChrSourceDefParseUnix(def, cur, ctxt) < 0) goto error; break; =20 @@ -11369,7 +11445,7 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDef= Ptr def, break; =20 case VIR_DOMAIN_CHR_TYPE_TCP: - if (virDomainChrSourceDefParseTCP(def, cur, flags) < 0) + if (virDomainChrSourceDefParseTCP(def, cur, ctxt, flags) <= 0) goto error; break; =20 @@ -11613,6 +11689,7 @@ virDomainChrDefParseXML(virDomainXMLOptionPtr xmlop= t, static virDomainSmartcardDefPtr virDomainSmartcardDefParseXML(virDomainXMLOptionPtr xmlopt, xmlNodePtr node, + xmlXPathContextPtr ctxt, unsigned int flags) { xmlNodePtr cur; @@ -11705,7 +11782,7 @@ virDomainSmartcardDefParseXML(virDomainXMLOptionPtr= xmlopt, =20 cur =3D node->children; if (virDomainChrSourceDefParseXML(def->data.passthru, cur, flags, - NULL, NULL, NULL, 0) < 0) + NULL, ctxt, NULL, 0) < 0) goto error; =20 if (def->data.passthru->type =3D=3D VIR_DOMAIN_CHR_TYPE_SPICEVMC) { @@ -14183,6 +14260,7 @@ virDomainHostdevDefParseXML(virDomainXMLOptionPtr x= mlopt, static virDomainRedirdevDefPtr virDomainRedirdevDefParseXML(virDomainXMLOptionPtr xmlopt, xmlNodePtr node, + xmlXPathContextPtr ctxt, virHashTablePtr bootHash, unsigned int flags) { @@ -14224,7 +14302,7 @@ virDomainRedirdevDefParseXML(virDomainXMLOptionPtr = xmlopt, /* boot gets parsed in virDomainDeviceInfoParseXML * source gets parsed in virDomainChrSourceDefParseXML */ if (virDomainChrSourceDefParseXML(def->source, cur, flags, - NULL, NULL, NULL, 0) < 0) + NULL, ctxt, NULL, 0) < 0) goto error; =20 if (def->source->type =3D=3D VIR_DOMAIN_CHR_TYPE_SPICEVMC) @@ -14883,7 +14961,7 @@ virDomainDeviceDefParse(const char *xmlStr, break; case VIR_DOMAIN_DEVICE_REDIRDEV: if (!(dev->data.redirdev =3D virDomainRedirdevDefParseXML(xmlopt, = node, - NULL, flag= s))) + ctxt, NULL= , flags))) goto error; break; case VIR_DOMAIN_DEVICE_RNG: @@ -14902,7 +14980,7 @@ virDomainDeviceDefParse(const char *xmlStr, break; case VIR_DOMAIN_DEVICE_SMARTCARD: if (!(dev->data.smartcard =3D virDomainSmartcardDefParseXML(xmlopt= , node, - flags))) + ctxt, fl= ags))) goto error; break; case VIR_DOMAIN_DEVICE_MEMBALLOON: @@ -18600,6 +18678,7 @@ virDomainDefParseXML(xmlDocPtr xml, for (i =3D 0; i < n; i++) { virDomainSmartcardDefPtr card =3D virDomainSmartcardDefParseXML(xm= lopt, node= s[i], + ctxt, flag= s); if (!card) goto error; @@ -18949,7 +19028,7 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; for (i =3D 0; i < n; i++) { virDomainRedirdevDefPtr redirdev =3D - virDomainRedirdevDefParseXML(xmlopt, nodes[i], bootHash, flags= ); + virDomainRedirdevDefParseXML(xmlopt, nodes[i], ctxt, bootHash,= flags); if (!redirdev) goto error; =20 @@ -23070,6 +23149,24 @@ virDomainChrAttrsDefFormat(virBufferPtr buf, return 0; } =20 + +static void +virDomainChrSourceReconnectDefFormat(virBufferPtr buf, + virDomainChrSourceReconnectDefPtr def) +{ + if (def->enabled =3D=3D VIR_TRISTATE_BOOL_ABSENT) + return; + + virBufferAsprintf(buf, "enabled)); + + if (def->enabled =3D=3D VIR_TRISTATE_BOOL_YES) + virBufferAsprintf(buf, " timeout=3D'%u'", def->timeout); + + virBufferAddLit(buf, "/>\n"); +} + + static int virDomainChrSourceDefFormat(virBufferPtr buf, virDomainChrSourceDefPtr def, @@ -23150,6 +23247,9 @@ virDomainChrSourceDefFormat(virBufferPtr buf, virBufferAsprintf(&attrBuf, " tlsFromConfig=3D'%d'", def->data.tcp.tlsFromConfig); =20 + virDomainChrSourceReconnectDefFormat(&childBuf, + &def->data.tcp.reconnect); + if (virXMLFormatElement(buf, "source", &attrBuf, &childBuf) < 0) goto error; =20 @@ -23166,6 +23266,9 @@ virDomainChrSourceDefFormat(virBufferPtr buf, virDomainSourceDefFormatSeclabel(&childBuf, def->nseclabels, def->seclabels, flags); =20 + virDomainChrSourceReconnectDefFormat(&childBuf, + &def->data.nix.reconnect); + if (virXMLFormatElement(buf, "source", &attrBuf, &childBuf) < = 0) goto error; } diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index c3d6845032..e2d0bb1b50 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1137,6 +1137,15 @@ typedef enum { VIR_DOMAIN_CHR_SPICEVMC_LAST } virDomainChrSpicevmcName; =20 + +struct _virDomainChrSourceReconnectDef { + virTristateBool enabled; + unsigned int timeout; +}; +typedef struct _virDomainChrSourceReconnectDef virDomainChrSourceReconnect= Def; +typedef virDomainChrSourceReconnectDef *virDomainChrSourceReconnectDefPtr; + + /* The host side information for a character device. */ struct _virDomainChrSourceDef { int type; /* virDomainChrType */ @@ -1159,6 +1168,7 @@ struct _virDomainChrSourceDef { bool tlscreds; int haveTLS; /* enum virTristateBool */ bool tlsFromConfig; + virDomainChrSourceReconnectDef reconnect; } tcp; struct { char *bindHost; @@ -1169,6 +1179,7 @@ struct _virDomainChrSourceDef { struct { char *path; bool listen; + virDomainChrSourceReconnectDef reconnect; } nix; int spicevmc; struct { --=20 2.13.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list