From 61a0026a941c0bd8c4e916b4cf62e53e77152713 Mon Sep 17 00:00:00 2001 From: Nikolay Shirokovskiy Date: Tue, 22 Nov 2016 14:09:33 +0300 Subject: [PATCH] qemu: Fix xml dump of autogenerated websocket When save/migrate a domain and we autogenerated a port, then if we print the inactive domain config, write out a -1 for the socket value; otherwise, it's possible that the subsequent start will fail if the autogenerated websocket used conflicts with an existing running config that also used autogenerated websockets. Examples: == A. Can not restore domain with autoconfigured websocket. domain 1 and 2 have autoconfigured websocket. 1. domain 1 is started then, saved 2. domain 2 is started 3. domain 1 restoration is failed: error: internal error: qemu unexpectedly closed the monitor: 2016-11-21T10:23:11.356687Z qemu-kvm: -vnc 0.0.0.0:2,websocket=5700: Failed to start VNC server on `(null)': Failed to bind socket: Address already in use == B. Can not migrate domain with autoconfigured websocket. domain 1 on host A, domain 2 on host B, both have autoconfigured websocket 1. domain 1 started, domain 2 started 2. domain 1 migration to host B is failed with the above error. --- src/conf/domain_conf.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 7715cadbdc..b0bd38d35c 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -22762,7 +22762,10 @@ virDomainGraphicsDefFormat(virBufferPtr buf, virBufferAsprintf(buf, " autoport='%s'", def->data.vnc.autoport ? "yes" : "no"); - if (def->data.vnc.websocket) + if (def->data.vnc.websocketGenerated && + (flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE)) + virBufferAddLit(buf, " websocket='-1'"); + else if (def->data.vnc.websocket) virBufferAsprintf(buf, " websocket='%d'", def->data.vnc.websocket); virDomainGraphicsListenDefFormatAddr(buf, glisten, flags);