~ubuntu-branches/ubuntu/natty/libvirt/natty-security

« back to all changes in this revision

Viewing changes to src/xen/xend_internal.c

  • Committer: Bazaar Package Importer
  • Author(s): Serge Hallyn
  • Date: 2011-02-23 09:05:46 UTC
  • mfrom: (1.2.8 upstream) (3.4.25 sid)
  • Revision ID: james.westby@ubuntu.com-20110223090546-4pwmrrt7h51hr3l3
Tags: 0.8.8-1ubuntu1
* Resynchronize and merge from Debian unstable. Remaining changes:
  - debian/patches:
    * 9000-delayed_iff_up_bridge.patch
    * 9001-dont_clobber_existing_bridges.patch
    * 9002-better_default_uri_virsh.patch
    * 9003-better-default-arch.patch
    * 9004-libvirtd-group-name.patch
    * 9005-increase-unix-socket-timeout.patch
    * 9006-default-config-test-case.patch
    * 9007-fix-daemon-conf-ftbfs.patch
    * 9011-move-ebtables-script.patch
    * 9014-skip-nodeinfotest.patch
    * 9020-lp545795.patch
    * 9021-fix-uint64_t.patch
  - debian/patches/series:
    * Disable qemu-disable-network.diff.patch
  - debian/control:
    * set ubuntu maintainer
    * Build-Depends:
      - swap libxen to libxen3, qemu to qemu-kvm, and open-iscsi to
        open-iscsi-utils in Build-Depends
      - remove virtualbox Build-Depends
      - add libxml2 and libapparmor-dev Build-Depends
    * convert Vcs-Git to Xs-Debian-Vcs-Git
    * libvirt-bin Depends: move netcat-openbsd, bridge-utils, dnsmasq-base
      (>= 2.46-1), and iptables from Recommends to Depends
    * libvirt-bin Recommends: move qemu to Suggests
    * libvirt-bin Suggests: add apparmor
    * libvirt0 Recommands: move lvm2 to Suggests
  - keep debian/libvirt-bin.apport
  - keep debian/libvirt-bin.cron.daily
  - debian/libvirt-bin.dirs:
    * add apparmor, cron.daily, and apport dirs
  - debian/libvirt-bin.examples:
    * add debian/libvirt-suspendonreboot
  - debian/libvirt-bin.install:
    * add /etc/apparmor.d files
    * add apport hook
  - debian/libvirt-bin.manpages:
    * add debian/libvirt-migrate-qemu-disks.1
  - debian/libvirt-bin.postinst:
    * replace libvirt groupname with libvirtd
    * add each admin user to libvirtd group
    * call apparmor_parser on usr.sbin.libvirtd and
      usr.lib.libvirt.virt-aa-helper
    * call 'libvirt-migrate-qemu-disks -a' after
      libvirt-bin has started if migrating from
      older than 0.8.3-1ubuntu1
  - debian/libvirt-bin.postrm:
    * replace libvirt groupname with libvirtd
    * remove usr.sbin.libvirtd and
      usr.lib.libvirt.virt-aa-helper
  - keep added files under debian/:
    * libvirt-bin.upstart
    * libvirt-migrate-qemu-disks
    * libvirt-migrate-qemu-disks.1
    * libvirt-suspendonreboot
    * apparmor profiles
  - debian/README.Debian:
    * add 'Apparmor Profile' section
    * add 'Disk migration' section
  - debian/rules:
    * don't build with vbox since virtualbox-ose is in universe
    * add --with-apparmor to DEB_CONFIGURE_EXTRA_FLAGS
    * set DEB_DH_INSTALLINIT_ARGS to '--upstart-only'
    * set DEB_MAKE_CHECK_TARGET to 'check'
    * remove unneeded binary-install/libvirt-bin:: and clean::
      sections (they only deal with sysvinit stuff)
    * add build/libvirt-bin:: section to install
      - apparmor files
      - apport hooks
      - libvirt-migrate-qemu-disks
* The following Ubuntu packaging changes occurred during the divergence
  between Debian and Ubuntu. These changes are not new, but included here
  for completeness: (0.8.5-0ubuntu1 - 0.8.5-0ubuntu5):
  - Have upstart job source /etc/default/libvirt-bin.  This is only a
    temporary fix until upstart provides proper default override support
    through /etc/init/libvirt-bin.override (or any other mechanism).
    (LP: 708172)
  - debian/apparmor/usr.sbin.libvirtd: use PUx instead of Ux for executables
    (LP: 573315)
  - Rebuild with python 2.7 as the python default.
  - debian/libvirt-bin.cron.daily: use shell globbing to enumerate xml files.
    Based on patch thanks to Henryk Plötz (LP: 655176)
* Dropped the following patches included/fixed upstream:
  - 9010-dont-disable-ipv6.patch
  - 9022-build-cleanup-declaration-of-xen-tests.patch
  - 9023-vah-require-uuid.patch
  - 9009-autodetect-nc-params.patch
    * rolled into Debian's
      Autodetect-if-the-remote-nc-command-supports-the-q-o.patch
* Updated the following patches:
  - 9011-move-ebtables-script.patch:
    * LOCALSTATEDIR is defined in configmake.h
  - 9000-9006: added DEP-3 tags
  - 9002-better_default_uri_virsh.patch: updated (context changed)
* New patches:
  - 9022-drop-booton-when-kernel-specified.patch (LP: #720426)
  - 9023-fix-lxc-console-hangup.patch (LP: #668369)
  - 9024-skip-broken-commandtest.patch
* debian/patches/series:
  - don't apply Disable-CHECKSUM-rule.patch: our iptables can do this
  - don't apply Debian-specific Debianize-libvirt-guests.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * xend_internal.c: access to Xen though the Xen Daemon interface
3
3
 *
4
 
 * Copyright (C) 2010 Red Hat, Inc.
 
4
 * Copyright (C) 2010-2011 Red Hat, Inc.
5
5
 * Copyright (C) 2005 Anthony Liguori <aliguori@us.ibm.com>
6
6
 *
7
7
 *  This file is subject to the terms and conditions of the GNU Lesser General
45
45
#include "xs_internal.h" /* To extract VNC port & Serial console TTY */
46
46
#include "memory.h"
47
47
#include "count-one-bits.h"
 
48
#include "files.h"
48
49
 
49
50
/* required for cpumap_t */
50
51
#include <xen/dom0_ops.h>
51
52
 
52
53
#define VIR_FROM_THIS VIR_FROM_XEND
53
54
 
54
 
#ifndef PROXY
55
 
 
56
55
/*
57
56
 * The number of Xen scheduler parameters
58
57
 */
59
 
# define XEN_SCHED_SEDF_NPARAM   6
60
 
# define XEN_SCHED_CRED_NPARAM   2
61
 
 
62
 
#endif /* PROXY */
 
58
#define XEN_SCHED_SEDF_NPARAM   6
 
59
#define XEN_SCHED_CRED_NPARAM   2
63
60
 
64
61
#ifdef WITH_RHEL5_API
65
62
# define XEND_CONFIG_MAX_VERS_NET_TYPE_IOEMU 0
71
68
 
72
69
#define XEND_RCV_BUF_MAX_LEN 65536
73
70
 
74
 
#ifndef PROXY
75
71
static int
76
72
xenDaemonFormatSxprDisk(virConnectPtr conn ATTRIBUTE_UNUSED,
77
73
                        virDomainDiskDefPtr def,
97
93
                  char *class,
98
94
                  char *ref,
99
95
                  int ref_len);
100
 
#endif
101
96
 
102
97
#define virXendError(code, ...)                                            \
103
98
        virReportErrorHelper(NULL, VIR_FROM_XEND, code, __FILE__,          \
118
113
do_connect(virConnectPtr xend)
119
114
{
120
115
    int s;
121
 
    int serrno;
122
116
    int no_slow_start = 1;
123
117
    xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) xend->privateData;
124
118
 
137
131
 
138
132
 
139
133
    if (connect(s, (struct sockaddr *)&priv->addr, priv->addrlen) == -1) {
140
 
        serrno = errno;
141
 
        close(s);
142
 
        errno = serrno;
143
 
        s = -1;
 
134
        VIR_FORCE_CLOSE(s); /* preserves errno */
144
135
 
145
136
        /*
146
137
         * Connecting to XenD when privileged is mandatory, so log this
387
378
            "Content-Type: application/x-www-form-urlencoded\r\n" "\r\n");
388
379
 
389
380
    ret = xend_req(s, content);
390
 
    close(s);
 
381
    VIR_FORCE_CLOSE(s);
391
382
 
392
383
    if (((ret < 0) || (ret >= 300)) &&
393
384
        ((ret != 404) || (!STRPREFIX(path, "/xend/domain/")))) {
399
390
    return ret;
400
391
}
401
392
 
402
 
#ifndef PROXY
403
393
/**
404
394
 * xend_post:
405
395
 * @xend: pointer to the Xen Daemon structure
437
427
    swrites(s, ops);
438
428
 
439
429
    ret = xend_req(s, &err_buf);
440
 
    close(s);
 
430
    VIR_FORCE_CLOSE(s);
441
431
 
442
432
    if ((ret < 0) || (ret >= 300)) {
443
433
        virXendError(VIR_ERR_POST_FAILED,
460
450
    VIR_FREE(err_buf);
461
451
    return ret;
462
452
}
463
 
#endif /* ! PROXY */
464
453
 
465
454
 
466
455
/**
495
484
    return -1;
496
485
}
497
486
 
498
 
#ifndef PROXY
499
487
/**
500
488
 * xend_op_ext:
501
489
 * @xend: pointer to the Xen Daemon structure
534
522
    }
535
523
 
536
524
    content = virBufferContentAndReset(&buf);
 
525
    DEBUG("xend op: %s\n", content);
537
526
    ret = http2unix(xend_post(xend, path, content));
538
527
    VIR_FREE(content);
539
528
 
570
559
    return ret;
571
560
}
572
561
 
573
 
#endif /* ! PROXY */
574
562
 
575
563
/**
576
564
 * sexpr_get:
698
686
}
699
687
 
700
688
 
701
 
#ifndef PROXY
702
689
/**
703
690
 * urlencode:
704
691
 * @string: the input URL
724
711
        switch (string[i]) {
725
712
            case ' ':
726
713
            case '\n':
 
714
            case '&':
727
715
                snprintf(ptr, 4, "%%%02x", string[i]);
728
716
                ptr += 3;
729
717
                break;
737
725
 
738
726
    return buffer;
739
727
}
740
 
#endif /* ! PROXY */
741
728
 
742
729
/* PUBLIC FUNCTIONS */
743
730
 
779
766
    return (0);
780
767
}
781
768
 
782
 
#ifndef PROXY
 
769
 
783
770
/**
784
771
 * xenDaemonOpen_tcp:
785
772
 * @conn: an existing virtual connection block
808
795
    priv->addrlen = 0;
809
796
    memset(&priv->addr, 0, sizeof(priv->addr));
810
797
 
811
 
    // http://people.redhat.com/drepper/userapi-ipv6.html
 
798
    /* http://people.redhat.com/drepper/userapi-ipv6.html */
812
799
    memset (&hints, 0, sizeof hints);
813
800
    hints.ai_socktype = SOCK_STREAM;
814
801
    hints.ai_flags = AI_ADDRCONFIG;
833
820
 
834
821
        if (connect (sock, r->ai_addr, r->ai_addrlen) == -1) {
835
822
            saved_errno = errno;
836
 
            close (sock);
 
823
            VIR_FORCE_CLOSE(sock);
837
824
            continue;
838
825
        }
839
826
 
843
830
        memcpy(&priv->addr,
844
831
               r->ai_addr,
845
832
               r->ai_addrlen);
846
 
        close(sock);
 
833
        VIR_FORCE_CLOSE(sock);
847
834
        break;
848
835
    }
849
836
 
879
866
}
880
867
 
881
868
 
882
 
#endif /* PROXY */
883
 
 
884
 
 
885
869
/**
886
870
 * xenDaemonListDomainsOld:
887
871
 * @xend: pointer to the Xen Daemon block
946
930
    return ret;
947
931
}
948
932
 
949
 
#ifndef PROXY
 
933
 
950
934
/**
951
935
 * xenDaemonDomainCreateXML:
952
936
 * @xend: A xend instance
983
967
 
984
968
    return ret;
985
969
}
986
 
#endif /* ! PROXY */
 
970
 
987
971
 
988
972
/**
989
973
 * xenDaemonDomainLookupByName_ids:
1090
1074
}
1091
1075
 
1092
1076
 
1093
 
#ifndef PROXY
1094
1077
static int
1095
1078
xend_detect_config_version(virConnectPtr conn) {
1096
1079
    struct sexpr *root;
1121
1104
    return (0);
1122
1105
}
1123
1106
 
1124
 
#endif /* PROXY */
1125
1107
 
1126
1108
/*****************************************************************
1127
1109
 ******
1235
1217
    prefix = value;
1236
1218
 
1237
1219
    if (value[0] == '/') {
1238
 
        def->type = VIR_DOMAIN_CHR_TYPE_DEV;
 
1220
        def->source.type = VIR_DOMAIN_CHR_TYPE_DEV;
1239
1221
    } else {
1240
1222
        if ((tmp = strchr(value, ':')) != NULL) {
1241
1223
            *tmp = '\0';
1243
1225
        }
1244
1226
 
1245
1227
        if (STRPREFIX(prefix, "telnet")) {
1246
 
            def->type = VIR_DOMAIN_CHR_TYPE_TCP;
1247
 
            def->data.tcp.protocol = VIR_DOMAIN_CHR_TCP_PROTOCOL_TELNET;
 
1228
            def->source.type = VIR_DOMAIN_CHR_TYPE_TCP;
 
1229
            def->source.data.tcp.protocol = VIR_DOMAIN_CHR_TCP_PROTOCOL_TELNET;
1248
1230
        } else {
1249
 
            if ((def->type = virDomainChrTypeFromString(prefix)) < 0) {
 
1231
            if ((def->source.type = virDomainChrTypeFromString(prefix)) < 0) {
1250
1232
                virXendError(VIR_ERR_INTERNAL_ERROR,
1251
1233
                             _("unknown chr device type '%s'"), prefix);
1252
1234
                goto error;
1255
1237
    }
1256
1238
 
1257
1239
    /* Compat with legacy  <console tty='/dev/pts/5'/> syntax */
1258
 
    switch (def->type) {
 
1240
    switch (def->source.type) {
1259
1241
    case VIR_DOMAIN_CHR_TYPE_PTY:
1260
1242
        if (tty != NULL &&
1261
 
            !(def->data.file.path = strdup(tty)))
 
1243
            !(def->source.data.file.path = strdup(tty)))
1262
1244
            goto no_memory;
1263
1245
        break;
1264
1246
 
1265
1247
    case VIR_DOMAIN_CHR_TYPE_FILE:
1266
1248
    case VIR_DOMAIN_CHR_TYPE_PIPE:
1267
 
        if (!(def->data.file.path = strdup(value)))
 
1249
        if (!(def->source.data.file.path = strdup(value)))
1268
1250
            goto no_memory;
1269
1251
        break;
1270
1252
 
1280
1262
        }
1281
1263
 
1282
1264
        if (offset != value &&
1283
 
            (def->data.tcp.host = strndup(value, offset - value)) == NULL)
 
1265
            (def->source.data.tcp.host = strndup(value,
 
1266
                                                 offset - value)) == NULL)
1284
1267
            goto no_memory;
1285
1268
 
1286
1269
        offset2 = strchr(offset, ',');
1287
1270
        if (offset2 == NULL)
1288
 
            def->data.tcp.service = strdup(offset+1);
 
1271
            def->source.data.tcp.service = strdup(offset+1);
1289
1272
        else
1290
 
            def->data.tcp.service = strndup(offset+1, offset2-(offset+1));
1291
 
        if (def->data.tcp.service == NULL)
 
1273
            def->source.data.tcp.service = strndup(offset+1,
 
1274
                                                   offset2-(offset+1));
 
1275
        if (def->source.data.tcp.service == NULL)
1292
1276
            goto no_memory;
1293
1277
 
1294
1278
        if (offset2 && strstr(offset2, ",server"))
1295
 
            def->data.tcp.listen = 1;
 
1279
            def->source.data.tcp.listen = true;
1296
1280
    }
1297
1281
    break;
1298
1282
 
1308
1292
        }
1309
1293
 
1310
1294
        if (offset != value &&
1311
 
            (def->data.udp.connectHost = strndup(value, offset - value)) == NULL)
 
1295
            (def->source.data.udp.connectHost
 
1296
             = strndup(value, offset - value)) == NULL)
1312
1297
            goto no_memory;
1313
1298
 
1314
1299
        offset2 = strchr(offset, '@');
1315
1300
        if (offset2 != NULL) {
1316
 
            if ((def->data.udp.connectService = strndup(offset + 1, offset2-(offset+1))) == NULL)
 
1301
            if ((def->source.data.udp.connectService
 
1302
                 = strndup(offset + 1, offset2-(offset+1))) == NULL)
1317
1303
                goto no_memory;
1318
1304
 
1319
1305
            offset3 = strchr(offset2, ':');
1324
1310
            }
1325
1311
 
1326
1312
            if (offset3 > (offset2 + 1) &&
1327
 
                (def->data.udp.bindHost = strndup(offset2 + 1, offset3 - (offset2+1))) == NULL)
 
1313
                (def->source.data.udp.bindHost
 
1314
                 = strndup(offset2 + 1, offset3 - (offset2+1))) == NULL)
1328
1315
                goto no_memory;
1329
1316
 
1330
 
            if ((def->data.udp.bindService = strdup(offset3 + 1)) == NULL)
 
1317
            if ((def->source.data.udp.bindService
 
1318
                 = strdup(offset3 + 1)) == NULL)
1331
1319
                goto no_memory;
1332
1320
        } else {
1333
 
            if ((def->data.udp.connectService = strdup(offset + 1)) == NULL)
 
1321
            if ((def->source.data.udp.connectService
 
1322
                 = strdup(offset + 1)) == NULL)
1334
1323
                goto no_memory;
1335
1324
        }
1336
1325
    }
1340
1329
    {
1341
1330
        const char *offset = strchr(value, ',');
1342
1331
        if (offset)
1343
 
            def->data.nix.path = strndup(value, (offset - value));
 
1332
            def->source.data.nix.path = strndup(value, (offset - value));
1344
1333
        else
1345
 
            def->data.nix.path = strdup(value);
1346
 
        if (def->data.nix.path == NULL)
 
1334
            def->source.data.nix.path = strdup(value);
 
1335
        if (def->source.data.nix.path == NULL)
1347
1336
            goto no_memory;
1348
1337
 
1349
1338
        if (offset != NULL &&
1350
1339
            strstr(offset, ",server") != NULL)
1351
 
            def->data.nix.listen = 1;
 
1340
            def->source.data.nix.listen = true;
1352
1341
    }
1353
1342
    break;
1354
1343
    }
1767
1756
                              int hvm,
1768
1757
                              int xendConfigVersion)
1769
1758
{
1770
 
#ifndef PROXY
1771
1759
    xenUnifiedPrivatePtr priv = conn->privateData;
1772
 
#endif
1773
1760
    const char *tmp;
1774
1761
    virDomainGraphicsDefPtr graphics = NULL;
1775
1762
 
1808
1795
            goto no_memory;
1809
1796
 
1810
1797
        if (vncPasswd &&
1811
 
            !(graphics->data.vnc.passwd = strdup(vncPasswd)))
 
1798
            !(graphics->data.vnc.auth.passwd = strdup(vncPasswd)))
1812
1799
            goto no_memory;
1813
1800
 
1814
1801
        if (keymap &&
1858
1845
                              virDomainDefPtr def,
1859
1846
                              const struct sexpr *root)
1860
1847
{
1861
 
#ifndef PROXY
1862
1848
    xenUnifiedPrivatePtr priv = conn->privateData;
1863
 
#endif
1864
1849
    virDomainGraphicsDefPtr graphics = NULL;
1865
1850
    const struct sexpr *cur, *node;
1866
1851
    const char *tmp;
1910
1895
                port = xenStoreDomainGetVNCPort(conn, def->id);
1911
1896
                xenUnifiedUnlock(priv);
1912
1897
 
1913
 
                // Didn't find port entry in xenstore
 
1898
                /* Didn't find port entry in xenstore */
1914
1899
                if (port == -1) {
1915
1900
                    const char *str = sexpr_node(node, "device/vfb/vncdisplay");
1916
1901
                    int val;
1930
1915
                    goto no_memory;
1931
1916
 
1932
1917
                if (vncPasswd &&
1933
 
                    !(graphics->data.vnc.passwd = strdup(vncPasswd)))
 
1918
                    !(graphics->data.vnc.auth.passwd = strdup(vncPasswd)))
1934
1919
                    goto no_memory;
1935
1920
 
1936
1921
                if (keymap &&
2099
2084
                   int xendConfigVersion,
2100
2085
                   const char *cpus)
2101
2086
{
2102
 
#ifndef PROXY
2103
2087
    xenUnifiedPrivatePtr priv = conn->privateData;
2104
 
#endif
2105
2088
    const char *tmp;
2106
2089
    virDomainDefPtr def;
2107
2090
    int hvm = 0;
2192
2175
    }
2193
2176
 
2194
2177
    def->maxvcpus = sexpr_int(root, "domain/vcpus");
2195
 
    def->vcpus = count_one_bits(sexpr_int(root, "domain/vcpu_avail"));
 
2178
    def->vcpus = count_one_bits_l(sexpr_u64(root, "domain/vcpu_avail"));
2196
2179
    if (!def->vcpus || def->maxvcpus < def->vcpus)
2197
2180
        def->vcpus = def->maxvcpus;
2198
2181
 
2234
2217
            def->features |= (1 << VIR_DOMAIN_FEATURE_APIC);
2235
2218
        if (sexpr_int(root, "domain/image/hvm/pae"))
2236
2219
            def->features |= (1 << VIR_DOMAIN_FEATURE_PAE);
 
2220
        if (sexpr_int(root, "domain/image/hvm/hap"))
 
2221
            def->features |= (1 << VIR_DOMAIN_FEATURE_HAP);
2237
2222
 
2238
2223
        /* Old XenD only allows localtime here for HVM */
2239
2224
        if (sexpr_int(root, "domain/image/hvm/localtime"))
2468
2453
    }
2469
2454
    info->cpuTime = sexpr_float(root, "domain/cpu_time") * 1000000000;
2470
2455
    vcpus = sexpr_int(root, "domain/vcpus");
2471
 
    info->nrVirtCpu = count_one_bits(sexpr_int(root, "domain/vcpu_avail"));
 
2456
    info->nrVirtCpu = count_one_bits_l(sexpr_u64(root, "domain/vcpu_avail"));
2472
2457
    if (!info->nrVirtCpu || vcpus < info->nrVirtCpu)
2473
2458
        info->nrVirtCpu = vcpus;
2474
2459
 
2521
2506
        if (procs == 0) /* Sanity check in case of Xen bugs in futures..*/
2522
2507
            return (-1);
2523
2508
        info->sockets = nr_cpus / procs;
2524
 
        /* Should already be fine, but for further sanity make
2525
 
         * sure we have at least one socket
2526
 
         */
2527
 
        if (info->sockets == 0)
2528
 
            info->sockets = 1;
2529
 
    }
 
2509
    }
 
2510
 
 
2511
    /* On systems where NUMA nodes are not composed of whole sockets either Xen
 
2512
     * provided us wrong number of sockets per node or we computed the wrong
 
2513
     * number in the compatibility code above. In such case, we compute the
 
2514
     * correct number of sockets on the host, lie about the number of NUMA
 
2515
     * nodes, and force apps to check capabilities XML for the actual NUMA
 
2516
     * topology.
 
2517
     */
 
2518
    if (info->nodes * info->sockets * info->cores * info->threads
 
2519
        != info->cpus) {
 
2520
        info->nodes = 1;
 
2521
        info->sockets = info->cpus / (info->cores * info->threads);
 
2522
    }
 
2523
 
2530
2524
    return (0);
2531
2525
}
2532
2526
 
2624
2618
}
2625
2619
 
2626
2620
 
2627
 
#ifndef PROXY
2628
2621
/**
2629
2622
 * sexpr_to_domain:
2630
2623
 * @conn: an existing virtual connection block
2678
2671
        virUnrefDomain(ret);
2679
2672
    return(NULL);
2680
2673
}
2681
 
#endif /* !PROXY */
 
2674
 
2682
2675
 
2683
2676
/*****************************************************************
2684
2677
 ******
2691
2684
 ******
2692
2685
 ******
2693
2686
 *****************************************************************/
2694
 
#ifndef PROXY
2695
2687
/**
2696
2688
 * xenDaemonOpen:
2697
2689
 * @conn: an existing virtual connection block
3053
3045
    }
3054
3046
    return xend_op(conn, "", "op", "restore", "file", filename, NULL);
3055
3047
}
3056
 
#endif /* !PROXY */
 
3048
 
3057
3049
 
3058
3050
/**
3059
3051
 * xenDaemonDomainGetMaxMemory:
3091
3083
    return(ret);
3092
3084
}
3093
3085
 
3094
 
#ifndef PROXY
 
3086
 
3095
3087
/**
3096
3088
 * xenDaemonDomainSetMaxMemory:
3097
3089
 * @domain: pointer to the Domain block
3119
3111
    if (domain->id < 0 && priv->xendConfigVersion < 3)
3120
3112
        return(-1);
3121
3113
 
3122
 
    snprintf(buf, sizeof(buf), "%lu", memory >> 10);
 
3114
    snprintf(buf, sizeof(buf), "%lu", VIR_DIV_UP(memory, 1024));
3123
3115
    return xend_op(domain->conn, domain->name, "op", "maxmem_set", "memory",
3124
3116
                   buf, NULL);
3125
3117
}
3156
3148
    if (domain->id < 0 && priv->xendConfigVersion < 3)
3157
3149
        return(-1);
3158
3150
 
3159
 
    snprintf(buf, sizeof(buf), "%lu", memory >> 10);
 
3151
    snprintf(buf, sizeof(buf), "%lu", VIR_DIV_UP(memory, 1024));
3160
3152
    return xend_op(domain->conn, domain->name, "op", "mem_target_set",
3161
3153
                   "target", buf, NULL);
3162
3154
}
3163
3155
 
3164
 
#endif /* ! PROXY */
3165
3156
 
3166
3157
virDomainDefPtr
3167
3158
xenDaemonDomainFetch(virConnectPtr conn,
3199
3190
}
3200
3191
 
3201
3192
 
3202
 
#ifndef PROXY
3203
3193
/**
3204
3194
 * xenDaemonDomainDumpXML:
3205
3195
 * @domain: a domain object
3225
3215
    priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
3226
3216
 
3227
3217
    if (domain->id < 0 && priv->xendConfigVersion < 3) {
3228
 
        // fall-through to the next driver to handle
 
3218
        /* fall-through to the next driver to handle */
3229
3219
        return(NULL);
3230
3220
    }
3231
3221
 
3241
3231
 
3242
3232
    return xml;
3243
3233
}
3244
 
#endif /* !PROXY */
 
3234
 
3245
3235
 
3246
3236
/**
3247
3237
 * xenDaemonDomainGetInfo:
3280
3270
    return (ret);
3281
3271
}
3282
3272
 
3283
 
#ifndef PROXY
 
3273
 
3284
3274
/**
3285
3275
 * xenDaemonLookupByName:
3286
3276
 * @conn: A xend instance
3313
3303
    sexpr_free(root);
3314
3304
    return(ret);
3315
3305
}
3316
 
#endif /* ! PROXY */
 
3306
 
3317
3307
 
3318
3308
/**
3319
3309
 * xenDaemonNodeGetInfo:
3420
3410
    return(0);
3421
3411
}
3422
3412
 
3423
 
#ifndef PROXY
 
3413
 
3424
3414
/**
3425
3415
 * xenDaemonListDomains:
3426
3416
 * @conn: pointer to the hypervisor connection
3500
3490
    sexpr_free(root);
3501
3491
    return(ret);
3502
3492
}
3503
 
#endif /* ! PROXY */
3504
 
 
3505
 
#ifndef PROXY
 
3493
 
 
3494
 
3506
3495
/**
3507
3496
 * xenDaemonLookupByID:
3508
3497
 * @conn: pointer to the hypervisor connection
3706
3695
 
3707
3696
    ret = sexpr_int(root, "domain/vcpus");
3708
3697
    if (!(flags & VIR_DOMAIN_VCPU_MAXIMUM)) {
3709
 
        int vcpus = count_one_bits(sexpr_int(root, "domain/vcpu_avail"));
 
3698
        int vcpus = count_one_bits_l(sexpr_u64(root, "domain/vcpu_avail"));
3710
3699
        if (vcpus)
3711
3700
            ret = MIN(vcpus, ret);
3712
3701
    }
3976
3965
    virDomainDefPtr def = NULL;
3977
3966
    virBuffer buf = VIR_BUFFER_INITIALIZER;
3978
3967
    char class[8], ref[80];
 
3968
    char *target = NULL;
3979
3969
 
3980
3970
    if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) {
3981
3971
        virXendError(VIR_ERR_INVALID_ARG, __FUNCTION__);
4040
4030
                                    STREQ(def->os.type, "hvm") ? 1 : 0,
4041
4031
                                    priv->xendConfigVersion, 1) < 0)
4042
4032
            goto cleanup;
 
4033
 
 
4034
        if (dev->data.disk->device != VIR_DOMAIN_DISK_DEVICE_CDROM) {
 
4035
            if (!(target = strdup(dev->data.disk->dst))) {
 
4036
                virReportOOMError();
 
4037
                goto cleanup;
 
4038
            }
 
4039
        }
4043
4040
        break;
4044
4041
 
4045
4042
    case VIR_DOMAIN_DEVICE_NET:
4049
4046
                                   STREQ(def->os.type, "hvm") ? 1 : 0,
4050
4047
                                   priv->xendConfigVersion, 1) < 0)
4051
4048
            goto cleanup;
 
4049
 
 
4050
        char macStr[VIR_MAC_STRING_BUFLEN];
 
4051
        virFormatMacAddr(dev->data.net->mac, macStr);
 
4052
 
 
4053
        if (!(target = strdup(macStr))) {
 
4054
            virReportOOMError();
 
4055
            goto cleanup;
 
4056
        }
4052
4057
        break;
4053
4058
 
4054
4059
    case VIR_DOMAIN_DEVICE_HOSTDEV:
4057
4062
            if (xenDaemonFormatSxprOnePCI(dev->data.hostdev,
4058
4063
                                          &buf, 0) < 0)
4059
4064
                goto cleanup;
 
4065
 
 
4066
            virDomainDevicePCIAddress PCIAddr;
 
4067
 
 
4068
            PCIAddr = dev->data.hostdev->source.subsys.u.pci;
 
4069
            virAsprintf(&target, "PCI device: %.4x:%.2x:%.2x", PCIAddr.domain,
 
4070
                                 PCIAddr.bus, PCIAddr.slot);
 
4071
 
 
4072
            if (target == NULL) {
 
4073
                virReportOOMError();
 
4074
                goto cleanup;
 
4075
            }
4060
4076
        } else {
4061
4077
            virXendError(VIR_ERR_NO_SUPPORT, "%s",
4062
4078
                         _("unsupported device type"));
4076
4092
        /* device doesn't exist, define it */
4077
4093
        ret = xend_op(domain->conn, domain->name, "op", "device_create",
4078
4094
                      "config", sexpr, NULL);
4079
 
    }
4080
 
    else {
4081
 
        /* device exists, attempt to modify it */
4082
 
        ret = xend_op(domain->conn, domain->name, "op", "device_configure",
4083
 
                      "config", sexpr, "dev", ref, NULL);
 
4095
    } else {
 
4096
        if (dev->data.disk->device != VIR_DOMAIN_DISK_DEVICE_CDROM) {
 
4097
            virXendError(VIR_ERR_OPERATION_INVALID,
 
4098
                         _("target '%s' already exists"), target);
 
4099
        } else {
 
4100
            /* device exists, attempt to modify it */
 
4101
            ret = xend_op(domain->conn, domain->name, "op", "device_configure",
 
4102
                          "config", sexpr, "dev", ref, NULL);
 
4103
        }
4084
4104
    }
4085
4105
 
4086
4106
cleanup:
4087
4107
    VIR_FREE(sexpr);
4088
4108
    virDomainDefFree(def);
4089
4109
    virDomainDeviceDefFree(dev);
 
4110
    VIR_FREE(target);
4090
4111
    return ret;
4091
4112
}
4092
4113
 
4391
4412
            goto error;
4392
4413
        }
4393
4414
 
4394
 
        // Change the autostart value in place, then define the new sexpr
 
4415
        /* Change the autostart value in place, then define the new sexpr */
4395
4416
        VIR_FREE(autonode->u.s.car->u.value);
4396
4417
        autonode->u.s.car->u.value = (autostart ? strdup("start")
4397
4418
                                                : strdup("ignore"));
4635
4656
        goto error;
4636
4657
    }
4637
4658
 
4638
 
    DEBUG("Defining w/ sexpr: \n%s", sexpr);
4639
 
 
4640
4659
    ret = xend_op(conn, "", "op", "new", "config", sexpr, NULL);
4641
4660
    VIR_FREE(sexpr);
4642
4661
    if (ret != 0) {
5153
5172
 
5154
5173
    ret = 0;
5155
5174
 cleanup:
5156
 
    if (fd >= 0) close (fd);
 
5175
    VIR_FORCE_CLOSE(fd);
5157
5176
    sexpr_free(root);
5158
5177
    virDomainDefFree(def);
5159
5178
    return ret;
5251
5270
 
5252
5271
        if (def->data.vnc.listenAddr)
5253
5272
            virBufferVSprintf(buf, "(vnclisten '%s')", def->data.vnc.listenAddr);
5254
 
        if (def->data.vnc.passwd)
5255
 
            virBufferVSprintf(buf, "(vncpasswd '%s')", def->data.vnc.passwd);
 
5273
        if (def->data.vnc.auth.passwd)
 
5274
            virBufferVSprintf(buf, "(vncpasswd '%s')", def->data.vnc.auth.passwd);
5256
5275
        if (def->data.vnc.keymap)
5257
5276
            virBufferVSprintf(buf, "(keymap '%s')", def->data.vnc.keymap);
5258
5277
    }
5294
5313
 
5295
5314
            if (def->data.vnc.listenAddr)
5296
5315
                virBufferVSprintf(buf, "(vnclisten '%s')", def->data.vnc.listenAddr);
5297
 
            if (def->data.vnc.passwd)
5298
 
                virBufferVSprintf(buf, "(vncpasswd '%s')", def->data.vnc.passwd);
 
5316
            if (def->data.vnc.auth.passwd)
 
5317
                virBufferVSprintf(buf, "(vncpasswd '%s')", def->data.vnc.auth.passwd);
5299
5318
            if (def->data.vnc.keymap)
5300
5319
                virBufferVSprintf(buf, "(keymap '%s')", def->data.vnc.keymap);
5301
5320
 
5309
5328
xenDaemonFormatSxprChr(virDomainChrDefPtr def,
5310
5329
                       virBufferPtr buf)
5311
5330
{
5312
 
    const char *type = virDomainChrTypeToString(def->type);
 
5331
    const char *type = virDomainChrTypeToString(def->source.type);
5313
5332
 
5314
5333
    if (!type) {
5315
5334
        virXendError(VIR_ERR_INTERNAL_ERROR,
5317
5336
        return -1;
5318
5337
    }
5319
5338
 
5320
 
    switch (def->type) {
 
5339
    switch (def->source.type) {
5321
5340
    case VIR_DOMAIN_CHR_TYPE_NULL:
5322
5341
    case VIR_DOMAIN_CHR_TYPE_STDIO:
5323
5342
    case VIR_DOMAIN_CHR_TYPE_VC:
5327
5346
 
5328
5347
    case VIR_DOMAIN_CHR_TYPE_FILE:
5329
5348
    case VIR_DOMAIN_CHR_TYPE_PIPE:
5330
 
        virBufferVSprintf(buf, "%s:%s", type, def->data.file.path);
 
5349
        virBufferVSprintf(buf, "%s:", type);
 
5350
        virBufferEscapeSexpr(buf, "%s", def->source.data.file.path);
5331
5351
        break;
5332
5352
 
5333
5353
    case VIR_DOMAIN_CHR_TYPE_DEV:
5334
 
        virBufferVSprintf(buf, "%s", def->data.file.path);
 
5354
        virBufferEscapeSexpr(buf, "%s", def->source.data.file.path);
5335
5355
        break;
5336
5356
 
5337
5357
    case VIR_DOMAIN_CHR_TYPE_TCP:
5338
5358
        virBufferVSprintf(buf, "%s:%s:%s%s",
5339
 
                          (def->data.tcp.protocol == VIR_DOMAIN_CHR_TCP_PROTOCOL_RAW ?
 
5359
                          (def->source.data.tcp.protocol
 
5360
                           == VIR_DOMAIN_CHR_TCP_PROTOCOL_RAW ?
5340
5361
                           "tcp" : "telnet"),
5341
 
                          (def->data.tcp.host ? def->data.tcp.host : ""),
5342
 
                          (def->data.tcp.service ? def->data.tcp.service : ""),
5343
 
                          (def->data.tcp.listen ? ",server,nowait" : ""));
 
5362
                          (def->source.data.tcp.host ?
 
5363
                           def->source.data.tcp.host : ""),
 
5364
                          (def->source.data.tcp.service ?
 
5365
                           def->source.data.tcp.service : ""),
 
5366
                          (def->source.data.tcp.listen ?
 
5367
                           ",server,nowait" : ""));
5344
5368
        break;
5345
5369
 
5346
5370
    case VIR_DOMAIN_CHR_TYPE_UDP:
5347
5371
        virBufferVSprintf(buf, "%s:%s:%s@%s:%s", type,
5348
 
                          (def->data.udp.connectHost ? def->data.udp.connectHost : ""),
5349
 
                          (def->data.udp.connectService ? def->data.udp.connectService : ""),
5350
 
                          (def->data.udp.bindHost ? def->data.udp.bindHost : ""),
5351
 
                          (def->data.udp.bindService ? def->data.udp.bindService : ""));
 
5372
                          (def->source.data.udp.connectHost ?
 
5373
                           def->source.data.udp.connectHost : ""),
 
5374
                          (def->source.data.udp.connectService ?
 
5375
                           def->source.data.udp.connectService : ""),
 
5376
                          (def->source.data.udp.bindHost ?
 
5377
                           def->source.data.udp.bindHost : ""),
 
5378
                          (def->source.data.udp.bindService ?
 
5379
                           def->source.data.udp.bindService : ""));
5352
5380
        break;
5353
5381
 
5354
5382
    case VIR_DOMAIN_CHR_TYPE_UNIX:
5355
 
        virBufferVSprintf(buf, "%s:%s%s", type,
5356
 
                          def->data.nix.path,
5357
 
                          def->data.nix.listen ? ",server,nowait" : "");
 
5383
        virBufferVSprintf(buf, "%s:", type);
 
5384
        virBufferEscapeSexpr(buf, "%s", def->source.data.nix.path);
 
5385
        if (def->source.data.nix.listen)
 
5386
            virBufferAddLit(buf, ",server,nowait");
5358
5387
        break;
5359
5388
    }
5360
5389
 
5430
5459
 
5431
5460
    if (hvm) {
5432
5461
        /* Xend <= 3.0.2 wants a ioemu: prefix on devices for HVM */
5433
 
        if (xendConfigVersion == 1)
5434
 
            virBufferVSprintf(buf, "(dev 'ioemu:%s')", def->dst);
5435
 
        else                    /* But newer does not */
5436
 
            virBufferVSprintf(buf, "(dev '%s:%s')", def->dst,
 
5462
        if (xendConfigVersion == 1) {
 
5463
            virBufferEscapeSexpr(buf, "(dev 'ioemu:%s')", def->dst);
 
5464
        } else {
 
5465
            /* But newer does not */
 
5466
            virBufferEscapeSexpr(buf, "(dev '%s:", def->dst);
 
5467
            virBufferVSprintf(buf, "%s')",
5437
5468
                              def->device == VIR_DOMAIN_DISK_DEVICE_CDROM ?
5438
5469
                              "cdrom" : "disk");
 
5470
        }
5439
5471
    } else if (def->device == VIR_DOMAIN_DISK_DEVICE_CDROM) {
5440
 
        virBufferVSprintf(buf, "(dev '%s:cdrom')", def->dst);
 
5472
        virBufferEscapeSexpr(buf, "(dev '%s:cdrom')", def->dst);
5441
5473
    } else {
5442
 
        virBufferVSprintf(buf, "(dev '%s')", def->dst);
 
5474
        virBufferEscapeSexpr(buf, "(dev '%s')", def->dst);
5443
5475
    }
5444
5476
 
5445
5477
    if (def->src) {
5446
5478
        if (def->driverName) {
5447
5479
            if (STREQ(def->driverName, "tap") ||
5448
5480
                STREQ(def->driverName, "tap2")) {
5449
 
                virBufferVSprintf(buf, "(uname '%s:%s:%s')",
5450
 
                                  def->driverName,
5451
 
                                  def->driverType ? def->driverType : "aio",
5452
 
                                  def->src);
 
5481
                virBufferEscapeSexpr(buf, "(uname '%s:", def->driverName);
 
5482
                virBufferEscapeSexpr(buf, "%s:",
 
5483
                                     def->driverType ? def->driverType : "aio");
 
5484
                virBufferEscapeSexpr(buf, "%s')", def->src);
5453
5485
            } else {
5454
 
                virBufferVSprintf(buf, "(uname '%s:%s')",
5455
 
                                  def->driverName,
5456
 
                                  def->src);
 
5486
                virBufferEscapeSexpr(buf, "(uname '%s:", def->driverName);
 
5487
                virBufferEscapeSexpr(buf, "%s')", def->src);
5457
5488
            }
5458
5489
        } else {
5459
5490
            if (def->type == VIR_DOMAIN_DISK_TYPE_FILE) {
5460
 
                virBufferVSprintf(buf, "(uname 'file:%s')", def->src);
 
5491
                virBufferEscapeSexpr(buf, "(uname 'file:%s')", def->src);
5461
5492
            } else if (def->type == VIR_DOMAIN_DISK_TYPE_BLOCK) {
5462
5493
                if (def->src[0] == '/')
5463
 
                    virBufferVSprintf(buf, "(uname 'phy:%s')", def->src);
 
5494
                    virBufferEscapeSexpr(buf, "(uname 'phy:%s')", def->src);
5464
5495
                else
5465
 
                    virBufferVSprintf(buf, "(uname 'phy:/dev/%s')", def->src);
 
5496
                    virBufferEscapeSexpr(buf, "(uname 'phy:/dev/%s')",
 
5497
                                         def->src);
5466
5498
            } else {
5467
5499
                virXendError(VIR_ERR_CONFIG_UNSUPPORTED,
5468
5500
                             _("unsupported disk type %s"),
5531
5563
 
5532
5564
    switch (def->type) {
5533
5565
    case VIR_DOMAIN_NET_TYPE_BRIDGE:
5534
 
        virBufferVSprintf(buf, "(bridge '%s')", def->data.bridge.brname);
 
5566
        virBufferEscapeSexpr(buf, "(bridge '%s')", def->data.bridge.brname);
5535
5567
        if (def->data.bridge.script)
5536
5568
            script = def->data.bridge.script;
5537
5569
 
5538
 
        virBufferVSprintf(buf, "(script '%s')", script);
 
5570
        virBufferEscapeSexpr(buf, "(script '%s')", script);
5539
5571
        if (def->data.bridge.ipaddr != NULL)
5540
 
            virBufferVSprintf(buf, "(ip '%s')", def->data.bridge.ipaddr);
 
5572
            virBufferEscapeSexpr(buf, "(ip '%s')", def->data.bridge.ipaddr);
5541
5573
        break;
5542
5574
 
5543
5575
    case VIR_DOMAIN_NET_TYPE_NETWORK:
5560
5592
                         def->data.network.name);
5561
5593
            return -1;
5562
5594
        }
5563
 
        virBufferVSprintf(buf, "(bridge '%s')", bridge);
5564
 
        virBufferVSprintf(buf, "(script '%s')", script);
 
5595
        virBufferEscapeSexpr(buf, "(bridge '%s')", bridge);
 
5596
        virBufferEscapeSexpr(buf, "(script '%s')", script);
5565
5597
        VIR_FREE(bridge);
5566
5598
    }
5567
5599
    break;
5568
5600
 
5569
5601
    case VIR_DOMAIN_NET_TYPE_ETHERNET:
5570
5602
        if (def->data.ethernet.script)
5571
 
            virBufferVSprintf(buf, "(script '%s')", def->data.ethernet.script);
 
5603
            virBufferEscapeSexpr(buf, "(script '%s')",
 
5604
                                 def->data.ethernet.script);
5572
5605
        if (def->data.ethernet.ipaddr != NULL)
5573
 
            virBufferVSprintf(buf, "(ip '%s')", def->data.ethernet.ipaddr);
 
5606
            virBufferEscapeSexpr(buf, "(ip '%s')", def->data.ethernet.ipaddr);
5574
5607
        break;
5575
5608
 
5576
5609
    case VIR_DOMAIN_NET_TYPE_USER:
5585
5618
 
5586
5619
    if (def->ifname != NULL &&
5587
5620
        !STRPREFIX(def->ifname, "vif"))
5588
 
        virBufferVSprintf(buf, "(vifname '%s')", def->ifname);
 
5621
        virBufferEscapeSexpr(buf, "(vifname '%s')", def->ifname);
5589
5622
 
5590
5623
    if (!hvm) {
5591
5624
        if (def->model != NULL)
5592
 
            virBufferVSprintf(buf, "(model '%s')", def->model);
 
5625
            virBufferEscapeSexpr(buf, "(model '%s')", def->model);
5593
5626
    }
5594
5627
    else if (def->model == NULL) {
5595
5628
        /*
5603
5636
        virBufferAddLit(buf, "(type netfront)");
5604
5637
    }
5605
5638
    else {
5606
 
        virBufferVSprintf(buf, "(model '%s')", def->model);
 
5639
        virBufferEscapeSexpr(buf, "(model '%s')", def->model);
5607
5640
        virBufferAddLit(buf, "(type ioemu)");
5608
5641
    }
5609
5642
 
5710
5743
                         def->sounds[i]->model);
5711
5744
            return -1;
5712
5745
        }
5713
 
        virBufferVSprintf(buf, "%s%s", i ? "," : "", str);
 
5746
        if (i)
 
5747
            virBufferAddChar(buf, ',');
 
5748
        virBufferEscapeSexpr(buf, "%s", str);
5714
5749
    }
5715
5750
 
5716
5751
    if (virBufferError(buf)) {
5744
5779
}
5745
5780
 
5746
5781
 
 
5782
/* Computing the vcpu_avail bitmask works because MAX_VIRT_CPUS is
 
5783
   either 32, or 64 on a platform where long is big enough.  */
 
5784
verify(MAX_VIRT_CPUS <= sizeof(1UL) * CHAR_BIT);
 
5785
 
5747
5786
/**
5748
5787
 * xenDaemonFormatSxpr:
5749
5788
 * @conn: pointer to the hypervisor connection
5763
5802
    virBuffer buf = VIR_BUFFER_INITIALIZER;
5764
5803
    char uuidstr[VIR_UUID_STRING_BUFLEN];
5765
5804
    const char *tmp;
 
5805
    char *bufout;
5766
5806
    int hvm = 0, i;
5767
5807
 
 
5808
    DEBUG0("Formatting domain sexpr");
 
5809
 
5768
5810
    virBufferAddLit(&buf, "(vm ");
5769
 
    virBufferVSprintf(&buf, "(name '%s')", def->name);
 
5811
    virBufferEscapeSexpr(&buf, "(name '%s')", def->name);
5770
5812
    virBufferVSprintf(&buf, "(memory %lu)(maxmem %lu)",
5771
 
                      def->mem.cur_balloon/1024, def->mem.max_balloon/1024);
 
5813
                      VIR_DIV_UP(def->mem.cur_balloon, 1024),
 
5814
                      VIR_DIV_UP(def->mem.max_balloon, 1024));
5772
5815
    virBufferVSprintf(&buf, "(vcpus %u)", def->maxvcpus);
5773
 
    /* Computing the vcpu_avail bitmask works because MAX_VIRT_CPUS is 32.  */
 
5816
    /* Computing the vcpu_avail bitmask works because MAX_VIRT_CPUS is
 
5817
       either 32, or 64 on a platform where long is big enough.  */
5774
5818
    if (def->vcpus < def->maxvcpus)
5775
 
        virBufferVSprintf(&buf, "(vcpu_avail %u)", (1U << def->vcpus) - 1);
 
5819
        virBufferVSprintf(&buf, "(vcpu_avail %lu)", (1UL << def->vcpus) - 1);
5776
5820
 
5777
5821
    if (def->cpumask) {
5778
5822
        char *ranges = virDomainCpuSetFormat(def->cpumask, def->cpumasklen);
5779
5823
        if (ranges == NULL)
5780
5824
            goto error;
5781
 
        virBufferVSprintf(&buf, "(cpus '%s')", ranges);
 
5825
        virBufferEscapeSexpr(&buf, "(cpus '%s')", ranges);
5782
5826
        VIR_FREE(ranges);
5783
5827
    }
5784
5828
 
5786
5830
    virBufferVSprintf(&buf, "(uuid '%s')", uuidstr);
5787
5831
 
5788
5832
    if (def->description)
5789
 
        virBufferVSprintf(&buf, "(description '%s')", def->description);
 
5833
        virBufferEscapeSexpr(&buf, "(description '%s')", def->description);
5790
5834
 
5791
5835
    if (def->os.bootloader) {
5792
5836
        if (def->os.bootloader[0])
5793
 
            virBufferVSprintf(&buf, "(bootloader '%s')", def->os.bootloader);
 
5837
            virBufferEscapeSexpr(&buf, "(bootloader '%s')", def->os.bootloader);
5794
5838
        else
5795
5839
            virBufferAddLit(&buf, "(bootloader)");
5796
5840
 
5797
5841
        if (def->os.bootloaderArgs)
5798
 
            virBufferVSprintf(&buf, "(bootloader_args '%s')", def->os.bootloaderArgs);
 
5842
            virBufferEscapeSexpr(&buf, "(bootloader_args '%s')", def->os.bootloaderArgs);
5799
5843
    }
5800
5844
 
5801
5845
    if (!(tmp = virDomainLifecycleTypeToString(def->onPoweroff))) {
5852
5896
        }
5853
5897
 
5854
5898
        if (def->os.kernel)
5855
 
            virBufferVSprintf(&buf, "(kernel '%s')", def->os.kernel);
 
5899
            virBufferEscapeSexpr(&buf, "(kernel '%s')", def->os.kernel);
5856
5900
        if (def->os.initrd)
5857
 
            virBufferVSprintf(&buf, "(ramdisk '%s')", def->os.initrd);
 
5901
            virBufferEscapeSexpr(&buf, "(ramdisk '%s')", def->os.initrd);
5858
5902
        if (def->os.root)
5859
 
            virBufferVSprintf(&buf, "(root '%s')", def->os.root);
 
5903
            virBufferEscapeSexpr(&buf, "(root '%s')", def->os.root);
5860
5904
        if (def->os.cmdline)
5861
 
            virBufferVSprintf(&buf, "(args '%s')", def->os.cmdline);
 
5905
            virBufferEscapeSexpr(&buf, "(args '%s')", def->os.cmdline);
5862
5906
 
5863
5907
        if (hvm) {
5864
5908
            char bootorder[VIR_DOMAIN_BOOT_LAST+1];
5865
5909
            if (def->os.kernel)
5866
 
                virBufferVSprintf(&buf, "(loader '%s')", def->os.loader);
 
5910
                virBufferEscapeSexpr(&buf, "(loader '%s')", def->os.loader);
5867
5911
            else
5868
 
                virBufferVSprintf(&buf, "(kernel '%s')", def->os.loader);
 
5912
                virBufferEscapeSexpr(&buf, "(kernel '%s')", def->os.loader);
5869
5913
 
5870
5914
            virBufferVSprintf(&buf, "(vcpus %u)", def->maxvcpus);
5871
5915
            if (def->vcpus < def->maxvcpus)
5872
 
                virBufferVSprintf(&buf, "(vcpu_avail %u)",
5873
 
                                  (1U << def->vcpus) - 1);
 
5916
                virBufferVSprintf(&buf, "(vcpu_avail %lu)",
 
5917
                                  (1UL << def->vcpus) - 1);
5874
5918
 
5875
5919
            for (i = 0 ; i < def->os.nBootDevs ; i++) {
5876
5920
                switch (def->os.bootDevs[i]) {
5908
5952
                        def->disks[i]->src == NULL)
5909
5953
                        break;
5910
5954
 
5911
 
                    virBufferVSprintf(&buf, "(cdrom '%s')",
5912
 
                                      def->disks[i]->src);
 
5955
                    virBufferEscapeSexpr(&buf, "(cdrom '%s')",
 
5956
                                         def->disks[i]->src);
5913
5957
                    break;
5914
5958
 
5915
5959
                case VIR_DOMAIN_DISK_DEVICE_FLOPPY:
5916
5960
                    /* all xend versions define floppies here */
5917
 
                    virBufferVSprintf(&buf, "(%s '%s')", def->disks[i]->dst,
5918
 
                        def->disks[i]->src);
 
5961
                    virBufferEscapeSexpr(&buf, "(%s ", def->disks[i]->dst);
 
5962
                    virBufferEscapeSexpr(&buf, "'%s')", def->disks[i]->src);
5919
5963
                    break;
5920
5964
 
5921
5965
                default:
5929
5973
                virBufferAddLit(&buf, "(apic 1)");
5930
5974
            if (def->features & (1 << VIR_DOMAIN_FEATURE_PAE))
5931
5975
                virBufferAddLit(&buf, "(pae 1)");
 
5976
            if (def->features & (1 << VIR_DOMAIN_FEATURE_HAP))
 
5977
                virBufferAddLit(&buf, "(hap 1)");
5932
5978
 
5933
5979
            virBufferAddLit(&buf, "(usb 1)");
5934
5980
 
5967
6013
 
5968
6014
        /* get the device emulation model */
5969
6015
        if (def->emulator && (hvm || xendConfigVersion >= 3))
5970
 
            virBufferVSprintf(&buf, "(device_model '%s')", def->emulator);
 
6016
            virBufferEscapeSexpr(&buf, "(device_model '%s')", def->emulator);
5971
6017
 
5972
6018
 
5973
6019
        /* PV graphics for xen <= 3.0.4, or HVM graphics for xen <= 3.1.0 */
6011
6057
        goto error;
6012
6058
    }
6013
6059
 
6014
 
    return virBufferContentAndReset(&buf);
 
6060
    bufout = virBufferContentAndReset(&buf);
 
6061
    DEBUG("Formatted sexpr: \n%s", bufout);
 
6062
    return bufout;
6015
6063
 
6016
6064
error:
6017
6065
    virBufferFreeAndReset(&buf);
6125
6173
 
6126
6174
    return 0;
6127
6175
}
6128
 
 
6129
 
#endif /* ! PROXY */