/*
* capabilities.c: hypervisor capabilities
*
- * Copyright (C) 2006-2008 Red Hat, Inc.
+ * Copyright (C) 2006-2008, 2010 Red Hat, Inc.
* Copyright (C) 2006-2008 Daniel P. Berrange
*
* This library is free software; you can redistribute it and/or
virCapabilitiesAddHostFeature(virCapsPtr caps,
const char *name)
{
- if (VIR_REALLOC_N(caps->host.features,
- caps->host.nfeatures + 1) < 0)
+ if (VIR_RESIZE_N(caps->host.features, caps->host.nfeatures_max,
+ caps->host.nfeatures, 1) < 0)
return -1;
if ((caps->host.features[caps->host.nfeatures] = strdup(name)) == NULL)
virCapabilitiesAddHostMigrateTransport(virCapsPtr caps,
const char *name)
{
- if (VIR_REALLOC_N(caps->host.migrateTrans,
- caps->host.nmigrateTrans + 1) < 0)
+ if (VIR_RESIZE_N(caps->host.migrateTrans, caps->host.nmigrateTrans_max,
+ caps->host.nmigrateTrans, 1) < 0)
return -1;
if ((caps->host.migrateTrans[caps->host.nmigrateTrans] = strdup(name)) == NULL)
{
virCapsHostNUMACellPtr cell;
- if (VIR_REALLOC_N(caps->host.numaCell,
- caps->host.nnumaCell + 1) < 0)
+ if (VIR_RESIZE_N(caps->host.numaCell, caps->host.nnumaCell_max,
+ caps->host.nnumaCell, 1) < 0)
return -1;
if (VIR_ALLOC(cell) < 0)
cell->ncpus = ncpus;
cell->num = num;
- caps->host.numaCell[caps->host.nnumaCell] = cell;
- caps->host.nnumaCell++;
+ caps->host.numaCell[caps->host.nnumaCell++] = cell;
return 0;
}
(guest->arch.defaultInfo.loader = strdup(loader)) == NULL)
goto no_memory;
- if (VIR_REALLOC_N(caps->guests,
- caps->nguests + 1) < 0)
+ if (VIR_RESIZE_N(caps->guests, caps->nguests_max,
+ caps->nguests, 1) < 0)
goto no_memory;
- caps->guests[caps->nguests] = guest;
- caps->nguests++;
+ caps->guests[caps->nguests++] = guest;
if (nmachines) {
guest->arch.defaultInfo.nmachines = nmachines;
(dom->info.loader = strdup(loader)) == NULL)
goto no_memory;
- if (VIR_REALLOC_N(guest->arch.domains,
- guest->arch.ndomains + 1) < 0)
+ if (VIR_RESIZE_N(guest->arch.domains, guest->arch.ndomains_max,
+ guest->arch.ndomains, 1) < 0)
goto no_memory;
guest->arch.domains[guest->arch.ndomains] = dom;
guest->arch.ndomains++;
feature->defaultOn = defaultOn;
feature->toggle = toggle;
- if (VIR_REALLOC_N(guest->features,
- guest->nfeatures + 1) < 0)
+ if (VIR_RESIZE_N(guest->features, guest->nfeatures_max,
+ guest->nfeatures, 1) < 0)
goto no_memory;
- guest->features[guest->nfeatures] = feature;
- guest->nfeatures++;
+ guest->features[guest->nfeatures++] = feature;
return feature;
if (caps->host.nnumaCell) {
virBufferAddLit(&xml, " <topology>\n");
- virBufferVSprintf(&xml, " <cells num='%d'>\n",
+ virBufferVSprintf(&xml, " <cells num='%zu'>\n",
caps->host.nnumaCell);
for (i = 0 ; i < caps->host.nnumaCell ; i++) {
virBufferVSprintf(&xml, " <cell id='%d'>\n",
/*
* capabilities.h: hypervisor capabilities
*
- * Copyright (C) 2006-2008 Red Hat, Inc.
+ * Copyright (C) 2006-2008, 2010 Red Hat, Inc.
* Copyright (C) 2006-2008 Daniel P. Berrange
*
* This library is free software; you can redistribute it and/or
char *name;
int wordsize;
virCapsGuestDomainInfo defaultInfo;
- int ndomains;
+ size_t ndomains;
+ size_t ndomains_max;
virCapsGuestDomainPtr *domains;
};
struct _virCapsGuest {
char *ostype;
virCapsGuestArch arch;
- int nfeatures;
+ size_t nfeatures;
+ size_t nfeatures_max;
virCapsGuestFeaturePtr *features;
};
typedef virCapsHost *virCapsHostPtr;
struct _virCapsHost {
char *arch;
- int nfeatures;
+ size_t nfeatures;
+ size_t nfeatures_max;
char **features;
int offlineMigrate;
int liveMigrate;
- int nmigrateTrans;
+ size_t nmigrateTrans;
+ size_t nmigrateTrans_max;
char **migrateTrans;
- int nnumaCell;
+ size_t nnumaCell;
+ size_t nnumaCell_max;
virCapsHostNUMACellPtr *numaCell;
virCapsHostSecModel secModel;
virCPUDefPtr cpu;
typedef virCaps* virCapsPtr;
struct _virCaps {
virCapsHost host;
- int nguests;
+ size_t nguests;
+ size_t nguests_max;
virCapsGuestPtr *guests;
unsigned char macPrefix[VIR_MAC_PREFIX_BUFLEN];
unsigned int emulatorRequired : 1;
|| (cpu->vendor && !(copy->vendor = strdup(cpu->vendor)))
|| VIR_ALLOC_N(copy->features, cpu->nfeatures) < 0)
goto no_memory;
+ copy->nfeatures_max = cpu->nfeatures;
copy->type = cpu->type;
copy->match = cpu->match;
goto error;
}
- if (VIR_ALLOC_N(def->features, n) < 0)
+ if (VIR_RESIZE_N(def->features, def->nfeatures_max,
+ def->nfeatures, n) < 0)
goto no_memory;
def->nfeatures = n;
}
}
}
- if (VIR_REALLOC_N(def->features, def->nfeatures + 1) < 0)
+ if (VIR_RESIZE_N(def->features, def->nfeatures_max,
+ def->nfeatures, 1) < 0)
goto no_memory;
if (def->type == VIR_CPU_TYPE_HOST)