From a54b4144fb7209e1c9c17843f57e626a7ec180ab Mon Sep 17 00:00:00 2001 From: Kiarie Kahurani Date: Tue, 12 Aug 2014 00:21:33 +0300 Subject: [PATCH] src/xenxs: Refactor code formating Vfb config introduce function xenFormatXMVfb(virConfPtr conf,.........); which formats Vfb config instead Signed-off-by: Kiarie Kahurani --- src/xenxs/xen_xm.c | 184 +++++++++++++++++++++++++-------------------- 1 file changed, 104 insertions(+), 80 deletions(-) diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index 72ae913ba..77e7fde32 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -2128,120 +2128,69 @@ xenFormatXMOS(virConfPtr conf, virDomainDefPtr def) } -/* Computing the vcpu_avail bitmask works because MAX_VIRT_CPUS is - either 32, or 64 on a platform where long is big enough. */ -verify(MAX_VIRT_CPUS <= sizeof(1UL) * CHAR_BIT); - -virConfPtr -xenFormatXM(virConnectPtr conn, - virDomainDefPtr def, - int xendConfigVersion) +static int +xenFormatXMVfb(virConfPtr conf, + virDomainDefPtr def, + int xendConfigVersion) { - virConfPtr conf = NULL; int hvm = STREQ(def->os.type, "hvm") ? 1 : 0; - size_t i; - virConfValuePtr netVal = NULL; - - if (!(conf = virConfNew())) - goto cleanup; - - if (xenFormatXMGeneralMeta(conf, def) < 0) - goto cleanup; - - if (xenFormatXMMem(conf, def) < 0) - goto cleanup; - - if (xenFormatXMCPUAllocation(conf, def) < 0) - goto cleanup; - - if (xenFormatXMOS(conf, def) < 0) - goto cleanup; - - if (xenFormatXMCPUFeatures(conf, def, xendConfigVersion) < 0) - goto cleanup; - - if (xenFormatXMCDROM(conf, def, xendConfigVersion) < 0) - goto cleanup; - - if (xenFormatXMTimeOffset(conf, def, xendConfigVersion) < 0) - goto cleanup; - - if (xenFormatXMEventActions(conf, def) < 0) - goto cleanup; - - if (xenFormatXMEmulator(conf, def) < 0) - goto cleanup; - - if (hvm) { - for (i = 0; i < def->ninputs; i++) { - if (def->inputs[i]->bus == VIR_DOMAIN_INPUT_BUS_USB) { - if (xenXMConfigSetInt(conf, "usb", 1) < 0) - goto cleanup; - switch (def->inputs[i]->type) { - case VIR_DOMAIN_INPUT_TYPE_MOUSE: - if (xenXMConfigSetString(conf, "usbdevice", "mouse") < 0) - goto cleanup; - break; - case VIR_DOMAIN_INPUT_TYPE_TABLET: - if (xenXMConfigSetString(conf, "usbdevice", "tablet") < 0) - goto cleanup; - break; - case VIR_DOMAIN_INPUT_TYPE_KBD: - if (xenXMConfigSetString(conf, "usbdevice", "keyboard") < 0) - goto cleanup; - break; - } - break; - } - } - } if (def->ngraphics == 1) { if (hvm || (xendConfigVersion < XEND_CONFIG_MIN_VERS_PVFB_NEWCONF)) { if (def->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_SDL) { if (xenXMConfigSetInt(conf, "sdl", 1) < 0) - goto cleanup; + return -1; + if (xenXMConfigSetInt(conf, "vnc", 0) < 0) - goto cleanup; + return -1; + if (def->graphics[0]->data.sdl.display && xenXMConfigSetString(conf, "display", def->graphics[0]->data.sdl.display) < 0) - goto cleanup; + return -1; + if (def->graphics[0]->data.sdl.xauth && xenXMConfigSetString(conf, "xauthority", def->graphics[0]->data.sdl.xauth) < 0) - goto cleanup; + return -1; } else { const char *listenAddr; if (xenXMConfigSetInt(conf, "sdl", 0) < 0) - goto cleanup; + return -1; + if (xenXMConfigSetInt(conf, "vnc", 1) < 0) - goto cleanup; + return -1; + if (xenXMConfigSetInt(conf, "vncunused", def->graphics[0]->data.vnc.autoport ? 1 : 0) < 0) - goto cleanup; + return -1; + if (!def->graphics[0]->data.vnc.autoport && xenXMConfigSetInt(conf, "vncdisplay", def->graphics[0]->data.vnc.port - 5900) < 0) - goto cleanup; + return -1; + listenAddr = virDomainGraphicsListenGetAddress(def->graphics[0], 0); if (listenAddr && xenXMConfigSetString(conf, "vnclisten", listenAddr) < 0) - goto cleanup; + return -1; + if (def->graphics[0]->data.vnc.auth.passwd && xenXMConfigSetString(conf, "vncpasswd", def->graphics[0]->data.vnc.auth.passwd) < 0) - goto cleanup; + return -1; + if (def->graphics[0]->data.vnc.keymap && xenXMConfigSetString(conf, "keymap", def->graphics[0]->data.vnc.keymap) < 0) - goto cleanup; + return -1; } } else { virConfValuePtr vfb, disp; char *vfbstr = NULL; virBuffer buf = VIR_BUFFER_INITIALIZER; + if (def->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_SDL) { virBufferAddLit(&buf, "type=sdl"); if (def->graphics[0]->data.sdl.display) @@ -2270,19 +2219,19 @@ xenFormatXM(virConnectPtr conn, def->graphics[0]->data.vnc.keymap); } if (virBufferCheckError(&buf) < 0) - goto cleanup; + return -1; vfbstr = virBufferContentAndReset(&buf); if (VIR_ALLOC(vfb) < 0) { VIR_FREE(vfbstr); - goto cleanup; + return -1; } if (VIR_ALLOC(disp) < 0) { VIR_FREE(vfb); VIR_FREE(vfbstr); - goto cleanup; + return -1; } vfb->type = VIR_CONF_LIST; @@ -2291,10 +2240,85 @@ xenFormatXM(virConnectPtr conn, disp->str = vfbstr; if (virConfSetValue(conf, "vfb", vfb) < 0) - goto cleanup; + return -1; } } + return 0; +} + + +/* Computing the vcpu_avail bitmask works because MAX_VIRT_CPUS is + either 32, or 64 on a platform where long is big enough. */ +verify(MAX_VIRT_CPUS <= sizeof(1UL) * CHAR_BIT); + +virConfPtr +xenFormatXM(virConnectPtr conn, + virDomainDefPtr def, + int xendConfigVersion) +{ + virConfPtr conf = NULL; + int hvm = STREQ(def->os.type, "hvm") ? 1 : 0; + size_t i; + virConfValuePtr netVal = NULL; + + if (!(conf = virConfNew())) + goto cleanup; + + if (xenFormatXMGeneralMeta(conf, def) < 0) + goto cleanup; + + if (xenFormatXMMem(conf, def) < 0) + goto cleanup; + + if (xenFormatXMCPUAllocation(conf, def) < 0) + goto cleanup; + + if (xenFormatXMOS(conf, def) < 0) + goto cleanup; + + if (xenFormatXMCPUFeatures(conf, def, xendConfigVersion) < 0) + goto cleanup; + + if (xenFormatXMCDROM(conf, def, xendConfigVersion) < 0) + goto cleanup; + + if (xenFormatXMTimeOffset(conf, def, xendConfigVersion) < 0) + goto cleanup; + + if (xenFormatXMEventActions(conf, def) < 0) + goto cleanup; + + if (xenFormatXMEmulator(conf, def) < 0) + goto cleanup; + + if (hvm) { + for (i = 0; i < def->ninputs; i++) { + if (def->inputs[i]->bus == VIR_DOMAIN_INPUT_BUS_USB) { + if (xenXMConfigSetInt(conf, "usb", 1) < 0) + goto cleanup; + switch (def->inputs[i]->type) { + case VIR_DOMAIN_INPUT_TYPE_MOUSE: + if (xenXMConfigSetString(conf, "usbdevice", "mouse") < 0) + goto cleanup; + break; + case VIR_DOMAIN_INPUT_TYPE_TABLET: + if (xenXMConfigSetString(conf, "usbdevice", "tablet") < 0) + goto cleanup; + break; + case VIR_DOMAIN_INPUT_TYPE_KBD: + if (xenXMConfigSetString(conf, "usbdevice", "keyboard") < 0) + goto cleanup; + break; + } + break; + } + } + } + + if (xenFormatXMVfb(conf, def, xendConfigVersion) < 0) + goto cleanup; + if (xenFormatXMDisks(conf, def, xendConfigVersion) < 0) goto cleanup; -- 2.39.5