mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
src/qemu: Utilize more of VIR_(APPEND|INSERT|DELETE)_ELEMENT
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
3f8b040d9a
commit
5ab80fc1ae
@ -10981,15 +10981,18 @@ qemuParseCommandLineCPU(virDomainDefPtr dom,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (j == dom->clock.ntimers) {
|
if (j == dom->clock.ntimers) {
|
||||||
if (VIR_REALLOC_N(dom->clock.timers, j + 1) < 0 ||
|
virDomainTimerDefPtr timer;
|
||||||
VIR_ALLOC(dom->clock.timers[j]) < 0)
|
if (VIR_ALLOC(timer) < 0 ||
|
||||||
|
VIR_APPEND_ELEMENT_COPY(dom->clock.timers,
|
||||||
|
dom->clock.ntimers, timer) < 0) {
|
||||||
|
VIR_FREE(timer);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
dom->clock.timers[j]->name = VIR_DOMAIN_TIMER_NAME_KVMCLOCK;
|
}
|
||||||
dom->clock.timers[j]->present = present;
|
timer->name = VIR_DOMAIN_TIMER_NAME_KVMCLOCK;
|
||||||
dom->clock.timers[j]->tickpolicy = -1;
|
timer->present = present;
|
||||||
dom->clock.timers[j]->track = -1;
|
timer->tickpolicy = -1;
|
||||||
dom->clock.timers[j]->mode = -1;
|
timer->track = -1;
|
||||||
dom->clock.ntimers++;
|
timer->mode = -1;
|
||||||
} else if (dom->clock.timers[j]->present != -1 &&
|
} else if (dom->clock.timers[j]->present != -1 &&
|
||||||
dom->clock.timers[j]->present != present) {
|
dom->clock.timers[j]->present != present) {
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
@ -11225,7 +11228,7 @@ qemuParseCommandLine(virCapsPtr qemuCaps,
|
|||||||
bool nographics = false;
|
bool nographics = false;
|
||||||
bool fullscreen = false;
|
bool fullscreen = false;
|
||||||
char *path;
|
char *path;
|
||||||
int nnics = 0;
|
size_t nnics = 0;
|
||||||
const char **nics = NULL;
|
const char **nics = NULL;
|
||||||
int video = VIR_DOMAIN_VIDEO_TYPE_CIRRUS;
|
int video = VIR_DOMAIN_VIDEO_TYPE_CIRRUS;
|
||||||
int nvirtiodisk = 0;
|
int nvirtiodisk = 0;
|
||||||
@ -11318,11 +11321,9 @@ qemuParseCommandLine(virCapsPtr qemuCaps,
|
|||||||
|
|
||||||
if (STREQ(arg, "-net")) {
|
if (STREQ(arg, "-net")) {
|
||||||
WANT_VALUE();
|
WANT_VALUE();
|
||||||
if (STRPREFIX(val, "nic")) {
|
if (STRPREFIX(val, "nic") &&
|
||||||
if (VIR_REALLOC_N(nics, nnics+1) < 0)
|
VIR_APPEND_ELEMENT(nics, nnics, val) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
nics[nnics++] = val;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -11456,11 +11457,10 @@ qemuParseCommandLine(virCapsPtr qemuCaps,
|
|||||||
vnc->data.vnc.autoport = false;
|
vnc->data.vnc.autoport = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_REALLOC_N(def->graphics, def->ngraphics+1) < 0) {
|
if (VIR_APPEND_ELEMENT(def->graphics, def->ngraphics, vnc) < 0) {
|
||||||
virDomainGraphicsDefFree(vnc);
|
virDomainGraphicsDefFree(vnc);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
def->graphics[def->ngraphics++] = vnc;
|
|
||||||
} else if (STREQ(arg, "-m")) {
|
} else if (STREQ(arg, "-m")) {
|
||||||
int mem;
|
int mem;
|
||||||
WANT_VALUE();
|
WANT_VALUE();
|
||||||
@ -11592,10 +11592,8 @@ qemuParseCommandLine(virCapsPtr qemuCaps,
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_REALLOC_N(def->disks, def->ndisks+1) < 0)
|
if (VIR_APPEND_ELEMENT(def->disks, def->ndisks, disk) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
def->disks[def->ndisks++] = disk;
|
|
||||||
disk = NULL;
|
|
||||||
} else if (STREQ(arg, "-no-acpi")) {
|
} else if (STREQ(arg, "-no-acpi")) {
|
||||||
def->features[VIR_DOMAIN_FEATURE_ACPI] = VIR_DOMAIN_FEATURE_STATE_DEFAULT;
|
def->features[VIR_DOMAIN_FEATURE_ACPI] = VIR_DOMAIN_FEATURE_STATE_DEFAULT;
|
||||||
} else if (STREQ(arg, "-no-reboot")) {
|
} else if (STREQ(arg, "-no-reboot")) {
|
||||||
@ -11732,13 +11730,12 @@ qemuParseCommandLine(virCapsPtr qemuCaps,
|
|||||||
virDomainChrDefFree(chr);
|
virDomainChrDefFree(chr);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (VIR_REALLOC_N(def->serials, def->nserials+1) < 0) {
|
chr->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL;
|
||||||
|
chr->target.port = def->nserials;
|
||||||
|
if (VIR_APPEND_ELEMENT(def->serials, def->nserials, chr) < 0) {
|
||||||
virDomainChrDefFree(chr);
|
virDomainChrDefFree(chr);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
chr->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL;
|
|
||||||
chr->target.port = def->nserials;
|
|
||||||
def->serials[def->nserials++] = chr;
|
|
||||||
}
|
}
|
||||||
} else if (STREQ(arg, "-parallel")) {
|
} else if (STREQ(arg, "-parallel")) {
|
||||||
WANT_VALUE();
|
WANT_VALUE();
|
||||||
@ -11752,13 +11749,12 @@ qemuParseCommandLine(virCapsPtr qemuCaps,
|
|||||||
virDomainChrDefFree(chr);
|
virDomainChrDefFree(chr);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (VIR_REALLOC_N(def->parallels, def->nparallels+1) < 0) {
|
chr->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL;
|
||||||
|
chr->target.port = def->nparallels;
|
||||||
|
if (VIR_APPEND_ELEMENT(def->parallels, def->nparallels, chr) < 0) {
|
||||||
virDomainChrDefFree(chr);
|
virDomainChrDefFree(chr);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
chr->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL;
|
|
||||||
chr->target.port = def->nparallels;
|
|
||||||
def->parallels[def->nparallels++] = chr;
|
|
||||||
}
|
}
|
||||||
} else if (STREQ(arg, "-usbdevice")) {
|
} else if (STREQ(arg, "-usbdevice")) {
|
||||||
WANT_VALUE();
|
WANT_VALUE();
|
||||||
@ -11794,19 +11790,16 @@ qemuParseCommandLine(virCapsPtr qemuCaps,
|
|||||||
disk->removable = VIR_DOMAIN_FEATURE_STATE_DEFAULT;
|
disk->removable = VIR_DOMAIN_FEATURE_STATE_DEFAULT;
|
||||||
if (VIR_STRDUP(disk->dst, "sda") < 0)
|
if (VIR_STRDUP(disk->dst, "sda") < 0)
|
||||||
goto error;
|
goto error;
|
||||||
if (VIR_REALLOC_N(def->disks, def->ndisks+1) < 0)
|
if (VIR_APPEND_ELEMENT(def->disks, def->ndisks, disk) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
def->disks[def->ndisks++] = disk;
|
|
||||||
disk = NULL;
|
|
||||||
} else {
|
} else {
|
||||||
virDomainHostdevDefPtr hostdev;
|
virDomainHostdevDefPtr hostdev;
|
||||||
if (!(hostdev = qemuParseCommandLineUSB(val)))
|
if (!(hostdev = qemuParseCommandLineUSB(val)))
|
||||||
goto error;
|
goto error;
|
||||||
if (VIR_REALLOC_N(def->hostdevs, def->nhostdevs+1) < 0) {
|
if (VIR_APPEND_ELEMENT(def->hostdevs, def->nhostdevs, hostdev) < 0) {
|
||||||
virDomainHostdevDefFree(hostdev);
|
virDomainHostdevDefFree(hostdev);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
def->hostdevs[def->nhostdevs++] = hostdev;
|
|
||||||
}
|
}
|
||||||
} else if (STREQ(arg, "-net")) {
|
} else if (STREQ(arg, "-net")) {
|
||||||
WANT_VALUE();
|
WANT_VALUE();
|
||||||
@ -11814,11 +11807,10 @@ qemuParseCommandLine(virCapsPtr qemuCaps,
|
|||||||
virDomainNetDefPtr net;
|
virDomainNetDefPtr net;
|
||||||
if (!(net = qemuParseCommandLineNet(xmlopt, val, nnics, nics)))
|
if (!(net = qemuParseCommandLineNet(xmlopt, val, nnics, nics)))
|
||||||
goto error;
|
goto error;
|
||||||
if (VIR_REALLOC_N(def->nets, def->nnets+1) < 0) {
|
if (VIR_APPEND_ELEMENT(def->nets, def->nnets, net) < 0) {
|
||||||
virDomainNetDefFree(net);
|
virDomainNetDefFree(net);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
def->nets[def->nnets++] = net;
|
|
||||||
}
|
}
|
||||||
} else if (STREQ(arg, "-drive")) {
|
} else if (STREQ(arg, "-drive")) {
|
||||||
WANT_VALUE();
|
WANT_VALUE();
|
||||||
@ -11826,23 +11818,19 @@ qemuParseCommandLine(virCapsPtr qemuCaps,
|
|||||||
nvirtiodisk,
|
nvirtiodisk,
|
||||||
ceph_args != NULL)))
|
ceph_args != NULL)))
|
||||||
goto error;
|
goto error;
|
||||||
if (VIR_REALLOC_N(def->disks, def->ndisks+1) < 0)
|
|
||||||
goto error;
|
|
||||||
if (disk->bus == VIR_DOMAIN_DISK_BUS_VIRTIO)
|
if (disk->bus == VIR_DOMAIN_DISK_BUS_VIRTIO)
|
||||||
nvirtiodisk++;
|
nvirtiodisk++;
|
||||||
|
if (VIR_APPEND_ELEMENT(def->disks, def->ndisks, disk) < 0)
|
||||||
def->disks[def->ndisks++] = disk;
|
goto error;
|
||||||
disk = NULL;
|
|
||||||
} else if (STREQ(arg, "-pcidevice")) {
|
} else if (STREQ(arg, "-pcidevice")) {
|
||||||
virDomainHostdevDefPtr hostdev;
|
virDomainHostdevDefPtr hostdev;
|
||||||
WANT_VALUE();
|
WANT_VALUE();
|
||||||
if (!(hostdev = qemuParseCommandLinePCI(val)))
|
if (!(hostdev = qemuParseCommandLinePCI(val)))
|
||||||
goto error;
|
goto error;
|
||||||
if (VIR_REALLOC_N(def->hostdevs, def->nhostdevs+1) < 0) {
|
if (VIR_APPEND_ELEMENT(def->hostdevs, def->nhostdevs, hostdev) < 0) {
|
||||||
virDomainHostdevDefFree(hostdev);
|
virDomainHostdevDefFree(hostdev);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
def->hostdevs[def->nhostdevs++] = hostdev;
|
|
||||||
} else if (STREQ(arg, "-soundhw")) {
|
} else if (STREQ(arg, "-soundhw")) {
|
||||||
const char *start;
|
const char *start;
|
||||||
WANT_VALUE();
|
WANT_VALUE();
|
||||||
@ -11867,11 +11855,10 @@ qemuParseCommandLine(virCapsPtr qemuCaps,
|
|||||||
if (VIR_ALLOC(snd) < 0)
|
if (VIR_ALLOC(snd) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
snd->model = type;
|
snd->model = type;
|
||||||
if (VIR_REALLOC_N(def->sounds, def->nsounds+1) < 0) {
|
if (VIR_APPEND_ELEMENT(def->sounds, def->nsounds, snd) < 0) {
|
||||||
VIR_FREE(snd);
|
VIR_FREE(snd);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
def->sounds[def->nsounds++] = snd;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
start = tmp ? tmp + 1 : NULL;
|
start = tmp ? tmp + 1 : NULL;
|
||||||
@ -12009,16 +11996,17 @@ qemuParseCommandLine(virCapsPtr qemuCaps,
|
|||||||
} else if (STREQ(arg, "-S")) {
|
} else if (STREQ(arg, "-S")) {
|
||||||
/* ignore, always added by libvirt */
|
/* ignore, always added by libvirt */
|
||||||
} else {
|
} else {
|
||||||
|
char *tmp = NULL;
|
||||||
/* something we can't yet parse. Add it to the qemu namespace
|
/* something we can't yet parse. Add it to the qemu namespace
|
||||||
* cmdline/environment advanced options and hope for the best
|
* cmdline/environment advanced options and hope for the best
|
||||||
*/
|
*/
|
||||||
VIR_WARN("unknown QEMU argument '%s', adding to the qemu namespace",
|
VIR_WARN("unknown QEMU argument '%s', adding to the qemu namespace",
|
||||||
arg);
|
arg);
|
||||||
if (VIR_REALLOC_N(cmd->args, cmd->num_args+1) < 0)
|
if (VIR_STRDUP(tmp, arg) < 0 ||
|
||||||
|
VIR_APPEND_ELEMENT(cmd->args, cmd->num_args, tmp) < 0) {
|
||||||
|
VIR_FREE(tmp);
|
||||||
goto error;
|
goto error;
|
||||||
if (VIR_STRDUP(cmd->args[cmd->num_args], arg) < 0)
|
}
|
||||||
goto error;
|
|
||||||
cmd->num_args++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -12112,11 +12100,10 @@ qemuParseCommandLine(virCapsPtr qemuCaps,
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_REALLOC_N(def->graphics, def->ngraphics+1) < 0) {
|
if (VIR_APPEND_ELEMENT(def->graphics, def->ngraphics, sdl) < 0) {
|
||||||
virDomainGraphicsDefFree(sdl);
|
virDomainGraphicsDefFree(sdl);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
def->graphics[def->ngraphics++] = sdl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (def->ngraphics) {
|
if (def->ngraphics) {
|
||||||
@ -12132,11 +12119,10 @@ qemuParseCommandLine(virCapsPtr qemuCaps,
|
|||||||
virDomainVideoDefaultRAM(def, vid->type) : 0;
|
virDomainVideoDefaultRAM(def, vid->type) : 0;
|
||||||
vid->heads = 1;
|
vid->heads = 1;
|
||||||
|
|
||||||
if (VIR_REALLOC_N(def->videos, def->nvideos+1) < 0) {
|
if (VIR_APPEND_ELEMENT(def->videos, def->nvideos, vid) < 0) {
|
||||||
virDomainVideoDefFree(vid);
|
virDomainVideoDefFree(vid);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
def->videos[def->nvideos++] = vid;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1084,13 +1084,7 @@ qemuRemoveSharedDevice(virQEMUDriverPtr driver,
|
|||||||
if (!(new_entry = qemuSharedDeviceEntryCopy(entry)))
|
if (!(new_entry = qemuSharedDeviceEntryCopy(entry)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (idx != new_entry->ref - 1)
|
VIR_DELETE_ELEMENT(new_entry->domains, idx, new_entry->ref);
|
||||||
memmove(&new_entry->domains[idx],
|
|
||||||
&new_entry->domains[idx + 1],
|
|
||||||
sizeof(*new_entry->domains) * (new_entry->ref - idx - 1));
|
|
||||||
|
|
||||||
VIR_SHRINK_N(new_entry->domains, new_entry->ref, 1);
|
|
||||||
|
|
||||||
if (virHashUpdateEntry(driver->sharedDevices, key, new_entry) < 0){
|
if (virHashUpdateEntry(driver->sharedDevices, key, new_entry) < 0){
|
||||||
qemuSharedDeviceEntryFree(new_entry, NULL);
|
qemuSharedDeviceEntryFree(new_entry, NULL);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
@ -248,7 +248,7 @@ struct _virQEMUDriver {
|
|||||||
typedef struct _qemuDomainCmdlineDef qemuDomainCmdlineDef;
|
typedef struct _qemuDomainCmdlineDef qemuDomainCmdlineDef;
|
||||||
typedef qemuDomainCmdlineDef *qemuDomainCmdlineDefPtr;
|
typedef qemuDomainCmdlineDef *qemuDomainCmdlineDefPtr;
|
||||||
struct _qemuDomainCmdlineDef {
|
struct _qemuDomainCmdlineDef {
|
||||||
unsigned int num_args;
|
size_t num_args;
|
||||||
char **args;
|
char **args;
|
||||||
|
|
||||||
unsigned int num_env;
|
unsigned int num_env;
|
||||||
|
@ -4044,17 +4044,19 @@ static int qemuDomainHotplugVcpus(virQEMUDriverPtr driver,
|
|||||||
*/
|
*/
|
||||||
virDomainVcpuPinDefPtr vcpupin = NULL;
|
virDomainVcpuPinDefPtr vcpupin = NULL;
|
||||||
|
|
||||||
if (VIR_REALLOC_N(vm->def->cputune.vcpupin,
|
|
||||||
vm->def->cputune.nvcpupin + 1) < 0)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if (VIR_ALLOC(vcpupin) < 0)
|
if (VIR_ALLOC(vcpupin) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
vcpupin->cpumask = virBitmapNew(VIR_DOMAIN_CPUMASK_LEN);
|
vcpupin->cpumask = virBitmapNew(VIR_DOMAIN_CPUMASK_LEN);
|
||||||
virBitmapCopy(vcpupin->cpumask, vm->def->cpumask);
|
virBitmapCopy(vcpupin->cpumask, vm->def->cpumask);
|
||||||
vcpupin->vcpuid = i;
|
vcpupin->vcpuid = i;
|
||||||
vm->def->cputune.vcpupin[vm->def->cputune.nvcpupin++] = vcpupin;
|
if (VIR_APPEND_ELEMENT_COPY(vm->def->cputune.vcpupin,
|
||||||
|
vm->def->cputune.nvcpupin, vcpupin) < 0) {
|
||||||
|
virBitmapFree(vcpupin->cpumask);
|
||||||
|
VIR_FREE(vcpupin);
|
||||||
|
ret = -1;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
if (cgroup_vcpu) {
|
if (cgroup_vcpu) {
|
||||||
if (qemuSetupCgroupVcpuPin(cgroup_vcpu,
|
if (qemuSetupCgroupVcpuPin(cgroup_vcpu,
|
||||||
|
@ -1212,7 +1212,7 @@ qemuMonitorJSONExtractCPUInfo(virJSONValuePtr reply,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_REALLOC_N(threads, ncpus) < 0)
|
if (VIR_ALLOC_N(threads, ncpus) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
for (i = 0; i < ncpus; i++) {
|
for (i = 0; i < ncpus; i++) {
|
||||||
|
@ -529,11 +529,10 @@ int qemuMonitorTextGetCPUInfo(qemuMonitorPtr mon,
|
|||||||
if (end == NULL || !c_isspace(*end))
|
if (end == NULL || !c_isspace(*end))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (VIR_REALLOC_N(cpupids, ncpupids+1) < 0)
|
if (VIR_APPEND_ELEMENT_COPY(cpupids, ncpupids, tid) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
VIR_DEBUG("tid=%d", tid);
|
VIR_DEBUG("tid=%d", tid);
|
||||||
cpupids[ncpupids++] = tid;
|
|
||||||
|
|
||||||
/* Skip to next data line */
|
/* Skip to next data line */
|
||||||
line = strchr(offset, '\r');
|
line = strchr(offset, '\r');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user