Kiarie Kahurani wrote: > introduce function > xenFormatXMEmulatedHardware(virConfPtr conf,....); > You've also added xenFormatXMVif in this patch. It should be in a separate patch IMO. Once removed, a better description of this patch is "src/xenxs: Refactor code formating peripheral device config" since it parses input devices, sound, etc. > which formats emulated hardware config instead > > Signed-off-by: Kiarie Kahurani <davidkiarie4@xxxxxxxxx> > --- > src/xenxs/xen_xm.c | 150 +++++++++++++++++------------ > tests/xmconfigdata/test-escape-paths.cfg | 2 +- > tests/xmconfigdata/test-fullvirt-sound.cfg | 2 +- > 3 files changed, 92 insertions(+), 62 deletions(-) > > diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c > index 4795644..9718c92 100644 > --- a/src/xenxs/xen_xm.c > +++ b/src/xenxs/xen_xm.c > @@ -2221,6 +2221,93 @@ xenFormatXMVfb(virConfPtr conf, virDomainDefPtr def, > > return 0; > } > + > + > +static int > +xenFormatXMVif(virConfPtr conf, virConnectPtr conn, > + virDomainDefPtr def, int xendConfigVersion) > +{ > + virConfValuePtr netVal = NULL; > + size_t i; > + int hvm = STREQ(def->os.type, "hvm"); > + > + if (VIR_ALLOC(netVal) < 0) > + goto cleanup; > + netVal->type = VIR_CONF_LIST; > + netVal->list = NULL; > + > + for (i = 0; i < def->nnets; i++) { > + if (xenFormatXMNet(conn, netVal, def->nets[i], > + hvm, xendConfigVersion) < 0) > + goto cleanup; > + } > + > + if (netVal->list != NULL) { > + int ret = virConfSetValue(conf, "vif", netVal); > + netVal = NULL; > + if (ret < 0) > + goto cleanup; > + } > + > + VIR_FREE(netVal); > + return 0; > + > + cleanup: > + virConfFreeValue(netVal); > + return -1; > +} > + > + > +static int > +xenFormatXMEmulatedHardware(virConfPtr conf, virDomainDefPtr def) > I've split this into xenFormatXMInputDevs and xenFormatXMSound. > +{ > + size_t i; > + > + if (STREQ(def->os.type, "hvm")) { > + if (def->sounds) { > + virBuffer buf = VIR_BUFFER_INITIALIZER; > + char *str = NULL; > + int ret = xenFormatSxprSound(def, &buf); > + str = virBufferContentAndReset(&buf); > + if (ret == 0) > + ret = xenXMConfigSetString(conf, "soundhw", str); > + > + VIR_FREE(str); > + if (ret < 0) > + return -1; > + } > + > + for (i = 0; i < def->ninputs; i++) { > + if (def->inputs[i]->bus == VIR_DOMAIN_INPUT_BUS_USB) { > + if (xenXMConfigSetInt(conf, "usb", 1) < 0) > + return -1; > + > + switch (def->inputs[i]->type) { > + case VIR_DOMAIN_INPUT_TYPE_MOUSE: > + if (xenXMConfigSetString(conf, "usbdevice", "mouse") < 0) > + return -1; > + > + break; > + case VIR_DOMAIN_INPUT_TYPE_TABLET: > + if (xenXMConfigSetString(conf, "usbdevice", "tablet") < 0) > + return -1; > + > + break; > + case VIR_DOMAIN_INPUT_TYPE_KBD: > + if (xenXMConfigSetString(conf, "usbdevice", "keyboard") < 0) > + return -1; > + > + break; > + } > + break; > + } > + } > + } > + > + 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); > @@ -2231,9 +2318,6 @@ xenFormatXM(virConnectPtr conn, > int xendConfigVersion) > { > virConfPtr conf = NULL; > - int hvm = 0; > - size_t i; > - virConfValuePtr netVal = NULL; > > if (!(conf = virConfNew())) > goto cleanup; > @@ -2247,8 +2331,6 @@ xenFormatXM(virConnectPtr conn, > if (xenFormatXMCPUFeatures(conf, def, xendConfigVersion) < 0) > goto cleanup; > > - hvm = STREQ(def->os.type, "hvm"); > - > if (xenFormatXMOS(conf, def, xendConfigVersion) < 0) > goto cleanup; > > @@ -2258,29 +2340,8 @@ xenFormatXM(virConnectPtr conn, > if (xenFormatXMEventActions(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 (xenFormatXMEmulatedHardware(conf, def) < 0) > + goto cleanup; > > if (xenFormatXMVfb(conf, def, xendConfigVersion) < 0) > goto cleanup; > @@ -2288,23 +2349,8 @@ xenFormatXM(virConnectPtr conn, > if (xenFormatXMDomainDisks(conf, def, xendConfigVersion) < 0) > goto cleanup; > > - if (VIR_ALLOC(netVal) < 0) > + if (xenFormatXMVif(conf, conn, def, xendConfigVersion) < 0) > goto cleanup; > - netVal->type = VIR_CONF_LIST; > - netVal->list = NULL; > - > - for (i = 0; i < def->nnets; i++) { > - if (xenFormatXMNet(conn, netVal, def->nets[i], > - hvm, xendConfigVersion) < 0) > - goto cleanup; > - } > - if (netVal->list != NULL) { > - int ret = virConfSetValue(conf, "vif", netVal); > - netVal = NULL; > - if (ret < 0) > - goto cleanup; > - } > - VIR_FREE(netVal); > > if (xenFormatXMPCI(conf, def) < 0) > goto cleanup; > @@ -2312,25 +2358,9 @@ xenFormatXM(virConnectPtr conn, > if (xenFormatXMCharDev(conf, def) < 0) > goto cleanup; > > - if (hvm) { > - if (def->sounds) { > - virBuffer buf = VIR_BUFFER_INITIALIZER; > - char *str = NULL; > - int ret = xenFormatSxprSound(def, &buf); > - str = virBufferContentAndReset(&buf); > - if (ret == 0) > - ret = xenXMConfigSetString(conf, "soundhw", str); > - > - VIR_FREE(str); > - if (ret < 0) > - goto cleanup; > - } > - } > - > return conf; > > cleanup: > - virConfFreeValue(netVal); > if (conf) > virConfFree(conf); > return NULL; > diff --git a/tests/xmconfigdata/test-escape-paths.cfg b/tests/xmconfigdata/test-escape-paths.cfg > > index 68984da..1336ece 100644 > --- a/tests/xmconfigdata/test-escape-paths.cfg > +++ b/tests/xmconfigdata/test-escape-paths.cfg > Separate functions for sound and input devices also avoids changes to the test data files. Simplified patch below. I've also included the trivial "11.2/12" patch for refactoring the vif formatting. Regards, Jim
>From ef4b383565fd030e67042cfd197e5f0251d28871 Mon Sep 17 00:00:00 2001 From: Kiarie Kahurani <davidkiarie4@xxxxxxxxx> Date: Tue, 12 Aug 2014 00:21:34 +0300 Subject: [PATCH 10/11] src/xenxs: Refactor code formating peripheral device config introduce functions xenFormatXMSound xenFormatXMInputDevs(virConfPtr conf,....); which formats peripheral device config instead Signed-off-by: Kiarie Kahurani <davidkiarie4@xxxxxxxxx> Signed-off-by: Jim Fehlig <jfehlig@xxxxxxxx> --- src/xenxs/xen_xm.c | 101 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 64 insertions(+), 37 deletions(-) diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index 77e7fde..2f79182 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -2248,6 +2248,66 @@ xenFormatXMVfb(virConfPtr conf, } +static int +xenFormatXMSound(virConfPtr conf, virDomainDefPtr def) +{ + if (STREQ(def->os.type, "hvm")) { + if (def->sounds) { + virBuffer buf = VIR_BUFFER_INITIALIZER; + char *str = NULL; + int ret = xenFormatSxprSound(def, &buf); + + str = virBufferContentAndReset(&buf); + if (ret == 0) + ret = xenXMConfigSetString(conf, "soundhw", str); + + VIR_FREE(str); + if (ret < 0) + return -1; + } + } + + return 0; +} + + +static int +xenFormatXMInputDevs(virConfPtr conf, virDomainDefPtr def) +{ + size_t i; + + if (STREQ(def->os.type, "hvm")) { + for (i = 0; i < def->ninputs; i++) { + if (def->inputs[i]->bus == VIR_DOMAIN_INPUT_BUS_USB) { + if (xenXMConfigSetInt(conf, "usb", 1) < 0) + return -1; + + switch (def->inputs[i]->type) { + case VIR_DOMAIN_INPUT_TYPE_MOUSE: + if (xenXMConfigSetString(conf, "usbdevice", "mouse") < 0) + return -1; + + break; + case VIR_DOMAIN_INPUT_TYPE_TABLET: + if (xenXMConfigSetString(conf, "usbdevice", "tablet") < 0) + return -1; + + break; + case VIR_DOMAIN_INPUT_TYPE_KBD: + if (xenXMConfigSetString(conf, "usbdevice", "keyboard") < 0) + return -1; + + break; + } + break; + } + } + } + + 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); @@ -2292,29 +2352,8 @@ xenFormatXM(virConnectPtr conn, 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 (xenFormatXMInputDevs(conf, def) < 0) + goto cleanup; if (xenFormatXMVfb(conf, def, xendConfigVersion) < 0) goto cleanup; @@ -2346,20 +2385,8 @@ xenFormatXM(virConnectPtr conn, if (xenFormatXMCharDev(conf, def) < 0) goto cleanup; - if (hvm) { - if (def->sounds) { - virBuffer buf = VIR_BUFFER_INITIALIZER; - char *str = NULL; - int ret = xenFormatSxprSound(def, &buf); - str = virBufferContentAndReset(&buf); - if (ret == 0) - ret = xenXMConfigSetString(conf, "soundhw", str); - - VIR_FREE(str); - if (ret < 0) - goto cleanup; - } - } + if (xenFormatXMSound(conf, def) < 0) + goto cleanup; return conf; -- 1.8.4.5
>From c4a96b78e915e6d940a5d617c00b182415d99a35 Mon Sep 17 00:00:00 2001 From: Jim Fehlig <jfehlig@xxxxxxxx> Date: Wed, 13 Aug 2014 14:46:16 -0600 Subject: [PATCH 11/11] src/xenxs: Refactor code formating vif device config Handle formating of VIF config in a new function xenFormatXMVif(). Signed-off-by: Kiarie Kahurani <davidkiarie4@xxxxxxxxx> Signed-off-by: Jim Fehlig <jfehlig@xxxxxxxx> --- src/xenxs/xen_xm.c | 58 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index 2f79182..292903e 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -2308,6 +2308,43 @@ xenFormatXMInputDevs(virConfPtr conf, virDomainDefPtr def) } +static int +xenFormatXMVif(virConfPtr conf, + virConnectPtr conn, + virDomainDefPtr def, + int xendConfigVersion) +{ + virConfValuePtr netVal = NULL; + size_t i; + int hvm = STREQ(def->os.type, "hvm"); + + if (VIR_ALLOC(netVal) < 0) + goto cleanup; + netVal->type = VIR_CONF_LIST; + netVal->list = NULL; + + for (i = 0; i < def->nnets; i++) { + if (xenFormatXMNet(conn, netVal, def->nets[i], + hvm, xendConfigVersion) < 0) + goto cleanup; + } + + if (netVal->list != NULL) { + int ret = virConfSetValue(conf, "vif", netVal); + netVal = NULL; + if (ret < 0) + goto cleanup; + } + + VIR_FREE(netVal); + return 0; + + cleanup: + virConfFreeValue(netVal); + return -1; +} + + /* 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); @@ -2318,9 +2355,6 @@ xenFormatXM(virConnectPtr conn, 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; @@ -2361,23 +2395,8 @@ xenFormatXM(virConnectPtr conn, if (xenFormatXMDisks(conf, def, xendConfigVersion) < 0) goto cleanup; - if (VIR_ALLOC(netVal) < 0) + if (xenFormatXMVif(conf, conn, def, xendConfigVersion) < 0) goto cleanup; - netVal->type = VIR_CONF_LIST; - netVal->list = NULL; - - for (i = 0; i < def->nnets; i++) { - if (xenFormatXMNet(conn, netVal, def->nets[i], - hvm, xendConfigVersion) < 0) - goto cleanup; - } - if (netVal->list != NULL) { - int ret = virConfSetValue(conf, "vif", netVal); - netVal = NULL; - if (ret < 0) - goto cleanup; - } - VIR_FREE(netVal); if (xenFormatXMPCI(conf, def) < 0) goto cleanup; @@ -2391,7 +2410,6 @@ xenFormatXM(virConnectPtr conn, return conf; cleanup: - virConfFreeValue(netVal); if (conf) virConfFree(conf); return NULL; -- 1.8.4.5
-- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list