提交 2e4defdc 编写于 作者: M Michal Privoznik

graphics: Cleanup port policy

Even though we say in documentation setting (tls-)port to -1 is legacy
compat style for enabling autoport, we're roughly doing this for VNC.
However, in case of SPICE auto enable autoport iff both port & tlsPort
are equal -1 as documentation says autoport plays with both.
上级 19c7980e
...@@ -5929,6 +5929,10 @@ virDomainGraphicsDefParseXML(xmlNodePtr node, ...@@ -5929,6 +5929,10 @@ virDomainGraphicsDefParseXML(xmlNodePtr node,
VIR_FREE(port); VIR_FREE(port);
goto error; goto error;
} }
/* Legacy compat syntax, used -1 for auto-port */
if (def->data.rdp.port == -1)
def->data.rdp.autoport = 1;
VIR_FREE(port); VIR_FREE(port);
} else { } else {
def->data.rdp.port = 0; def->data.rdp.port = 0;
...@@ -5936,14 +5940,15 @@ virDomainGraphicsDefParseXML(xmlNodePtr node, ...@@ -5936,14 +5940,15 @@ virDomainGraphicsDefParseXML(xmlNodePtr node,
} }
if ((autoport = virXMLPropString(node, "autoport")) != NULL) { if ((autoport = virXMLPropString(node, "autoport")) != NULL) {
if (STREQ(autoport, "yes")) { if (STREQ(autoport, "yes"))
if (flags & VIR_DOMAIN_XML_INACTIVE)
def->data.rdp.port = 0;
def->data.rdp.autoport = 1; def->data.rdp.autoport = 1;
}
VIR_FREE(autoport); VIR_FREE(autoport);
} }
if (def->data.rdp.autoport && (flags & VIR_DOMAIN_XML_INACTIVE))
def->data.rdp.port = 0;
if ((replaceUser = virXMLPropString(node, "replaceUser")) != NULL) { if ((replaceUser = virXMLPropString(node, "replaceUser")) != NULL) {
if (STREQ(replaceUser, "yes")) { if (STREQ(replaceUser, "yes")) {
def->data.rdp.replaceUser = 1; def->data.rdp.replaceUser = 1;
...@@ -6009,16 +6014,21 @@ virDomainGraphicsDefParseXML(xmlNodePtr node, ...@@ -6009,16 +6014,21 @@ virDomainGraphicsDefParseXML(xmlNodePtr node,
} }
if ((autoport = virXMLPropString(node, "autoport")) != NULL) { if ((autoport = virXMLPropString(node, "autoport")) != NULL) {
if (STREQ(autoport, "yes")) { if (STREQ(autoport, "yes"))
if (flags & VIR_DOMAIN_XML_INACTIVE) {
def->data.spice.port = 0;
def->data.spice.tlsPort = 0;
}
def->data.spice.autoport = 1; def->data.spice.autoport = 1;
}
VIR_FREE(autoport); VIR_FREE(autoport);
} }
if (def->data.spice.port == -1 && def->data.spice.tlsPort == -1) {
/* Legacy compat syntax, used -1 for auto-port */
def->data.spice.autoport = 1;
}
if (def->data.spice.autoport && (flags & VIR_DOMAIN_XML_INACTIVE)) {
def->data.spice.port = 0;
def->data.spice.tlsPort = 0;
}
def->data.spice.keymap = virXMLPropString(node, "keymap"); def->data.spice.keymap = virXMLPropString(node, "keymap");
if (virDomainGraphicsAuthDefParseXML(node, &def->data.spice.auth, if (virDomainGraphicsAuthDefParseXML(node, &def->data.spice.auth,
......
...@@ -1183,6 +1183,11 @@ struct _virDomainGraphicsListenDef { ...@@ -1183,6 +1183,11 @@ struct _virDomainGraphicsListenDef {
}; };
struct _virDomainGraphicsDef { struct _virDomainGraphicsDef {
/* Port value discipline:
* Value -1 is legacy syntax indicating that it should be auto-allocated.
* Value 0 means port wasn't specified in XML at all.
* Positive value is actual port number given in XML.
*/
int type; int type;
union { union {
struct { struct {
......
...@@ -5379,7 +5379,7 @@ qemuBuildCommandLine(virConnectPtr conn, ...@@ -5379,7 +5379,7 @@ qemuBuildCommandLine(virConnectPtr conn,
virBufferAsprintf(&opt, "port=%u", def->graphics[0]->data.spice.port); virBufferAsprintf(&opt, "port=%u", def->graphics[0]->data.spice.port);
if (def->graphics[0]->data.spice.tlsPort) { if (def->graphics[0]->data.spice.tlsPort > 0) {
if (!driver->spiceTLS) { if (!driver->spiceTLS) {
qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED, qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("spice TLS port set in XML configuration," _("spice TLS port set in XML configuration,"
......
...@@ -3169,28 +3169,35 @@ int qemuProcessStart(virConnectPtr conn, ...@@ -3169,28 +3169,35 @@ int qemuProcessStart(virConnectPtr conn,
goto cleanup; goto cleanup;
} }
vm->def->graphics[0]->data.vnc.port = port; vm->def->graphics[0]->data.vnc.port = port;
} else if (vm->def->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE && } else if (vm->def->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE) {
vm->def->graphics[0]->data.spice.autoport) { int port = -1;
int port = qemuProcessNextFreePort(driver, QEMU_VNC_PORT_MIN); if (vm->def->graphics[0]->data.spice.autoport ||
int tlsPort = -1; vm->def->graphics[0]->data.spice.port == -1) {
if (port < 0) { port = qemuProcessNextFreePort(driver, QEMU_VNC_PORT_MIN);
qemuReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("Unable to find an unused SPICE port")); if (port < 0) {
goto cleanup; qemuReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("Unable to find an unused SPICE port"));
goto cleanup;
}
vm->def->graphics[0]->data.spice.port = port;
} }
if (driver->spiceTLS) { if (driver->spiceTLS &&
tlsPort = qemuProcessNextFreePort(driver, port + 1); (vm->def->graphics[0]->data.spice.autoport ||
vm->def->graphics[0]->data.spice.tlsPort == -1)) {
int tlsPort = qemuProcessNextFreePort(driver,
vm->def->graphics[0]->data.spice.port + 1);
if (tlsPort < 0) { if (tlsPort < 0) {
qemuReportError(VIR_ERR_INTERNAL_ERROR, qemuReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("Unable to find an unused SPICE TLS port")); "%s", _("Unable to find an unused SPICE TLS port"));
qemuProcessReturnPort(driver, port); qemuProcessReturnPort(driver, port);
goto cleanup; goto cleanup;
} }
}
vm->def->graphics[0]->data.spice.port = port; vm->def->graphics[0]->data.spice.tlsPort = tlsPort;
vm->def->graphics[0]->data.spice.tlsPort = tlsPort; }
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册