openvz_driver.c 36.4 KB
Newer Older
1 2 3 4 5
/*
 * openvz_driver.c: core driver methods for managing OpenVZ VEs
 *
 * Copyright (C) 2006, 2007 Binary Karma
 * Copyright (C) 2006 Shuveb Hussain
6
 * Copyright (C) 2007 Anoop Joe Cyriac
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
 *
22
 * Authors:
23 24 25
 * Shuveb Hussain <shuveb@binarykarma.com>
 * Anoop Joe Cyriac <anoop@binarykarma.com>
 *
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
 */

#include <config.h>

#include <sys/types.h>
#include <sys/poll.h>
#include <dirent.h>
#include <limits.h>
#include <string.h>
#include <stdio.h>
#include <strings.h>
#include <stdarg.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <sys/utsname.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <signal.h>
#include <paths.h>
#include <pwd.h>
#include <stdio.h>
#include <sys/wait.h>

50
#include "virterror_internal.h"
51
#include "datatypes.h"
52
#include "openvz_driver.h"
53 54
#include "event.h"
#include "buf.h"
55
#include "util.h"
56
#include "openvz_conf.h"
57
#include "nodeinfo.h"
58
#include "memory.h"
59
#include "bridge.h"
60

61 62 63
#define OPENVZ_MAX_ARG 28
#define CMDBUF_LEN 1488
#define CMDOP_LEN 288
64

D
Daniel Veillard 已提交
65
static int openvzGetProcessInfo(unsigned long long *cpuTime, int vpsid);
66 67 68
static int openvzGetMaxVCPUs(virConnectPtr conn, const char *type);
static int openvzDomainGetMaxVcpus(virDomainPtr dom);
static int openvzDomainSetVcpus(virDomainPtr dom, unsigned int nvcpus);
D
Daniel Veillard 已提交
69

70 71 72 73 74 75 76 77 78 79
static void openvzDriverLock(struct openvz_driver *driver)
{
    pthread_mutex_lock(&driver->lock);
}

static void openvzDriverUnlock(struct openvz_driver *driver)
{
    pthread_mutex_unlock(&driver->lock);
}

80 81
struct openvz_driver ovz_driver;

82
static void cmdExecFree(const char *cmdExec[])
83 84 85 86
{
    int i=-1;
    while(cmdExec[++i])
    {
87
        VIR_FREE(cmdExec[i]);
88 89 90
    }
}

91 92 93 94 95
/* generate arguments to create OpenVZ container
   return -1 - error
           0 - OK
*/
static int openvzDomainDefineCmd(virConnectPtr conn,
96
                                 const char *args[],
97
                                 int maxarg,
98
                                 virDomainDefPtr vmdef)
99 100 101 102 103 104 105 106
{
    int narg;

    for (narg = 0; narg < maxarg; narg++)
        args[narg] = NULL;

    if (vmdef == NULL){
        openvzError(conn, VIR_ERR_INTERNAL_ERROR,
J
Jim Meyering 已提交
107
                   "%s", _("Container is not defined"));
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
        return -1;
    }

#define ADD_ARG(thisarg)                                                \
    do {                                                                \
        if (narg >= maxarg)                                             \
                 goto no_memory;                                        \
        args[narg++] = thisarg;                                         \
    } while (0)

#define ADD_ARG_LIT(thisarg)                                            \
    do {                                                                \
        if (narg >= maxarg)                                             \
                 goto no_memory;                                        \
        if ((args[narg++] = strdup(thisarg)) == NULL)                   \
            goto no_memory;                                             \
    } while (0)

    narg = 0;
    ADD_ARG_LIT(VZCTL);
    ADD_ARG_LIT("--quiet");
    ADD_ARG_LIT("create");
    ADD_ARG_LIT(vmdef->name);
131

132 133
    if (vmdef->nfss) {
        if (vmdef->fss[0]->type != VIR_DOMAIN_FS_TYPE_TEMPLATE) {
134 135 136 137
            openvzError(conn, VIR_ERR_INTERNAL_ERROR,
                        "%s", _("only filesystem templates are supported"));
            return -1;
        }
138

139
        if (vmdef->nfss > 1) {
140 141 142 143
            openvzError(conn, VIR_ERR_INTERNAL_ERROR,
                        "%s", _("only one filesystem supported"));
            return -1;
        }
144 145

        ADD_ARG_LIT("--ostemplate");
146
        ADD_ARG_LIT(vmdef->fss[0]->src);
147
    }
148
#if 0
149 150 151 152
    if ((vmdef->profile && *(vmdef->profile))) {
        ADD_ARG_LIT("--config");
        ADD_ARG_LIT(vmdef->profile);
    }
153
#endif
154 155 156 157 158 159 160 161 162 163 164 165

    ADD_ARG(NULL);
    return 0;
 no_memory:
    openvzError(conn, VIR_ERR_INTERNAL_ERROR,
                _("Could not put argument to %s"), VZCTL);
    return -1;
#undef ADD_ARG
#undef ADD_ARG_LIT
}


166
static virDomainPtr openvzDomainLookupByID(virConnectPtr conn,
167
                                           int id) {
168
    struct openvz_driver *driver = conn->privateData;
169
    virDomainObjPtr vm;
170
    virDomainPtr dom = NULL;
171

172
    openvzDriverLock(driver);
173
    vm = virDomainFindByID(&driver->domains, id);
174 175
    openvzDriverUnlock(driver);

176
    if (!vm) {
177
        openvzError(conn, VIR_ERR_NO_DOMAIN, NULL);
178
        goto cleanup;
179 180
    }

181
    dom = virGetDomain(conn, vm->def->name, vm->def->uuid);
182 183
    if (dom)
        dom->id = vm->def->id;
184

185
cleanup:
186 187
    if (vm)
        virDomainObjUnlock(vm);
188 189 190
    return dom;
}

191
static int openvzGetVersion(virConnectPtr conn, unsigned long *version) {
192
    struct  openvz_driver *driver = conn->privateData;
193
    openvzDriverLock(driver);
194
    *version = driver->version;
195
    openvzDriverUnlock(driver);
196 197 198
    return 0;
}

199
static char *openvzGetOSType(virDomainPtr dom)
200
{
201 202 203
    struct  openvz_driver *driver = dom->conn->privateData;
    virDomainObjPtr vm;
    char *ret = NULL;
204

205
    openvzDriverLock(driver);
206
    vm = virDomainFindByUUID(&driver->domains, dom->uuid);
207 208
    openvzDriverUnlock(driver);

209 210
    if (!vm) {
        openvzError(dom->conn, VIR_ERR_NO_DOMAIN, NULL);
211
        goto cleanup;
212 213 214 215 216
    }

    if (!(ret = strdup(vm->def->os.type)))
        openvzError(dom->conn, VIR_ERR_NO_MEMORY, NULL);

217
cleanup:
218 219
    if (vm)
        virDomainObjUnlock(vm);
220
    return ret;
221 222 223 224
}


static virDomainPtr openvzDomainLookupByUUID(virConnectPtr conn,
225
                                             const unsigned char *uuid) {
226 227 228
    struct  openvz_driver *driver = conn->privateData;
    virDomainObjPtr vm;
    virDomainPtr dom = NULL;
229

230
    openvzDriverLock(driver);
231
    vm = virDomainFindByUUID(&driver->domains, uuid);
232 233
    openvzDriverUnlock(driver);

234
    if (!vm) {
235
        openvzError(conn, VIR_ERR_NO_DOMAIN, NULL);
236
        goto cleanup;
237 238
    }

239
    dom = virGetDomain(conn, vm->def->name, vm->def->uuid);
240 241
    if (dom)
        dom->id = vm->def->id;
242

243
cleanup:
244 245
    if (vm)
        virDomainObjUnlock(vm);
246 247 248 249
    return dom;
}

static virDomainPtr openvzDomainLookupByName(virConnectPtr conn,
250 251 252 253
                                             const char *name) {
    struct openvz_driver *driver = conn->privateData;
    virDomainObjPtr vm;
    virDomainPtr dom = NULL;
254

255
    openvzDriverLock(driver);
256
    vm = virDomainFindByName(&driver->domains, name);
257 258
    openvzDriverUnlock(driver);

259
    if (!vm) {
260
        openvzError(conn, VIR_ERR_NO_DOMAIN, NULL);
261
        goto cleanup;
262 263
    }

264
    dom = virGetDomain(conn, vm->def->name, vm->def->uuid);
265 266
    if (dom)
        dom->id = vm->def->id;
267

268
cleanup:
269 270
    if (vm)
        virDomainObjUnlock(vm);
271 272 273 274
    return dom;
}

static int openvzDomainGetInfo(virDomainPtr dom,
275
                               virDomainInfoPtr info) {
276 277 278
    struct openvz_driver *driver = dom->conn->privateData;
    virDomainObjPtr vm;
    int ret = -1;
279

280
    openvzDriverLock(driver);
281
    vm = virDomainFindByUUID(&driver->domains, dom->uuid);
282 283
    openvzDriverUnlock(driver);

284
    if (!vm) {
D
Daniel Veillard 已提交
285
        openvzError(dom->conn, VIR_ERR_INVALID_DOMAIN,
J
Jim Meyering 已提交
286
                    "%s", _("no domain with matching uuid"));
287
        goto cleanup;
288 289
    }

290
    info->state = vm->state;
291

292
    if (!virDomainIsActive(vm)) {
D
Daniel Veillard 已提交
293 294 295 296
        info->cpuTime = 0;
    } else {
        if (openvzGetProcessInfo(&(info->cpuTime), dom->id) < 0) {
            openvzError(dom->conn, VIR_ERR_OPERATION_FAILED,
297
                        _("cannot read cputime for domain %d"), dom->id);
298
            goto cleanup;
D
Daniel Veillard 已提交
299 300 301
        }
    }

302 303 304
    info->maxMem = vm->def->maxmem;
    info->memory = vm->def->memory;
    info->nrVirtCpu = vm->def->vcpus;
305 306 307
    ret = 0;

cleanup:
308 309
    if (vm)
        virDomainObjUnlock(vm);
310
    return ret;
311 312 313
}


314
static char *openvzDomainDumpXML(virDomainPtr dom, int flags) {
315 316 317
    struct openvz_driver *driver = dom->conn->privateData;
    virDomainObjPtr vm;
    char *ret = NULL;
318

319
    openvzDriverLock(driver);
320
    vm = virDomainFindByUUID(&driver->domains, dom->uuid);
321 322
    openvzDriverUnlock(driver);

323
    if (!vm) {
D
Daniel Veillard 已提交
324
        openvzError(dom->conn, VIR_ERR_INVALID_DOMAIN,
J
Jim Meyering 已提交
325
                    "%s", _("no domain with matching uuid"));
326
        goto cleanup;
327
    }
328

329 330 331
    ret = virDomainDefFormat(dom->conn, vm->def, flags);

cleanup:
332 333
    if (vm)
        virDomainObjUnlock(vm);
334
    return ret;
335
}
336

337

338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355
/*
 * Convenient helper to target a command line argv
 * and fill in an empty slot with the supplied
 * key value. This lets us declare the argv on the
 * stack and just splice in the domain name after
 */
#define PROGRAM_SENTINAL ((char *)0x1)
static void openvzSetProgramSentinal(const char **prog, const char *key)
{
    const char **tmp = prog;
    while (tmp && *tmp) {
        if (*tmp == PROGRAM_SENTINAL) {
            *tmp = key;
            break;
        }
        tmp++;
    }
}
356 357

static int openvzDomainShutdown(virDomainPtr dom) {
358 359 360 361
    struct openvz_driver *driver = dom->conn->privateData;
    virDomainObjPtr vm;
    const char *prog[] = {VZCTL, "--quiet", "stop", PROGRAM_SENTINAL, NULL};
    int ret = -1;
362

363
    openvzDriverLock(driver);
364
    vm = virDomainFindByUUID(&driver->domains, dom->uuid);
365 366
    openvzDriverUnlock(driver);

367 368
    if (!vm) {
        openvzError(dom->conn, VIR_ERR_INVALID_DOMAIN,
J
Jim Meyering 已提交
369
                    "%s", _("no domain with matching uuid"));
370
        goto cleanup;
371
    }
372

373
    openvzSetProgramSentinal(prog, vm->def->name);
374
    if (vm->state != VIR_DOMAIN_RUNNING) {
D
Daniel Veillard 已提交
375
        openvzError(dom->conn, VIR_ERR_INTERNAL_ERROR,
J
Jim Meyering 已提交
376
                    "%s", _("domain is not in running state"));
377
        goto cleanup;
378
    }
379

380
    if (virRun(dom->conn, prog, NULL) < 0)
381
        goto cleanup;
382

383 384
    vm->def->id = -1;
    vm->state = VIR_DOMAIN_SHUTOFF;
385
    ret = 0;
386

387
cleanup:
388 389
    if (vm)
        virDomainObjUnlock(vm);
390
    return ret;
391 392
}

393 394
static int openvzDomainReboot(virDomainPtr dom,
                              unsigned int flags ATTRIBUTE_UNUSED) {
395 396 397 398
    struct openvz_driver *driver = dom->conn->privateData;
    virDomainObjPtr vm;
    const char *prog[] = {VZCTL, "--quiet", "restart", PROGRAM_SENTINAL, NULL};
    int ret = -1;
399

400
    openvzDriverLock(driver);
401
    vm = virDomainFindByUUID(&driver->domains, dom->uuid);
402 403
    openvzDriverUnlock(driver);

404
    if (!vm) {
D
Daniel Veillard 已提交
405
        openvzError(dom->conn, VIR_ERR_INVALID_DOMAIN,
J
Jim Meyering 已提交
406
                    "%s", _("no domain with matching uuid"));
407
        goto cleanup;
408
    }
409

410
    openvzSetProgramSentinal(prog, vm->def->name);
411 412
    if (vm->state != VIR_DOMAIN_RUNNING) {
        openvzError(dom->conn, VIR_ERR_INTERNAL_ERROR,
J
Jim Meyering 已提交
413
                    "%s", _("domain is not in running state"));
414
        goto cleanup;
415
    }
416

417
    if (virRun(dom->conn, prog, NULL) < 0)
418 419
        goto cleanup;
    ret = 0;
420

421
cleanup:
422 423
    if (vm)
        virDomainObjUnlock(vm);
424
    return ret;
425 426
}

427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466
static char *
openvzGenerateVethName(int veid, char *dev_name_ve)
{
    char    dev_name[32];
    int     ifNo = 0;

    if (sscanf(dev_name_ve, "%*[^0-9]%d", &ifNo) != 1)
        return NULL;
    if (snprintf(dev_name, sizeof(dev_name), "veth%d.%d", veid, ifNo) < 7)
        return NULL;
    return strdup(dev_name);
}

static char *
openvzGenerateContainerVethName(int veid)
{
    int     ret;
    char    temp[1024];

    /* try to get line "^NETIF=..." from config */
    if ( (ret = openvzReadConfigParam(veid, "NETIF", temp, sizeof(temp))) <= 0) {
        snprintf(temp, sizeof(temp), "eth0");
    } else {
        char   *s;
        int     max = 0;

        /* get maximum interface number (actually, it is the last one) */
        for (s=strtok(temp, ";"); s; s=strtok(NULL, ";")) {
            int x;

            if (sscanf(s, "ifname=eth%d", &x) != 1) return NULL;
            if (x > max) max = x;
        }

        /* set new name */
        snprintf(temp, sizeof(temp), "eth%d", max+1);
    }
    return strdup(temp);
}

D
Daniel Veillard 已提交
467 468
static int
openvzDomainSetNetwork(virConnectPtr conn, const char *vpsid,
469 470
                       virDomainNetDefPtr net,
                       virBufferPtr configBuf)
D
Daniel Veillard 已提交
471 472
{
    int rc = 0, narg;
473
    const char *prog[OPENVZ_MAX_ARG];
474
    char macaddr[VIR_MAC_STRING_BUFLEN];
475
    struct openvz_driver *driver =  conn->privateData;
476
    char *opt = NULL;
D
Daniel Veillard 已提交
477 478 479 480 481 482 483 484 485 486 487 488 489 490

#define ADD_ARG_LIT(thisarg)                                            \
    do {                                                                \
        if (narg >= OPENVZ_MAX_ARG)                                             \
                 goto no_memory;                                        \
        if ((prog[narg++] = strdup(thisarg)) == NULL)                   \
            goto no_memory;                                             \
    } while (0)


    if (net == NULL)
       return 0;
    if (vpsid == NULL) {
        openvzError(conn, VIR_ERR_INTERNAL_ERROR,
J
Jim Meyering 已提交
491
                    "%s", _("Container ID is not specified"));
D
Daniel Veillard 已提交
492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507
        return -1;
    }

    for (narg = 0; narg < OPENVZ_MAX_ARG; narg++)
        prog[narg] = NULL;

    narg = 0;

    if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE ||
        net->type == VIR_DOMAIN_NET_TYPE_ETHERNET) {
        ADD_ARG_LIT(VZCTL);
        ADD_ARG_LIT("--quiet");
        ADD_ARG_LIT("set");
        ADD_ARG_LIT(vpsid);
    }

508 509 510 511 512 513
    virFormatMacAddr(net->mac, macaddr);

    if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE) {
        virBuffer buf = VIR_BUFFER_INITIALIZER;
        char *dev_name_ve;
        int veid = strtoI(vpsid);
D
Daniel Veillard 已提交
514 515 516

        //--netif_add ifname[,mac,host_ifname,host_mac]
        ADD_ARG_LIT("--netif_add") ;
517 518 519 520 521

        /* generate interface name in ve and copy it to options */
        dev_name_ve = openvzGenerateContainerVethName(veid);
        if (dev_name_ve == NULL) {
           openvzError(conn, VIR_ERR_INTERNAL_ERROR,
J
Jim Meyering 已提交
522
                       "%s", _("Could not generate eth name for container"));
523 524 525 526 527 528 529 530 531 532
           rc = -1;
           goto exit;
        }

        /* if user doesn't specified host interface name,
         * than we need to generate it */
        if (net->ifname == NULL) {
            net->ifname = openvzGenerateVethName(veid, dev_name_ve);
            if (net->ifname == NULL) {
               openvzError(conn, VIR_ERR_INTERNAL_ERROR,
J
Jim Meyering 已提交
533
                           "%s", _("Could not generate veth name"));
534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552
               rc = -1;
               VIR_FREE(dev_name_ve);
               goto exit;
            }
        }

        virBufferAdd(&buf, dev_name_ve, -1); /* Guest dev */
        virBufferVSprintf(&buf, ",%s", macaddr); /* Guest dev mac */
        virBufferVSprintf(&buf, ",%s", net->ifname); /* Host dev */
        virBufferVSprintf(&buf, ",%s", macaddr); /* Host dev mac */

        if (driver->version >= VZCTL_BRIDGE_MIN_VERSION) {
            virBufferVSprintf(&buf, ",%s", net->data.bridge.brname); /* Host bridge */
        } else {
            virBufferVSprintf(configBuf, "ifname=%s", dev_name_ve);
            virBufferVSprintf(configBuf, ",mac=%s", macaddr); /* Guest dev mac */
            virBufferVSprintf(configBuf, ",host_ifname=%s", net->ifname); /* Host dev */
            virBufferVSprintf(configBuf, ",host_mac=%s", macaddr); /* Host dev mac */
            virBufferVSprintf(configBuf, ",bridge=%s", net->data.bridge.brname); /* Host bridge */
D
Daniel Veillard 已提交
553
        }
554 555 556 557 558 559

        VIR_FREE(dev_name_ve);

        if (!(opt = virBufferContentAndReset(&buf)))
            goto no_memory;

D
Daniel Veillard 已提交
560
        ADD_ARG_LIT(opt) ;
561 562
        VIR_FREE(opt);
    } else if (net->type == VIR_DOMAIN_NET_TYPE_ETHERNET &&
D
Daniel Veillard 已提交
563 564 565 566 567 568 569 570 571 572
              net->data.ethernet.ipaddr != NULL) {
        //--ipadd ip
        ADD_ARG_LIT("--ipadd") ;
        ADD_ARG_LIT(net->data.ethernet.ipaddr) ;
    }

    //TODO: processing NAT and physical device

    if (prog[0] != NULL){
        ADD_ARG_LIT("--save");
573
        if (virRun(conn, prog, NULL) < 0) {
D
Daniel Veillard 已提交
574 575 576 577 578 579 580 581 582 583 584 585
           openvzError(conn, VIR_ERR_INTERNAL_ERROR,
                    _("Could not exec %s"), VZCTL);
           rc = -1;
           goto exit;
        }
    }

 exit:
    cmdExecFree(prog);
    return rc;

 no_memory:
586
    VIR_FREE(opt);
D
Daniel Veillard 已提交
587 588 589 590 591 592 593 594
    openvzError(conn, VIR_ERR_INTERNAL_ERROR,
                _("Could not put argument to %s"), VZCTL);
    cmdExecFree(prog);
    return -1;

#undef ADD_ARG_LIT
}

595 596 597 598 599 600 601 602 603

static int
openvzDomainSetNetworkConfig(virConnectPtr conn,
                             virDomainDefPtr def)
{
    unsigned int i;
    virBuffer buf = VIR_BUFFER_INITIALIZER;
    char *param;
    int first = 1;
604
    struct openvz_driver *driver =  conn->privateData;
605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643

    for (i = 0 ; i < def->nnets ; i++) {
        if (driver->version < VZCTL_BRIDGE_MIN_VERSION &&
            def->nets[i]->type == VIR_DOMAIN_NET_TYPE_BRIDGE) {
            if (first)
                first = 0;
            else
                virBufferAddLit(&buf, ";");
        }

        if (openvzDomainSetNetwork(conn, def->name, def->nets[i], &buf) < 0) {
            openvzError(conn, VIR_ERR_INTERNAL_ERROR,
                        "%s", _("Could not configure network"));
            goto exit;
        }
    }

    if (driver->version < VZCTL_BRIDGE_MIN_VERSION && def->nnets) {
        param = virBufferContentAndReset(&buf);
        if (param) {
            if (openvzWriteConfigParam(strtoI(def->name), "NETIF", param) < 0) {
                VIR_FREE(param);
                openvzError(conn, VIR_ERR_INTERNAL_ERROR,
                            "%s", _("cannot replace NETIF config"));
                return -1;
            }
            VIR_FREE(param);
        }
    }

    return 0;

exit:
    param = virBufferContentAndReset(&buf);
    VIR_FREE(param);
    return -1;
}


644 645 646
static virDomainPtr
openvzDomainDefineXML(virConnectPtr conn, const char *xml)
{
647
    struct openvz_driver *driver =  conn->privateData;
648 649
    virDomainDefPtr vmdef = NULL;
    virDomainObjPtr vm = NULL;
650
    virDomainPtr dom = NULL;
651
    const char *prog[OPENVZ_MAX_ARG];
652
    prog[0] = NULL;
653

654
    openvzDriverLock(driver);
655
    if ((vmdef = virDomainDefParseString(conn, driver->caps, xml)) == NULL)
656
        goto cleanup;
657

658 659
    if (vmdef->os.init == NULL &&
        !(vmdef->os.init = strdup("/sbin/init"))) {
660
        goto cleanup;
661 662
    }

663
    vm = virDomainFindByName(&driver->domains, vmdef->name);
664
    if (vm) {
665 666
        openvzError(conn, VIR_ERR_OPERATION_FAILED,
                  _("Already an OPENVZ VM active with the id '%s'"),
667
                  vmdef->name);
668
        goto cleanup;
669
    }
670 671 672
    if (!(vm = virDomainAssignDef(conn, &driver->domains, vmdef)))
        goto cleanup;
    vmdef = NULL;
673

674
    if (openvzDomainDefineCmd(conn, prog, OPENVZ_MAX_ARG, vm->def) < 0) {
675
        openvzError(conn, VIR_ERR_INTERNAL_ERROR,
J
Jim Meyering 已提交
676
                "%s", _("Error creating command for container"));
677
        goto cleanup;
678 679
    }

D
Daniel Veillard 已提交
680 681
    //TODO: set quota

682
    if (virRun(conn, prog, NULL) < 0) {
D
Daniel Veillard 已提交
683
        openvzError(conn, VIR_ERR_INTERNAL_ERROR,
684
               _("Could not exec %s"), VZCTL);
685
        goto cleanup;
686
    }
687

688
    if (openvzSetDefinedUUID(strtoI(vm->def->name), vm->def->uuid) < 0) {
689
        openvzError(conn, VIR_ERR_INTERNAL_ERROR,
J
Jim Meyering 已提交
690
               "%s", _("Could not set UUID"));
691
        goto cleanup;
692 693
    }

694 695
    if (openvzDomainSetNetworkConfig(conn, vm->def) < 0)
        goto cleanup;
D
Daniel Veillard 已提交
696

697 698
    if (vm->def->vcpus > 0) {
        if (openvzDomainSetVcpus(dom, vm->def->vcpus) < 0) {
699
            openvzError(conn, VIR_ERR_INTERNAL_ERROR,
J
Jim Meyering 已提交
700
                     "%s", _("Could not set number of virtual cpu"));
701
             goto cleanup;
702 703 704
        }
    }

705 706 707 708 709 710
    dom = virGetDomain(conn, vm->def->name, vm->def->uuid);
    if (dom)
        dom->id = -1;

cleanup:
    virDomainDefFree(vmdef);
711
    cmdExecFree(prog);
712 713 714
    if (vm)
        virDomainObjUnlock(vm);
    openvzDriverUnlock(driver);
715 716 717 718
    return dom;
}

static virDomainPtr
719
openvzDomainCreateXML(virConnectPtr conn, const char *xml,
720
                      unsigned int flags ATTRIBUTE_UNUSED)
721
{
722
    struct openvz_driver *driver =  conn->privateData;
723 724
    virDomainDefPtr vmdef = NULL;
    virDomainObjPtr vm = NULL;
725
    virDomainPtr dom = NULL;
726
    const char *progstart[] = {VZCTL, "--quiet", "start", PROGRAM_SENTINAL, NULL};
727
    const char *progcreate[OPENVZ_MAX_ARG];
728
    progcreate[0] = NULL;
729

730
    openvzDriverLock(driver);
731
    if ((vmdef = virDomainDefParseString(conn, driver->caps, xml)) == NULL)
732
        goto cleanup;
733 734

    if (vmdef->os.init == NULL &&
735 736
        !(vmdef->os.init = strdup("/sbin/init")))
        goto cleanup;
737

738
    vm = virDomainFindByName(&driver->domains, vmdef->name);
739
    if (vm) {
740 741 742
        openvzError(conn, VIR_ERR_OPERATION_FAILED,
                  _("Already an OPENVZ VM defined with the id '%s'"),
                  vmdef->name);
743
        goto cleanup;
744
    }
745 746 747
    if (!(vm = virDomainAssignDef(conn, &driver->domains, vmdef)))
        goto cleanup;
    vmdef = NULL;
748

749
    if (openvzDomainDefineCmd(conn, progcreate, OPENVZ_MAX_ARG, vm->def) < 0) {
750
        openvzError(conn, VIR_ERR_INTERNAL_ERROR,
751 752
                    "%s", _("Error creating command for container"));
        goto cleanup;
753 754
    }

755
    if (virRun(conn, progcreate, NULL) < 0) {
D
Daniel Veillard 已提交
756
        openvzError(conn, VIR_ERR_INTERNAL_ERROR,
757
               _("Could not exec %s"), VZCTL);
758
        goto cleanup;
759
    }
760

761
    if (openvzSetDefinedUUID(strtoI(vm->def->name), vm->def->uuid) < 0) {
762
        openvzError(conn, VIR_ERR_INTERNAL_ERROR,
J
Jim Meyering 已提交
763
               "%s", _("Could not set UUID"));
764
        goto cleanup;
765 766
    }

767 768
    if (openvzDomainSetNetworkConfig(conn, vm->def) < 0)
        goto cleanup;
D
Daniel Veillard 已提交
769

770
    openvzSetProgramSentinal(progstart, vm->def->name);
771

772
    if (virRun(conn, progstart, NULL) < 0) {
D
Daniel Veillard 已提交
773
        openvzError(conn, VIR_ERR_INTERNAL_ERROR,
774
               _("Could not exec %s"), VZCTL);
775
        goto cleanup;
776
    }
777

778
    vm->pid = strtoI(vm->def->name);
779 780
    vm->def->id = vm->pid;
    vm->state = VIR_DOMAIN_RUNNING;
781

782 783
    if (vm->def->vcpus > 0) {
        if (openvzDomainSetVcpus(dom, vm->def->vcpus) < 0) {
784
            openvzError(conn, VIR_ERR_INTERNAL_ERROR,
J
Jim Meyering 已提交
785
                        "%s", _("Could not set number of virtual cpu"));
786
            goto cleanup;
787 788 789
        }
    }

790 791 792 793 794 795
    dom = virGetDomain(conn, vm->def->name, vm->def->uuid);
    if (dom)
        dom->id = vm->def->id;

cleanup:
    virDomainDefFree(vmdef);
796
    cmdExecFree(progcreate);
797 798 799
    if (vm)
        virDomainObjUnlock(vm);
    openvzDriverUnlock(driver);
800 801 802 803 804 805
    return dom;
}

static int
openvzDomainCreate(virDomainPtr dom)
{
806 807 808 809
    struct openvz_driver *driver = dom->conn->privateData;
    virDomainObjPtr vm;
    const char *prog[] = {VZCTL, "--quiet", "start", PROGRAM_SENTINAL, NULL };
    int ret = -1;
810

811
    openvzDriverLock(driver);
812
    vm = virDomainFindByName(&driver->domains, dom->name);
813 814
    openvzDriverUnlock(driver);

815
    if (!vm) {
D
Daniel Veillard 已提交
816
        openvzError(dom->conn, VIR_ERR_INVALID_DOMAIN,
817 818
                    "%s", _("no domain with matching id"));
        goto cleanup;
819
    }
820

821
    if (vm->state != VIR_DOMAIN_SHUTOFF) {
D
Daniel Veillard 已提交
822
        openvzError(dom->conn, VIR_ERR_OPERATION_DENIED,
823 824
                    "%s", _("domain is not in shutoff state"));
        goto cleanup;
825 826
    }

827
    openvzSetProgramSentinal(prog, vm->def->name);
828
    if (virRun(dom->conn, prog, NULL) < 0) {
D
Daniel Veillard 已提交
829
        openvzError(dom->conn, VIR_ERR_INTERNAL_ERROR,
830 831
                    _("Could not exec %s"), VZCTL);
        goto cleanup;
832
    }
833

834 835 836
    vm->pid = strtoI(vm->def->name);
    vm->def->id = vm->pid;
    vm->state = VIR_DOMAIN_RUNNING;
837
    ret = 0;
838

839
cleanup:
840 841
    if (vm)
        virDomainObjUnlock(vm);
842
    return ret;
843 844 845 846 847
}

static int
openvzDomainUndefine(virDomainPtr dom)
{
848 849 850 851
    struct openvz_driver *driver = dom->conn->privateData;
    virDomainObjPtr vm;
    const char *prog[] = { VZCTL, "--quiet", "destroy", PROGRAM_SENTINAL, NULL };
    int ret = -1;
852

853
    openvzDriverLock(driver);
854
    vm = virDomainFindByUUID(&driver->domains, dom->uuid);
855
    if (!vm) {
856 857
        openvzError(dom->conn, VIR_ERR_INVALID_DOMAIN, "%s", _("no domain with matching uuid"));
        goto cleanup;
858
    }
859

860
    if (virDomainIsActive(vm)) {
861 862
        openvzError(dom->conn, VIR_ERR_INTERNAL_ERROR, "%s", _("cannot delete active domain"));
        goto cleanup;
863
    }
864

865 866 867 868 869
    openvzSetProgramSentinal(prog, vm->def->name);
    if (virRun(dom->conn, prog, NULL) < 0) {
        openvzError(dom->conn, VIR_ERR_INTERNAL_ERROR,
                    _("Could not exec %s"), VZCTL);
        goto cleanup;
870
    }
871

872
    virDomainRemoveInactive(&driver->domains, vm);
873
    vm = NULL;
874
    ret = 0;
875

876
cleanup:
877 878 879
    if (vm)
        virDomainObjUnlock(vm);
    openvzDriverUnlock(driver);
880
    return ret;
881 882
}

883 884 885
static int
openvzDomainSetAutostart(virDomainPtr dom, int autostart)
{
886 887 888
    struct openvz_driver *driver = dom->conn->privateData;
    virDomainObjPtr vm;
    const char *prog[] = { VZCTL, "--quiet", "set", PROGRAM_SENTINAL,
D
Daniel Veillard 已提交
889
                           "--onboot", autostart ? "yes" : "no",
890
                           "--save", NULL };
891
    int ret = -1;
892

893
    openvzDriverLock(driver);
894
    vm = virDomainFindByUUID(&driver->domains, dom->uuid);
895 896
    openvzDriverUnlock(driver);

897
    if (!vm) {
898 899
        openvzError(dom->conn, VIR_ERR_INVALID_DOMAIN, "%s", _("no domain with matching uuid"));
        goto cleanup;
900 901
    }

902 903 904 905
    openvzSetProgramSentinal(prog, vm->def->name);
    if (virRun(dom->conn, prog, NULL) < 0) {
        openvzError(dom->conn, VIR_ERR_INTERNAL_ERROR, _("Could not exec %s"), VZCTL);
        goto cleanup;
906
    }
907
    ret = 0;
908

909
cleanup:
910 911
    if (vm)
        virDomainObjUnlock(vm);
912
    return ret;
913 914 915 916 917
}

static int
openvzDomainGetAutostart(virDomainPtr dom, int *autostart)
{
918 919
    struct openvz_driver *driver = dom->conn->privateData;
    virDomainObjPtr vm;
920
    char value[1024];
921
    int ret = -1;
922

923
    openvzDriverLock(driver);
924
    vm = virDomainFindByUUID(&driver->domains, dom->uuid);
925 926
    openvzDriverUnlock(driver);

927
    if (!vm) {
928 929 930
        openvzError(dom->conn, VIR_ERR_INVALID_DOMAIN,
                    "%s", _("no domain with matching uuid"));
        goto cleanup;
931 932
    }

933
    if (openvzReadConfigParam(strtoI(vm->def->name), "ONBOOT", value, sizeof(value)) < 0) {
934 935 936
        openvzError(dom->conn, VIR_ERR_INTERNAL_ERROR,
                    "%s", _("Could not read container config"));
        goto cleanup;
937 938 939 940
    }

    *autostart = 0;
    if (STREQ(value,"yes"))
D
Daniel Veillard 已提交
941
        *autostart = 1;
942
    ret = 0;
943

944
cleanup:
945 946
    if (vm)
        virDomainObjUnlock(vm);
947
    return ret;
948 949
}

950 951 952 953 954 955 956 957 958 959 960 961 962 963 964
static int openvzGetMaxVCPUs(virConnectPtr conn, const char *type) {
    if (STRCASEEQ(type, "openvz"))
        return 1028; //OpenVZ has no limitation

    openvzError(conn, VIR_ERR_INVALID_ARG,
                     _("unknown type '%s'"), type);
    return -1;
}


static int openvzDomainGetMaxVcpus(virDomainPtr dom) {
    return openvzGetMaxVCPUs(dom->conn, "openvz");
}

static int openvzDomainSetVcpus(virDomainPtr dom, unsigned int nvcpus) {
965 966
    struct openvz_driver *driver = dom->conn->privateData;
    virDomainObjPtr vm;
967
    char   str_vcpus[32];
968
    const char *prog[] = { VZCTL, "--quiet", "set", PROGRAM_SENTINAL,
969
                           "--cpus", str_vcpus, "--save", NULL };
970
    unsigned int pcpus;
971
    int ret = -1;
972

973
    openvzDriverLock(driver);
974
    vm = virDomainFindByUUID(&driver->domains, dom->uuid);
975 976
    openvzDriverUnlock(driver);

977
    if (!vm) {
978
        openvzError(dom->conn, VIR_ERR_INVALID_DOMAIN,
J
Jim Meyering 已提交
979
                    "%s", _("no domain with matching uuid"));
980
        goto cleanup;
981 982
    }

983
    if (nvcpus <= 0) {
984
        openvzError(dom->conn, VIR_ERR_INTERNAL_ERROR,
J
Jim Meyering 已提交
985
                    "%s", _("VCPUs should be >= 1"));
986
        goto cleanup;
987 988
    }

989 990 991 992
    pcpus = openvzGetNodeCPUs();
    if (pcpus > 0 && pcpus < nvcpus)
        nvcpus = pcpus;

993 994 995
    snprintf(str_vcpus, 31, "%d", nvcpus);
    str_vcpus[31] = '\0';

996 997 998
    openvzSetProgramSentinal(prog, vm->def->name);
    if (virRun(dom->conn, prog, NULL) < 0) {
        openvzError(dom->conn, VIR_ERR_INTERNAL_ERROR,
999
                    _("Could not exec %s"), VZCTL);
1000
        goto cleanup;
1001 1002
    }

1003
    vm->def->vcpus = nvcpus;
1004 1005 1006
    ret = 0;

cleanup:
1007 1008
    if (vm)
        virDomainObjUnlock(vm);
1009
    return ret;
1010 1011
}

1012
static int openvzProbe(void)
1013
{
1014 1015 1016 1017 1018
    if (geteuid() == 0 &&
        virFileExists("/proc/vz"))
        return 1;

    return 0;
1019 1020
}

1021
static virDrvOpenStatus openvzOpen(virConnectPtr conn,
1022 1023
                                   virConnectAuthPtr auth ATTRIBUTE_UNUSED,
                                   int flags ATTRIBUTE_UNUSED)
1024
{
1025
    struct openvz_driver *driver;
1026
    if (!openvzProbe())
1027
        return VIR_DRV_OPEN_DECLINED;
1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038

    if (conn->uri == NULL) {
        conn->uri = xmlParseURI("openvz:///system");
        if (conn->uri == NULL) {
            openvzError(conn, VIR_ERR_NO_DOMAIN, NULL);
            return VIR_DRV_OPEN_ERROR;
        }
    } else if (conn->uri->scheme == NULL ||
               conn->uri->path == NULL ||
               STRNEQ (conn->uri->scheme, "openvz") ||
               STRNEQ (conn->uri->path, "/system")) {
1039 1040 1041 1042 1043 1044 1045 1046 1047 1048
        return VIR_DRV_OPEN_DECLINED;
    }

    if (VIR_ALLOC(driver) < 0) {
        openvzError(conn, VIR_ERR_NO_MEMORY, NULL);
        return VIR_DRV_OPEN_ERROR;
    }

    if (!(driver->caps = openvzCapsInit()))
        goto cleanup;
1049

1050 1051
    if (openvzLoadDomains(driver) < 0)
        goto cleanup;
1052

1053 1054 1055
    if (openvzExtractVersion(conn, driver) < 0)
        goto cleanup;

1056
    conn->privateData = driver;
1057

1058
    return VIR_DRV_OPEN_SUCCESS;
1059

1060 1061 1062
cleanup:
    openvzFreeDriver(driver);
    return VIR_DRV_OPEN_ERROR;
1063
};
1064 1065

static int openvzClose(virConnectPtr conn) {
1066
    struct openvz_driver *driver = conn->privateData;
1067

1068
    openvzFreeDriver(driver);
1069 1070 1071 1072 1073 1074 1075 1076 1077
    conn->privateData = NULL;

    return 0;
}

static const char *openvzGetType(virConnectPtr conn ATTRIBUTE_UNUSED) {
    return strdup("OpenVZ");
}

1078 1079 1080 1081 1082
static int openvzGetNodeInfo(virConnectPtr conn,
                             virNodeInfoPtr nodeinfo) {
    return virNodeInfoPopulate(conn, nodeinfo);
}

1083
static char *openvzGetCapabilities(virConnectPtr conn) {
1084 1085 1086
    struct openvz_driver *driver = conn->privateData;
    char *ret;

1087
    openvzDriverLock(driver);
1088
    ret = virCapabilitiesFormatXML(driver->caps);
1089
    openvzDriverUnlock(driver);
1090

1091
    return ret;
1092 1093
}

1094 1095
static int openvzListDomains(virConnectPtr conn, int *ids, int nids) {
    int got = 0;
1096 1097 1098
    int veid, pid;
    int outfd = -1;
    int errfd = -1;
1099 1100
    int ret;
    char buf[32];
1101
    char *endptr;
1102
    const char *cmd[] = {VZLIST, "-ovpsid", "-H" , NULL};
1103

1104 1105
    ret = virExec(conn, cmd, NULL, NULL,
                  &pid, -1, &outfd, &errfd, VIR_EXEC_NONE);
1106
    if(ret == -1) {
D
Daniel Veillard 已提交
1107
        openvzError(conn, VIR_ERR_INTERNAL_ERROR,
1108
               _("Could not exec %s"), VZLIST);
D
Daniel P. Berrange 已提交
1109
        return -1;
1110 1111
    }

1112 1113 1114
    while(got < nids){
        ret = openvz_readline(outfd, buf, 32);
        if(!ret) break;
1115 1116 1117 1118 1119
        if (virStrToLong_i(buf, &endptr, 10, &veid) < 0) {
            openvzError(conn, VIR_ERR_INTERNAL_ERROR,
                    _("Could not parse VPS ID %s"), buf);
            continue;
        }
1120 1121 1122
        ids[got] = veid;
        got ++;
    }
1123
    waitpid(pid, NULL, 0);
1124 1125 1126 1127

    return got;
}

1128
static int openvzNumDomains(virConnectPtr conn) {
1129
    struct openvz_driver *driver = conn->privateData;
1130 1131
    int nactive = 0, i;

1132 1133 1134
    openvzDriverLock(driver);
    for (i = 0 ; i < driver->domains.count ; i++) {
        virDomainObjLock(driver->domains.objs[i]);
1135
        if (virDomainIsActive(driver->domains.objs[i]))
1136
            nactive++;
1137 1138 1139
        virDomainObjUnlock(driver->domains.objs[i]);
    }
    openvzDriverUnlock(driver);
1140

1141
    return nactive;
1142 1143 1144
}

static int openvzListDefinedDomains(virConnectPtr conn,
1145
                                    char **const names, int nnames) {
1146
    int got = 0;
1147
    int veid, pid, outfd = -1, errfd = -1, ret;
1148
    char vpsname[32];
1149
    char buf[32];
1150
    char *endptr;
1151
    const char *cmd[] = {VZLIST, "-ovpsid", "-H", "-S", NULL};
1152 1153

    /* the -S options lists only stopped domains */
1154 1155
    ret = virExec(conn, cmd, NULL, NULL,
                  &pid, -1, &outfd, &errfd, VIR_EXEC_NONE);
1156
    if(ret == -1) {
D
Daniel Veillard 已提交
1157
        openvzError(conn, VIR_ERR_INTERNAL_ERROR,
1158
               _("Could not exec %s"), VZLIST);
D
Daniel P. Berrange 已提交
1159
        return -1;
1160 1161
    }

1162 1163 1164
    while(got < nnames){
        ret = openvz_readline(outfd, buf, 32);
        if(!ret) break;
1165 1166 1167 1168 1169
        if (virStrToLong_i(buf, &endptr, 10, &veid) < 0) {
            openvzError(conn, VIR_ERR_INTERNAL_ERROR,
                    _("Could not parse VPS ID %s"), buf);
            continue;
        }
1170 1171 1172
        snprintf(vpsname, sizeof(vpsname), "%d", veid);
        if (!(names[got] = strdup(vpsname)))
            goto no_memory;
1173 1174
        got ++;
    }
1175
    waitpid(pid, NULL, 0);
1176
    return got;
1177 1178 1179 1180 1181 1182

no_memory:
    openvzError(conn, VIR_ERR_NO_MEMORY, NULL);
    for ( ; got >= 0 ; got--)
        VIR_FREE(names[got]);
    return -1;
1183 1184
}

D
Daniel Veillard 已提交
1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229
static int openvzGetProcessInfo(unsigned long long *cpuTime, int vpsid) {
    int fd;
    char line[1024] ;
    unsigned long long usertime, systime, nicetime;
    int readvps = 0, ret;

/* read statistic from /proc/vz/vestat.
sample:
Version: 2.2
      VEID     user      nice     system     uptime                 idle   other..
        33       78         0       1330   59454597      142650441835148   other..
        55      178         0       5340   59424597      542650441835148   other..
*/

    if ((fd = open("/proc/vz/vestat", O_RDONLY)) == -1)
        return -1;

    /*search line with VEID=vpsid*/
    while(1) {
        ret = openvz_readline(fd, line, sizeof(line));
        if(ret <= 0)
            break;

        if (sscanf(line, "%d %llu %llu %llu",
                          &readvps, &usertime, &nicetime, &systime) != 4)
            continue;

        if (readvps == vpsid)
            break; /*found vpsid*/
    }

    close(fd);
    if (ret < 0)
        return -1;

    if (readvps != vpsid) /*not found*/
        return -1;

    /* convert jiffies to nanoseconds */
    *cpuTime = 1000ull * 1000ull * 1000ull * (usertime + nicetime  + systime)
                                     / (unsigned long long)sysconf(_SC_CLK_TCK);

    return 0;
}

1230
static int openvzNumDefinedDomains(virConnectPtr conn) {
1231
    struct openvz_driver *driver =  conn->privateData;
1232 1233
    int ninactive = 0, i;

1234 1235 1236
    openvzDriverLock(driver);
    for (i = 0 ; i < driver->domains.count ; i++) {
        virDomainObjLock(driver->domains.objs[i]);
1237
        if (!virDomainIsActive(driver->domains.objs[i]))
1238
            ninactive++;
1239 1240 1241
        virDomainObjUnlock(driver->domains.objs[i]);
    }
    openvzDriverUnlock(driver);
1242

1243
    return ninactive;
1244 1245 1246 1247 1248 1249 1250
}

static virDriver openvzDriver = {
    VIR_DRV_OPENVZ,
    "OPENVZ",
    openvzOpen, /* open */
    openvzClose, /* close */
1251
    NULL, /* supports_feature */
1252
    openvzGetType, /* type */
1253
    openvzGetVersion, /* version */
1254 1255
    NULL, /* hostname */
    NULL, /* uri */
1256
    openvzGetMaxVCPUs, /* getMaxVcpus */
1257
    openvzGetNodeInfo, /* nodeGetInfo */
1258
    openvzGetCapabilities, /* getCapabilities */
1259 1260
    openvzListDomains, /* listDomains */
    openvzNumDomains, /* numOfDomains */
1261
    openvzDomainCreateXML, /* domainCreateXML */
1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277
    openvzDomainLookupByID, /* domainLookupByID */
    openvzDomainLookupByUUID, /* domainLookupByUUID */
    openvzDomainLookupByName, /* domainLookupByName */
    NULL, /* domainSuspend */
    NULL, /* domainResume */
    openvzDomainShutdown, /* domainShutdown */
    openvzDomainReboot, /* domainReboot */
    openvzDomainShutdown, /* domainDestroy */
    openvzGetOSType, /* domainGetOSType */
    NULL, /* domainGetMaxMemory */
    NULL, /* domainSetMaxMemory */
    NULL, /* domainSetMemory */
    openvzDomainGetInfo, /* domainGetInfo */
    NULL, /* domainSave */
    NULL, /* domainRestore */
    NULL, /* domainCoreDump */
1278
    openvzDomainSetVcpus, /* domainSetVcpus */
1279 1280
    NULL, /* domainPinVcpu */
    NULL, /* domainGetVcpus */
1281
    openvzDomainGetMaxVcpus, /* domainGetMaxVcpus */
1282
    openvzDomainDumpXML, /* domainDumpXML */
1283 1284 1285
    openvzListDefinedDomains, /* listDomains */
    openvzNumDefinedDomains, /* numOfDomains */
    openvzDomainCreate, /* domainCreate */
1286 1287
    openvzDomainDefineXML, /* domainDefineXML */
    openvzDomainUndefine, /* domainUndefine */
1288 1289
    NULL, /* domainAttachDevice */
    NULL, /* domainDetachDevice */
1290 1291
    openvzDomainGetAutostart, /* domainGetAutostart */
    openvzDomainSetAutostart, /* domainSetAutostart */
1292 1293 1294
    NULL, /* domainGetSchedulerType */
    NULL, /* domainGetSchedulerParameters */
    NULL, /* domainSetSchedulerParameters */
1295 1296 1297 1298 1299
    NULL, /* domainMigratePrepare */
    NULL, /* domainMigratePerform */
    NULL, /* domainMigrateFinish */
    NULL, /* domainBlockStats */
    NULL, /* domainInterfaceStats */
D
Daniel P. Berrange 已提交
1300 1301
    NULL, /* domainBlockPeek */
    NULL, /* domainMemoryPeek */
1302
    NULL, /* nodeGetCellsFreeMemory */
1303
    NULL, /* nodeGetFreeMemory */
1304 1305
    NULL, /* domainEventRegister */
    NULL, /* domainEventDeregister */
D
Daniel Veillard 已提交
1306 1307
    NULL, /* domainMigratePrepare2 */
    NULL, /* domainMigrateFinish2 */
1308 1309 1310 1311 1312 1313 1314
};

int openvzRegister(void) {
    virRegisterDriver(&openvzDriver);
    return 0;
}