本文整理汇总了C++中VIR_EXPAND_N函数的典型用法代码示例。如果您正苦于以下问题:C++ VIR_EXPAND_N函数的具体用法?C++ VIR_EXPAND_N怎么用?C++ VIR_EXPAND_N使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了VIR_EXPAND_N函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: uncomment_all_params
static int
uncomment_all_params(char *data,
size_t **ret)
{
size_t count = 0;
char *tmp;
size_t *params = 0;
tmp = data;
while (tmp && *tmp) {
tmp = strchr(tmp, '\n');
if (!tmp)
break;
tmp++;
/* Uncomment any lines starting #some_var */
if (*tmp == '#' &&
c_isalpha(*(tmp + 1))) {
if (VIR_EXPAND_N(params, count, 1) < 0) {
VIR_FREE(params);
return -1;
}
*tmp = ' ';
params[count-1] = (tmp + 1) - data;
}
}
if (VIR_EXPAND_N(params, count, 1) < 0) {
VIR_FREE(params);
return -1;
}
params[count-1] = 0;
*ret = params;
return count;
}
示例2: virStorageBackendSheepdogAddVolume
static int
virStorageBackendSheepdogAddVolume(virConnectPtr conn ATTRIBUTE_UNUSED,
virStoragePoolObjPtr pool, const char *diskInfo)
{
virStorageVolDefPtr vol = NULL;
if (diskInfo == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Missing disk info when adding volume"));
goto error;
}
if (VIR_ALLOC(vol) < 0 || VIR_STRDUP(vol->name, diskInfo) < 0)
goto error;
vol->type = VIR_STORAGE_VOL_NETWORK;
if (virStorageBackendSheepdogRefreshVol(conn, pool, vol) < 0)
goto error;
if (VIR_EXPAND_N(pool->volumes.objs, pool->volumes.count, 1) < 0)
goto error;
pool->volumes.objs[pool->volumes.count - 1] = vol;
return 0;
error:
virStorageVolDefFree(vol);
return -1;
}
示例3: virDomainPCIAddressSetGrow
/* Ensure addr fits in the address set, by expanding it if needed.
* This will only grow if the flags say that we need a normal
* hot-pluggable PCI slot. If we need a different type of slot, it
* will fail.
*
* Return value:
* -1 = OOM
* 0 = no action performed
* >0 = number of buses added
*/
int
virDomainPCIAddressSetGrow(virDomainPCIAddressSetPtr addrs,
virDevicePCIAddressPtr addr,
virDomainPCIConnectFlags flags)
{
int add;
size_t i;
add = addr->bus - addrs->nbuses + 1;
i = addrs->nbuses;
if (add <= 0)
return 0;
/* auto-grow only works when we're adding plain PCI devices */
if (!(flags & VIR_PCI_CONNECT_TYPE_PCI)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Cannot automatically add a new PCI bus for a "
"device requiring a slot other than standard PCI."));
return -1;
}
if (VIR_EXPAND_N(addrs->buses, addrs->nbuses, add) < 0)
return -1;
for (; i < addrs->nbuses; i++) {
/* Any time we auto-add a bus, we will want a multi-slot
* bus. Currently the only type of bus we will auto-add is a
* pci-bridge, which is hot-pluggable and provides standard
* PCI slots.
*/
virDomainPCIAddressBusSetModel(&addrs->buses[i],
VIR_DOMAIN_CONTROLLER_MODEL_PCI_BRIDGE);
}
return add;
}
示例4: virNetServerAddClient
static int virNetServerAddClient(virNetServerPtr srv,
virNetServerClientPtr client)
{
virObjectLock(srv);
if (srv->nclients >= srv->nclients_max) {
virReportError(VIR_ERR_RPC,
_("Too many active clients (%zu), dropping connection from %s"),
srv->nclients_max, virNetServerClientRemoteAddrString(client));
goto error;
}
if (virNetServerClientInit(client) < 0)
goto error;
if (VIR_EXPAND_N(srv->clients, srv->nclients, 1) < 0)
goto error;
srv->clients[srv->nclients-1] = client;
virObjectRef(client);
virNetServerClientSetDispatcher(client,
virNetServerDispatchNewMessage,
srv);
virNetServerClientInitKeepAlive(client, srv->keepaliveInterval,
srv->keepaliveCount);
virObjectUnlock(srv);
return 0;
error:
virObjectUnlock(srv);
return -1;
}
示例5: virCloseCallbacksGetOne
static int
virCloseCallbacksGetOne(void *payload,
const void *key,
void *opaque)
{
struct virCloseCallbacksData *data = opaque;
virDriverCloseDefPtr closeDef = payload;
const char *uuidstr = key;
unsigned char uuid[VIR_UUID_BUFLEN];
if (virUUIDParse(uuidstr, uuid) < 0)
return 0;
VIR_DEBUG("conn=%p, thisconn=%p, uuid=%s, cb=%p",
closeDef->conn, data->conn, uuidstr, closeDef->cb);
if (data->conn != closeDef->conn || !closeDef->cb)
return 0;
if (VIR_EXPAND_N(data->list->entries,
data->list->nentries, 1) < 0) {
data->oom = true;
return 0;
}
memcpy(data->list->entries[data->list->nentries - 1].uuid,
uuid, VIR_UUID_BUFLEN);
data->list->entries[data->list->nentries - 1].callback = closeDef->cb;
return 0;
}
示例6: virCapabilitiesHostSecModelAddBaseLabel
/**
* virCapabilitiesHostSecModelAddBaseLabel
* @secmodel: Security model to add a base label for
* @type: virtualization type
* @label: base label
*
* Returns non-zero on error.
*/
extern int
virCapabilitiesHostSecModelAddBaseLabel(virCapsHostSecModelPtr secmodel,
const char *type,
const char *label)
{
char *t = NULL, *l = NULL;
if (type == NULL || label == NULL)
return -1;
if (VIR_STRDUP(t, type) < 0)
goto no_memory;
if (VIR_STRDUP(l, label) < 0)
goto no_memory;
if (VIR_EXPAND_N(secmodel->labels, secmodel->nlabels, 1) < 0)
goto no_memory;
secmodel->labels[secmodel->nlabels - 1].type = t;
secmodel->labels[secmodel->nlabels - 1].label = l;
return 0;
no_memory:
VIR_FREE(l);
VIR_FREE(t);
return -1;
}
示例7: virNWFilterVarValueAddValue
int
virNWFilterVarValueAddValue(virNWFilterVarValuePtr val, char *value)
{
char *tmp;
int rc = -1;
switch (val->valType) {
case NWFILTER_VALUE_TYPE_SIMPLE:
/* switch to array */
tmp = val->u.simple.value;
if (VIR_ALLOC_N(val->u.array.values, 2) < 0) {
val->u.simple.value = tmp;
return -1;
}
val->valType = NWFILTER_VALUE_TYPE_ARRAY;
val->u.array.nValues = 2;
val->u.array.values[0] = tmp;
val->u.array.values[1] = value;
rc = 0;
break;
case NWFILTER_VALUE_TYPE_ARRAY:
if (VIR_EXPAND_N(val->u.array.values,
val->u.array.nValues, 1) < 0)
return -1;
val->u.array.values[val->u.array.nValues - 1] = value;
rc = 0;
break;
case NWFILTER_VALUE_TYPE_LAST:
break;
}
return rc;
}
示例8: qemuMonitorTestAddItem
int
qemuMonitorTestAddItem(qemuMonitorTestPtr test,
const char *command_name,
const char *response)
{
qemuMonitorTestItemPtr item;
if (VIR_ALLOC(item) < 0)
goto no_memory;
if (!(item->command_name = strdup(command_name)) ||
!(item->response = strdup(response)))
goto no_memory;
virMutexLock(&test->lock);
if (VIR_EXPAND_N(test->items, test->nitems, 1) < 0) {
virMutexUnlock(&test->lock);
goto no_memory;
}
test->items[test->nitems - 1] = item;
virMutexUnlock(&test->lock);
return 0;
no_memory:
virReportOOMError();
qemuMonitorTestItemFree(item);
return -1;
}
示例9: lxcIdmapWalkCallback
static int
lxcIdmapWalkCallback(const char *name, virConfValuePtr value, void *data)
{
virDomainDefPtr def = data;
virDomainIdMapEntryPtr idmap = NULL;
char type;
unsigned long start, target, count;
/* LXC 3.0 uses "lxc.idmap", while legacy used "lxc.id_map" */
if (STRNEQ(name, "lxc.idmap") || !value->str) {
if (!value->str || STRNEQ(name, "lxc.id_map"))
return 0;
}
if (sscanf(value->str, "%c %lu %lu %lu", &type,
&target, &start, &count) != 4) {
virReportError(VIR_ERR_INTERNAL_ERROR, _("invalid %s: '%s'"),
name, value->str);
return -1;
}
if (type == 'u') {
if (VIR_EXPAND_N(def->idmap.uidmap, def->idmap.nuidmap, 1) < 0)
return -1;
idmap = &def->idmap.uidmap[def->idmap.nuidmap - 1];
} else if (type == 'g') {
if (VIR_EXPAND_N(def->idmap.gidmap, def->idmap.ngidmap, 1) < 0)
return -1;
idmap = &def->idmap.gidmap[def->idmap.ngidmap - 1];
} else {
return -1;
}
idmap->start = start;
idmap->target = target;
idmap->count = count;
return 0;
}
示例10: virNWFilterVarCombIterAddVariable
static int
virNWFilterVarCombIterAddVariable(virNWFilterVarCombIterEntryPtr cie,
virNWFilterHashTablePtr hash,
const virNWFilterVarAccess *varAccess)
{
virNWFilterVarValuePtr varValue;
unsigned int maxValue = 0, minValue = 0;
const char *varName = virNWFilterVarAccessGetVarName(varAccess);
varValue = virHashLookup(hash->hashTable, varName);
if (varValue == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Could not find value for variable '%s'"),
varName);
return -1;
}
switch (virNWFilterVarAccessGetType(varAccess)) {
case VIR_NWFILTER_VAR_ACCESS_ELEMENT:
maxValue = virNWFilterVarAccessGetIndex(varAccess);
minValue = maxValue;
break;
case VIR_NWFILTER_VAR_ACCESS_ITERATOR:
maxValue = virNWFilterVarValueGetCardinality(varValue) - 1;
minValue = 0;
break;
case VIR_NWFILTER_VAR_ACCESS_LAST:
return -1;
}
if (cie->nVarNames == 0) {
cie->maxValue = maxValue;
cie->minValue = minValue;
cie->curValue = minValue;
} else {
if (cie->maxValue != maxValue) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Cardinality of list items must be "
"the same for processing them in "
"parallel"));
return -1;
}
}
if (VIR_EXPAND_N(cie->varNames, cie->nVarNames, 1) < 0)
return -1;
cie->varNames[cie->nVarNames - 1] = varName;
return 0;
}
示例11: virNetServerAddClient
static int virNetServerAddClient(virNetServerPtr srv,
virNetServerClientPtr client)
{
virObjectLock(srv);
if (srv->nclients >= srv->nclients_max) {
virReportError(VIR_ERR_RPC,
_("Too many active clients (%zu), dropping connection from %s"),
srv->nclients_max, virNetServerClientRemoteAddrString(client));
goto error;
}
if (virNetServerClientInit(client) < 0)
goto error;
if (VIR_EXPAND_N(srv->clients, srv->nclients, 1) < 0)
goto error;
srv->clients[srv->nclients-1] = client;
virObjectRef(client);
if (virNetServerClientNeedAuth(client))
virNetServerTrackPendingAuthLocked(srv);
if (srv->nclients_unauth_max &&
srv->nclients_unauth == srv->nclients_unauth_max) {
/* Temporarily stop accepting new clients */
VIR_DEBUG("Temporarily suspending services "
"due to max_anonymous_clients");
virNetServerUpdateServicesLocked(srv, false);
}
if (srv->nclients == srv->nclients_max) {
/* Temporarily stop accepting new clients */
VIR_DEBUG("Temporarily suspending services due to max_clients");
virNetServerUpdateServicesLocked(srv, false);
}
virNetServerClientSetDispatcher(client,
virNetServerDispatchNewMessage,
srv);
virNetServerClientInitKeepAlive(client, srv->keepaliveInterval,
srv->keepaliveCount);
virObjectUnlock(srv);
return 0;
error:
virObjectUnlock(srv);
return -1;
}
示例12: virSysinfoParseProcessor
static int
virSysinfoParseProcessor(const char *base, virSysinfoDefPtr ret)
{
const char *cur;
char *eol, *tmp_base;
virSysinfoProcessorDefPtr processor;
char *processor_type = NULL;
if (!(tmp_base = strstr(base, "Processor")))
return 0;
base = tmp_base;
eol = strchr(base, '\n');
cur = strchr(base, ':') + 1;
virSkipSpaces(&cur);
if (eol &&
((processor_type = strndup(cur, eol - cur))
== NULL))
goto no_memory;
base = cur;
while ((tmp_base = strstr(base, "processor")) != NULL) {
base = tmp_base;
eol = strchr(base, '\n');
cur = strchr(base, ':') + 1;
if (VIR_EXPAND_N(ret->processor, ret->nprocessor, 1) < 0) {
goto no_memory;
}
processor = &ret->processor[ret->nprocessor - 1];
virSkipSpaces(&cur);
if (eol &&
((processor->processor_socket_destination = strndup
(cur, eol - cur)) == NULL))
goto no_memory;
if (processor_type &&
!(processor->processor_type = strdup(processor_type)))
goto no_memory;
base = cur;
}
VIR_FREE(processor_type);
return 0;
no_memory:
VIR_FREE(processor_type);
return -1;
}
示例13: virSysinfoParseProcessor
static int
virSysinfoParseProcessor(const char *base, virSysinfoDefPtr ret)
{
const char *cur;
char *eol, *tmp_base;
virSysinfoProcessorDefPtr processor;
char *processor_type = NULL;
if (!(tmp_base = strstr(base, "Processor")))
return 0;
base = tmp_base;
eol = strchr(base, '\n');
cur = strchr(base, ':') + 1;
virSkipSpaces(&cur);
if (eol && VIR_STRNDUP(processor_type, cur, eol - cur) < 0)
goto error;
base = cur;
while ((tmp_base = strstr(base, "processor")) != NULL) {
base = tmp_base;
eol = strchr(base, '\n');
cur = strchr(base, ':') + 1;
if (VIR_EXPAND_N(ret->processor, ret->nprocessor, 1) < 0)
goto error;
processor = &ret->processor[ret->nprocessor - 1];
virSkipSpaces(&cur);
if (eol &&
VIR_STRNDUP(processor->processor_socket_destination,
cur, eol - cur) < 0)
goto error;
if (processor_type &&
VIR_STRDUP(processor->processor_type, processor_type) < 0)
goto error;
base = cur;
}
VIR_FREE(processor_type);
return 0;
error:
VIR_FREE(processor_type);
return -1;
}
示例14: virTypedParamsReplaceString
/**
* virTypedParamsReplaceString:
* @params: pointer to the array of typed parameters
* @nparams: number of parameters in the @params array
* @name: name of the parameter to set
* @value: the value to store into the parameter
*
* Sets new value @value to parameter called @name with char * type. If the
* parameter does not exist yet in @params, it is automatically created and
* @naprams is incremented by one. Otherwise current value of the parameter
* is freed on success. The function creates its own copy of @value string,
* which needs to be freed using virTypedParamsFree or virTypedParamsClear.
*
* Returns 0 on success, -1 on error.
*/
int
virTypedParamsReplaceString(virTypedParameterPtr *params,
int *nparams,
const char *name,
const char *value)
{
char *str = NULL;
char *old = NULL;
size_t n = *nparams;
virTypedParameterPtr param;
param = virTypedParamsGet(*params, n, name);
if (param) {
if (param->type != VIR_TYPED_PARAM_STRING) {
virReportError(VIR_ERR_INVALID_ARG,
_("Parameter '%s' is not a string"),
param->field);
goto error;
}
old = param->value.s;
} else {
if (VIR_EXPAND_N(*params, n, 1) < 0)
goto error;
param = *params + n - 1;
}
if (VIR_STRDUP(str, value) < 0)
goto error;
if (virTypedParameterAssign(param, name,
VIR_TYPED_PARAM_STRING, str) < 0) {
param->value.s = old;
VIR_FREE(str);
goto error;
}
VIR_FREE(old);
*nparams = n;
return 0;
error:
return -1;
}
示例15: virProcessGetNamespaces
int virProcessGetNamespaces(pid_t pid,
size_t *nfdlist,
int **fdlist)
{
int ret = -1;
char *nsfile = NULL;
size_t i = 0;
const char *ns[] = { "user", "ipc", "uts", "net", "pid", "mnt" };
*nfdlist = 0;
*fdlist = NULL;
for (i = 0; i < ARRAY_CARDINALITY(ns); i++) {
int fd;
if (virAsprintf(&nsfile, "/proc/%llu/ns/%s",
(unsigned long long)pid,
ns[i]) < 0)
goto cleanup;
if ((fd = open(nsfile, O_RDONLY)) >= 0) {
if (VIR_EXPAND_N(*fdlist, *nfdlist, 1) < 0) {
VIR_FORCE_CLOSE(fd);
goto cleanup;
}
(*fdlist)[(*nfdlist)-1] = fd;
}
VIR_FREE(nsfile);
}
ret = 0;
cleanup:
VIR_FREE(nsfile);
if (ret < 0) {
for (i = 0; i < *nfdlist; i++)
VIR_FORCE_CLOSE((*fdlist)[i]);
VIR_FREE(*fdlist);
}
return ret;
}