Move graphic device config to post parse. This way we
detect error on early stage and leverage checking on detach too.
Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy(a)virtuozzo.com>
---
src/vz/vz_driver.c | 2 +
src/vz/vz_sdk.c | 141 ++++++++++++++++++-----------------------------------
src/vz/vz_utils.c | 70 ++++++++++++++++++++++++++
src/vz/vz_utils.h | 2 +
4 files changed, 121 insertions(+), 94 deletions(-)
diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c
index ea28698..e57f573 100644
--- a/src/vz/vz_driver.c
+++ b/src/vz/vz_driver.c
@@ -257,6 +257,8 @@ vzDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
if (dev->type == VIR_DOMAIN_DEVICE_DISK)
return vzCheckUnsupportedDisk(def, dev->data.disk, opaque);
+ else if (dev->type == VIR_DOMAIN_DEVICE_GRAPHICS)
+ return vzCheckUnsupportedGraphics(dev->data.graphics);
return 0;
}
diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c
index 9ffcc70..322b316 100644
--- a/src/vz/vz_sdk.c
+++ b/src/vz/vz_sdk.c
@@ -2441,9 +2441,6 @@ static int prlsdkClearDevices(PRL_HANDLE sdkdom)
PRL_HANDLE dev;
int ret = -1;
- pret = PrlVmCfg_SetVNCMode(sdkdom, PRD_DISABLED);
- prlsdkCheckRetGoto(pret, cleanup);
-
pret = PrlVmCfg_GetAllDevices(sdkdom, &devList);
prlsdkCheckRetGoto(pret, cleanup);
@@ -2527,89 +2524,6 @@ prlsdkAddDeviceToBootList(PRL_HANDLE sdkdom,
return -1;
}
-static int prlsdkCheckGraphicsUnsupportedParams(virDomainDefPtr def)
-{
- virDomainGraphicsDefPtr gr;
-
- if (def->ngraphics == 0)
- return 0;
-
- if (def->ngraphics > 1) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
- _("vz driver supports only "
- "one VNC per domain."));
- return -1;
- }
-
- gr = def->graphics[0];
-
- if (gr->type != VIR_DOMAIN_GRAPHICS_TYPE_VNC) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
- _("vz driver supports only "
- "VNC graphics."));
- return -1;
- }
-
- if (gr->data.vnc.websocket != 0) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
- _("vz driver doesn't support "
- "websockets for VNC graphics."));
- return -1;
- }
-
- if (gr->data.vnc.keymap != 0 &&
- STRNEQ(gr->data.vnc.keymap, "en-us")) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
- _("vz driver supports only "
- "\"en-us\" keymap for VNC graphics."));
- return -1;
- }
-
- if (gr->data.vnc.sharePolicy == VIR_DOMAIN_GRAPHICS_VNC_SHARE_ALLOW_EXCLUSIVE) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
- _("vz driver doesn't support "
- "exclusive share policy for VNC graphics."));
- return -1;
- }
-
- if (gr->data.vnc.socket) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
- _("vz driver doesn't support "
- "VNC graphics over unix sockets."));
- return -1;
- }
-
- if (gr->data.vnc.auth.connected == VIR_DOMAIN_GRAPHICS_AUTH_CONNECTED_FAIL ||
- gr->data.vnc.auth.connected == VIR_DOMAIN_GRAPHICS_AUTH_CONNECTED_KEEP) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
- _("vz driver doesn't support "
- "given action in case of password change."));
- return -1;
- }
-
- if (gr->data.vnc.auth.expires) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
- _("vz driver doesn't support "
- "setting password expire time."));
- return -1;
- }
-
- if (gr->nListens > 1) {
- virReportError(VIR_ERR_INVALID_ARG, "%s",
- _("vz driver doesn't support more than "
- "one listening VNC server per domain"));
- return -1;
- }
-
- if (gr->nListens == 1 &&
- gr->listens[0].type != VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS) {
- virReportError(VIR_ERR_INVALID_ARG, "%s",
- _("vz driver supports only address-based VNC
listening"));
- return -1;
- }
-
- return 0;
-}
static int prlsdkCheckVideoUnsupportedParams(virDomainDefPtr def)
{
@@ -2833,20 +2747,19 @@ static int prlsdkCheckFSUnsupportedParams(virDomainFSDefPtr fs)
return 0;
}
-static int prlsdkApplyGraphicsParams(PRL_HANDLE sdkdom, virDomainDefPtr def)
+static int prlsdkApplyGraphicsParams(PRL_HANDLE sdkdom,
+ virDomainGraphicsDefPtr gr)
{
- virDomainGraphicsDefPtr gr;
virDomainGraphicsListenDefPtr gListen;
PRL_RESULT pret;
int ret = -1;
- if (prlsdkCheckGraphicsUnsupportedParams(def))
- return -1;
+ if (!gr) {
+ pret = PrlVmCfg_SetVNCMode(sdkdom, PRD_DISABLED);
+ prlsdkCheckRetExit(pret, -1);
- if (def->ngraphics == 0)
return 0;
-
- gr = def->graphics[0];
+ }
if (gr->data.vnc.autoport) {
pret = PrlVmCfg_SetVNCMode(sdkdom, PRD_AUTO);
@@ -3449,6 +3362,17 @@ prlsdkAttachDevice(vzDriverPtr driver,
return -1;
break;
+ case VIR_DOMAIN_DEVICE_GRAPHICS:
+ if (dom->def->ngraphics > 0) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("domain already has VNC graphics"));
+ return -1;
+ }
+
+ if (prlsdkApplyGraphicsParams(privdom->sdkdom, dev->data.graphics) < 0)
+ return -1;
+
+ break;
default:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("attaching device type '%s' is unsupported"),
@@ -3505,6 +3429,17 @@ prlsdkDetachDevice(vzDriverPtr driver,
prlsdkCheckRetGoto(pret, cleanup);
break;
+ case VIR_DOMAIN_DEVICE_GRAPHICS:
+ if (dom->def->ngraphics < 1) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("cannot find VNC graphics device"));
+ goto cleanup;
+ }
+
+ if (prlsdkApplyGraphicsParams(privdom->sdkdom, NULL) < 0)
+ goto cleanup;
+
+ break;
default:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("detaching device type '%s' is unsupported"),
@@ -3549,6 +3484,17 @@ prlsdkUpdateDevice(vzDriverPtr driver,
return -1;
break;
+ case VIR_DOMAIN_DEVICE_GRAPHICS:
+ if (dom->def->ngraphics < 1) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("cannot find VNC graphics device"));
+ return -1;
+ }
+
+ if (prlsdkApplyGraphicsParams(privdom->sdkdom, dev->data.graphics) < 0)
+ return -1;
+
+ break;
default:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("updating device type '%s' is unsupported"),
@@ -3752,7 +3698,14 @@ prlsdkDoApplyConfig(vzDriverPtr driver,
goto error;
}
- if (prlsdkApplyGraphicsParams(sdkdom, def) < 0)
+ if (def->ngraphics > 1) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("vz driver supports only VNC graphics"));
+ goto error;
+ }
+
+ if (prlsdkApplyGraphicsParams(sdkdom,
+ def->ngraphics == 1 ? def->graphics[0] : NULL)
< 0)
goto error;
if (prlsdkApplyVideoParams(sdkdom, def) < 0)
diff --git a/src/vz/vz_utils.c b/src/vz/vz_utils.c
index 5c53e79..a6f5919 100644
--- a/src/vz/vz_utils.c
+++ b/src/vz/vz_utils.c
@@ -555,3 +555,73 @@ int vzGetDefaultSCSIModel(vzDriverPtr driver,
}
return 0;
}
+
+int vzCheckUnsupportedGraphics(virDomainGraphicsDefPtr gr)
+{
+ if (gr->type != VIR_DOMAIN_GRAPHICS_TYPE_VNC) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("vz driver supports only "
+ "VNC graphics."));
+ return -1;
+ }
+
+ if (gr->data.vnc.websocket != 0) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("vz driver doesn't support "
+ "websockets for VNC graphics."));
+ return -1;
+ }
+
+ if (gr->data.vnc.keymap != 0 &&
+ STRNEQ(gr->data.vnc.keymap, "en-us")) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("vz driver supports only "
+ "\"en-us\" keymap for VNC graphics."));
+ return -1;
+ }
+
+ if (gr->data.vnc.sharePolicy == VIR_DOMAIN_GRAPHICS_VNC_SHARE_ALLOW_EXCLUSIVE) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("vz driver doesn't support "
+ "exclusive share policy for VNC graphics."));
+ return -1;
+ }
+
+ if (gr->data.vnc.socket) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("vz driver doesn't support "
+ "VNC graphics over unix sockets."));
+ return -1;
+ }
+
+ if (gr->data.vnc.auth.connected == VIR_DOMAIN_GRAPHICS_AUTH_CONNECTED_FAIL ||
+ gr->data.vnc.auth.connected == VIR_DOMAIN_GRAPHICS_AUTH_CONNECTED_KEEP) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("vz driver doesn't support "
+ "given action in case of password change."));
+ return -1;
+ }
+
+ if (gr->data.vnc.auth.expires) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("vz driver doesn't support "
+ "setting password expire time."));
+ return -1;
+ }
+
+ if (gr->nListens > 1) {
+ virReportError(VIR_ERR_INVALID_ARG, "%s",
+ _("vz driver doesn't support more than "
+ "one listening VNC server per domain"));
+ return -1;
+ }
+
+ if (gr->nListens == 1 &&
+ gr->listens[0].type != VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS) {
+ virReportError(VIR_ERR_INVALID_ARG, "%s",
+ _("vz driver supports only address-based VNC
listening"));
+ return -1;
+ }
+
+ return 0;
+}
diff --git a/src/vz/vz_utils.h b/src/vz/vz_utils.h
index fc5f695..a8a74b6 100644
--- a/src/vz/vz_utils.h
+++ b/src/vz/vz_utils.h
@@ -138,6 +138,8 @@ int
vzGetDefaultSCSIModel(vzDriverPtr driver,
PRL_CLUSTERED_DEVICE_SUBTYPE *scsiModel);
+int vzCheckUnsupportedGraphics(virDomainGraphicsDefPtr gr);
+
# define PARALLELS_BLOCK_STATS_FOREACH(OP) \
OP(rd_req, VIR_DOMAIN_BLOCK_STATS_READ_REQ, "read_requests") \
OP(rd_bytes, VIR_DOMAIN_BLOCK_STATS_READ_BYTES, "read_total") \
--
1.8.3.1