本文整理汇总了C++中VIR_ALLOC_N函数的典型用法代码示例。如果您正苦于以下问题:C++ VIR_ALLOC_N函数的具体用法?C++ VIR_ALLOC_N怎么用?C++ VIR_ALLOC_N使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了VIR_ALLOC_N函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: virInterfaceDefParseProtoIPv4
static int
virInterfaceDefParseProtoIPv4(virInterfaceProtocolDefPtr def,
xmlXPathContextPtr ctxt) {
xmlNodePtr dhcp;
xmlNodePtr *ipNodes = NULL;
int nIpNodes, ret = -1;
size_t i;
char *tmp;
tmp = virXPathString("string(./route[1]/@gateway)", ctxt);
def->gateway = tmp;
dhcp = virXPathNode("./dhcp", ctxt);
if (dhcp != NULL) {
if (virInterfaceDefParseDhcp(def, dhcp, ctxt) < 0)
return -1;
}
nIpNodes = virXPathNodeSet("./ip", ctxt, &ipNodes);
if (nIpNodes < 0)
return -1;
if (ipNodes == NULL)
return 0;
if (VIR_ALLOC_N(def->ips, nIpNodes) < 0)
goto error;
def->nips = 0;
for (i = 0; i < nIpNodes; i++) {
virInterfaceIpDefPtr ip;
if (VIR_ALLOC(ip) < 0)
goto error;
ctxt->node = ipNodes[i];
if (virInterfaceDefParseIp(ip, ctxt) < 0) {
virInterfaceIpDefFree(ip);
goto error;
}
def->ips[def->nips++] = ip;
}
ret = 0;
error:
VIR_FREE(ipNodes);
return ret;
}
示例2: munge_param
static char *
munge_param(const char *datain,
size_t *params,
size_t paramnum,
int *type)
{
char *dataout;
const char *sol;
const char *eol;
const char *eq;
const char *tmp;
size_t dataoutlen;
const char *replace = NULL;
sol = datain + params[paramnum];
eq = strchr(sol, '=');
eol = strchr(sol, '\n');
for (tmp = eq + 1; tmp < eol && !replace; tmp++) {
if (c_isspace(*tmp))
continue;
if (c_isdigit(*tmp)) {
*type = VIR_CONF_LONG;
replace = "\"foo\"";
} else if (*tmp == '[') {
*type = VIR_CONF_LIST;
replace = "666";
} else {
*type = VIR_CONF_STRING;
replace = "666";
}
}
dataoutlen = (eq - datain) + 1 +
strlen(replace) +
strlen(eol) + 1;
if (VIR_ALLOC_N(dataout, dataoutlen) < 0) {
virReportOOMError();
return NULL;
}
memcpy(dataout, datain, (eq - datain) + 1);
memcpy(dataout + (eq - datain) + 1,
replace, strlen(replace));
memcpy(dataout + (eq - datain) + 1 + strlen(replace),
eol, strlen(eol) + 1);
return dataout;
}
示例3: virSecurityManagerGetNested
virSecurityManagerPtr*
virSecurityManagerGetNested(virSecurityManagerPtr mgr)
{
virSecurityManagerPtr* list = NULL;
if (STREQ("stack", mgr->drv->name))
return virSecurityStackGetNested(mgr);
if (VIR_ALLOC_N(list, 2) < 0)
return NULL;
list[0] = mgr;
list[1] = NULL;
return list;
}
示例4: lxctoolsReadConfigItem
/*
* str is callee allocated
*/
int lxctoolsReadConfigItem(struct lxc_container* cont, const char* key, char** str)
{
int ret_len;
if ((ret_len = cont->get_config_item(cont, key, NULL, 0)) < 0)
goto error;
if (VIR_ALLOC_N(*str, ret_len+1) < 0)
goto error;
if ((cont->get_config_item(cont, key, *str, ret_len+1)) < 0)
goto error;
return 0;
error:
VIR_ERROR("Error on reading config for container: '%s'", cont->error_string);
*str = NULL;
return -1;
}
示例5: virNetServerServiceNewFD
virNetServerServicePtr virNetServerServiceNewFD(int fd,
int auth,
bool readonly,
size_t nrequests_client_max,
virNetTLSContextPtr tls)
{
virNetServerServicePtr svc;
int i;
if (virNetServerServiceInitialize() < 0)
return NULL;
if (!(svc = virObjectNew(virNetServerServiceClass)))
return NULL;
svc->auth = auth;
svc->readonly = readonly;
svc->nrequests_client_max = nrequests_client_max;
svc->tls = virObjectRef(tls);
svc->nsocks = 1;
if (VIR_ALLOC_N(svc->socks, svc->nsocks) < 0)
goto no_memory;
if (virNetSocketNewListenFD(fd,
&svc->socks[0]) < 0)
goto error;
for (i = 0 ; i < svc->nsocks ; i++) {
/* IO callback is initially disabled, until we're ready
* to deal with incoming clients */
if (virNetSocketAddIOCallback(svc->socks[i],
0,
virNetServerServiceAccept,
svc,
virObjectFreeCallback) < 0)
goto error;
}
return svc;
no_memory:
virReportOOMError();
error:
virObjectUnref(svc);
return NULL;
}
示例6: virNetServerClientNewInternal
static virNetServerClientPtr
virNetServerClientNewInternal(virNetSocketPtr sock,
int auth,
#ifdef WITH_GNUTLS
virNetTLSContextPtr tls,
#endif
bool readonly,
size_t nrequests_max)
{
virNetServerClientPtr client;
if (virNetServerClientInitialize() < 0)
return NULL;
if (!(client = virObjectLockableNew(virNetServerClientClass)))
return NULL;
client->sock = virObjectRef(sock);
client->auth = auth;
client->readonly = readonly;
#ifdef WITH_GNUTLS
client->tlsCtxt = virObjectRef(tls);
#endif
client->nrequests_max = nrequests_max;
client->sockTimer = virEventAddTimeout(-1, virNetServerClientSockTimerFunc,
client, NULL);
if (client->sockTimer < 0)
goto error;
/* Prepare one for packet receive */
if (!(client->rx = virNetMessageNew(true)))
goto error;
client->rx->bufferLength = VIR_NET_MESSAGE_LEN_MAX;
if (VIR_ALLOC_N(client->rx->buffer, client->rx->bufferLength) < 0)
goto error;
client->nrequests = 1;
PROBE(RPC_SERVER_CLIENT_NEW,
"client=%p sock=%p",
client, client->sock);
return client;
error:
virObjectUnref(client);
return NULL;
}
示例7: virXPathNodeSet
/**
* virXPathNodeSet:
* @xpath: the XPath string to evaluate
* @ctxt: an XPath context
* @list: the returned list of nodes (or NULL if only count matters)
*
* Convenience function to evaluate an XPath node set
*
* Returns the number of nodes found in which case @list is set (and
* must be freed) or -1 if the evaluation failed.
*/
int
virXPathNodeSet(const char *xpath,
xmlXPathContextPtr ctxt,
xmlNodePtr **list)
{
xmlXPathObjectPtr obj;
xmlNodePtr relnode;
int ret;
if ((ctxt == NULL) || (xpath == NULL)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("Invalid parameter to virXPathNodeSet()"));
return -1;
}
if (list != NULL)
*list = NULL;
relnode = ctxt->node;
obj = xmlXPathEval(BAD_CAST xpath, ctxt);
ctxt->node = relnode;
if (obj == NULL)
return 0;
if (obj->type != XPATH_NODESET) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Incorrect xpath '%s'"), xpath);
xmlXPathFreeObject(obj);
return -1;
}
if ((obj->nodesetval == NULL) || (obj->nodesetval->nodeNr < 0)) {
xmlXPathFreeObject(obj);
return 0;
}
ret = obj->nodesetval->nodeNr;
if (list != NULL && ret) {
if (VIR_ALLOC_N(*list, ret) < 0) {
ret = -1;
} else {
memcpy(*list, obj->nodesetval->nodeTab,
ret * sizeof(xmlNodePtr));
}
}
xmlXPathFreeObject(obj);
return ret;
}
示例8: qemuMigrationCookieNetworkXMLParse
static qemuMigrationCookieNetworkPtr
qemuMigrationCookieNetworkXMLParse(xmlXPathContextPtr ctxt)
{
qemuMigrationCookieNetworkPtr optr;
size_t i;
int n;
xmlNodePtr *interfaces = NULL;
char *vporttype;
xmlNodePtr save_ctxt = ctxt->node;
if (VIR_ALLOC(optr) < 0)
goto error;
if ((n = virXPathNodeSet("./network/interface", ctxt, &interfaces)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("missing interface information"));
goto error;
}
optr->nnets = n;
if (VIR_ALLOC_N(optr->net, optr->nnets) < 0)
goto error;
for (i = 0; i < n; i++) {
/* portdata is optional, and may not exist */
ctxt->node = interfaces[i];
optr->net[i].portdata = virXPathString("string(./portdata[1])", ctxt);
if (!(vporttype = virXMLPropString(interfaces[i], "vporttype"))) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("missing vporttype attribute in migration data"));
goto error;
}
optr->net[i].vporttype = virNetDevVPortTypeFromString(vporttype);
}
VIR_FREE(interfaces);
cleanup:
ctxt->node = save_ctxt;
return optr;
error:
VIR_FREE(interfaces);
qemuMigrationCookieNetworkFree(optr);
optr = NULL;
goto cleanup;
}
示例9: virReportSystemError
/**
* virTimeStringNow:
*
* Creates a string containing a formatted timestamp
* corresponding to the current time.
*
* This function is not async signal safe
*
* Returns a formatted allocated string, or NULL on error
*/
char *virTimeStringNow(void)
{
char *ret;
if (VIR_ALLOC_N(ret, VIR_TIME_STRING_BUFLEN) < 0)
return NULL;
if (virTimeStringNowRaw(ret) < 0) {
virReportSystemError(errno, "%s",
_("Unable to format time"));
VIR_FREE(ret);
return NULL;
}
return ret;
}
示例10: virNetDevVlanCopy
/*
* virNetDevVlanCopy - copy from src into (already existing) dst.
* If src is NULL, dst will have nTags set to 0.
* dst is assumed to be empty on entry.
*/
int
virNetDevVlanCopy(virNetDevVlanPtr dst, const virNetDevVlanPtr src)
{
if (!src || src->nTags == 0)
return 0;
if (VIR_ALLOC_N(dst->tag, src->nTags) < 0) {
virReportOOMError();
return -1;
}
dst->trunk = src->trunk;
dst->nTags = src->nTags;
memcpy(dst->tag, src->tag, src->nTags * sizeof(*src->tag));
return 0;
}
示例11: virCPUDefCopy
virCPUDefPtr
virCPUDefCopy(const virCPUDef *cpu)
{
virCPUDefPtr copy;
size_t i;
if (!cpu || VIR_ALLOC(copy) < 0)
return NULL;
copy->type = cpu->type;
copy->mode = cpu->mode;
copy->match = cpu->match;
copy->fallback = cpu->fallback;
copy->sockets = cpu->sockets;
copy->cores = cpu->cores;
copy->threads = cpu->threads;
copy->arch = cpu->arch;
if (virCPUDefCopyModel(copy, cpu, false) < 0)
goto error;
if (cpu->ncells) {
if (VIR_ALLOC_N(copy->cells, cpu->ncells) < 0)
goto error;
copy->ncells_max = copy->ncells = cpu->ncells;
for (i = 0; i < cpu->ncells; i++) {
copy->cells[i].cellid = cpu->cells[i].cellid;
copy->cells[i].mem = cpu->cells[i].mem;
copy->cells[i].cpumask = virBitmapNewCopy(cpu->cells[i].cpumask);
if (!copy->cells[i].cpumask)
goto error;
if (VIR_STRDUP(copy->cells[i].cpustr, cpu->cells[i].cpustr) < 0)
goto error;
}
copy->cells_cpus = cpu->cells_cpus;
}
return copy;
error:
virCPUDefFree(copy);
return NULL;
}
示例12: cpuTestLoadMultiXML
static virCPUDefPtr *
cpuTestLoadMultiXML(const char *arch,
const char *name,
unsigned int *count)
{
char *xml = NULL;
xmlDocPtr doc = NULL;
xmlXPathContextPtr ctxt = NULL;
xmlNodePtr *nodes = NULL;
virCPUDefPtr *cpus = NULL;
int n;
size_t i;
if (virAsprintf(&xml, "%s/cputestdata/%s-%s.xml", abs_srcdir, arch, name) < 0)
goto cleanup;
if (!(doc = virXMLParseFileCtxt(xml, &ctxt)))
goto cleanup;
n = virXPathNodeSet("/cpuTest/cpu", ctxt, &nodes);
if (n <= 0 || (VIR_ALLOC_N(cpus, n) < 0)) {
fprintf(stderr, "\nNo /cpuTest/cpu elements found in %s\n", xml);
goto cleanup;
}
for (i = 0; i < n; i++) {
ctxt->node = nodes[i];
cpus[i] = virCPUDefParseXML(nodes[i], ctxt, VIR_CPU_TYPE_HOST);
if (!cpus[i])
goto cleanup_cpus;
}
*count = n;
cleanup:
VIR_FREE(xml);
VIR_FREE(nodes);
xmlXPathFreeContext(ctxt);
xmlFreeDoc(doc);
return cpus;
cleanup_cpus:
for (i = 0; i < n; i++)
virCPUDefFree(cpus[i]);
VIR_FREE(cpus);
goto cleanup;
}
示例13: testCompareParseXML
/*
* Parses domXML to virDomainDef object, which is then converted to xl.cfg(5)
* config and compared with expected config.
*/
static int
testCompareParseXML(const char *xlcfg, const char *xml)
{
char *gotxlcfgData = NULL;
virConfPtr conf = NULL;
virConnectPtr conn = NULL;
int wrote = 4096;
int ret = -1;
virDomainDefPtr def = NULL;
if (VIR_ALLOC_N(gotxlcfgData, wrote) < 0)
goto fail;
conn = virGetConnect();
if (!conn) goto fail;
if (!(def = virDomainDefParseFile(xml, caps, xmlopt,
VIR_DOMAIN_XML_INACTIVE)))
goto fail;
if (!virDomainDefCheckABIStability(def, def)) {
fprintf(stderr, "ABI stability check failed on %s", xml);
goto fail;
}
if (!(conf = xenFormatXL(def, conn)))
goto fail;
if (virConfWriteMem(gotxlcfgData, &wrote, conf) < 0)
goto fail;
gotxlcfgData[wrote] = '\0';
if (virtTestCompareToFile(gotxlcfgData, xlcfg) < 0)
goto fail;
ret = 0;
fail:
VIR_FREE(gotxlcfgData);
if (conf)
virConfFree(conf);
virDomainDefFree(def);
virObjectUnref(conn);
return ret;
}
示例14: ppc64DataCopy
static int
ppc64DataCopy(virCPUppc64Data *dst, const virCPUppc64Data *src)
{
size_t i;
if (VIR_ALLOC_N(dst->pvr, src->len) < 0)
return -1;
dst->len = src->len;
for (i = 0; i < src->len; i++) {
dst->pvr[i].value = src->pvr[i].value;
dst->pvr[i].mask = src->pvr[i].mask;
}
return 0;
}
示例15: lxctoolsSetNetConfig
/*
* Output only lxc.net.x
*/
int lxctoolsSetNetConfig(lxctoolsConffilePtr conffile, virDomainDefPtr def)
{
int ret = -1;
char *mac_str = NULL;
// Remove old net config
if (lxctoolsConffileRemoveItems(conffile, "lxc.net.") < 0)
goto cleanup;
if (lxctoolsConffileRemoveItems(conffile, "lxc.network.") < 0)
goto cleanup;
// Insert new net config
if (lxctoolsConffileAddComment(conffile, "begin: generated network configuration") < 0)
goto cleanup;
for (size_t i = 0; i != def->nnets; i++) {
if (def->nets[i]->type != VIR_DOMAIN_NET_TYPE_BRIDGE) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("only network type bridge is currently supported."));
goto cleanup;
}
if (lxctoolsConffileAddItemEnumerated(conffile, "lxc.net.%zu.type", "veth", i) < 0) {
VIR_ERROR("Failed to set lxc.net.%zu.type to veth", i);
goto cleanup;
}
if (VIR_ALLOC_N(mac_str, VIR_MAC_STRING_BUFLEN) < 0)
goto cleanup;
virMacAddrFormat(&def->nets[i]->mac, mac_str);
if (lxctoolsConffileAddItemEnumerated(conffile, "lxc.net.%zu.hwaddr", mac_str, i) < 0) {
VIR_ERROR("Failed to set lxc.net.%zu.hwaddr", i);
goto cleanup;
}
if (lxctoolsConffileAddItemEnumerated(conffile, "lxc.net.%zu.link", def->nets[i]->data.bridge.brname, i) < 0) {
VIR_ERROR("failed to set lxc.net.%zu.link", i);
goto cleanup;
}
if (def->nets[i]->linkstate == VIR_DOMAIN_NET_INTERFACE_LINK_STATE_UP) {
if (lxctoolsConffileAddItemEnumerated(conffile, "lxc.net.%zu.flags", "up", i) < 0)
goto cleanup;
}
}
if (lxctoolsConffileAddComment(conffile, "end: generated network configuration") < 0)
goto cleanup;
ret = 0;
cleanup:
VIR_FREE(mac_str);
return ret;
}