这篇教程C++ virBufferFreeAndReset函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中virBufferFreeAndReset函数的典型用法代码示例。如果您正苦于以下问题:C++ virBufferFreeAndReset函数的具体用法?C++ virBufferFreeAndReset怎么用?C++ virBufferFreeAndReset使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了virBufferFreeAndReset函数的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: virBitmapNextSetBit/** * virBitmapFormat: * @bitmap: the bitmap * * This function is the counterpart of virBitmapParse. This function creates * a human-readable string representing the bits in bitmap. * * See virBitmapParse for the format of @str. * * Returns the string on success or NULL otherwise. Caller should call * VIR_FREE to free the string. */char *virBitmapFormat(virBitmapPtr bitmap){ virBuffer buf = VIR_BUFFER_INITIALIZER; bool first = true; int start, cur, prev; if (!bitmap) return NULL; cur = virBitmapNextSetBit(bitmap, -1); if (cur < 0) return strdup(""); start = prev = cur; while (prev >= 0) { cur = virBitmapNextSetBit(bitmap, prev); if (cur == prev + 1) { prev = cur; continue; } /* cur < 0 or cur > prev + 1 */ if (!first) virBufferAddLit(&buf, ","); else first = false; if (prev == start) virBufferAsprintf(&buf, "%d", start); else virBufferAsprintf(&buf, "%d-%d", start, prev); start = prev = cur; } if (virBufferError(&buf)) { virBufferFreeAndReset(&buf); return NULL; } return virBufferContentAndReset(&buf);}
开发者ID:xushiwei,项目名称:libvirt,代码行数:56,
示例2: ignore_value/** * virBitmapFormat: * @bitmap: the bitmap * * This function is the counterpart of virBitmapParse. This function creates * a human-readable string representing the bits in bitmap. * * See virBitmapParse for the format of @str. * * If bitmap is NULL or it has no bits set, an empty string is returned. * * Returns the string on success or NULL otherwise. Caller should call * VIR_FREE to free the string. */char *virBitmapFormat(virBitmapPtr bitmap){ virBuffer buf = VIR_BUFFER_INITIALIZER; bool first = true; int start, cur, prev; if (!bitmap || (cur = virBitmapNextSetBit(bitmap, -1)) < 0) { char *ret; ignore_value(VIR_STRDUP(ret, "")); return ret; } start = prev = cur; while (prev >= 0) { cur = virBitmapNextSetBit(bitmap, prev); if (cur == prev + 1) { prev = cur; continue; } /* cur < 0 or cur > prev + 1 */ if (!first) virBufferAddLit(&buf, ","); else first = false; if (prev == start) virBufferAsprintf(&buf, "%d", start); else virBufferAsprintf(&buf, "%d-%d", start, prev); start = prev = cur; } if (virBufferError(&buf)) { virBufferFreeAndReset(&buf); virReportOOMError(); return NULL; } return virBufferContentAndReset(&buf);}
开发者ID:carriercomm,项目名称:libvirt-1,代码行数:58,
示例3: virQEMUBuildDriveCommandlineFromJSONchar *virQEMUBuildDriveCommandlineFromJSON(virJSONValuePtr srcdef){ virBuffer buf = VIR_BUFFER_INITIALIZER; char *ret = NULL; if (virQEMUBuildCommandLineJSON(srcdef, &buf, virQEMUBuildCommandLineJSONArrayNumbered) < 0) goto cleanup; if (virBufferCheckError(&buf) < 0) goto cleanup; ret = virBufferContentAndReset(&buf); cleanup: virBufferFreeAndReset(&buf); return ret;}
开发者ID:MountainWei,项目名称:libvirt,代码行数:19,
示例4: testCgroupDetectMountsstatic inttestCgroupDetectMounts(const void *args){ int result = -1; const char *file = args; char *mounts = NULL; char *parsed = NULL; const char *actual; virCgroupPtr group = NULL; virBuffer buf = VIR_BUFFER_INITIALIZER; size_t i; if (virAsprintf(&mounts, "%s/vircgroupdata/%s.mounts", abs_srcdir, file) < 0 || virAsprintf(&parsed, "%s/vircgroupdata/%s.parsed", abs_srcdir, file) < 0 || VIR_ALLOC(group) < 0) goto cleanup; if (virCgroupDetectMountsFromFile(group, mounts, false) < 0) goto cleanup; for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { virBufferAsprintf(&buf, "%-12s %s/n", virCgroupControllerTypeToString(i), NULLSTR(group->controllers[i].mountPoint)); } if (virBufferCheckError(&buf) < 0) goto cleanup; actual = virBufferCurrentContent(&buf); if (virtTestCompareToFile(actual, parsed) < 0) goto cleanup; result = 0; cleanup: VIR_FREE(mounts); VIR_FREE(parsed); virCgroupFree(&group); virBufferFreeAndReset(&buf); return result;}
开发者ID:candhare,项目名称:libvirt,代码行数:43,
示例5: virCPUDefFormatchar *virCPUDefFormat(virCPUDefPtr def, unsigned int flags){ virBuffer buf = VIR_BUFFER_INITIALIZER; if (virCPUDefFormatBufFull(&buf, def, flags) < 0) goto cleanup; if (virBufferError(&buf)) goto no_memory; return virBufferContentAndReset(&buf);no_memory: virReportOOMError();cleanup: virBufferFreeAndReset(&buf); return NULL;}
开发者ID:rmarwaha,项目名称:libvirt1,代码行数:20,
示例6: virConfWriteFile/** * virConfWriteFile: * @filename: the path to the configuration file. * @conf: the conf * * Writes a configuration file back to a file. * * Returns the number of bytes written or -1 in case of error. */intvirConfWriteFile(const char *filename, virConfPtr conf){ virBuffer buf = VIR_BUFFER_INITIALIZER; virConfEntryPtr cur; int ret; int fd; char *content; unsigned int use; if (conf == NULL) return -1; cur = conf->entries; while (cur != NULL) { virConfSaveEntry(&buf, cur); cur = cur->next; } if (virBufferCheckError(&buf) < 0) return -1; fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); if (fd < 0) { virBufferFreeAndReset(&buf); virConfError(NULL, VIR_ERR_WRITE_FAILED, _("failed to open file")); return -1; } use = virBufferUse(&buf); content = virBufferContentAndReset(&buf); ret = safewrite(fd, content, use); VIR_FREE(content); VIR_FORCE_CLOSE(fd); if (ret != (int)use) { virConfError(NULL, VIR_ERR_WRITE_FAILED, _("failed to save content")); return -1; } return ret;}
开发者ID:JGulic,项目名称:libvirt,代码行数:50,
示例7: dnsmasqDhcpHostsToString/** dnsmasqDhcpHostsToString: * * Turns a vector of dnsmasqDhcpHost into the string that is ought to be * stored in the hostsfile, this functionality is split to make hostsfiles * testable. Returs NULL if nhosts is 0. */char *dnsmasqDhcpHostsToString (dnsmasqDhcpHost *hosts, unsigned int nhosts){ int i; char *result = NULL; virBuffer hostsfilebuf = VIR_BUFFER_INITIALIZER; if (nhosts == 0) goto cleanup; for (i = 0; i < nhosts; i++) { virBufferAsprintf(&hostsfilebuf, "%s/n", hosts[i].host); } result = virBufferContentAndReset(&hostsfilebuf);cleanup: virBufferFreeAndReset(&hostsfilebuf); return result;}
开发者ID:aruiz,项目名称:libvirt,代码行数:27,
示例8: virBufferAddLit/** * virBitmapString: * @bitmap: Pointer to bitmap * * Convert @bitmap to printable string. * * Returns pointer to the string or NULL on error. */char *virBitmapString(virBitmapPtr bitmap){ virBuffer buf = VIR_BUFFER_INITIALIZER; size_t sz; virBufferAddLit(&buf, "0x"); sz = bitmap->map_len; while (sz--) { virBufferAsprintf(&buf, "%0*lx", VIR_BITMAP_BITS_PER_UNIT / 4, bitmap->map[sz]); } if (virBufferError(&buf)) { virBufferFreeAndReset(&buf); return NULL; } return virBufferContentAndReset(&buf);}
开发者ID:carriercomm,项目名称:libvirt-1,代码行数:30,
示例9: testSysinfostatic inttestSysinfo(const void *data){ int result = -1; char *sysfsExpectData = NULL; const char *sysfsActualData; virSysinfoDefPtr ret = NULL; virBuffer buf = VIR_BUFFER_INITIALIZER; const struct testSysinfoData *testdata = data; virSysinfoSetup(testdata->decoder, testdata->sysinfo, testdata->cpuinfo); if (!testdata->expected || virtTestLoadFile(testdata->expected, &sysfsExpectData) < 0 || !(ret = virSysinfoRead())) { goto cleanup; } if (virSysinfoFormat(&buf,ret) < 0) goto cleanup; if (!(sysfsActualData = virBufferCurrentContent(&buf))) goto cleanup; if (STRNEQ(sysfsActualData, sysfsExpectData)) { virtTestDifference(stderr, sysfsActualData, sysfsExpectData); goto cleanup; } result = 0;cleanup: VIR_FREE(sysfsExpectData); virSysinfoDefFree(ret); virBufferFreeAndReset(&buf); return result;}
开发者ID:cardoe,项目名称:libvirt,代码行数:38,
示例10: virQEMUBuildObjectCommandlineFromJSONchar *virQEMUBuildObjectCommandlineFromJSON(const char *type, const char *alias, virJSONValuePtr props){ virBuffer buf = VIR_BUFFER_INITIALIZER; char *ret = NULL; virBufferAsprintf(&buf, "%s,id=%s,", type, alias); if (virQEMUBuildCommandLineJSON(props, &buf, virQEMUBuildCommandLineJSONArrayBitmap) < 0) goto cleanup; if (virBufferCheckError(&buf) < 0) goto cleanup; ret = virBufferContentAndReset(&buf); cleanup: virBufferFreeAndReset(&buf); return ret;}
开发者ID:MountainWei,项目名称:libvirt,代码行数:23,
示例11: qparam_get_querychar *qparam_get_query (const struct qparam_set *ps){ virBuffer buf = VIR_BUFFER_INITIALIZER; int i, amp = 0; for (i = 0; i < ps->n; ++i) { if (!ps->p[i].ignore) { if (amp) virBufferAddChar (&buf, '&'); virBufferStrcat (&buf, ps->p[i].name, "=", NULL); virBufferURIEncodeString (&buf, ps->p[i].value); amp = 1; } } if (virBufferError(&buf)) { virBufferFreeAndReset(&buf); virReportOOMError(); return NULL; } return virBufferContentAndReset(&buf);}
开发者ID:kthguru,项目名称:libvirt,代码行数:23,
示例12: testCompareXMLToArgvFilesstatic int testCompareXMLToArgvFiles(const char *xml, const char *cmdline){ char *expectargv = NULL; char *actualargv = NULL; virBuffer buf = VIR_BUFFER_INITIALIZER; virNetworkDefPtr def = NULL; int ret = -1; virCommandSetDryRun(&buf, NULL, NULL); if (!(def = virNetworkDefParseFile(xml))) goto cleanup; if (networkAddFirewallRules(def) < 0) goto cleanup; if (virBufferError(&buf)) goto cleanup; actualargv = virBufferContentAndReset(&buf); virTestClearCommandPath(actualargv); virCommandSetDryRun(NULL, NULL, NULL); if (virTestCompareToFile(actualargv, cmdline) < 0) goto cleanup; ret = 0; cleanup: virBufferFreeAndReset(&buf); VIR_FREE(expectargv); VIR_FREE(actualargv); virNetworkDefFree(def); return ret;}
开发者ID:Archer-sys,项目名称:libvirt,代码行数:36,
示例13: virCommandToString/* * Call after adding all arguments and environment settings, but before * Run/RunAsync, to return a string representation of the environment and * arguments of cmd. If virCommandRun cannot succeed (because of an * out-of-memory condition while building cmd), NULL will be returned. * Caller is responsible for freeing the resulting string. */char *virCommandToString(virCommandPtr cmd){ size_t i; virBuffer buf = VIR_BUFFER_INITIALIZER; /* Cannot assume virCommandRun will be called; so report the error * now. If virCommandRun is called, it will report the same error. */ if (!cmd ||cmd->has_error == ENOMEM) { virReportOOMError(); return NULL; } if (cmd->has_error) { virCommandError(VIR_ERR_INTERNAL_ERROR, "%s", _("invalid use of command API")); return NULL; } for (i = 0; i < cmd->nenv; i++) { virBufferAdd(&buf, cmd->env[i], strlen(cmd->env[i])); virBufferAddChar(&buf, ' '); } virBufferAdd(&buf, cmd->args[0], strlen(cmd->args[0])); for (i = 1; i < cmd->nargs; i++) { virBufferAddChar(&buf, ' '); virBufferAdd(&buf, cmd->args[i], strlen(cmd->args[i])); } if (virBufferError(&buf)) { virBufferFreeAndReset(&buf); virReportOOMError(); return NULL; } return virBufferContentAndReset(&buf);}
开发者ID:rbu,项目名称:libvirt,代码行数:43,
示例14: virConfWriteMem/** * virConfWriteMem: * @memory: pointer to the memory to store the config file * @len: pointer to the length in bytes of the store, on output the size * @conf: the conf * * Writes a configuration file back to a memory area. @len is an IN/OUT * parameter, it indicates the size available in bytes, and on output the * size required for the configuration file (even if the call fails due to * insufficient space). * * Returns the number of bytes written or -1 in case of error. */intvirConfWriteMem(char *memory, int *len, virConfPtr conf){ virBuffer buf = VIR_BUFFER_INITIALIZER; virConfEntryPtr cur; char *content; unsigned int use; if ((memory == NULL) || (len == NULL) || (*len <= 0) || (conf == NULL)) return -1; cur = conf->entries; while (cur != NULL) { virConfSaveEntry(&buf, cur); cur = cur->next; } if (virBufferError(&buf)) { virBufferFreeAndReset(&buf); virReportOOMError(); return -1; } use = virBufferUse(&buf); content = virBufferContentAndReset(&buf); if ((int)use >= *len) { *len = (int)use; VIR_FREE(content); return -1; } memcpy(memory, content, use); VIR_FREE(content); *len = use; return use;}
开发者ID:i-ninth,项目名称:libvirt,代码行数:49,
示例15: virBufferAddLit//.........这里部分代码省略......... virBufferAddLit(&buf, " </capability>/n"); } if (data->scsi_host.flags & VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS) { virBufferAddLit(&buf, " <capability type='vport_ops' />/n"); } break; case VIR_NODE_DEV_CAP_SCSI_TARGET: virBufferEscapeString(&buf, " <target>%s</target>/n", data->scsi_target.name); break; case VIR_NODE_DEV_CAP_SCSI: virBufferVSprintf(&buf, " <host>%d</host>/n", data->scsi.host); virBufferVSprintf(&buf, " <bus>%d</bus>/n", data->scsi.bus); virBufferVSprintf(&buf, " <target>%d</target>/n", data->scsi.target); virBufferVSprintf(&buf, " <lun>%d</lun>/n", data->scsi.lun); if (data->scsi.type) virBufferEscapeString(&buf, " <type>%s</type>/n", data->scsi.type); break; case VIR_NODE_DEV_CAP_STORAGE: virBufferEscapeString(&buf, " <block>%s</block>/n", data->storage.block); if (data->storage.bus) virBufferEscapeString(&buf, " <bus>%s</bus>/n", data->storage.bus); if (data->storage.drive_type) virBufferEscapeString(&buf, " <drive_type>%s</drive_type>/n", data->storage.drive_type); if (data->storage.model) virBufferEscapeString(&buf, " <model>%s</model>/n", data->storage.model); if (data->storage.vendor) virBufferEscapeString(&buf, " <vendor>%s</vendor>/n", data->storage.vendor); if (data->storage.serial) virBufferVSprintf(&buf, " <serial>%s</serial>/n", data->storage.serial); if (data->storage.flags & VIR_NODE_DEV_CAP_STORAGE_REMOVABLE) { int avl = data->storage.flags & VIR_NODE_DEV_CAP_STORAGE_REMOVABLE_MEDIA_AVAILABLE; virBufferAddLit(&buf, " <capability type='removable'>/n"); virBufferVSprintf(&buf, " <media_available>%d" "</media_available>/n", avl ? 1 : 0); virBufferVSprintf(&buf, " <media_size>%llu</media_size>/n", data->storage.removable_media_size); if (data->storage.media_label) virBufferEscapeString(&buf, " <media_label>%s</media_label>/n", data->storage.media_label); if (data->storage.logical_block_size > 0) virBufferVSprintf(&buf, " <logical_block_size>%llu" "</logical_block_size>/n", data->storage.logical_block_size); if (data->storage.num_blocks > 0) virBufferVSprintf(&buf, " <num_blocks>%llu</num_blocks>/n", data->storage.num_blocks); virBufferAddLit(&buf, " </capability>/n"); } else { virBufferVSprintf(&buf, " <size>%llu</size>/n", data->storage.size); if (data->storage.logical_block_size > 0) virBufferVSprintf(&buf, " <logical_block_size>%llu" "</logical_block_size>/n", data->storage.logical_block_size); if (data->storage.num_blocks > 0) virBufferVSprintf(&buf, " <num_blocks>%llu</num_blocks>/n", data->storage.num_blocks); } if (data->storage.flags & VIR_NODE_DEV_CAP_STORAGE_HOTPLUGGABLE) virBufferAddLit(&buf, " <capability type='hotpluggable' />/n"); break; case VIR_NODE_DEV_CAP_LAST: /* ignore special LAST value */ break; } virBufferAddLit(&buf, " </capability>/n"); } virBufferAddLit(&buf, "</device>/n"); if (virBufferError(&buf)) goto no_memory; return virBufferContentAndReset(&buf); no_memory: virReportOOMError(); virBufferFreeAndReset(&buf); return NULL;}
开发者ID:hjwsm1989,项目名称:libvirt,代码行数:101,
示例16: linuxCPUStatsCompareFilesstatic intlinuxCPUStatsCompareFiles(const char *cpustatfile, size_t ncpus, const char *outfile){ int ret = -1; char *actualData = NULL; char *expectData = NULL; FILE *cpustat = NULL; virNodeCPUStatsPtr params = NULL; virBuffer buf = VIR_BUFFER_INITIALIZER; size_t i; int nparams = 0; if (virtTestLoadFile(outfile, &expectData) < 0) goto fail; if (!(cpustat = fopen(cpustatfile, "r"))) { virReportSystemError(errno, "failed to open '%s': ", cpustatfile); goto fail; } if (linuxNodeGetCPUStats(NULL, 0, NULL, &nparams) < 0) goto fail; if (VIR_ALLOC_N(params, nparams) < 0) goto fail; if (linuxNodeGetCPUStats(cpustat, VIR_NODE_CPU_STATS_ALL_CPUS, params, &nparams) < 0) goto fail; if (linuxCPUStatsToBuf(&buf, VIR_NODE_CPU_STATS_ALL_CPUS, params, nparams) < 0) goto fail; for (i = 0; i < ncpus; i++) { if (linuxNodeGetCPUStats(cpustat, i, params, &nparams) < 0) goto fail; if (linuxCPUStatsToBuf(&buf, i, params, nparams) < 0) goto fail; } if (!(actualData = virBufferContentAndReset(&buf))) { virReportOOMError(); goto fail; } if (STRNEQ(actualData, expectData)) { virtTestDifference(stderr, expectData, actualData); goto fail; } ret = 0; fail: virBufferFreeAndReset(&buf); VIR_FORCE_FCLOSE(cpustat); VIR_FREE(expectData); VIR_FREE(actualData); VIR_FREE(params); return ret;}
开发者ID:SvenDowideit,项目名称:clearlinux,代码行数:63,
示例17: virStorageBackendRBDOpenRADOSConn//.........这里部分代码省略......... if (secret == NULL) { virReportError(VIR_ERR_NO_SECRET, "%s", _("failed to find the secret")); goto cleanup; } secret_value = virSecretGetValue(secret, &secret_value_size, 0); base64_encode_alloc((char *)secret_value, secret_value_size, &rados_key); memset(secret_value, 0, secret_value_size); if (rados_key == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("failed to decode the RADOS key")); goto cleanup; } VIR_DEBUG("Found cephx key: %s", rados_key); if (rados_conf_set(ptr->cluster, "key", rados_key) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("failed to set RADOS option: %s"), "rados_key"); goto cleanup; } memset(rados_key, 0, strlen(rados_key)); if (rados_conf_set(ptr->cluster, "auth_supported", "cephx") < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("failed to set RADOS option: %s"), "auth_supported"); goto cleanup; } } else { VIR_DEBUG("Not using cephx authorization"); if (rados_create(&ptr->cluster, NULL) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("failed to create the RADOS cluster")); goto cleanup; } if (rados_conf_set(ptr->cluster, "auth_supported", "none") < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("failed to set RADOS option: %s"), "auth_supported"); goto cleanup; } } VIR_DEBUG("Found %zu RADOS cluster monitors in the pool configuration", pool->def->source.nhost); for (i = 0; i < pool->def->source.nhost; i++) { if (pool->def->source.hosts[i].name != NULL && !pool->def->source.hosts[i].port) { virBufferAsprintf(&mon_host, "%s:6789,", pool->def->source.hosts[i].name); } else if (pool->def->source.hosts[i].name != NULL && pool->def->source.hosts[i].port) { virBufferAsprintf(&mon_host, "%s:%d,", pool->def->source.hosts[i].name, pool->def->source.hosts[i].port); } else { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("received malformed monitor, check the XML definition")); } } if (virBufferError(&mon_host)) { virReportOOMError(); goto cleanup; } mon_buff = virBufferContentAndReset(&mon_host); VIR_DEBUG("RADOS mon_host has been set to: %s", mon_buff); if (rados_conf_set(ptr->cluster, "mon_host", mon_buff) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("failed to set RADOS option: %s"), "mon_host"); goto cleanup; } ptr->starttime = time(0); if (rados_connect(ptr->cluster) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("failed to connect to the RADOS monitor on: %s"), mon_buff); goto cleanup; } ret = 0;cleanup: VIR_FREE(secret_value); VIR_FREE(rados_key); virSecretFree(secret); virBufferFreeAndReset(&mon_host); VIR_FREE(mon_buff); return ret;}
开发者ID:pawitp,项目名称:libvirt,代码行数:101,
示例18: virStorageBackendRBDOpenRADOSConn//.........这里部分代码省略......... VIR_DEBUG("Found cephx key: %s", rados_key); if (rados_conf_set(ptr->cluster, "key", rados_key) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("failed to set RADOS option: %s"), "rados_key"); goto cleanup; } if (rados_conf_set(ptr->cluster, "auth_supported", "cephx") < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("failed to set RADOS option: %s"), "auth_supported"); goto cleanup; } } else { VIR_DEBUG("Not using cephx authorization"); if (rados_create(&ptr->cluster, NULL) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("failed to create the RADOS cluster")); goto cleanup; } if (rados_conf_set(ptr->cluster, "auth_supported", "none") < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("failed to set RADOS option: %s"), "auth_supported"); goto cleanup; } } VIR_DEBUG("Found %zu RADOS cluster monitors in the pool configuration", source->nhost); for (i = 0; i < source->nhost; i++) { if (source->hosts[i].name != NULL && !source->hosts[i].port) { virBufferAsprintf(&mon_host, "%s,", source->hosts[i].name); } else if (source->hosts[i].name != NULL && source->hosts[i].port) { virBufferAsprintf(&mon_host, "%s:%d,", source->hosts[i].name, source->hosts[i].port); } else { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("received malformed monitor, check the XML definition")); } } if (virBufferCheckError(&mon_host) < 0) goto cleanup; mon_buff = virBufferContentAndReset(&mon_host); VIR_DEBUG("RADOS mon_host has been set to: %s", mon_buff); if (rados_conf_set(ptr->cluster, "mon_host", mon_buff) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("failed to set RADOS option: %s"), "mon_host"); goto cleanup; } /* * Set timeout options for librados. * In case the Ceph cluster is down libvirt won't block forever. * Operations in librados will return -ETIMEDOUT when the timeout is reached. */ VIR_DEBUG("Setting RADOS option client_mount_timeout to %s", client_mount_timeout); rados_conf_set(ptr->cluster, "client_mount_timeout", client_mount_timeout); VIR_DEBUG("Setting RADOS option rados_mon_op_timeout to %s", mon_op_timeout); rados_conf_set(ptr->cluster, "rados_mon_op_timeout", mon_op_timeout); VIR_DEBUG("Setting RADOS option rados_osd_op_timeout to %s", osd_op_timeout); rados_conf_set(ptr->cluster, "rados_osd_op_timeout", osd_op_timeout); /* * Librbd supports creating RBD format 2 images. We no longer have to invoke * rbd_create3(), we can tell librbd to default to format 2. * This leaves us to simply use rbd_create() and use the default behavior of librbd */ VIR_DEBUG("Setting RADOS option rbd_default_format to %s", rbd_default_format); rados_conf_set(ptr->cluster, "rbd_default_format", rbd_default_format); ptr->starttime = time(0); if ((r = rados_connect(ptr->cluster)) < 0) { virReportSystemError(-r, _("failed to connect to the RADOS monitor on: %s"), mon_buff); goto cleanup; } ret = 0; cleanup: VIR_DISPOSE_N(secret_value, secret_value_size); VIR_DISPOSE_STRING(rados_key); virBufferFreeAndReset(&mon_host); VIR_FREE(mon_buff); return ret;}
开发者ID:Archer-sys,项目名称:libvirt,代码行数:101,
示例19: xenFormatXLDiskstatic intxenFormatXLDisk(virConfValuePtr list, virDomainDiskDefPtr disk){ virBuffer buf = VIR_BUFFER_INITIALIZER; virConfValuePtr val, tmp; const char *src = virDomainDiskGetSource(disk); int format = virDomainDiskGetFormat(disk); const char *driver = virDomainDiskGetDriver(disk); /* target */ virBufferAsprintf(&buf, "%s,", src); /* format */ switch (format) { case VIR_STORAGE_FILE_RAW: virBufferAddLit(&buf, "raw,"); break; case VIR_STORAGE_FILE_VHD: virBufferAddLit(&buf, "xvhd,"); break; case VIR_STORAGE_FILE_QCOW: virBufferAddLit(&buf, "qcow,"); break; case VIR_STORAGE_FILE_QCOW2: virBufferAddLit(&buf, "qcow2,"); break; /* set default */ default: virBufferAddLit(&buf, "raw,"); } /* device */ virBufferAdd(&buf, disk->dst, -1); virBufferAddLit(&buf, ","); if (disk->src->readonly) virBufferAddLit(&buf, "r,"); else if (disk->src->shared) virBufferAddLit(&buf, "!,"); else virBufferAddLit(&buf, "w,"); if (disk->transient) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("transient disks not supported yet")); goto cleanup; } if (STREQ_NULLABLE(driver, "qemu")) virBufferAddLit(&buf, "backendtype=qdisk"); else if (STREQ_NULLABLE(driver, "tap")) virBufferAddLit(&buf, "backendtype=tap"); else if (STREQ_NULLABLE(driver, "phy")) virBufferAddLit(&buf, "backendtype=phy"); if (disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM) virBufferAddLit(&buf, ",devtype=cdrom"); if (virBufferCheckError(&buf) < 0) goto cleanup; if (VIR_ALLOC(val) < 0) goto cleanup; val->type = VIR_CONF_STRING; val->str = virBufferContentAndReset(&buf); tmp = list->list; while (tmp && tmp->next) tmp = tmp->next; if (tmp) tmp->next = val; else list->list = val; return 0; cleanup: virBufferFreeAndReset(&buf); return -1;}
开发者ID:AGSaidi,项目名称:hacked-libvirt,代码行数:78,
示例20: xenFormatXLDiskstatic intxenFormatXLDisk(virConfValuePtr list, virDomainDiskDefPtr disk){ virBuffer buf = VIR_BUFFER_INITIALIZER; virConfValuePtr val, tmp; int format = virDomainDiskGetFormat(disk); const char *driver = virDomainDiskGetDriver(disk); char *target = NULL; /* format */ virBufferAddLit(&buf, "format="); switch (format) { case VIR_STORAGE_FILE_RAW: virBufferAddLit(&buf, "raw,"); break; case VIR_STORAGE_FILE_VHD: virBufferAddLit(&buf, "xvhd,"); break; case VIR_STORAGE_FILE_QCOW: virBufferAddLit(&buf, "qcow,"); break; case VIR_STORAGE_FILE_QCOW2: virBufferAddLit(&buf, "qcow2,"); break; /* set default */ default: virBufferAddLit(&buf, "raw,"); } /* device */ virBufferAsprintf(&buf, "vdev=%s,", disk->dst); /* access */ virBufferAddLit(&buf, "access="); if (disk->src->readonly) virBufferAddLit(&buf, "ro,"); else if (disk->src->shared) virBufferAddLit(&buf, "!,"); else virBufferAddLit(&buf, "rw,"); if (disk->transient) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("transient disks not supported yet")); goto cleanup; } /* backendtype */ if (driver) { virBufferAddLit(&buf, "backendtype="); if (STREQ(driver, "qemu") || STREQ(driver, "file")) virBufferAddLit(&buf, "qdisk,"); else if (STREQ(driver, "tap")) virBufferAddLit(&buf, "tap,"); else if (STREQ(driver, "phy")) virBufferAddLit(&buf, "phy,"); } /* devtype */ if (disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM) virBufferAddLit(&buf, "devtype=cdrom,"); /* * target * From $xensrc/docs/misc/xl-disk-configuration.txt: * When this parameter is specified by name, ie with the "target=" * syntax in the configuration file, it consumes the whole rest of the * <diskspec> including trailing whitespaces. Therefore in that case * it must come last. */ if (xenFormatXLDiskSrc(disk->src, &target) < 0) goto cleanup; virBufferAsprintf(&buf, "target=%s", target); if (virBufferCheckError(&buf) < 0) goto cleanup; if (VIR_ALLOC(val) < 0) goto cleanup; val->type = VIR_CONF_STRING; val->str = virBufferContentAndReset(&buf); tmp = list->list; while (tmp && tmp->next) tmp = tmp->next; if (tmp) tmp->next = val; else list->list = val; return 0; cleanup: VIR_FREE(target); virBufferFreeAndReset(&buf); return -1;}
开发者ID:Lantame,项目名称:libvirt,代码行数:96,
示例21: xenFormatXLDiskSrcNetstatic char *xenFormatXLDiskSrcNet(virStorageSourcePtr src){ char *ret = NULL; virBuffer buf = VIR_BUFFER_INITIALIZER; size_t i; switch ((virStorageNetProtocol) src->protocol) { case VIR_STORAGE_NET_PROTOCOL_NBD: case VIR_STORAGE_NET_PROTOCOL_HTTP: case VIR_STORAGE_NET_PROTOCOL_HTTPS: case VIR_STORAGE_NET_PROTOCOL_FTP: case VIR_STORAGE_NET_PROTOCOL_FTPS: case VIR_STORAGE_NET_PROTOCOL_TFTP: case VIR_STORAGE_NET_PROTOCOL_ISCSI: case VIR_STORAGE_NET_PROTOCOL_GLUSTER: case VIR_STORAGE_NET_PROTOCOL_SHEEPDOG: case VIR_STORAGE_NET_PROTOCOL_LAST: case VIR_STORAGE_NET_PROTOCOL_NONE: virReportError(VIR_ERR_NO_SUPPORT, _("Unsupported network block protocol '%s'"), virStorageNetProtocolTypeToString(src->protocol)); goto cleanup; case VIR_STORAGE_NET_PROTOCOL_RBD: if (strchr(src->path, ':')) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("':' not allowed in RBD source volume name '%s'"), src->path); goto cleanup; } virBufferStrcat(&buf, "rbd:", src->path, NULL); virBufferAddLit(&buf, ":auth_supported=none"); if (src->nhosts > 0) { virBufferAddLit(&buf, ":mon_host="); for (i = 0; i < src->nhosts; i++) { if (i) virBufferAddLit(&buf, "////;"); /* assume host containing : is ipv6 */ if (strchr(src->hosts[i].name, ':')) virBufferEscape(&buf, '//', ":", "[%s]", src->hosts[i].name); else virBufferAsprintf(&buf, "%s", src->hosts[i].name); if (src->hosts[i].port) virBufferAsprintf(&buf, "////:%s", src->hosts[i].port); } } if (virBufferCheckError(&buf) < 0) goto cleanup; ret = virBufferContentAndReset(&buf); break; } cleanup: virBufferFreeAndReset(&buf); return ret;}
开发者ID:Lantame,项目名称:libvirt,代码行数:66,
示例22: umlBuildCommandLineNet//.........这里部分代码省略......... } break; case VIR_DOMAIN_NET_TYPE_VHOSTUSER: virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("vhostuser networking type not supported")); goto error; case VIR_DOMAIN_NET_TYPE_SERVER: virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("TCP server networking type not supported")); goto error; case VIR_DOMAIN_NET_TYPE_CLIENT: virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("TCP client networking type not supported")); goto error; case VIR_DOMAIN_NET_TYPE_MCAST: /* ethNNN=tuntap,macaddr,ipaddr,port */ virBufferAddLit(&buf, "mcast"); break; case VIR_DOMAIN_NET_TYPE_NETWORK: { char *bridge; virNetworkPtr network = virNetworkLookupByName(conn, def->data.network.name); if (!network) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Network '%s' not found"), def->data.network.name); goto error; } bridge = virNetworkGetBridgeName(network); virObjectUnref(network); if (bridge == NULL) goto error; if (umlConnectTapDevice(vm, def, bridge) < 0) { VIR_FREE(bridge); goto error; } /* ethNNN=tuntap,tapname,macaddr,gateway */ virBufferAsprintf(&buf, "tuntap,%s", def->ifname); break; } case VIR_DOMAIN_NET_TYPE_BRIDGE: if (umlConnectTapDevice(vm, def, def->data.bridge.brname) < 0) goto error; /* ethNNN=tuntap,tapname,macaddr,gateway */ virBufferAsprintf(&buf, "tuntap,%s", def->ifname); break; case VIR_DOMAIN_NET_TYPE_INTERNAL: virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("internal networking type not supported")); goto error; case VIR_DOMAIN_NET_TYPE_DIRECT: virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("direct networking type not supported")); goto error; case VIR_DOMAIN_NET_TYPE_HOSTDEV: virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("hostdev networking type not supported")); goto error; case VIR_DOMAIN_NET_TYPE_LAST: break; } if (def->script) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("interface script execution not supported by this driver")); goto error; } virBufferAsprintf(&buf, ",%s", virMacAddrFormat(&def->mac, macaddr)); if (def->type == VIR_DOMAIN_NET_TYPE_MCAST) { virBufferAsprintf(&buf, ",%s,%d", def->data.socket.address, def->data.socket.port); } if (virBufferCheckError(&buf) < 0) return NULL; return virBufferContentAndReset(&buf); error: virBufferFreeAndReset(&buf); return NULL;}
开发者ID:candhare,项目名称:libvirt,代码行数:101,
示例23: testFirewallRemoveRulestatic inttestFirewallRemoveRule(const void *opaque){ virBuffer cmdbuf = VIR_BUFFER_INITIALIZER; virFirewallPtr fw = NULL; int ret = -1; const char *actual = NULL; const char *expected = IPTABLES_PATH " -A INPUT --source-host 192.168.122.1 --jump ACCEPT/n" IPTABLES_PATH " -A INPUT --source-host '!192.168.122.1' --jump REJECT/n"; const struct testFirewallData *data = opaque; virFirewallRulePtr fwrule; fwDisabled = data->fwDisabled; if (virFirewallSetBackend(data->tryBackend) < 0) goto cleanup; if (data->expectBackend == VIR_FIREWALL_BACKEND_DIRECT) virCommandSetDryRun(&cmdbuf, NULL, NULL); else fwBuf = &cmdbuf; fw = virFirewallNew(); virFirewallStartTransaction(fw, 0); virFirewallAddRule(fw, VIR_FIREWALL_LAYER_IPV4, "-A", "INPUT", "--source-host", "192.168.122.1", "--jump", "ACCEPT", NULL); fwrule = virFirewallAddRule(fw, VIR_FIREWALL_LAYER_IPV4, "-A", "INPUT", NULL); virFirewallRuleAddArg(fw, fwrule, "--source-host"); virFirewallRemoveRule(fw, fwrule); fwrule = virFirewallAddRule(fw, VIR_FIREWALL_LAYER_IPV4, "-A", "INPUT", NULL); virFirewallRuleAddArg(fw, fwrule, "--source-host"); virFirewallRuleAddArgFormat(fw, fwrule, "%s", "!192.168.122.1"); virFirewallRuleAddArgList(fw, fwrule, "--jump", "REJECT", NULL); if (virFirewallApply(fw) < 0) goto cleanup; if (virBufferError(&cmdbuf)) goto cleanup; actual = virBufferCurrentContent(&cmdbuf); if (STRNEQ_NULLABLE(expected, actual)) { fprintf(stderr, "Unexected command execution/n"); virTestDifference(stderr, expected, actual); goto cleanup; } ret = 0; cleanup: virBufferFreeAndReset(&cmdbuf); fwBuf = NULL; virCommandSetDryRun(NULL, NULL, NULL); virFirewallFree(fw); return ret;}
开发者ID:Archer-sys,项目名称:libvirt,代码行数:64,
示例24: hypervEnumAndPull/* This function guarantees that query is freed, even on failure */inthypervEnumAndPull(hypervPrivate *priv, virBufferPtr query, const char *root, XmlSerializerInfo *serializerInfo, const char *resourceUri, const char *className, hypervObject **list){ int result = -1; WsSerializerContextH serializerContext; client_opt_t *options = NULL; char *query_string = NULL; filter_t *filter = NULL; WsXmlDocH response = NULL; char *enumContext = NULL; hypervObject *head = NULL; hypervObject *tail = NULL; WsXmlNodeH node = NULL; XML_TYPE_PTR data = NULL; hypervObject *object; if (virBufferCheckError(query) < 0) { virBufferFreeAndReset(query); return -1; } query_string = virBufferContentAndReset(query); if (list == NULL || *list != NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); VIR_FREE(query_string); return -1; } serializerContext = wsmc_get_serialization_context(priv->client); options = wsmc_options_init(); if (options == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not initialize options")); goto cleanup; } filter = filter_create_simple(WSM_WQL_FILTER_DIALECT, query_string); if (filter == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not create filter")); goto cleanup; } response = wsmc_action_enumerate(priv->client, root, options, filter); if (hyperyVerifyResponse(priv->client, response, "enumeration") < 0) goto cleanup; enumContext = wsmc_get_enum_context(response); ws_xml_destroy_doc(response); response = NULL; while (enumContext != NULL && *enumContext != '/0') { response = wsmc_action_pull(priv->client, resourceUri, options, filter, enumContext); if (hyperyVerifyResponse(priv->client, response, "pull") < 0) goto cleanup; node = ws_xml_get_soap_body(response); if (node == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not lookup SOAP body")); goto cleanup; } node = ws_xml_get_child(node, 0, XML_NS_ENUMERATION, WSENUM_PULL_RESP); if (node == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not lookup pull response")); goto cleanup; } node = ws_xml_get_child(node, 0, XML_NS_ENUMERATION, WSENUM_ITEMS); if (node == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not lookup pull response items")); goto cleanup; } if (ws_xml_get_child(node, 0, resourceUri, className) == NULL) break; data = ws_deserialize(serializerContext, node, serializerInfo, className, resourceUri, NULL, 0, 0); if (data == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not deserialize pull response item")); goto cleanup;//.........这里部分代码省略.........
开发者ID:Archer-sys,项目名称:libvirt,代码行数:101,
示例25: virNetDevOpenvswitchAddPort//.........这里部分代码省略......... virMacAddrFormat(macaddr, macaddrstr); virUUIDFormat(ovsport->interfaceID, ifuuidstr); virUUIDFormat(vmuuid, vmuuidstr); if (virAsprintf(&attachedmac_ex_id, "external-ids:attached-mac=/"%s/"", macaddrstr) < 0) goto cleanup; if (virAsprintf(&ifaceid_ex_id, "external-ids:iface-id=/"%s/"", ifuuidstr) < 0) goto cleanup; if (virAsprintf(&vmid_ex_id, "external-ids:vm-id=/"%s/"", vmuuidstr) < 0) goto cleanup; if (ovsport->profileID[0] != '/0') { if (virAsprintf(&profile_ex_id, "external-ids:port-profile=/"%s/"", ovsport->profileID) < 0) goto cleanup; } cmd = virCommandNew(OVSVSCTL); virCommandAddArgList(cmd, "--timeout=5", "--", "--if-exists", "del-port", ifname, "--", "add-port", brname, ifname, NULL); if (virtVlan && virtVlan->nTags > 0) { switch (virtVlan->nativeMode) { case VIR_NATIVE_VLAN_MODE_TAGGED: virCommandAddArg(cmd, "vlan_mode=native-tagged"); virCommandAddArgFormat(cmd, "tag=%d", virtVlan->nativeTag); break; case VIR_NATIVE_VLAN_MODE_UNTAGGED: virCommandAddArg(cmd, "vlan_mode=native-untagged"); virCommandAddArgFormat(cmd, "tag=%d", virtVlan->nativeTag); break; case VIR_NATIVE_VLAN_MODE_DEFAULT: default: break; } if (virtVlan->trunk) { virBufferAddLit(&buf, "trunk="); /* * Trunk ports have at least one VLAN. Do the first one * outside the "for" loop so we can put a "," at the * start of the for loop if there are more than one VLANs * on this trunk port. */ virBufferAsprintf(&buf, "%d", virtVlan->tag[i]); for (i = 1; i < virtVlan->nTags; i++) { virBufferAddLit(&buf, ","); virBufferAsprintf(&buf, "%d", virtVlan->tag[i]); } if (virBufferCheckError(&buf) < 0) goto cleanup; virCommandAddArg(cmd, virBufferCurrentContent(&buf)); } else if (virtVlan->nTags) { virCommandAddArgFormat(cmd, "tag=%d", virtVlan->tag[0]); } } if (ovsport->profileID[0] == '/0') { virCommandAddArgList(cmd, "--", "set", "Interface", ifname, attachedmac_ex_id, "--", "set", "Interface", ifname, ifaceid_ex_id, "--", "set", "Interface", ifname, vmid_ex_id, "--", "set", "Interface", ifname, "external-ids:iface-status=active", NULL); } else { virCommandAddArgList(cmd, "--", "set", "Interface", ifname, attachedmac_ex_id, "--", "set", "Interface", ifname, ifaceid_ex_id, "--", "set", "Interface", ifname, vmid_ex_id, "--", "set", "Interface", ifname, profile_ex_id, "--", "set", "Interface", ifname, "external-ids:iface-status=active", NULL); } if (virCommandRun(cmd, NULL) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to add port %s to OVS bridge %s"), ifname, brname); goto cleanup; } ret = 0; cleanup: virBufferFreeAndReset(&buf); VIR_FREE(attachedmac_ex_id); VIR_FREE(ifaceid_ex_id); VIR_FREE(vmid_ex_id); VIR_FREE(profile_ex_id); virCommandFree(cmd); return ret;}
开发者ID:icclab,项目名称:libvirt,代码行数:101,
示例26: cpuTestGuestDatastatic intcpuTestGuestData(const void *arg){ const struct data *data = arg; int ret = -1; virCPUDefPtr host = NULL; virCPUDefPtr cpu = NULL; virCPUDefPtr guest = NULL; union cpuData *guestData = NULL; virCPUCompareResult cmpResult; virBuffer buf = VIR_BUFFER_INITIALIZER; char *result = NULL; if (!(host = cpuTestLoadXML(data->arch, data->host)) || !(cpu = cpuTestLoadXML(data->arch, data->name))) goto cleanup; cmpResult = cpuGuestData(host, cpu, &guestData); if (cmpResult == VIR_CPU_COMPARE_ERROR || cmpResult == VIR_CPU_COMPARE_INCOMPATIBLE) goto cleanup; if (VIR_ALLOC(guest) < 0 || !(guest->arch = strdup(host->arch))) goto cleanup; guest->type = VIR_CPU_TYPE_GUEST; guest->match = VIR_CPU_MATCH_EXACT; guest->fallback = cpu->fallback; if (cpuDecode(guest, guestData, data->models, data->nmodels, data->preferred) < 0) { if (data->result < 0) { virResetLastError(); ret = 0; } goto cleanup; } virBufferAsprintf(&buf, "%s+%s", data->host, data->name); if (data->nmodels) virBufferAsprintf(&buf, ",%s", data->modelsName); if (data->preferred) virBufferAsprintf(&buf, ",%s", data->preferred); virBufferAddLit(&buf, "-result"); if (virBufferError(&buf)) { virBufferFreeAndReset(&buf); goto cleanup; } result = virBufferContentAndReset(&buf); ret = cpuTestCompareXML(data->arch, guest, result, 0);cleanup: VIR_FREE(result); if (host) cpuDataFree(host->arch, guestData); virCPUDefFree(host); virCPUDefFree(cpu); virCPUDefFree(guest); return ret;}
开发者ID:ansisatteka,项目名称:libvirt-ovs,代码行数:61,
示例27: virLockManagerSanlockRegisterKillscriptstatic intvirLockManagerSanlockRegisterKillscript(int sock, const char *vmuri, const char *uuidstr, virDomainLockFailureAction action){ virBuffer buf = VIR_BUFFER_INITIALIZER; char *path; char *args = NULL; int ret = -1; int rv; if (action > VIR_DOMAIN_LOCK_FAILURE_IGNORE) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Failure action %s is not supported by sanlock"), virDomainLockFailureTypeToString(action)); goto cleanup; } virBufferEscape(&buf, '//', "// ", "%s", vmuri); virBufferAddLit(&buf, " "); virBufferEscape(&buf, '//', "// ", "%s", uuidstr); virBufferAddLit(&buf, " "); virBufferEscape(&buf, '//', "// ", "%s", virDomainLockFailureTypeToString(action)); if (virBufferError(&buf)) { virBufferFreeAndReset(&buf); virReportOOMError(); goto cleanup; } /* Unfortunately, sanlock_killpath() does not use const for either * path or args even though it will just copy them into its own * buffers. */ path = (char *) VIR_LOCK_MANAGER_SANLOCK_KILLPATH; args = virBufferContentAndReset(&buf); VIR_DEBUG("Register sanlock killpath: %s %s", path, args); /* sanlock_killpath() would just crop the strings */ if (strlen(path) >= SANLK_HELPER_PATH_LEN) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Sanlock helper path is longer than %d: '%s'"), SANLK_HELPER_PATH_LEN - 1, path); goto cleanup; } if (strlen(args) >= SANLK_HELPER_ARGS_LEN) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Sanlock helper arguments are longer than %d:" " '%s'"), SANLK_HELPER_ARGS_LEN - 1, args); goto cleanup; } if ((rv = sanlock_killpath(sock, 0, path, args)) < 0) { if (rv <= -200) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to register lock failure action:" " error %d"), rv); } else { virReportSystemError(-rv, "%s", _("Failed to register lock failure" " action")); } goto cleanup; } ret = 0;cleanup: VIR_FREE(args); return ret;}
开发者ID:mithleshvrts,项目名称:libvirt-0.10.2,代码行数:75,
示例28: virCapabilitiesFormatXML//.........这里部分代码省略......... virBufferAddLit(&xml, " <secmodel>/n"); virBufferAsprintf(&xml, " <model>%s</model>/n", caps->host.secModels[i].model); virBufferAsprintf(&xml, " <doi>%s</doi>/n", caps->host.secModels[i].doi); for (j = 0; j < caps->host.secModels[i].nlabels; j++) { virBufferAsprintf(&xml, " <baselabel type='%s'>%s</baselabel>/n", caps->host.secModels[i].labels[j].type, caps->host.secModels[i].labels[j].label); } virBufferAddLit(&xml, " </secmodel>/n"); } virBufferAddLit(&xml, " </host>/n/n"); for (i = 0; i < caps->nguests; i++) { virBufferAddLit(&xml, " <guest>/n"); virBufferAsprintf(&xml, " <os_type>%s</os_type>/n", caps->guests[i]->ostype); if (caps->guests[i]->arch.id) virBufferAsprintf(&xml, " <arch name='%s'>/n", virArchToString(caps->guests[i]->arch.id)); virBufferAsprintf(&xml, " <wordsize>%d</wordsize>/n", caps->guests[i]->arch.wordsize); if (caps->guests[i]->arch.defaultInfo.emulator) virBufferAsprintf(&xml, " <emulator>%s</emulator>/n", caps->guests[i]->arch.defaultInfo.emulator); if (caps->guests[i]->arch.defaultInfo.loader) virBufferAsprintf(&xml, " <loader>%s</loader>/n", caps->guests[i]->arch.defaultInfo.loader); for (j = 0; j < caps->guests[i]->arch.defaultInfo.nmachines; j++) { virCapsGuestMachinePtr machine = caps->guests[i]->arch.defaultInfo.machines[j]; virBufferAddLit(&xml, " <machine"); if (machine->canonical) virBufferAsprintf(&xml, " canonical='%s'", machine->canonical); if (machine->maxCpus > 0) virBufferAsprintf(&xml, " maxCpus='%d'", machine->maxCpus); virBufferAsprintf(&xml, ">%s</machine>/n", machine->name); } for (j = 0; j < caps->guests[i]->arch.ndomains; j++) { virBufferAsprintf(&xml, " <domain type='%s'>/n", caps->guests[i]->arch.domains[j]->type); if (caps->guests[i]->arch.domains[j]->info.emulator) virBufferAsprintf(&xml, " <emulator>%s</emulator>/n", caps->guests[i]->arch.domains[j]->info.emulator); if (caps->guests[i]->arch.domains[j]->info.loader) virBufferAsprintf(&xml, " <loader>%s</loader>/n", caps->guests[i]->arch.domains[j]->info.loader); for (k = 0; k < caps->guests[i]->arch.domains[j]->info.nmachines; k++) { virCapsGuestMachinePtr machine = caps->guests[i]->arch.domains[j]->info.machines[k]; virBufferAddLit(&xml, " <machine"); if (machine->canonical) virBufferAsprintf(&xml, " canonical='%s'", machine->canonical); if (machine->maxCpus > 0) virBufferAsprintf(&xml, " maxCpus='%d'", machine->maxCpus); virBufferAsprintf(&xml, ">%s</machine>/n", machine->name); } virBufferAddLit(&xml, " </domain>/n"); } virBufferAddLit(&xml, " </arch>/n"); if (caps->guests[i]->nfeatures) { virBufferAddLit(&xml, " <features>/n"); for (j = 0; j < caps->guests[i]->nfeatures; j++) { if (STREQ(caps->guests[i]->features[j]->name, "pae") || STREQ(caps->guests[i]->features[j]->name, "nonpae") || STREQ(caps->guests[i]->features[j]->name, "ia64_be") || STREQ(caps->guests[i]->features[j]->name, "cpuselection") || STREQ(caps->guests[i]->features[j]->name, "deviceboot")) { virBufferAsprintf(&xml, " <%s/>/n", caps->guests[i]->features[j]->name); } else { virBufferAsprintf(&xml, " <%s default='%s' toggle='%s'/>/n", caps->guests[i]->features[j]->name, caps->guests[i]->features[j]->defaultOn ? "on" : "off", caps->guests[i]->features[j]->toggle ? "yes" : "no"); } } virBufferAddLit(&xml, " </features>/n"); } virBufferAddLit(&xml, " </guest>/n/n"); } virBufferAddLit(&xml, "</capabilities>/n"); if (virBufferError(&xml)) { virBufferFreeAndReset(&xml); return NULL; } return virBufferContentAndReset(&xml);}
开发者ID:virtualopensystems,项目名称:libvirt,代码行数:101,
示例29: virCapabilitiesFormatXML//.........这里部分代码省略......... caps->host.numaCell[i]->ncpus); for (j = 0 ; j < caps->host.numaCell[i]->ncpus ; j++) virBufferAsprintf(&xml, " <cpu id='%d'/>/n", caps->host.numaCell[i]->cpus[j]); virBufferAddLit(&xml, " </cpus>/n"); virBufferAddLit(&xml, " </cell>/n"); } virBufferAddLit(&xml, " </cells>/n"); virBufferAddLit(&xml, " </topology>/n"); } if (caps->host.secModel.model) { virBufferAddLit(&xml, " <secmodel>/n"); virBufferAsprintf(&xml, " <model>%s</model>/n", caps->host.secModel.model); virBufferAsprintf(&xml, " <doi>%s</doi>/n", caps->host.secModel.doi); virBufferAddLit(&xml, " </secmodel>/n"); } virBufferAddLit(&xml, " </host>/n/n"); for (i = 0 ; i < caps->nguests ; i++) { virBufferAddLit(&xml, " <guest>/n"); virBufferAsprintf(&xml, " <os_type>%s</os_type>/n", caps->guests[i]->ostype); virBufferAsprintf(&xml, " <arch name='%s'>/n", caps->guests[i]->arch.name); virBufferAsprintf(&xml, " <wordsize>%d</wordsize>/n", caps->guests[i]->arch.wordsize); if (caps->guests[i]->arch.defaultInfo.emulator) virBufferAsprintf(&xml, " <emulator>%s</emulator>/n", caps->guests[i]->arch.defaultInfo.emulator); if (caps->guests[i]->arch.defaultInfo.loader) virBufferAsprintf(&xml, " <loader>%s</loader>/n", caps->guests[i]->arch.defaultInfo.loader); for (j = 0 ; j < caps->guests[i]->arch.defaultInfo.nmachines ; j++) { virCapsGuestMachinePtr machine = caps->guests[i]->arch.defaultInfo.machines[j]; virBufferAddLit(&xml, " <machine"); if (machine->canonical) virBufferAsprintf(&xml, " canonical='%s'", machine->canonical); virBufferAsprintf(&xml, ">%s</machine>/n", machine->name); } for (j = 0 ; j < caps->guests[i]->arch.ndomains ; j++) { virBufferAsprintf(&xml, " <domain type='%s'>/n", caps->guests[i]->arch.domains[j]->type); if (caps->guests[i]->arch.domains[j]->info.emulator) virBufferAsprintf(&xml, " <emulator>%s</emulator>/n", caps->guests[i]->arch.domains[j]->info.emulator); if (caps->guests[i]->arch.domains[j]->info.loader) virBufferAsprintf(&xml, " <loader>%s</loader>/n", caps->guests[i]->arch.domains[j]->info.loader); for (k = 0 ; k < caps->guests[i]->arch.domains[j]->info.nmachines ; k++) { virCapsGuestMachinePtr machine = caps->guests[i]->arch.domains[j]->info.machines[k]; virBufferAddLit(&xml, " <machine"); if (machine->canonical) virBufferAsprintf(&xml, " canonical='%s'", machine->canonical); virBufferAsprintf(&xml, ">%s</machine>/n", machine->name); } virBufferAddLit(&xml, " </domain>/n"); } virBufferAddLit(&xml, " </arch>/n"); if (caps->guests[i]->nfeatures) { virBufferAddLit(&xml, " <features>/n"); for (j = 0 ; j < caps->guests[i]->nfeatures ; j++) { if (STREQ(caps->guests[i]->features[j]->name, "pae") || STREQ(caps->guests[i]->features[j]->name, "nonpae") || STREQ(caps->guests[i]->features[j]->name, "ia64_be") || STREQ(caps->guests[i]->features[j]->name, "cpuselection") || STREQ(caps->guests[i]->features[j]->name, "deviceboot")) { virBufferAsprintf(&xml, " <%s/>/n", caps->guests[i]->features[j]->name); } else { virBufferAsprintf(&xml, " <%s default='%s' toggle='%s'/>/n", caps->guests[i]->features[j]->name, caps->guests[i]->features[j]->defaultOn ? "on" : "off", caps->guests[i]->features[j]->toggle ? "yes" : "no"); } } virBufferAddLit(&xml, " </features>/n"); } virBufferAddLit(&xml, " </guest>/n/n"); } virBufferAddLit(&xml, "</capabilities>/n"); if (virBufferError(&xml)) { virBufferFreeAndReset(&xml); return NULL; } return virBufferContentAndReset(&xml);}
开发者ID:kantai,项目名称:libvirt-vfork,代码行数:101,
示例30: virCheckFlagschar *virDomainSnapshotDefFormat(const char *domain_uuid, virDomainSnapshotDefPtr def, unsigned int flags, int internal){ virBuffer buf = VIR_BUFFER_INITIALIZER; int i; virCheckFlags(VIR_DOMAIN_XML_SECURE | VIR_DOMAIN_XML_UPDATE_CPU, NULL); flags |= VIR_DOMAIN_XML_INACTIVE; virBufferAddLit(&buf, "<domainsnapshot>/n"); virBufferEscapeString(&buf, " <name>%s</name>/n", def->name); if (def->description) virBufferEscapeString(&buf, " <description>%s</description>/n", def->description); virBufferAsprintf(&buf, " <state>%s</state>/n", virDomainSnapshotStateTypeToString(def->state)); if (def->parent) { virBufferAddLit(&buf, " <parent>/n"); virBufferEscapeString(&buf, " <name>%s</name>/n", def->parent); virBufferAddLit(&buf, " </parent>/n"); } virBufferAsprintf(&buf, " <creationTime>%lld</creationTime>/n", def->creationTime); if (def->memory) { virBufferAsprintf(&buf, " <memory snapshot='%s'", virDomainSnapshotLocationTypeToString(def->memory)); virBufferEscapeString(&buf, " file='%s'", def->file); virBufferAddLit(&buf, "/>/n"); } if (def->ndisks) { virBufferAddLit(&buf, " <disks>/n"); for (i = 0; i < def->ndisks; i++) { virDomainSnapshotDiskDefPtr disk = &def->disks[i]; if (!disk->name) continue; virBufferEscapeString(&buf, " <disk name='%s'", disk->name); if (disk->snapshot) virBufferAsprintf(&buf, " snapshot='%s'", virDomainSnapshotLocationTypeToString(disk->snapshot)); if (disk->file || disk->format > 0) { virBufferAddLit(&buf, ">/n"); if (disk->format > 0) virBufferEscapeString(&buf, " <driver type='%s'/>/n", virStorageFileFormatTypeToString( disk->format)); if (disk->file) virBufferEscapeString(&buf, " <source file='%s'/>/n", disk->file); virBufferAddLit(&buf, " </disk>/n"); } else { virBufferAddLit(&buf, "/>/n"); } } virBufferAddLit(&buf, " </disks>/n"); } if (def->dom) { virBufferAdjustIndent(&buf, 2); if (virDomainDefFormatInternal(def->dom, flags, &buf) < 0) { virBufferFreeAndReset(&buf); return NULL; } virBufferAdjustIndent(&buf, -2); } else if (domain_uuid) { virBufferAddLit(&buf, " <domain>/n"); virBufferAsprintf(&buf, " <uuid>%s</uuid>/n", domain_uuid); virBufferAddLit(&buf, " </domain>/n"); } if (internal) virBufferAsprintf(&buf, " <active>%d</active>/n", def->current); virBufferAddLit(&buf, "</domainsnapshot>/n"); if (virBufferError(&buf)) { virBufferFreeAndReset(&buf); virReportOOMError(); return NULL; } return virBufferContentAndReset(&buf);}
开发者ID:bigclouds,项目名称:libvirt,代码行数:85,
注:本文中的virBufferFreeAndReset函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ virCapabilitiesAddGuest函数代码示例 C++ virBufferError函数代码示例 |