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

« back to all changes in this revision

Viewing changes to src/libvirt.c

Tags: upstream-0.2.2
ImportĀ upstreamĀ versionĀ 0.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#include <libxml/parser.h>
22
22
#include <libxml/xpath.h>
23
23
 
24
 
#include <xs.h>
25
 
 
26
24
#include "internal.h"
27
25
#include "driver.h"
28
 
#include "xen_internal.h"
29
 
#include "xend_internal.h"
30
 
#include "xs_internal.h"
31
 
#include "proxy_internal.h"
 
26
 
32
27
#include "xml.h"
33
28
#include "test.h"
 
29
#include "xen_unified.h"
 
30
#include "qemu_internal.h"
34
31
 
35
32
/*
36
33
 * TODO:
37
34
 * - use lock to protect against concurrent accesses ?
38
35
 * - use reference counting to garantee coherent pointer state ?
39
 
 * - memory wrappers for malloc/free ?
40
36
 */
41
37
 
42
38
static virDriverPtr virDriverTab[MAX_DRIVERS];
 
39
static int virDriverTabCount = 0;
 
40
static virNetworkDriverPtr virNetworkDriverTab[MAX_DRIVERS];
 
41
static int virNetworkDriverTabCount = 0;
43
42
static int initialized = 0;
44
43
 
45
44
/**
54
53
int
55
54
virInitialize(void)
56
55
{
57
 
    int i;
58
 
 
59
56
    if (initialized)
60
57
        return(0);
61
58
    initialized = 1;
64
61
        return (-1);
65
62
 
66
63
    /*
67
 
     * should not be needed but...
 
64
     * Note that the order is important: the first ones have a higher
 
65
     * priority when calling virConnectOpen.
68
66
     */
69
 
    for (i = 0;i < MAX_DRIVERS;i++)
70
 
         virDriverTab[i] = NULL;
 
67
#ifdef WITH_XEN
 
68
    if (xenUnifiedRegister () == -1) return -1;
 
69
#endif
 
70
#ifdef WITH_TEST
 
71
    if (testRegister() == -1) return -1;
 
72
#endif
 
73
#ifdef WITH_QEMU
 
74
    if (qemuRegister() == -1) return -1;
 
75
#endif
71
76
 
72
 
    /*
73
 
     * Note that the order is important the first ones have a higher priority
74
 
     */
75
 
    xenHypervisorRegister();
76
 
    xenProxyRegister();
77
 
    xenDaemonRegister();
78
 
    xenStoreRegister();
79
 
    testRegister();
80
77
    return(0);
81
78
}
82
79
 
99
96
        return;
100
97
 
101
98
    errmsg = __virErrorMsg(error, info);
102
 
    __virRaiseError(conn, NULL, VIR_FROM_NONE, error, VIR_ERR_ERROR,
 
99
    __virRaiseError(conn, NULL, NULL, VIR_FROM_NONE, error, VIR_ERR_ERROR,
103
100
                    errmsg, info, NULL, 0, 0, errmsg, info);
104
101
}
105
102
 
125
122
    if (error != VIR_ERR_INVALID_DOMAIN) {
126
123
        conn = domain->conn;
127
124
    }
128
 
    __virRaiseError(conn, domain, VIR_FROM_DOM, error, VIR_ERR_ERROR,
129
 
                    errmsg, info, NULL, 0, 0, errmsg, info);
 
125
    __virRaiseError(conn, domain, NULL, VIR_FROM_DOM, error, VIR_ERR_ERROR,
 
126
                    errmsg, info, NULL, 0, 0, errmsg, info);
 
127
}
 
128
 
 
129
/**
 
130
 * virLibNetworkError:
 
131
 * @conn: the connection if available
 
132
 * @error: the error noumber
 
133
 * @info: extra information string
 
134
 *
 
135
 * Handle an error at the connection level
 
136
 */
 
137
static void
 
138
virLibNetworkError(virNetworkPtr network, virErrorNumber error,
 
139
                   const char *info)
 
140
{
 
141
    virConnectPtr conn = NULL;
 
142
    const char *errmsg;
 
143
 
 
144
    if (error == VIR_ERR_OK)
 
145
        return;
 
146
 
 
147
    errmsg = __virErrorMsg(error, info);
 
148
    if (error != VIR_ERR_INVALID_NETWORK) {
 
149
        conn = network->conn;
 
150
    }
 
151
    __virRaiseError(conn, NULL, network, VIR_FROM_NET, error, VIR_ERR_ERROR,
 
152
                    errmsg, info, NULL, 0, 0, errmsg, info);
 
153
}
 
154
 
 
155
/**
 
156
 * virRegisterNetworkDriver:
 
157
 * @driver: pointer to a network driver block
 
158
 *
 
159
 * Register a network virtualization driver
 
160
 *
 
161
 * Returns the driver priority or -1 in case of error.
 
162
 */
 
163
int
 
164
virRegisterNetworkDriver(virNetworkDriverPtr driver)
 
165
{
 
166
    if (virInitialize() < 0)
 
167
      return -1;
 
168
 
 
169
    if (driver == NULL) {
 
170
        virLibConnError(NULL, VIR_ERR_INVALID_ARG, __FUNCTION__);
 
171
        return(-1);
 
172
    }
 
173
 
 
174
    if (virNetworkDriverTabCount >= MAX_DRIVERS) {
 
175
        virLibConnError(NULL, VIR_ERR_INVALID_ARG, __FUNCTION__);
 
176
        return(-1);
 
177
    }
 
178
 
 
179
    virNetworkDriverTab[virNetworkDriverTabCount] = driver;
 
180
    return virNetworkDriverTabCount++;
130
181
}
131
182
 
132
183
/**
140
191
int
141
192
virRegisterDriver(virDriverPtr driver)
142
193
{
143
 
    int i;
144
 
 
145
 
    if (!initialized)
146
 
        if (virInitialize() < 0)
147
 
            return -1;
 
194
    if (virInitialize() < 0)
 
195
      return -1;
148
196
 
149
197
    if (driver == NULL) {
150
198
        virLibConnError(NULL, VIR_ERR_INVALID_ARG, __FUNCTION__);
151
199
        return(-1);
152
200
    }
153
 
    for (i = 0;i < MAX_DRIVERS;i++) {
154
 
        if (virDriverTab[i] == driver)
155
 
            return(i);
156
 
    }
157
 
    for (i = 0;i < MAX_DRIVERS;i++) {
158
 
        if (virDriverTab[i] == NULL) {
159
 
            virDriverTab[i] = driver;
160
 
            return(i);
161
 
        }
162
 
    }
163
 
    virLibConnError(NULL, VIR_ERR_INVALID_ARG, __FUNCTION__);
164
 
    return(-1);
 
201
 
 
202
    if (virDriverTabCount >= MAX_DRIVERS) {
 
203
        virLibConnError(NULL, VIR_ERR_INVALID_ARG, __FUNCTION__);
 
204
        return(-1);
 
205
    }
 
206
 
 
207
    if (driver->no < 0) {
 
208
        virLibConnError
 
209
            (NULL, VIR_ERR_INVALID_ARG,
 
210
             "virRegisterDriver: tried to register an internal Xen driver");
 
211
        return -1;
 
212
    }
 
213
 
 
214
    virDriverTab[virDriverTabCount] = driver;
 
215
    return virDriverTabCount++;
165
216
}
166
217
 
167
218
/**
196
247
    if (typeVer != NULL) {
197
248
        if (type == NULL)
198
249
            type = "Xen";
199
 
        for (i = 0;i < MAX_DRIVERS;i++) {
 
250
        for (i = 0;i < virDriverTabCount;i++) {
200
251
            if ((virDriverTab[i] != NULL) &&
201
252
                (!strcmp(virDriverTab[i]->name, type))) {
202
253
                *typeVer = virDriverTab[i]->ver;
203
254
                break;
204
255
            }
205
256
        }
206
 
        if (i >= MAX_DRIVERS) {
 
257
        if (i >= virDriverTabCount) {
207
258
            *typeVer = 0;
208
259
            virLibConnError(NULL, VIR_ERR_NO_SUPPORT, type);
209
260
            return (-1);
212
263
    return (0);
213
264
}
214
265
 
 
266
static virConnectPtr
 
267
do_open (const char *name, int flags)
 
268
{
 
269
    int i, res;
 
270
    virConnectPtr ret = NULL;
 
271
 
 
272
    if (!initialized)
 
273
        if (virInitialize() < 0)
 
274
            return NULL;
 
275
 
 
276
    ret = virGetConnect();
 
277
    if (ret == NULL) {
 
278
        virLibConnError(NULL, VIR_ERR_NO_MEMORY, _("allocating connection"));
 
279
        goto failed;
 
280
    }
 
281
 
 
282
    for (i = 0; i < virDriverTabCount; i++) {
 
283
        res = virDriverTab[i]->open (ret, name, flags);
 
284
        if (res == VIR_DRV_OPEN_ERROR) goto failed;
 
285
        else if (res == VIR_DRV_OPEN_SUCCESS) {
 
286
            ret->driver = virDriverTab[i];
 
287
            break;
 
288
        }
 
289
    }
 
290
 
 
291
    if (!ret->driver) {
 
292
        virLibConnError (NULL, VIR_ERR_NO_SUPPORT, name);
 
293
        goto failed;
 
294
    }
 
295
 
 
296
    for (i = 0; i < virNetworkDriverTabCount; i++) {
 
297
        res = virNetworkDriverTab[i]->open (ret, name, flags);
 
298
        if (res == -1) goto failed;
 
299
        else if (res == 0) {
 
300
            ret->networkDriver = virNetworkDriverTab[i];
 
301
            break;
 
302
        }
 
303
    }
 
304
 
 
305
    if (flags & VIR_DRV_OPEN_RO) {
 
306
        ret->flags = VIR_CONNECT_RO;
 
307
    }
 
308
 
 
309
    return ret;
 
310
 
 
311
failed:
 
312
    if (ret->driver) ret->driver->close (ret);
 
313
        virFreeConnect(ret);
 
314
    return (NULL);
 
315
}
 
316
 
215
317
/**
216
318
 * virConnectOpen:
217
319
 * @name: optional argument currently unused, pass NULL
222
324
 * Returns a pointer to the hypervisor connection or NULL in case of error
223
325
 */
224
326
virConnectPtr
225
 
virConnectOpen(const char *name)
 
327
virConnectOpen (const char *name)
226
328
{
227
 
    int i, res, for_xen = 0;
228
 
    virConnectPtr ret = NULL;
229
 
 
230
 
    if (!initialized)
231
 
        if (virInitialize() < 0)
232
 
            return NULL;
233
 
 
234
 
    if (name == NULL) {
235
 
        name = "Xen";
236
 
        for_xen = 1;
237
 
    } else if (!strncasecmp(name, "xen", 3)) {
238
 
        for_xen = 1;
239
 
    }
240
 
 
241
 
    ret = virGetConnect();
242
 
    if (ret == NULL) {
243
 
        virLibConnError(NULL, VIR_ERR_NO_MEMORY, _("allocating connection"));
244
 
        goto failed;
245
 
    }
246
 
 
247
 
    for (i = 0;i < MAX_DRIVERS;i++) {
248
 
        if ((virDriverTab[i] != NULL) && (virDriverTab[i]->open != NULL)) {
249
 
            res = virDriverTab[i]->open(ret, name, VIR_DRV_OPEN_QUIET);
250
 
            /*
251
 
             * For a default connect to Xen make sure we manage to contact
252
 
             * all related drivers.
253
 
             */
254
 
            if ((res < 0) && (for_xen) &&
255
 
                (!strncasecmp(virDriverTab[i]->name, "xen", 3)) &&
256
 
                (virDriverTab[i]->no != VIR_DRV_XEN_PROXY))
257
 
                goto failed;
258
 
            if (res == 0)
259
 
                ret->drivers[ret->nb_drivers++] = virDriverTab[i];
260
 
        }
261
 
    }
262
 
 
263
 
    if (ret->nb_drivers == 0) {
264
 
        /* we failed to find an adequate driver */
265
 
        virLibConnError(NULL, VIR_ERR_NO_SUPPORT, name);
266
 
        goto failed;
267
 
    }
268
 
 
269
 
    return (ret);
270
 
 
271
 
failed:
272
 
    if (ret != NULL) {
273
 
        for (i = 0;i < ret->nb_drivers;i++) {
274
 
            if ((ret->drivers[i] != NULL) && (ret->drivers[i]->close != NULL))
275
 
                ret->drivers[i]->close(ret);
276
 
        }
277
 
        virFreeConnect(ret);
278
 
    }
279
 
    return (NULL);
 
329
    return do_open (name, VIR_DRV_OPEN_QUIET);
280
330
}
281
331
 
282
332
/**
292
342
virConnectPtr
293
343
virConnectOpenReadOnly(const char *name)
294
344
{
295
 
    int i, res;
296
 
    virConnectPtr ret = NULL;
297
 
 
298
 
    if (!initialized)
299
 
        if (virInitialize() < 0)
300
 
            return NULL;
301
 
 
302
 
    if (name == NULL)
303
 
        name = "Xen";
304
 
 
305
 
    ret = virGetConnect();
306
 
    if (ret == NULL) {
307
 
        virLibConnError(NULL, VIR_ERR_NO_MEMORY, _("allocating connection"));
308
 
        goto failed;
309
 
    }
310
 
 
311
 
    for (i = 0;i < MAX_DRIVERS;i++) {
312
 
        if ((virDriverTab[i] != NULL) && (virDriverTab[i]->open != NULL)) {
313
 
            res = virDriverTab[i]->open(ret, name,
314
 
                                        VIR_DRV_OPEN_QUIET | VIR_DRV_OPEN_RO);
315
 
            if (res == 0)
316
 
                ret->drivers[ret->nb_drivers++] = virDriverTab[i];
317
 
 
318
 
        }
319
 
    }
320
 
    if (ret->nb_drivers == 0) {
321
 
        if (name == NULL)
322
 
            virLibConnError(NULL, VIR_ERR_NO_CONNECT,
323
 
                            _("Xen Daemon or Xen Store"));
324
 
        else
325
 
            /* we failed to find an adequate driver */
326
 
            virLibConnError(NULL, VIR_ERR_NO_SUPPORT, name);
327
 
        goto failed;
328
 
    }
329
 
    ret->flags = VIR_CONNECT_RO;
330
 
 
331
 
    return (ret);
332
 
 
333
 
failed:
334
 
    if (ret != NULL) {
335
 
        for (i = 0;i < ret->nb_drivers;i++) {
336
 
            if ((ret->drivers[i] != NULL) && (ret->drivers[i]->close != NULL))
337
 
                ret->drivers[i]->close(ret);
338
 
        }
339
 
        virFreeConnect(ret);
340
 
    }
341
 
    return (NULL);
 
345
    return do_open (name, VIR_DRV_OPEN_QUIET | VIR_DRV_OPEN_RO);
342
346
}
343
347
 
344
348
/**
355
359
int
356
360
virConnectClose(virConnectPtr conn)
357
361
{
358
 
    int i;
359
 
 
360
362
    if (!VIR_IS_CONNECT(conn))
361
363
        return (-1);
362
 
    for (i = 0;i < conn->nb_drivers;i++) {
363
 
        if ((conn->drivers[i] != NULL) && (conn->drivers[i]->close != NULL))
364
 
            conn->drivers[i]->close(conn);
365
 
    }
 
364
 
 
365
    conn->driver->close (conn);
 
366
    if (conn->networkDriver)
 
367
        conn->networkDriver->close (conn);
 
368
 
366
369
    if (virFreeConnect(conn) < 0)
367
370
        return (-1);
368
371
    return (0);
379
382
const char *
380
383
virConnectGetType(virConnectPtr conn)
381
384
{
382
 
    int i;
383
385
    const char *ret;
384
386
 
385
387
    if (!VIR_IS_CONNECT(conn)) {
386
388
        virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
387
389
        return (NULL);
388
390
    }
389
 
    for (i = 0;i < conn->nb_drivers;i++) {
390
 
        if ((conn->drivers[i] != NULL) &&
391
 
            (conn->drivers[i]->type != NULL)) {
392
 
            ret = conn->drivers[i]->type(conn);
393
 
            if (ret != NULL)
394
 
                return(ret);
395
 
        }
396
 
    }
397
 
    for (i = 0;i < conn->nb_drivers;i++) {
398
 
        if ((conn->drivers[i] != NULL) &&
399
 
            (conn->drivers[i]->name != NULL)) {
400
 
            return(conn->drivers[i]->name);
401
 
        }
402
 
    }
403
 
    return(NULL);
 
391
 
 
392
    if (conn->driver->type) {
 
393
        ret = conn->driver->type (conn);
 
394
        if (ret) return ret;
 
395
    }
 
396
    return conn->driver->name;
404
397
}
405
398
 
406
399
/**
419
412
int
420
413
virConnectGetVersion(virConnectPtr conn, unsigned long *hvVer)
421
414
{
422
 
    int ret, i;
423
 
 
424
415
    if (!VIR_IS_CONNECT(conn)) {
425
416
        virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
426
417
        return (-1);
431
422
        return (-1);
432
423
    }
433
424
 
434
 
    for (i = 0;i < conn->nb_drivers;i++) {
435
 
        if ((conn->drivers[i] != NULL) &&
436
 
            (conn->drivers[i]->version != NULL)) {
437
 
            ret = conn->drivers[i]->version(conn, hvVer);
438
 
            if (ret == 0)
439
 
                return(0);
440
 
        }
 
425
    if (conn->driver->version)
 
426
        return conn->driver->version (conn, hvVer);
 
427
 
 
428
    virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
 
429
    return -1;
 
430
}
 
431
 
 
432
/**
 
433
 * virConnectGetMaxVcpus:
 
434
 * @conn: pointer to the hypervisor connection
 
435
 * @type: value of the 'type' attribute in the <domain> element
 
436
 *
 
437
 * Provides the maximum number of virtual CPUs supported for a guest VM of a
 
438
 * specific type. The 'type' parameter here corresponds to the 'type'
 
439
 * attribute in the <domain> element of the XML.
 
440
 *
 
441
 * Returns the maximum of virtual CPU or -1 in case of error.
 
442
 */
 
443
int
 
444
virConnectGetMaxVcpus(virConnectPtr conn,
 
445
                      const char *type)
 
446
{
 
447
    if (!VIR_IS_CONNECT(conn)) {
 
448
        virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
 
449
        return (-1);
441
450
    }
442
 
    return (-1);
 
451
 
 
452
    if (conn->driver->getMaxVcpus)
 
453
        return conn->driver->getMaxVcpus (conn, type);
 
454
 
 
455
    virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
 
456
    return -1;
443
457
}
444
458
 
445
459
/**
455
469
int
456
470
virConnectListDomains(virConnectPtr conn, int *ids, int maxids)
457
471
{
458
 
    int ret = -1;
459
 
    int i;
460
 
 
461
472
    if (!VIR_IS_CONNECT(conn)) {
462
473
        virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
463
474
        return (-1);
468
479
        return (-1);
469
480
    }
470
481
 
471
 
    /* Go though the driver registered entry points */
472
 
    for (i = 0;i < conn->nb_drivers;i++) {
473
 
        if ((conn->drivers[i] != NULL) &&
474
 
            (conn->drivers[i]->listDomains != NULL)) {
475
 
            ret = conn->drivers[i]->listDomains(conn, ids, maxids);
476
 
            if (ret >= 0)
477
 
                return(ret);
478
 
        }
479
 
    }
 
482
    if (conn->driver->listDomains)
 
483
        return conn->driver->listDomains (conn, ids, maxids);
480
484
 
481
 
    return (-1);
 
485
    virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
 
486
    return -1;
482
487
}
483
488
 
484
489
/**
492
497
int
493
498
virConnectNumOfDomains(virConnectPtr conn)
494
499
{
495
 
    int ret = -1;
496
 
    int i;
497
 
 
498
500
    if (!VIR_IS_CONNECT(conn)) {
499
501
        virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
500
502
        return (-1);
501
503
    }
502
504
 
503
 
    /* Go though the driver registered entry points */
504
 
    for (i = 0;i < conn->nb_drivers;i++) {
505
 
        if ((conn->drivers[i] != NULL) &&
506
 
            (conn->drivers[i]->numOfDomains != NULL)) {
507
 
            ret = conn->drivers[i]->numOfDomains(conn);
508
 
            if (ret >= 0)
509
 
                return(ret);
510
 
        }
511
 
    }
 
505
    if (conn->driver->numOfDomains)
 
506
        return conn->driver->numOfDomains (conn);
512
507
 
513
 
    return(-1);
 
508
    virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
 
509
    return -1;
514
510
}
515
511
 
516
512
/**
529
525
virDomainCreateLinux(virConnectPtr conn, const char *xmlDesc,
530
526
                     unsigned int flags)
531
527
{
532
 
    virDomainPtr ret;
533
 
    int i;
534
 
 
535
528
    if (!VIR_IS_CONNECT(conn)) {
536
529
        virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
537
530
        return (NULL);
545
538
        return (NULL);
546
539
    }
547
540
 
548
 
    for (i = 0;i < conn->nb_drivers;i++) {
549
 
        if ((conn->drivers[i] != NULL) &&
550
 
            (conn->drivers[i]->domainCreateLinux != NULL)) {
551
 
            ret = conn->drivers[i]->domainCreateLinux(conn, xmlDesc, flags);
552
 
            if (ret != NULL)
553
 
                return(ret);
554
 
        }
555
 
    }
556
 
    return(NULL);
 
541
    if (conn->driver->domainCreateLinux)
 
542
        return conn->driver->domainCreateLinux (conn, xmlDesc, flags);
 
543
 
 
544
    virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
 
545
    return NULL;
557
546
}
558
547
 
559
548
 
569
558
virDomainPtr
570
559
virDomainLookupByID(virConnectPtr conn, int id)
571
560
{
572
 
    virDomainPtr ret;
573
 
    int i;
574
 
 
575
561
    if (!VIR_IS_CONNECT(conn)) {
576
562
        virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
577
563
        return (NULL);
581
567
        return (NULL);
582
568
    }
583
569
 
584
 
    /* Go though the driver registered entry points */
585
 
    for (i = 0;i < conn->nb_drivers;i++) {
586
 
        if ((conn->drivers[i] != NULL) &&
587
 
            (conn->drivers[i]->domainLookupByID != NULL)) {
588
 
            ret = conn->drivers[i]->domainLookupByID(conn, id);
589
 
            if (ret)
590
 
                return(ret);
591
 
        }
592
 
    }
 
570
    if (conn->driver->domainLookupByID)
 
571
        return conn->driver->domainLookupByID (conn, id);
593
572
 
594
 
    return (NULL);
 
573
    virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
 
574
    return NULL;
595
575
}
596
576
 
597
577
/**
606
586
virDomainPtr
607
587
virDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
608
588
{
609
 
    virDomainPtr ret;
610
 
    int i;
611
 
 
612
589
    if (!VIR_IS_CONNECT(conn)) {
613
590
        virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
614
591
        return (NULL);
618
595
        return (NULL);
619
596
    }
620
597
 
621
 
    /* Go though the driver registered entry points */
622
 
    for (i = 0;i < conn->nb_drivers;i++) {
623
 
        if ((conn->drivers[i] != NULL) &&
624
 
            (conn->drivers[i]->domainLookupByUUID != NULL)) {
625
 
            ret = conn->drivers[i]->domainLookupByUUID(conn, uuid);
626
 
            if (ret)
627
 
                return(ret);
628
 
        }
629
 
    }
 
598
    if (conn->driver->domainLookupByUUID)
 
599
        return conn->driver->domainLookupByUUID (conn, uuid);
630
600
 
631
 
    return (NULL);
 
601
    virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
 
602
    return NULL;
632
603
}
633
604
 
634
605
/**
643
614
virDomainPtr
644
615
virDomainLookupByUUIDString(virConnectPtr conn, const char *uuidstr)
645
616
{
646
 
    int raw[16], i;
647
 
    unsigned char uuid[16];
 
617
    int raw[VIR_UUID_BUFLEN], i;
 
618
    unsigned char uuid[VIR_UUID_BUFLEN];
648
619
    int ret;
649
620
 
650
621
    if (!VIR_IS_CONNECT(conn)) {
670
641
                 raw + 8, raw + 9, raw + 10, raw + 11,
671
642
                 raw + 12, raw + 13, raw + 14, raw + 15);
672
643
    
673
 
    if (ret!=16) {
 
644
    if (ret!=VIR_UUID_BUFLEN) {
674
645
        virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
675
646
        return (NULL);
676
647
    }
677
 
    for (i = 0; i < 16; i++)
 
648
    for (i = 0; i < VIR_UUID_BUFLEN; i++)
678
649
        uuid[i] = raw[i] & 0xFF;
679
650
    
680
651
    return virDomainLookupByUUID(conn, &uuid[0]);
692
663
virDomainPtr
693
664
virDomainLookupByName(virConnectPtr conn, const char *name)
694
665
{
695
 
    virDomainPtr ret = NULL;
696
 
    int i;
697
 
 
698
666
    if (!VIR_IS_CONNECT(conn)) {
699
667
        virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
700
668
        return (NULL);
704
672
        return (NULL);
705
673
    }
706
674
 
707
 
    /* Go though the driver registered entry points */
708
 
    for (i = 0;i < conn->nb_drivers;i++) {
709
 
        if ((conn->drivers[i] != NULL) &&
710
 
            (conn->drivers[i]->domainLookupByName != NULL)) {
711
 
            ret = conn->drivers[i]->domainLookupByName(conn, name);
712
 
            if (ret)
713
 
                return(ret);
714
 
        }
715
 
    }
716
 
    return (NULL);
 
675
    if (conn->driver->domainLookupByName)
 
676
        return conn->driver->domainLookupByName (conn, name);
 
677
 
 
678
    virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
 
679
    return NULL;
717
680
}
718
681
 
719
682
/**
731
694
int
732
695
virDomainDestroy(virDomainPtr domain)
733
696
{
734
 
    int i;
735
697
    virConnectPtr conn;
736
698
 
737
699
    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
745
707
        return (-1);
746
708
    }
747
709
 
748
 
    /*
749
 
     * Go though the driver registered entry points but use the 
750
 
     * XEN_HYPERVISOR directly only as a last mechanism
751
 
     */
752
 
    for (i = 0;i < conn->nb_drivers;i++) {
753
 
        if ((conn->drivers[i] != NULL) &&
754
 
            (conn->drivers[i]->no != VIR_DRV_XEN_HYPERVISOR) &&
755
 
            (conn->drivers[i]->domainDestroy != NULL)) {
756
 
            if (conn->drivers[i]->domainDestroy(domain) == 0)
757
 
                return (0);
758
 
        }
759
 
    }
760
 
    for (i = 0;i < conn->nb_drivers;i++) {
761
 
        if ((conn->drivers[i] != NULL) &&
762
 
            (conn->drivers[i]->no == VIR_DRV_XEN_HYPERVISOR) &&
763
 
            (conn->drivers[i]->domainDestroy != NULL)) {
764
 
            if (conn->drivers[i]->domainDestroy(domain) == 0)
765
 
                return (0);
766
 
        }
767
 
    }
 
710
    if (conn->driver->domainDestroy)
 
711
        return conn->driver->domainDestroy (domain);
768
712
 
769
 
        virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
770
 
    return (-1);
 
713
    virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
 
714
    return -1;
771
715
}
772
716
 
773
717
/**
806
750
int
807
751
virDomainSuspend(virDomainPtr domain)
808
752
{
809
 
    int i;
810
753
    virConnectPtr conn;
811
754
 
812
755
    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
820
763
 
821
764
    conn = domain->conn;
822
765
 
823
 
    /*
824
 
     * Go though the driver registered entry points but use the 
825
 
     * XEN_HYPERVISOR directly only as a last mechanism
826
 
     */
827
 
    for (i = 0;i < conn->nb_drivers;i++) {
828
 
        if ((conn->drivers[i] != NULL) &&
829
 
            (conn->drivers[i]->no != VIR_DRV_XEN_HYPERVISOR) &&
830
 
            (conn->drivers[i]->domainSuspend != NULL)) {
831
 
            if (conn->drivers[i]->domainSuspend(domain) == 0)
832
 
                return (0);
833
 
        }
834
 
    }
835
 
    for (i = 0;i < conn->nb_drivers;i++) {
836
 
        if ((conn->drivers[i] != NULL) &&
837
 
            (conn->drivers[i]->no == VIR_DRV_XEN_HYPERVISOR) &&
838
 
            (conn->drivers[i]->domainSuspend != NULL)) {
839
 
            if (conn->drivers[i]->domainSuspend(domain) == 0)
840
 
                return (0);
841
 
        }
842
 
    }
 
766
    if (conn->driver->domainSuspend)
 
767
        return conn->driver->domainSuspend (domain);
843
768
 
844
 
        virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
845
 
    return (-1);
 
769
    virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
 
770
    return -1;
846
771
}
847
772
 
848
773
/**
858
783
int
859
784
virDomainResume(virDomainPtr domain)
860
785
{
861
 
    int i;
862
786
    virConnectPtr conn;
863
787
 
864
788
    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
872
796
 
873
797
    conn = domain->conn;
874
798
 
875
 
    /*
876
 
     * Go though the driver registered entry points but use the 
877
 
     * XEN_HYPERVISOR directly only as a last mechanism
878
 
     */
879
 
    for (i = 0;i < conn->nb_drivers;i++) {
880
 
        if ((conn->drivers[i] != NULL) &&
881
 
            (conn->drivers[i]->no != VIR_DRV_XEN_HYPERVISOR) &&
882
 
            (conn->drivers[i]->domainResume != NULL)) {
883
 
            if (conn->drivers[i]->domainResume(domain) == 0)
884
 
                return(0);
885
 
        }
886
 
    }
887
 
    for (i = 0;i < conn->nb_drivers;i++) {
888
 
        if ((conn->drivers[i] != NULL) &&
889
 
            (conn->drivers[i]->no == VIR_DRV_XEN_HYPERVISOR) &&
890
 
            (conn->drivers[i]->domainResume != NULL)) {
891
 
            if (conn->drivers[i]->domainResume(domain) == 0)
892
 
                return(0);
893
 
        }
894
 
    }
 
799
    if (conn->driver->domainResume)
 
800
        return conn->driver->domainResume (domain);
895
801
 
896
 
    virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
897
 
    return (-1);
 
802
    virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
 
803
    return -1;
898
804
}
899
805
 
900
806
/**
912
818
int
913
819
virDomainSave(virDomainPtr domain, const char *to)
914
820
{
915
 
    int ret, i;
916
821
    char filepath[4096];
917
822
    virConnectPtr conn;
918
823
 
950
855
 
951
856
    }
952
857
 
953
 
    /* Go though the driver registered entry points */
954
 
    for (i = 0;i < conn->nb_drivers;i++) {
955
 
        if ((conn->drivers[i] != NULL) &&
956
 
            (conn->drivers[i]->domainSave != NULL)) {
957
 
            ret = conn->drivers[i]->domainSave(domain, to);
958
 
            if (ret == 0)
959
 
                return(0);
960
 
        }
961
 
    }
962
 
    virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
963
 
    return (-1);
 
858
    if (conn->driver->domainSave)
 
859
        return conn->driver->domainSave (domain, to);
 
860
 
 
861
    virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
 
862
    return -1;
964
863
}
965
864
 
966
865
/**
975
874
int
976
875
virDomainRestore(virConnectPtr conn, const char *from)
977
876
{
978
 
    int ret, i;
979
877
    char filepath[4096];
980
878
 
981
879
    if (!VIR_IS_CONNECT(conn)) {
1010
908
        from = &filepath[0];
1011
909
    }
1012
910
 
1013
 
    /* Go though the driver registered entry points */
1014
 
    for (i = 0;i < conn->nb_drivers;i++) {
1015
 
        if ((conn->drivers[i] != NULL) &&
1016
 
            (conn->drivers[i]->domainSave != NULL)) {
1017
 
            ret = conn->drivers[i]->domainRestore(conn, from);
1018
 
            if (ret == 0)
1019
 
                return(0);
1020
 
        }
1021
 
    }
1022
 
    virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
1023
 
    return (-1);
 
911
    if (conn->driver->domainRestore)
 
912
        return conn->driver->domainRestore (conn, from);
 
913
 
 
914
    virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
 
915
    return -1;
 
916
}
 
917
 
 
918
/**
 
919
 * virDomainCoreDump:
 
920
 * @domain: a domain object
 
921
 * @to: path for the core file
 
922
 * @flags: extra flags, currently unused
 
923
 *
 
924
 * This method will dump the core of a domain on a given file for analysis.
 
925
 * Note that for remote Xen Daemon the file path will be interpreted in
 
926
 * the remote host.
 
927
 *
 
928
 * Returns 0 in case of success and -1 in case of failure.
 
929
 */
 
930
int
 
931
virDomainCoreDump(virDomainPtr domain, const char *to, int flags)
 
932
{
 
933
    char filepath[4096];
 
934
    virConnectPtr conn;
 
935
 
 
936
    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
 
937
        virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
 
938
        return (-1);
 
939
    }
 
940
    if (domain->conn->flags & VIR_CONNECT_RO) {
 
941
        virLibDomainError(domain, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
 
942
        return (-1);
 
943
    }
 
944
    conn = domain->conn;
 
945
    if (to == NULL) {
 
946
        virLibDomainError(domain, VIR_ERR_INVALID_ARG, __FUNCTION__);
 
947
        return (-1);
 
948
    }
 
949
 
 
950
    /*
 
951
     * We must absolutize the file path as the save is done out of process
 
952
     * TODO: check for URI when libxml2 is linked in.
 
953
     */
 
954
    if (to[0] != '/') {
 
955
        unsigned int len, t;
 
956
 
 
957
        t = strlen(to);
 
958
        if (getcwd(filepath, sizeof(filepath) - (t + 3)) == NULL)
 
959
            return (-1);
 
960
        len = strlen(filepath);
 
961
        /* that should be covered by getcwd() semantic, but be 100% sure */
 
962
        if (len > sizeof(filepath) - (t + 3))
 
963
            return (-1);
 
964
        filepath[len] = '/';
 
965
        strcpy(&filepath[len + 1], to);
 
966
        to = &filepath[0];
 
967
 
 
968
    }
 
969
 
 
970
    if (conn->driver->domainCoreDump)
 
971
        return conn->driver->domainCoreDump (domain, to, flags);
 
972
 
 
973
    virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
 
974
    return -1;
1024
975
}
1025
976
 
1026
977
/**
1039
990
int
1040
991
virDomainShutdown(virDomainPtr domain)
1041
992
{
1042
 
    int ret = -1, i;
1043
993
    virConnectPtr conn;
1044
994
 
1045
995
    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
1053
1003
 
1054
1004
    conn = domain->conn;
1055
1005
 
1056
 
    /* Go though the driver registered entry points */
1057
 
    for (i = 0;i < conn->nb_drivers;i++) {
1058
 
        if ((conn->drivers[i] != NULL) &&
1059
 
            (conn->drivers[i]->domainShutdown != NULL)) {
1060
 
            if (conn->drivers[i]->domainShutdown(domain) == 0)
1061
 
                ret = 0;
1062
 
        }
1063
 
    }
1064
 
 
1065
 
    if (ret != 0) {
1066
 
        virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
1067
 
        return (ret);
1068
 
    }
1069
 
 
1070
 
    return (ret);
 
1006
    if (conn->driver->domainShutdown)
 
1007
        return conn->driver->domainShutdown (domain);
 
1008
 
 
1009
    virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
 
1010
    return -1;
1071
1011
}
1072
1012
 
1073
1013
/**
1084
1024
int
1085
1025
virDomainReboot(virDomainPtr domain, unsigned int flags)
1086
1026
{
1087
 
    int ret = -1, i;
1088
1027
    virConnectPtr conn;
1089
1028
 
1090
1029
    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
1098
1037
 
1099
1038
    conn = domain->conn;
1100
1039
 
1101
 
    /* Go though the driver registered entry points */
1102
 
    for (i = 0;i < conn->nb_drivers;i++) {
1103
 
        if ((conn->drivers[i] != NULL) &&
1104
 
            (conn->drivers[i]->domainReboot != NULL)) {
1105
 
            if (conn->drivers[i]->domainReboot(domain, flags) == 0)
1106
 
                ret = 0;
1107
 
        }
1108
 
    }
1109
 
 
1110
 
    if (ret != 0) {
1111
 
        virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
1112
 
        return (ret);
1113
 
    }
1114
 
 
1115
 
    return (ret);
 
1040
    if (conn->driver->domainReboot)
 
1041
        return conn->driver->domainReboot (domain, flags);
 
1042
 
 
1043
    virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
 
1044
    return -1;
1116
1045
}
1117
1046
 
1118
1047
/**
1137
1066
/**
1138
1067
 * virDomainGetUUID:
1139
1068
 * @domain: a domain object
1140
 
 * @uuid: pointer to a 16 bytes array
 
1069
 * @uuid: pointer to a VIR_UUID_BUFLEN bytes array
1141
1070
 *
1142
1071
 * Get the UUID for a domain
1143
1072
 *
1155
1084
        return (-1);
1156
1085
    }
1157
1086
 
1158
 
    if (domain->handle == 0) {
1159
 
        memset(uuid, 0, 16);
 
1087
    if (domain->id == 0) {
 
1088
        memset(uuid, 0, VIR_UUID_BUFLEN);
1160
1089
    } else {
 
1090
#if 0
 
1091
        /* Probably legacy code: It appears that we always fill in
 
1092
         * the UUID when creating the virDomain structure, so this
 
1093
         * shouldn't be necessary.
 
1094
         */
1161
1095
        if ((domain->uuid[0] == 0) && (domain->uuid[1] == 0) &&
1162
1096
            (domain->uuid[2] == 0) && (domain->uuid[3] == 0) &&
1163
1097
            (domain->uuid[4] == 0) && (domain->uuid[5] == 0) &&
1168
1102
            (domain->uuid[14] == 0) && (domain->uuid[15] == 0))
1169
1103
            xenDaemonDomainLookupByName_ids(domain->conn, domain->name,
1170
1104
                                &domain->uuid[0]);
1171
 
        memcpy(uuid, &domain->uuid[0], 16);
 
1105
#endif
 
1106
        memcpy(uuid, &domain->uuid[0], VIR_UUID_BUFLEN);
1172
1107
    }
1173
1108
    return (0);
1174
1109
}
1176
1111
/**
1177
1112
 * virDomainGetUUIDString:
1178
1113
 * @domain: a domain object
1179
 
 * @buf: pointer to a 37 bytes array
 
1114
 * @buf: pointer to a VIR_UUID_STRING_BUFLEN bytes array
1180
1115
 *
1181
1116
 * Get the UUID for a domain as string. For more information about 
1182
1117
 * UUID see RFC4122.
1186
1121
int
1187
1122
virDomainGetUUIDString(virDomainPtr domain, char *buf)
1188
1123
{
1189
 
    unsigned char uuid[16];
 
1124
    unsigned char uuid[VIR_UUID_BUFLEN];
1190
1125
 
1191
1126
    if (!VIR_IS_DOMAIN(domain)) {
1192
1127
        virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
1198
1133
    }
1199
1134
    
1200
1135
    if (virDomainGetUUID(domain, &uuid[0]))
1201
 
        return (-1);
 
1136
        return (-1);
1202
1137
 
1203
 
    snprintf(buf, 37, 
 
1138
    snprintf(buf, VIR_UUID_STRING_BUFLEN,
1204
1139
        "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
1205
1140
                      uuid[0], uuid[1], uuid[2], uuid[3],
1206
1141
                      uuid[4], uuid[5], uuid[6], uuid[7],
1224
1159
        virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
1225
1160
        return ((unsigned int) -1);
1226
1161
    }
1227
 
    return (domain->handle);
 
1162
    return (domain->id);
1228
1163
}
1229
1164
 
1230
1165
/**
1239
1174
char *
1240
1175
virDomainGetOSType(virDomainPtr domain)
1241
1176
{
1242
 
    char *vm, *str = NULL;
 
1177
    virConnectPtr conn;
1243
1178
 
1244
1179
    if (!VIR_IS_DOMAIN(domain)) {
1245
1180
        virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
1246
1181
        return (NULL);
1247
1182
    }
1248
1183
 
1249
 
    vm = virDomainGetVM(domain);
1250
 
    if (vm) {
1251
 
        str = virDomainGetVMInfo(domain, vm, "image/ostype");
1252
 
        free(vm);
1253
 
    }
1254
 
    if (str == NULL)
1255
 
        str = strdup("linux");
1256
 
 
1257
 
    return (str);
 
1184
    conn = domain->conn;
 
1185
 
 
1186
    if (conn->driver->domainGetOSType)
 
1187
        return conn->driver->domainGetOSType (domain);
 
1188
 
 
1189
    virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
 
1190
    return NULL;
1258
1191
}
1259
1192
 
1260
1193
/**
1270
1203
unsigned long
1271
1204
virDomainGetMaxMemory(virDomainPtr domain)
1272
1205
{
1273
 
    unsigned long ret = 0;
1274
1206
    virConnectPtr conn;
1275
 
    int i;
1276
1207
 
1277
1208
    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
1278
1209
        virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
1281
1212
 
1282
1213
    conn = domain->conn;
1283
1214
 
1284
 
    /*
1285
 
     * in that case instead of trying only though one method try all availble.
1286
 
     * If needed that can be changed back if it's a performcance problem.
1287
 
     */
1288
 
    for (i = 0;i < conn->nb_drivers;i++) {
1289
 
        if ((conn->drivers[i] != NULL) &&
1290
 
            (conn->drivers[i]->domainGetMaxMemory != NULL)) {
1291
 
            ret = conn->drivers[i]->domainGetMaxMemory(domain);
1292
 
            if (ret != 0)
1293
 
                return(ret);
1294
 
        }
1295
 
    }
1296
 
    virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
1297
 
    return (-1);
 
1215
    if (conn->driver->domainGetMaxMemory)
 
1216
        return conn->driver->domainGetMaxMemory (domain);
 
1217
 
 
1218
    virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
 
1219
    return 0;
1298
1220
}
1299
1221
 
1300
1222
/**
1312
1234
int
1313
1235
virDomainSetMaxMemory(virDomainPtr domain, unsigned long memory)
1314
1236
{
1315
 
    int ret = -1 , i;
1316
1237
    virConnectPtr conn;
1317
1238
 
1318
1239
    if (domain == NULL) {
1333
1254
    }
1334
1255
    conn = domain->conn;
1335
1256
 
1336
 
    /*
1337
 
     * in that case instead of trying only though one method try all availble.
1338
 
     * If needed that can be changed back if it's a performcance problem.
1339
 
     */
1340
 
    for (i = 0;i < conn->nb_drivers;i++) {
1341
 
        if ((conn->drivers[i] != NULL) &&
1342
 
            (conn->drivers[i]->domainSetMaxMemory != NULL)) {
1343
 
            if (conn->drivers[i]->domainSetMaxMemory(domain, memory) == 0)
1344
 
                ret = 0;
1345
 
        }
1346
 
    }
1347
 
    if (ret != 0) {
1348
 
        virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
1349
 
        return (-1);
1350
 
    }
1351
 
    return (ret);
 
1257
    if (conn->driver->domainSetMaxMemory)
 
1258
        return conn->driver->domainSetMaxMemory (domain, memory);
 
1259
 
 
1260
    virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
 
1261
    return -1;
1352
1262
}
1353
1263
 
1354
1264
/**
1366
1276
int
1367
1277
virDomainSetMemory(virDomainPtr domain, unsigned long memory)
1368
1278
{
1369
 
    int ret = -1 , i;
1370
1279
    virConnectPtr conn;
1371
1280
 
1372
1281
    if (domain == NULL) {
1388
1297
 
1389
1298
    conn = domain->conn;
1390
1299
 
1391
 
    /*
1392
 
     * in that case instead of trying only though one method try all availble.
1393
 
     * If needed that can be changed back if it's a performcance problem.
1394
 
     */
1395
 
    for (i = 0;i < conn->nb_drivers;i++) {
1396
 
        if ((conn->drivers[i] != NULL) &&
1397
 
            (conn->drivers[i]->domainSetMemory != NULL)) {
1398
 
            if (conn->drivers[i]->domainSetMemory(domain, memory) == 0)
1399
 
                ret = 0;
1400
 
        }
1401
 
    }
1402
 
    if (ret != 0) {
1403
 
        virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
1404
 
        return (-1);
1405
 
    }
1406
 
    return (ret);
 
1300
    if (conn->driver->domainSetMemory)
 
1301
        return conn->driver->domainSetMemory (domain, memory);
 
1302
 
 
1303
    virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
 
1304
    return -1;
1407
1305
}
1408
1306
 
1409
1307
/**
1420
1318
int
1421
1319
virDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info)
1422
1320
{
1423
 
    int i;
 
1321
    virConnectPtr conn;
1424
1322
 
1425
1323
    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
1426
1324
        virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
1433
1331
 
1434
1332
    memset(info, 0, sizeof(virDomainInfo));
1435
1333
 
1436
 
    for (i = 0;i < domain->conn->nb_drivers;i++) {
1437
 
        if ((domain->conn->drivers[i] != NULL) &&
1438
 
            (domain->conn->drivers[i]->domainGetInfo != NULL)) {
1439
 
            if (domain->conn->drivers[i]->domainGetInfo(domain, info) == 0)
1440
 
                return 0;
1441
 
        }
1442
 
    }
1443
 
 
1444
 
    return (-1);
 
1334
    conn = domain->conn;
 
1335
 
 
1336
    if (conn->driver->domainGetInfo)
 
1337
        return conn->driver->domainGetInfo (domain, info);
 
1338
 
 
1339
    virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
 
1340
    return -1;
1445
1341
}
1446
1342
 
1447
1343
/**
1458
1354
char *
1459
1355
virDomainGetXMLDesc(virDomainPtr domain, int flags)
1460
1356
{
1461
 
    int i;
1462
 
    char *ret = NULL;
 
1357
    virConnectPtr conn;
 
1358
 
1463
1359
    if (!VIR_IS_DOMAIN(domain)) {
1464
1360
        virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
1465
1361
        return (NULL);
1469
1365
        return (NULL);
1470
1366
    }
1471
1367
 
1472
 
    for (i = 0;i < domain->conn->nb_drivers;i++) {
1473
 
        if ((domain->conn->drivers[i] != NULL) &&
1474
 
            (domain->conn->drivers[i]->domainDumpXML != NULL)) {
1475
 
            ret = domain->conn->drivers[i]->domainDumpXML(domain, flags);
1476
 
            if (ret)
1477
 
                break;
1478
 
        }
1479
 
    }
1480
 
    if (!ret) {
1481
 
        virLibConnError(domain->conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
1482
 
        return (NULL);
1483
 
    }
1484
 
    return(ret);
 
1368
    conn = domain->conn;
 
1369
 
 
1370
    if (conn->driver->domainDumpXML)
 
1371
        return conn->driver->domainDumpXML (domain, flags);
 
1372
 
 
1373
    virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
 
1374
    return NULL;
1485
1375
}
1486
1376
 
1487
1377
/**
1494
1384
 * Returns 0 in case of success and -1 in case of failure.
1495
1385
 */
1496
1386
int
1497
 
virNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info) {
1498
 
    int i;
1499
 
    int ret = -1;
1500
 
 
 
1387
virNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info)
 
1388
{
1501
1389
    if (!VIR_IS_CONNECT(conn)) {
1502
1390
        virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
1503
1391
        return (-1);
1507
1395
        return (-1);
1508
1396
    }
1509
1397
 
1510
 
    for (i = 0;i < conn->nb_drivers;i++) {
1511
 
        if ((conn->drivers[i] != NULL) &&
1512
 
            (conn->drivers[i]->nodeGetInfo != NULL)) {
1513
 
            ret = conn->drivers[i]->nodeGetInfo(conn, info);
1514
 
            if (ret == 0)
1515
 
                break;
1516
 
        }
1517
 
    }
1518
 
    if (ret != 0) {
1519
 
        virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
1520
 
        return (-1);
1521
 
    }
1522
 
    return(0);
 
1398
    if (conn->driver->nodeGetInfo)
 
1399
        return conn->driver->nodeGetInfo (conn, info);
 
1400
 
 
1401
    virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
 
1402
    return -1;
 
1403
}
 
1404
 
 
1405
/**
 
1406
 * virConnectGetCapabilities:
 
1407
 * @conn: pointer to the hypervisor connection
 
1408
 *
 
1409
 * Provides capabilities of the hypervisor / driver.
 
1410
 *
 
1411
 * Returns NULL in case of error, or a pointer to an opaque
 
1412
 * virCapabilities structure (virCapabilitiesPtr).
 
1413
 * The client must free the returned string after use.
 
1414
 */
 
1415
char *
 
1416
virConnectGetCapabilities (virConnectPtr conn)
 
1417
{
 
1418
    if (!VIR_IS_CONNECT (conn)) {
 
1419
        virLibConnError (conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
 
1420
        return NULL;
 
1421
    }
 
1422
 
 
1423
    if (conn->driver->getCapabilities)
 
1424
        return conn->driver->getCapabilities (conn);
 
1425
 
 
1426
    virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
 
1427
    return NULL;
1523
1428
}
1524
1429
 
1525
1430
/************************************************************************
1539
1444
 */
1540
1445
virDomainPtr
1541
1446
virDomainDefineXML(virConnectPtr conn, const char *xml) {
1542
 
    virDomainPtr ret = NULL;
1543
 
    int i;
1544
 
 
1545
1447
    if (!VIR_IS_CONNECT(conn)) {
1546
1448
        virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
1547
1449
        return (NULL);
1555
1457
        return (NULL);
1556
1458
    }
1557
1459
 
1558
 
    /* Go though the driver registered entry points */
1559
 
    for (i = 0;i < conn->nb_drivers;i++) {
1560
 
        if ((conn->drivers[i] != NULL) &&
1561
 
            (conn->drivers[i]->domainDefineXML != NULL)) {
1562
 
            ret = conn->drivers[i]->domainDefineXML(conn, xml);
1563
 
            if (ret)
1564
 
                return(ret);
1565
 
        }
1566
 
    }
 
1460
    if (conn->driver->domainDefineXML)
 
1461
        return conn->driver->domainDefineXML (conn, xml);
1567
1462
 
1568
 
    return(ret);
 
1463
    virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
 
1464
    return NULL;
1569
1465
}
1570
1466
 
1571
1467
/**
1578
1474
 */
1579
1475
int
1580
1476
virDomainUndefine(virDomainPtr domain) {
1581
 
    int ret, i;
1582
1477
    virConnectPtr conn;
1583
1478
 
1584
1479
    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
1591
1486
        return (-1);
1592
1487
    }
1593
1488
 
1594
 
    /* Go though the driver registered entry points */
1595
 
    for (i = 0;i < conn->nb_drivers;i++) {
1596
 
        if ((conn->drivers[i] != NULL) &&
1597
 
            (conn->drivers[i]->domainUndefine != NULL)) {
1598
 
            ret = conn->drivers[i]->domainUndefine(domain);
1599
 
            if (ret >= 0)
1600
 
                return(ret);
1601
 
        }
1602
 
    }
 
1489
    if (conn->driver->domainUndefine)
 
1490
        return conn->driver->domainUndefine (domain);
1603
1491
 
1604
 
    return(-1);
 
1492
    virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
 
1493
    return -1;
1605
1494
}
1606
1495
 
1607
1496
/**
1615
1504
int
1616
1505
virConnectNumOfDefinedDomains(virConnectPtr conn)
1617
1506
{
1618
 
    int ret = -1;
1619
 
    int i;
1620
 
 
1621
1507
    if (!VIR_IS_CONNECT(conn)) {
1622
1508
        virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
1623
1509
        return (-1);
1624
1510
    }
1625
1511
 
1626
 
    /* Go though the driver registered entry points */
1627
 
    for (i = 0;i < conn->nb_drivers;i++) {
1628
 
        if ((conn->drivers[i] != NULL) &&
1629
 
            (conn->drivers[i]->numOfDefinedDomains != NULL)) {
1630
 
            ret = conn->drivers[i]->numOfDefinedDomains(conn);
1631
 
            if (ret >= 0)
1632
 
                return(ret);
1633
 
        }
1634
 
    }
 
1512
    if (conn->driver->numOfDefinedDomains)
 
1513
        return conn->driver->numOfDefinedDomains (conn);
1635
1514
 
1636
 
    return(-1);
 
1515
    virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
 
1516
    return -1;
1637
1517
}
1638
1518
 
1639
1519
/**
1647
1527
 * Returns the number of names provided in the array or -1 in case of error
1648
1528
 */
1649
1529
int
1650
 
virConnectListDefinedDomains(virConnectPtr conn, const char **names,
 
1530
virConnectListDefinedDomains(virConnectPtr conn, char **const names,
1651
1531
                             int maxnames) {
1652
 
    int ret = -1;
1653
 
    int i;
1654
 
 
1655
1532
    if (!VIR_IS_CONNECT(conn)) {
1656
1533
        virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
1657
1534
        return (-1);
1662
1539
        return (-1);
1663
1540
    }
1664
1541
 
1665
 
    /* Go though the driver registered entry points */
1666
 
    for (i = 0;i < conn->nb_drivers;i++) {
1667
 
        if ((conn->drivers[i] != NULL) &&
1668
 
            (conn->drivers[i]->listDefinedDomains != NULL)) {
1669
 
            ret = conn->drivers[i]->listDefinedDomains(conn, names, maxnames);
1670
 
            if (ret >= 0)
1671
 
                return(ret);
1672
 
        }
1673
 
    }
 
1542
    if (conn->driver->listDefinedDomains)
 
1543
        return conn->driver->listDefinedDomains (conn, names, maxnames);
1674
1544
 
1675
 
    return (-1);
 
1545
    virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
 
1546
    return -1;
1676
1547
}
1677
1548
 
1678
1549
/**
1686
1557
 */
1687
1558
int
1688
1559
virDomainCreate(virDomainPtr domain) {
1689
 
    int i, ret = -1;
1690
1560
    virConnectPtr conn;
 
1561
 
1691
1562
    if (domain == NULL) {
1692
1563
        TODO
1693
1564
        return (-1);
1702
1573
        return (-1);
1703
1574
    }
1704
1575
 
1705
 
    for (i = 0;i < conn->nb_drivers;i++) {
1706
 
        if ((conn->drivers[i] != NULL) &&
1707
 
            (conn->drivers[i]->domainCreate != NULL)) {
1708
 
            ret = conn->drivers[i]->domainCreate(domain);
1709
 
            if (ret == 0)
1710
 
                return(ret);
1711
 
        }
1712
 
    }
1713
 
    return(ret);
 
1576
    if (conn->driver->domainCreate)
 
1577
        return conn->driver->domainCreate (domain);
 
1578
 
 
1579
    virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
 
1580
    return -1;
 
1581
}
 
1582
 
 
1583
/**
 
1584
 * virDomainGetAutostart:
 
1585
 * @domain: a domain object
 
1586
 * @autostart: the value returned
 
1587
 *
 
1588
 * Provides a boolean value indicating whether the domain
 
1589
 * configured to be automatically started when the host
 
1590
 * machine boots.
 
1591
 *
 
1592
 * Returns -1 in case of error, 0 in case of success
 
1593
 */
 
1594
int
 
1595
virDomainGetAutostart(virDomainPtr domain,
 
1596
                      int *autostart)
 
1597
{
 
1598
    virConnectPtr conn;
 
1599
 
 
1600
    if (!VIR_IS_DOMAIN(domain)) {
 
1601
        virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
 
1602
        return (-1);
 
1603
    }
 
1604
    if (!autostart) {
 
1605
        virLibDomainError(domain, VIR_ERR_INVALID_ARG, __FUNCTION__);
 
1606
        return (-1);
 
1607
    }
 
1608
 
 
1609
    conn = domain->conn;
 
1610
 
 
1611
    if (conn->driver->domainGetAutostart)
 
1612
        return conn->driver->domainGetAutostart (domain, autostart);
 
1613
 
 
1614
    virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
 
1615
    return -1;
 
1616
}
 
1617
 
 
1618
/**
 
1619
 * virDomainSetAutostart:
 
1620
 * @domain: a domain object
 
1621
 * @autostart: whether the domain should be automatically started 0 or 1
 
1622
 *
 
1623
 * Configure the domain to be automatically started
 
1624
 * when the host machine boots.
 
1625
 *
 
1626
 * Returns -1 in case of error, 0 in case of success
 
1627
 */
 
1628
int
 
1629
virDomainSetAutostart(virDomainPtr domain,
 
1630
                      int autostart)
 
1631
{
 
1632
    virConnectPtr conn;
 
1633
 
 
1634
    if (!VIR_IS_DOMAIN(domain)) {
 
1635
        virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
 
1636
        return (-1);
 
1637
    }
 
1638
 
 
1639
    conn = domain->conn;
 
1640
 
 
1641
    if (conn->driver->domainSetAutostart)
 
1642
        return conn->driver->domainSetAutostart (domain, autostart);
 
1643
 
 
1644
    virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
 
1645
    return -1;
1714
1646
}
1715
1647
 
1716
1648
/**
1729
1661
int
1730
1662
virDomainSetVcpus(virDomainPtr domain, unsigned int nvcpus)
1731
1663
{
1732
 
    int i;
1733
1664
    virConnectPtr conn;
1734
1665
 
1735
1666
    if (domain == NULL) {
1751
1682
    }
1752
1683
    conn = domain->conn;
1753
1684
 
1754
 
    /*
1755
 
     * Go though the driver registered entry points but use the 
1756
 
     * XEN_HYPERVISOR directly only as a last mechanism
1757
 
     */
1758
 
    for (i = 0;i < conn->nb_drivers;i++) {
1759
 
        if ((conn->drivers[i] != NULL) &&
1760
 
            (conn->drivers[i]->no != VIR_DRV_XEN_HYPERVISOR) &&
1761
 
            (conn->drivers[i]->domainSetVcpus != NULL)) {
1762
 
            if (conn->drivers[i]->domainSetVcpus(domain, nvcpus) == 0)
1763
 
                return(0);
1764
 
        }
1765
 
    }
1766
 
    for (i = 0;i < conn->nb_drivers;i++) {
1767
 
        if ((conn->drivers[i] != NULL) &&
1768
 
            (conn->drivers[i]->no == VIR_DRV_XEN_HYPERVISOR) &&
1769
 
            (conn->drivers[i]->domainSetVcpus != NULL)) {
1770
 
            if (conn->drivers[i]->domainSetVcpus(domain, nvcpus) == 0)
1771
 
                return(0);
1772
 
        }
1773
 
    }
 
1685
    if (conn->driver->domainSetVcpus)
 
1686
        return conn->driver->domainSetVcpus (domain, nvcpus);
1774
1687
 
1775
 
    virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
1776
 
    return (-1);
 
1688
    virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
 
1689
    return -1;
1777
1690
}
1778
1691
 
1779
1692
/**
1798
1711
virDomainPinVcpu(virDomainPtr domain, unsigned int vcpu,
1799
1712
                 unsigned char *cpumap, int maplen)
1800
1713
{
1801
 
    int i;
1802
1714
    virConnectPtr conn;
1803
1715
 
1804
1716
    if (domain == NULL) {
1818
1730
        virLibDomainError(domain, VIR_ERR_INVALID_ARG, __FUNCTION__);
1819
1731
        return (-1);
1820
1732
    }
 
1733
 
1821
1734
    conn = domain->conn;
1822
1735
 
1823
 
    /*
1824
 
     * Go though the driver registered entry points
1825
 
     */
1826
 
    for (i = 0;i < conn->nb_drivers;i++) {
1827
 
        if ((conn->drivers[i] != NULL) &&
1828
 
            (conn->drivers[i]->domainPinVcpu != NULL)) {
1829
 
            if (conn->drivers[i]->domainPinVcpu(domain, vcpu,
1830
 
                                                cpumap, maplen) == 0)
1831
 
                return(0);
1832
 
        }
1833
 
    }
1834
 
    virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
1835
 
    return (-1);
 
1736
    if (conn->driver->domainPinVcpu)
 
1737
        return conn->driver->domainPinVcpu (domain, vcpu, cpumap, maplen);
 
1738
 
 
1739
    virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
 
1740
    return -1;
1836
1741
}
1837
1742
 
1838
1743
/**
1860
1765
virDomainGetVcpus(virDomainPtr domain, virVcpuInfoPtr info, int maxinfo,
1861
1766
                  unsigned char *cpumaps, int maplen)
1862
1767
{
1863
 
    int ret;
1864
 
    int i;
1865
1768
    virConnectPtr conn;
1866
1769
 
1867
1770
    if (domain == NULL) {
1880
1783
        virLibDomainError(domain, VIR_ERR_INVALID_ARG, __FUNCTION__);
1881
1784
        return (-1);
1882
1785
    }
1883
 
    conn = domain->conn;
1884
 
 
1885
 
    /*
1886
 
     * Go though the driver registered entry points
 
1786
 
 
1787
    conn = domain->conn;
 
1788
 
 
1789
    if (conn->driver->domainGetVcpus)
 
1790
        return conn->driver->domainGetVcpus (domain, info, maxinfo,
 
1791
                                             cpumaps, maplen);
 
1792
 
 
1793
    virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
 
1794
    return -1;
 
1795
}
 
1796
 
 
1797
/**
 
1798
 * virDomainGetMaxVcpus:
 
1799
 * @domain: pointer to domain object
 
1800
 * 
 
1801
 * Provides the maximum number of virtual CPUs supported for
 
1802
 * the guest VM. If the guest is inactive, this is basically
 
1803
 * the same as virConnectGetMaxVcpus. If the guest is running
 
1804
 * this will reflect the maximum number of virtual CPUs the
 
1805
 * guest was booted with.
 
1806
 *
 
1807
 * Returns the maximum of virtual CPU or -1 in case of error.
 
1808
 */
 
1809
int
 
1810
virDomainGetMaxVcpus(virDomainPtr domain)
 
1811
{
 
1812
    virConnectPtr conn;
 
1813
 
 
1814
    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
 
1815
        virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
 
1816
        return (-1);
 
1817
    }
 
1818
 
 
1819
    conn = domain->conn;
 
1820
 
 
1821
    if (conn->driver->domainGetMaxVcpus)
 
1822
        return conn->driver->domainGetMaxVcpus (domain);
 
1823
 
 
1824
    virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
 
1825
    return -1;
 
1826
}
 
1827
 
 
1828
 
 
1829
/**
 
1830
 * virDomainAttachDevice:
 
1831
 * @domain: pointer to domain object
 
1832
 * @xml: pointer to XML description of one device
 
1833
 * 
 
1834
 * Create a virtual device attachment to backend.
 
1835
 *
 
1836
 * Returns 0 in case of success, -1 in case of failure.
 
1837
 */
 
1838
int
 
1839
virDomainAttachDevice(virDomainPtr domain, char *xml)
 
1840
{
 
1841
    virConnectPtr conn;
 
1842
 
 
1843
    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
 
1844
        virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
 
1845
        return (-1);
 
1846
    }
 
1847
    if (domain->conn->flags & VIR_CONNECT_RO) {
 
1848
        virLibDomainError(domain, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
 
1849
        return (-1);
 
1850
    }
 
1851
    conn = domain->conn;
 
1852
 
 
1853
    if (conn->driver->domainAttachDevice)
 
1854
        return conn->driver->domainAttachDevice (domain, xml);
 
1855
 
 
1856
    virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
 
1857
    return -1;
 
1858
}
 
1859
 
 
1860
/**
 
1861
 * virDomainDetachDevice:
 
1862
 * @domain: pointer to domain object
 
1863
 * @xml: pointer to XML description of one device
 
1864
 * 
 
1865
 * Destroy a virtual device attachment to backend.
 
1866
 *
 
1867
 * Returns 0 in case of success, -1 in case of failure.
 
1868
 */
 
1869
int
 
1870
virDomainDetachDevice(virDomainPtr domain, char *xml)
 
1871
{
 
1872
    virConnectPtr conn;
 
1873
 
 
1874
    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
 
1875
        virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
 
1876
        return (-1);
 
1877
    }
 
1878
    if (domain->conn->flags & VIR_CONNECT_RO) {
 
1879
        virLibDomainError(domain, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
 
1880
        return (-1);
 
1881
    }
 
1882
    conn = domain->conn;
 
1883
 
 
1884
    if (conn->driver->domainDetachDevice)
 
1885
        return conn->driver->domainDetachDevice (domain, xml);
 
1886
 
 
1887
    virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
 
1888
    return -1;
 
1889
}
 
1890
 
 
1891
/**
 
1892
 * virConnectNumOfNetworks:
 
1893
 * @conn: pointer to the hypervisor connection
 
1894
 *
 
1895
 * Provides the number of active networks.
 
1896
 *
 
1897
 * Returns the number of network found or -1 in case of error
 
1898
 */
 
1899
int
 
1900
virConnectNumOfNetworks(virConnectPtr conn)
 
1901
{
 
1902
    if (!VIR_IS_CONNECT(conn)) {
 
1903
        virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
 
1904
        return (-1);
 
1905
    }
 
1906
 
 
1907
    if (conn->networkDriver && conn->networkDriver->numOfNetworks)
 
1908
        return conn->networkDriver->numOfNetworks (conn);
 
1909
 
 
1910
    virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
 
1911
    return -1;
 
1912
}
 
1913
 
 
1914
/**
 
1915
 * virConnectListNetworks:
 
1916
 * @conn: pointer to the hypervisor connection
 
1917
 * @names: array to collect the list of names of active networks
 
1918
 * @maxnames: size of @names
 
1919
 *
 
1920
 * Collect the list of active networks, and store their names in @names
 
1921
 *
 
1922
 * Returns the number of networks found or -1 in case of error
 
1923
 */
 
1924
int
 
1925
virConnectListNetworks(virConnectPtr conn, char **const names, int maxnames)
 
1926
{
 
1927
    if (!VIR_IS_CONNECT(conn)) {
 
1928
        virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
 
1929
        return (-1);
 
1930
    }
 
1931
 
 
1932
    if ((names == NULL) || (maxnames <= 0)) {
 
1933
        virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
 
1934
        return (-1);
 
1935
    }
 
1936
 
 
1937
    if (conn->networkDriver && conn->networkDriver->listNetworks)
 
1938
        return conn->networkDriver->listNetworks (conn, names, maxnames);
 
1939
 
 
1940
    virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
 
1941
    return -1;
 
1942
}
 
1943
 
 
1944
/**
 
1945
 * virConnectNumOfDefinedNetworks:
 
1946
 * @conn: pointer to the hypervisor connection
 
1947
 *
 
1948
 * Provides the number of inactive networks.
 
1949
 *
 
1950
 * Returns the number of networks found or -1 in case of error
 
1951
 */
 
1952
int
 
1953
virConnectNumOfDefinedNetworks(virConnectPtr conn)
 
1954
{
 
1955
    if (!VIR_IS_CONNECT(conn)) {
 
1956
        virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
 
1957
        return (-1);
 
1958
    }
 
1959
 
 
1960
    if (conn->networkDriver && conn->networkDriver->numOfDefinedNetworks)
 
1961
        return conn->networkDriver->numOfDefinedNetworks (conn);
 
1962
 
 
1963
    virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
 
1964
    return -1;
 
1965
}
 
1966
 
 
1967
/**
 
1968
 * virConnectListDefinedNetworks:
 
1969
 * @conn: pointer to the hypervisor connection
 
1970
 * @names: pointer to an array to store the names
 
1971
 * @maxnames: size of the array
 
1972
 *
 
1973
 * list the inactive networks, stores the pointers to the names in @names
 
1974
 *
 
1975
 * Returns the number of names provided in the array or -1 in case of error
 
1976
 */
 
1977
int
 
1978
virConnectListDefinedNetworks(virConnectPtr conn, char **const names,
 
1979
                              int maxnames)
 
1980
{
 
1981
    if (!VIR_IS_CONNECT(conn)) {
 
1982
        virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
 
1983
        return (-1);
 
1984
    }
 
1985
 
 
1986
    if ((names == NULL) || (maxnames <= 0)) {
 
1987
        virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
 
1988
        return (-1);
 
1989
    }
 
1990
 
 
1991
    if (conn->networkDriver && conn->networkDriver->listDefinedNetworks)
 
1992
        return conn->networkDriver->listDefinedNetworks (conn,
 
1993
                                                         names, maxnames);
 
1994
 
 
1995
    virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
 
1996
    return -1;
 
1997
}
 
1998
 
 
1999
/**
 
2000
 * virNetworkLookupByName:
 
2001
 * @conn: pointer to the hypervisor connection
 
2002
 * @name: name for the network
 
2003
 *
 
2004
 * Try to lookup a network on the given hypervisor based on its name.
 
2005
 *
 
2006
 * Returns a new network object or NULL in case of failure
 
2007
 */
 
2008
virNetworkPtr
 
2009
virNetworkLookupByName(virConnectPtr conn, const char *name)
 
2010
{
 
2011
    if (!VIR_IS_CONNECT(conn)) {
 
2012
        virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
 
2013
        return (NULL);
 
2014
    }
 
2015
    if (name == NULL) {
 
2016
        virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
 
2017
        return (NULL);
 
2018
    }
 
2019
 
 
2020
    if (conn->networkDriver && conn->networkDriver->networkLookupByName)
 
2021
        return conn->networkDriver->networkLookupByName (conn, name);
 
2022
 
 
2023
    virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
 
2024
    return NULL;
 
2025
}
 
2026
 
 
2027
/**
 
2028
 * virNetworkLookupByUUID:
 
2029
 * @conn: pointer to the hypervisor connection
 
2030
 * @uuid: the raw UUID for the network
 
2031
 *
 
2032
 * Try to lookup a network on the given hypervisor based on its UUID.
 
2033
 *
 
2034
 * Returns a new network object or NULL in case of failure
 
2035
 */
 
2036
virNetworkPtr
 
2037
virNetworkLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
 
2038
{
 
2039
    if (!VIR_IS_CONNECT(conn)) {
 
2040
        virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
 
2041
        return (NULL);
 
2042
    }
 
2043
    if (uuid == NULL) {
 
2044
        virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
 
2045
        return (NULL);
 
2046
    }
 
2047
 
 
2048
    if (conn->networkDriver && conn->networkDriver->networkLookupByUUID)
 
2049
        return conn->networkDriver->networkLookupByUUID (conn, uuid);
 
2050
 
 
2051
    virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
 
2052
    return NULL;
 
2053
}
 
2054
 
 
2055
/**
 
2056
 * virNetworkLookupByUUIDString:
 
2057
 * @conn: pointer to the hypervisor connection
 
2058
 * @uuidstr: the string UUID for the network
 
2059
 *
 
2060
 * Try to lookup a network on the given hypervisor based on its UUID.
 
2061
 *
 
2062
 * Returns a new network object or NULL in case of failure
 
2063
 */
 
2064
virNetworkPtr
 
2065
virNetworkLookupByUUIDString(virConnectPtr conn, const char *uuidstr)
 
2066
{
 
2067
    int raw[VIR_UUID_BUFLEN], i;
 
2068
    unsigned char uuid[VIR_UUID_BUFLEN];
 
2069
    int ret;
 
2070
 
 
2071
    if (!VIR_IS_CONNECT(conn)) {
 
2072
        virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
 
2073
        return (NULL);
 
2074
    }
 
2075
    if (uuidstr == NULL) {
 
2076
        virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
 
2077
        return (NULL);
 
2078
    }
 
2079
 
 
2080
    /* XXX: sexpr_uuid() also supports 'xxxx-xxxx-xxxx-xxxx' format.
 
2081
     *      We needn't it here. Right?
1887
2082
     */
1888
 
    for (i = 0;i < conn->nb_drivers;i++) {
1889
 
        if ((conn->drivers[i] != NULL) &&
1890
 
            (conn->drivers[i]->domainGetVcpus != NULL)) {
1891
 
            ret = conn->drivers[i]->domainGetVcpus(domain, info, maxinfo,
1892
 
                                                   cpumaps, maplen);
1893
 
            if (ret >= 0)
1894
 
                return(ret);
1895
 
        }
1896
 
    }
1897
 
    virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
1898
 
    return (-1);
1899
 
}
 
2083
    ret = sscanf(uuidstr,
 
2084
                 "%02x%02x%02x%02x-"
 
2085
                 "%02x%02x-"
 
2086
                 "%02x%02x-"
 
2087
                 "%02x%02x-"
 
2088
                 "%02x%02x%02x%02x%02x%02x",
 
2089
                 raw + 0, raw + 1, raw + 2, raw + 3,
 
2090
                 raw + 4, raw + 5, raw + 6, raw + 7,
 
2091
                 raw + 8, raw + 9, raw + 10, raw + 11,
 
2092
                 raw + 12, raw + 13, raw + 14, raw + 15);
 
2093
 
 
2094
    if (ret!=VIR_UUID_BUFLEN) {
 
2095
        virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
 
2096
        return (NULL);
 
2097
    }
 
2098
    for (i = 0; i < VIR_UUID_BUFLEN; i++)
 
2099
        uuid[i] = raw[i] & 0xFF;
 
2100
 
 
2101
    return virNetworkLookupByUUID(conn, &uuid[0]);
 
2102
}
 
2103
 
 
2104
/**
 
2105
 * virNetworkCreateXML:
 
2106
 * @conn: pointer to the hypervisor connection
 
2107
 * @xmlDesc: an XML description of the network
 
2108
 *
 
2109
 * Create and start a new virtual network, based on an XML description
 
2110
 * similar to the one returned by virNetworkGetXMLDesc()
 
2111
 *
 
2112
 * Returns a new network object or NULL in case of failure
 
2113
 */
 
2114
virNetworkPtr
 
2115
virNetworkCreateXML(virConnectPtr conn, const char *xmlDesc)
 
2116
{
 
2117
    if (!VIR_IS_CONNECT(conn)) {
 
2118
        virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
 
2119
        return (NULL);
 
2120
    }
 
2121
    if (xmlDesc == NULL) {
 
2122
        virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
 
2123
        return (NULL);
 
2124
    }
 
2125
    if (conn->flags & VIR_CONNECT_RO) {
 
2126
        virLibConnError(conn, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
 
2127
        return (NULL);
 
2128
    }
 
2129
 
 
2130
    if (conn->networkDriver && conn->networkDriver->networkCreateXML)
 
2131
        return conn->networkDriver->networkCreateXML (conn, xmlDesc);
 
2132
 
 
2133
    virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
 
2134
    return NULL;
 
2135
}
 
2136
 
 
2137
/**
 
2138
 * virNetworkDefineXML:
 
2139
 * @conn: pointer to the hypervisor connection
 
2140
 * @xml: the XML description for the network, preferably in UTF-8
 
2141
 *
 
2142
 * Define a network, but does not create it
 
2143
 *
 
2144
 * Returns NULL in case of error, a pointer to the network otherwise
 
2145
 */
 
2146
virNetworkPtr
 
2147
virNetworkDefineXML(virConnectPtr conn, const char *xml)
 
2148
{
 
2149
    if (!VIR_IS_CONNECT(conn)) {
 
2150
        virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
 
2151
        return (NULL);
 
2152
    }
 
2153
    if (conn->flags & VIR_CONNECT_RO) {
 
2154
        virLibConnError(conn, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
 
2155
        return (NULL);
 
2156
    }
 
2157
    if (xml == NULL) {
 
2158
        virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
 
2159
        return (NULL);
 
2160
    }
 
2161
 
 
2162
    if (conn->networkDriver && conn->networkDriver->networkDefineXML)
 
2163
        return conn->networkDriver->networkDefineXML (conn, xml);
 
2164
 
 
2165
    virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
 
2166
    return NULL;
 
2167
}
 
2168
 
 
2169
/**
 
2170
 * virNetworkUndefine:
 
2171
 * @network: pointer to a defined network
 
2172
 *
 
2173
 * Undefine a network but does not stop it if it is running
 
2174
 *
 
2175
 * Returns 0 in case of success, -1 in case of error
 
2176
 */
 
2177
int
 
2178
virNetworkUndefine(virNetworkPtr network) {
 
2179
    virConnectPtr conn;
 
2180
 
 
2181
    if (!VIR_IS_CONNECTED_NETWORK(network)) {
 
2182
        virLibNetworkError(network, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
 
2183
        return (-1);
 
2184
    }
 
2185
    conn = network->conn;
 
2186
    if (conn->flags & VIR_CONNECT_RO) {
 
2187
        virLibNetworkError(network, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
 
2188
        return (-1);
 
2189
    }
 
2190
 
 
2191
    if (conn->networkDriver && conn->networkDriver->networkUndefine)
 
2192
        return conn->networkDriver->networkUndefine (network);
 
2193
 
 
2194
    virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
 
2195
    return -1;
 
2196
}
 
2197
 
 
2198
/**
 
2199
 * virNetworkCreate:
 
2200
 * @network: pointer to a defined network
 
2201
 *
 
2202
 * Create and start a defined network. If the call succeed the network
 
2203
 * moves from the defined to the running networks pools.
 
2204
 *
 
2205
 * Returns 0 in case of success, -1 in case of error
 
2206
 */
 
2207
int
 
2208
virNetworkCreate(virNetworkPtr network)
 
2209
{
 
2210
    virConnectPtr conn;
 
2211
    if (network == NULL) {
 
2212
        TODO
 
2213
        return (-1);
 
2214
    }
 
2215
    if (!VIR_IS_CONNECTED_NETWORK(network)) {
 
2216
        virLibNetworkError(network, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
 
2217
        return (-1);
 
2218
    }
 
2219
    conn = network->conn;
 
2220
    if (conn->flags & VIR_CONNECT_RO) {
 
2221
        virLibNetworkError(network, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
 
2222
        return (-1);
 
2223
    }
 
2224
 
 
2225
    if (conn->networkDriver && conn->networkDriver->networkCreate)
 
2226
        return conn->networkDriver->networkCreate (network);
 
2227
 
 
2228
    virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
 
2229
    return -1;
 
2230
}
 
2231
 
 
2232
/**
 
2233
 * virNetworkDestroy:
 
2234
 * @network: a network object
 
2235
 *
 
2236
 * Destroy the network object. The running instance is shutdown if not down
 
2237
 * already and all resources used by it are given back to the hypervisor.
 
2238
 * The data structure is freed and should not be used thereafter if the
 
2239
 * call does not return an error.
 
2240
 * This function may requires priviledged access
 
2241
 *
 
2242
 * Returns 0 in case of success and -1 in case of failure.
 
2243
 */
 
2244
int
 
2245
virNetworkDestroy(virNetworkPtr network)
 
2246
{
 
2247
    virConnectPtr conn;
 
2248
 
 
2249
    if (!VIR_IS_CONNECTED_NETWORK(network)) {
 
2250
        virLibNetworkError(network, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
 
2251
        return (-1);
 
2252
    }
 
2253
 
 
2254
    conn = network->conn;
 
2255
    if (conn->flags & VIR_CONNECT_RO) {
 
2256
        virLibNetworkError(network, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
 
2257
        return (-1);
 
2258
    }
 
2259
 
 
2260
    if (conn->networkDriver && conn->networkDriver->networkDestroy)
 
2261
        return conn->networkDriver->networkDestroy (network);
 
2262
 
 
2263
    virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
 
2264
    return -1;
 
2265
}
 
2266
 
 
2267
/**
 
2268
 * virNetworkFree:
 
2269
 * @network: a network object
 
2270
 *
 
2271
 * Free the network object. The running instance is kept alive.
 
2272
 * The data structure is freed and should not be used thereafter.
 
2273
 *
 
2274
 * Returns 0 in case of success and -1 in case of failure.
 
2275
 */
 
2276
int
 
2277
virNetworkFree(virNetworkPtr network)
 
2278
{
 
2279
    if (!VIR_IS_NETWORK(network)) {
 
2280
        virLibNetworkError(network, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
 
2281
        return (-1);
 
2282
    }
 
2283
    if (virFreeNetwork(network->conn, network) < 0)
 
2284
        return (-1);
 
2285
    return(0);
 
2286
}
 
2287
 
 
2288
/**
 
2289
 * virNetworkGetName:
 
2290
 * @network: a network object
 
2291
 *
 
2292
 * Get the public name for that network
 
2293
 *
 
2294
 * Returns a pointer to the name or NULL, the string need not be deallocated
 
2295
 * its lifetime will be the same as the network object.
 
2296
 */
 
2297
const char *
 
2298
virNetworkGetName(virNetworkPtr network)
 
2299
{
 
2300
    if (!VIR_IS_NETWORK(network)) {
 
2301
        virLibNetworkError(network, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
 
2302
        return (NULL);
 
2303
    }
 
2304
    return (network->name);
 
2305
}
 
2306
 
 
2307
/**
 
2308
 * virNetworkGetUUID:
 
2309
 * @network: a network object
 
2310
 * @uuid: pointer to a VIR_UUID_BUFLEN bytes array
 
2311
 *
 
2312
 * Get the UUID for a network
 
2313
 *
 
2314
 * Returns -1 in case of error, 0 in case of success
 
2315
 */
 
2316
int
 
2317
virNetworkGetUUID(virNetworkPtr network, unsigned char *uuid)
 
2318
{
 
2319
    if (!VIR_IS_NETWORK(network)) {
 
2320
        virLibNetworkError(network, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
 
2321
        return (-1);
 
2322
    }
 
2323
    if (uuid == NULL) {
 
2324
        virLibNetworkError(network, VIR_ERR_INVALID_ARG, __FUNCTION__);
 
2325
        return (-1);
 
2326
    }
 
2327
 
 
2328
    memcpy(uuid, &network->uuid[0], VIR_UUID_BUFLEN);
 
2329
 
 
2330
    return (0);
 
2331
}
 
2332
 
 
2333
/**
 
2334
 * virNetworkGetUUIDString:
 
2335
 * @network: a network object
 
2336
 * @buf: pointer to a VIR_UUID_STRING_BUFLEN bytes array
 
2337
 *
 
2338
 * Get the UUID for a network as string. For more information about
 
2339
 * UUID see RFC4122.
 
2340
 *
 
2341
 * Returns -1 in case of error, 0 in case of success
 
2342
 */
 
2343
int
 
2344
virNetworkGetUUIDString(virNetworkPtr network, char *buf)
 
2345
{
 
2346
    unsigned char uuid[VIR_UUID_BUFLEN];
 
2347
 
 
2348
    if (!VIR_IS_NETWORK(network)) {
 
2349
        virLibNetworkError(network, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
 
2350
        return (-1);
 
2351
    }
 
2352
    if (buf == NULL) {
 
2353
        virLibNetworkError(network, VIR_ERR_INVALID_ARG, __FUNCTION__);
 
2354
        return (-1);
 
2355
    }
 
2356
 
 
2357
    if (virNetworkGetUUID(network, &uuid[0]))
 
2358
        return (-1);
 
2359
 
 
2360
    snprintf(buf, VIR_UUID_STRING_BUFLEN,
 
2361
        "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
 
2362
                      uuid[0], uuid[1], uuid[2], uuid[3],
 
2363
                      uuid[4], uuid[5], uuid[6], uuid[7],
 
2364
                      uuid[8], uuid[9], uuid[10], uuid[11],
 
2365
                      uuid[12], uuid[13], uuid[14], uuid[15]);
 
2366
    return (0);
 
2367
}
 
2368
 
 
2369
/**
 
2370
 * virNetworkGetXMLDesc:
 
2371
 * @network: a network object
 
2372
 * @flags: and OR'ed set of extraction flags, not used yet
 
2373
 *
 
2374
 * Provide an XML description of the network. The description may be reused
 
2375
 * later to relaunch the network with virNetworkCreateXML().
 
2376
 *
 
2377
 * Returns a 0 terminated UTF-8 encoded XML instance, or NULL in case of error.
 
2378
 *         the caller must free() the returned value.
 
2379
 */
 
2380
char *
 
2381
virNetworkGetXMLDesc(virNetworkPtr network, int flags)
 
2382
{
 
2383
    virConnectPtr conn;
 
2384
 
 
2385
    if (!VIR_IS_NETWORK(network)) {
 
2386
        virLibNetworkError(network, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
 
2387
        return (NULL);
 
2388
    }
 
2389
    if (flags != 0) {
 
2390
        virLibNetworkError(network, VIR_ERR_INVALID_ARG, __FUNCTION__);
 
2391
        return (NULL);
 
2392
    }
 
2393
 
 
2394
    conn = network->conn;
 
2395
 
 
2396
    if (conn->networkDriver && conn->networkDriver->networkDumpXML)
 
2397
        return conn->networkDriver->networkDumpXML (network, flags);
 
2398
 
 
2399
    virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
 
2400
    return NULL;
 
2401
}
 
2402
 
 
2403
/**
 
2404
 * virNetworkGetBridgeName:
 
2405
 * @network: a network object
 
2406
 *
 
2407
 * Provides a bridge interface name to which a domain may connect
 
2408
 * a network interface in order to join the network.
 
2409
 *
 
2410
 * Returns a 0 terminated interface name, or NULL in case of error.
 
2411
 *         the caller must free() the returned value.
 
2412
 */
 
2413
char *
 
2414
virNetworkGetBridgeName(virNetworkPtr network)
 
2415
{
 
2416
    virConnectPtr conn;
 
2417
 
 
2418
    if (!VIR_IS_NETWORK(network)) {
 
2419
        virLibNetworkError(network, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
 
2420
        return (NULL);
 
2421
    }
 
2422
 
 
2423
    conn = network->conn;
 
2424
 
 
2425
    if (conn->networkDriver && conn->networkDriver->networkGetBridgeName)
 
2426
        return conn->networkDriver->networkGetBridgeName (network);
 
2427
 
 
2428
    virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
 
2429
    return NULL;
 
2430
}
 
2431
 
 
2432
/**
 
2433
 * virNetworkGetAutostart:
 
2434
 * @network: a network object
 
2435
 * @autostart: the value returned
 
2436
 *
 
2437
 * Provides a boolean value indicating whether the network
 
2438
 * configured to be automatically started when the host
 
2439
 * machine boots.
 
2440
 *
 
2441
 * Returns -1 in case of error, 0 in case of success
 
2442
 */
 
2443
int
 
2444
virNetworkGetAutostart(virNetworkPtr network,
 
2445
                       int *autostart)
 
2446
{
 
2447
    virConnectPtr conn;
 
2448
 
 
2449
    if (!VIR_IS_NETWORK(network)) {
 
2450
        virLibNetworkError(network, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
 
2451
        return (-1);
 
2452
    }
 
2453
    if (!autostart) {
 
2454
        virLibNetworkError(network, VIR_ERR_INVALID_ARG, __FUNCTION__);
 
2455
        return (-1);
 
2456
    }
 
2457
 
 
2458
    conn = network->conn;
 
2459
 
 
2460
    if (conn->networkDriver && conn->networkDriver->networkGetAutostart)
 
2461
        return conn->networkDriver->networkGetAutostart (network, autostart);
 
2462
 
 
2463
    virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
 
2464
    return -1;
 
2465
}
 
2466
 
 
2467
/**
 
2468
 * virNetworkSetAutostart:
 
2469
 * @network: a network object
 
2470
 * @autostart: whether the network should be automatically started 0 or 1
 
2471
 *
 
2472
 * Configure the network to be automatically started
 
2473
 * when the host machine boots.
 
2474
 *
 
2475
 * Returns -1 in case of error, 0 in case of success
 
2476
 */
 
2477
int
 
2478
virNetworkSetAutostart(virNetworkPtr network,
 
2479
                       int autostart)
 
2480
{
 
2481
    virConnectPtr conn;
 
2482
 
 
2483
    if (!VIR_IS_NETWORK(network)) {
 
2484
        virLibNetworkError(network, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
 
2485
        return (-1);
 
2486
    }
 
2487
 
 
2488
    conn = network->conn;
 
2489
 
 
2490
    if (conn->networkDriver && conn->networkDriver->networkSetAutostart)
 
2491
        return conn->networkDriver->networkSetAutostart (network, autostart);
 
2492
 
 
2493
    virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
 
2494
    return -1;
 
2495
}
 
2496
 
 
2497
/*
 
2498
 * vim: set tabstop=4:
 
2499
 * vim: set shiftwidth=4:
 
2500
 * vim: set expandtab:
 
2501
 */
 
2502
/*
 
2503
 * Local variables:
 
2504
 *  indent-tabs-mode: nil
 
2505
 *  c-indent-level: 4
 
2506
 *  c-basic-offset: 4
 
2507
 *  tab-width: 4
 
2508
 * End:
 
2509
 */