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

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

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

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

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

示例1: virStorageBackendSheepdogRefreshVol

static intvirStorageBackendSheepdogRefreshVol(virConnectPtr conn ATTRIBUTE_UNUSED,                                    virStoragePoolObjPtr pool,                                    virStorageVolDefPtr vol){    int ret;    char *output = NULL;    virCommandPtr cmd = virCommandNewArgList(COLLIE, "vdi", "list", vol->name, "-r", NULL);    virStorageBackendSheepdogAddHostArg(cmd, pool);    virCommandSetOutputBuffer(cmd, &output);    ret = virCommandRun(cmd, NULL);    if (ret < 0)        goto cleanup;    if ((ret = virStorageBackendSheepdogParseVdiList(vol, output)) < 0)        goto cleanup;    vol->type = VIR_STORAGE_VOL_NETWORK;    VIR_FREE(vol->key);    if (virAsprintf(&vol->key, "%s/%s",                    pool->def->source.name, vol->name) == -1)        goto cleanup;    VIR_FREE(vol->target.path);    ignore_value(VIR_STRDUP(vol->target.path, vol->name)); cleanup:    virCommandFree(cmd);    return ret;}
开发者ID:6WIND,项目名称:libvirt,代码行数:32,


示例2: parallelsDoCmdRun

static intparallelsDoCmdRun(char **outbuf, const char *binary, va_list list){    virCommandPtr cmd = virCommandNewVAList(binary, list);    char *scmd = NULL;    int ret = -1;    if (outbuf)        virCommandSetOutputBuffer(cmd, outbuf);    scmd = virCommandToString(cmd);    if (!scmd)        goto cleanup;    if (virCommandRun(cmd, NULL))        goto cleanup;    ret = 0;  cleanup:    VIR_FREE(scmd);    virCommandFree(cmd);    if (ret)        VIR_FREE(*outbuf);    return ret;}
开发者ID:mohankku,项目名称:libvirt,代码行数:26,


示例3: libxlDomainGetEmulatorType

intlibxlDomainGetEmulatorType(const virDomainDef *def){    int ret = LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN;    virCommandPtr cmd = NULL;    char *output = NULL;    if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) {        if (def->emulator) {            if (!virFileExists(def->emulator))                goto cleanup;            cmd = virCommandNew(def->emulator);            virCommandAddArgList(cmd, "-help", NULL);            virCommandSetOutputBuffer(cmd, &output);            if (virCommandRun(cmd, NULL) < 0)                goto cleanup;            if (strstr(output, LIBXL_QEMU_DM_STR))                ret = LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL;        }    } cleanup:    VIR_FREE(output);    virCommandFree(cmd);    return ret;}
开发者ID:open-power-host-os,项目名称:libvirt,代码行数:30,


示例4: openvzGetVEID

int openvzGetVEID(const char *name){    virCommandPtr cmd;    char *outbuf;    char *temp;    int veid;    bool ok;    cmd = virCommandNewArgList(VZLIST, name, "-ovpsid", "-H", NULL);    virCommandSetOutputBuffer(cmd, &outbuf);    if (virCommandRun(cmd, NULL) < 0) {        virCommandFree(cmd);        VIR_FREE(outbuf);        return -1;    }    virCommandFree(cmd);    ok = virStrToLong_i(outbuf, &temp, 10, &veid) == 0 && *temp == '/n';    VIR_FREE(outbuf);    if (ok && veid >= 0)        return veid;    virReportError(VIR_ERR_INTERNAL_ERROR, "%s",                   _("Failed to parse vzlist output"));    return -1;}
开发者ID:noxdafox,项目名称:libvirt,代码行数:27,


示例5: virBhyveProbeGrubCaps

intvirBhyveProbeGrubCaps(virBhyveGrubCapsFlags *caps){    char *binary, *help;    virCommandPtr cmd;    int ret, exit;    ret = 0;    *caps = 0;    cmd = NULL;    help = NULL;    binary = virFindFileInPath("grub-bhyve");    if (binary == NULL)        goto out;    if (!virFileIsExecutable(binary))        goto out;    cmd = virCommandNew(binary);    virCommandAddArg(cmd, "--help");    virCommandSetOutputBuffer(cmd, &help);    if (virCommandRun(cmd, &exit) < 0) {        ret = -1;        goto out;    }    if (strstr(help, "--cons-dev") != NULL)        *caps |= BHYVE_GRUB_CAP_CONSDEV; out:    VIR_FREE(help);    virCommandFree(cmd);    VIR_FREE(binary);    return ret;}
开发者ID:JGulic,项目名称:libvirt,代码行数:35,


示例6: virStorageBackendSCSISerial

static char *virStorageBackendSCSISerial(const char *dev){    char *serial = NULL;#ifdef WITH_UDEV    virCommandPtr cmd = virCommandNewArgList(        "/lib/udev/scsi_id",        "--replace-whitespace",        "--whitelisted",        "--device", dev,        NULL        );    /* Run the program and capture its output */    virCommandSetOutputBuffer(cmd, &serial);    if (virCommandRun(cmd, NULL) < 0)        goto cleanup;#endif    if (serial && STRNEQ(serial, "")) {        char *nl = strchr(serial, '/n');        if (nl)            *nl = '/0';    } else {        VIR_FREE(serial);        ignore_value(VIR_STRDUP(serial, dev));    }#ifdef WITH_UDEVcleanup:    virCommandFree(cmd);#endif    return serial;}
开发者ID:TelekomCloud,项目名称:libvirt,代码行数:35,


示例7: virSysinfoRead

virSysinfoDefPtrvirSysinfoRead(void) {    char *path;    virSysinfoDefPtr ret = NULL;    char *outbuf = NULL;    virCommandPtr cmd;    path = virFindFileInPath(SYSINFO_SMBIOS_DECODER);    if (path == NULL) {        virSmbiosReportError(VIR_ERR_INTERNAL_ERROR,                             _("Failed to find path for %s binary"),                             SYSINFO_SMBIOS_DECODER);        return NULL;    }    cmd = virCommandNewArgList(path, "-q", "-t", "0,1,4,17", NULL);    VIR_FREE(path);    virCommandSetOutputBuffer(cmd, &outbuf);    if (virCommandRun(cmd, NULL) < 0) {        virSmbiosReportError(VIR_ERR_INTERNAL_ERROR,                             _("Failed to execute command %s"),                             path);        goto cleanup;    }    if (VIR_ALLOC(ret) < 0)        goto no_memory;    ret->type = VIR_SYSINFO_SMBIOS;    if (virSysinfoParseBIOS(outbuf, ret) < 0)        goto no_memory;    if (virSysinfoParseSystem(outbuf, ret) < 0)        goto no_memory;    ret->nprocessor = 0;    ret->processor = NULL;    if (virSysinfoParseProcessor(outbuf, ret) < 0)        goto no_memory;    ret->nmemory = 0;    ret->memory = NULL;    if (virSysinfoParseMemory(outbuf, ret) < 0)        goto no_memory;cleanup:    VIR_FREE(outbuf);    virCommandFree(cmd);    return ret;no_memory:    virReportOOMError();    virSysinfoDefFree(ret);    ret = NULL;    goto cleanup;}
开发者ID:rmarwaha,项目名称:libvirt1,代码行数:59,


示例8: vmwareUpdateVMStatus

static intvmwareUpdateVMStatus(struct vmware_driver *driver, virDomainObjPtr vm){    virCommandPtr cmd;    char *outbuf = NULL;    char *vmxAbsolutePath = NULL;    char *parsedVmxPath = NULL;    char *str;    char *saveptr = NULL;    bool found = false;    int oldState = virDomainObjGetState(vm, NULL);    int newState;    int ret = -1;    cmd = virCommandNewArgList(VMRUN, "-T", vmw_types[driver->type],                               "list", NULL);    virCommandSetOutputBuffer(cmd, &outbuf);    if (virCommandRun(cmd, NULL) < 0)        goto cleanup;    if (virFileResolveAllLinks(((vmwareDomainPtr) vm->privateData)->vmxPath,                               &vmxAbsolutePath) < 0)        goto cleanup;    for (str = outbuf ; (parsedVmxPath = strtok_r(str, "/n", &saveptr)) != NULL;         str = NULL) {        if (parsedVmxPath[0] != '/')            continue;        if (STREQ(parsedVmxPath, vmxAbsolutePath)) {            found = true;            /* If the vmx path is in the output, the domain is running or             * is paused but we have no way to detect if it is paused or not. */            if (oldState == VIR_DOMAIN_PAUSED)                newState = oldState;            else                newState = VIR_DOMAIN_RUNNING;            break;        }    }    if (!found) {        vm->def->id = -1;        newState = VIR_DOMAIN_SHUTOFF;    }    virDomainObjSetState(vm, newState, 0);    ret = 0;cleanup:    virCommandFree(cmd);    VIR_FREE(outbuf);    VIR_FREE(vmxAbsolutePath);    return ret;}
开发者ID:bigclouds,项目名称:libvirt,代码行数:57,


示例9: vmwareExtractVersion

intvmwareExtractVersion(struct vmware_driver *driver){    int ret = -1;    virCommandPtr cmd = NULL;    char * outbuf = NULL;    char *bin = NULL;    char *vmwarePath = NULL;    if ((vmwarePath = mdir_name(driver->vmrun)) == NULL)        goto cleanup;    switch (driver->type) {        case VMWARE_DRIVER_PLAYER:            if (virAsprintf(&bin, "%s/%s", vmwarePath, "vmplayer") < 0)                goto cleanup;            break;        case VMWARE_DRIVER_WORKSTATION:            if (virAsprintf(&bin, "%s/%s", vmwarePath, "vmware") < 0)                goto cleanup;            break;        case VMWARE_DRIVER_FUSION:            if (virAsprintf(&bin, "%s/%s", vmwarePath, "vmware-vmx") < 0)                goto cleanup;            break;        default:            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",                           _("invalid driver type for version detection"));            goto cleanup;    }    cmd = virCommandNewArgList(bin, "-v", NULL);    virCommandSetOutputBuffer(cmd, &outbuf);    virCommandSetErrorBuffer(cmd, &outbuf);    if (virCommandRun(cmd, NULL) < 0)        goto cleanup;    if (vmwareParseVersionStr(driver->type, outbuf, &driver->version) < 0)        goto cleanup;    ret = 0; cleanup:    virCommandFree(cmd);    VIR_FREE(outbuf);    VIR_FREE(bin);    VIR_FREE(vmwarePath);    return ret;}
开发者ID:AGSaidi,项目名称:hacked-libvirt,代码行数:53,


示例10: virStorageBackendZFSFindVols

static intvirStorageBackendZFSFindVols(virStoragePoolObjPtr pool,                             virStorageVolDefPtr vol){    virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);    virCommandPtr cmd = NULL;    char *volumes_list = NULL;    char **lines = NULL;    size_t i;    /**     * $ zfs list -Hp -t volume -o name,volsize -r test     * test/vol1       5368709120     * test/vol3       1073741824     * test/vol4       1572864000     * $     *     * Arguments description:     *  -t volume -- we want to see only volumes     *  -o name,volsize -- limit output to name and volume size     *  -r -- we want to see all the childer of our pool     */    cmd = virCommandNewArgList(ZFS,                               "list", "-Hp",                               "-t", "volume", "-r",                               "-o", "name,volsize,refreservation",                               def->source.name,                               NULL);    virCommandSetOutputBuffer(cmd, &volumes_list);    if (virCommandRun(cmd, NULL) < 0)        goto cleanup;    if (!(lines = virStringSplit(volumes_list, "/n", 0)))        goto cleanup;    for (i = 0; lines[i]; i++) {        if (STREQ(lines[i], ""))            continue;        if (virStorageBackendZFSParseVol(pool, vol, lines[i]) < 0)            continue;    } cleanup:    virCommandFree(cmd);    virStringListFree(lines);    VIR_FREE(volumes_list);    return 0;}
开发者ID:RWTH-OS,项目名称:libvirt,代码行数:50,


示例11: qemuCapsProbeCPUModels

intqemuCapsProbeCPUModels(const char *qemu,                       virBitmapPtr qemuCaps,                       const char *arch,                       unsigned int *count,                       const char ***cpus){    char *output = NULL;    int ret = -1;    qemuCapsParseCPUModels parse;    virCommandPtr cmd;    if (count)        *count = 0;    if (cpus)        *cpus = NULL;    if (STREQ(arch, "i686") || STREQ(arch, "x86_64"))        parse = qemuCapsParseX86Models;    else if (STREQ(arch, "ppc64"))        parse = qemuCapsParsePPCModels;    else {        VIR_DEBUG("don't know how to parse %s CPU models", arch);        return 0;    }    cmd = virCommandNewArgList(qemu, "-cpu", "?", NULL);    if (qemuCapsGet(qemuCaps, QEMU_CAPS_NODEFCONFIG))        virCommandAddArg(cmd, "-nodefconfig");    virCommandAddEnvPassCommon(cmd);    virCommandSetOutputBuffer(cmd, &output);    virCommandClearCaps(cmd);    if (virCommandRun(cmd, NULL) < 0)        goto cleanup;    if (parse(output, count, cpus) < 0)        goto cleanup;    ret = 0;cleanup:    VIR_FREE(output);    virCommandFree(cmd);    return ret;}
开发者ID:kthguru,项目名称:libvirt,代码行数:47,


示例12: virStorageBackendSheepdogRefreshAllVol

static intvirStorageBackendSheepdogRefreshAllVol(virConnectPtr conn ATTRIBUTE_UNUSED,                                       virStoragePoolObjPtr pool){    int ret = -1;    char *output = NULL;    char **lines = NULL;    char **cells = NULL;    size_t i;    virCommandPtr cmd = virCommandNewArgList(COLLIE, "vdi", "list", "-r", NULL);    virStorageBackendSheepdogAddHostArg(cmd, pool);    virCommandSetOutputBuffer(cmd, &output);    if (virCommandRun(cmd, NULL) < 0)        goto cleanup;    lines = virStringSplit(output, "/n", 0);    if (lines == NULL)        goto cleanup;    for (i = 0; lines[i]; i++) {        const char *line = lines[i];        if (line == NULL)            break;        cells = virStringSplit(line, " ", 0);        if (cells != NULL && virStringListLength(cells) > 2) {            if (virStorageBackendSheepdogAddVolume(conn, pool, cells[1]) < 0)                goto cleanup;        }        virStringFreeList(cells);        cells = NULL;    }    ret = 0; cleanup:    virCommandFree(cmd);    virStringFreeList(lines);    virStringFreeList(cells);    VIR_FREE(output);    return ret;}
开发者ID:6WIND,项目名称:libvirt,代码行数:45,


示例13: virStorageBackendSheepdogRefreshPool

static intvirStorageBackendSheepdogRefreshPool(virConnectPtr conn ATTRIBUTE_UNUSED,                                     virStoragePoolObjPtr pool){    int ret;    char *output = NULL;    virCommandPtr cmd;    cmd = virCommandNewArgList(COLLIE, "node", "info", "-r", NULL);    virStorageBackendSheepdogAddHostArg(cmd, pool);    virCommandSetOutputBuffer(cmd, &output);    ret = virCommandRun(cmd, NULL);    if (ret == 0)        ret = virStorageBackendSheepdogParseNodeInfo(pool->def, output);    virCommandFree(cmd);    VIR_FREE(output);    return ret;}
开发者ID:avdv,项目名称:libvirt,代码行数:19,


示例14: vzDoCmdRun

static intvzDoCmdRun(char **outbuf, const char *binary, va_list list){    virCommandPtr cmd = virCommandNewVAList(binary, list);    int ret = -1;    if (outbuf)        virCommandSetOutputBuffer(cmd, outbuf);    if (virCommandRun(cmd, NULL) < 0)        goto cleanup;    ret = 0; cleanup:    virCommandFree(cmd);    if (ret && outbuf)        VIR_FREE(*outbuf);    return ret;}
开发者ID:JGulic,项目名称:libvirt,代码行数:20,


示例15: openvzGetVEStatus

static intopenvzGetVEStatus(virDomainObjPtr vm, int *status, int *reason){    virCommandPtr cmd;    char *outbuf;    char *line;    int state;    int ret = -1;    cmd = virCommandNewArgList(VZLIST, vm->def->name, "-ostatus", "-H", NULL);    virCommandSetOutputBuffer(cmd, &outbuf);    if (virCommandRun(cmd, NULL) < 0)        goto cleanup;    if ((line = strchr(outbuf, '/n')) == NULL) {        openvzError(VIR_ERR_INTERNAL_ERROR, "%s",                    _("Failed to parse vzlist output"));        goto cleanup;    }    *line++ = '/0';    state = virDomainObjGetState(vm, reason);    if (STREQ(outbuf, "running")) {        /* There is no way to detect whether a domain is paused or not         * with vzlist */        if (state == VIR_DOMAIN_PAUSED)            *status = state;        else            *status = VIR_DOMAIN_RUNNING;    } else {        *status = VIR_DOMAIN_SHUTOFF;    }    ret = 0;cleanup:    virCommandFree(cmd);    VIR_FREE(outbuf);    return ret;}
开发者ID:coolsnow77,项目名称:libvirt,代码行数:41,


示例16: virNumaGetAutoPlacementAdvice

char *virNumaGetAutoPlacementAdvice(unsigned short vcpus,                              unsigned long long balloon){    virCommandPtr cmd = NULL;    char *output = NULL;    cmd = virCommandNewArgList(NUMAD, "-w", NULL);    virCommandAddArgFormat(cmd, "%d:%llu", vcpus,                           VIR_DIV_UP(balloon, 1024));    virCommandSetOutputBuffer(cmd, &output);    if (virCommandRun(cmd, NULL) < 0)        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",                       _("Failed to query numad for the "                         "advisory nodeset"));    virCommandFree(cmd);    return output;}
开发者ID:AGSaidi,项目名称:hacked-libvirt,代码行数:21,


示例17: qemuCapsProbeMachineTypes

intqemuCapsProbeMachineTypes(const char *binary,                          virCapsGuestMachinePtr **machines,                          int *nmachines){    char *output;    int ret = -1;    virCommandPtr cmd;    int status;    /* Make sure the binary we are about to try exec'ing exists.     * Technically we could catch the exec() failure, but that's     * in a sub-process so it's hard to feed back a useful error.     */    if (!virFileIsExecutable(binary)) {        virReportSystemError(errno, _("Cannot find QEMU binary %s"), binary);        return -1;    }    cmd = virCommandNewArgList(binary, "-M", "?", NULL);    virCommandAddEnvPassCommon(cmd);    virCommandSetOutputBuffer(cmd, &output);    virCommandClearCaps(cmd);    /* Ignore failure from older qemu that did not understand '-M ?'.  */    if (virCommandRun(cmd, &status) < 0)        goto cleanup;    if (qemuCapsParseMachineTypesStr(output, machines, nmachines) < 0)        goto cleanup;    ret = 0;cleanup:    VIR_FREE(output);    virCommandFree(cmd);    return ret;}
开发者ID:kthguru,项目名称:libvirt,代码行数:39,


示例18: vmwareExtractVersion

intvmwareExtractVersion(struct vmware_driver *driver){    unsigned long version = 0;    char *tmp;    int ret = -1;    virCommandPtr cmd;    char * outbuf = NULL;    const char * bin = (driver->type == TYPE_PLAYER) ? "vmplayer" : "vmware";    const char * pattern = (driver->type == TYPE_PLAYER) ?                "VMware Player " : "VMware Workstation ";    cmd = virCommandNewArgList(bin, "-v", NULL);    virCommandSetOutputBuffer(cmd, &outbuf);    if (virCommandRun(cmd, NULL) < 0)        goto cleanup;    if ((tmp = STRSKIP(outbuf, pattern)) == NULL) {        virReportError(VIR_ERR_INTERNAL_ERROR,                       _("failed to parse %s version"), bin);        goto cleanup;    }    if (virParseVersionString(tmp, &version, false) < 0) {        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",                       _("version parsing error"));        goto cleanup;    }    driver->version = version;    ret = 0;cleanup:    virCommandFree(cmd);    VIR_FREE(outbuf);    return ret;}
开发者ID:hzguanqiang,项目名称:libvirt,代码行数:38,


示例19: openvzExtractVersionInfo

static intopenvzExtractVersionInfo(const char *cmdstr, int *retversion){    int ret = -1;    unsigned long version;    char *help = NULL;    char *tmp;    virCommandPtr cmd = virCommandNewArgList(cmdstr, "--help", NULL);    if (retversion)        *retversion = 0;    virCommandAddEnvString(cmd, "LC_ALL=C");    virCommandSetOutputBuffer(cmd, &help);    if (virCommandRun(cmd, NULL) < 0)        goto cleanup;    tmp = help;    /* expected format: vzctl version <major>.<minor>.<micro> */    if ((tmp = STRSKIP(tmp, "vzctl version ")) == NULL)        goto cleanup;    if (virParseVersionString(tmp, &version, true) < 0)        goto cleanup;    if (retversion)        *retversion = version;    ret = 0;cleanup:    virCommandFree(cmd);    VIR_FREE(help);    return ret;}
开发者ID:mohankku,项目名称:libvirt,代码行数:38,


示例20: virHookCall

/** * virHookCall: * @driver: the driver number (from virHookDriver enum) * @id: an id for the object '-' if non available for example on daemon hooks * @op: the operation on the id e.g. VIR_HOOK_QEMU_OP_START * @sub_op: a sub_operation, currently unused * @extra: optional string information * @input: extra input given to the script on stdin * @output: optional address of variable to store malloced result buffer * * Implement a hook call, where the external script for the driver is * called with the given information. This is a synchronous call, we wait for * execution completion. If @output is non-NULL, *output is guaranteed to be * allocated after successful virHookCall, and is best-effort allocated after * failed virHookCall; the caller is responsible for freeing *output. * * Returns: 0 if the execution succeeded, 1 if the script was not found or *          invalid parameters, and -1 if script returned an error */intvirHookCall(int driver,            const char *id,            int op,            int sub_op,            const char *extra,            const char *input,            char **output){    int ret;    int exitstatus;    char *path;    virCommandPtr cmd;    const char *drvstr;    const char *opstr;    const char *subopstr;    if (output)        *output = NULL;    if ((driver < VIR_HOOK_DRIVER_DAEMON) ||        (driver >= VIR_HOOK_DRIVER_LAST))        return 1;    /*     * We cache the availability of the script to minimize impact at     * runtime if no script is defined, this is being reset on SIGHUP     */    if ((virHooksFound == -1) ||        ((driver == VIR_HOOK_DRIVER_DAEMON) &&         (op == VIR_HOOK_DAEMON_OP_RELOAD ||         op == VIR_HOOK_DAEMON_OP_SHUTDOWN)))        virHookInitialize();    if ((virHooksFound & (1 << driver)) == 0)        return 1;    drvstr = virHookDriverTypeToString(driver);    opstr = NULL;    switch (driver) {        case VIR_HOOK_DRIVER_DAEMON:            opstr = virHookDaemonOpTypeToString(op);            break;        case VIR_HOOK_DRIVER_QEMU:            opstr = virHookQemuOpTypeToString(op);            break;        case VIR_HOOK_DRIVER_LXC:            opstr = virHookLxcOpTypeToString(op);            break;    }    if (opstr == NULL) {        virHookReportError(VIR_ERR_INTERNAL_ERROR,                           _("Hook for %s, failed to find operation #%d"),                           drvstr, op);        return 1;    }    subopstr = virHookSubopTypeToString(sub_op);    if (subopstr == NULL)        subopstr = "-";    if (extra == NULL)        extra = "-";    ret = virBuildPath(&path, LIBVIRT_HOOK_DIR, drvstr);    if ((ret < 0) || (path == NULL)) {        virHookReportError(VIR_ERR_INTERNAL_ERROR,                           _("Failed to build path for %s hook"),                           drvstr);        return -1;    }    cmd = virCommandNewArgList(path, id, opstr, subopstr, extra, NULL);    virCommandAddEnvPassCommon(cmd);    if (input)        virCommandSetInputBuffer(cmd, input);    if (output)        virCommandSetOutputBuffer(cmd, output);    ret = virCommandRun(cmd, &exitstatus);//.........这里部分代码省略.........
开发者ID:foomango,项目名称:libvirt,代码行数:101,


示例21: testPrepImages

static inttestPrepImages(void){    int ret = EXIT_FAILURE;    virCommandPtr cmd = NULL;    char *buf = NULL;    bool compat = false;    qemuimg = virFindFileInPath("kvm-img");    if (!qemuimg)        qemuimg = virFindFileInPath("qemu-img");    if (!qemuimg)        goto skip;    /* Clean up from any earlier failed tests */    virFileDeleteTree(datadir);    /* See if qemu-img supports '-o compat=xxx'.  If so, we force the     * use of both v2 and v3 files; if not, it is v2 only but the test     * still works. */    cmd = virCommandNewArgList(qemuimg, "create", "-f", "qcow2",                               "-o?", "/dev/null", NULL);    virCommandSetOutputBuffer(cmd, &buf);    if (virCommandRun(cmd, NULL) < 0)        goto skip;    if (strstr(buf, "compat "))        compat = true;    VIR_FREE(buf);    if (virAsprintf(&absraw, "%s/raw", datadir) < 0 ||        virAsprintf(&absqcow2, "%s/qcow2", datadir) < 0 ||        virAsprintf(&abswrap, "%s/wrap", datadir) < 0 ||        virAsprintf(&absqed, "%s/qed", datadir) < 0 ||        virAsprintf(&absdir, "%s/dir", datadir) < 0 ||        virAsprintf(&abslink2, "%s/sub/link2", datadir) < 0)        goto cleanup;    if (virFileMakePath(datadir "/sub") < 0) {        fprintf(stderr, "unable to create directory %s/n", datadir "/sub");        goto cleanup;    }    if (virFileMakePath(datadir "/dir") < 0) {        fprintf(stderr, "unable to create directory %s/n", datadir "/dir");        goto cleanup;    }    if (!(canondir = canonicalize_file_name(absdir))) {        virReportOOMError();        goto cleanup;    }    if (chdir(datadir) < 0) {        fprintf(stderr, "unable to test relative backing chains/n");        goto cleanup;    }    if (virAsprintf(&buf, "%1024d", 0) < 0 ||        virFileWriteStr("raw", buf, 0600) < 0) {        fprintf(stderr, "unable to create raw file/n");        goto cleanup;    }    if (!(canonraw = canonicalize_file_name(absraw))) {        virReportOOMError();        goto cleanup;    }    /* Create a qcow2 wrapping relative raw; later on, we modify its     * metadata to test other configurations */    virCommandFree(cmd);    cmd = virCommandNewArgList(qemuimg, "create", "-f", "qcow2", NULL);    virCommandAddArgFormat(cmd, "-obacking_file=raw,backing_fmt=raw%s",                           compat ? ",compat=0.10" : "");    virCommandAddArg(cmd, "qcow2");    if (virCommandRun(cmd, NULL) < 0)        goto skip;    /* Make sure our later uses of 'qemu-img rebase' will work */    virCommandFree(cmd);    cmd = virCommandNewArgList(qemuimg, "rebase", "-u", "-f", "qcow2",                               "-F", "raw", "-b", "raw", "qcow2", NULL);    if (virCommandRun(cmd, NULL) < 0)        goto skip;    if (!(canonqcow2 = canonicalize_file_name(absqcow2))) {        virReportOOMError();        goto cleanup;    }    /* Create a second qcow2 wrapping the first, to be sure that we     * can correctly avoid insecure probing.  */    virCommandFree(cmd);    cmd = virCommandNewArgList(qemuimg, "create", "-f", "qcow2", NULL);    virCommandAddArgFormat(cmd, "-obacking_file=%s,backing_fmt=qcow2%s",                           absqcow2, compat ? ",compat=1.1" : "");    virCommandAddArg(cmd, "wrap");    if (virCommandRun(cmd, NULL) < 0)        goto skip;    if (!(canonwrap = canonicalize_file_name(abswrap))) {        virReportOOMError();        goto cleanup;    }    /* Create a qed file. *///.........这里部分代码省略.........
开发者ID:CLisa,项目名称:libvirt,代码行数:101,


示例22: virHookCall

//.........这里部分代码省略......... * Returns: 0 if the execution succeeded, 1 if the script was not found or *          invalid parameters, and -1 if script returned an error */intvirHookCall(int driver,            const char *id,            int op,            int sub_op,            const char *extra,            const char *input,            char **output){    int ret;    char *path;    virCommandPtr cmd;    const char *drvstr;    const char *opstr;    const char *subopstr;    if (output)        *output = NULL;    if ((driver < VIR_HOOK_DRIVER_DAEMON) ||        (driver >= VIR_HOOK_DRIVER_LAST))        return 1;    /*     * We cache the availability of the script to minimize impact at     * runtime if no script is defined, this is being reset on SIGHUP     */    if ((virHooksFound == -1) ||        ((driver == VIR_HOOK_DRIVER_DAEMON) &&         (op == VIR_HOOK_DAEMON_OP_RELOAD ||         op == VIR_HOOK_DAEMON_OP_SHUTDOWN)))        virHookInitialize();    if ((virHooksFound & (1 << driver)) == 0)        return 1;    drvstr = virHookDriverTypeToString(driver);    opstr = NULL;    switch (driver) {        case VIR_HOOK_DRIVER_DAEMON:            opstr = virHookDaemonOpTypeToString(op);            break;        case VIR_HOOK_DRIVER_QEMU:            opstr = virHookQemuOpTypeToString(op);            break;        case VIR_HOOK_DRIVER_LXC:            opstr = virHookLxcOpTypeToString(op);            break;        case VIR_HOOK_DRIVER_NETWORK:            opstr = virHookNetworkOpTypeToString(op);    }    if (opstr == NULL) {        virReportError(VIR_ERR_INTERNAL_ERROR,                       _("Hook for %s, failed to find operation #%d"),                       drvstr, op);        return 1;    }    subopstr = virHookSubopTypeToString(sub_op);    if (subopstr == NULL)        subopstr = "-";    if (extra == NULL)        extra = "-";    if (virBuildPath(&path, LIBVIRT_HOOK_DIR, drvstr) < 0) {        virReportError(VIR_ERR_INTERNAL_ERROR,                       _("Failed to build path for %s hook"),                       drvstr);        return -1;    }    VIR_DEBUG("Calling hook opstr=%s subopstr=%s extra=%s",              opstr, subopstr, extra);    cmd = virCommandNewArgList(path, id, opstr, subopstr, extra, NULL);    virCommandAddEnvPassCommon(cmd);    if (input)        virCommandSetInputBuffer(cmd, input);    if (output)        virCommandSetOutputBuffer(cmd, output);    ret = virCommandRun(cmd, NULL);    if (ret < 0) {        /* Convert INTERNAL_ERROR into known error.  */        virErrorPtr err = virGetLastError();        virReportError(VIR_ERR_HOOK_SCRIPT_FAILED, "%s",                       err ? err->message : _("unknown error"));    }    virCommandFree(cmd);    VIR_FREE(path);    return ret;}
开发者ID:FrankYu,项目名称:libvirt,代码行数:101,


示例23: vmwareLoadDomains

intvmwareLoadDomains(struct vmware_driver *driver){    virDomainDefPtr vmdef = NULL;    virDomainObjPtr vm = NULL;    char *vmxPath = NULL;    char *vmx = NULL;    vmwareDomainPtr pDomain;    char *directoryName = NULL;    char *fileName = NULL;    int ret = -1;    virVMXContext ctx;    char *outbuf = NULL;    char *str;    char *saveptr = NULL;    virCommandPtr cmd;    ctx.parseFileName = vmwareCopyVMXFileName;    cmd = virCommandNewArgList(VMRUN, "-T",                               driver->type == TYPE_PLAYER ? "player" : "ws",                               "list", NULL);    virCommandSetOutputBuffer(cmd, &outbuf);    if (virCommandRun(cmd, NULL) < 0)        goto cleanup;    for (str = outbuf; (vmxPath = strtok_r(str, "/n", &saveptr)) != NULL;        str = NULL) {        if (vmxPath[0] != '/')            continue;        if (virFileReadAll(vmxPath, 10000, &vmx) < 0)            goto cleanup;        if ((vmdef =             virVMXParseConfig(&ctx, driver->xmlopt, vmx)) == NULL) {            goto cleanup;        }        if (!(vm = virDomainObjListAdd(driver->domains, vmdef,                                       driver->xmlopt,                                       0, NULL)))            goto cleanup;        pDomain = vm->privateData;        if (VIR_STRDUP(pDomain->vmxPath, vmxPath) < 0)            goto cleanup;        vmwareDomainConfigDisplay(pDomain, vmdef);        if ((vm->def->id = vmwareExtractPid(vmxPath)) < 0)            goto cleanup;        /* vmrun list only reports running vms */        virDomainObjSetState(vm, VIR_DOMAIN_RUNNING,                             VIR_DOMAIN_RUNNING_UNKNOWN);        vm->persistent = 1;        virObjectUnlock(vm);        vmdef = NULL;        vm = NULL;    }    ret = 0;cleanup:    virCommandFree(cmd);    VIR_FREE(outbuf);    virDomainDefFree(vmdef);    VIR_FREE(directoryName);    VIR_FREE(fileName);    VIR_FREE(vmx);    virObjectUnref(vm);    return ret;}
开发者ID:hzguanqiang,项目名称:libvirt,代码行数:77,


示例24: dnsmasqCapsRefreshInternal

static intdnsmasqCapsRefreshInternal(dnsmasqCapsPtr caps, bool force){    int ret = -1;    struct stat sb;    virCommandPtr cmd = NULL;    char *help = NULL, *version = NULL, *complete = NULL;    if (!caps || caps->noRefresh)        return 0;    if (stat(caps->binaryPath, &sb) < 0) {        virReportSystemError(errno, _("Cannot check dnsmasq binary %s"),                             caps->binaryPath);        return -1;    }    if (!force && caps->mtime == sb.st_mtime)        return 0;    caps->mtime = sb.st_mtime;    /* Make sure the binary we are about to try exec'ing exists.     * Technically we could catch the exec() failure, but that's     * in a sub-process so it's hard to feed back a useful error.     */    if (!virFileIsExecutable(caps->binaryPath)) {        virReportSystemError(errno, _("dnsmasq binary %s is not executable"),                             caps->binaryPath);        goto cleanup;    }    cmd = virCommandNewArgList(caps->binaryPath, "--version", NULL);    virCommandSetOutputBuffer(cmd, &version);    virCommandAddEnvPassCommon(cmd);    virCommandClearCaps(cmd);    if (virCommandRun(cmd, NULL) < 0) {        virReportSystemError(errno, _("failed to run '%s --version': %s"),                             caps->binaryPath, version);        goto cleanup;    }    virCommandFree(cmd);    cmd = virCommandNewArgList(caps->binaryPath, "--help", NULL);    virCommandSetOutputBuffer(cmd, &help);    virCommandAddEnvPassCommon(cmd);    virCommandClearCaps(cmd);    if (virCommandRun(cmd, NULL) < 0) {        virReportSystemError(errno, _("failed to run '%s --help': %s"),                             caps->binaryPath, help);        goto cleanup;    }    if (virAsprintf(&complete, "%s/n%s", version, help) < 0)        goto cleanup;    ret = dnsmasqCapsSetFromBuffer(caps, complete); cleanup:    virCommandFree(cmd);    VIR_FREE(help);    VIR_FREE(version);    VIR_FREE(complete);    return ret;}
开发者ID:Archer-sys,项目名称:libvirt,代码行数:63,


示例25: openvzLoadDomains

int openvzLoadDomains(struct openvz_driver *driver){    int veid, ret;    char *status;    char uuidstr[VIR_UUID_STRING_BUFLEN];    virDomainObjPtr dom = NULL;    virDomainDefPtr def = NULL;    char *temp = NULL;    char *outbuf = NULL;    char *line;    virCommandPtr cmd = NULL;    unsigned int vcpus = 0;    if (openvzAssignUUIDs() < 0)        return -1;    cmd = virCommandNewArgList(VZLIST, "-a", "-ovpsid,status", "-H", NULL);    virCommandSetOutputBuffer(cmd, &outbuf);    if (virCommandRun(cmd, NULL) < 0)        goto cleanup;    line = outbuf;    while (line[0] != '/0') {        unsigned int flags = 0;        if (virStrToLong_i(line, &status, 10, &veid) < 0 ||            *status++ != ' ' ||            (line = strchr(status, '/n')) == NULL) {            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",                           _("Failed to parse vzlist output"));            goto cleanup;        }        *line++ = '/0';        if (!(def = virDomainDefNew()))            goto cleanup;        def->virtType = VIR_DOMAIN_VIRT_OPENVZ;        if (STREQ(status, "stopped"))            def->id = -1;        else            def->id = veid;        if (virAsprintf(&def->name, "%i", veid) < 0)            goto cleanup;        openvzGetVPSUUID(veid, uuidstr, sizeof(uuidstr));        ret = virUUIDParse(uuidstr, def->uuid);        if (ret == -1) {            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",                           _("UUID in config file malformed"));            goto cleanup;        }        def->os.type = VIR_DOMAIN_OSTYPE_EXE;        if (VIR_STRDUP(def->os.init, "/sbin/init") < 0)            goto cleanup;        ret = openvzReadVPSConfigParam(veid, "CPUS", &temp);        if (ret < 0) {            virReportError(VIR_ERR_INTERNAL_ERROR,                           _("Could not read config for container %d"),                           veid);            goto cleanup;        } else if (ret > 0) {            vcpus = strtoI(temp);        }        if (ret == 0 || vcpus == 0)            vcpus = openvzGetNodeCPUs();        def->maxvcpus = vcpus;        def->vcpus = vcpus;        /* XXX load rest of VM config data .... */        openvzReadNetworkConf(def, veid);        openvzReadFSConf(def, veid);        openvzReadMemConf(def, veid);        virUUIDFormat(def->uuid, uuidstr);        flags = VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE;        if (STRNEQ(status, "stopped"))            flags |= VIR_DOMAIN_OBJ_LIST_ADD_LIVE;        if (!(dom = virDomainObjListAdd(driver->domains,                                        def,                                        driver->xmlopt,                                        flags,                                        NULL)))            goto cleanup;        if (STREQ(status, "stopped")) {            virDomainObjSetState(dom, VIR_DOMAIN_SHUTOFF,                                 VIR_DOMAIN_SHUTOFF_UNKNOWN);            dom->pid = -1;        } else {            virDomainObjSetState(dom, VIR_DOMAIN_RUNNING,                                 VIR_DOMAIN_RUNNING_UNKNOWN);            dom->pid = veid;//.........这里部分代码省略.........
开发者ID:noxdafox,项目名称:libvirt,代码行数:101,


示例26: virStorageBackendZFSRefreshPool

static intvirStorageBackendZFSRefreshPool(virConnectPtr conn ATTRIBUTE_UNUSED,                                virStoragePoolObjPtr pool ATTRIBUTE_UNUSED){    virCommandPtr cmd = NULL;    char *zpool_props = NULL;    char **lines = NULL;    char **tokens = NULL;    size_t i;    /**     * $ zpool get -Hp health,size,free,allocated test     * test    health  ONLINE  -     * test    size    199715979264    -     * test    free    198899976704    -     * test    allocated       816002560       -     * $     *     * Here we just provide a list of properties we want to see     */    cmd = virCommandNewArgList(ZPOOL,                               "get", "-Hp",                               "health,size,free,allocated",                               pool->def->source.name,                               NULL);    virCommandSetOutputBuffer(cmd, &zpool_props);    if (virCommandRun(cmd, NULL) < 0)        goto cleanup;    if (!(lines = virStringSplit(zpool_props, "/n", 0)))        goto cleanup;    for (i = 0; lines[i]; i++) {        size_t count;        char *prop_name;        if (STREQ(lines[i], ""))            continue;        virStringFreeList(tokens);        if (!(tokens = virStringSplitCount(lines[i], "/t", 0, &count)))            goto cleanup;        if (count != 4)            continue;        prop_name = tokens[1];        if (STREQ(prop_name, "free") || STREQ(prop_name, "size") ||            STREQ(prop_name, "allocated")) {            unsigned long long value;            if (virStrToLong_ull(tokens[2], NULL, 10, &value) < 0)                goto cleanup;            if (STREQ(prop_name, "free"))                pool->def->available = value;            else if (STREQ(prop_name, "size"))                pool->def->capacity = value;            else if (STREQ(prop_name, "allocated"))                pool->def->allocation = value;        }    }    /* Obtain a list of volumes */    if (virStorageBackendZFSFindVols(pool, NULL) < 0)        goto cleanup; cleanup:    virCommandFree(cmd);    virStringFreeList(lines);    virStringFreeList(tokens);    VIR_FREE(zpool_props);    return 0;}
开发者ID:vtolstov,项目名称:libvirt,代码行数:75,



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


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