~ubuntu-branches/ubuntu/raring/libvirt/raring

« back to all changes in this revision

Viewing changes to .pc/fix-ubuntu-xen-qemu-dm-path.patch/src/xen/xen_hypervisor.c

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-11-19 10:41:02 UTC
  • mfrom: (1.2.15) (223.1.2 raring-proposed)
  • Revision ID: package-import@ubuntu.com-20121119104102-l6ewdppikysbzztu
Tags: 1.0.0-0ubuntu2
debian/patches/add-armhf-sysinfo-infomration.patch: Disable
to fix FTBFS on arm.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 *
4
4
 * Copyright (C) 2005-2012 Red Hat, Inc.
5
5
 *
6
 
 * See COPYING.LIB for the License of this software
 
6
 * This library is free software; you can redistribute it and/or
 
7
 * modify it under the terms of the GNU Lesser General Public
 
8
 * License as published by the Free Software Foundation; either
 
9
 * version 2.1 of the License, or (at your option) any later version.
 
10
 *
 
11
 * This library is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
 * Lesser General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU Lesser General Public
 
17
 * License along with this library.  If not, see
 
18
 * <http://www.gnu.org/licenses/>.
7
19
 *
8
20
 * Daniel Veillard <veillard@redhat.com>
9
21
 */
65
77
#include "buf.h"
66
78
#include "capabilities.h"
67
79
#include "memory.h"
 
80
#include "threads.h"
68
81
#include "virfile.h"
69
82
#include "virnodesuspend.h"
70
83
#include "virtypedparam.h"
113
126
#endif
114
127
 
115
128
static int xen_ioctl_hypercall_cmd = 0;
116
 
static int initialized = 0;
117
 
static int in_init = 0;
118
129
static struct xenHypervisorVersions hv_versions = {
119
130
    .hv = 0,
120
131
    .hypervisor = 2,
526
537
lock_pages(void *addr, size_t len)
527
538
{
528
539
#ifdef __linux__
529
 
        return mlock(addr, len);
 
540
    if (mlock(addr, len) < 0) {
 
541
        virReportSystemError(errno,
 
542
                             _("Unable to lock %zu bytes of memory"),
 
543
                             len);
 
544
        return -1;
 
545
    }
 
546
    return 0;
530
547
#elif defined(__sun)
531
 
        return 0;
 
548
    return 0;
532
549
#endif
533
550
}
534
551
 
536
553
unlock_pages(void *addr, size_t len)
537
554
{
538
555
#ifdef __linux__
539
 
        return munlock(addr, len);
 
556
    if (munlock(addr, len) < 0) {
 
557
        virReportSystemError(errno,
 
558
                             _("Unable to unlock %zu bytes of memory"),
 
559
                             len);
 
560
        return -1;
 
561
    }
 
562
    return 0;
540
563
#elif defined(__sun)
541
 
        return 0;
 
564
    return 0;
542
565
#endif
543
566
}
544
567
 
874
897
    .xenDomainSetSchedulerParameters = xenHypervisorSetSchedulerParameters,
875
898
};
876
899
 
877
 
#define virXenError(code, ...)                                             \
878
 
        if (in_init == 0)                                                  \
879
 
            virReportErrorHelper(VIR_FROM_XEN, code, __FILE__,             \
880
 
                                 __FUNCTION__, __LINE__, __VA_ARGS__)
881
 
 
882
900
/**
883
901
 * xenHypervisorDoV0Op:
884
902
 * @handle: the handle to the Xen hypervisor
900
918
    hc.op = __HYPERVISOR_dom0_op;
901
919
    hc.arg[0] = (unsigned long) op;
902
920
 
903
 
    if (lock_pages(op, sizeof(dom0_op_t)) < 0) {
904
 
        virXenError(VIR_ERR_XEN_CALL, " locking");
 
921
    if (lock_pages(op, sizeof(dom0_op_t)) < 0)
905
922
        return -1;
906
 
    }
907
923
 
908
924
    ret = ioctl(handle, xen_ioctl_hypercall_cmd, (unsigned long) &hc);
909
925
    if (ret < 0) {
910
 
        virXenError(VIR_ERR_XEN_CALL, " ioctl %d",
911
 
                    xen_ioctl_hypercall_cmd);
 
926
        virReportSystemError(errno,
 
927
                             _("Unable to issue hypervisor ioctl %d"),
 
928
                             xen_ioctl_hypercall_cmd);
912
929
    }
913
930
 
914
 
    if (unlock_pages(op, sizeof(dom0_op_t)) < 0) {
915
 
        virXenError(VIR_ERR_XEN_CALL, " releasing");
 
931
    if (unlock_pages(op, sizeof(dom0_op_t)) < 0)
916
932
        ret = -1;
917
 
    }
918
933
 
919
934
    if (ret < 0)
920
935
        return -1;
942
957
    hc.op = __HYPERVISOR_dom0_op;
943
958
    hc.arg[0] = (unsigned long) op;
944
959
 
945
 
    if (lock_pages(op, sizeof(dom0_op_t)) < 0) {
946
 
        virXenError(VIR_ERR_XEN_CALL, " locking");
 
960
    if (lock_pages(op, sizeof(dom0_op_t)) < 0)
947
961
        return -1;
948
 
    }
949
962
 
950
963
    ret = ioctl(handle, xen_ioctl_hypercall_cmd, (unsigned long) &hc);
951
964
    if (ret < 0) {
952
 
        virXenError(VIR_ERR_XEN_CALL, " ioctl %d",
953
 
                    xen_ioctl_hypercall_cmd);
 
965
        virReportSystemError(errno,
 
966
                             _("Unable to issue hypervisor ioctl %d"),
 
967
                             xen_ioctl_hypercall_cmd);
954
968
    }
955
969
 
956
 
    if (unlock_pages(op, sizeof(dom0_op_t)) < 0) {
957
 
        virXenError(VIR_ERR_XEN_CALL, " releasing");
 
970
    if (unlock_pages(op, sizeof(dom0_op_t)) < 0)
958
971
        ret = -1;
959
 
    }
960
972
 
961
973
    if (ret < 0)
962
974
        return -1;
985
997
    hc.op = __HYPERVISOR_sysctl;
986
998
    hc.arg[0] = (unsigned long) op;
987
999
 
988
 
    if (lock_pages(op, sizeof(dom0_op_t)) < 0) {
989
 
        virXenError(VIR_ERR_XEN_CALL, " locking");
 
1000
    if (lock_pages(op, sizeof(dom0_op_t)) < 0)
990
1001
        return -1;
991
 
    }
992
1002
 
993
1003
    ret = ioctl(handle, xen_ioctl_hypercall_cmd, (unsigned long) &hc);
994
1004
    if (ret < 0) {
995
 
        virXenError(VIR_ERR_XEN_CALL, " sys ioctl %d",
996
 
                                            xen_ioctl_hypercall_cmd);
 
1005
        virReportSystemError(errno,
 
1006
                             _("Unable to issue hypervisor ioctl %d"),
 
1007
                             xen_ioctl_hypercall_cmd);
997
1008
    }
998
1009
 
999
 
    if (unlock_pages(op, sizeof(dom0_op_t)) < 0) {
1000
 
        virXenError(VIR_ERR_XEN_CALL, " releasing");
 
1010
    if (unlock_pages(op, sizeof(dom0_op_t)) < 0)
1001
1011
        ret = -1;
1002
 
    }
1003
1012
 
1004
1013
    if (ret < 0)
1005
1014
        return -1;
1028
1037
    hc.op = __HYPERVISOR_domctl;
1029
1038
    hc.arg[0] = (unsigned long) op;
1030
1039
 
1031
 
    if (lock_pages(op, sizeof(dom0_op_t)) < 0) {
1032
 
        virXenError(VIR_ERR_XEN_CALL, " locking");
 
1040
    if (lock_pages(op, sizeof(dom0_op_t)) < 0)
1033
1041
        return -1;
1034
 
    }
1035
1042
 
1036
1043
    ret = ioctl(handle, xen_ioctl_hypercall_cmd, (unsigned long) &hc);
1037
1044
    if (ret < 0) {
1038
 
        virXenError(VIR_ERR_XEN_CALL, " ioctl %d",
1039
 
                    xen_ioctl_hypercall_cmd);
 
1045
        virReportSystemError(errno,
 
1046
                             _("Unable to issue hypervisor ioctl %d"),
 
1047
                             xen_ioctl_hypercall_cmd);
1040
1048
    }
1041
1049
 
1042
 
    if (unlock_pages(op, sizeof(dom0_op_t)) < 0) {
1043
 
        virXenError(VIR_ERR_XEN_CALL, " releasing");
 
1050
    if (unlock_pages(op, sizeof(dom0_op_t)) < 0)
1044
1051
        ret = -1;
1045
 
    }
1046
1052
 
1047
1053
    if (ret < 0)
1048
1054
        return -1;
1068
1074
    int ret = -1;
1069
1075
 
1070
1076
    if (lock_pages(XEN_GETDOMAININFOLIST_DATA(dominfos),
1071
 
              XEN_GETDOMAININFO_SIZE * maxids) < 0) {
1072
 
        virXenError(VIR_ERR_XEN_CALL, " locking");
 
1077
                   XEN_GETDOMAININFO_SIZE * maxids) < 0)
1073
1078
        return -1;
1074
 
    }
 
1079
 
1075
1080
    if (hv_versions.hypervisor > 1) {
1076
1081
        xen_op_v2_sys op;
1077
1082
 
1123
1128
            ret = op.u.getdomaininfolist.num_domains;
1124
1129
    }
1125
1130
    if (unlock_pages(XEN_GETDOMAININFOLIST_DATA(dominfos),
1126
 
                XEN_GETDOMAININFO_SIZE * maxids) < 0) {
1127
 
        virXenError(VIR_ERR_XEN_CALL, " release");
 
1131
                     XEN_GETDOMAININFO_SIZE * maxids) < 0)
1128
1132
        ret = -1;
1129
 
    }
 
1133
 
1130
1134
    return ret;
1131
1135
}
1132
1136
 
1161
1165
    xenUnifiedPrivatePtr priv;
1162
1166
 
1163
1167
    if (domain->conn == NULL) {
1164
 
        virXenError(VIR_ERR_INTERNAL_ERROR, "%s",
1165
 
                    _("domain or conn is NULL"));
 
1168
        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
 
1169
                       _("domain or conn is NULL"));
1166
1170
        return NULL;
1167
1171
    }
1168
1172
 
1169
1173
    priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
1170
1174
    if (priv->handle < 0) {
1171
 
        virXenError(VIR_ERR_INTERNAL_ERROR, "%s",
1172
 
                    _("priv->handle invalid"));
 
1175
        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
 
1176
                       _("priv->handle invalid"));
1173
1177
        return NULL;
1174
1178
    }
1175
1179
    if (domain->id < 0) {
1176
 
        virXenError(VIR_ERR_OPERATION_INVALID,
1177
 
                    "%s", _("domain is not running"));
 
1180
        virReportError(VIR_ERR_OPERATION_INVALID,
 
1181
                       "%s", _("domain is not running"));
1178
1182
        return NULL;
1179
1183
    }
1180
1184
 
1184
1188
     * TODO: check on Xen 3.0.3
1185
1189
     */
1186
1190
    if (hv_versions.dom_interface < 5) {
1187
 
        virXenError(VIR_ERR_NO_XEN, "%s",
1188
 
                    _("unsupported in dom interface < 5"));
 
1191
        virReportError(VIR_ERR_NO_XEN, "%s",
 
1192
                       _("unsupported in dom interface < 5"));
1189
1193
        return NULL;
1190
1194
    }
1191
1195
 
1242
1246
    xenUnifiedPrivatePtr priv;
1243
1247
 
1244
1248
    if (domain->conn == NULL) {
1245
 
        virXenError(VIR_ERR_INTERNAL_ERROR, "%s",
1246
 
                    _("domain or conn is NULL"));
 
1249
        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
 
1250
                       _("domain or conn is NULL"));
1247
1251
        return -1;
1248
1252
    }
1249
1253
 
1250
1254
    priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
1251
1255
    if (priv->handle < 0) {
1252
 
        virXenError(VIR_ERR_INTERNAL_ERROR, "%s",
1253
 
                    _("priv->handle invalid"));
 
1256
        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
 
1257
                       _("priv->handle invalid"));
1254
1258
        return -1;
1255
1259
    }
1256
1260
    if (domain->id < 0) {
1257
 
        virXenError(VIR_ERR_OPERATION_INVALID,
1258
 
                    "%s", _("domain is not running"));
 
1261
        virReportError(VIR_ERR_OPERATION_INVALID,
 
1262
                       "%s", _("domain is not running"));
1259
1263
        return -1;
1260
1264
    }
1261
1265
 
1265
1269
     * TODO: check on Xen 3.0.3
1266
1270
     */
1267
1271
    if (hv_versions.dom_interface < 5) {
1268
 
        virXenError(VIR_ERR_NO_XEN, "%s",
1269
 
                    _("unsupported in dom interface < 5"));
 
1272
        virReportError(VIR_ERR_NO_XEN, "%s",
 
1273
                       _("unsupported in dom interface < 5"));
1270
1274
        return -1;
1271
1275
    }
1272
1276
 
1284
1288
        switch (op_sys.u.getschedulerid.sched_id){
1285
1289
            case XEN_SCHEDULER_SEDF:
1286
1290
                if (*nparams < XEN_SCHED_SEDF_NPARAM) {
1287
 
                    virXenError(VIR_ERR_INVALID_ARG,
1288
 
                                "%s", _("Invalid parameter count"));
 
1291
                    virReportError(VIR_ERR_INVALID_ARG,
 
1292
                                   "%s", _("Invalid parameter count"));
1289
1293
                    return -1;
1290
1294
                }
1291
1295
 
1319
1323
                    *nparams = XEN_SCHED_CRED_NPARAM;
1320
1324
                break;
1321
1325
            default:
1322
 
                virXenError(VIR_ERR_INVALID_ARG,
1323
 
                            _("Unknown scheduler %d"),
1324
 
                            op_sys.u.getschedulerid.sched_id);
 
1326
                virReportError(VIR_ERR_INVALID_ARG,
 
1327
                               _("Unknown scheduler %d"),
 
1328
                               op_sys.u.getschedulerid.sched_id);
1325
1329
                return -1;
1326
1330
        }
1327
1331
    }
1348
1352
    char buf[256];
1349
1353
 
1350
1354
    if (domain->conn == NULL) {
1351
 
        virXenError(VIR_ERR_INTERNAL_ERROR, "%s",
1352
 
                    _("domain or conn is NULL"));
 
1355
        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
 
1356
                       _("domain or conn is NULL"));
1353
1357
        return -1;
1354
1358
    }
1355
1359
 
1368
1372
 
1369
1373
    priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
1370
1374
    if (priv->handle < 0) {
1371
 
        virXenError(VIR_ERR_INTERNAL_ERROR, "%s",
1372
 
                    _("priv->handle invalid"));
 
1375
        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
 
1376
                       _("priv->handle invalid"));
1373
1377
        return -1;
1374
1378
    }
1375
1379
    if (domain->id < 0) {
1376
 
        virXenError(VIR_ERR_OPERATION_INVALID,
1377
 
                    "%s", _("domain is not running"));
 
1380
        virReportError(VIR_ERR_OPERATION_INVALID,
 
1381
                       "%s", _("domain is not running"));
1378
1382
        return -1;
1379
1383
    }
1380
1384
 
1384
1388
     * TODO: check on Xen 3.0.3
1385
1389
     */
1386
1390
    if (hv_versions.dom_interface < 5) {
1387
 
        virXenError(VIR_ERR_NO_XEN, "%s",
1388
 
                    _("unsupported in dom interface < 5"));
 
1391
        virReportError(VIR_ERR_NO_XEN, "%s",
 
1392
                       _("unsupported in dom interface < 5"));
1389
1393
        return -1;
1390
1394
    }
1391
1395
 
1423
1427
                if (STREQ(params[i].field, VIR_DOMAIN_SCHEDULER_WEIGHT)) {
1424
1428
                    val = params[i].value.ui;
1425
1429
                    if ((val < 1) || (val > USHRT_MAX)) {
1426
 
                        virXenError(VIR_ERR_INVALID_ARG,
1427
 
                                    _("Credit scheduler weight parameter (%d) "
1428
 
                                      "is out of range (1-65535)"), val);
 
1430
                        virReportError(VIR_ERR_INVALID_ARG,
 
1431
                                       _("Credit scheduler weight parameter (%d) "
 
1432
                                         "is out of range (1-65535)"), val);
1429
1433
                        return -1;
1430
1434
                    }
1431
1435
                    op_dom.u.getschedinfo.u.credit.weight = val;
1432
1436
                } else if (STREQ(params[i].field, VIR_DOMAIN_SCHEDULER_CAP)) {
1433
1437
                    val = params[i].value.ui;
1434
1438
                    if (val >= USHRT_MAX) {
1435
 
                        virXenError(VIR_ERR_INVALID_ARG,
1436
 
                                    _("Credit scheduler cap parameter (%d) is "
1437
 
                                      "out of range (0-65534)"), val);
 
1439
                        virReportError(VIR_ERR_INVALID_ARG,
 
1440
                                       _("Credit scheduler cap parameter (%d) is "
 
1441
                                         "out of range (0-65534)"), val);
1438
1442
                        return -1;
1439
1443
                    }
1440
1444
                    op_dom.u.getschedinfo.u.credit.cap = val;
1447
1451
            break;
1448
1452
        }
1449
1453
        default:
1450
 
            virXenError(VIR_ERR_INVALID_ARG,
1451
 
                        _("Unknown scheduler %d"),
1452
 
                        op_sys.u.getschedulerid.sched_id);
 
1454
            virReportError(VIR_ERR_INVALID_ARG,
 
1455
                           _("Unknown scheduler %d"),
 
1456
                           op_sys.u.getschedulerid.sched_id);
1453
1457
            return -1;
1454
1458
        }
1455
1459
    }
1474
1478
    xenUnifiedUnlock(priv);
1475
1479
    return ret;
1476
1480
#else
1477
 
    virXenError(VIR_ERR_OPERATION_INVALID, "%s",
1478
 
                _("block statistics not supported on this platform"));
 
1481
    virReportError(VIR_ERR_OPERATION_INVALID, "%s",
 
1482
                   _("block statistics not supported on this platform"));
1479
1483
    return -1;
1480
1484
#endif
1481
1485
}
1499
1503
     * domain.
1500
1504
     */
1501
1505
    if (sscanf(path, "vif%d.%d", &rqdomid, &device) != 2) {
1502
 
        virXenError(VIR_ERR_INVALID_ARG, "%s",
1503
 
                    _("invalid path, should be vif<domid>.<n>."));
 
1506
        virReportError(VIR_ERR_INVALID_ARG, "%s",
 
1507
                       _("invalid path, should be vif<domid>.<n>."));
1504
1508
        return -1;
1505
1509
    }
1506
1510
    if (rqdomid != dom->id) {
1507
 
        virXenError(VIR_ERR_INVALID_ARG, "%s",
1508
 
                    _("invalid path, vif<domid> should match this domain ID"));
 
1511
        virReportError(VIR_ERR_INVALID_ARG, "%s",
 
1512
                       _("invalid path, vif<domid> should match this domain ID"));
1509
1513
        return -1;
1510
1514
    }
1511
1515
 
1512
1516
    return linuxDomainInterfaceStats(path, stats);
1513
1517
#else
1514
 
    virXenError(VIR_ERR_OPERATION_INVALID, "%s",
1515
 
                _("/proc/net/dev: Interface not found"));
 
1518
    virReportError(VIR_ERR_OPERATION_INVALID, "%s",
 
1519
                   _("/proc/net/dev: Interface not found"));
1516
1520
    return -1;
1517
1521
#endif
1518
1522
}
1747
1751
    if (hv_versions.hypervisor > 1) {
1748
1752
        xen_op_v2_dom op;
1749
1753
 
1750
 
        if (lock_pages(cpumap, maplen) < 0) {
1751
 
            virXenError(VIR_ERR_XEN_CALL, " locking");
 
1754
        if (lock_pages(cpumap, maplen) < 0)
1752
1755
            return -1;
1753
 
        }
 
1756
 
1754
1757
        memset(&op, 0, sizeof(op));
1755
1758
        op.cmd = XEN_V2_OP_SETVCPUMAP;
1756
1759
        op.domain = (domid_t) id;
1782
1785
        ret = xenHypervisorDoV2Dom(handle, &op);
1783
1786
        VIR_FREE(new);
1784
1787
 
1785
 
        if (unlock_pages(cpumap, maplen) < 0) {
1786
 
            virXenError(VIR_ERR_XEN_CALL, " release");
 
1788
        if (unlock_pages(cpumap, maplen) < 0)
1787
1789
            ret = -1;
1788
 
        }
1789
1790
    } else {
1790
1791
        cpumap_t xen_cpumap; /* limited to 64 CPUs in old hypervisors */
1791
1792
        uint64_t *pm = &xen_cpumap;
1879
1880
            ipt->cpu = op.u.getvcpuinfod5.online ? (int)op.u.getvcpuinfod5.cpu : -1;
1880
1881
        }
1881
1882
        if ((cpumap != NULL) && (maplen > 0)) {
1882
 
            if (lock_pages(cpumap, maplen) < 0) {
1883
 
                virXenError(VIR_ERR_XEN_CALL, " locking");
 
1883
            if (lock_pages(cpumap, maplen) < 0)
1884
1884
                return -1;
1885
 
            }
 
1885
 
1886
1886
            memset(cpumap, 0, maplen);
1887
1887
            memset(&op, 0, sizeof(op));
1888
1888
            op.cmd = XEN_V2_OP_GETVCPUMAP;
1897
1897
                op.u.getvcpumapd5.cpumap.nr_cpus = maplen * 8;
1898
1898
            }
1899
1899
            ret = xenHypervisorDoV2Dom(handle, &op);
1900
 
            if (unlock_pages(cpumap, maplen) < 0) {
1901
 
                virXenError(VIR_ERR_XEN_CALL, " release");
 
1900
            if (unlock_pages(cpumap, maplen) < 0)
1902
1901
                ret = -1;
1903
 
            }
1904
1902
        }
1905
1903
    } else {
1906
1904
        int mapl = maplen;
1981
1979
    xen_getdomaininfo info;
1982
1980
    virVcpuInfoPtr ipt = NULL;
1983
1981
 
1984
 
    if (initialized) {
1985
 
        if (hv_versions.hypervisor == -1)
1986
 
            return -1;
1987
 
        return 0;
1988
 
    }
1989
 
    initialized = 1;
1990
 
    in_init = 1;
1991
 
 
1992
1982
    /* Compile regular expressions used by xenHypervisorGetCapabilities.
1993
1983
     * Note that errors here are really internal errors since these
1994
1984
     * regexps should never fail to compile.
1998
1988
        char error[100];
1999
1989
        regerror (errcode, &flags_hvm_rec, error, sizeof(error));
2000
1990
        regfree (&flags_hvm_rec);
2001
 
        virXenError(VIR_ERR_INTERNAL_ERROR, "%s", error);
2002
 
        in_init = 0;
 
1991
        virReportError(VIR_ERR_INTERNAL_ERROR, "%s", error);
2003
1992
        return -1;
2004
1993
    }
2005
1994
    errcode = regcomp (&flags_pae_rec, flags_pae_re, REG_EXTENDED);
2008
1997
        regerror (errcode, &flags_pae_rec, error, sizeof(error));
2009
1998
        regfree (&flags_pae_rec);
2010
1999
        regfree (&flags_hvm_rec);
2011
 
        virXenError(VIR_ERR_INTERNAL_ERROR, "%s", error);
2012
 
        in_init = 0;
 
2000
        virReportError(VIR_ERR_INTERNAL_ERROR, "%s", error);
2013
2001
        return -1;
2014
2002
    }
2015
2003
    errcode = regcomp (&xen_cap_rec, xen_cap_re, REG_EXTENDED);
2019
2007
        regfree (&xen_cap_rec);
2020
2008
        regfree (&flags_pae_rec);
2021
2009
        regfree (&flags_hvm_rec);
2022
 
        virXenError(VIR_ERR_INTERNAL_ERROR, "%s", error);
2023
 
        in_init = 0;
 
2010
        virReportError(VIR_ERR_INTERNAL_ERROR, "%s", error);
2024
2011
        return -1;
2025
2012
    }
2026
2013
 
2027
2014
    if (override_versions) {
2028
2015
      hv_versions = *override_versions;
2029
 
      in_init = 0;
2030
2016
      return 0;
2031
2017
    }
2032
2018
 
2034
2020
    ret = open(XEN_HYPERVISOR_SOCKET, O_RDWR);
2035
2021
    if (ret < 0) {
2036
2022
        hv_versions.hypervisor = -1;
2037
 
        in_init = 0;
2038
 
        /* Missing socket may appear after xenfs is loaded as a module */
2039
 
        initialized = 0;
2040
2023
        return -1;
2041
2024
    }
2042
2025
    fd = ret;
2082
2065
     */
2083
2066
 
2084
2067
    hv_versions.hypervisor = -1;
2085
 
    virXenError(VIR_ERR_XEN_CALL, " ioctl %lu",
2086
 
                (unsigned long) IOCTL_PRIVCMD_HYPERCALL);
 
2068
    virReportSystemError(errno,
 
2069
                         _("Unable to issue hypervisor ioctl %lu"),
 
2070
                         (unsigned long)IOCTL_PRIVCMD_HYPERCALL);
2087
2071
    VIR_FORCE_CLOSE(fd);
2088
 
    in_init = 0;
2089
2072
    return -1;
2090
2073
 
2091
2074
 detect_v2:
2174
2157
        }
2175
2158
    }
2176
2159
 
 
2160
    /* Xen 4.2
 
2161
     * sysctl version 9 -> xen-unstable c/s 24102:dc8e55c90604
 
2162
     * domctl version 8 -> unchanged from Xen 4.1
 
2163
     */
 
2164
    hv_versions.sys_interface = 9; /* XEN_SYSCTL_INTERFACE_VERSION */
 
2165
    if (virXen_getdomaininfo(fd, 0, &info) == 1) {
 
2166
        hv_versions.dom_interface = 8; /* XEN_DOMCTL_INTERFACE_VERSION */
 
2167
        if (virXen_getvcpusinfo(fd, 0, 0, ipt, NULL, 0) == 0){
 
2168
            VIR_DEBUG("Using hypervisor call v2, sys ver9 dom ver8");
 
2169
            goto done;
 
2170
        }
 
2171
    }
 
2172
 
2177
2173
    hv_versions.hypervisor = 1;
2178
2174
    hv_versions.sys_interface = -1;
2179
2175
    if (virXen_getdomaininfo(fd, 0, &info) == 1) {
2184
2180
    /*
2185
2181
     * we failed to make the getdomaininfolist hypercall
2186
2182
     */
2187
 
 
 
2183
    hv_versions.hypervisor = -1;
 
2184
    virReportSystemError(errno,
 
2185
                         _("Unable to issue hypervisor ioctl %lu"),
 
2186
                         (unsigned long)IOCTL_PRIVCMD_HYPERCALL);
2188
2187
    VIR_DEBUG("Failed to find any Xen hypervisor method");
2189
 
    hv_versions.hypervisor = -1;
2190
 
    virXenError(VIR_ERR_XEN_CALL, " ioctl %lu",
2191
 
                (unsigned long)IOCTL_PRIVCMD_HYPERCALL);
2192
2188
    VIR_FORCE_CLOSE(fd);
2193
 
    in_init = 0;
2194
2189
    VIR_FREE(ipt);
2195
2190
    return -1;
2196
2191
 
2197
2192
 done:
2198
2193
    VIR_FORCE_CLOSE(fd);
2199
 
    in_init = 0;
2200
2194
    VIR_FREE(ipt);
2201
2195
    return 0;
2202
2196
}
2203
2197
 
 
2198
 
 
2199
static int xenHypervisorOnceInit(void) {
 
2200
    return xenHypervisorInit(NULL);
 
2201
}
 
2202
 
 
2203
VIR_ONCE_GLOBAL_INIT(xenHypervisor)
 
2204
 
2204
2205
/**
2205
2206
 * xenHypervisorOpen:
2206
2207
 * @conn: pointer to the connection block
2221
2222
 
2222
2223
    virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
2223
2224
 
2224
 
    if (initialized == 0)
2225
 
        if (xenHypervisorInit(NULL) == -1)
2226
 
            return -1;
 
2225
    if (xenHypervisorInitialize() < 0)
 
2226
        return -1;
2227
2227
 
2228
2228
    priv->handle = -1;
2229
2229
 
2230
2230
    ret = open(XEN_HYPERVISOR_SOCKET, O_RDWR);
2231
2231
    if (ret < 0) {
2232
 
        virXenError(VIR_ERR_NO_XEN, "%s", XEN_HYPERVISOR_SOCKET);
 
2232
        virReportError(VIR_ERR_NO_XEN, "%s", XEN_HYPERVISOR_SOCKET);
2233
2233
        return -1;
2234
2234
    }
2235
2235
 
2928
2928
 
2929
2929
    priv = (xenUnifiedPrivatePtr) dom->conn->privateData;
2930
2930
    if (priv->handle < 0) {
2931
 
        virXenError(VIR_ERR_INTERNAL_ERROR, "%s",
2932
 
                    _("domain shut off or invalid"));
 
2931
        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
 
2932
                       _("domain shut off or invalid"));
2933
2933
        return NULL;
2934
2934
    }
2935
2935
 
2936
2936
    /* HV's earlier than 3.1.0 don't include the HVM flags in guests status*/
2937
2937
    if (hv_versions.hypervisor < 2 ||
2938
2938
        hv_versions.dom_interface < 4) {
2939
 
        virXenError(VIR_ERR_INTERNAL_ERROR, "%s",
2940
 
                    _("unsupported in dom interface < 4"));
 
2939
        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
 
2940
                       _("unsupported in dom interface < 4"));
2941
2941
        return NULL;
2942
2942
    }
2943
2943
 
2944
2944
    XEN_GETDOMAININFO_CLEAR(dominfo);
2945
2945
 
2946
2946
    if (virXen_getdomaininfo(priv->handle, dom->id, &dominfo) < 0) {
2947
 
        virXenError(VIR_ERR_INTERNAL_ERROR, "%s",
2948
 
                    _("cannot get domain details"));
 
2947
        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
 
2948
                       _("cannot get domain details"));
2949
2949
        return NULL;
2950
2950
    }
2951
2951
 
2952
2952
    if (XEN_GETDOMAININFO_DOMAIN(dominfo) != dom->id) {
2953
 
        virXenError(VIR_ERR_INTERNAL_ERROR, "%s",
2954
 
                    _("cannot get domain details"));
 
2953
        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
 
2954
                       _("cannot get domain details"));
2955
2955
        return NULL;
2956
2956
    }
2957
2957
 
3350
3350
    xenUnifiedPrivatePtr priv;
3351
3351
 
3352
3352
    if (conn == NULL) {
3353
 
        virXenError(VIR_ERR_INVALID_ARG, "%s", _("invalid argument"));
 
3353
        virReportError(VIR_ERR_INVALID_ARG, "%s", _("invalid argument"));
3354
3354
        return -1;
3355
3355
    }
3356
3356
 
3357
3357
    priv = conn->privateData;
3358
3358
 
3359
3359
    if (priv->nbNodeCells < 0) {
3360
 
        virXenError(VIR_ERR_XEN_CALL, "%s",
3361
 
                    _("cannot determine actual number of cells"));
 
3360
        virReportError(VIR_ERR_XEN_CALL, "%s",
 
3361
                       _("cannot determine actual number of cells"));
3362
3362
        return -1;
3363
3363
    }
3364
3364
 
3365
3365
    if ((maxCells < 1) || (startCell >= priv->nbNodeCells)) {
3366
 
        virXenError(VIR_ERR_INVALID_ARG, "%s",
3367
 
                    _("invalid argument"));
 
3366
        virReportError(VIR_ERR_INVALID_ARG, "%s",
 
3367
                       _("invalid argument"));
3368
3368
        return -1;
3369
3369
    }
3370
3370
 
3372
3372
     * Support only hv_versions.sys_interface >=4
3373
3373
     */
3374
3374
    if (hv_versions.sys_interface < SYS_IFACE_MIN_VERS_NUMA) {
3375
 
        virXenError(VIR_ERR_XEN_CALL, "%s",
3376
 
                    _("unsupported in sys interface < 4"));
 
3375
        virReportError(VIR_ERR_XEN_CALL, "%s",
 
3376
                       _("unsupported in sys interface < 4"));
3377
3377
        return -1;
3378
3378
    }
3379
3379
 
3380
3380
    if (priv->handle < 0) {
3381
 
        virXenError(VIR_ERR_INTERNAL_ERROR, "%s",
3382
 
                    _("priv->handle invalid"));
 
3381
        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
 
3382
                       _("priv->handle invalid"));
3383
3383
        return -1;
3384
3384
    }
3385
3385
 
3620
3620
    if (priv->handle < 0 || (domain->id < 0) ||
3621
3621
        (info == NULL) || (maxinfo < 1) ||
3622
3622
        (sizeof(cpumap_t) & 7)) {
3623
 
        virXenError(VIR_ERR_INTERNAL_ERROR, "%s",
3624
 
                    _("domain shut off or invalid"));
 
3623
        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
 
3624
                       _("domain shut off or invalid"));
3625
3625
        return -1;
3626
3626
    }
3627
3627
    if ((cpumaps != NULL) && (maplen < 1)) {
3628
 
        virXenError(VIR_ERR_INVALID_ARG, "%s",
3629
 
                    _("invalid argument"));
 
3628
        virReportError(VIR_ERR_INVALID_ARG, "%s",
 
3629
                       _("invalid argument"));
3630
3630
        return -1;
3631
3631
    }
3632
3632
    /* first get the number of virtual CPUs in this domain */
3635
3635
                               &dominfo);
3636
3636
 
3637
3637
    if ((ret < 0) || (XEN_GETDOMAININFO_DOMAIN(dominfo) != domain->id)) {
3638
 
        virXenError(VIR_ERR_INTERNAL_ERROR, "%s",
3639
 
                    _("cannot get domain details"));
 
3638
        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
 
3639
                       _("cannot get domain details"));
3640
3640
        return -1;
3641
3641
    }
3642
3642
    nbinfo = XEN_GETDOMAININFO_CPUCOUNT(dominfo) + 1;
3652
3652
                                      (unsigned char *)VIR_GET_CPUMAP(cpumaps, maplen, i),
3653
3653
                                      maplen);
3654
3654
            if (ret < 0) {
3655
 
                virXenError(VIR_ERR_INTERNAL_ERROR, "%s",
3656
 
                            _("cannot get VCPUs info"));
 
3655
                virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
 
3656
                               _("cannot get VCPUs info"));
3657
3657
                return -1;
3658
3658
            }
3659
3659
        } else {
3660
3660
            ret = virXen_getvcpusinfo(priv->handle, domain->id, i,
3661
3661
                                      ipt, NULL, 0);
3662
3662
            if (ret < 0) {
3663
 
                virXenError(VIR_ERR_INTERNAL_ERROR, "%s",
3664
 
                            _("cannot get VCPUs info"));
 
3663
                virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
 
3664
                               _("cannot get VCPUs info"));
3665
3665
                return -1;
3666
3666
            }
3667
3667
        }