On Thu, Jun 06, 2013 at 14:30:03 +0200, Michal Privoznik wrote: > The chardev alias assignment is going to be needed in a separate > places, so it should be moved into a separate function rather > than copying code randomly around. > --- > src/qemu/qemu_command.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++--- > src/qemu/qemu_command.h | 3 +++ > 2 files changed, 65 insertions(+), 4 deletions(-) > > diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c > index c4a162a..39b9d24 100644 > --- a/src/qemu/qemu_command.c > +++ b/src/qemu/qemu_command.c > @@ -891,6 +891,64 @@ qemuAssignDeviceControllerAlias(virDomainControllerDefPtr controller) > return 0; > } > > +int > +qemuAssignDeviceChrAlias(virDomainDefPtr def, > + virDomainChrDefPtr chr, > + size_t idx) Since you want to pass -1 as idx, you should declare it as signed > +{ > + virDomainChrDefPtr **arrPtr; > + size_t *cntPtr; > + const char *prefix; > + > + if (virDomainChrGetDomainPtrs(def, chr, &arrPtr, &cntPtr) < 0) > + return -1; > + > + switch ((enum virDomainChrDeviceType) chr->deviceType) { > + case VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL: > + prefix = "parallel"; > + break; > + > + case VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL: > + prefix = "serial"; > + break; > + > + case VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE: > + prefix = "console"; > + break; > + > + case VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL: > + prefix = "channel"; > + break; > + > + default: > + virReportError(VIR_ERR_OPERATION_INVALID, > + _("Unsupported device type '%d'"), > + chr->deviceType); > + return -1; > + } > + > + if (idx == -1) { > + size_t i; > + idx = 0; > + for (i = 0; i < *cntPtr; i++) { > + int thisidx; > + if ((thisidx = qemuDomainDeviceAliasIndex(&(*arrPtr)[i]->info, prefix)) < 0) { > + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", > + _("Unable to determine device index for character device")); > + return -1; > + } > + if (thisidx >= idx) > + idx = thisidx + 1; > + } > + } > + > + if (virAsprintf(&chr->info.alias, "%s%zu", prefix, idx) < 0) { and update %zu to be signed, too. > + virReportOOMError(); > + return -1; > + } > + > + return 0; > +} ACK with the change. Jirka -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list