~serge-hallyn/ubuntu/raring/libvirt/libvirt-hugepages

« back to all changes in this revision

Viewing changes to src/libvirt.c

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-05-13 15:44:12 UTC
  • mfrom: (1.2.13)
  • Revision ID: package-import@ubuntu.com-20120513154412-fgmn5sxqdzgnzlx3
Tags: 0.9.12-0ubuntu1
* New upstream version:
  * Synchronize with debian packaging:
    - debian/control: Update build depends.
    - debian/libvirt-bin.postrm: Cleanup /var/log/libvirt
      on purge.
    - Bump standards verson (no changes).
    - debian/patches/Don-t-fail-if-we-can-t-setup-avahi.patch: Added
  * Dropped patches:
    - debian/patches/Debianize-libvirt-guests.patch
    - debian/patches/rewrite-lxc-controller-eof-handling-yet-again
    - debian/patches/ubuntu/libnl13.patch
    - debian/patches/ubuntu/fix-lxc-startup-error.patch
    - debian/patches/ubuntu/fix-bridge-fd.patch
    - debian/patches/ubuntu/skip-labelling-network-disks.patch
    - debian/patches/ubuntu/xen-xend-shutdown-detection.patch
    - debian/patches/ubuntu/xen-config-no-vfb-for-hvm.patch
    - debian/patches/debian/Disable-daemon-start-test.patch
    - debian/patches/debian/Disable-gnulib-s-test-nonplocking-pipe.sh.patch
    - debian/patches/ubuntu/9006-default-config-test-case.patch
    - debian/patches/fix-block-migration.patch
    - debian/patches/ubuntu/9022-qemu-unescape-HMP-commands-before-converting-them-to.patch
    - debian/patches/ubuntu/9023-qemu-change-rbd-auth_supported-separation-character-.patch
    - debian/patches/ubuntu/9024-qemu-allow-snapshotting-of-sheepdog-and-rbd-disks.patch
    - debian/patches/9025-qemu-change-rbd-auth_supported-separation-character-.patch
    - debian/patches/ubuntu/arm-gcc-workaround.patch
  * Rediffed:
    - debian/patches/Allow-libvirt-group-to-access-the-socket.patch
    - debian/patches/Disable-failing-virnetsockettest.patch
    - debian/patches/dnsmasq-as-priv-user
    - debian/patches/9002-better_default_uri_virsh.patch
  * debian/control: Add libnl-route-3-dev ass a build depends.
  * debian/patches/libnl3-build-fix.patch: Fix build with libnl3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * libvirt.c: Main interfaces for the libvirt library to handle virtualization
3
3
 *           domains from a process running in domain 0
4
4
 *
5
 
 * Copyright (C) 2005-2006, 2008-2011 Red Hat, Inc.
 
5
 * Copyright (C) 2005-2006, 2008-2012 Red Hat, Inc.
6
6
 *
7
7
 * See COPYING.LIB for the License of this software
8
8
 *
23
23
 
24
24
#include <libxml/parser.h>
25
25
#include <libxml/xpath.h>
26
 
#include <libxml/uri.h>
27
26
#include "getpass.h"
28
27
 
29
28
#ifdef HAVE_WINSOCK2_H
36
35
#include "driver.h"
37
36
 
38
37
#include "uuid.h"
39
 
#include "util.h"
40
38
#include "memory.h"
41
39
#include "configmake.h"
42
40
#include "intprops.h"
44
42
#include "rpc/virnettlscontext.h"
45
43
#include "command.h"
46
44
#include "virnodesuspend.h"
 
45
#include "virrandom.h"
 
46
#include "viruri.h"
47
47
 
48
48
#ifndef WITH_DRIVER_MODULES
49
49
# ifdef WITH_TEST
119
119
 
120
120
    cmd = virCommandNewArgList(POLKIT_AUTH, "--obtain", privilege, NULL);
121
121
    if (virCommandRun(cmd, &status) < 0 ||
122
 
        status > 1)
 
122
        status > 0)
123
123
        goto cleanup;
124
124
 
125
125
    ret = 0;
961
961
}
962
962
 
963
963
static char *
964
 
virConnectConfigFile(void)
 
964
virConnectGetConfigFilePath(void)
965
965
{
966
966
    char *path;
967
967
    if (geteuid() == 0) {
989
989
    return NULL;
990
990
}
991
991
 
 
992
static int
 
993
virConnectGetConfigFile(virConfPtr *conf)
 
994
{
 
995
    char *filename = NULL;
 
996
    int ret = -1;
 
997
 
 
998
    *conf = NULL;
 
999
 
 
1000
    if (!(filename = virConnectGetConfigFilePath()))
 
1001
        goto cleanup;
 
1002
 
 
1003
    if (!virFileExists(filename)) {
 
1004
        ret = 0;
 
1005
        goto cleanup;
 
1006
    }
 
1007
 
 
1008
    VIR_DEBUG("Loading config file '%s'", filename);
 
1009
    if (!(*conf = virConfReadFile(filename, 0)))
 
1010
        goto cleanup;
 
1011
 
 
1012
    ret = 0;
 
1013
 
 
1014
cleanup:
 
1015
    VIR_FREE(filename);
 
1016
    return ret;
 
1017
}
 
1018
 
992
1019
#define URI_ALIAS_CHARS "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-"
993
1020
 
994
1021
static int
1025
1052
        safe  = strspn(entry->str, URI_ALIAS_CHARS);
1026
1053
        if (safe < (offset - entry->str)) {
1027
1054
            virLibConnError(VIR_ERR_CONF_SYNTAX,
1028
 
                            _("Malformed 'uri_aliases' config entry '%s', aliases may only container 'a-Z, 0-9, _, -'"),
 
1055
                            _("Malformed 'uri_aliases' config entry '%s', aliases may only contain 'a-Z, 0-9, _, -'"),
1029
1056
                            entry->str);
1030
1057
            return -1;
1031
1058
        }
1050
1077
}
1051
1078
 
1052
1079
static int
1053
 
virConnectOpenResolveURIAlias(const char *alias, char **uri)
 
1080
virConnectOpenResolveURIAlias(virConfPtr conf,
 
1081
                              const char *alias, char **uri)
1054
1082
{
1055
 
    char *config = NULL;
1056
1083
    int ret = -1;
1057
 
    virConfPtr conf = NULL;
1058
1084
    virConfValuePtr value = NULL;
1059
1085
 
1060
1086
    *uri = NULL;
1061
1087
 
1062
 
    if (!(config = virConnectConfigFile()))
1063
 
        goto cleanup;
1064
 
 
1065
 
    if (!virFileExists(config)) {
1066
 
        ret = 0;
1067
 
        goto cleanup;
1068
 
    }
1069
 
 
1070
 
    VIR_DEBUG("Loading config file '%s'", config);
1071
 
    if (!(conf = virConfReadFile(config, 0)))
1072
 
        goto cleanup;
1073
 
 
1074
1088
    if ((value = virConfGetValue(conf, "uri_aliases")))
1075
1089
        ret = virConnectOpenFindURIAliasMatch(value, alias, uri);
1076
1090
    else
1077
1091
        ret = 0;
1078
1092
 
 
1093
    return ret;
 
1094
}
 
1095
 
 
1096
 
 
1097
static int
 
1098
virConnectGetDefaultURI(virConfPtr conf,
 
1099
                        const char **name)
 
1100
{
 
1101
    int ret = -1;
 
1102
    virConfValuePtr value = NULL;
 
1103
    char *defname = getenv("LIBVIRT_DEFAULT_URI");
 
1104
    if (defname && *defname) {
 
1105
        VIR_DEBUG("Using LIBVIRT_DEFAULT_URI '%s'", defname);
 
1106
        *name = defname;
 
1107
    } else if ((value = virConfGetValue(conf, "uri_default"))) {
 
1108
        if (value->type != VIR_CONF_STRING) {
 
1109
            virLibConnError(VIR_ERR_INTERNAL_ERROR, "%s",
 
1110
                            _("Expected a string for 'uri_default' config parameter"));
 
1111
            goto cleanup;
 
1112
        }
 
1113
        VIR_DEBUG("Using config file uri '%s'", value->str);
 
1114
        *name = value->str;
 
1115
    }
 
1116
 
 
1117
    ret = 0;
1079
1118
cleanup:
1080
 
    virConfFree(conf);
1081
 
    VIR_FREE(config);
1082
1119
    return ret;
1083
1120
}
1084
1121
 
1089
1126
{
1090
1127
    int i, res;
1091
1128
    virConnectPtr ret;
 
1129
    virConfPtr conf = NULL;
1092
1130
 
1093
1131
    virResetLastError();
1094
1132
 
1096
1134
    if (ret == NULL)
1097
1135
        return NULL;
1098
1136
 
 
1137
    if (virConnectGetConfigFile(&conf) < 0)
 
1138
        goto failed;
 
1139
 
 
1140
    if (name && name[0] == '\0')
 
1141
        name = NULL;
 
1142
 
1099
1143
    /*
1100
1144
     *  If no URI is passed, then check for an environment string if not
1101
1145
     *  available probe the compiled in drivers to find a default hypervisor
1102
1146
     *  if detectable.
1103
1147
     */
1104
 
    if (!name || name[0] == '\0') {
1105
 
        char *defname = getenv("LIBVIRT_DEFAULT_URI");
1106
 
        if (defname && *defname) {
1107
 
            VIR_DEBUG("Using LIBVIRT_DEFAULT_URI %s", defname);
1108
 
            name = defname;
1109
 
        } else {
1110
 
            name = NULL;
1111
 
        }
1112
 
    }
 
1148
    if (!name &&
 
1149
        virConnectGetDefaultURI(conf, &name) < 0)
 
1150
        goto failed;
1113
1151
 
1114
1152
    if (name) {
1115
1153
        char *alias = NULL;
1124
1162
            name = "xen:///";
1125
1163
 
1126
1164
        if (!(flags & VIR_CONNECT_NO_ALIASES) &&
1127
 
            virConnectOpenResolveURIAlias(name, &alias) < 0)
 
1165
            virConnectOpenResolveURIAlias(conf, name, &alias) < 0)
1128
1166
            goto failed;
1129
1167
 
1130
 
        ret->uri = xmlParseURI (alias ? alias : name);
1131
 
        if (!ret->uri) {
1132
 
            virLibConnError(VIR_ERR_INVALID_ARG,
1133
 
                            _("could not parse connection URI %s"),
1134
 
                            alias ? alias : name);
 
1168
        if (!(ret->uri = virURIParse (alias ? alias : name))) {
1135
1169
            VIR_FREE(alias);
1136
1170
            goto failed;
1137
1171
        }
1138
1172
 
1139
1173
        VIR_DEBUG("name \"%s\" to URI components:\n"
1140
1174
                  "  scheme %s\n"
1141
 
                  "  opaque %s\n"
1142
 
                  "  authority %s\n"
1143
1175
                  "  server %s\n"
1144
1176
                  "  user %s\n"
1145
1177
                  "  port %d\n"
1146
1178
                  "  path %s\n",
1147
1179
                  alias ? alias : name,
1148
 
                  NULLSTR(ret->uri->scheme), NULLSTR(ret->uri->opaque),
1149
 
                  NULLSTR(ret->uri->authority), NULLSTR(ret->uri->server),
 
1180
                  NULLSTR(ret->uri->scheme), NULLSTR(ret->uri->server),
1150
1181
                  NULLSTR(ret->uri->user), ret->uri->port,
1151
1182
                  NULLSTR(ret->uri->path));
1152
1183
 
1308
1339
        }
1309
1340
    }
1310
1341
 
 
1342
    virConfFree(conf);
 
1343
 
1311
1344
    return ret;
1312
1345
 
1313
1346
failed:
 
1347
    virConfFree(conf);
1314
1348
    virUnrefConnect(ret);
1315
1349
 
1316
1350
    return NULL;
1325
1359
 *
1326
1360
 * Returns a pointer to the hypervisor connection or NULL in case of error
1327
1361
 *
1328
 
 * If @name is NULL then probing will be done to determine a suitable
1329
 
 * default driver to activate. This involves trying each hypervisor
1330
 
 * in turn until one successfully opens. If the LIBVIRT_DEFAULT_URI
1331
 
 * environment variable is set, then it will be used in preference
1332
 
 * to probing for a driver.
 
1362
 * If @name is NULL, if the LIBVIRT_DEFAULT_URI environment variable is set,
 
1363
 * then it will be used. Otherwise if the client configuration file
 
1364
 * has the "uri_default" parameter set, then it will be used. Finally
 
1365
 * probing will be done to determine a suitable default driver to activate.
 
1366
 * This involves trying each hypervisor in turn until one successfully opens.
1333
1367
 *
1334
1368
 * If connecting to an unprivileged hypervisor driver which requires
1335
1369
 * the libvirtd daemon to be active, it will automatically be launched
1395
1429
 * virConnectOpenAuth:
1396
1430
 * @name: URI of the hypervisor
1397
1431
 * @auth: Authenticate callback parameters
1398
 
 * @flags: Open flags
 
1432
 * @flags: bitwise-OR of virConnectFlags
1399
1433
 *
1400
1434
 * This function should be called first to get a connection to the
1401
1435
 * Hypervisor. If necessary, authentication will be performed fetching
1729
1763
        return NULL;
1730
1764
    }
1731
1765
 
1732
 
    name = (char *)xmlSaveUri(conn->uri);
1733
 
    if (!name) {
1734
 
        virReportOOMError();
 
1766
    if (!(name = virURIFormat(conn->uri)))
1735
1767
        goto error;
1736
 
    }
 
1768
 
1737
1769
    return name;
1738
1770
 
1739
1771
error:
1744
1776
/**
1745
1777
 * virConnectGetSysinfo:
1746
1778
 * @conn: pointer to a hypervisor connection
1747
 
 * @flags: callers should always pass 0
 
1779
 * @flags: extra flags; not used yet, so callers should always pass 0
1748
1780
 *
1749
1781
 * This returns the XML description of the sysinfo details for the
1750
1782
 * host on which the hypervisor is running, in the same format as the
1825
1857
 * @ids: array to collect the list of IDs of active domains
1826
1858
 * @maxids: size of @ids
1827
1859
 *
1828
 
 * Collect the list of active domains, and store their ID in @maxids
 
1860
 * Collect the list of active domains, and store their IDs in array @ids
1829
1861
 *
1830
 
 * Returns the number of domain found or -1 in case of error
 
1862
 * Returns the number of domains found or -1 in case of error
1831
1863
 */
1832
1864
int
1833
1865
virConnectListDomains(virConnectPtr conn, int *ids, int maxids)
1927
1959
 * virDomainCreateXML:
1928
1960
 * @conn: pointer to the hypervisor connection
1929
1961
 * @xmlDesc: string containing an XML description of the domain
1930
 
 * @flags: bitwise-or of supported virDomainCreateFlags
 
1962
 * @flags: bitwise-OR of supported virDomainCreateFlags
1931
1963
 *
1932
1964
 * Launch a new guest domain, based on an XML description similar
1933
1965
 * to the one returned by virDomainGetXMLDesc()
1989
2021
 * virDomainCreateLinux:
1990
2022
 * @conn: pointer to the hypervisor connection
1991
2023
 * @xmlDesc: string containing an XML description of the domain
1992
 
 * @flags: callers should always pass 0
 
2024
 * @flags: extra flags; not used yet, so callers should always pass 0
1993
2025
 *
1994
2026
 * Deprecated after 0.4.6.
1995
2027
 * Renamed to virDomainCreateXML() providing identical functionality.
2181
2213
 * does not free the associated virDomainPtr object.
2182
2214
 * This function may require privileged access
2183
2215
 *
 
2216
 * virDomainDestroy first requests that a guest terminate
 
2217
 * (e.g. SIGTERM), then waits for it to comply. After a reasonable
 
2218
 * timeout, if the guest still exists, virDomainDestory will
 
2219
 * forcefully terminate the guest (e.g. SIGKILL) if necessary (which
 
2220
 * may produce undesirable results, for example unflushed disk cache
 
2221
 * in the guest). To avoid this possibility, it's recommended to
 
2222
 * instead call virDomainDestroyFlags, sending the
 
2223
 * VIR_DOMAIN_DESTROY_GRACEFUL flag.
 
2224
 *
2184
2225
 * If the domain is transient and has any snapshot metadata (see
2185
2226
 * virDomainSnapshotNum()), then that metadata will automatically
2186
2227
 * be deleted when the domain quits.
2226
2267
/**
2227
2268
 * virDomainDestroyFlags:
2228
2269
 * @domain: a domain object
2229
 
 * @flags: an OR'ed set of virDomainDestroyFlagsValues
 
2270
 * @flags: bitwise-OR of virDomainDestroyFlagsValues
2230
2271
 *
2231
2272
 * Destroy the domain object. The running instance is shutdown if not down
2232
2273
 * already and all resources used by it are given back to the hypervisor.
2233
2274
 * This does not free the associated virDomainPtr object.
2234
2275
 * This function may require privileged access.
2235
2276
 *
2236
 
 * Calling this function with no @flags set (equal to zero)
2237
 
 * is equivalent to calling virDomainDestroy.  Using virDomainShutdown()
2238
 
 * may produce cleaner results for the guest's disks, but depends on guest
2239
 
 * support.
 
2277
 * Calling this function with no @flags set (equal to zero) is
 
2278
 * equivalent to calling virDomainDestroy, and after a reasonable
 
2279
 * timeout will forcefully terminate the guest (e.g. SIGKILL) if
 
2280
 * necessary (which may produce undesirable results, for example
 
2281
 * unflushed disk cache in the guest). Including
 
2282
 * VIR_DOMAIN_DESTROY_GRACEFUL in the flags will prevent the forceful
 
2283
 * termination of the guest, and virDomainDestroyFlags will instead
 
2284
 * return an error if the guest doesn't terminate by the end of the
 
2285
 * timeout; at that time, the management application can decide if
 
2286
 * calling again without VIR_DOMAIN_DESTROY_GRACEFUL is appropriate.
 
2287
 *
 
2288
 * Another alternative which may produce cleaner results for the
 
2289
 * guest's disks is to use virDomainShutdown() instead, but that
 
2290
 * depends on guest support (some hypervisor/guest combinations may
 
2291
 * ignore the shutdown request).
 
2292
 *
2240
2293
 *
2241
2294
 * Returns 0 in case of success and -1 in case of failure.
2242
2295
 */
2433
2486
}
2434
2487
 
2435
2488
/**
 
2489
 * virDomainPMSuspendForDuration:
 
2490
 * @dom: a domain object
 
2491
 * @target: a value from virNodeSuspendTarget
 
2492
 * @duration: duration in seconds to suspend, or 0 for indefinite
 
2493
 * @flags: extra flags; not used yet, so callers should always pass 0
 
2494
 *
 
2495
 * Attempt to have the guest enter the given @target power management
 
2496
 * suspension level.  If @duration is non-zero, also schedule the guest to
 
2497
 * resume normal operation after that many seconds, if nothing else has
 
2498
 * resumed it earlier.  Some hypervisors require that @duration be 0, for
 
2499
 * an indefinite suspension.
 
2500
 *
 
2501
 * Dependent on hypervisor used, this may require a
 
2502
 * guest agent to be available, e.g. QEMU.
 
2503
 *
 
2504
 * Returns: 0 on success,
 
2505
 *          -1 on failure.
 
2506
 */
 
2507
int
 
2508
virDomainPMSuspendForDuration(virDomainPtr dom,
 
2509
                              unsigned int target,
 
2510
                              unsigned long long duration,
 
2511
                              unsigned int flags)
 
2512
{
 
2513
    virConnectPtr conn;
 
2514
 
 
2515
    VIR_DOMAIN_DEBUG(dom, "target=%u duration=%llu flags=%x",
 
2516
                     target, duration, flags);
 
2517
 
 
2518
    virResetLastError();
 
2519
 
 
2520
    if (!VIR_IS_CONNECTED_DOMAIN(dom)) {
 
2521
        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
 
2522
        virDispatchError(NULL);
 
2523
        return -1;
 
2524
    }
 
2525
 
 
2526
    conn = dom->conn;
 
2527
 
 
2528
    if (conn->flags & VIR_CONNECT_RO) {
 
2529
        virLibConnError(VIR_ERR_OPERATION_DENIED, __FUNCTION__);
 
2530
        goto error;
 
2531
    }
 
2532
 
 
2533
    if (conn->driver->domainPMSuspendForDuration) {
 
2534
        int ret;
 
2535
        ret = conn->driver->domainPMSuspendForDuration(dom, target,
 
2536
                                                       duration, flags);
 
2537
        if (ret < 0)
 
2538
            goto error;
 
2539
        return ret;
 
2540
    }
 
2541
 
 
2542
    virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
 
2543
 
 
2544
error:
 
2545
    virDispatchError(conn);
 
2546
    return -1;
 
2547
}
 
2548
 
 
2549
/**
 
2550
 * virDomainPMWakeup:
 
2551
 * @dom: a domain object
 
2552
 * @flags: extra flags; not used yet, so callers should always pass 0
 
2553
 *
 
2554
 * Inject a wakeup into the guest that previously used
 
2555
 * virDomainPMSuspendForDuration, rather than waiting for the
 
2556
 * previously requested duration (if any) to elapse.
 
2557
 *
 
2558
 * Returns: 0 on success,
 
2559
 *          -1 on failure.
 
2560
 */
 
2561
int
 
2562
virDomainPMWakeup(virDomainPtr dom,
 
2563
                  unsigned int flags)
 
2564
{
 
2565
    virConnectPtr conn;
 
2566
 
 
2567
    VIR_DOMAIN_DEBUG(dom, "flags=%x", flags);
 
2568
 
 
2569
    virResetLastError();
 
2570
 
 
2571
    if (!VIR_IS_CONNECTED_DOMAIN(dom)) {
 
2572
        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
 
2573
        virDispatchError(NULL);
 
2574
        return -1;
 
2575
    }
 
2576
 
 
2577
    conn = dom->conn;
 
2578
 
 
2579
    if (conn->flags & VIR_CONNECT_RO) {
 
2580
        virLibConnError(VIR_ERR_OPERATION_DENIED, __FUNCTION__);
 
2581
        goto error;
 
2582
    }
 
2583
 
 
2584
    if (conn->driver->domainPMWakeup) {
 
2585
        int ret;
 
2586
        ret = conn->driver->domainPMWakeup(dom, flags);
 
2587
        if (ret < 0)
 
2588
            goto error;
 
2589
        return ret;
 
2590
    }
 
2591
 
 
2592
    virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
 
2593
 
 
2594
error:
 
2595
    virDispatchError(conn);
 
2596
    return -1;
 
2597
}
 
2598
 
 
2599
/**
2436
2600
 * virDomainSave:
2437
2601
 * @domain: a domain object
2438
2602
 * @to: path for the output file
2532
2696
 * A save file can be inspected or modified slightly with
2533
2697
 * virDomainSaveImageGetXMLDesc() and virDomainSaveImageDefineXML().
2534
2698
 *
 
2699
 * Some hypervisors may prevent this operation if there is a current
 
2700
 * block copy operation; in that case, use virDomainBlockJobAbort()
 
2701
 * to stop the block copy first.
 
2702
 *
2535
2703
 * Returns 0 in case of success and -1 in case of failure.
2536
2704
 */
2537
2705
int
2896
3064
 * virDomainCoreDump:
2897
3065
 * @domain: a domain object
2898
3066
 * @to: path for the core file
2899
 
 * @flags: an OR'ed set of virDomainCoreDumpFlags
 
3067
 * @flags: bitwise-OR of virDomainCoreDumpFlags
2900
3068
 *
2901
3069
 * This method will dump the core of a domain on a given file for analysis.
2902
3070
 * Note that for remote Xen Daemon the file path will be interpreted in
2991
3159
 * @domain: a domain object
2992
3160
 * @stream: stream to use as output
2993
3161
 * @screen: monitor ID to take screenshot from
2994
 
 * @flags: extra flags, currently unused
 
3162
 * @flags: extra flags; not used yet, so callers should always pass 0
2995
3163
 *
2996
3164
 * Take a screenshot of current domain console as a stream. The image format
2997
3165
 * is hypervisor specific. Moreover, some hypervisors supports multiple
3106
3274
}
3107
3275
 
3108
3276
/**
 
3277
 * virDomainShutdownFlags:
 
3278
 * @domain: a domain object
 
3279
 * @flags: bitwise-OR of virDomainShutdownFlagValues
 
3280
 *
 
3281
 * Shutdown a domain, the domain object is still usable thereafter but
 
3282
 * the domain OS is being stopped. Note that the guest OS may ignore the
 
3283
 * request.  For guests that react to a shutdown request, the differences
 
3284
 * from virDomainDestroy() are that the guest's disk storage will be in a
 
3285
 * stable state rather than having the (virtual) power cord pulled, and
 
3286
 * this command returns as soon as the shutdown request is issued rather
 
3287
 * than blocking until the guest is no longer running.
 
3288
 *
 
3289
 * If the domain is transient and has any snapshot metadata (see
 
3290
 * virDomainSnapshotNum()), then that metadata will automatically
 
3291
 * be deleted when the domain quits.
 
3292
 *
 
3293
 * If @flags is set to zero, then the hypervisor will choose the
 
3294
 * method of shutdown it considers best. To have greater control
 
3295
 * pass exactly one of the virDomainShutdownFlagValues.
 
3296
 *
 
3297
 * Returns 0 in case of success and -1 in case of failure.
 
3298
 */
 
3299
int
 
3300
virDomainShutdownFlags(virDomainPtr domain, unsigned int flags)
 
3301
{
 
3302
    virConnectPtr conn;
 
3303
 
 
3304
    VIR_DOMAIN_DEBUG(domain);
 
3305
 
 
3306
    virResetLastError();
 
3307
 
 
3308
    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
 
3309
        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
 
3310
        virDispatchError(NULL);
 
3311
        return -1;
 
3312
    }
 
3313
    if (domain->conn->flags & VIR_CONNECT_RO) {
 
3314
        virLibDomainError(VIR_ERR_OPERATION_DENIED, __FUNCTION__);
 
3315
        goto error;
 
3316
    }
 
3317
 
 
3318
    /* At most one of these two flags should be set.  */
 
3319
    if ((flags & VIR_DOMAIN_SHUTDOWN_ACPI_POWER_BTN) &&
 
3320
        (flags & VIR_DOMAIN_SHUTDOWN_GUEST_AGENT)) {
 
3321
        virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
 
3322
        goto error;
 
3323
    }
 
3324
 
 
3325
    conn = domain->conn;
 
3326
 
 
3327
    if (conn->driver->domainShutdownFlags) {
 
3328
        int ret;
 
3329
        ret = conn->driver->domainShutdownFlags(domain, flags);
 
3330
        if (ret < 0)
 
3331
            goto error;
 
3332
        return ret;
 
3333
    }
 
3334
 
 
3335
    virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
 
3336
 
 
3337
error:
 
3338
    virDispatchError(domain->conn);
 
3339
    return -1;
 
3340
}
 
3341
 
 
3342
/**
3109
3343
 * virDomainReboot:
3110
3344
 * @domain: a domain object
3111
 
 * @flags: extra flags for the reboot operation, not used yet
 
3345
 * @flags: bitwise-OR of virDomainRebootFlagValues
3112
3346
 *
3113
3347
 * Reboot a domain, the domain object is still usable there after but
3114
3348
 * the domain OS is being stopped for a restart.
3115
3349
 * Note that the guest OS may ignore the request.
3116
3350
 *
 
3351
 * If @flags is set to zero, then the hypervisor will choose the
 
3352
 * method of shutdown it considers best. To have greater control
 
3353
 * pass exactly one of the virDomainRebootFlagValues.
 
3354
 *
 
3355
 * To use guest agent (VIR_DOMAIN_REBOOT_GUEST_AGENT) the domain XML
 
3356
 * must have <channel> configured.
 
3357
 *
3117
3358
 * Returns 0 in case of success and -1 in case of failure.
3118
3359
 */
3119
3360
int
3135
3376
        goto error;
3136
3377
    }
3137
3378
 
 
3379
    /* At most one of these two flags should be set.  */
 
3380
    if ((flags & VIR_DOMAIN_SHUTDOWN_ACPI_POWER_BTN) &&
 
3381
        (flags & VIR_DOMAIN_SHUTDOWN_GUEST_AGENT)) {
 
3382
        virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
 
3383
        goto error;
 
3384
    }
 
3385
 
3138
3386
    conn = domain->conn;
3139
3387
 
3140
3388
    if (conn->driver->domainReboot) {
3155
3403
/**
3156
3404
 * virDomainReset:
3157
3405
 * @domain: a domain object
3158
 
 * @flags: extra flags for the reboot operation, not used yet
 
3406
 * @flags: extra flags; not used yet, so callers should always pass 0
3159
3407
 *
3160
3408
 * Reset a domain immediately without any guest OS shutdown.
3161
3409
 * Reset emulates the power reset button on a machine, where all
3370
3618
 * domain. If domain is NULL, then this get the amount of memory reserved
3371
3619
 * to Domain0 i.e. the domain where the application runs.
3372
3620
 *
3373
 
 * Returns the memory size in kilobytes or 0 in case of error.
 
3621
 * Returns the memory size in kibibytes (blocks of 1024 bytes), or 0 in
 
3622
 * case of error.
3374
3623
 */
3375
3624
unsigned long
3376
3625
virDomainGetMaxMemory(virDomainPtr domain)
3390
3639
    conn = domain->conn;
3391
3640
 
3392
3641
    if (conn->driver->domainGetMaxMemory) {
3393
 
        unsigned long ret;
 
3642
        unsigned long long ret;
3394
3643
        ret = conn->driver->domainGetMaxMemory (domain);
3395
3644
        if (ret == 0)
3396
3645
            goto error;
 
3646
        if ((unsigned long) ret != ret) {
 
3647
            virLibDomainError(VIR_ERR_OVERFLOW, _("result too large: %llu"),
 
3648
                              ret);
 
3649
            goto error;
 
3650
        }
3397
3651
        return ret;
3398
3652
    }
3399
3653
 
3407
3661
/**
3408
3662
 * virDomainSetMaxMemory:
3409
3663
 * @domain: a domain object or NULL
3410
 
 * @memory: the memory size in kilobytes
 
3664
 * @memory: the memory size in kibibytes (blocks of 1024 bytes)
3411
3665
 *
3412
3666
 * Dynamically change the maximum amount of physical memory allocated to a
3413
3667
 * domain. If domain is NULL, then this change the amount of memory reserved
3462
3716
/**
3463
3717
 * virDomainSetMemory:
3464
3718
 * @domain: a domain object or NULL
3465
 
 * @memory: the memory size in kilobytes
 
3719
 * @memory: the memory size in kibibytes (blocks of 1024 bytes)
3466
3720
 *
3467
3721
 * Dynamically change the target amount of physical memory allocated to a
3468
3722
 * domain. If domain is NULL, then this change the amount of memory reserved
3514
3768
    return -1;
3515
3769
}
3516
3770
 
3517
 
/*
 
3771
/**
3518
3772
 * virDomainSetMemoryFlags:
3519
3773
 * @domain: a domain object or NULL
3520
 
 * @memory: the memory size in kilobytes
3521
 
 * @flags: an OR'ed set of virDomainMemoryModFlags
 
3774
 * @memory: the memory size in kibibytes (blocks of 1024 bytes)
 
3775
 * @flags: bitwise-OR of virDomainMemoryModFlags
3522
3776
 *
3523
3777
 * Dynamically change the target amount of physical memory allocated to a
3524
3778
 * domain. If domain is NULL, then this change the amount of memory reserved
3769
4023
}
3770
4024
 
3771
4025
/**
 
4026
 * virDomainSetNumaParameters:
 
4027
 * @domain: pointer to domain object
 
4028
 * @params: pointer to numa parameter objects
 
4029
 * @nparams: number of numa parameters (this value can be the same or
 
4030
 *          less than the number of parameters supported)
 
4031
 * @flags: bitwise-OR of virDomainModificationImpact
 
4032
 *
 
4033
 * Change all or a subset of the numa tunables.
 
4034
 * This function may require privileged access to the hypervisor.
 
4035
 *
 
4036
 * Returns -1 in case of error, 0 in case of success.
 
4037
 */
 
4038
int
 
4039
virDomainSetNumaParameters(virDomainPtr domain,
 
4040
                           virTypedParameterPtr params,
 
4041
                           int nparams, unsigned int flags)
 
4042
{
 
4043
    virConnectPtr conn;
 
4044
 
 
4045
    VIR_DOMAIN_DEBUG(domain, "params=%p, nparams=%d, flags=%x",
 
4046
                     params, nparams, flags);
 
4047
 
 
4048
    virResetLastError();
 
4049
 
 
4050
    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
 
4051
        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
 
4052
        virDispatchError(NULL);
 
4053
        return -1;
 
4054
    }
 
4055
    if (domain->conn->flags & VIR_CONNECT_RO) {
 
4056
        virLibDomainError(VIR_ERR_OPERATION_DENIED, __FUNCTION__);
 
4057
        goto error;
 
4058
    }
 
4059
    if ((nparams <= 0) || (params == NULL)) {
 
4060
        virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
 
4061
        goto error;
 
4062
    }
 
4063
    if (virTypedParameterValidateSet(domain, params, nparams) < 0)
 
4064
        return -1;
 
4065
 
 
4066
    conn = domain->conn;
 
4067
 
 
4068
    if (conn->driver->domainSetNumaParameters) {
 
4069
        int ret;
 
4070
        ret = conn->driver->domainSetNumaParameters(domain, params, nparams,
 
4071
                                                    flags);
 
4072
        if (ret < 0)
 
4073
            goto error;
 
4074
        return ret;
 
4075
    }
 
4076
 
 
4077
    virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
 
4078
 
 
4079
error:
 
4080
    virDispatchError(domain->conn);
 
4081
    return -1;
 
4082
}
 
4083
 
 
4084
/**
 
4085
 * virDomainGetNumaParameters:
 
4086
 * @domain: pointer to domain object
 
4087
 * @params: pointer to numa parameter object
 
4088
 *          (return value, allocated by the caller)
 
4089
 * @nparams: pointer to number of numa parameters
 
4090
 * @flags: bitwise-OR of virDomainModificationImpact and virTypedParameterFlags
 
4091
 *
 
4092
 * Get all numa parameters.  On input, @nparams gives the size of the
 
4093
 * @params array; on output, @nparams gives how many slots were filled
 
4094
 * with parameter information, which might be less but will not exceed
 
4095
 * the input value.
 
4096
 *
 
4097
 * As a special case, calling with @params as NULL and @nparams as 0 on
 
4098
 * input will cause @nparams on output to contain the number of parameters
 
4099
 * supported by the hypervisor. The caller should then allocate @params
 
4100
 * array, i.e. (sizeof(@virTypedParameter) * @nparams) bytes and call the API
 
4101
 * again.
 
4102
 *
 
4103
 * See virDomainGetMemoryParameters() for an equivalent usage example.
 
4104
 *
 
4105
 * This function may require privileged access to the hypervisor. This function
 
4106
 * expects the caller to allocate the @params.
 
4107
 *
 
4108
 * Returns -1 in case of error, 0 in case of success.
 
4109
 */
 
4110
 
 
4111
int
 
4112
virDomainGetNumaParameters(virDomainPtr domain,
 
4113
                           virTypedParameterPtr params,
 
4114
                           int *nparams, unsigned int flags)
 
4115
{
 
4116
    virConnectPtr conn;
 
4117
 
 
4118
    VIR_DOMAIN_DEBUG(domain, "params=%p, nparams=%d, flags=%x",
 
4119
                     params, (nparams) ? *nparams : -1, flags);
 
4120
 
 
4121
    virResetLastError();
 
4122
 
 
4123
    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
 
4124
        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
 
4125
        virDispatchError(NULL);
 
4126
        return -1;
 
4127
    }
 
4128
    if ((nparams == NULL) || (*nparams < 0) ||
 
4129
        (params == NULL && *nparams != 0)) {
 
4130
        virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
 
4131
        goto error;
 
4132
    }
 
4133
    if (VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
 
4134
                                 VIR_DRV_FEATURE_TYPED_PARAM_STRING))
 
4135
        flags |= VIR_TYPED_PARAM_STRING_OKAY;
 
4136
 
 
4137
    conn = domain->conn;
 
4138
 
 
4139
    if (conn->driver->domainGetNumaParameters) {
 
4140
        int ret;
 
4141
        ret = conn->driver->domainGetNumaParameters(domain, params, nparams,
 
4142
                                                    flags);
 
4143
        if (ret < 0)
 
4144
            goto error;
 
4145
        return ret;
 
4146
    }
 
4147
    virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
 
4148
 
 
4149
error:
 
4150
    virDispatchError(domain->conn);
 
4151
    return -1;
 
4152
}
 
4153
 
 
4154
/**
3772
4155
 * virDomainSetBlkioParameters:
3773
4156
 * @domain: pointer to domain object
3774
4157
 * @params: pointer to blkio parameter objects
3955
4338
 * @state: returned state of the domain (one of virDomainState)
3956
4339
 * @reason: returned reason which led to @state (one of virDomain*Reason
3957
4340
 * corresponding to the current state); it is allowed to be NULL
3958
 
 * @flags: additional flags, 0 for now.
 
4341
 * @flags: extra flags; not used yet, so callers should always pass 0
3959
4342
 *
3960
4343
 * Extract domain state. Each state can be accompanied with a reason (if known)
3961
4344
 * which led to the state.
4005
4388
 * virDomainGetControlInfo:
4006
4389
 * @domain: a domain object
4007
4390
 * @info: pointer to a virDomainControlInfo structure allocated by the user
4008
 
 * @flags: additional flags, 0 for now
 
4391
 * @flags: extra flags; not used yet, so callers should always pass 0
4009
4392
 *
4010
4393
 * Extract details about current state of control interface to a domain.
4011
4394
 *
4052
4435
/**
4053
4436
 * virDomainGetXMLDesc:
4054
4437
 * @domain: a domain object
4055
 
 * @flags: an OR'ed set of virDomainXMLFlags
 
4438
 * @flags: bitwise-OR of virDomainXMLFlags
4056
4439
 *
4057
4440
 * Provide an XML description of the domain. The description may be reused
4058
4441
 * later to relaunch the domain with virDomainCreateXML().
4113
4496
 * @conn: a connection object
4114
4497
 * @nativeFormat: configuration format importing from
4115
4498
 * @nativeConfig: the configuration data to import
4116
 
 * @flags: currently unused, pass 0
 
4499
 * @flags: extra flags; not used yet, so callers should always pass 0
4117
4500
 *
4118
4501
 * Reads native configuration data  describing a domain, and
4119
4502
 * generates libvirt domain XML. The format of the native
4166
4549
 * @conn: a connection object
4167
4550
 * @nativeFormat: configuration format exporting to
4168
4551
 * @domainXml: the domain configuration to export
4169
 
 * @flags: currently unused, pass 0
 
4552
 * @flags: extra flags; not used yet, so callers should always pass 0
4170
4553
 *
4171
4554
 * Reads a domain XML configuration document, and generates
4172
4555
 * a native configuration file describing the domain.
4661
5044
                           const char *uri,
4662
5045
                           unsigned long bandwidth)
4663
5046
{
4664
 
    xmlURIPtr tempuri = NULL;
 
5047
    virURIPtr tempuri = NULL;
4665
5048
    VIR_DOMAIN_DEBUG(domain, "xmlin=%s, flags=%lx, dname=%s, "
4666
5049
                     "dconnuri=%s, uri=%s, bandwidth=%lu",
4667
5050
                     NULLSTR(xmlin), flags, NULLSTR(dname),
4673
5056
        return -1;
4674
5057
    }
4675
5058
 
4676
 
    tempuri = xmlParseURI(dconnuri);
4677
 
    if (!tempuri) {
4678
 
        virLibConnError(VIR_ERR_INVALID_ARG, __FUNCTION__);
 
5059
    if (!(tempuri = virURIParse(dconnuri))) {
4679
5060
        virDispatchError(domain->conn);
4680
5061
        return -1;
4681
5062
    }
4683
5064
    if (!tempuri->server || STRPREFIX(tempuri->server, "localhost")) {
4684
5065
        virLibConnError(VIR_ERR_INVALID_ARG, __FUNCTION__);
4685
5066
        virDispatchError(domain->conn);
4686
 
        xmlFreeURI(tempuri);
 
5067
        virURIFree(tempuri);
4687
5068
        return -1;
4688
5069
    }
4689
 
    xmlFreeURI(tempuri);
 
5070
    virURIFree(tempuri);
4690
5071
 
4691
5072
    /* Perform the migration.  The driver isn't supposed to return
4692
5073
     * until the migration is complete.
4799
5180
 * virDomainMigrate:
4800
5181
 * @domain: a domain object
4801
5182
 * @dconn: destination host (a connection object)
4802
 
 * @flags: flags
 
5183
 * @flags: bitwise-OR of virDomainMigrateFlags
4803
5184
 * @dname: (optional) rename domain to this at destination
4804
5185
 * @uri: (optional) dest hostname/URI as seen from the source host
4805
5186
 * @bandwidth: (optional) specify migration bandwidth limit in Mbps
4819
5200
 *   VIR_MIGRATE_CHANGE_PROTECTION Protect against domain configuration
4820
5201
 *                                 changes during the migration process (set
4821
5202
 *                                 automatically when supported).
 
5203
 *   VIR_MIGRATE_UNSAFE    Force migration even if it is considered unsafe.
4822
5204
 *
4823
5205
 * VIR_MIGRATE_TUNNELLED requires that VIR_MIGRATE_PEER2PEER be set.
4824
5206
 * Applications using the VIR_MIGRATE_PEER2PEER flag will probably
4989
5371
 * virDomainMigrate2:
4990
5372
 * @domain: a domain object
4991
5373
 * @dconn: destination host (a connection object)
4992
 
 * @flags: flags
 
5374
 * @flags: bitwise-OR of virDomainMigrateFlags
4993
5375
 * @dxml: (optional) XML config for launching guest on target
4994
5376
 * @dname: (optional) rename domain to this at destination
4995
5377
 * @uri: (optional) dest hostname/URI as seen from the source host
5010
5392
 *   VIR_MIGRATE_CHANGE_PROTECTION Protect against domain configuration
5011
5393
 *                                 changes during the migration process (set
5012
5394
 *                                 automatically when supported).
 
5395
 *   VIR_MIGRATE_UNSAFE    Force migration even if it is considered unsafe.
5013
5396
 *
5014
5397
 * VIR_MIGRATE_TUNNELLED requires that VIR_MIGRATE_PEER2PEER be set.
5015
5398
 * Applications using the VIR_MIGRATE_PEER2PEER flag will probably
5059
5442
 * if @dxml would cause any guest-visible changes.  Pass NULL
5060
5443
 * if no changes are needed to the XML between source and destination.
5061
5444
 * @dxml cannot be used to rename the domain during migration (use
5062
 
 * @dname for that purpose).  Domain name in @dxml must either match the
5063
 
 * original domain name or @dname if it was specified.
 
5445
 * @dname for that purpose).  Domain name in @dxml must match the
 
5446
 * original domain name.
5064
5447
 *
5065
5448
 * Returns the new domain object if the migration was successful,
5066
5449
 *   or NULL in case of error.  Note that the new domain object
5200
5583
 * virDomainMigrateToURI:
5201
5584
 * @domain: a domain object
5202
5585
 * @duri: mandatory URI for the destination host
5203
 
 * @flags: flags
 
5586
 * @flags: bitwise-OR of virDomainMigrateFlags
5204
5587
 * @dname: (optional) rename domain to this at destination
5205
5588
 * @bandwidth: (optional) specify migration bandwidth limit in Mbps
5206
5589
 *
5218
5601
 *   VIR_MIGRATE_CHANGE_PROTECTION Protect against domain configuration
5219
5602
 *                                 changes during the migration process (set
5220
5603
 *                                 automatically when supported).
 
5604
 *   VIR_MIGRATE_UNSAFE    Force migration even if it is considered unsafe.
5221
5605
 *
5222
5606
 * The operation of this API hinges on the VIR_MIGRATE_PEER2PEER flag.
5223
5607
 * If the VIR_MIGRATE_PEER2PEER flag is NOT set, the duri parameter
5324
5708
 * @dconnuri: (optional) URI for target libvirtd if @flags includes VIR_MIGRATE_PEER2PEER
5325
5709
 * @miguri: (optional) URI for invoking the migration, not if @flags includs VIR_MIGRATE_TUNNELLED
5326
5710
 * @dxml: (optional) XML config for launching guest on target
5327
 
 * @flags: flags
 
5711
 * @flags: bitwise-OR of virDomainMigrateFlags
5328
5712
 * @dname: (optional) rename domain to this at destination
5329
5713
 * @bandwidth: (optional) specify migration bandwidth limit in Mbps
5330
5714
 *
5342
5726
 *   VIR_MIGRATE_CHANGE_PROTECTION Protect against domain configuration
5343
5727
 *                                 changes during the migration process (set
5344
5728
 *                                 automatically when supported).
 
5729
 *   VIR_MIGRATE_UNSAFE    Force migration even if it is considered unsafe.
5345
5730
 *
5346
5731
 * The operation of this API hinges on the VIR_MIGRATE_PEER2PEER flag.
5347
5732
 *
6166
6551
 * @params: pointer to node cpu time parameter objects
6167
6552
 * @nparams: number of node cpu time parameter (this value should be same or
6168
6553
 *          less than the number of parameters supported)
6169
 
 * @flags: currently unused, for future extension. always pass 0.
 
6554
 * @flags: extra flags; not used yet, so callers should always pass 0
6170
6555
 *
6171
6556
 * This function provides individual cpu statistics of the node.
6172
6557
 * If you want to get total cpu statistics of the node, you must specify
6256
6641
 * @params: pointer to node memory stats objects
6257
6642
 * @nparams: number of node memory stats (this value should be same or
6258
6643
 *          less than the number of stats supported)
6259
 
 * @flags: currently unused, for future extension. always pass 0.
 
6644
 * @flags: extra flags; not used yet, so callers should always pass 0
6260
6645
 *
6261
6646
 * This function provides memory stats of the node.
6262
6647
 * If you want to get total cpu statistics of the node, you must specify
6339
6724
 * @conn: pointer to the hypervisor connection
6340
6725
 *
6341
6726
 * provides the free memory available on the Node
6342
 
 * Note: most libvirt APIs provide memory sizes in kilobytes, but in this
 
6727
 * Note: most libvirt APIs provide memory sizes in kibibytes, but in this
6343
6728
 * function the returned value is in bytes. Divide by 1024 as necessary.
6344
6729
 *
6345
6730
 * Returns the available free memory in bytes or 0 in case of error
6382
6767
 *                  which is a combination of the former modes).
6383
6768
 * @duration: the time duration in seconds for which the host
6384
6769
 *            has to be suspended
6385
 
 * @flags: any flag values that might need to be passed;
6386
 
 *         currently unused (0).
 
6770
 * @flags: extra flags; not used yet, so callers should always pass 0
6387
6771
 *
6388
6772
 * Attempt to suspend the node (host machine) for the given duration of
6389
6773
 * time in the specified state (Suspend-to-RAM, Suspend-to-Disk or
6785
7169
        virDispatchError(NULL);
6786
7170
        return -1;
6787
7171
    }
6788
 
    if (!disk || !stats || size > sizeof stats2) {
 
7172
    if (!disk || !stats || size > sizeof(stats2)) {
6789
7173
        virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
6790
7174
        goto error;
6791
7175
    }
6925
7309
        virDispatchError(NULL);
6926
7310
        return -1;
6927
7311
    }
6928
 
    if (!path || !stats || size > sizeof stats2) {
 
7312
    if (!path || !stats || size > sizeof(stats2)) {
6929
7313
        virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
6930
7314
        goto error;
6931
7315
    }
6946
7330
    return -1;
6947
7331
}
6948
7332
 
 
7333
 /**
 
7334
 * virDomainSetInterfaceParameters:
 
7335
 * @domain: pointer to domain object
 
7336
 * @device: the interface name or mac address
 
7337
 * @params: pointer to interface parameter objects
 
7338
 * @nparams: number of interface parameter (this value can be the same or
 
7339
 *          less than the number of parameters supported)
 
7340
 * @flags: bitwise-OR of virDomainModificationImpact
 
7341
 *
 
7342
 * Change a subset or all parameters of interface; currently this
 
7343
 * includes bandwidth parameters.  The value of @flags should be
 
7344
 * either VIR_DOMAIN_AFFECT_CURRENT, or a bitwise-or of values
 
7345
 * VIR_DOMAIN_AFFECT_LIVE and VIR_DOMAIN_AFFECT_CONFIG, although
 
7346
 * hypervisors vary in which flags are supported.
 
7347
 *
 
7348
 * This function may require privileged access to the hypervisor.
 
7349
 *
 
7350
 * Returns -1 in case of error, 0 in case of success.
 
7351
 */
 
7352
int
 
7353
virDomainSetInterfaceParameters(virDomainPtr domain,
 
7354
                                const char *device,
 
7355
                                virTypedParameterPtr params,
 
7356
                                int nparams, unsigned int flags)
 
7357
{
 
7358
    virConnectPtr conn;
 
7359
 
 
7360
    VIR_DOMAIN_DEBUG(domain, "device=%s, params=%p, nparams=%d, flags=%x",
 
7361
                     device, params, nparams, flags);
 
7362
 
 
7363
    virResetLastError();
 
7364
 
 
7365
    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
 
7366
        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
 
7367
        virDispatchError(NULL);
 
7368
        return -1;
 
7369
    }
 
7370
    if (domain->conn->flags & VIR_CONNECT_RO) {
 
7371
        virLibDomainError(VIR_ERR_OPERATION_DENIED, __FUNCTION__);
 
7372
        goto error;
 
7373
    }
 
7374
    if ((nparams <= 0) || (params == NULL)) {
 
7375
        virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
 
7376
        goto error;
 
7377
    }
 
7378
    if (virTypedParameterValidateSet(domain, params, nparams) < 0)
 
7379
        return -1;
 
7380
 
 
7381
    conn = domain->conn;
 
7382
 
 
7383
    if (conn->driver->domainSetInterfaceParameters) {
 
7384
        int ret;
 
7385
        ret = conn->driver->domainSetInterfaceParameters(domain, device,
 
7386
                                                         params, nparams,
 
7387
                                                         flags);
 
7388
        if (ret < 0)
 
7389
            goto error;
 
7390
        return ret;
 
7391
    }
 
7392
 
 
7393
    virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
 
7394
 
 
7395
error:
 
7396
    virDispatchError(domain->conn);
 
7397
    return -1;
 
7398
}
 
7399
 
 
7400
 /**
 
7401
 * virDomainGetInterfaceParameters:
 
7402
 * @domain: pointer to domain object
 
7403
 * @device: the interface name or mac address
 
7404
 * @params: pointer to interface parameter objects
 
7405
 *          (return value, allocated by the caller)
 
7406
 * @nparams: pointer to number of interface parameter; input and output
 
7407
 * @flags: bitwise-OR of virDomainModificationImpact and virTypedParameterFlags
 
7408
 *
 
7409
 * Get all interface parameters. On input, @nparams gives the size of
 
7410
 * the @params array; on output, @nparams gives how many slots were
 
7411
 * filled with parameter information, which might be less but will not
 
7412
 * exceed the input value.
 
7413
 *
 
7414
 * As a special case, calling with @params as NULL and @nparams as 0 on
 
7415
 * input will cause @nparams on output to contain the number of parameters
 
7416
 * supported by the hypervisor. The caller should then allocate @params
 
7417
 * array, i.e. (sizeof(@virTypedParameter) * @nparams) bytes and call the
 
7418
 * API again. See virDomainGetMemoryParameters() for an equivalent usage
 
7419
 * example.
 
7420
 *
 
7421
 * This function may require privileged access to the hypervisor. This function
 
7422
 * expects the caller to allocate the @params.
 
7423
 *
 
7424
 * Returns -1 in case of error, 0 in case of success.
 
7425
 */
 
7426
 
 
7427
int
 
7428
virDomainGetInterfaceParameters(virDomainPtr domain,
 
7429
                                const char *device,
 
7430
                                virTypedParameterPtr params,
 
7431
                                int *nparams, unsigned int flags)
 
7432
{
 
7433
    virConnectPtr conn;
 
7434
 
 
7435
    VIR_DOMAIN_DEBUG(domain, "device=%s, params=%p, nparams=%d, flags=%x",
 
7436
                     device, params, (nparams) ? *nparams : -1, flags);
 
7437
 
 
7438
    virResetLastError();
 
7439
 
 
7440
    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
 
7441
        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
 
7442
        virDispatchError(NULL);
 
7443
        return -1;
 
7444
    }
 
7445
    if ((nparams == NULL) || (*nparams < 0) ||
 
7446
        (params == NULL && *nparams != 0)) {
 
7447
        virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
 
7448
        goto error;
 
7449
    }
 
7450
    if (VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
 
7451
                                 VIR_DRV_FEATURE_TYPED_PARAM_STRING))
 
7452
        flags |= VIR_TYPED_PARAM_STRING_OKAY;
 
7453
 
 
7454
    conn = domain->conn;
 
7455
 
 
7456
    if (conn->driver->domainGetInterfaceParameters) {
 
7457
        int ret;
 
7458
        ret = conn->driver->domainGetInterfaceParameters(domain, device,
 
7459
                                                         params, nparams,
 
7460
                                                         flags);
 
7461
        if (ret < 0)
 
7462
            goto error;
 
7463
        return ret;
 
7464
    }
 
7465
    virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
 
7466
 
 
7467
error:
 
7468
    virDispatchError(domain->conn);
 
7469
    return -1;
 
7470
}
 
7471
 
6949
7472
/**
6950
7473
 * virDomainMemoryStats:
6951
7474
 * @dom: pointer to the domain object
6952
7475
 * @stats: nr_stats-sized array of stat structures (returned)
6953
7476
 * @nr_stats: number of memory statistics requested
6954
 
 * @flags: unused, always pass 0
 
7477
 * @flags: extra flags; not used yet, so callers should always pass 0
6955
7478
 *
6956
7479
 * This function provides memory statistics for the domain.
6957
7480
 *
7024
7547
 * @offset: offset within block device
7025
7548
 * @size: size to read
7026
7549
 * @buffer: return buffer (must be at least size bytes)
7027
 
 * @flags: unused, always pass 0
 
7550
 * @flags: extra flags; not used yet, so callers should always pass 0
7028
7551
 *
7029
7552
 * This function allows you to read the contents of a domain's
7030
7553
 * disk device.
7118
7641
 * virDomainBlockResize:
7119
7642
 * @dom: pointer to the domain object
7120
7643
 * @disk: path to the block image, or shorthand
7121
 
 * @size: new size of the block image in kilobytes
7122
 
 * @flags: unused, always pass 0
 
7644
 * @size: new size of the block image, see below for unit
 
7645
 * @flags: bitwise-OR of virDomainBlockResizeFlags
7123
7646
 *
7124
 
 * Note that this call may fail if the underlying virtualization hypervisor
7125
 
 * does not support it. And this call requires privileged access to the
7126
 
 * hypervisor.
 
7647
 * Resize a block device of domain while the domain is running.  If
 
7648
 * @flags is 0, then @size is in kibibytes (blocks of 1024 bytes);
 
7649
 * since 0.9.11, if @flags includes VIR_DOMAIN_BLOCK_RESIZE_BYTES,
 
7650
 * @size is in bytes instead.  @size is taken directly as the new
 
7651
 * size.  Depending on the file format, the hypervisor may round up
 
7652
 * to the next alignment boundary.
7127
7653
 *
7128
7654
 * The @disk parameter is either an unambiguous source name of the
7129
7655
 * block device (the <source file='...'/> sub-element, such as
7132
7658
 * can be found by calling virDomainGetXMLDesc() and inspecting
7133
7659
 * elements within //domain/devices/disk.
7134
7660
 *
7135
 
 * Resize a block device of domain while the domain is running.
 
7661
 * Note that this call may fail if the underlying virtualization hypervisor
 
7662
 * does not support it; this call requires privileged access to the
 
7663
 * hypervisor.
7136
7664
 *
7137
7665
 * Returns: 0 in case of success or -1 in case of failure.
7138
7666
 */
7188
7716
 * @start: start of memory to peek
7189
7717
 * @size: size of memory to peek
7190
7718
 * @buffer: return buffer (must be at least size bytes)
7191
 
 * @flags: flags, see below
 
7719
 * @flags: bitwise-OR of virDomainMemoryFlags
7192
7720
 *
7193
7721
 * This function allows you to read the contents of a domain's
7194
7722
 * memory.
7298
7826
 * @domain: a domain object
7299
7827
 * @disk: path to the block device, or device shorthand
7300
7828
 * @info: pointer to a virDomainBlockInfo structure allocated by the user
7301
 
 * @flags: currently unused, pass zero
 
7829
 * @flags: extra flags; not used yet, so callers should always pass 0
7302
7830
 *
7303
7831
 * Extract information about a domain's block device.
7304
7832
 *
7367
7895
 * virDomainUndefine(). A previous definition for this domain would be
7368
7896
 * overriden if it already exists.
7369
7897
 *
 
7898
 * Some hypervisors may prevent this operation if there is a current
 
7899
 * block copy operation on a transient domain with the same id as the
 
7900
 * domain being defined; in that case, use virDomainBlockJobAbort() to
 
7901
 * stop the block copy first.
 
7902
 *
7370
7903
 * Returns NULL in case of error, a pointer to the domain otherwise
7371
7904
 */
7372
7905
virDomainPtr
7456
7989
/**
7457
7990
 * virDomainUndefineFlags:
7458
7991
 * @domain: pointer to a defined domain
7459
 
 * @flags: bitwise-or of supported virDomainUndefineFlagsValues
 
7992
 * @flags: bitwise-OR of supported virDomainUndefineFlagsValues
7460
7993
 *
7461
7994
 * Undefine a domain. If the domain is running, it's converted to
7462
7995
 * transient domain, without stopping it. If the domain is inactive,
7642
8175
/**
7643
8176
 * virDomainCreateWithFlags:
7644
8177
 * @domain: pointer to a defined domain
7645
 
 * @flags: bitwise-or of supported virDomainCreateFlags
 
8178
 * @flags: bitwise-OR of supported virDomainCreateFlags
7646
8179
 *
7647
8180
 * Launch a defined domain. If the call succeeds the domain moves from the
7648
8181
 * defined to the running domains pools.
7805
8338
/**
7806
8339
 * virDomainInjectNMI:
7807
8340
 * @domain: pointer to domain object, or NULL for Domain0
7808
 
 * @flags:  the flags for controlling behavior, pass 0 for now
 
8341
 * @flags: extra flags; not used yet, so callers should always pass 0
7809
8342
 *
7810
8343
 * Send NMI to the guest
7811
8344
 *
7853
8386
 * @holdtime:  the duration (in milliseconds) that the keys will be held
7854
8387
 * @keycodes:  array of keycodes
7855
8388
 * @nkeycodes: number of keycodes, up to VIR_DOMAIN_SEND_KEY_MAX_KEYS
7856
 
 * @flags:     the flags for controlling behavior, pass 0 for now
 
8389
 * @flags: extra flags; not used yet, so callers should always pass 0
7857
8390
 *
7858
8391
 * Send key(s) to the guest.
7859
8392
 *
7970
8503
 * virDomainSetVcpusFlags:
7971
8504
 * @domain: pointer to domain object, or NULL for Domain0
7972
8505
 * @nvcpus: the new number of virtual CPUs for this domain, must be at least 1
7973
 
 * @flags: an OR'ed set of virDomainVcpuFlags
 
8506
 * @flags: bitwise-OR of virDomainVcpuFlags
7974
8507
 *
7975
8508
 * Dynamically change the number of virtual CPUs used by the domain.
7976
8509
 * Note that this call may fail if the underlying virtualization hypervisor
8018
8551
    }
8019
8552
 
8020
8553
    /* Perform some argument validation common to all implementations.  */
8021
 
    if (nvcpus < 1 || (unsigned short) nvcpus != nvcpus) {
 
8554
    if (nvcpus < 1) {
8022
8555
        virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
8023
8556
        goto error;
8024
8557
    }
 
8558
    if ((unsigned short) nvcpus != nvcpus) {
 
8559
        virLibDomainError(VIR_ERR_OVERFLOW, _("input too large: %u"), nvcpus);
 
8560
        goto error;
 
8561
    }
8025
8562
    conn = domain->conn;
8026
8563
 
8027
8564
    if (conn->driver->domainSetVcpusFlags) {
8042
8579
/**
8043
8580
 * virDomainGetVcpusFlags:
8044
8581
 * @domain: pointer to domain object, or NULL for Domain0
8045
 
 * @flags: an OR'ed set of virDomainVcpuFlags
 
8582
 * @flags: bitwise-OR of virDomainVcpuFlags
8046
8583
 *
8047
8584
 * Query the number of virtual CPUs used by the domain.  Note that
8048
8585
 * this call may fail if the underlying virtualization hypervisor does
8111
8648
 *      Bytes are stored in little-endian order: CPU0-7, 8-15...
8112
8649
 *      In each byte, lowest CPU number is least significant bit.
8113
8650
 * @maplen: number of bytes in cpumap, from 1 up to size of CPU map in
8114
 
 *      underlying virtualization system (Xen...).
8115
 
 *      If maplen < size, missing bytes are set to zero.
8116
 
 *      If maplen > size, failure code is returned.
 
8651
 *      underlying virtualization system (Xen...).
 
8652
 *      If maplen < size, missing bytes are set to zero.
 
8653
 *      If maplen > size, failure code is returned.
8117
8654
 *
8118
8655
 * Dynamically change the real CPUs which can be allocated to a virtual CPU.
8119
8656
 * This function may require privileged access to the hypervisor.
8258
8795
 *     Must not be NULL.
8259
8796
 * @maplen: the number of bytes in one cpumap, from 1 up to size of CPU map.
8260
8797
 *     Must be positive.
8261
 
 * @flags: an OR'ed set of virDomainModificationImpact
 
8798
 * @flags: bitwise-OR of virDomainModificationImpact
8262
8799
 *     Must not be VIR_DOMAIN_AFFECT_LIVE and
8263
8800
 *     VIR_DOMAIN_AFFECT_CONFIG concurrently.
8264
8801
 *
8285
8822
        return -1;
8286
8823
    }
8287
8824
 
8288
 
    if (ncpumaps < 1 || !cpumaps || maplen <= 0 ||
8289
 
        INT_MULTIPLY_OVERFLOW(ncpumaps, maplen)) {
 
8825
    if (ncpumaps < 1 || !cpumaps || maplen <= 0) {
8290
8826
        virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
8291
8827
        goto error;
8292
8828
    }
 
8829
    if (INT_MULTIPLY_OVERFLOW(ncpumaps, maplen)) {
 
8830
        virLibDomainError(VIR_ERR_OVERFLOW, _("input too large: %d * %d"),
 
8831
                          ncpumaps, maplen);
 
8832
        goto error;
 
8833
    }
8293
8834
 
8294
8835
    /* At most one of these two flags should be set.  */
8295
8836
    if ((flags & VIR_DOMAIN_AFFECT_LIVE) &&
8322
8863
 * @maxinfo: number of structures in info array
8323
8864
 * @cpumaps: pointer to a bit map of real CPUs for all vcpus of this
8324
8865
 *      domain (in 8-bit bytes) (OUT)
8325
 
 *      If cpumaps is NULL, then no cpumap information is returned by the API.
8326
 
 *      It's assumed there is <maxinfo> cpumap in cpumaps array.
8327
 
 *      The memory allocated to cpumaps must be (maxinfo * maplen) bytes
8328
 
 *      (ie: calloc(maxinfo, maplen)).
8329
 
 *      One cpumap inside cpumaps has the format described in
 
8866
 *      If cpumaps is NULL, then no cpumap information is returned by the API.
 
8867
 *      It's assumed there is <maxinfo> cpumap in cpumaps array.
 
8868
 *      The memory allocated to cpumaps must be (maxinfo * maplen) bytes
 
8869
 *      (ie: calloc(maxinfo, maplen)).
 
8870
 *      One cpumap inside cpumaps has the format described in
8330
8871
 *      virDomainPinVcpu() API.
8331
8872
 * @maplen: number of bytes in one cpumap, from 1 up to size of CPU map in
8332
 
 *      underlying virtualization system (Xen...).
8333
 
 *      Must be zero when cpumaps is NULL and positive when it is non-NULL.
 
8873
 *      underlying virtualization system (Xen...).
 
8874
 *      Must be zero when cpumaps is NULL and positive when it is non-NULL.
8334
8875
 *
8335
8876
 * Extract information about virtual CPUs of domain, store it in info array
8336
8877
 * and also in cpumaps if this pointer isn't NULL.  This call may fail
8364
8905
 
8365
8906
    /* Ensure that domainGetVcpus (aka remoteDomainGetVcpus) does not
8366
8907
       try to memcpy anything into a NULL pointer.  */
8367
 
    if (!cpumaps ? maplen != 0
8368
 
        : (maplen <= 0 || INT_MULTIPLY_OVERFLOW(maxinfo, maplen))) {
 
8908
    if (!cpumaps ? maplen != 0 : maplen <= 0) {
8369
8909
        virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
8370
8910
        goto error;
8371
8911
    }
 
8912
    if (cpumaps && INT_MULTIPLY_OVERFLOW(maxinfo, maplen)) {
 
8913
        virLibDomainError(VIR_ERR_OVERFLOW, _("input too large: %d * %d"),
 
8914
                          maxinfo, maplen);
 
8915
        goto error;
 
8916
    }
8372
8917
 
8373
8918
    conn = domain->conn;
8374
8919
 
8479
9024
}
8480
9025
 
8481
9026
/**
 
9027
 * virDomainSetMetadata:
 
9028
 * @domain: a domain object
 
9029
 * @type: type of description, from virDomainMetadataType
 
9030
 * @metadata: new metadata text
 
9031
 * @key: XML namespace key, or NULL
 
9032
 * @uri: XML namespace URI, or NULL
 
9033
 * @flags: bitwise-OR of virDomainModificationImpact
 
9034
 *
 
9035
 * Sets the appropriate domain element given by @type to the
 
9036
 * value of @description.  A @type of VIR_DOMAIN_METADATA_DESCRIPTION
 
9037
 * is free-form text; VIR_DOMAIN_METADATA_TITLE is free-form, but no
 
9038
 * newlines are permitted, and should be short (although the length is
 
9039
 * not enforced). For these two options @key and @uri are irrelevant and
 
9040
 * must be set to NULL.
 
9041
 *
 
9042
 * For type VIR_DOMAIN_METADATA_ELEMENT @metadata  must be well-formed
 
9043
 * XML belonging to namespace defined by @uri with local name @key.
 
9044
 *
 
9045
 * Passing NULL for @metadata says to remove that element from the
 
9046
 * domain XML (passing the empty string leaves the element present).
 
9047
 *
 
9048
 * The resulting metadata will be present in virDomainGetXMLDesc(),
 
9049
 * as well as quick access through virDomainGetMetadata().
 
9050
 *
 
9051
 * @flags controls whether the live domain, persistent configuration,
 
9052
 * or both will be modified.
 
9053
 *
 
9054
 * Returns 0 on success, -1 in case of failure.
 
9055
 */
 
9056
int
 
9057
virDomainSetMetadata(virDomainPtr domain,
 
9058
                     int type,
 
9059
                     const char *metadata,
 
9060
                     const char *key,
 
9061
                     const char *uri,
 
9062
                     unsigned int flags)
 
9063
{
 
9064
    virConnectPtr conn;
 
9065
 
 
9066
    VIR_DOMAIN_DEBUG(domain,
 
9067
                     "type=%d, metadata='%s', key='%s', uri='%s', flags=%x",
 
9068
                     type, NULLSTR(metadata), NULLSTR(key), NULLSTR(uri),
 
9069
                     flags);
 
9070
 
 
9071
    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
 
9072
        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
 
9073
        goto error;
 
9074
    }
 
9075
 
 
9076
    conn = domain->conn;
 
9077
 
 
9078
    if (conn->flags & VIR_CONNECT_RO) {
 
9079
        virLibDomainError(VIR_ERR_OPERATION_DENIED, __FUNCTION__);
 
9080
        goto error;
 
9081
    }
 
9082
 
 
9083
    switch (type) {
 
9084
    case VIR_DOMAIN_METADATA_TITLE:
 
9085
        if (metadata && strchr(metadata, '\n')) {
 
9086
                virLibDomainError(VIR_ERR_INVALID_ARG, "%s",
 
9087
                                  _("Domain title can't contain newlines"));
 
9088
                goto error;
 
9089
        }
 
9090
        /* fallthrough */
 
9091
    case VIR_DOMAIN_METADATA_DESCRIPTION:
 
9092
        if (uri || key) {
 
9093
            virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
 
9094
            goto error;
 
9095
        }
 
9096
        break;
 
9097
    case VIR_DOMAIN_METADATA_ELEMENT:
 
9098
        if (!uri || !key) {
 
9099
            virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
 
9100
            goto error;
 
9101
        }
 
9102
        break;
 
9103
    default:
 
9104
        /* For future expansion */
 
9105
        break;
 
9106
    }
 
9107
 
 
9108
    if (conn->driver->domainSetMetadata) {
 
9109
        int ret;
 
9110
        ret = conn->driver->domainSetMetadata(domain, type, metadata, key, uri,
 
9111
                                              flags);
 
9112
        if (ret < 0)
 
9113
            goto error;
 
9114
        return ret;
 
9115
    }
 
9116
 
 
9117
    virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
 
9118
 
 
9119
error:
 
9120
    virDispatchError(domain->conn);
 
9121
    return -1;
 
9122
}
 
9123
 
 
9124
/**
 
9125
 * virDomainGetMetadata:
 
9126
 * @domain: a domain object
 
9127
 * @type: type of description, from virDomainMetadataType
 
9128
 * @uri: XML namespace identifier
 
9129
 * @flags: bitwise-OR of virDomainModificationImpact
 
9130
 *
 
9131
 * Retrieves the appropriate domain element given by @type.
 
9132
 * If VIR_DOMAIN_METADATA_ELEMENT is requested parameter @uri
 
9133
 * must be set to the name of the namespace the requested elements
 
9134
 * belong to, otherwise must be NULL.
 
9135
 *
 
9136
 * If an element of the domain XML is not present, the resulting
 
9137
 * error will be VIR_ERR_NO_DOMAIN_METADATA.  This method forms
 
9138
 * a shortcut for seeing information from virDomainSetMetadata()
 
9139
 * without having to go through virDomainGetXMLDesc().
 
9140
 *
 
9141
 * @flags controls whether the live domain or persistent
 
9142
 * configuration will be queried.
 
9143
 *
 
9144
 * Returns the metadata string on success (caller must free),
 
9145
 * or NULL in case of failure.
 
9146
 */
 
9147
char *
 
9148
virDomainGetMetadata(virDomainPtr domain,
 
9149
                     int type,
 
9150
                     const char *uri,
 
9151
                     unsigned int flags)
 
9152
{
 
9153
    virConnectPtr conn;
 
9154
 
 
9155
    VIR_DOMAIN_DEBUG(domain, "type=%d, uri='%s', flags=%x",
 
9156
                     type, NULLSTR(uri), flags);
 
9157
 
 
9158
    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
 
9159
        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
 
9160
        goto error;
 
9161
    }
 
9162
 
 
9163
    if ((flags & VIR_DOMAIN_AFFECT_LIVE) &&
 
9164
        (flags & VIR_DOMAIN_AFFECT_CONFIG)) {
 
9165
        virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
 
9166
        goto error;
 
9167
    }
 
9168
 
 
9169
    switch (type) {
 
9170
    case VIR_DOMAIN_METADATA_TITLE:
 
9171
    case VIR_DOMAIN_METADATA_DESCRIPTION:
 
9172
        if (uri) {
 
9173
            virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
 
9174
            goto error;
 
9175
        }
 
9176
        break;
 
9177
    case VIR_DOMAIN_METADATA_ELEMENT:
 
9178
        if (!uri) {
 
9179
            virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
 
9180
            goto error;
 
9181
        }
 
9182
        break;
 
9183
    default:
 
9184
        /* For future expansion */
 
9185
        break;
 
9186
    }
 
9187
 
 
9188
    conn = domain->conn;
 
9189
 
 
9190
    if (conn->driver->domainGetMetadata) {
 
9191
        char *ret;
 
9192
        if (!(ret = conn->driver->domainGetMetadata(domain, type, uri, flags)))
 
9193
            goto error;
 
9194
        return ret;
 
9195
    }
 
9196
 
 
9197
    virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
 
9198
 
 
9199
error:
 
9200
    virDispatchError(domain->conn);
 
9201
    return NULL;
 
9202
}
 
9203
 
 
9204
/**
8482
9205
 * virNodeGetSecurityModel:
8483
9206
 * @conn: a connection object
8484
9207
 * @secmodel: pointer to a virSecurityModel structure
8579
9302
 * virDomainAttachDeviceFlags:
8580
9303
 * @domain: pointer to domain object
8581
9304
 * @xml: pointer to XML description of one device
8582
 
 * @flags: an OR'ed set of virDomainDeviceModifyFlags
 
9305
 * @flags: bitwise-OR of virDomainDeviceModifyFlags
8583
9306
 *
8584
9307
 * Attach a virtual device to a domain, using the flags parameter
8585
9308
 * to control how the device is attached.  VIR_DOMAIN_AFFECT_CURRENT
8696
9419
 * virDomainDetachDeviceFlags:
8697
9420
 * @domain: pointer to domain object
8698
9421
 * @xml: pointer to XML description of one device
8699
 
 * @flags: an OR'ed set of virDomainDeviceModifyFlags
 
9422
 * @flags: bitwise-OR of virDomainDeviceModifyFlags
8700
9423
 *
8701
9424
 * Detach a virtual device from a domain, using the flags parameter
8702
9425
 * to control how the device is detached.  VIR_DOMAIN_AFFECT_CURRENT
8710
9433
 * return failure if LIVE is specified but it only supports removing the
8711
9434
 * persisted device allocation.
8712
9435
 *
 
9436
 * Some hypervisors may prevent this operation if there is a current
 
9437
 * block copy operation on the device being detached; in that case,
 
9438
 * use virDomainBlockJobAbort() to stop the block copy first.
 
9439
 *
8713
9440
 * Returns 0 in case of success, -1 in case of failure.
8714
9441
 */
8715
9442
int
8758
9485
 * virDomainUpdateDeviceFlags:
8759
9486
 * @domain: pointer to domain object
8760
9487
 * @xml: pointer to XML description of one device
8761
 
 * @flags: an OR'ed set of virDomainDeviceModifyFlags
 
9488
 * @flags: bitwise-OR of virDomainDeviceModifyFlags
8762
9489
 *
8763
9490
 * Change a virtual device on a domain, using the flags parameter
8764
9491
 * to control how the device is changed.  VIR_DOMAIN_AFFECT_CURRENT
9568
10295
/**
9569
10296
 * virNetworkGetXMLDesc:
9570
10297
 * @network: a network object
9571
 
 * @flags: an OR'ed set of extraction flags, not used yet
 
10298
 * @flags: bitwise-OR of virNetworkXMLFlags
9572
10299
 *
9573
10300
 * Provide an XML description of the network. The description may be reused
9574
10301
 * later to relaunch the network with virNetworkCreateXML().
9575
10302
 *
 
10303
 * Normally, if a network included a physical function, the output includes
 
10304
 * all virtual functions tied to that physical interface.  If @flags includes
 
10305
 * VIR_NETWORK_XML_INACTIVE, then the expansion of virtual interfaces is
 
10306
 * not performed.
 
10307
 *
9576
10308
 * Returns a 0 terminated UTF-8 encoded XML instance, or NULL in case of error.
9577
10309
 *         the caller must free() the returned value.
9578
10310
 */
10070
10802
/**
10071
10803
 * virInterfaceGetXMLDesc:
10072
10804
 * @iface: an interface object
10073
 
 * @flags: an OR'ed set of extraction flags. Current valid bits:
 
10805
 * @flags: bitwise-OR of extraction flags. Current valid bits:
10074
10806
 *
10075
10807
 *      VIR_INTERFACE_XML_INACTIVE - return the static configuration,
10076
10808
 *                                   suitable for use redefining the
10120
10852
 * virInterfaceDefineXML:
10121
10853
 * @conn: pointer to the hypervisor connection
10122
10854
 * @xml: the XML description for the interface, preferably in UTF-8
10123
 
 * @flags: and OR'ed set of extraction flags, not used yet
 
10855
 * @flags: extra flags; not used yet, so callers should always pass 0
10124
10856
 *
10125
 
 
10126
10857
 * Define an interface (or modify existing interface configuration).
10127
10858
 *
10128
10859
 * Normally this change in the interface configuration is immediately
10228
10959
/**
10229
10960
 * virInterfaceCreate:
10230
10961
 * @iface: pointer to a defined interface
10231
 
 * @flags: and OR'ed set of extraction flags, not used yet
 
10962
 * @flags: extra flags; not used yet, so callers should always pass 0
10232
10963
 *
10233
10964
 * Activate an interface (i.e. call "ifup").
10234
10965
 *
10276
11007
/**
10277
11008
 * virInterfaceDestroy:
10278
11009
 * @iface: an interface object
10279
 
 * @flags: and OR'ed set of extraction flags, not used yet
 
11010
 * @flags: extra flags; not used yet, so callers should always pass 0
10280
11011
 *
10281
11012
 * deactivate an interface (ie call "ifdown")
10282
11013
 * This does not remove the interface from the config, and
10389
11120
/**
10390
11121
 * virInterfaceChangeBegin:
10391
11122
 * @conn: pointer to hypervisor connection
10392
 
 * @flags: flags, not used yet
 
11123
 * @flags: extra flags; not used yet, so callers should always pass 0
10393
11124
 *
10394
 
 * This functions creates a restore point to which one can return
 
11125
 * This function creates a restore point to which one can return
10395
11126
 * later by calling virInterfaceChangeRollback(). This function should
10396
11127
 * be called before any transaction with interface configuration.
10397
 
 * Once knowing, new configuration works, it can be commited via
 
11128
 * Once it is known that a new configuration works, it can be committed via
10398
11129
 * virInterfaceChangeCommit(), which frees the restore point.
10399
11130
 *
10400
11131
 * If virInterfaceChangeBegin() is called when a transaction is
10439
11170
/**
10440
11171
 * virInterfaceChangeCommit:
10441
11172
 * @conn: pointer to hypervisor connection
10442
 
 * @flags: flags, not used yet
 
11173
 * @flags: extra flags; not used yet, so callers should always pass 0
10443
11174
 *
10444
11175
 * This commits the changes made to interfaces and frees the restore point
10445
11176
 * created by virInterfaceChangeBegin().
10486
11217
/**
10487
11218
 * virInterfaceChangeRollback:
10488
11219
 * @conn: pointer to hypervisor connection
10489
 
 * @flags: flags, not used yet
 
11220
 * @flags: extra flags; not used yet, so callers should always pass 0
10490
11221
 *
10491
11222
 * This cancels changes made to interfaces settings by restoring previous
10492
11223
 * state created by virInterfaceChangeBegin().
10570
11301
 * Returns the number of pools found, or -1 on error
10571
11302
 */
10572
11303
int
10573
 
virConnectNumOfStoragePools     (virConnectPtr conn)
 
11304
virConnectNumOfStoragePools(virConnectPtr conn)
10574
11305
{
10575
11306
    VIR_DEBUG("conn=%p", conn);
10576
11307
 
10610
11341
 * Returns 0 on success, -1 on error
10611
11342
 */
10612
11343
int
10613
 
virConnectListStoragePools      (virConnectPtr conn,
10614
 
                             char **const names,
10615
 
                             int maxnames)
 
11344
virConnectListStoragePools(virConnectPtr conn,
 
11345
                           char **const names,
 
11346
                           int maxnames)
10616
11347
{
10617
11348
    VIR_DEBUG("conn=%p, names=%p, maxnames=%d", conn, names, maxnames);
10618
11349
 
10735
11466
 * @conn: pointer to hypervisor connection
10736
11467
 * @type: type of storage pool sources to discover
10737
11468
 * @srcSpec: XML document specifying discovery source
10738
 
 * @flags: flags for discovery (unused, pass 0)
 
11469
 * @flags: extra flags; not used yet, so callers should always pass 0
10739
11470
 *
10740
11471
 * Talks to a storage backend and attempts to auto-discover the set of
10741
11472
 * available storage pool sources. e.g. For iSCSI this would be a set of
10960
11691
 * virStoragePoolCreateXML:
10961
11692
 * @conn: pointer to hypervisor connection
10962
11693
 * @xmlDesc: XML description for new pool
10963
 
 * @flags: future flags, use 0 for now
 
11694
 * @flags: extra flags; not used yet, so callers should always pass 0
10964
11695
 *
10965
11696
 * Create a new storage based on its XML description. The
10966
11697
 * pool is not persistent, so its definition will disappear
11010
11741
 * virStoragePoolDefineXML:
11011
11742
 * @conn: pointer to hypervisor connection
11012
11743
 * @xml: XML description for new pool
11013
 
 * @flags: future flags, use 0 for now
 
11744
 * @flags: extra flags; not used yet, so callers should always pass 0
11014
11745
 *
11015
11746
 * Define a new inactive storage pool based on its XML description. The
11016
11747
 * pool is persistent, until explicitly undefined.
11058
11789
/**
11059
11790
 * virStoragePoolBuild:
11060
11791
 * @pool: pointer to storage pool
11061
 
 * @flags: future flags, use 0 for now
11062
 
 * @flags: flags to control pool build behaviour
 
11792
 * @flags: bitwise-OR of virStoragePoolBuildFlags
11063
11793
 *
11064
11794
 * Currently only filesystem pool accepts flags VIR_STORAGE_POOL_BUILD_OVERWRITE
11065
11795
 * and VIR_STORAGE_POOL_BUILD_NO_OVERWRITE.
11150
11880
/**
11151
11881
 * virStoragePoolCreate:
11152
11882
 * @pool: pointer to storage pool
11153
 
 * @flags: future flags, use 0 for now
 
11883
 * @flags: extra flags; not used yet, so callers should always pass 0
11154
11884
 *
11155
11885
 * Starts an inactive storage pool
11156
11886
 *
11242
11972
/**
11243
11973
 * virStoragePoolDelete:
11244
11974
 * @pool: pointer to storage pool
11245
 
 * @flags: flags for obliteration process
 
11975
 * @flags: bitwise-OR of virStoragePoolDeleteFlags
11246
11976
 *
11247
11977
 * Delete the underlying pool resources. This is
11248
11978
 * a non-recoverable operation. The virStoragePoolPtr object
11352
12082
/**
11353
12083
 * virStoragePoolRefresh:
11354
12084
 * @pool: pointer to storage pool
11355
 
 * @flags: flags to control refresh behaviour (currently unused, use 0)
 
12085
 * @flags: extra flags; not used yet, so callers should always pass 0
11356
12086
 *
11357
12087
 * Request that the pool refresh its list of volumes. This may
11358
12088
 * involve communicating with a remote server, and/or initializing
11549
12279
/**
11550
12280
 * virStoragePoolGetXMLDesc:
11551
12281
 * @pool: pointer to storage pool
11552
 
 * @flags: flags for XML format options (set of virDomainXMLFlags)
 
12282
 * @flags: bitwise-OR of virDomainXMLFlags
11553
12283
 *
11554
12284
 * Fetch an XML document describing all aspects of the
11555
12285
 * storage pool. This is suitable for later feeding back
11985
12715
 * virStorageVolCreateXML:
11986
12716
 * @pool: pointer to storage pool
11987
12717
 * @xmldesc: description of volume to create
11988
 
 * @flags: flags for creation (unused, pass 0)
 
12718
 * @flags: extra flags; not used yet, so callers should always pass 0
11989
12719
 *
11990
12720
 * Create a storage volume within a pool based
11991
12721
 * on an XML description. Not all pools support
12039
12769
 * @pool: pointer to parent pool for the new volume
12040
12770
 * @xmldesc: description of volume to create
12041
12771
 * @clonevol: storage volume to use as input
12042
 
 * @flags: flags for creation (unused, pass 0)
 
12772
 * @flags: extra flags; not used yet, so callers should always pass 0
12043
12773
 *
12044
12774
 * Create a storage volume in the parent pool, using the
12045
12775
 * 'clonevol' volume as input. Information for the new
12104
12834
 * @stream: stream to use as output
12105
12835
 * @offset: position in @vol to start reading from
12106
12836
 * @length: limit on amount of data to download
12107
 
 * @flags: future flags (unused, pass 0)
 
12837
 * @flags: extra flags; not used yet, so callers should always pass 0
12108
12838
 *
12109
12839
 * Download the content of the volume as a stream. If @length
12110
12840
 * is zero, then the remaining contents of the volume after
12173
12903
 * @stream: stream to use as input
12174
12904
 * @offset: position to start writing to
12175
12905
 * @length: limit on amount of data to upload
12176
 
 * @flags: flags for creation (unused, pass 0)
 
12906
 * @flags: extra flags; not used yet, so callers should always pass 0
12177
12907
 *
12178
12908
 * Upload new content to the volume from a stream. This call
12179
12909
 * will fail if @offset + @length exceeds the size of the
12241
12971
/**
12242
12972
 * virStorageVolDelete:
12243
12973
 * @vol: pointer to storage volume
12244
 
 * @flags: future flags, use 0 for now
 
12974
 * @flags: extra flags; not used yet, so callers should always pass 0
12245
12975
 *
12246
12976
 * Delete the storage volume from the pool
12247
12977
 *
12287
13017
/**
12288
13018
 * virStorageVolWipe:
12289
13019
 * @vol: pointer to storage volume
12290
 
 * @flags: future flags, use 0 for now
 
13020
 * @flags: extra flags; not used yet, so callers should always pass 0
12291
13021
 *
12292
13022
 * Ensure data previously on a volume is not accessible to future reads
12293
13023
 *
12332
13062
 
12333
13063
 
12334
13064
/**
 
13065
 * virStorageVolWipePattern:
 
13066
 * @vol: pointer to storage volume
 
13067
 * @algorithm: one of virStorageVolWipeAlgorithm
 
13068
 * @flags: future flags, use 0 for now
 
13069
 *
 
13070
 * Similar to virStorageVolWipe, but one can choose
 
13071
 * between different wiping algorithms.
 
13072
 *
 
13073
 * Returns 0 on success, or -1 on error.
 
13074
 */
 
13075
int
 
13076
virStorageVolWipePattern(virStorageVolPtr vol,
 
13077
                         unsigned int algorithm,
 
13078
                         unsigned int flags)
 
13079
{
 
13080
    virConnectPtr conn;
 
13081
    VIR_DEBUG("vol=%p, algorithm=%u, flags=%x", vol, algorithm, flags);
 
13082
 
 
13083
    virResetLastError();
 
13084
 
 
13085
    if (!VIR_IS_CONNECTED_STORAGE_VOL(vol)) {
 
13086
        virLibStorageVolError(VIR_ERR_INVALID_STORAGE_VOL, __FUNCTION__);
 
13087
        virDispatchError(NULL);
 
13088
        return -1;
 
13089
    }
 
13090
 
 
13091
    conn = vol->conn;
 
13092
    if (conn->flags & VIR_CONNECT_RO) {
 
13093
        virLibStorageVolError(VIR_ERR_OPERATION_DENIED, __FUNCTION__);
 
13094
        goto error;
 
13095
    }
 
13096
 
 
13097
    if (conn->storageDriver && conn->storageDriver->volWipePattern) {
 
13098
        int ret;
 
13099
        ret = conn->storageDriver->volWipePattern(vol, algorithm, flags);
 
13100
        if (ret < 0) {
 
13101
            goto error;
 
13102
        }
 
13103
        return ret;
 
13104
    }
 
13105
 
 
13106
    virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
 
13107
 
 
13108
error:
 
13109
    virDispatchError(vol->conn);
 
13110
    return -1;
 
13111
}
 
13112
 
 
13113
/**
12335
13114
 * virStorageVolFree:
12336
13115
 * @vol: pointer to storage volume
12337
13116
 *
12444
13223
/**
12445
13224
 * virStorageVolGetXMLDesc:
12446
13225
 * @vol: pointer to storage volume
12447
 
 * @flags: flags for XML generation (unused, pass 0)
 
13226
 * @flags: extra flags; not used yet, so callers should always pass 0
12448
13227
 *
12449
13228
 * Fetch an XML document describing all aspects of
12450
13229
 * the storage volume
12528
13307
    return NULL;
12529
13308
}
12530
13309
 
 
13310
/**
 
13311
 * virStorageVolResize:
 
13312
 * @vol: pointer to storage volume
 
13313
 * @capacity: new capacity, in bytes
 
13314
 * @flags: bitwise-OR of virStorageVolResizeFlags
 
13315
 *
 
13316
 * Changes the capacity of the storage volume @vol to @capacity. The
 
13317
 * operation will fail if the new capacity requires allocation that would
 
13318
 * exceed the remaining free space in the parent pool.  The contents of
 
13319
 * the new capacity will appear as all zero bytes.
 
13320
 *
 
13321
 * Normally, the operation will attempt to affect capacity with a minimum
 
13322
 * impact on allocation (that is, the default operation favors a sparse
 
13323
 * resize).  If @flags contains VIR_STORAGE_VOL_RESIZE_ALLOCATE, then the
 
13324
 * operation will ensure that allocation is sufficient for the new
 
13325
 * capacity; this may make the operation take noticeably longer.
 
13326
 *
 
13327
 * Normally, the operation treats @capacity as the new size in bytes;
 
13328
 * but if @flags contains VIR_STORAGE_VOL_RESIZE_DELTA, then @capacity
 
13329
 * represents the size difference to add to the current size.  It is
 
13330
 * up to the storage pool implementation whether unaligned requests are
 
13331
 * rounded up to the next valid boundary, or rejected.
 
13332
 *
 
13333
 * Normally, this operation should only be used to enlarge capacity;
 
13334
 * but if @flags contains VIR_STORAGE_VOL_RESIZE_SHRINK, it is possible to
 
13335
 * attempt a reduction in capacity even though it might cause data loss.
 
13336
 * If VIR_STORAGE_VOL_RESIZE_DELTA is also present, then @capacity is
 
13337
 * subtracted from the current size; without it, @capacity represents
 
13338
 * the absolute new size regardless of whether it is larger or smaller
 
13339
 * than the current size.
 
13340
 *
 
13341
 * Returns 0 on success, or -1 on error.
 
13342
 */
 
13343
int
 
13344
virStorageVolResize(virStorageVolPtr vol,
 
13345
                    unsigned long long capacity,
 
13346
                    unsigned int flags)
 
13347
{
 
13348
    virConnectPtr conn;
 
13349
    VIR_DEBUG("vol=%p capacity=%llu flags=%x", vol, capacity, flags);
 
13350
 
 
13351
    virResetLastError();
 
13352
 
 
13353
    if (!VIR_IS_STORAGE_VOL(vol)) {
 
13354
        virLibStorageVolError(VIR_ERR_INVALID_STORAGE_VOL, __FUNCTION__);
 
13355
        virDispatchError(NULL);
 
13356
        return -1;
 
13357
    }
 
13358
 
 
13359
    conn = vol->conn;
 
13360
 
 
13361
    if (conn->flags & VIR_CONNECT_RO) {
 
13362
       virLibConnError(VIR_ERR_OPERATION_DENIED, __FUNCTION__);
 
13363
       goto error;
 
13364
    }
 
13365
 
 
13366
    /* Zero capacity is only valid with either delta or shrink.  */
 
13367
    if (capacity == 0 && !((flags & VIR_STORAGE_VOL_RESIZE_DELTA) ||
 
13368
                           (flags & VIR_STORAGE_VOL_RESIZE_SHRINK))) {
 
13369
        virLibStorageVolError(VIR_ERR_INVALID_ARG, __FUNCTION__);
 
13370
        goto error;
 
13371
    }
 
13372
 
 
13373
    if (conn->storageDriver && conn->storageDriver->volResize) {
 
13374
        int ret;
 
13375
        ret = conn->storageDriver->volResize(vol, capacity, flags);
 
13376
        if (ret < 0)
 
13377
            goto error;
 
13378
        return ret;
 
13379
    }
 
13380
 
 
13381
    virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
 
13382
 
 
13383
error:
 
13384
    virDispatchError(vol->conn);
 
13385
    return -1;
 
13386
}
12531
13387
 
12532
13388
/**
12533
13389
 * virNodeNumOfDevices:
12534
13390
 * @conn: pointer to the hypervisor connection
12535
13391
 * @cap: capability name
12536
 
 * @flags: flags (unused, pass 0)
 
13392
 * @flags: extra flags; not used yet, so callers should always pass 0
12537
13393
 *
12538
13394
 * Provides the number of node devices.
12539
13395
 *
12577
13433
 * @cap: capability name
12578
13434
 * @names: array to collect the list of node device names
12579
13435
 * @maxnames: size of @names
12580
 
 * @flags: flags (unused, pass 0)
 
13436
 * @flags: extra flags; not used yet, so callers should always pass 0
12581
13437
 *
12582
13438
 * Collect the list of node devices, and store their names in @names
12583
13439
 *
12668
13524
/**
12669
13525
 * virNodeDeviceGetXMLDesc:
12670
13526
 * @dev: pointer to the node device
12671
 
 * @flags: flags for XML generation (unused, pass 0)
 
13527
 * @flags: extra flags; not used yet, so callers should always pass 0
12672
13528
 *
12673
13529
 * Fetch an XML document describing all aspects of
12674
13530
 * the device.
13053
13909
 * virNodeDeviceCreateXML:
13054
13910
 * @conn: pointer to the hypervisor connection
13055
13911
 * @xmlDesc: string containing an XML description of the device to be created
13056
 
 * @flags: callers should always pass 0
 
13912
 * @flags: extra flags; not used yet, so callers should always pass 0
13057
13913
 *
13058
13914
 * Create a new device on the VM host machine, for example, virtual
13059
13915
 * HBAs created using vport_create.
13498
14354
 * virSecretDefineXML:
13499
14355
 * @conn: virConnect connection
13500
14356
 * @xml: XML describing the secret.
13501
 
 * @flags: flags, use 0 for now
 
14357
 * @flags: extra flags; not used yet, so callers should always pass 0
13502
14358
 *
13503
14359
 * If XML specifies a UUID, locates the specified secret and replaces all
13504
14360
 * attributes of the secret specified by UUID by attributes specified in xml
13681
14537
/**
13682
14538
 * virSecretGetXMLDesc:
13683
14539
 * @secret: A virSecret secret
13684
 
 * @flags: flags, use 0 for now
 
14540
 * @flags: extra flags; not used yet, so callers should always pass 0
13685
14541
 *
13686
14542
 * Fetches an XML document describing attributes of the secret.
13687
14543
 *
13725
14581
 * @secret: A virSecret secret
13726
14582
 * @value: Value of the secret
13727
14583
 * @value_size: Size of the value
13728
 
 * @flags: flags, use 0 for now
 
14584
 * @flags: extra flags; not used yet, so callers should always pass 0
13729
14585
 *
13730
14586
 * Sets the value of a secret.
13731
14587
 *
13777
14633
 * virSecretGetValue:
13778
14634
 * @secret: A virSecret connection
13779
14635
 * @value_size: Place for storing size of the secret value
13780
 
 * @flags: flags, use 0 for now
 
14636
 * @flags: extra flags; not used yet, so callers should always pass 0
13781
14637
 *
13782
14638
 * Fetches the value of a secret.
13783
14639
 *
13931
14787
/**
13932
14788
 * virStreamNew:
13933
14789
 * @conn: pointer to the connection
13934
 
 * @flags: control features of the stream
 
14790
 * @flags: bitwise-OR of virStreamFlags
13935
14791
 *
13936
14792
 * Creates a new stream object which can be used to perform
13937
14793
 * streamed I/O with other public API function.
15323
16179
/**
15324
16180
 * virNWFilterGetXMLDesc:
15325
16181
 * @nwfilter: a nwfilter object
15326
 
 * @flags: an OR'ed set of extraction flags, not used yet
 
16182
 * @flags: extra flags; not used yet, so callers should always pass 0
15327
16183
 *
15328
16184
 * Provide an XML description of the network filter. The description may be
15329
16185
 * reused later to redefine the network filter with virNWFilterCreateXML().
15505
16361
 * virConnectCompareCPU:
15506
16362
 * @conn: virConnect connection
15507
16363
 * @xmlDesc: XML describing the CPU to compare with host CPU
15508
 
 * @flags: currently unused, pass 0
 
16364
 * @flags: extra flags; not used yet, so callers should always pass 0
15509
16365
 *
15510
16366
 * Compares the given CPU description with the host CPU
15511
16367
 *
15553
16409
 * @conn: virConnect connection
15554
16410
 * @xmlCPUs: array of XML descriptions of host CPUs
15555
16411
 * @ncpus: number of CPUs in xmlCPUs
15556
 
 * @flags: fine-tuning flags, currently unused, pass 0.
 
16412
 * @flags: extra flags; not used yet, so callers should always pass 0
15557
16413
 *
15558
16414
 * Computes the most feature-rich CPU which is compatible with all given
15559
16415
 * host CPUs.
15704
16560
 * virDomainMigrateSetMaxDowntime:
15705
16561
 * @domain: a domain object
15706
16562
 * @downtime: maximum tolerable downtime for live migration, in milliseconds
15707
 
 * @flags: fine-tuning flags, currently unused, use 0
 
16563
 * @flags: extra flags; not used yet, so callers should always pass 0
15708
16564
 *
15709
16565
 * Sets maximum tolerable time for which the domain is allowed to be paused
15710
16566
 * at the end of live migration. It's supposed to be called while the domain is
15751
16607
 * virDomainMigrateSetMaxSpeed:
15752
16608
 * @domain: a domain object
15753
16609
 * @bandwidth: migration bandwidth limit in Mbps
15754
 
 * @flags: fine-tuning flags, currently unused, use 0
 
16610
 * @flags: extra flags; not used yet, so callers should always pass 0
15755
16611
 *
15756
16612
 * The maximum bandwidth (in Mbps) that will be used to do migration
15757
16613
 * can be specified with the bandwidth parameter. Not all hypervisors
15798
16654
 * virDomainMigrateGetMaxSpeed:
15799
16655
 * @domain: a domain object
15800
16656
 * @bandwidth: return value of current migration bandwidth limit in Mbps
15801
 
 * @flags: fine-tuning flags, currently unused, use 0
 
16657
 * @flags: extra flags; not used yet, so callers should always pass 0
15802
16658
 *
15803
16659
 * Get the current maximum bandwidth (in Mbps) that will be used if the
15804
16660
 * domain is migrated.  Not all hypervisors will support a bandwidth limit.
15862
16718
 * is non-NULL, then only the specific domain will be monitored
15863
16719
 *
15864
16720
 * Most types of event have a callback providing a custom set of parameters
15865
 
 * for the event. When registering an event, it is thus neccessary to use
 
16721
 * for the event. When registering an event, it is thus necessary to use
15866
16722
 * the VIR_DOMAIN_EVENT_CALLBACK() macro to cast the supplied function pointer
15867
16723
 * to match the signature of this method.
15868
16724
 *
16037
16893
/**
16038
16894
 * virDomainHasManagedSaveImage:
16039
16895
 * @dom: pointer to the domain
16040
 
 * @flags: optional flags currently unused
 
16896
 * @flags: extra flags; not used yet, so callers should always pass 0
16041
16897
 *
16042
16898
 * Check if a domain has a managed save image as created by
16043
16899
 * virDomainManagedSave(). Note that any running domain should not have
16081
16937
/**
16082
16938
 * virDomainManagedSaveRemove:
16083
16939
 * @dom: pointer to the domain
16084
 
 * @flags: optional flags currently unused
 
16940
 * @flags: extra flags; not used yet, so callers should always pass 0
16085
16941
 *
16086
16942
 * Remove any managed save image for this domain.
16087
16943
 *
16252
17108
 * inconsistent (as if power had been pulled), and specifying this
16253
17109
 * with the VIR_DOMAIN_SNAPSHOT_CREATE_HALT flag risks data loss.
16254
17110
 *
 
17111
 * If @flags includes VIR_DOMAIN_SNAPSHOT_CREATE_QUIESCE, then the
 
17112
 * libvirt will attempt to use guest agent to freeze and thaw all
 
17113
 * file systems in use within domain OS. However, if the guest agent
 
17114
 * is not present, an error is thrown. Moreover, this flag requires
 
17115
 * VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY to be passed as well.
 
17116
 *
 
17117
 * By default, if the snapshot involves external files, and any of the
 
17118
 * destination files already exist as a non-empty regular file, the
 
17119
 * snapshot is rejected to avoid losing contents of those files.
 
17120
 * However, if @flags includes VIR_DOMAIN_SNAPSHOT_CREATE_REUSE_EXT,
 
17121
 * then the destination files must already exist and contain content
 
17122
 * identical to the source files (this allows a management app to
 
17123
 * pre-create files with relative backing file names, rather than the
 
17124
 * default of creating with absolute backing file names).
 
17125
 *
 
17126
 * Be aware that although libvirt prefers to report errors up front with
 
17127
 * no other effect, some hypervisors have certain types of failures where
 
17128
 * the overall command can easily fail even though the guest configuration
 
17129
 * was partially altered (for example, if a disk snapshot request for two
 
17130
 * disks fails on the second disk, but the first disk alteration cannot be
 
17131
 * rolled back).  If this API call fails, it is therefore normally
 
17132
 * necessary to follow up with virDomainGetXMLDesc() and check each disk
 
17133
 * to determine if any partial changes occurred.  However, if @flags
 
17134
 * contains VIR_DOMAIN_SNAPSHOT_CREATE_ATOMIC, then libvirt guarantees
 
17135
 * that this command will not alter any disks unless the entire set of
 
17136
 * changes can be done atomically, making failure recovery simpler (note
 
17137
 * that it is still possible to fail after disks have changed, but only
 
17138
 * in the much rarer cases of running out of memory or disk space).
 
17139
 *
 
17140
 * Some hypervisors may prevent this operation if there is a current
 
17141
 * block copy operation; in that case, use virDomainBlockJobAbort()
 
17142
 * to stop the block copy first.
 
17143
 *
16255
17144
 * Returns an (opaque) virDomainSnapshotPtr on success, NULL on failure.
16256
17145
 */
16257
17146
virDomainSnapshotPtr
16372
17261
/**
16373
17262
 * virDomainSnapshotNum:
16374
17263
 * @domain: a domain object
16375
 
 * @flags: bitwise-or of supported virDomainSnapshotListFlags
 
17264
 * @flags: bitwise-OR of supported virDomainSnapshotListFlags
16376
17265
 *
16377
17266
 * Provides the number of domain snapshots for this domain.
16378
17267
 *
16423
17312
 * @domain: a domain object
16424
17313
 * @names: array to collect the list of names of snapshots
16425
17314
 * @nameslen: size of @names
16426
 
 * @flags: bitwise-or of supported virDomainSnapshotListFlags
 
17315
 * @flags: bitwise-OR of supported virDomainSnapshotListFlags
16427
17316
 *
16428
17317
 * Collect the list of domain snapshots for the given domain, and store
16429
17318
 * their names in @names.  Caller is responsible for freeing each member
16484
17373
/**
16485
17374
 * virDomainSnapshotNumChildren:
16486
17375
 * @snapshot: a domain snapshot object
16487
 
 * @flags: bitwise-or of supported virDomainSnapshotListFlags
 
17376
 * @flags: bitwise-OR of supported virDomainSnapshotListFlags
16488
17377
 *
16489
17378
 * Provides the number of child snapshots for this domain snapshot.
16490
17379
 *
16536
17425
 * @snapshot: a domain snapshot object
16537
17426
 * @names: array to collect the list of names of snapshots
16538
17427
 * @nameslen: size of @names
16539
 
 * @flags: bitwise-or of supported virDomainSnapshotListFlags
 
17428
 * @flags: bitwise-OR of supported virDomainSnapshotListFlags
16540
17429
 *
16541
17430
 * Collect the list of domain snapshots that are children of the given
16542
17431
 * snapshot, and store their names in @names.  Caller is responsible for
16602
17491
 * virDomainSnapshotLookupByName:
16603
17492
 * @domain: a domain object
16604
17493
 * @name: name for the domain snapshot
16605
 
 * @flags: unused flag parameters; callers should pass 0
 
17494
 * @flags: extra flags; not used yet, so callers should always pass 0
16606
17495
 *
16607
17496
 * Try to lookup a domain snapshot based on its name.
16608
17497
 *
16651
17540
/**
16652
17541
 * virDomainHasCurrentSnapshot:
16653
17542
 * @domain: pointer to the domain object
16654
 
 * @flags: unused flag parameters; callers should pass 0
 
17543
 * @flags: extra flags; not used yet, so callers should always pass 0
16655
17544
 *
16656
17545
 * Determine if the domain has a current snapshot.
16657
17546
 *
16690
17579
/**
16691
17580
 * virDomainSnapshotCurrent:
16692
17581
 * @domain: a domain object
16693
 
 * @flags: unused flag parameters; callers should pass 0
 
17582
 * @flags: extra flags; not used yet, so callers should always pass 0
16694
17583
 *
16695
17584
 * Get the current snapshot for a domain, if any.
16696
17585
 *
16733
17622
/**
16734
17623
 * virDomainSnapshotGetParent:
16735
17624
 * @snapshot: a snapshot object
16736
 
 * @flags: unused flag parameters; callers should pass 0
 
17625
 * @flags: extra flags; not used yet, so callers should always pass 0
16737
17626
 *
16738
17627
 * Get the parent snapshot for @snapshot, if any.
16739
17628
 *
16863
17752
/**
16864
17753
 * virDomainSnapshotDelete:
16865
17754
 * @snapshot: a domain snapshot object
16866
 
 * @flags: bitwise-or of supported virDomainSnapshotDeleteFlags
 
17755
 * @flags: bitwise-OR of supported virDomainSnapshotDeleteFlags
16867
17756
 *
16868
17757
 * Delete the snapshot.
16869
17758
 *
16962
17851
 * @dom: a domain object
16963
17852
 * @dev_name: the console, serial or parallel port device alias, or NULL
16964
17853
 * @st: a stream to associate with the console
16965
 
 * @flags: unused, pass 0
 
17854
 * @flags: bitwise-OR of virDomainConsoleFlags
16966
17855
 *
16967
17856
 * This opens the backend associated with a console, serial or
16968
17857
 * parallel port device on a guest, if the backend is supported.
16971
17860
 * in @st stream, which should have been opened in non-blocking
16972
17861
 * mode for bi-directional I/O.
16973
17862
 *
16974
 
 * returns 0 if the console was opened, -1 on error
 
17863
 * By default, when @flags is 0, the open will fail if libvirt
 
17864
 * detects that the console is already in use by another client;
 
17865
 * passing VIR_DOMAIN_CONSOLE_FORCE will cause libvirt to forcefully
 
17866
 * remove the other client prior to opening this console.
 
17867
 *
 
17868
 * If flag VIR_DOMAIN_CONSOLE_SAFE the console is opened only in the
 
17869
 * case where the hypervisor driver supports safe (mutually exclusive)
 
17870
 * console handling.
 
17871
 *
 
17872
 * Older servers did not support either flag, and also did not forbid
 
17873
 * simultaneous clients on a console, with potentially confusing results.
 
17874
 * When passing @flags of 0 in order to support a wider range of server
 
17875
 * versions, it is up to the client to ensure mutual exclusion.
 
17876
 *
 
17877
 * Returns 0 if the console was opened, -1 on error
16975
17878
 */
16976
17879
int virDomainOpenConsole(virDomainPtr dom,
16977
17880
                         const char *dev_name,
17016
17919
 * virDomainBlockJobAbort:
17017
17920
 * @dom: pointer to domain object
17018
17921
 * @disk: path to the block device, or device shorthand
17019
 
 * @flags: currently unused, for future extension
 
17922
 * @flags: bitwise-OR of virDomainBlockJobAbortFlags
17020
17923
 *
17021
17924
 * Cancel the active block job on the given disk.
17022
17925
 *
17027
17930
 * can be found by calling virDomainGetXMLDesc() and inspecting
17028
17931
 * elements within //domain/devices/disk.
17029
17932
 *
 
17933
 * If the current block job for @disk is VIR_DOMAIN_BLOCK_JOB_TYPE_PULL, then
 
17934
 * by default, this function performs a synchronous operation and the caller
 
17935
 * may assume that the operation has completed when 0 is returned.  However,
 
17936
 * BlockJob operations may take a long time to cancel, and during this time
 
17937
 * further domain interactions may be unresponsive.  To avoid this problem,
 
17938
 * pass VIR_DOMAIN_BLOCK_JOB_ABORT_ASYNC in the @flags argument to enable
 
17939
 * asynchronous behavior, returning as soon as possible.  When the job has
 
17940
 * been canceled, a BlockJob event will be emitted, with status
 
17941
 * VIR_DOMAIN_BLOCK_JOB_CANCELED (even if the ABORT_ASYNC flag was not
 
17942
 * used); it is also possible to poll virDomainBlockJobInfo() to see if
 
17943
 * the job cancellation is still pending.  This type of job can be restarted
 
17944
 * to pick up from where it left off.
 
17945
 *
 
17946
 * If the current block job for @disk is VIR_DOMAIN_BLOCK_JOB_TYPE_COPY, then
 
17947
 * the default is to abort the mirroring and revert to the source disk;
 
17948
 * adding @flags of VIR_DOMAIN_BLOCK_JOB_ABORT_PIVOT causes this call to
 
17949
 * fail with VIR_ERR_BLOCK_COPY_ACTIVE if the copy is not fully populated,
 
17950
 * otherwise it will swap the disk over to the copy to end the mirroring.  An
 
17951
 * event will be issued when the job is ended, and it is possible to use
 
17952
 * VIR_DOMAIN_BLOCK_JOB_ABORT_ASYNC to control whether this command waits
 
17953
 * for the completion of the job.  Restarting this job requires starting
 
17954
 * over from the beginning of the first phase.
 
17955
 *
17030
17956
 * Returns -1 in case of failure, 0 when successful.
17031
17957
 */
17032
17958
int virDomainBlockJobAbort(virDomainPtr dom, const char *disk,
17034
17960
{
17035
17961
    virConnectPtr conn;
17036
17962
 
17037
 
    VIR_DOMAIN_DEBUG(dom, "disk=%p, flags=%x", disk, flags);
 
17963
    VIR_DOMAIN_DEBUG(dom, "disk=%s, flags=%x", disk, flags);
17038
17964
 
17039
17965
    virResetLastError();
17040
17966
 
17076
18002
 * @dom: pointer to domain object
17077
18003
 * @disk: path to the block device, or device shorthand
17078
18004
 * @info: pointer to a virDomainBlockJobInfo structure
17079
 
 * @flags: currently unused, for future extension
 
18005
 * @flags: extra flags; not used yet, so callers should always pass 0
17080
18006
 *
17081
18007
 * Request block job information for the given disk.  If an operation is active
17082
18008
 * @info will be updated with the current progress.
17095
18021
{
17096
18022
    virConnectPtr conn;
17097
18023
 
17098
 
    VIR_DOMAIN_DEBUG(dom, "disk=%p, info=%p, flags=%x", disk, info, flags);
 
18024
    VIR_DOMAIN_DEBUG(dom, "disk=%s, info=%p, flags=%x", disk, info, flags);
17099
18025
 
17100
18026
    virResetLastError();
17101
18027
 
17138
18064
 * @dom: pointer to domain object
17139
18065
 * @disk: path to the block device, or device shorthand
17140
18066
 * @bandwidth: specify bandwidth limit in Mbps
17141
 
 * @flags: currently unused, for future extension
 
18067
 * @flags: extra flags; not used yet, so callers should always pass 0
17142
18068
 *
17143
18069
 * Set the maximimum allowable bandwidth that a block job may consume.  If
17144
18070
 * bandwidth is 0, the limit will revert to the hypervisor default.
17157
18083
{
17158
18084
    virConnectPtr conn;
17159
18085
 
17160
 
    VIR_DOMAIN_DEBUG(dom, "disk=%p, bandwidth=%lu, flags=%x",
 
18086
    VIR_DOMAIN_DEBUG(dom, "disk=%s, bandwidth=%lu, flags=%x",
17161
18087
                     disk, bandwidth, flags);
17162
18088
 
17163
18089
    virResetLastError();
17200
18126
 * @dom: pointer to domain object
17201
18127
 * @disk: path to the block device, or device shorthand
17202
18128
 * @bandwidth: (optional) specify copy bandwidth limit in Mbps
17203
 
 * @flags: currently unused, for future extension
 
18129
 * @flags: extra flags; not used yet, so callers should always pass 0
17204
18130
 *
17205
18131
 * Populate a disk image with data from its backing image.  Once all data from
17206
18132
 * its backing image has been pulled, the disk no longer depends on a backing
17219
18145
 * The maximum bandwidth (in Mbps) that will be used to do the copy can be
17220
18146
 * specified with the bandwidth parameter.  If set to 0, libvirt will choose a
17221
18147
 * suitable default.  Some hypervisors do not support this feature and will
17222
 
 * return an error if bandwidth is not 0.
 
18148
 * return an error if bandwidth is not 0; in this case, it might still be
 
18149
 * possible for a later call to virDomainBlockJobSetSpeed() to succeed.
 
18150
 * The actual speed can be determined with virDomainGetBlockJobInfo().
 
18151
 *
 
18152
 * This is shorthand for virDomainBlockRebase() with a NULL base.
17223
18153
 *
17224
18154
 * Returns 0 if the operation has started, -1 on failure.
17225
18155
 */
17228
18158
{
17229
18159
    virConnectPtr conn;
17230
18160
 
17231
 
    VIR_DOMAIN_DEBUG(dom, "disk=%p, bandwidth=%lu, flags=%x",
 
18161
    VIR_DOMAIN_DEBUG(dom, "disk=%s, bandwidth=%lu, flags=%x",
17232
18162
                     disk, bandwidth, flags);
17233
18163
 
17234
18164
    virResetLastError();
17268
18198
 
17269
18199
 
17270
18200
/**
 
18201
 * virDomainBlockRebase:
 
18202
 * @dom: pointer to domain object
 
18203
 * @disk: path to the block device, or device shorthand
 
18204
 * @base: path to backing file to keep, or NULL for no backing file
 
18205
 * @bandwidth: (optional) specify copy bandwidth limit in Mbps
 
18206
 * @flags: bitwise-OR of virDomainBlockRebaseFlags
 
18207
 *
 
18208
 * Populate a disk image with data from its backing image chain, and
 
18209
 * setting the backing image to @base, or alternatively copy an entire
 
18210
 * backing chain to a new file @base.
 
18211
 *
 
18212
 * When @flags is 0, this starts a pull, where @base must be the absolute
 
18213
 * path of one of the backing images further up the chain, or NULL to
 
18214
 * convert the disk image so that it has no backing image.  Once all
 
18215
 * data from its backing image chain has been pulled, the disk no
 
18216
 * longer depends on those intermediate backing images.  This function
 
18217
 * pulls data for the entire device in the background.  Progress of
 
18218
 * the operation can be checked with virDomainGetBlockJobInfo() with a
 
18219
 * job type of VIR_DOMAIN_BLOCK_JOB_TYPE_PULL, and the operation can be
 
18220
 * aborted with virDomainBlockJobAbort().  When finished, an asynchronous
 
18221
 * event is raised to indicate the final status, and the job no longer
 
18222
 * exists.  If the job is aborted, a new one can be started later to
 
18223
 * resume from the same point.
 
18224
 *
 
18225
 * When @flags includes VIR_DOMAIN_BLOCK_REBASE_COPY, this starts a copy,
 
18226
 * where @base must be the name of a new file to copy the chain to.  By
 
18227
 * default, the copy will pull the entire source chain into the destination
 
18228
 * file, but if @flags also contains VIR_DOMAIN_BLOCK_REBASE_SHALLOW, then
 
18229
 * only the top of the source chain will be copied (the source and
 
18230
 * destination have a common backing file).  By default, @base will be
 
18231
 * created with the same file format as the source, but this can be altered
 
18232
 * by adding VIR_DOMAIN_BLOCK_REBASE_COPY_RAW to force the copy to be raw
 
18233
 * (does not make sense with the shallow flag unless the source is also raw),
 
18234
 * or by using VIR_DOMAIN_BLOCK_REBASE_REUSE_EXT to reuse an existing file
 
18235
 * with initial contents identical to the backing file of the source (this
 
18236
 * allows a management app to pre-create files with relative backing file
 
18237
 * names, rather than the default of absolute backing file names; as a
 
18238
 * security precaution, you should generally only use reuse_ext with the
 
18239
 * shallow flag and a non-raw destination file).
 
18240
 *
 
18241
 * A copy job has two parts; in the first phase, the @bandwidth parameter
 
18242
 * affects how fast the source is pulled into the destination, and the job
 
18243
 * can only be canceled by reverting to the source file; progress in this
 
18244
 * phase can be tracked via the virDomainBlockJobInfo() command, with a
 
18245
 * job type of VIR_DOMAIN_BLOCK_JOB_TYPE_COPY.  The job transitions to the
 
18246
 * second phase when the job info states cur == end, and remains alive to
 
18247
 * mirror all further changes to both source and destination.  The user
 
18248
 * must call virDomainBlockJobAbort() to end the mirroring while choosing
 
18249
 * whether to revert to source or pivot to the destination.  An event is
 
18250
 * issued when the job ends, and in the future, an event may be added when
 
18251
 * the job transitions from pulling to mirroring.  If the job is aborted,
 
18252
 * a new job will have to start over from the beginning of the first phase.
 
18253
 *
 
18254
 * Some hypervisors will restrict certain actions, such as virDomainSave()
 
18255
 * or virDomainDetachDevice(), while a copy job is active; they may
 
18256
 * also restrict a copy job to transient domains.
 
18257
 *
 
18258
 * The @disk parameter is either an unambiguous source name of the
 
18259
 * block device (the <source file='...'/> sub-element, such as
 
18260
 * "/path/to/image"), or the device target shorthand (the
 
18261
 * <target dev='...'/> sub-element, such as "xvda").  Valid names
 
18262
 * can be found by calling virDomainGetXMLDesc() and inspecting
 
18263
 * elements within //domain/devices/disk.
 
18264
 *
 
18265
 * The maximum bandwidth (in Mbps) that will be used to do the copy can be
 
18266
 * specified with the bandwidth parameter.  If set to 0, libvirt will choose a
 
18267
 * suitable default.  Some hypervisors do not support this feature and will
 
18268
 * return an error if bandwidth is not 0; in this case, it might still be
 
18269
 * possible for a later call to virDomainBlockJobSetSpeed() to succeed.
 
18270
 * The actual speed can be determined with virDomainGetBlockJobInfo().
 
18271
 *
 
18272
 * When @base is NULL and @flags is 0, this is identical to
 
18273
 * virDomainBlockPull().
 
18274
 *
 
18275
 * Returns 0 if the operation has started, -1 on failure.
 
18276
 */
 
18277
int virDomainBlockRebase(virDomainPtr dom, const char *disk,
 
18278
                         const char *base, unsigned long bandwidth,
 
18279
                         unsigned int flags)
 
18280
{
 
18281
    virConnectPtr conn;
 
18282
 
 
18283
    VIR_DOMAIN_DEBUG(dom, "disk=%s, base=%s bandwidth=%lu, flags=%x",
 
18284
                     disk, NULLSTR(base), bandwidth, flags);
 
18285
 
 
18286
    virResetLastError();
 
18287
 
 
18288
    if (!VIR_IS_CONNECTED_DOMAIN (dom)) {
 
18289
        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
 
18290
        virDispatchError(NULL);
 
18291
        return -1;
 
18292
    }
 
18293
    conn = dom->conn;
 
18294
 
 
18295
    if (dom->conn->flags & VIR_CONNECT_RO) {
 
18296
        virLibDomainError(VIR_ERR_OPERATION_DENIED, __FUNCTION__);
 
18297
        goto error;
 
18298
    }
 
18299
 
 
18300
    if (!disk) {
 
18301
        virLibDomainError(VIR_ERR_INVALID_ARG,
 
18302
                          _("disk is NULL"));
 
18303
        goto error;
 
18304
    }
 
18305
 
 
18306
    if (flags & VIR_DOMAIN_BLOCK_REBASE_COPY) {
 
18307
        if (!base) {
 
18308
            virLibDomainError(VIR_ERR_INVALID_ARG,
 
18309
                              _("base is required when starting a copy"));
 
18310
            goto error;
 
18311
        }
 
18312
    } else if (flags & (VIR_DOMAIN_BLOCK_REBASE_SHALLOW |
 
18313
                        VIR_DOMAIN_BLOCK_REBASE_REUSE_EXT |
 
18314
                        VIR_DOMAIN_BLOCK_REBASE_COPY_RAW)) {
 
18315
        virLibDomainError(VIR_ERR_INVALID_ARG,
 
18316
                          _("use of flags requires a copy job"));
 
18317
        goto error;
 
18318
    }
 
18319
 
 
18320
    if (conn->driver->domainBlockRebase) {
 
18321
        int ret;
 
18322
        ret = conn->driver->domainBlockRebase(dom, disk, base, bandwidth,
 
18323
                                              flags);
 
18324
        if (ret < 0)
 
18325
            goto error;
 
18326
        return ret;
 
18327
    }
 
18328
 
 
18329
    virLibDomainError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
 
18330
 
 
18331
error:
 
18332
    virDispatchError(dom->conn);
 
18333
    return -1;
 
18334
}
 
18335
 
 
18336
 
 
18337
/**
17271
18338
 * virDomainOpenGraphics:
17272
18339
 * @dom: pointer to domain object
17273
18340
 * @idx: index of graphics config to open
17274
18341
 * @fd: file descriptor to attach graphics to
17275
 
 * @flags: flags to control open operation
 
18342
 * @flags: bitwise-OR of virDomainOpenGraphicsFlags
17276
18343
 *
17277
18344
 * This will attempt to connect the file descriptor @fd, to
17278
18345
 * the graphics backend of @dom. If @dom has multiple graphics
17370
18437
 * messages.  Failure to do so may result in connections being closed
17371
18438
 * unexpectedly.
17372
18439
 *
 
18440
 * Note: This API function controls only keepalive messages sent by the client.
 
18441
 * If the server is configured to use keepalive you still need to run the event
 
18442
 * loop to respond to them, even if you disable keepalives by this function.
 
18443
 *
17373
18444
 * Returns -1 on error, 0 on success, 1 when remote party doesn't support
17374
18445
 * keepalive messages.
17375
18446
 */
17389
18460
        return -1;
17390
18461
    }
17391
18462
 
17392
 
    if (interval <= 0) {
17393
 
        virLibConnError(VIR_ERR_INVALID_ARG,
17394
 
                        _("negative or zero interval make no sense"));
17395
 
        goto error;
17396
 
    }
17397
 
 
17398
18463
    if (conn->driver->setKeepAlive) {
17399
18464
        ret = conn->driver->setKeepAlive(conn, interval, count);
17400
18465
        if (ret < 0)
17453
18518
 * @params: Pointer to blkio parameter objects
17454
18519
 * @nparams: Number of blkio parameters (this value can be the same or
17455
18520
 *           less than the number of parameters supported)
17456
 
 * @flags: An OR'ed set of virDomainModificationImpact
 
18521
 * @flags: bitwise-OR of virDomainModificationImpact
17457
18522
 *
17458
18523
 * Change all or a subset of the per-device block IO tunables.
17459
18524
 *
17474
18539
{
17475
18540
    virConnectPtr conn;
17476
18541
 
17477
 
    VIR_DOMAIN_DEBUG(dom, "disk=%p, params=%p, nparams=%d, flags=%x",
 
18542
    VIR_DOMAIN_DEBUG(dom, "disk=%s, params=%p, nparams=%d, flags=%x",
17478
18543
                     disk, params, nparams, flags);
17479
18544
 
17480
18545
    virResetLastError();
17522
18587
 * @params: Pointer to blkio parameter object
17523
18588
 *          (return value, allocated by the caller)
17524
18589
 * @nparams: Pointer to number of blkio parameters
17525
 
 * @flags: An OR'ed set of virDomainModificationImpact
 
18590
 * @flags: bitwise-OR of virDomainModificationImpact and virTypedParameterFlags
17526
18591
 *
17527
18592
 * Get all block IO tunable parameters for a given device.  On input,
17528
18593
 * @nparams gives the size of the @params array; on output, @nparams
17556
18621
{
17557
18622
    virConnectPtr conn;
17558
18623
 
17559
 
    VIR_DOMAIN_DEBUG(dom, "disk=%p, params=%p, nparams=%d, flags=%x",
 
18624
    VIR_DOMAIN_DEBUG(dom, "disk=%s, params=%p, nparams=%d, flags=%x",
17560
18625
                     NULLSTR(disk), params, (nparams) ? *nparams : -1, flags);
17561
18626
 
17562
18627
    virResetLastError();
17599
18664
    virDispatchError(dom->conn);
17600
18665
    return -1;
17601
18666
}
 
18667
 
 
18668
/**
 
18669
 * virDomainGetCPUStats:
 
18670
 * @domain: domain to query
 
18671
 * @params: array to populate on output
 
18672
 * @nparams: number of parameters per cpu
 
18673
 * @start_cpu: which cpu to start with, or -1 for summary
 
18674
 * @ncpus: how many cpus to query
 
18675
 * @flags: bitwise-OR of virTypedParameterFlags
 
18676
 *
 
18677
 * Get statistics relating to CPU usage attributable to a single
 
18678
 * domain (in contrast to the statistics returned by
 
18679
 * virNodeGetCPUStats() for all processes on the host).  @dom
 
18680
 * must be running (an inactive domain has no attributable cpu
 
18681
 * usage).  On input, @params must contain at least @nparams * @ncpus
 
18682
 * entries, allocated by the caller.
 
18683
 *
 
18684
 * If @start_cpu is -1, then @ncpus must be 1, and the returned
 
18685
 * results reflect the statistics attributable to the entire
 
18686
 * domain (such as user and system time for the process as a
 
18687
 * whole).  Otherwise, @start_cpu represents which cpu to start
 
18688
 * with, and @ncpus represents how many consecutive processors to
 
18689
 * query, with statistics attributable per processor (such as
 
18690
 * per-cpu usage).  If @ncpus is larger than the number of cpus
 
18691
 * available to query, then the trailing part of the array will
 
18692
 * be unpopulated.
 
18693
 *
 
18694
 * The remote driver imposes a limit of 128 @ncpus and 16 @nparams;
 
18695
 * the number of parameters per cpu should not exceed 16, but if you
 
18696
 * have a host with more than 128 CPUs, your program should split
 
18697
 * the request into multiple calls.
 
18698
 *
 
18699
 * As special cases, if @params is NULL and @nparams is 0 and
 
18700
 * @ncpus is 1, and the return value will be how many
 
18701
 * statistics are available for the given @start_cpu.  This number
 
18702
 * may be different for @start_cpu of -1 than for any non-negative
 
18703
 * value, but will be the same for all non-negative @start_cpu.
 
18704
 * Likewise, if @params is NULL and @nparams is 0 and @ncpus is 0,
 
18705
 * the number of cpus available to query is returned.  From the
 
18706
 * host perspective, this would typically match the cpus member
 
18707
 * of virNodeGetInfo(), but might be less due to host cpu hotplug.
 
18708
 *
 
18709
 * For now, @flags is unused, and the statistics all relate to the
 
18710
 * usage from the host perspective.  It is possible that a future
 
18711
 * version will support a flag that queries the cpu usage from the
 
18712
 * guest's perspective, where the maximum cpu to query would be
 
18713
 * related to virDomainGetVcpusFlags() rather than virNodeGetInfo().
 
18714
 * An individual guest vcpu cannot be reliably mapped back to a
 
18715
 * specific host cpu unless a single-processor vcpu pinning was used,
 
18716
 * but when @start_cpu is -1, any difference in usage between a host
 
18717
 * and guest perspective would serve as a measure of hypervisor overhead.
 
18718
 *
 
18719
 * Typical use sequence is below.
 
18720
 *
 
18721
 * getting total stats: set start_cpu as -1, ncpus 1
 
18722
 * virDomainGetCPUStats(dom, NULL, 0, -1, 1, 0) => nparams
 
18723
 * params = calloc(nparams, sizeof(virTypedParameter))
 
18724
 * virDomainGetCPUStats(dom, params, nparams, -1, 1, 0) => total stats.
 
18725
 *
 
18726
 * getting per-cpu stats:
 
18727
 * virDomainGetCPUStats(dom, NULL, 0, 0, 0, 0) => ncpus
 
18728
 * virDomainGetCPUStats(dom, NULL, 0, 0, 1, 0) => nparams
 
18729
 * params = calloc(ncpus * nparams, sizeof(virTypedParameter))
 
18730
 * virDomainGetCPUStats(dom, params, nparams, 0, ncpus, 0) => per-cpu stats
 
18731
 *
 
18732
 * Returns -1 on failure, or the number of statistics that were
 
18733
 * populated per cpu on success (this will be less than the total
 
18734
 * number of populated @params, unless @ncpus was 1; and may be
 
18735
 * less than @nparams).  The populated parameters start at each
 
18736
 * stride of @nparams, which means the results may be discontiguous;
 
18737
 * any unpopulated parameters will be zeroed on success (this includes
 
18738
 * skipped elements if @nparams is too large, and tail elements if
 
18739
 * @ncpus is too large).  The caller is responsible for freeing any
 
18740
 * returned string parameters.
 
18741
 */
 
18742
int virDomainGetCPUStats(virDomainPtr domain,
 
18743
                         virTypedParameterPtr params,
 
18744
                         unsigned int nparams,
 
18745
                         int start_cpu,
 
18746
                         unsigned int ncpus,
 
18747
                         unsigned int flags)
 
18748
{
 
18749
    virConnectPtr conn;
 
18750
 
 
18751
    VIR_DOMAIN_DEBUG(domain,
 
18752
                     "params=%p, nparams=%d, start_cpu=%d, ncpus=%u, flags=%x",
 
18753
                     params, nparams, start_cpu, ncpus, flags);
 
18754
    virResetLastError();
 
18755
 
 
18756
    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
 
18757
        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
 
18758
        virDispatchError(NULL);
 
18759
        return -1;
 
18760
    }
 
18761
 
 
18762
    conn = domain->conn;
 
18763
    /* Special cases:
 
18764
     * start_cpu must be non-negative, or else -1
 
18765
     * if start_cpu is -1, ncpus must be 1
 
18766
     * params == NULL must match nparams == 0
 
18767
     * ncpus must be non-zero unless params == NULL
 
18768
     * nparams * ncpus must not overflow (RPC may restrict it even more)
 
18769
     */
 
18770
    if (start_cpu < -1 ||
 
18771
        (start_cpu == -1 && ncpus != 1) ||
 
18772
        ((params == NULL) != (nparams == 0)) ||
 
18773
        (ncpus == 0 && params != NULL)) {
 
18774
        virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
 
18775
        goto error;
 
18776
    }
 
18777
    if (nparams && ncpus > UINT_MAX / nparams) {
 
18778
        virLibDomainError(VIR_ERR_OVERFLOW, _("input too large: %u * %u"),
 
18779
                          nparams, ncpus);
 
18780
        goto error;
 
18781
    }
 
18782
    if (VIR_DRV_SUPPORTS_FEATURE(domain->conn->driver, domain->conn,
 
18783
                                 VIR_DRV_FEATURE_TYPED_PARAM_STRING))
 
18784
        flags |= VIR_TYPED_PARAM_STRING_OKAY;
 
18785
 
 
18786
    if (conn->driver->domainGetCPUStats) {
 
18787
        int ret;
 
18788
 
 
18789
        ret = conn->driver->domainGetCPUStats(domain, params, nparams,
 
18790
                                              start_cpu, ncpus, flags);
 
18791
        if (ret < 0)
 
18792
            goto error;
 
18793
        return ret;
 
18794
    }
 
18795
 
 
18796
    virLibDomainError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
 
18797
 
 
18798
error:
 
18799
    virDispatchError(domain->conn);
 
18800
    return -1;
 
18801
}
 
18802
 
 
18803
/**
 
18804
 * virDomainGetDiskErrors:
 
18805
 * @dom: a domain object
 
18806
 * @errors: array to populate on output
 
18807
 * @maxerrors: size of @errors array
 
18808
 * @flags: extra flags; not used yet, so callers should always pass 0
 
18809
 *
 
18810
 * The function populates @errors array with all disks that encountered an
 
18811
 * I/O error.  Disks with no error will not be returned in the @errors array.
 
18812
 * Each disk is identified by its target (the dev attribute of target
 
18813
 * subelement in domain XML), such as "vda", and accompanied with the error
 
18814
 * that was seen on it.  The caller is also responsible for calling free()
 
18815
 * on each disk name returned.
 
18816
 *
 
18817
 * In a special case when @errors is NULL and @maxerrors is 0, the function
 
18818
 * returns preferred size of @errors that the caller should use to get all
 
18819
 * disk errors.
 
18820
 *
 
18821
 * Since calling virDomainGetDiskErrors(dom, NULL, 0, 0) to get preferred size
 
18822
 * of @errors array and getting the errors are two separate operations, new
 
18823
 * disks may be hotplugged to the domain and new errors may be encountered
 
18824
 * between the two calls.  Thus, this function may not return all disk errors
 
18825
 * because the supplied array is not large enough.  Such errors may, however,
 
18826
 * be detected by listening to domain events.
 
18827
 *
 
18828
 * Returns number of disks with errors filled in the @errors array or -1 on
 
18829
 * error.
 
18830
 */
 
18831
int
 
18832
virDomainGetDiskErrors(virDomainPtr dom,
 
18833
                       virDomainDiskErrorPtr errors,
 
18834
                       unsigned int maxerrors,
 
18835
                       unsigned int flags)
 
18836
{
 
18837
    VIR_DOMAIN_DEBUG(dom, "errors=%p, maxerrors=%u, flags=%x",
 
18838
                     errors, maxerrors, flags);
 
18839
 
 
18840
    virResetLastError();
 
18841
 
 
18842
    if (!VIR_IS_DOMAIN(dom)) {
 
18843
        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
 
18844
        virDispatchError(NULL);
 
18845
        return -1;
 
18846
    }
 
18847
 
 
18848
    if ((!errors && maxerrors) || (errors && !maxerrors)) {
 
18849
        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
 
18850
        goto error;
 
18851
    }
 
18852
 
 
18853
    if (dom->conn->driver->domainGetDiskErrors) {
 
18854
        int ret = dom->conn->driver->domainGetDiskErrors(dom, errors,
 
18855
                                                         maxerrors, flags);
 
18856
        if (ret < 0)
 
18857
            goto error;
 
18858
        return ret;
 
18859
    }
 
18860
 
 
18861
    virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
 
18862
 
 
18863
error:
 
18864
    virDispatchError(dom->conn);
 
18865
    return -1;
 
18866
}