您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ virRun函数代码示例

51自学网 2021-06-03 09:42:37
  C++
这篇教程C++ virRun函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中virRun函数的典型用法代码示例。如果您正苦于以下问题:C++ virRun函数的具体用法?C++ virRun怎么用?C++ virRun使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了virRun函数的29个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: virStorageBackendISCSIConnectionIQN

static intvirStorageBackendISCSIConnectionIQN(virStoragePoolObjPtr pool,                                    const char *portal,                                    const char *action){    int ret = -1;    char *ifacename = NULL;    switch (virStorageBackendIQNFound(pool, &ifacename)) {    case IQN_FOUND:        VIR_DEBUG("ifacename: '%s'", ifacename);        break;    case IQN_MISSING:        if (virStorageBackendCreateIfaceIQN(pool, &ifacename) != 0) {            goto out;        }        break;    case IQN_ERROR:    default:        goto out;    }    const char *const sendtargets[] = {        ISCSIADM, "--mode", "discovery", "--type", "sendtargets", "--portal", portal, NULL    };    if (virRun(sendtargets, NULL) < 0) {        virStorageReportError(VIR_ERR_INTERNAL_ERROR,                              _("Failed to run %s to get target list"),                              sendtargets[0]);        goto out;    }    const char *const cmdargv[] = {        ISCSIADM, "--mode", "node", "--portal", portal,        "--targetname", pool->def->source.devices[0].path, "--interface",        ifacename, action, NULL    };    if (virRun(cmdargv, NULL) < 0) {        virStorageReportError(VIR_ERR_INTERNAL_ERROR,                              _("Failed to run command '%s' with action '%s'"),                              cmdargv[0], action);        goto out;    }    ret = 0;out:    VIR_FREE(ifacename);    return ret;}
开发者ID:hjwsm1989,项目名称:libvirt,代码行数:51,


示例2: vmwareStartVM

static intvmwareStartVM(struct vmware_driver *driver, virDomainObjPtr vm){    const char *cmd[] = {        VMRUN, "-T", PROGRAM_SENTINAL, "start",        PROGRAM_SENTINAL, PROGRAM_SENTINAL, NULL    };    const char *vmxPath = ((vmwareDomainPtr) vm->privateData)->vmxPath;    if (virDomainObjGetState(vm, NULL) != VIR_DOMAIN_SHUTOFF) {        virReportError(VIR_ERR_OPERATION_INVALID, "%s",                       _("domain is not in shutoff state"));        return -1;    }    vmwareSetSentinal(cmd, vmw_types[driver->type]);    vmwareSetSentinal(cmd, vmxPath);    if (!((vmwareDomainPtr) vm->privateData)->gui)        vmwareSetSentinal(cmd, NOGUI);    else        vmwareSetSentinal(cmd, NULL);    if (virRun(cmd, NULL) < 0) {        return -1;    }    if ((vm->def->id = vmwareExtractPid(vmxPath)) < 0) {        vmwareStopVM(driver, vm, VIR_DOMAIN_SHUTOFF_FAILED);        return -1;    }    virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, VIR_DOMAIN_RUNNING_BOOTED);    return 0;}
开发者ID:bigclouds,项目名称:libvirt,代码行数:35,


示例3: vmwareMoveFile

intvmwareMoveFile(char *srcFile, char *dstFile){    const char *cmdmv[] =        { "mv", PROGRAM_SENTINAL, PROGRAM_SENTINAL, NULL };    if (!virFileExists(srcFile)) {        virReportError(VIR_ERR_INTERNAL_ERROR, _("file %s does not exist"),                       srcFile);        return -1;    }    if (STREQ(srcFile, dstFile))        return 0;    vmwareSetSentinal(cmdmv, srcFile);    vmwareSetSentinal(cmdmv, dstFile);    if (virRun(cmdmv, NULL) < 0) {        virReportError(VIR_ERR_INTERNAL_ERROR,                       _("failed to move file to %s "), dstFile);        return -1;    }    return 0;}
开发者ID:hzguanqiang,项目名称:libvirt,代码行数:25,


示例4: openvzDomainSetAutostart

static intopenvzDomainSetAutostart(virDomainPtr dom, int autostart){    struct openvz_driver *driver = dom->conn->privateData;    virDomainObjPtr vm;    const char *prog[] = { VZCTL, "--quiet", "set", PROGRAM_SENTINAL,                           "--onboot", autostart ? "yes" : "no",                           "--save", NULL };    int ret = -1;    openvzDriverLock(driver);    vm = virDomainFindByUUID(&driver->domains, dom->uuid);    openvzDriverUnlock(driver);    if (!vm) {        openvzError(VIR_ERR_NO_DOMAIN, "%s",                    _("no domain with matching uuid"));        goto cleanup;    }    openvzSetProgramSentinal(prog, vm->def->name);    if (virRun(prog, NULL) < 0) {        goto cleanup;    }    ret = 0;cleanup:    if (vm)        virDomainObjUnlock(vm);    return ret;}
开发者ID:coolsnow77,项目名称:libvirt,代码行数:31,


示例5: virStorageBackendISCSIConnection

static intvirStorageBackendISCSIConnection(virStoragePoolObjPtr pool,                                 const char *portal,                                 const char *action){    int ret = 0;    if (pool->def->source.initiator.iqn != NULL) {        ret = virStorageBackendISCSIConnectionIQN(pool, portal, action);    } else {        const char *const cmdargv[] = {            ISCSIADM, "--mode", "node", "--portal", portal,            "--targetname", pool->def->source.devices[0].path, action, NULL        };        if (virRun(cmdargv, NULL) < 0) {            ret = -1;        }    }    return ret;}
开发者ID:hjwsm1989,项目名称:libvirt,代码行数:26,


示例6: virNetDevVethDelete

/** * virNetDevVethDelete: * @veth: name for one end of veth pair * * This will delete both veth devices in a pair.  Only one end needs to * be specified.  The ip command will identify and delete the other veth * device as well. * ip link del veth * * Returns 0 on success or -1 in case of error */int virNetDevVethDelete(const char *veth){    const char *argv[] = {"ip", "link", "del", veth, NULL};    VIR_DEBUG("veth: %s", veth);    return virRun(argv, NULL);}
开发者ID:heidsoft,项目名称:libvirt,代码行数:19,


示例7: virNetDevVethCreate

/** * virNetDevVethCreate: * @veth1: pointer to name for parent end of veth pair * @veth2: pointer to return name for container end of veth pair * * Creates a veth device pair using the ip command: * ip link add veth1 type veth peer name veth2 * If veth1 points to NULL on entry, it will be a valid interface on * return.  veth2 should point to NULL on entry. * * NOTE: If veth1 and veth2 names are not specified, ip will auto assign *       names.  There seems to be two problems here - *       1) There doesn't seem to be a way to determine the names of the *          devices that it creates.  They show up in ip link show and *          under /sys/class/net/ however there is no guarantee that they *          are the devices that this process just created. *       2) Once one of the veth devices is moved to another namespace, it *          is no longer visible in the parent namespace.  This seems to *          confuse the name assignment causing it to fail with File exists. *       Because of these issues, this function currently allocates names *       prior to using the ip command, and returns any allocated names *       to the caller. * * Returns 0 on success or -1 in case of error */int virNetDevVethCreate(char** veth1, char** veth2){    int rc = -1;    const char *argv[] = {        "ip", "link", "add", NULL, "type", "veth", "peer", "name", NULL, NULL    };    int vethDev = 0;    bool veth1_alloc = false;    bool veth2_alloc = false;    VIR_DEBUG("Host: %s guest: %s", NULLSTR(*veth1), NULLSTR(*veth2));    if (*veth1 == NULL) {        if ((vethDev = virNetDevVethGetFreeName(veth1, vethDev)) < 0)            goto cleanup;        VIR_DEBUG("Assigned host: %s", *veth1);        veth1_alloc = true;        vethDev++;    }    argv[3] = *veth1;    while (*veth2 == NULL) {        if ((vethDev = virNetDevVethGetFreeName(veth2, vethDev)) < 0) {            if (veth1_alloc)                VIR_FREE(*veth1);            goto cleanup;        }        /* Just make sure they didn't accidentally get same name */        if (STREQ(*veth1, *veth2)) {            vethDev++;            VIR_FREE(*veth2);            continue;        }        VIR_DEBUG("Assigned guest: %s", *veth2);        veth2_alloc = true;    }    argv[8] = *veth2;    VIR_DEBUG("Create Host: %s guest: %s", *veth1, *veth2);    if (virRun(argv, NULL) < 0) {        if (veth1_alloc)            VIR_FREE(*veth1);        if (veth2_alloc)            VIR_FREE(*veth2);        goto cleanup;    }    rc = 0;cleanup:    return rc;}
开发者ID:heidsoft,项目名称:libvirt,代码行数:79,


示例8: virStorageBackendISCSIRescanLUNs

static intvirStorageBackendISCSIRescanLUNs(virStoragePoolObjPtr pool ATTRIBUTE_UNUSED,                                 const char *session){    const char *const cmdargv[] = {        ISCSIADM, "--mode", "session", "-r", session, "-R", NULL,    };    if (virRun(cmdargv, NULL) < 0)        return -1;    return 0;}
开发者ID:kantai,项目名称:libvirt-vfork,代码行数:13,


示例9: remove_profile

static intremove_profile(const char *profile){    int rc = -1;    const char * const argv[] = {        VIRT_AA_HELPER, "-R", "-u", profile, NULL    };    if (virRun(argv, NULL) == 0)        rc = 0;    return rc;}
开发者ID:hitchiker42,项目名称:libvirt,代码行数:13,


示例10: virStorageBackendISCSILogin

static intvirStorageBackendISCSILogin(virStoragePoolObjPtr pool,                            const char *portal){    const char *const cmdsendtarget[] = {        ISCSIADM, "--mode", "discovery", "--type", "sendtargets",        "--portal", portal, NULL    };    if (virRun(cmdsendtarget, NULL) < 0)        return -1;    return virStorageBackendISCSIConnection(pool, portal, "--login");}
开发者ID:hjwsm1989,项目名称:libvirt,代码行数:14,


示例11: vmwareDomainResume

static intvmwareDomainResume(virDomainPtr dom){    struct vmware_driver *driver = dom->conn->privateData;    virDomainObjPtr vm;    const char *cmd[] = {        VMRUN, "-T", PROGRAM_SENTINAL, "unpause", PROGRAM_SENTINAL,        NULL    };    int ret = -1;    if (driver->type == TYPE_PLAYER) {        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",                       _("vmplayer does not support libvirt suspend/resume "                         "(vmware pause/unpause) operation "));        return ret;    }    vmwareDriverLock(driver);    vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);    vmwareDriverUnlock(driver);    if (!vm) {        virReportError(VIR_ERR_NO_DOMAIN, "%s",                       _("no domain with matching uuid"));        goto cleanup;    }    vmwareSetSentinal(cmd, vmw_types[driver->type]);    vmwareSetSentinal(cmd, ((vmwareDomainPtr) vm->privateData)->vmxPath);    if (virDomainObjGetState(vm, NULL) != VIR_DOMAIN_PAUSED) {        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",                       _("domain is not in suspend state"));        goto cleanup;    }    if (virRun(cmd, NULL) < 0)        goto cleanup;    virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, VIR_DOMAIN_RUNNING_UNPAUSED);    ret = 0;  cleanup:    if (vm)        virObjectUnlock(vm);    return ret;}
开发者ID:bigclouds,项目名称:libvirt,代码行数:48,


示例12: virStorageBackendLogicalSetActive

static intvirStorageBackendLogicalSetActive(virStoragePoolObjPtr pool,                                  int on){    const char *cmdargv[4];    cmdargv[0] = VGCHANGE;    cmdargv[1] = on ? "-ay" : "-an";    cmdargv[2] = pool->def->source.name;    cmdargv[3] = NULL;    if (virRun(cmdargv, NULL) < 0)        return -1;    return 0;}
开发者ID:amery,项目名称:libvirt-vserver,代码行数:16,


示例13: vmwareDomainReboot

static intvmwareDomainReboot(virDomainPtr dom, unsigned int flags){    struct vmware_driver *driver = dom->conn->privateData;    const char * vmxPath = NULL;    virDomainObjPtr vm;    const char *cmd[] = {        VMRUN, "-T", PROGRAM_SENTINAL,        "reset", PROGRAM_SENTINAL, "soft", NULL    };    int ret = -1;    virCheckFlags(0, -1);    vmwareDriverLock(driver);    vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);    vmwareDriverUnlock(driver);    if (!vm) {        virReportError(VIR_ERR_NO_DOMAIN, "%s",                       _("no domain with matching uuid"));        goto cleanup;    }    vmxPath = ((vmwareDomainPtr) vm->privateData)->vmxPath;    vmwareSetSentinal(cmd, vmw_types[driver->type]);    vmwareSetSentinal(cmd, vmxPath);    if (vmwareUpdateVMStatus(driver, vm) < 0)        goto cleanup;    if (virDomainObjGetState(vm, NULL) != VIR_DOMAIN_RUNNING) {        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",                       _("domain is not in running state"));        goto cleanup;    }    if (virRun(cmd, NULL) < 0)        goto cleanup;    ret = 0;  cleanup:    if (vm)        virObjectUnlock(vm);    return ret;}
开发者ID:bigclouds,项目名称:libvirt,代码行数:47,


示例14: openvzDomainCreateWithFlags

static intopenvzDomainCreateWithFlags(virDomainPtr dom, unsigned int flags){    struct openvz_driver *driver = dom->conn->privateData;    virDomainObjPtr vm;    const char *prog[] = {VZCTL, "--quiet", "start", PROGRAM_SENTINAL, NULL };    int ret = -1;    int status;    virCheckFlags(0, -1);    openvzDriverLock(driver);    vm = virDomainFindByName(&driver->domains, dom->name);    openvzDriverUnlock(driver);    if (!vm) {        openvzError(VIR_ERR_NO_DOMAIN, "%s",                    _("no domain with matching id"));        goto cleanup;    }    if (openvzGetVEStatus(vm, &status, NULL) == -1)        goto cleanup;    if (status != VIR_DOMAIN_SHUTOFF) {        openvzError(VIR_ERR_OPERATION_DENIED, "%s",                    _("domain is not in shutoff state"));        goto cleanup;    }    openvzSetProgramSentinal(prog, vm->def->name);    if (virRun(prog, NULL) < 0) {        goto cleanup;    }    vm->pid = strtoI(vm->def->name);    vm->def->id = vm->pid;    dom->id = vm->pid;    virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, VIR_DOMAIN_RUNNING_BOOTED);    ret = 0;cleanup:    if (vm)        virDomainObjUnlock(vm);    return ret;}
开发者ID:coolsnow77,项目名称:libvirt,代码行数:46,


示例15: virStorageBackendFileSystemUnmount

/** * @conn connection to report errors against * @pool storage pool to unmount * * Ensure that a FS storage pool is not mounted on its target location. * If already unmounted, this is a no-op * * Returns 0 if successfully unmounted, -1 on error */static intvirStorageBackendFileSystemUnmount(virStoragePoolObjPtr pool) {    const char *mntargv[3];    int ret;    if (pool->def->type == VIR_STORAGE_POOL_NETFS) {        if (pool->def->source.nhost != 1) {            virStorageReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",                                  _("Expected exactly 1 host for the storage pool"));            return -1;        }        if (pool->def->source.hosts[0].name == NULL) {            virStorageReportError(VIR_ERR_INTERNAL_ERROR,                                  "%s", _("missing source host"));            return -1;        }        if (pool->def->source.dir == NULL) {            virStorageReportError(VIR_ERR_INTERNAL_ERROR,                                  "%s", _("missing source dir"));            return -1;        }    } else {        if (pool->def->source.ndevice != 1) {            virStorageReportError(VIR_ERR_INTERNAL_ERROR,                                  "%s", _("missing source device"));            return -1;        }    }    /* Short-circuit if already unmounted */    if ((ret = virStorageBackendFileSystemIsMounted(pool)) != 1) {        if (ret < 0)            return -1;        else            return 0;    }    mntargv[0] = UMOUNT;    mntargv[1] = pool->def->target.path;    mntargv[2] = NULL;    if (virRun(mntargv, NULL) < 0) {        return -1;    }    return 0;}
开发者ID:rmarwaha,项目名称:libvirt,代码行数:55,


示例16: openvzDomainShutdownFlags

static intopenvzDomainShutdownFlags(virDomainPtr dom,                          unsigned int flags) {    struct openvz_driver *driver = dom->conn->privateData;    virDomainObjPtr vm;    const char *prog[] = {VZCTL, "--quiet", "stop", PROGRAM_SENTINAL, NULL};    int ret = -1;    int status;    virCheckFlags(0, -1);    openvzDriverLock(driver);    vm = virDomainFindByUUID(&driver->domains, dom->uuid);    openvzDriverUnlock(driver);    if (!vm) {        openvzError(VIR_ERR_NO_DOMAIN, "%s",                    _("no domain with matching uuid"));        goto cleanup;    }    if (openvzGetVEStatus(vm, &status, NULL) == -1)        goto cleanup;    openvzSetProgramSentinal(prog, vm->def->name);    if (status != VIR_DOMAIN_RUNNING) {        openvzError(VIR_ERR_INTERNAL_ERROR, "%s",                    _("domain is not in running state"));        goto cleanup;    }    if (virRun(prog, NULL) < 0)        goto cleanup;    vm->def->id = -1;    virDomainObjSetState(vm, VIR_DOMAIN_SHUTOFF, VIR_DOMAIN_SHUTOFF_SHUTDOWN);    dom->id = -1;    ret = 0;cleanup:    if (vm)        virDomainObjUnlock(vm);    return ret;}
开发者ID:coolsnow77,项目名称:libvirt,代码行数:44,


示例17: openvzDomainUndefineFlags

static intopenvzDomainUndefineFlags(virDomainPtr dom,                          unsigned int flags){    struct openvz_driver *driver = dom->conn->privateData;    virDomainObjPtr vm;    const char *prog[] = { VZCTL, "--quiet", "destroy", PROGRAM_SENTINAL, NULL };    int ret = -1;    int status;    virCheckFlags(0, -1);    openvzDriverLock(driver);    vm = virDomainFindByUUID(&driver->domains, dom->uuid);    if (!vm) {        openvzError(VIR_ERR_NO_DOMAIN, "%s",                    _("no domain with matching uuid"));        goto cleanup;    }    if (openvzGetVEStatus(vm, &status, NULL) == -1)        goto cleanup;    openvzSetProgramSentinal(prog, vm->def->name);    if (virRun(prog, NULL) < 0) {        goto cleanup;    }    if (virDomainObjIsActive(vm)) {        vm->persistent = 0;    } else {        virDomainRemoveInactive(&driver->domains, vm);        vm = NULL;    }    ret = 0;cleanup:    if (vm)        virDomainObjUnlock(vm);    openvzDriverUnlock(driver);    return ret;}
开发者ID:coolsnow77,项目名称:libvirt,代码行数:43,


示例18: vmwareStopVM

static intvmwareStopVM(struct vmware_driver *driver, virDomainObjPtr vm){    const char *cmd[] = {        VMRUN, "-T", PROGRAM_SENTINAL, "stop",        PROGRAM_SENTINAL, "soft", NULL    };    vmwareSetSentinal(cmd, vmw_types[driver->type]);    vmwareSetSentinal(cmd, ((vmwareDomainPtr) vm->privateData)->vmxPath);    if (virRun(cmd, NULL) < 0) {        return -1;    }    vm->def->id = -1;    vm->state = VIR_DOMAIN_SHUTOFF;    return 0;}
开发者ID:rbu,项目名称:libvirt,代码行数:20,


示例19: openvzDomainSetVcpusInternal

static int openvzDomainSetVcpusInternal(virDomainObjPtr vm,                                        unsigned int nvcpus){    char        str_vcpus[32];    const char *prog[] = { VZCTL, "--quiet", "set", PROGRAM_SENTINAL,                           "--cpus", str_vcpus, "--save", NULL };    unsigned int pcpus;    pcpus = openvzGetNodeCPUs();    if (pcpus > 0 && pcpus < nvcpus)        nvcpus = pcpus;    snprintf(str_vcpus, 31, "%d", nvcpus);    str_vcpus[31] = '/0';    openvzSetProgramSentinal(prog, vm->def->name);    if (virRun(prog, NULL) < 0) {        return -1;    }    vm->def->maxvcpus = vm->def->vcpus = nvcpus;    return 0;}
开发者ID:coolsnow77,项目名称:libvirt,代码行数:22,


示例20: openvzDomainSetMemoryInternal

static intopenvzDomainSetMemoryInternal(virDomainObjPtr vm,                              unsigned long mem){    char str_mem[16];    const char *prog[] = { VZCTL, "--quiet", "set", PROGRAM_SENTINAL,        "--kmemsize", str_mem, "--save", NULL    };    /* memory has to be changed its format from kbyte to byte */    snprintf(str_mem, sizeof(str_mem), "%lu", mem * 1024);    openvzSetProgramSentinal(prog, vm->def->name);    if (virRun(prog, NULL) < 0) {        goto cleanup;    }    return 0;cleanup:    return -1;}
开发者ID:coolsnow77,项目名称:libvirt,代码行数:22,


示例21: openvzDomainResume

static int openvzDomainResume(virDomainPtr dom) {  struct openvz_driver *driver = dom->conn->privateData;  virDomainObjPtr vm;  const char *prog[] = {VZCTL, "--quiet", "chkpnt", PROGRAM_SENTINAL, "--resume", NULL};  int ret = -1;  openvzDriverLock(driver);  vm = virDomainFindByUUID(&driver->domains, dom->uuid);  openvzDriverUnlock(driver);  if (!vm) {      openvzError(VIR_ERR_NO_DOMAIN, "%s",                  _("no domain with matching uuid"));      goto cleanup;  }  if (!virDomainObjIsActive(vm)) {      openvzError(VIR_ERR_OPERATION_INVALID, "%s",                  _("Domain is not running"));      goto cleanup;  }  if (virDomainObjGetState(vm, NULL) == VIR_DOMAIN_PAUSED) {      openvzSetProgramSentinal(prog, vm->def->name);      if (virRun(prog, NULL) < 0) {          goto cleanup;      }      virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, VIR_DOMAIN_RUNNING_UNPAUSED);  }  ret = 0;cleanup:  if (vm)      virDomainObjUnlock(vm);  return ret;}
开发者ID:coolsnow77,项目名称:libvirt,代码行数:37,


示例22: openvzDomainSetNetwork

//.........这里部分代码省略.........    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);    }    virFormatMacAddr(net->mac, macaddr);    virCapabilitiesGenerateMac(driver->caps, host_mac);    virFormatMacAddr(host_mac, host_macaddr);    if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE ||        (net->type == VIR_DOMAIN_NET_TYPE_ETHERNET &&         net->data.ethernet.ipaddr == NULL)) {        virBuffer buf = VIR_BUFFER_INITIALIZER;        int veid = openvzGetVEID(vpsid);        /* --netif_add ifname[,mac,host_ifname,host_mac] */        ADD_ARG_LIT("--netif_add") ;        /* if user doesn't specify guest interface name,         * then we need to generate it */        if (net->data.ethernet.dev == NULL) {            net->data.ethernet.dev = openvzGenerateContainerVethName(veid);            if (net->data.ethernet.dev == NULL) {               openvzError(VIR_ERR_INTERNAL_ERROR, "%s",                           _("Could not generate eth name for container"));               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, net->data.ethernet.dev);            if (net->ifname == NULL) {               openvzError(VIR_ERR_INTERNAL_ERROR, "%s",                           _("Could not generate veth name"));               rc = -1;               goto exit;            }        }        virBufferAdd(&buf, net->data.ethernet.dev, -1); /* Guest dev */        virBufferAsprintf(&buf, ",%s", macaddr); /* Guest dev mac */        virBufferAsprintf(&buf, ",%s", net->ifname); /* Host dev */        virBufferAsprintf(&buf, ",%s", host_macaddr); /* Host dev mac */        if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE) {            if (driver->version >= VZCTL_BRIDGE_MIN_VERSION) {                virBufferAsprintf(&buf, ",%s", net->data.bridge.brname); /* Host bridge */            } else {                virBufferAsprintf(configBuf, "ifname=%s", net->data.ethernet.dev);                virBufferAsprintf(configBuf, ",mac=%s", macaddr); /* Guest dev mac */                virBufferAsprintf(configBuf, ",host_ifname=%s", net->ifname); /* Host dev */                virBufferAsprintf(configBuf, ",host_mac=%s", host_macaddr); /* Host dev mac */                virBufferAsprintf(configBuf, ",bridge=%s", net->data.bridge.brname); /* Host bridge */            }        }        if (!(opt = virBufferContentAndReset(&buf)))            goto no_memory;        ADD_ARG_LIT(opt) ;        VIR_FREE(opt);    } else if (net->type == VIR_DOMAIN_NET_TYPE_ETHERNET &&              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");        if (virRun(prog, NULL) < 0) {           rc = -1;           goto exit;        }    } exit:    cmdExecFree(prog);    return rc; no_memory:    VIR_FREE(opt);    openvzError(VIR_ERR_INTERNAL_ERROR,                _("Could not put argument to %s"), VZCTL);    cmdExecFree(prog);    return -1;#undef ADD_ARG_LIT}
开发者ID:coolsnow77,项目名称:libvirt,代码行数:101,


示例23: virStorageBackendFileSystemMount

//.........这里部分代码省略.........    int glusterfs = (pool->def->type == VIR_STORAGE_POOL_NETFS &&                 pool->def->source.format == VIR_STORAGE_POOL_NETFS_GLUSTERFS);    int source_index;    const char *netfs_auto_argv[] = {        MOUNT,        NULL, /* source path */        pool->def->target.path,        NULL,    };    const char *fs_argv[] =  {        MOUNT,        "-t",        pool->def->type == VIR_STORAGE_POOL_FS ?        virStoragePoolFormatFileSystemTypeToString(pool->def->source.format) :        virStoragePoolFormatFileSystemNetTypeToString(pool->def->source.format),        NULL, /* Fill in shortly - careful not to add extra fields                 before this */        pool->def->target.path,        NULL,    };    const char *glusterfs_argv[] = {        MOUNT,        "-t",        pool->def->type == VIR_STORAGE_POOL_FS ?        virStoragePoolFormatFileSystemTypeToString(pool->def->source.format) :        virStoragePoolFormatFileSystemNetTypeToString(pool->def->source.format),        NULL,        "-o",        "direct-io-mode=1",        pool->def->target.path,        NULL,    };    if (netauto) {        mntargv = netfs_auto_argv;        source_index = 1;    } else if (glusterfs) {        mntargv = glusterfs_argv;        source_index = 3;    } else {        mntargv = fs_argv;        source_index = 3;    }    int ret;    if (pool->def->type == VIR_STORAGE_POOL_NETFS) {        if (pool->def->source.host.name == NULL) {            virStorageReportError(VIR_ERR_INTERNAL_ERROR,                                  "%s", _("missing source host"));            return -1;        }        if (pool->def->source.dir == NULL) {            virStorageReportError(VIR_ERR_INTERNAL_ERROR,                                  "%s", _("missing source path"));            return -1;        }    } else {        if (pool->def->source.ndevice != 1) {            virStorageReportError(VIR_ERR_INTERNAL_ERROR,                                  "%s", _("missing source device"));            return -1;        }    }    /* Short-circuit if already mounted */    if ((ret = virStorageBackendFileSystemIsMounted(pool)) != 0) {        if (ret < 0)            return -1;        else            return 0;    }    if (pool->def->type == VIR_STORAGE_POOL_NETFS) {        if (virAsprintf(&src, "%s:%s",                        pool->def->source.host.name,                        pool->def->source.dir) == -1) {            virReportOOMError();            return -1;        }    } else {        if ((src = strdup(pool->def->source.devices[0].path)) == NULL) {            virReportOOMError();            return -1;        }    }    mntargv[source_index] = src;    if (virRun(mntargv, NULL) < 0) {        VIR_FREE(src);        return -1;    }    VIR_FREE(src);    return 0;}
开发者ID:danwent,项目名称:libvirt-ovs,代码行数:101,


示例24: virStorageBackendCreateIfaceIQN

static intvirStorageBackendCreateIfaceIQN(const char *initiatoriqn,                                char **ifacename){    int ret = -1, exitstatus = -1;    char temp_ifacename[32];    const char *const cmdargv1[] = {        ISCSIADM, "--mode", "iface", "--interface",        temp_ifacename, "--op", "new", NULL    };    const char *const cmdargv2[] = {        ISCSIADM, "--mode", "iface", "--interface", temp_ifacename,        "--op", "update", "--name", "iface.initiatorname", "--value",        initiatoriqn, NULL    };    if (virRandomInitialize(time(NULL) ^ getpid()) == -1) {        virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s",                              _("Failed to initialize random generator "                                "when creating iscsi interface"));        goto out;    }    snprintf(temp_ifacename, sizeof(temp_ifacename), "libvirt-iface-%08x",             virRandom(1024 * 1024 * 1024));    VIR_DEBUG("Attempting to create interface '%s' with IQN '%s'",              &temp_ifacename[0], initiatoriqn);    /* Note that we ignore the exitstatus.  Older versions of iscsiadm     * tools returned an exit status of > 0, even if they succeeded.     * We will just rely on whether the interface got created     * properly. */    if (virRun(cmdargv1, &exitstatus) < 0) {        virStorageReportError(VIR_ERR_INTERNAL_ERROR,                              _("Failed to run command '%s' to create new iscsi interface"),                              cmdargv1[0]);        goto out;    }    /* Note that we ignore the exitstatus.  Older versions of iscsiadm tools     * returned an exit status of > 0, even if they succeeded.  We will just     * rely on whether iface file got updated properly. */    if (virRun(cmdargv2, &exitstatus) < 0) {        virStorageReportError(VIR_ERR_INTERNAL_ERROR,                              _("Failed to run command '%s' to update iscsi interface with IQN '%s'"),                              cmdargv2[0], initiatoriqn);        goto out;    }    /* Check again to make sure the interface was created. */    if (virStorageBackendIQNFound(initiatoriqn, ifacename) != IQN_FOUND) {        VIR_DEBUG("Failed to find interface '%s' with IQN '%s' "                  "after attempting to create it",                  &temp_ifacename[0], initiatoriqn);        goto out;    } else {        VIR_DEBUG("Interface '%s' with IQN '%s' was created successfully",                  *ifacename, initiatoriqn);    }    ret = 0;out:    if (ret != 0)        VIR_FREE(*ifacename);    return ret;}
开发者ID:kantai,项目名称:libvirt-vfork,代码行数:68,


示例25: openvzSetInitialConfig

static int openvzSetInitialConfig(virDomainDefPtr vmdef){    int ret = -1;    int vpsid;    char * confdir = NULL;    const char *prog[OPENVZ_MAX_ARG];    prog[0] = NULL;    if (vmdef->nfss > 1) {        openvzError(VIR_ERR_INTERNAL_ERROR, "%s",                    _("only one filesystem supported"));        goto cleanup;    }    if (vmdef->nfss == 1 &&        vmdef->fss[0]->type != VIR_DOMAIN_FS_TYPE_TEMPLATE &&        vmdef->fss[0]->type != VIR_DOMAIN_FS_TYPE_MOUNT)    {        openvzError(VIR_ERR_INTERNAL_ERROR, "%s",                    _("filesystem is not of type 'template' or 'mount'"));        goto cleanup;    }    if (vmdef->nfss == 1 &&        vmdef->fss[0]->type == VIR_DOMAIN_FS_TYPE_MOUNT)    {        if (virStrToLong_i(vmdef->name, NULL, 10, &vpsid) < 0) {            openvzError(VIR_ERR_INTERNAL_ERROR, "%s",                        _("Could not convert domain name to VEID"));            goto cleanup;        }        if (openvzCopyDefaultConfig(vpsid) < 0) {            openvzError(VIR_ERR_INTERNAL_ERROR, "%s",                        _("Could not copy default config"));            goto cleanup;        }        if (openvzWriteVPSConfigParam(vpsid, "VE_PRIVATE", vmdef->fss[0]->src) < 0) {            openvzError(VIR_ERR_INTERNAL_ERROR, "%s",                        _("Could not set the source dir for the filesystem"));            goto cleanup;        }    }    else    {        if (openvzDomainDefineCmd(prog, OPENVZ_MAX_ARG, vmdef) < 0) {            VIR_ERROR(_("Error creating command for container"));            goto cleanup;        }        if (virRun(prog, NULL) < 0) {            goto cleanup;        }    }    ret = 0;cleanup:  VIR_FREE(confdir);  cmdExecFree(prog);  return ret;}
开发者ID:coolsnow77,项目名称:libvirt,代码行数:65,


示例26: iptablesAddRemoveRule

static int ATTRIBUTE_SENTINELiptablesAddRemoveRule(iptRules *rules, int action, const char *arg, ...){    va_list args;    int retval = ENOMEM;    const char **argv;    const char *s;    int n;    n = 1 + /* /sbin/iptables  */        2 + /*   --table foo   */        2 + /*   --insert bar  */        1;  /*   arg           */    va_start(args, arg);    while (va_arg(args, const char *))        n++;    va_end(args);    if (VIR_ALLOC_N(argv, n + 1) < 0)        goto error;    n = 0;    if (!(argv[n++] = strdup(IPTABLES_PATH)))        goto error;    if (!(argv[n++] = strdup("--table")))        goto error;    if (!(argv[n++] = strdup(rules->table)))        goto error;    if (!(argv[n++] = strdup(action == ADD ? "--insert" : "--delete")))        goto error;    if (!(argv[n++] = strdup(rules->chain)))        goto error;    if (!(argv[n++] = strdup(arg)))        goto error;    va_start(args, arg);    while ((s = va_arg(args, const char *))) {        if (!(argv[n++] = strdup(s))) {            va_end(args);            goto error;        }    }    va_end(args);    if (virRun(argv, NULL) < 0) {        retval = errno;        goto error;    }    retval = 0; error:    if (argv) {        n = 0;        while (argv[n])            VIR_FREE(argv[n++]);        VIR_FREE(argv);    }    return retval;}
开发者ID:amery,项目名称:libvirt-vserver,代码行数:71,


示例27: openvzDomainCreateXML

static virDomainPtropenvzDomainCreateXML(virConnectPtr conn, const char *xml,                      unsigned int flags){    struct openvz_driver *driver =  conn->privateData;    virDomainDefPtr vmdef = NULL;    virDomainObjPtr vm = NULL;    virDomainPtr dom = NULL;    const char *progstart[] = {VZCTL, "--quiet", "start", PROGRAM_SENTINAL, NULL};    virCheckFlags(0, NULL);    openvzDriverLock(driver);    if ((vmdef = virDomainDefParseString(driver->caps, xml,                                         1 << VIR_DOMAIN_VIRT_OPENVZ,                                         VIR_DOMAIN_XML_INACTIVE)) == NULL)        goto cleanup;    vm = virDomainFindByName(&driver->domains, vmdef->name);    if (vm) {        openvzError(VIR_ERR_OPERATION_FAILED,                    _("Already an OPENVZ VM defined with the id '%s'"),                   vmdef->name);        goto cleanup;    }    if (!(vm = virDomainAssignDef(driver->caps,                                  &driver->domains, vmdef, false)))        goto cleanup;    vmdef = NULL;    /* All OpenVZ domains seem to be persistent - this is a bit of a violation     * of this libvirt API which is intended for transient domain creation */    vm->persistent = 1;    if (openvzSetInitialConfig(vm->def) < 0) {        VIR_ERROR(_("Error creating initial configuration"));        goto cleanup;    }    if (openvzSetDefinedUUID(strtoI(vm->def->name), vm->def->uuid) < 0) {        openvzError(VIR_ERR_INTERNAL_ERROR, "%s",                    _("Could not set UUID"));        goto cleanup;    }    if (openvzDomainSetNetworkConfig(conn, vm->def) < 0)        goto cleanup;    openvzSetProgramSentinal(progstart, vm->def->name);    if (virRun(progstart, NULL) < 0) {        goto cleanup;    }    vm->pid = strtoI(vm->def->name);    vm->def->id = vm->pid;    virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, VIR_DOMAIN_RUNNING_BOOTED);    if (vm->def->maxvcpus > 0) {        if (openvzDomainSetVcpusInternal(vm, vm->def->maxvcpus) < 0) {            openvzError(VIR_ERR_INTERNAL_ERROR, "%s",                        _("Could not set number of virtual cpu"));            goto cleanup;        }    }    dom = virGetDomain(conn, vm->def->name, vm->def->uuid);    if (dom)        dom->id = vm->def->id;cleanup:    virDomainDefFree(vmdef);    if (vm)        virDomainObjUnlock(vm);    openvzDriverUnlock(driver);    return dom;}
开发者ID:coolsnow77,项目名称:libvirt,代码行数:76,


示例28: ebtablesAddRemoveRule

static int ATTRIBUTE_SENTINELebtablesAddRemoveRule(ebtRules *rules, int action, const char *arg, ...){    va_list args;    int retval = ENOMEM;    const char **argv;    char *rule = NULL;    const char *s;    int n, command_idx;    n = 1 + /* /sbin/ebtables  */        2 + /*   --table foo   */        2 + /*   --insert bar  */        1;  /*   arg           */#if HAVE_FIREWALLD    virEbTablesInitialize();    if (firewall_cmd_path)        n += 3; /* --direct --passthrough eb */#endif    va_start(args, arg);    while (va_arg(args, const char *))        n++;    va_end(args);    if (VIR_ALLOC_N(argv, n + 1) < 0)        goto error;    n = 0;#if HAVE_FIREWALLD    if (firewall_cmd_path) {        if (!(argv[n++] = strdup(firewall_cmd_path)))            goto error;        if (!(argv[n++] = strdup("--direct")))            goto error;        if (!(argv[n++] = strdup("--passthrough")))            goto error;        if (!(argv[n++] = strdup("eb")))            goto error;    } else#endif    if (!(argv[n++] = strdup(EBTABLES_PATH)))        goto error;    command_idx = n;    if(action == ADD || action == REMOVE) {        if (!(argv[n++] = strdup("--insert")))            goto error;        if (!(argv[n++] = strdup(rules->chain)))            goto error;    }    if (!(argv[n++] = strdup(arg)))        goto error;    va_start(args, arg);    while ((s = va_arg(args, const char *))) {        if (!(argv[n++] = strdup(s))) {            va_end(args);            goto error;        }    }    va_end(args);    if (!(rule = virArgvToString(&argv[command_idx])))        goto error;    if (action == REMOVE) {        VIR_FREE(argv[command_idx]);        if (!(argv[command_idx] = strdup("--delete")))            goto error;    }    if (virRun(argv, NULL) < 0) {        retval = errno;        goto error;    }    if (action == ADD || action == CREATE || action == POLICY ||        action == INSERT) {        retval = ebtRulesAppend(rules, rule, argv, command_idx);        rule = NULL;        argv = NULL;    } else {        retval = ebtRulesRemove(rules, rule);    } error:    VIR_FREE(rule);    if (argv) {        n = 0;        while (argv[n])//.........这里部分代码省略.........
开发者ID:mohankku,项目名称:libvirt,代码行数:101,


示例29: criuExists

bool criuExists(void){    const char* prog[] = {"which", "criu", NULL};    return (virRun(prog, NULL) == 0);}
开发者ID:RWTH-OS,项目名称:libvirt,代码行数:5,



注:本文中的virRun函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


C++ virStoragePoolObjUnlock函数代码示例
C++ virResetLastError函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。