2
* xen_xm.c: Xen XM parsing functions
4
* Copyright (C) 2011 Univention GmbH
5
* Copyright (C) 2006-2007, 2009-2010 Red Hat, Inc.
6
* Copyright (C) 2006 Daniel P. Berrange
8
* This library is free software; you can redistribute it and/or
9
* modify it under the terms of the GNU Lesser General Public
10
* License as published by the Free Software Foundation; either
11
* version 2.1 of the License, or (at your option) any later version.
13
* This library is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
* Lesser General Public License for more details.
18
* You should have received a copy of the GNU Lesser General Public
19
* License along with this library; if not, write to the Free Software
20
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
* Author: Daniel P. Berrange <berrange@redhat.com>
23
* Author: Markus Groß <gross@univention.de>
29
#include "virterror_internal.h"
35
#include "count-one-bits.h"
36
#include "xenxs_private.h"
39
#include "domain_conf.h"
41
/* Convenience method to grab a int from the config file object */
42
static int xenXMConfigGetBool(virConfPtr conf,
49
if (!(val = virConfGetValue(conf, name))) {
54
if (val->type == VIR_CONF_LONG) {
55
*value = val->l ? 1 : 0;
56
} else if (val->type == VIR_CONF_STRING) {
57
*value = STREQ(val->str, "1") ? 1 : 0;
59
XENXS_ERROR(VIR_ERR_INTERNAL_ERROR,
60
_("config value %s was malformed"), name);
67
/* Convenience method to grab a int from the config file object */
68
static int xenXMConfigGetULong(virConfPtr conf,
75
if (!(val = virConfGetValue(conf, name))) {
80
if (val->type == VIR_CONF_LONG) {
82
} else if (val->type == VIR_CONF_STRING) {
84
*value = strtol(val->str, &ret, 10);
85
if (ret == val->str) {
86
XENXS_ERROR(VIR_ERR_INTERNAL_ERROR,
87
_("config value %s was malformed"), name);
91
XENXS_ERROR(VIR_ERR_INTERNAL_ERROR,
92
_("config value %s was malformed"), name);
99
/* Convenience method to grab a string from the config file object */
100
static int xenXMConfigGetString(virConfPtr conf,
107
if (!(val = virConfGetValue(conf, name))) {
112
if (val->type != VIR_CONF_STRING) {
113
XENXS_ERROR(VIR_ERR_INTERNAL_ERROR,
114
_("config value %s was malformed"), name);
124
static int xenXMConfigCopyStringInternal(virConfPtr conf,
131
if (!(val = virConfGetValue(conf, name))) {
134
XENXS_ERROR(VIR_ERR_INTERNAL_ERROR,
135
_("config value %s was missing"), name);
139
if (val->type != VIR_CONF_STRING) {
140
XENXS_ERROR(VIR_ERR_INTERNAL_ERROR,
141
_("config value %s was not a string"), name);
147
XENXS_ERROR(VIR_ERR_INTERNAL_ERROR,
148
_("config value %s was missing"), name);
152
if (!(*value = strdup(val->str))) {
161
static int xenXMConfigCopyString(virConfPtr conf,
164
return xenXMConfigCopyStringInternal(conf, name, value, 0);
167
static int xenXMConfigCopyStringOpt(virConfPtr conf,
170
return xenXMConfigCopyStringInternal(conf, name, value, 1);
174
/* Convenience method to grab a string UUID from the config file object */
175
static int xenXMConfigGetUUID(virConfPtr conf, const char *name, unsigned char *uuid) {
178
if (!uuid || !name || !conf) {
179
XENXS_ERROR(VIR_ERR_INVALID_ARG,
180
_("Arguments must be non null"));
184
if (!(val = virConfGetValue(conf, name))) {
185
XENXS_ERROR(VIR_ERR_CONF_SYNTAX,
186
_("config value %s was missing"), name);
190
if (val->type != VIR_CONF_STRING) {
191
XENXS_ERROR(VIR_ERR_CONF_SYNTAX,
192
_("config value %s not a string"), name);
197
XENXS_ERROR(VIR_ERR_CONF_SYNTAX,
198
_("%s can't be empty"), name);
202
if (virUUIDParse(val->str, uuid) < 0) {
203
XENXS_ERROR(VIR_ERR_CONF_SYNTAX,
204
_("%s not parseable"), val->str);
213
* Turn a config record into a lump of XML describing the
214
* domain, suitable for later feeding for virDomainCreateXML
217
xenParseXM(virConfPtr conf, int xendConfigVersion,
222
virConfValuePtr list;
223
virDomainDefPtr def = NULL;
224
virDomainDiskDefPtr disk = NULL;
225
virDomainNetDefPtr net = NULL;
226
virDomainGraphicsDefPtr graphics = NULL;
227
virDomainHostdevDefPtr hostdev = NULL;
229
const char *defaultArch, *defaultMachine;
233
char *listenAddr = NULL;
235
if (VIR_ALLOC(def) < 0) {
240
def->virtType = VIR_DOMAIN_VIRT_XEN;
243
if (xenXMConfigCopyString(conf, "name", &def->name) < 0)
245
if (xenXMConfigGetUUID(conf, "uuid", def->uuid) < 0)
249
if ((xenXMConfigGetString(conf, "builder", &str, "linux") == 0) &&
253
if (!(def->os.type = strdup(hvm ? "hvm" : "xen")))
256
defaultArch = virCapabilitiesDefaultGuestArch(caps, def->os.type, virDomainVirtTypeToString(def->virtType));
257
if (defaultArch == NULL) {
258
XENXS_ERROR(VIR_ERR_INTERNAL_ERROR,
259
_("no supported architecture for os type '%s'"),
263
if (!(def->os.arch = strdup(defaultArch)))
266
defaultMachine = virCapabilitiesDefaultGuestMachine(caps,
269
virDomainVirtTypeToString(def->virtType));
270
if (defaultMachine != NULL) {
271
if (!(def->os.machine = strdup(defaultMachine)))
277
if (xenXMConfigCopyString(conf, "kernel", &def->os.loader) < 0)
280
if (xenXMConfigGetString(conf, "boot", &boot, "c") < 0)
283
for (i = 0 ; i < VIR_DOMAIN_BOOT_LAST && boot[i] ; i++) {
286
def->os.bootDevs[i] = VIR_DOMAIN_BOOT_FLOPPY;
289
def->os.bootDevs[i] = VIR_DOMAIN_BOOT_CDROM;
292
def->os.bootDevs[i] = VIR_DOMAIN_BOOT_NET;
296
def->os.bootDevs[i] = VIR_DOMAIN_BOOT_DISK;
302
if (xenXMConfigCopyStringOpt(conf, "bootloader", &def->os.bootloader) < 0)
304
if (xenXMConfigCopyStringOpt(conf, "bootargs", &def->os.bootloaderArgs) < 0)
307
if (xenXMConfigCopyStringOpt(conf, "kernel", &def->os.kernel) < 0)
309
if (xenXMConfigCopyStringOpt(conf, "ramdisk", &def->os.initrd) < 0)
311
if (xenXMConfigCopyStringOpt(conf, "extra", &def->os.cmdline) < 0)
315
if (xenXMConfigGetULong(conf, "memory", &def->mem.cur_balloon,
316
MIN_XEN_GUEST_SIZE * 2) < 0)
319
if (xenXMConfigGetULong(conf, "maxmem", &def->mem.max_balloon,
320
def->mem.cur_balloon) < 0)
323
def->mem.cur_balloon *= 1024;
324
def->mem.max_balloon *= 1024;
326
if (xenXMConfigGetULong(conf, "vcpus", &count, 1) < 0 ||
327
MAX_VIRT_CPUS < count)
329
def->maxvcpus = count;
330
if (xenXMConfigGetULong(conf, "vcpu_avail", &count, -1) < 0)
332
def->vcpus = MIN(count_one_bits_l(count), def->maxvcpus);
334
if (xenXMConfigGetString(conf, "cpus", &str, NULL) < 0)
337
def->cpumasklen = 4096;
338
if (VIR_ALLOC_N(def->cpumask, def->cpumasklen) < 0)
341
if (virDomainCpuSetParse(str, 0,
342
def->cpumask, def->cpumasklen) < 0)
347
if (xenXMConfigGetString(conf, "on_poweroff", &str, "destroy") < 0)
349
if ((def->onPoweroff = virDomainLifecycleTypeFromString(str)) < 0) {
350
XENXS_ERROR(VIR_ERR_INTERNAL_ERROR,
351
_("unexpected value %s for on_poweroff"), str);
355
if (xenXMConfigGetString(conf, "on_reboot", &str, "restart") < 0)
357
if ((def->onReboot = virDomainLifecycleTypeFromString(str)) < 0) {
358
XENXS_ERROR(VIR_ERR_INTERNAL_ERROR,
359
_("unexpected value %s for on_reboot"), str);
363
if (xenXMConfigGetString(conf, "on_crash", &str, "restart") < 0)
365
if ((def->onCrash = virDomainLifecycleCrashTypeFromString(str)) < 0) {
366
XENXS_ERROR(VIR_ERR_INTERNAL_ERROR,
367
_("unexpected value %s for on_crash"), str);
374
if (xenXMConfigGetBool(conf, "pae", &val, 0) < 0)
377
def->features |= (1 << VIR_DOMAIN_FEATURE_PAE);
378
if (xenXMConfigGetBool(conf, "acpi", &val, 0) < 0)
381
def->features |= (1 << VIR_DOMAIN_FEATURE_ACPI);
382
if (xenXMConfigGetBool(conf, "apic", &val, 0) < 0)
385
def->features |= (1 << VIR_DOMAIN_FEATURE_APIC);
386
if (xenXMConfigGetBool(conf, "hap", &val, 0) < 0)
389
def->features |= (1 << VIR_DOMAIN_FEATURE_HAP);
390
if (xenXMConfigGetBool(conf, "viridian", &val, 0) < 0)
393
def->features |= (1 << VIR_DOMAIN_FEATURE_VIRIDIAN);
395
if (xenXMConfigGetBool(conf, "hpet", &val, -1) < 0)
397
else if (val != -1) {
398
virDomainTimerDefPtr timer;
400
if (VIR_ALLOC_N(def->clock.timers, 1) < 0 ||
401
VIR_ALLOC(timer) < 0) {
406
timer->name = VIR_DOMAIN_TIMER_NAME_HPET;
407
timer->present = val;
408
timer->tickpolicy = -1;
410
def->clock.ntimers = 1;
411
def->clock.timers[0] = timer;
414
if (xenXMConfigGetBool(conf, "localtime", &vmlocaltime, 0) < 0)
417
def->clock.offset = vmlocaltime ?
418
VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME :
419
VIR_DOMAIN_CLOCK_OFFSET_UTC;
421
if (xenXMConfigCopyStringOpt(conf, "device_model", &def->emulator) < 0)
424
list = virConfGetValue(conf, "disk");
425
if (list && list->type == VIR_CONF_LIST) {
432
if ((list->type != VIR_CONF_STRING) || (list->str == NULL))
436
if (VIR_ALLOC(disk) < 0)
440
* Disks have 3 components, SOURCE,DEST-DEVICE,MODE
441
* eg, phy:/dev/HostVG/XenGuest1,xvda,w
442
* The SOURCE is usually prefixed with a driver type,
443
* and optionally driver sub-type
444
* The DEST-DEVICE is optionally post-fixed with disk type
447
/* Extract the source file path*/
448
if (!(offset = strchr(head, ',')))
450
if ((offset - head) >= (PATH_MAX-1))
453
if (offset == head) {
454
disk->src = NULL; /* No source file given, eg CDROM with no media */
456
if (VIR_ALLOC_N(disk->src, (offset - head) + 1) < 0)
458
if (virStrncpy(disk->src, head, offset - head,
459
(offset - head) + 1) == NULL) {
460
XENXS_ERROR(VIR_ERR_INTERNAL_ERROR,
461
_("Source file %s too big for destination"),
468
/* Remove legacy ioemu: junk */
469
if (STRPREFIX(head, "ioemu:"))
472
/* Extract the dest device name */
473
if (!(offset = strchr(head, ',')))
475
if (VIR_ALLOC_N(disk->dst, (offset - head) + 1) < 0)
477
if (virStrncpy(disk->dst, head, offset - head,
478
(offset - head) + 1) == NULL) {
479
XENXS_ERROR(VIR_ERR_INTERNAL_ERROR,
480
_("Dest file %s too big for destination"), head);
486
/* Extract source driver type */
488
/* The main type phy:, file:, tap: ... */
489
if ((tmp = strchr(disk->src, ':')) != NULL) {
490
if (VIR_ALLOC_N(disk->driverName, (tmp - disk->src) + 1) < 0)
492
if (virStrncpy(disk->driverName, disk->src,
494
(tmp - disk->src) + 1) == NULL) {
495
XENXS_ERROR(VIR_ERR_INTERNAL_ERROR,
496
_("Driver name %s too big for destination"),
501
/* Strip the prefix we found off the source file name */
502
memmove(disk->src, disk->src+(tmp-disk->src)+1,
503
strlen(disk->src)-(tmp-disk->src));
506
/* And the sub-type for tap:XXX: type */
507
if (disk->driverName &&
508
STREQ(disk->driverName, "tap")) {
509
if (!(tmp = strchr(disk->src, ':')))
511
if (VIR_ALLOC_N(disk->driverType, (tmp - disk->src) + 1) < 0)
513
if (virStrncpy(disk->driverType, disk->src,
515
(tmp - disk->src) + 1) == NULL) {
516
XENXS_ERROR(VIR_ERR_INTERNAL_ERROR,
517
_("Driver type %s too big for destination"),
522
/* Strip the prefix we found off the source file name */
523
memmove(disk->src, disk->src+(tmp-disk->src)+1,
524
strlen(disk->src)-(tmp-disk->src));
528
/* No source, or driver name, so fix to phy: */
529
if (!disk->driverName &&
530
!(disk->driverName = strdup("phy")))
534
/* phy: type indicates a block device */
535
disk->type = STREQ(disk->driverName, "phy") ?
536
VIR_DOMAIN_DISK_TYPE_BLOCK : VIR_DOMAIN_DISK_TYPE_FILE;
538
/* Check for a :cdrom/:disk postfix */
539
disk->device = VIR_DOMAIN_DISK_DEVICE_DISK;
540
if ((tmp = strchr(disk->dst, ':')) != NULL) {
541
if (STREQ(tmp, ":cdrom"))
542
disk->device = VIR_DOMAIN_DISK_DEVICE_CDROM;
546
if (STRPREFIX(disk->dst, "xvd") || !hvm) {
547
disk->bus = VIR_DOMAIN_DISK_BUS_XEN;
548
} else if (STRPREFIX(disk->dst, "sd")) {
549
disk->bus = VIR_DOMAIN_DISK_BUS_SCSI;
551
disk->bus = VIR_DOMAIN_DISK_BUS_IDE;
554
if (STREQ(head, "r") ||
557
else if ((STREQ(head, "w!")) ||
561
/* Maintain list in sorted order according to target device name */
562
if (VIR_REALLOC_N(def->disks, def->ndisks+1) < 0)
564
def->disks[def->ndisks++] = disk;
569
virDomainDiskDefFree(disk);
573
if (hvm && xendConfigVersion == 1) {
574
if (xenXMConfigGetString(conf, "cdrom", &str, NULL) < 0)
577
if (VIR_ALLOC(disk) < 0)
580
disk->type = VIR_DOMAIN_DISK_TYPE_FILE;
581
disk->device = VIR_DOMAIN_DISK_DEVICE_CDROM;
582
if (!(disk->driverName = strdup("file")))
584
if (!(disk->src = strdup(str)))
586
if (!(disk->dst = strdup("hdc")))
588
disk->bus = VIR_DOMAIN_DISK_BUS_IDE;
591
if (VIR_REALLOC_N(def->disks, def->ndisks+1) < 0)
593
def->disks[def->ndisks++] = disk;
598
list = virConfGetValue(conf, "vif");
599
if (list && list->type == VIR_CONF_LIST) {
617
if ((list->type != VIR_CONF_STRING) || (list->str == NULL))
623
char *nextkey = strchr(key, ',');
625
if (!(data = strchr(key, '=')))
629
if (STRPREFIX(key, "mac=")) {
630
int len = nextkey ? (nextkey - data) : sizeof(mac) - 1;
631
if (virStrncpy(mac, data, len, sizeof(mac)) == NULL) {
632
XENXS_ERROR(VIR_ERR_INTERNAL_ERROR,
633
_("MAC address %s too big for destination"),
637
} else if (STRPREFIX(key, "bridge=")) {
638
int len = nextkey ? (nextkey - data) : sizeof(bridge) - 1;
639
if (virStrncpy(bridge, data, len, sizeof(bridge)) == NULL) {
640
XENXS_ERROR(VIR_ERR_INTERNAL_ERROR,
641
_("Bridge %s too big for destination"),
645
} else if (STRPREFIX(key, "script=")) {
646
int len = nextkey ? (nextkey - data) : strlen(data);
648
if (!(script = strndup(data, len))) {
651
} else if (STRPREFIX(key, "model=")) {
652
int len = nextkey ? (nextkey - data) : sizeof(model) - 1;
653
if (virStrncpy(model, data, len, sizeof(model)) == NULL) {
654
XENXS_ERROR(VIR_ERR_INTERNAL_ERROR,
655
_("Model %s too big for destination"), data);
658
} else if (STRPREFIX(key, "type=")) {
659
int len = nextkey ? (nextkey - data) : sizeof(type) - 1;
660
if (virStrncpy(type, data, len, sizeof(type)) == NULL) {
661
XENXS_ERROR(VIR_ERR_INTERNAL_ERROR,
662
_("Type %s too big for destination"), data);
665
} else if (STRPREFIX(key, "vifname=")) {
666
int len = nextkey ? (nextkey - data) : sizeof(vifname) - 1;
667
if (virStrncpy(vifname, data, len, sizeof(vifname)) == NULL) {
668
XENXS_ERROR(VIR_ERR_INTERNAL_ERROR,
669
_("Vifname %s too big for destination"),
673
} else if (STRPREFIX(key, "ip=")) {
674
int len = nextkey ? (nextkey - data) : sizeof(ip) - 1;
675
if (virStrncpy(ip, data, len, sizeof(ip)) == NULL) {
676
XENXS_ERROR(VIR_ERR_INTERNAL_ERROR,
677
_("IP %s too big for destination"), data);
682
while (nextkey && (nextkey[0] == ',' ||
689
if (VIR_ALLOC(net) < 0)
693
if (virParseMacAddr(mac, net->mac) < 0) {
694
XENXS_ERROR(VIR_ERR_INTERNAL_ERROR,
695
_("malformed mac address '%s'"), mac);
700
if (bridge[0] || STREQ_NULLABLE(script, "vif-bridge") ||
701
STREQ_NULLABLE(script, "vif-vnic")) {
702
net->type = VIR_DOMAIN_NET_TYPE_BRIDGE;
704
net->type = VIR_DOMAIN_NET_TYPE_ETHERNET;
707
if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE) {
709
!(net->data.bridge.brname = strdup(bridge)))
712
!(net->data.bridge.script = strdup(script)))
715
!(net->data.bridge.ipaddr = strdup(ip)))
718
if (script && script[0] &&
719
!(net->data.ethernet.script = strdup(script)))
722
!(net->data.ethernet.ipaddr = strdup(ip)))
727
!(net->model = strdup(model)))
730
if (!model[0] && type[0] &&
731
STREQ(type, "netfront") &&
732
!(net->model = strdup("netfront")))
736
!(net->ifname = strdup(vifname)))
739
if (VIR_REALLOC_N(def->nets, def->nnets+1) < 0)
741
def->nets[def->nnets++] = net;
746
virDomainNetDefFree(net);
750
list = virConfGetValue(conf, "pci");
751
if (list && list->type == VIR_CONF_LIST) {
764
domain[0] = bus[0] = slot[0] = func[0] = '\0';
766
if ((list->type != VIR_CONF_STRING) || (list->str == NULL))
769
/* pci=['0000:00:1b.0','0000:00:13.0'] */
770
if (!(key = list->str))
772
if (!(nextkey = strchr(key, ':')))
775
if (virStrncpy(domain, key, (nextkey - key), sizeof(domain)) == NULL) {
776
XENXS_ERROR(VIR_ERR_INTERNAL_ERROR,
777
_("Domain %s too big for destination"), key);
782
if (!(nextkey = strchr(key, ':')))
785
if (virStrncpy(bus, key, (nextkey - key), sizeof(bus)) == NULL) {
786
XENXS_ERROR(VIR_ERR_INTERNAL_ERROR,
787
_("Bus %s too big for destination"), key);
792
if (!(nextkey = strchr(key, '.')))
795
if (virStrncpy(slot, key, (nextkey - key), sizeof(slot)) == NULL) {
796
XENXS_ERROR(VIR_ERR_INTERNAL_ERROR,
797
_("Slot %s too big for destination"), key);
802
if (strlen(key) != 1)
805
if (virStrncpy(func, key, 1, sizeof(func)) == NULL) {
806
XENXS_ERROR(VIR_ERR_INTERNAL_ERROR,
807
_("Function %s too big for destination"), key);
811
if (virStrToLong_i(domain, NULL, 16, &domainID) < 0)
813
if (virStrToLong_i(bus, NULL, 16, &busID) < 0)
815
if (virStrToLong_i(slot, NULL, 16, &slotID) < 0)
817
if (virStrToLong_i(func, NULL, 16, &funcID) < 0)
820
if (VIR_ALLOC(hostdev) < 0)
823
hostdev->managed = 0;
824
hostdev->source.subsys.type = VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI;
825
hostdev->source.subsys.u.pci.domain = domainID;
826
hostdev->source.subsys.u.pci.bus = busID;
827
hostdev->source.subsys.u.pci.slot = slotID;
828
hostdev->source.subsys.u.pci.function = funcID;
830
if (VIR_REALLOC_N(def->hostdevs, def->nhostdevs+1) < 0)
832
def->hostdevs[def->nhostdevs++] = hostdev;
841
if (xenXMConfigGetString(conf, "usbdevice", &str, NULL) < 0)
844
(STREQ(str, "tablet") ||
845
STREQ(str, "mouse"))) {
846
virDomainInputDefPtr input;
847
if (VIR_ALLOC(input) < 0)
849
input->bus = VIR_DOMAIN_INPUT_BUS_USB;
850
input->type = STREQ(str, "tablet") ?
851
VIR_DOMAIN_INPUT_TYPE_TABLET :
852
VIR_DOMAIN_INPUT_TYPE_MOUSE;
853
if (VIR_ALLOC_N(def->inputs, 1) < 0) {
854
virDomainInputDefFree(input);
857
def->inputs[0] = input;
862
/* HVM guests, or old PV guests use this config format */
863
if (hvm || xendConfigVersion < 3) {
864
if (xenXMConfigGetBool(conf, "vnc", &val, 0) < 0)
868
if (VIR_ALLOC(graphics) < 0)
870
graphics->type = VIR_DOMAIN_GRAPHICS_TYPE_VNC;
871
if (xenXMConfigGetBool(conf, "vncunused", &val, 1) < 0)
873
graphics->data.vnc.autoport = val ? 1 : 0;
875
if (!graphics->data.vnc.autoport) {
876
unsigned long vncdisplay;
877
if (xenXMConfigGetULong(conf, "vncdisplay", &vncdisplay, 0) < 0)
879
graphics->data.vnc.port = (int)vncdisplay + 5900;
882
if (xenXMConfigCopyStringOpt(conf, "vnclisten", &listenAddr) < 0)
885
virDomainGraphicsListenSetAddress(graphics, 0, listenAddr,
889
VIR_FREE(listenAddr);
891
if (xenXMConfigCopyStringOpt(conf, "vncpasswd", &graphics->data.vnc.auth.passwd) < 0)
893
if (xenXMConfigCopyStringOpt(conf, "keymap", &graphics->data.vnc.keymap) < 0)
896
if (VIR_ALLOC_N(def->graphics, 1) < 0)
898
def->graphics[0] = graphics;
902
if (xenXMConfigGetBool(conf, "sdl", &val, 0) < 0)
905
if (VIR_ALLOC(graphics) < 0)
907
graphics->type = VIR_DOMAIN_GRAPHICS_TYPE_SDL;
908
if (xenXMConfigCopyStringOpt(conf, "display", &graphics->data.sdl.display) < 0)
910
if (xenXMConfigCopyStringOpt(conf, "xauthority", &graphics->data.sdl.xauth) < 0)
912
if (VIR_ALLOC_N(def->graphics, 1) < 0)
914
def->graphics[0] = graphics;
921
if (!hvm && def->graphics == NULL) { /* New PV guests use this format */
922
list = virConfGetValue(conf, "vfb");
923
if (list && list->type == VIR_CONF_LIST &&
924
list->list && list->list->type == VIR_CONF_STRING &&
929
if (virStrcpyStatic(vfb, list->list->str) == NULL) {
930
XENXS_ERROR(VIR_ERR_INTERNAL_ERROR,
931
_("VFB %s too big for destination"),
936
if (VIR_ALLOC(graphics) < 0)
939
if (strstr(key, "type=sdl"))
940
graphics->type = VIR_DOMAIN_GRAPHICS_TYPE_SDL;
942
graphics->type = VIR_DOMAIN_GRAPHICS_TYPE_VNC;
945
char *nextkey = strchr(key, ',');
952
if (!strchr(key, '='))
955
if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC) {
956
if (STRPREFIX(key, "vncunused=")) {
957
if (STREQ(key + 10, "1"))
958
graphics->data.vnc.autoport = 1;
959
} else if (STRPREFIX(key, "vnclisten=")) {
960
if (virDomainGraphicsListenSetAddress(graphics, 0, key+10,
963
} else if (STRPREFIX(key, "vncpasswd=")) {
964
if (!(graphics->data.vnc.auth.passwd = strdup(key + 10)))
966
} else if (STRPREFIX(key, "keymap=")) {
967
if (!(graphics->data.vnc.keymap = strdup(key + 7)))
969
} else if (STRPREFIX(key, "vncdisplay=")) {
970
graphics->data.vnc.port = strtol(key+11, NULL, 10) + 5900;
973
if (STRPREFIX(key, "display=")) {
974
if (!(graphics->data.sdl.display = strdup(key + 8)))
976
} else if (STRPREFIX(key, "xauthority=")) {
977
if (!(graphics->data.sdl.xauth = strdup(key + 11)))
982
while (nextkey && (nextkey[0] == ',' ||
988
if (VIR_ALLOC_N(def->graphics, 1) < 0)
990
def->graphics[0] = graphics;
997
virDomainChrDefPtr chr = NULL;
999
if (xenXMConfigGetString(conf, "parallel", &str, NULL) < 0)
1001
if (str && STRNEQ(str, "none") &&
1002
!(chr = xenParseSxprChar(str, NULL)))
1006
if (VIR_ALLOC_N(def->parallels, 1) < 0) {
1007
virDomainChrDefFree(chr);
1010
chr->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL;
1011
chr->target.port = 0;
1012
def->parallels[0] = chr;
1017
/* Try to get the list of values to support multiple serial ports */
1018
list = virConfGetValue(conf, "serial");
1019
if (list && list->type == VIR_CONF_LIST) {
1026
if ((list->type != VIR_CONF_STRING) || (list->str == NULL))
1031
if (STREQ(port, "none")) {
1036
if (!(chr = xenParseSxprChar(port, NULL)))
1039
if (VIR_REALLOC_N(def->serials, def->nserials+1) < 0)
1042
chr->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL;
1043
chr->target.port = portnum;
1045
def->serials[def->nserials++] = chr;
1051
/* If domain is not using multiple serial ports we parse data old way */
1052
if (xenXMConfigGetString(conf, "serial", &str, NULL) < 0)
1054
if (str && STRNEQ(str, "none") &&
1055
!(chr = xenParseSxprChar(str, NULL)))
1058
if (VIR_ALLOC_N(def->serials, 1) < 0) {
1059
virDomainChrDefFree(chr);
1062
chr->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL;
1063
chr->target.port = 0;
1064
def->serials[0] = chr;
1070
if (VIR_ALLOC_N(def->consoles, 1) < 0)
1072
if (!(def->consoles[0] = xenParseSxprChar("pty", NULL)))
1074
def->consoles[0]->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE;
1075
def->consoles[0]->target.port = 0;
1076
def->consoles[0]->targetType = VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_XEN;
1080
if (xenXMConfigGetString(conf, "soundhw", &str, NULL) < 0)
1084
xenParseSxprSound(def, str) < 0)
1092
virReportOOMError();
1095
virDomainGraphicsDefFree(graphics);
1096
virDomainNetDefFree(net);
1097
virDomainDiskDefFree(disk);
1098
virDomainDefFree(def);
1100
VIR_FREE(listenAddr);
1106
int xenXMConfigSetInt(virConfPtr conf, const char *setting, long l) {
1107
virConfValuePtr value = NULL;
1109
if (VIR_ALLOC(value) < 0) {
1110
virReportOOMError();
1114
value->type = VIR_CONF_LONG;
1118
return virConfSetValue(conf, setting, value);
1123
int xenXMConfigSetString(virConfPtr conf, const char *setting, const char *str) {
1124
virConfValuePtr value = NULL;
1126
if (VIR_ALLOC(value) < 0) {
1127
virReportOOMError();
1131
value->type = VIR_CONF_STRING;
1133
if (!(value->str = strdup(str))) {
1135
virReportOOMError();
1139
return virConfSetValue(conf, setting, value);
1143
static int xenFormatXMDisk(virConfValuePtr list,
1144
virDomainDiskDefPtr disk,
1146
int xendConfigVersion)
1148
virBuffer buf = VIR_BUFFER_INITIALIZER;
1149
virConfValuePtr val, tmp;
1152
if (disk->driverName) {
1153
virBufferAsprintf(&buf, "%s:", disk->driverName);
1154
if (STREQ(disk->driverName, "tap"))
1155
virBufferAsprintf(&buf, "%s:", disk->driverType ? disk->driverType : "aio");
1157
switch (disk->type) {
1158
case VIR_DOMAIN_DISK_TYPE_FILE:
1159
virBufferAddLit(&buf, "file:");
1161
case VIR_DOMAIN_DISK_TYPE_BLOCK:
1162
virBufferAddLit(&buf, "phy:");
1165
XENXS_ERROR(VIR_ERR_INTERNAL_ERROR,
1166
_("unsupported disk type %s"),
1167
virDomainDiskTypeToString(disk->type));
1171
virBufferAdd(&buf, disk->src, -1);
1173
virBufferAddLit(&buf, ",");
1174
if (hvm && xendConfigVersion == 1)
1175
virBufferAddLit(&buf, "ioemu:");
1177
virBufferAdd(&buf, disk->dst, -1);
1178
if (disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM)
1179
virBufferAddLit(&buf, ":cdrom");
1182
virBufferAddLit(&buf, ",r");
1183
else if (disk->shared)
1184
virBufferAddLit(&buf, ",!");
1186
virBufferAddLit(&buf, ",w");
1187
if (disk->transient) {
1188
XENXS_ERROR(VIR_ERR_CONFIG_UNSUPPORTED,
1189
_("transient disks not supported yet"));
1193
if (virBufferError(&buf)) {
1194
virReportOOMError();
1198
if (VIR_ALLOC(val) < 0) {
1199
virReportOOMError();
1203
val->type = VIR_CONF_STRING;
1204
val->str = virBufferContentAndReset(&buf);
1206
while (tmp && tmp->next)
1216
virBufferFreeAndReset(&buf);
1220
static int xenFormatXMSerial(virConfValuePtr list,
1221
virDomainChrDefPtr serial)
1223
virBuffer buf = VIR_BUFFER_INITIALIZER;
1224
virConfValuePtr val, tmp;
1228
ret = xenFormatSxprChr(serial, &buf);
1230
virReportOOMError();
1234
virBufferAddLit(&buf, "none");
1236
if (virBufferError(&buf)) {
1237
virReportOOMError();
1241
if (VIR_ALLOC(val) < 0) {
1242
virReportOOMError();
1246
val->type = VIR_CONF_STRING;
1247
val->str = virBufferContentAndReset(&buf);
1249
while (tmp && tmp->next)
1259
virBufferFreeAndReset(&buf);
1263
static int xenFormatXMNet(virConnectPtr conn,
1264
virConfValuePtr list,
1265
virDomainNetDefPtr net,
1266
int hvm, int xendConfigVersion)
1268
virBuffer buf = VIR_BUFFER_INITIALIZER;
1269
virConfValuePtr val, tmp;
1271
virBufferAsprintf(&buf, "mac=%02x:%02x:%02x:%02x:%02x:%02x",
1272
net->mac[0], net->mac[1],
1273
net->mac[2], net->mac[3],
1274
net->mac[4], net->mac[5]);
1276
switch (net->type) {
1277
case VIR_DOMAIN_NET_TYPE_BRIDGE:
1278
virBufferAsprintf(&buf, ",bridge=%s", net->data.bridge.brname);
1279
if (net->data.bridge.ipaddr)
1280
virBufferAsprintf(&buf, ",ip=%s", net->data.bridge.ipaddr);
1281
virBufferAsprintf(&buf, ",script=%s", DEFAULT_VIF_SCRIPT);
1284
case VIR_DOMAIN_NET_TYPE_ETHERNET:
1285
if (net->data.ethernet.script)
1286
virBufferAsprintf(&buf, ",script=%s", net->data.ethernet.script);
1287
if (net->data.ethernet.ipaddr)
1288
virBufferAsprintf(&buf, ",ip=%s", net->data.ethernet.ipaddr);
1291
case VIR_DOMAIN_NET_TYPE_NETWORK:
1293
virNetworkPtr network = virNetworkLookupByName(conn, net->data.network.name);
1296
XENXS_ERROR(VIR_ERR_NO_NETWORK, "%s",
1297
net->data.network.name);
1300
bridge = virNetworkGetBridgeName(network);
1301
virNetworkFree(network);
1303
XENXS_ERROR(VIR_ERR_INTERNAL_ERROR,
1304
_("network %s is not active"),
1305
net->data.network.name);
1309
virBufferAsprintf(&buf, ",bridge=%s", bridge);
1310
virBufferAsprintf(&buf, ",script=%s", DEFAULT_VIF_SCRIPT);
1315
XENXS_ERROR(VIR_ERR_INTERNAL_ERROR,
1316
_("unsupported network type %d"),
1322
if (net->model != NULL)
1323
virBufferAsprintf(&buf, ",model=%s", net->model);
1325
else if (net->model == NULL) {
1327
* apparently type ioemu breaks paravirt drivers on HVM so skip this
1328
* from XEND_CONFIG_MAX_VERS_NET_TYPE_IOEMU
1330
if (xendConfigVersion <= XEND_CONFIG_MAX_VERS_NET_TYPE_IOEMU)
1331
virBufferAddLit(&buf, ",type=ioemu");
1333
else if (STREQ(net->model, "netfront")) {
1334
virBufferAddLit(&buf, ",type=netfront");
1337
virBufferAsprintf(&buf, ",model=%s", net->model);
1338
virBufferAddLit(&buf, ",type=ioemu");
1342
virBufferAsprintf(&buf, ",vifname=%s",
1345
if (virBufferError(&buf)) {
1346
virReportOOMError();
1350
if (VIR_ALLOC(val) < 0) {
1351
virReportOOMError();
1355
val->type = VIR_CONF_STRING;
1356
val->str = virBufferContentAndReset(&buf);
1358
while (tmp && tmp->next)
1368
virBufferFreeAndReset(&buf);
1375
xenFormatXMPCI(virConfPtr conf,
1376
virDomainDefPtr def)
1379
virConfValuePtr pciVal = NULL;
1383
for (i = 0 ; i < def->nhostdevs ; i++)
1384
if (def->hostdevs[i]->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
1385
def->hostdevs[i]->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI)
1391
if (VIR_ALLOC(pciVal) < 0) {
1392
virReportOOMError();
1396
pciVal->type = VIR_CONF_LIST;
1397
pciVal->list = NULL;
1399
for (i = 0 ; i < def->nhostdevs ; i++) {
1400
if (def->hostdevs[i]->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
1401
def->hostdevs[i]->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI) {
1402
virConfValuePtr val, tmp;
1405
if (virAsprintf(&buf, "%04x:%02x:%02x.%x",
1406
def->hostdevs[i]->source.subsys.u.pci.domain,
1407
def->hostdevs[i]->source.subsys.u.pci.bus,
1408
def->hostdevs[i]->source.subsys.u.pci.slot,
1409
def->hostdevs[i]->source.subsys.u.pci.function) < 0) {
1410
virReportOOMError();
1414
if (VIR_ALLOC(val) < 0) {
1416
virReportOOMError();
1419
val->type = VIR_CONF_STRING;
1422
while (tmp && tmp->next)
1431
if (pciVal->list != NULL) {
1432
int ret = virConfSetValue(conf, "pci", pciVal);
1442
virConfFreeValue(pciVal);
1447
/* Computing the vcpu_avail bitmask works because MAX_VIRT_CPUS is
1448
either 32, or 64 on a platform where long is big enough. */
1449
verify(MAX_VIRT_CPUS <= sizeof(1UL) * CHAR_BIT);
1451
virConfPtr xenFormatXM(virConnectPtr conn,
1452
virDomainDefPtr def,
1453
int xendConfigVersion) {
1454
virConfPtr conf = NULL;
1457
const char *lifecycle;
1458
char uuid[VIR_UUID_STRING_BUFLEN];
1459
virConfValuePtr diskVal = NULL;
1460
virConfValuePtr netVal = NULL;
1462
if (!(conf = virConfNew()))
1466
if (xenXMConfigSetString(conf, "name", def->name) < 0)
1469
virUUIDFormat(def->uuid, uuid);
1470
if (xenXMConfigSetString(conf, "uuid", uuid) < 0)
1473
if (xenXMConfigSetInt(conf, "maxmem", VIR_DIV_UP(def->mem.max_balloon, 1024)) < 0)
1476
if (xenXMConfigSetInt(conf, "memory", VIR_DIV_UP(def->mem.cur_balloon, 1024)) < 0)
1479
if (xenXMConfigSetInt(conf, "vcpus", def->maxvcpus) < 0)
1481
/* Computing the vcpu_avail bitmask works because MAX_VIRT_CPUS is
1482
either 32, or 64 on a platform where long is big enough. */
1483
if (def->vcpus < def->maxvcpus &&
1484
xenXMConfigSetInt(conf, "vcpu_avail", (1UL << def->vcpus) - 1) < 0)
1487
if ((def->cpumask != NULL) &&
1488
((cpus = virDomainCpuSetFormat(def->cpumask,
1489
def->cpumasklen)) == NULL))
1493
xenXMConfigSetString(conf, "cpus", cpus) < 0)
1497
hvm = STREQ(def->os.type, "hvm") ? 1 : 0;
1500
char boot[VIR_DOMAIN_BOOT_LAST+1];
1501
if (xenXMConfigSetString(conf, "builder", "hvm") < 0)
1504
if (def->os.loader &&
1505
xenXMConfigSetString(conf, "kernel", def->os.loader) < 0)
1508
for (i = 0 ; i < def->os.nBootDevs ; i++) {
1509
switch (def->os.bootDevs[i]) {
1510
case VIR_DOMAIN_BOOT_FLOPPY:
1513
case VIR_DOMAIN_BOOT_CDROM:
1516
case VIR_DOMAIN_BOOT_NET:
1519
case VIR_DOMAIN_BOOT_DISK:
1525
if (!def->os.nBootDevs) {
1529
boot[def->os.nBootDevs] = '\0';
1532
if (xenXMConfigSetString(conf, "boot", boot) < 0)
1535
if (xenXMConfigSetInt(conf, "pae",
1537
(1 << VIR_DOMAIN_FEATURE_PAE)) ? 1 : 0) < 0)
1540
if (xenXMConfigSetInt(conf, "acpi",
1542
(1 << VIR_DOMAIN_FEATURE_ACPI)) ? 1 : 0) < 0)
1545
if (xenXMConfigSetInt(conf, "apic",
1547
(1 << VIR_DOMAIN_FEATURE_APIC)) ? 1 : 0) < 0)
1550
if (xendConfigVersion >= 3) {
1551
if (xenXMConfigSetInt(conf, "hap",
1553
(1 << VIR_DOMAIN_FEATURE_HAP)) ? 1 : 0) < 0)
1556
if (xenXMConfigSetInt(conf, "viridian",
1558
(1 << VIR_DOMAIN_FEATURE_VIRIDIAN)) ? 1 : 0) < 0)
1562
if (def->clock.offset == VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME) {
1563
if (def->clock.data.timezone) {
1564
XENXS_ERROR(VIR_ERR_CONFIG_UNSUPPORTED,
1565
"%s", _("configurable timezones are not supported"));
1569
if (xenXMConfigSetInt(conf, "localtime", 1) < 0)
1571
} else if (def->clock.offset == VIR_DOMAIN_CLOCK_OFFSET_UTC) {
1572
if (xenXMConfigSetInt(conf, "localtime", 0) < 0)
1575
/* XXX We could support Xen's rtc clock offset */
1576
XENXS_ERROR(VIR_ERR_CONFIG_UNSUPPORTED,
1577
_("unsupported clock offset '%s'"),
1578
virDomainClockOffsetTypeToString(def->clock.offset));
1582
for (i = 0; i < def->clock.ntimers; i++) {
1583
if (def->clock.timers[i]->name == VIR_DOMAIN_TIMER_NAME_HPET &&
1584
def->clock.timers[i]->present != -1 &&
1585
xenXMConfigSetInt(conf, "hpet", def->clock.timers[i]->present) < 0)
1589
if (xendConfigVersion == 1) {
1590
for (i = 0 ; i < def->ndisks ; i++) {
1591
if (def->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_CDROM &&
1592
def->disks[i]->dst &&
1593
STREQ(def->disks[i]->dst, "hdc") &&
1594
def->disks[i]->src) {
1595
if (xenXMConfigSetString(conf, "cdrom",
1596
def->disks[i]->src) < 0)
1603
/* XXX floppy disks */
1605
if (def->os.bootloader &&
1606
xenXMConfigSetString(conf, "bootloader", def->os.bootloader) < 0)
1608
if (def->os.bootloaderArgs &&
1609
xenXMConfigSetString(conf, "bootargs", def->os.bootloaderArgs) < 0)
1611
if (def->os.kernel &&
1612
xenXMConfigSetString(conf, "kernel", def->os.kernel) < 0)
1614
if (def->os.initrd &&
1615
xenXMConfigSetString(conf, "ramdisk", def->os.initrd) < 0)
1617
if (def->os.cmdline &&
1618
xenXMConfigSetString(conf, "extra", def->os.cmdline) < 0)
1623
if (!(lifecycle = virDomainLifecycleTypeToString(def->onPoweroff))) {
1624
XENXS_ERROR(VIR_ERR_INTERNAL_ERROR,
1625
_("unexpected lifecycle action %d"), def->onPoweroff);
1628
if (xenXMConfigSetString(conf, "on_poweroff", lifecycle) < 0)
1632
if (!(lifecycle = virDomainLifecycleTypeToString(def->onReboot))) {
1633
XENXS_ERROR(VIR_ERR_INTERNAL_ERROR,
1634
_("unexpected lifecycle action %d"), def->onReboot);
1637
if (xenXMConfigSetString(conf, "on_reboot", lifecycle) < 0)
1641
if (!(lifecycle = virDomainLifecycleCrashTypeToString(def->onCrash))) {
1642
XENXS_ERROR(VIR_ERR_INTERNAL_ERROR,
1643
_("unexpected lifecycle action %d"), def->onCrash);
1646
if (xenXMConfigSetString(conf, "on_crash", lifecycle) < 0)
1652
if (def->emulator &&
1653
xenXMConfigSetString(conf, "device_model", def->emulator) < 0)
1656
for (i = 0 ; i < def->ninputs ; i++) {
1657
if (def->inputs[i]->bus == VIR_DOMAIN_INPUT_BUS_USB) {
1658
if (xenXMConfigSetInt(conf, "usb", 1) < 0)
1660
if (xenXMConfigSetString(conf, "usbdevice",
1661
def->inputs[i]->type == VIR_DOMAIN_INPUT_TYPE_MOUSE ?
1662
"mouse" : "tablet") < 0)
1669
if (def->ngraphics == 1) {
1670
if (xendConfigVersion < (hvm ? 4 : XEND_CONFIG_MIN_VERS_PVFB_NEWCONF)) {
1671
if (def->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_SDL) {
1672
if (xenXMConfigSetInt(conf, "sdl", 1) < 0)
1674
if (xenXMConfigSetInt(conf, "vnc", 0) < 0)
1676
if (def->graphics[0]->data.sdl.display &&
1677
xenXMConfigSetString(conf, "display",
1678
def->graphics[0]->data.sdl.display) < 0)
1680
if (def->graphics[0]->data.sdl.xauth &&
1681
xenXMConfigSetString(conf, "xauthority",
1682
def->graphics[0]->data.sdl.xauth) < 0)
1685
const char *listenAddr;
1687
if (xenXMConfigSetInt(conf, "sdl", 0) < 0)
1689
if (xenXMConfigSetInt(conf, "vnc", 1) < 0)
1691
if (xenXMConfigSetInt(conf, "vncunused",
1692
def->graphics[0]->data.vnc.autoport ? 1 : 0) < 0)
1694
if (!def->graphics[0]->data.vnc.autoport &&
1695
xenXMConfigSetInt(conf, "vncdisplay",
1696
def->graphics[0]->data.vnc.port - 5900) < 0)
1698
listenAddr = virDomainGraphicsListenGetAddress(def->graphics[0], 0);
1700
xenXMConfigSetString(conf, "vnclisten", listenAddr) < 0)
1702
if (def->graphics[0]->data.vnc.auth.passwd &&
1703
xenXMConfigSetString(conf, "vncpasswd",
1704
def->graphics[0]->data.vnc.auth.passwd) < 0)
1706
if (def->graphics[0]->data.vnc.keymap &&
1707
xenXMConfigSetString(conf, "keymap",
1708
def->graphics[0]->data.vnc.keymap) < 0)
1712
virConfValuePtr vfb, disp;
1713
char *vfbstr = NULL;
1714
virBuffer buf = VIR_BUFFER_INITIALIZER;
1715
if (def->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_SDL) {
1716
virBufferAddLit(&buf, "type=sdl");
1717
if (def->graphics[0]->data.sdl.display)
1718
virBufferAsprintf(&buf, ",display=%s",
1719
def->graphics[0]->data.sdl.display);
1720
if (def->graphics[0]->data.sdl.xauth)
1721
virBufferAsprintf(&buf, ",xauthority=%s",
1722
def->graphics[0]->data.sdl.xauth);
1724
const char *listenAddr
1725
= virDomainGraphicsListenGetAddress(def->graphics[0], 0);
1727
virBufferAddLit(&buf, "type=vnc");
1728
virBufferAsprintf(&buf, ",vncunused=%d",
1729
def->graphics[0]->data.vnc.autoport ? 1 : 0);
1730
if (!def->graphics[0]->data.vnc.autoport)
1731
virBufferAsprintf(&buf, ",vncdisplay=%d",
1732
def->graphics[0]->data.vnc.port - 5900);
1734
virBufferAsprintf(&buf, ",vnclisten=%s", listenAddr);
1735
if (def->graphics[0]->data.vnc.auth.passwd)
1736
virBufferAsprintf(&buf, ",vncpasswd=%s",
1737
def->graphics[0]->data.vnc.auth.passwd);
1738
if (def->graphics[0]->data.vnc.keymap)
1739
virBufferAsprintf(&buf, ",keymap=%s",
1740
def->graphics[0]->data.vnc.keymap);
1742
if (virBufferError(&buf)) {
1743
virBufferFreeAndReset(&buf);
1747
vfbstr = virBufferContentAndReset(&buf);
1749
if (VIR_ALLOC(vfb) < 0) {
1754
if (VIR_ALLOC(disp) < 0) {
1760
vfb->type = VIR_CONF_LIST;
1762
disp->type = VIR_CONF_STRING;
1765
if (virConfSetValue(conf, "vfb", vfb) < 0)
1770
/* analyze of the devices */
1771
if (VIR_ALLOC(diskVal) < 0)
1773
diskVal->type = VIR_CONF_LIST;
1774
diskVal->list = NULL;
1776
for (i = 0 ; i < def->ndisks ; i++) {
1777
if (xendConfigVersion == 1 &&
1778
def->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_CDROM &&
1779
def->disks[i]->dst &&
1780
STREQ(def->disks[i]->dst, "hdc")) {
1783
if (def->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY)
1786
if (xenFormatXMDisk(diskVal, def->disks[i],
1787
hvm, xendConfigVersion) < 0)
1790
if (diskVal->list != NULL) {
1791
int ret = virConfSetValue(conf, "disk", diskVal);
1798
if (VIR_ALLOC(netVal) < 0)
1800
netVal->type = VIR_CONF_LIST;
1801
netVal->list = NULL;
1803
for (i = 0 ; i < def->nnets ; i++) {
1804
if (xenFormatXMNet(conn, netVal,def->nets[i],
1805
hvm, xendConfigVersion) < 0)
1808
if (netVal->list != NULL) {
1809
int ret = virConfSetValue(conf, "vif", netVal);
1816
if (xenFormatXMPCI(conf, def) < 0)
1820
if (def->nparallels) {
1821
virBuffer buf = VIR_BUFFER_INITIALIZER;
1825
ret = xenFormatSxprChr(def->parallels[0], &buf);
1826
str = virBufferContentAndReset(&buf);
1828
ret = xenXMConfigSetString(conf, "parallel", str);
1833
if (xenXMConfigSetString(conf, "parallel", "none") < 0)
1837
if (def->nserials) {
1838
if ((def->nserials == 1) && (def->serials[0]->target.port == 0)) {
1839
virBuffer buf = VIR_BUFFER_INITIALIZER;
1843
ret = xenFormatSxprChr(def->serials[0], &buf);
1844
str = virBufferContentAndReset(&buf);
1846
ret = xenXMConfigSetString(conf, "serial", str);
1853
virConfValuePtr serialVal = NULL;
1855
if (VIR_ALLOC(serialVal) < 0)
1857
serialVal->type = VIR_CONF_LIST;
1858
serialVal->list = NULL;
1860
for (i = 0; i < def->nserials; i++)
1861
if (def->serials[i]->target.port > maxport)
1862
maxport = def->serials[i]->target.port;
1864
for (i = 0; i <= maxport; i++) {
1865
virDomainChrDefPtr chr = NULL;
1866
for (j = 0; j < def->nserials; j++) {
1867
if (def->serials[j]->target.port == i) {
1868
chr = def->serials[j];
1872
if (xenFormatXMSerial(serialVal, chr) < 0)
1876
if (serialVal->list != NULL) {
1877
int ret = virConfSetValue(conf, "serial", serialVal);
1882
VIR_FREE(serialVal);
1885
if (xenXMConfigSetString(conf, "serial", "none") < 0)
1891
virBuffer buf = VIR_BUFFER_INITIALIZER;
1893
int ret = xenFormatSxprSound(def, &buf);
1894
str = virBufferContentAndReset(&buf);
1896
ret = xenXMConfigSetString(conf, "soundhw", str);
1907
virReportOOMError();
1910
virConfFreeValue(diskVal);
1911
virConfFreeValue(netVal);