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

« back to all changes in this revision

Viewing changes to src/xs_internal.c

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Mitchell
  • Date: 2006-10-23 20:00:28 UTC
  • Revision ID: james.westby@ubuntu.com-20061023200028-ucukxl0jrwmteed6
Tags: upstream-0.1.8
ImportĀ upstreamĀ versionĀ 0.1.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * xs_internal.c: access to Xen Store
 
3
 *
 
4
 * Copyright (C) 2006 Red Hat, Inc.
 
5
 *
 
6
 * See COPYING.LIB for the License of this software
 
7
 *
 
8
 * Daniel Veillard <veillard@redhat.com>
 
9
 */
 
10
 
 
11
#include <stdio.h>
 
12
#include <string.h>
 
13
#include <unistd.h>
 
14
#include <stdlib.h>
 
15
#include <fcntl.h>
 
16
#include <sys/mman.h>
 
17
#include <sys/ioctl.h>
 
18
 
 
19
#include <stdint.h>
 
20
 
 
21
#include <xen/dom0_ops.h>
 
22
#include <xen/version.h>
 
23
#include <xen/xen.h>
 
24
 
 
25
#include <xs.h>
 
26
 
 
27
#include "internal.h"
 
28
#include "driver.h"
 
29
#include "xs_internal.h"
 
30
#include "xen_internal.h" /* for xenHypervisorCheckID */
 
31
 
 
32
#define XEN_HYPERVISOR_SOCKET "/proc/xen/privcmd"
 
33
 
 
34
#ifndef PROXY
 
35
static virDriver xenStoreDriver = {
 
36
    VIR_DRV_XEN_STORE,
 
37
    "XenStore",
 
38
    (DOM0_INTERFACE_VERSION >> 24) * 1000000 +
 
39
    ((DOM0_INTERFACE_VERSION >> 16) & 0xFF) * 1000 +
 
40
    (DOM0_INTERFACE_VERSION & 0xFFFF),
 
41
    NULL, /* init */
 
42
    xenStoreOpen, /* open */
 
43
    xenStoreClose, /* close */
 
44
    NULL, /* type */
 
45
    NULL, /* version */
 
46
    NULL, /* nodeGetInfo */
 
47
    xenStoreListDomains, /* listDomains */
 
48
    NULL, /* numOfDomains */
 
49
    NULL, /* domainCreateLinux */
 
50
    NULL, /* domainLookupByID */
 
51
    NULL, /* domainLookupByUUID */
 
52
    xenStoreDomainLookupByName, /* domainLookupByName */
 
53
    NULL, /* domainSuspend */
 
54
    NULL, /* domainResume */
 
55
    xenStoreDomainShutdown, /* domainShutdown */
 
56
    xenStoreDomainReboot, /* domainReboot */
 
57
    NULL, /* domainDestroy */
 
58
    NULL, /* domainFree */
 
59
    NULL, /* domainGetName */
 
60
    NULL, /* domainGetID */
 
61
    NULL, /* domainGetUUID */
 
62
    NULL, /* domainGetOSType */
 
63
    xenStoreDomainGetMaxMemory, /* domainGetMaxMemory */
 
64
    NULL, /* domainSetMaxMemory */
 
65
    xenStoreDomainSetMemory, /* domainSetMemory */
 
66
    xenStoreGetDomainInfo, /* domainGetInfo */
 
67
    NULL, /* domainSave */
 
68
    NULL, /* domainRestore */
 
69
    NULL, /* domainSetVcpus */
 
70
    NULL, /* domainPinVcpu */
 
71
    NULL, /* domainGetVcpus */
 
72
    NULL, /* domainDumpXML */
 
73
    NULL, /* listDefinedDomains */
 
74
    NULL, /* numOfDefinedDomains */
 
75
    NULL, /* domainCreate */
 
76
    NULL, /* domainDefineXML */
 
77
    NULL, /* domainUndefine */
 
78
};
 
79
 
 
80
/**
 
81
 * xenStoreRegister:
 
82
 *
 
83
 * Registers the xenStore driver
 
84
 */
 
85
void xenStoreRegister(void)
 
86
{
 
87
    virRegisterDriver(&xenStoreDriver);
 
88
}
 
89
#endif /* ! PROXY */
 
90
 
 
91
/**
 
92
 * virXenStoreError:
 
93
 * @conn: the connection if available
 
94
 * @error: the error number
 
95
 * @info: extra information string
 
96
 *
 
97
 * Handle an error at the xend store interface
 
98
 */
 
99
static void
 
100
virXenStoreError(virConnectPtr conn, virErrorNumber error, const char *info)
 
101
{
 
102
    const char *errmsg;
 
103
 
 
104
    if (error == VIR_ERR_OK)
 
105
        return;
 
106
 
 
107
    errmsg = __virErrorMsg(error, info);
 
108
    __virRaiseError(conn, NULL, VIR_FROM_XENSTORE, error, VIR_ERR_ERROR,
 
109
                    errmsg, info, NULL, 0, 0, errmsg, info);
 
110
}
 
111
 
 
112
/************************************************************************
 
113
 *                                                                      *
 
114
 *              Helper internal APIs                                    *
 
115
 *                                                                      *
 
116
 ************************************************************************/
 
117
#ifndef PROXY
 
118
/**
 
119
 * virConnectDoStoreList:
 
120
 * @conn: pointer to the hypervisor connection
 
121
 * @path: the absolute path of the directory in the store to list
 
122
 * @nb: OUT pointer to the number of items found
 
123
 *
 
124
 * Internal API querying the Xenstore for a list
 
125
 *
 
126
 * Returns a string which must be freed by the caller or NULL in case of error
 
127
 */
 
128
static char **
 
129
virConnectDoStoreList(virConnectPtr conn, const char *path,
 
130
                      unsigned int *nb)
 
131
{
 
132
    if ((conn == NULL) || (conn->xshandle == NULL) || (path == NULL) ||
 
133
        (nb == NULL))
 
134
        return (NULL);
 
135
 
 
136
    return xs_directory(conn->xshandle, 0, path, nb);
 
137
}
 
138
#endif /* ! PROXY */
 
139
 
 
140
/**
 
141
 * virDomainDoStoreQuery:
 
142
 * @conn: pointer to the hypervisor connection
 
143
 * @domid: id of the domain
 
144
 * @path: the relative path of the data in the store to retrieve
 
145
 *
 
146
 * Internal API querying the Xenstore for a string value.
 
147
 *
 
148
 * Returns a string which must be freed by the caller or NULL in case of error
 
149
 */
 
150
static char *
 
151
virDomainDoStoreQuery(virConnectPtr conn, int domid, const char *path)
 
152
{
 
153
    char s[256];
 
154
    unsigned int len = 0;
 
155
 
 
156
    if (!conn || conn->xshandle == NULL)
 
157
        return (NULL);
 
158
 
 
159
    snprintf(s, 255, "/local/domain/%d/%s", domid, path);
 
160
    s[255] = 0;
 
161
 
 
162
    return xs_read(conn->xshandle, 0, &s[0], &len);
 
163
}
 
164
 
 
165
#ifndef PROXY
 
166
/**
 
167
 * virDomainDoStoreWrite:
 
168
 * @domain: a domain object
 
169
 * @path: the relative path of the data in the store to retrieve
 
170
 *
 
171
 * Internal API setting up a string value in the Xenstore
 
172
 * Requires write access to the XenStore
 
173
 *
 
174
 * Returns 0 in case of success, -1 in case of failure
 
175
 */
 
176
static int
 
177
virDomainDoStoreWrite(virDomainPtr domain, const char *path,
 
178
                      const char *value)
 
179
{
 
180
    char s[256];
 
181
 
 
182
    int ret = -1;
 
183
 
 
184
    if (!VIR_IS_CONNECTED_DOMAIN(domain))
 
185
        return (-1);
 
186
    if (domain->conn->xshandle == NULL)
 
187
        return (-1);
 
188
    if (domain->conn->flags & VIR_CONNECT_RO)
 
189
        return (-1);
 
190
 
 
191
    snprintf(s, 255, "/local/domain/%d/%s", domain->handle, path);
 
192
    s[255] = 0;
 
193
 
 
194
    if (xs_write(domain->conn->xshandle, 0, &s[0], value, strlen(value)))
 
195
        ret = 0;
 
196
 
 
197
    return (ret);
 
198
}
 
199
 
 
200
/**
 
201
 * virDomainGetVM:
 
202
 * @domain: a domain object
 
203
 *
 
204
 * Internal API extracting a xenstore vm path.
 
205
 *
 
206
 * Returns the new string or NULL in case of error
 
207
 */
 
208
char *
 
209
virDomainGetVM(virDomainPtr domain)
 
210
{
 
211
    char *vm;
 
212
    char query[200];
 
213
    unsigned int len;
 
214
 
 
215
    if (!VIR_IS_CONNECTED_DOMAIN(domain))
 
216
        return (NULL);
 
217
    if (domain->conn->xshandle == NULL)
 
218
        return (NULL);
 
219
 
 
220
    snprintf(query, 199, "/local/domain/%d/vm", virDomainGetID(domain));
 
221
    query[199] = 0;
 
222
 
 
223
    vm = xs_read(domain->conn->xshandle, 0, &query[0], &len);
 
224
 
 
225
    return (vm);
 
226
}
 
227
 
 
228
/**
 
229
 * virDomainGetVMInfo:
 
230
 * @domain: a domain object
 
231
 * @vm: the xenstore vm path
 
232
 * @name: the value's path
 
233
 *
 
234
 * Internal API extracting one information the device used 
 
235
 * by the domain from xensttore
 
236
 *
 
237
 * Returns the new string or NULL in case of error
 
238
 */
 
239
char *
 
240
virDomainGetVMInfo(virDomainPtr domain, const char *vm, const char *name)
 
241
{
 
242
    char s[256];
 
243
    char *ret = NULL;
 
244
    unsigned int len = 0;
 
245
 
 
246
    if (!VIR_IS_CONNECTED_DOMAIN(domain))
 
247
        return (NULL);
 
248
    if (domain->conn->xshandle == NULL)
 
249
        return (NULL);
 
250
 
 
251
    snprintf(s, 255, "%s/%s", vm, name);
 
252
    s[255] = 0;
 
253
 
 
254
    ret = xs_read(domain->conn->xshandle, 0, &s[0], &len);
 
255
 
 
256
    return (ret);
 
257
}
 
258
 
 
259
#if 0
 
260
/**
 
261
 * virConnectCheckStoreID:
 
262
 * @conn: pointer to the hypervisor connection
 
263
 * @id: the id number as returned from Xenstore
 
264
 *
 
265
 * the xenstore sometimes list non-running domains, double check
 
266
 * from the hypervisor if we have direct access
 
267
 *
 
268
 * Returns -1 if the check failed, 0 if successful or not possible to check
 
269
 */
 
270
static int
 
271
virConnectCheckStoreID(virConnectPtr conn, int id)
 
272
{
 
273
    if (conn->handle >= 0) {
 
274
        int tmp;
 
275
 
 
276
        tmp = xenHypervisorCheckID(conn, id);
 
277
        if (tmp < 0)
 
278
            return (-1);
 
279
    }
 
280
    return (0);
 
281
}
 
282
#endif
 
283
#endif /* ! PROXY */
 
284
 
 
285
/************************************************************************
 
286
 *                                                                      *
 
287
 *              Canonical internal APIs                                 *
 
288
 *                                                                      *
 
289
 ************************************************************************/
 
290
/**
 
291
 * xenStoreOpen:
 
292
 * @conn: pointer to the connection block
 
293
 * @name: URL for the target, NULL for local
 
294
 * @flags: combination of virDrvOpenFlag(s)
 
295
 *
 
296
 * Connects to the Xen hypervisor.
 
297
 *
 
298
 * Returns 0 or -1 in case of error.
 
299
 */
 
300
int
 
301
xenStoreOpen(virConnectPtr conn, const char *name, int flags)
 
302
{
 
303
    if ((name != NULL) && (strcasecmp(name, "xen")))
 
304
        return(-1);
 
305
 
 
306
#ifdef PROXY
 
307
    conn->xshandle = xs_daemon_open_readonly();
 
308
#else
 
309
    if (flags & VIR_DRV_OPEN_RO)
 
310
        conn->xshandle = xs_daemon_open_readonly();
 
311
    else
 
312
        conn->xshandle = xs_daemon_open();
 
313
#endif /* ! PROXY */
 
314
 
 
315
    if (conn->xshandle == NULL) {
 
316
        if (!(flags & VIR_DRV_OPEN_QUIET))
 
317
            virXenStoreError(conn, VIR_ERR_NO_XEN, 
 
318
                             _("failed to connect to Xen Store"));
 
319
        return (-1);
 
320
    }
 
321
    return (0);
 
322
}
 
323
 
 
324
/**
 
325
 * xenStoreClose:
 
326
 * @conn: pointer to the connection block
 
327
 *
 
328
 * Close the connection to the Xen hypervisor.
 
329
 *
 
330
 * Returns 0 in case of success or -1 in case of error.
 
331
 */
 
332
int
 
333
xenStoreClose(virConnectPtr conn)
 
334
{
 
335
    if (conn == NULL) {
 
336
        virXenStoreError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
 
337
        return(-1);
 
338
    }
 
339
    if (conn->xshandle == NULL)
 
340
        return(-1);
 
341
 
 
342
    xs_daemon_close(conn->xshandle);
 
343
    return (0);
 
344
}
 
345
 
 
346
#ifndef PROXY
 
347
/**
 
348
 * xenStoreGetDomainInfo:
 
349
 * @domain: pointer to the domain block
 
350
 * @info: the place where information should be stored
 
351
 *
 
352
 * Do an hypervisor call to get the related set of domain information.
 
353
 *
 
354
 * Returns 0 in case of success, -1 in case of error.
 
355
 */
 
356
int
 
357
xenStoreGetDomainInfo(virDomainPtr domain, virDomainInfoPtr info)
 
358
{
 
359
    char *tmp, **tmp2;
 
360
    unsigned int nb_vcpus;
 
361
    char request[200];
 
362
 
 
363
    if (!VIR_IS_CONNECTED_DOMAIN(domain))
 
364
        return (-1);
 
365
 
 
366
    if ((domain == NULL) || (domain->conn == NULL) || (info == NULL)) {
 
367
        virXenStoreError(domain ? domain->conn : NULL, VIR_ERR_INVALID_ARG,
 
368
                         __FUNCTION__);
 
369
        return(-1);
 
370
    }
 
371
    if (domain->conn->xshandle == NULL)
 
372
        return(-1);
 
373
 
 
374
    tmp = virDomainDoStoreQuery(domain->conn, domain->handle, "running");
 
375
    if (tmp != NULL) {
 
376
        if (tmp[0] == '1')
 
377
            info->state = VIR_DOMAIN_RUNNING;
 
378
        free(tmp);
 
379
    } else {
 
380
        info->state = VIR_DOMAIN_NONE;
 
381
    }
 
382
    tmp = virDomainDoStoreQuery(domain->conn, domain->handle, "memory/target");
 
383
    if (tmp != NULL) {
 
384
        info->memory = atol(tmp);
 
385
        info->maxMem = atol(tmp);
 
386
        free(tmp);
 
387
    } else {
 
388
        info->memory = 0;
 
389
        info->maxMem = 0;
 
390
    }
 
391
#if 0
 
392
    /* doesn't seems to work */
 
393
    tmp = virDomainDoStoreQuery(domain->conn, domain->handle, "cpu_time");
 
394
    if (tmp != NULL) {
 
395
        info->cpuTime = atol(tmp);
 
396
        free(tmp);
 
397
    } else {
 
398
        info->cpuTime = 0;
 
399
    }
 
400
#endif
 
401
    snprintf(request, 199, "/local/domain/%d/cpu", domain->handle);
 
402
    request[199] = 0;
 
403
    tmp2 = virConnectDoStoreList(domain->conn, request, &nb_vcpus);
 
404
    if (tmp2 != NULL) {
 
405
        info->nrVirtCpu = nb_vcpus;
 
406
        free(tmp2);
 
407
    }
 
408
    return (0);
 
409
}
 
410
 
 
411
/**
 
412
 * xenStoreDomainSetMemory:
 
413
 * @domain: pointer to the domain block
 
414
 * @memory: the max memory size in kilobytes.
 
415
 *
 
416
 * Change the maximum amount of memory allowed in the xen store
 
417
 *
 
418
 * Returns 0 in case of success, -1 in case of error.
 
419
 */
 
420
int
 
421
xenStoreDomainSetMemory(virDomainPtr domain, unsigned long memory)
 
422
{
 
423
    int ret;
 
424
    char value[20];
 
425
 
 
426
    if ((domain == NULL) || (domain->conn == NULL) || (memory < 4096)) {
 
427
        virXenStoreError(domain ? domain->conn : NULL, VIR_ERR_INVALID_ARG,
 
428
                         __FUNCTION__);
 
429
        return(-1);
 
430
    }
 
431
    snprintf(value, 19, "%lu", memory);
 
432
    value[19] = 0;
 
433
    ret = virDomainDoStoreWrite(domain, "memory/target", &value[0]);
 
434
    if (ret < 0)
 
435
        return (-1);
 
436
    return (0);
 
437
}
 
438
 
 
439
/**
 
440
 * xenStoreDomainGetMaxMemory:
 
441
 * @domain: pointer to the domain block
 
442
 *
 
443
 * Ask the xenstore for the maximum memory allowed for a domain
 
444
 *
 
445
 * Returns the memory size in kilobytes or 0 in case of error.
 
446
 */
 
447
unsigned long
 
448
xenStoreDomainGetMaxMemory(virDomainPtr domain)
 
449
{
 
450
    char *tmp;
 
451
    unsigned long ret = 0;
 
452
 
 
453
    if (!VIR_IS_CONNECTED_DOMAIN(domain))
 
454
        return (ret);
 
455
 
 
456
    tmp = virDomainDoStoreQuery(domain->conn, domain->handle, "memory/target");
 
457
    if (tmp != NULL) {
 
458
        ret = (unsigned long) atol(tmp);
 
459
        free(tmp);
 
460
    }
 
461
    return(ret);
 
462
}
 
463
 
 
464
/**
 
465
 * xenStoreNumOfDomains:
 
466
 * @conn: pointer to the hypervisor connection
 
467
 *
 
468
 * Provides the number of active domains.
 
469
 *
 
470
 * Returns the number of domain found or -1 in case of error
 
471
 */
 
472
int
 
473
xenStoreNumOfDomains(virConnectPtr conn)
 
474
{
 
475
    unsigned int num;
 
476
    char **idlist;
 
477
    int ret = -1;
 
478
 
 
479
    if ((conn == NULL) || (conn->xshandle == NULL)) {
 
480
        virXenStoreError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
 
481
        return(-1);
 
482
    }
 
483
    idlist = xs_directory(conn->xshandle, 0, "/local/domain", &num);
 
484
    if (idlist) {
 
485
        free(idlist);
 
486
        ret = num;
 
487
    }
 
488
    return(ret);
 
489
}
 
490
 
 
491
/**
 
492
 * xenStoreListDomains:
 
493
 * @conn: pointer to the hypervisor connection
 
494
 * @ids: array to collect the list of IDs of active domains
 
495
 * @maxids: size of @ids
 
496
 *
 
497
 * Collect the list of active domains, and store their ID in @maxids
 
498
 *
 
499
 * Returns the number of domain found or -1 in case of error
 
500
 */
 
501
int
 
502
xenStoreListDomains(virConnectPtr conn, int *ids, int maxids)
 
503
{
 
504
    char **idlist = NULL, *endptr;
 
505
    unsigned int num, i;
 
506
    int ret;
 
507
    long id;
 
508
 
 
509
    if ((conn == NULL) || (ids == NULL)) {
 
510
        virXenStoreError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
 
511
        return(-1);
 
512
    }
 
513
    if (conn->xshandle == NULL)
 
514
        return(-1);
 
515
 
 
516
    idlist = xs_directory(conn->xshandle, 0, "/local/domain", &num);
 
517
    if (idlist == NULL)
 
518
        return(-1);
 
519
 
 
520
    for (ret = 0, i = 0; (i < num) && (ret < maxids); i++) {
 
521
        id = strtol(idlist[i], &endptr, 10);
 
522
        if ((endptr == idlist[i]) || (*endptr != 0)) {
 
523
            ret = -1;
 
524
            break;
 
525
        }
 
526
#if 0
 
527
        if (virConnectCheckStoreID(conn, (int) id) < 0)
 
528
            continue;
 
529
#endif
 
530
        ids[ret++] = (int) id;
 
531
    }
 
532
    return(ret);
 
533
}
 
534
 
 
535
/**
 
536
 * xenStoreDomainLookupByName:
 
537
 * @conn: A xend instance
 
538
 * @name: The name of the domain
 
539
 *
 
540
 * Try to lookup a domain on the Xen Store based on its name.
 
541
 *
 
542
 * Returns a new domain object or NULL in case of failure
 
543
 */
 
544
virDomainPtr
 
545
xenStoreDomainLookupByName(virConnectPtr conn, const char *name)
 
546
{
 
547
    virDomainPtr ret = NULL;
 
548
    unsigned int num, i, len;
 
549
    long id = -1;
 
550
    char **idlist = NULL, *endptr;
 
551
    char prop[200], *tmp, *path = NULL;
 
552
    int found = 0;
 
553
    struct xend_domain *xenddomain = NULL;
 
554
 
 
555
    if ((conn == NULL) || (name == NULL)) {
 
556
        virXenStoreError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
 
557
        return(NULL);
 
558
    }
 
559
    if (conn->xshandle == NULL)
 
560
        return(NULL);
 
561
 
 
562
    idlist = xs_directory(conn->xshandle, 0, "/local/domain", &num);
 
563
    if (idlist == NULL)
 
564
        goto done;
 
565
 
 
566
    for (i = 0; i < num; i++) {
 
567
        id = strtol(idlist[i], &endptr, 10);
 
568
        if ((endptr == idlist[i]) || (*endptr != 0)) {
 
569
            goto done;
 
570
        }
 
571
#if 0
 
572
        if (virConnectCheckStoreID(conn, (int) id) < 0)
 
573
            continue;
 
574
#endif
 
575
        snprintf(prop, 199, "/local/domain/%s/name", idlist[i]);
 
576
        prop[199] = 0;
 
577
        tmp = xs_read(conn->xshandle, 0, prop, &len);
 
578
        if (tmp != NULL) {
 
579
            found = !strcmp(name, tmp);
 
580
            free(tmp);
 
581
            if (found)
 
582
                break;
 
583
        }
 
584
    }
 
585
    path = xs_get_domain_path(conn->xshandle, (unsigned int) id);
 
586
 
 
587
    if (!found)
 
588
        return(NULL);
 
589
 
 
590
    ret = virGetDomain(conn, name, NULL);
 
591
    if (ret == NULL) {
 
592
        virXenStoreError(conn, VIR_ERR_NO_MEMORY, _("allocating domain"));
 
593
        if (path != NULL)
 
594
            free(path);
 
595
        goto done;
 
596
    }
 
597
    ret->handle = id;
 
598
    ret->path = path;
 
599
 
 
600
done:
 
601
    if (xenddomain != NULL)
 
602
        free(xenddomain);
 
603
    if (idlist != NULL)
 
604
        free(idlist);
 
605
 
 
606
    return(ret);
 
607
}
 
608
 
 
609
/**
 
610
 * xenStoreDomainShutdown:
 
611
 * @domain: pointer to the Domain block
 
612
 *
 
613
 * Shutdown the domain, the OS is requested to properly shutdown
 
614
 * and the domain may ignore it.  It will return immediately
 
615
 * after queuing the request.
 
616
 *
 
617
 * Returns 0 in case of success, -1 in case of error.
 
618
 */
 
619
int
 
620
xenStoreDomainShutdown(virDomainPtr domain)
 
621
{
 
622
    if ((domain == NULL) || (domain->conn == NULL)) {
 
623
        virXenStoreError((domain ? domain->conn : NULL), VIR_ERR_INVALID_ARG,
 
624
                         __FUNCTION__);
 
625
        return(-1);
 
626
    }
 
627
    /*
 
628
     * this is very hackish, the domU kernel probes for a special 
 
629
     * node in the xenstore and launch the shutdown command if found.
 
630
     */
 
631
    return(virDomainDoStoreWrite(domain, "control/shutdown", "halt"));
 
632
}
 
633
 
 
634
/**
 
635
 * xenStoreDomainReboot:
 
636
 * @domain: pointer to the Domain block
 
637
 * @flags: extra flags for the reboot operation, not used yet
 
638
 *
 
639
 * Reboot the domain, the OS is requested to properly shutdown
 
640
 * and reboot but the domain may ignore it.  It will return immediately
 
641
 * after queuing the request.
 
642
 *
 
643
 * Returns 0 in case of success, -1 in case of error.
 
644
 */
 
645
int
 
646
xenStoreDomainReboot(virDomainPtr domain, unsigned int flags ATTRIBUTE_UNUSED)
 
647
{
 
648
    if ((domain == NULL) || (domain->conn == NULL)) {
 
649
        virXenStoreError((domain ? domain->conn : NULL), VIR_ERR_INVALID_ARG,
 
650
                         __FUNCTION__);
 
651
        return(-1);
 
652
    }
 
653
    /*
 
654
     * this is very hackish, the domU kernel probes for a special 
 
655
     * node in the xenstore and launch the shutdown command if found.
 
656
     */
 
657
    return(virDomainDoStoreWrite(domain, "control/shutdown", "reboot"));
 
658
}
 
659
#endif /* ! PROXY */
 
660
 
 
661
/**
 
662
 * xenStoreDomainGetVNCPort:
 
663
 * @conn: the hypervisor connection
 
664
 * @domid: id of the domain
 
665
 *
 
666
 * Return the port number on which the domain is listening for VNC
 
667
 * connections. 
 
668
 *
 
669
 * Returns the port number, -1 in case of error
 
670
 */
 
671
int             xenStoreDomainGetVNCPort(virConnectPtr conn, int domid) {
 
672
    char *tmp;
 
673
    int ret = -1;
 
674
 
 
675
    tmp = virDomainDoStoreQuery(conn, domid, "console/vnc-port");
 
676
    if (tmp != NULL) {
 
677
        char *end;
 
678
        ret = strtol(tmp, &end, 10);
 
679
        if (ret == 0 && end == tmp)
 
680
            ret = -1;
 
681
        free(tmp);
 
682
    }
 
683
    return(ret);
 
684
}
 
685
 
 
686
/**
 
687
 * xenStoreDomainGetConsolePath:
 
688
 * @conn: the hypervisor connection
 
689
 * @domid: id of the domain
 
690
 *
 
691
 * Return the path to the psuedo TTY on which the guest domain's
 
692
 * serial console is attached.
 
693
 *
 
694
 * Returns the path to the serial console. It is the callers
 
695
 * responsibilty to free() the return string. Returns NULL
 
696
 * on error
 
697
 */
 
698
char *          xenStoreDomainGetConsolePath(virConnectPtr conn, int domid) {
 
699
  return virDomainDoStoreQuery(conn, domid, "console/tty");
 
700
}