This function is then used to simplify port assignment. It will also be used in upcoming patches. --- src/conf/domain_conf.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index e65f3e3..2bade1b 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -10896,6 +10896,21 @@ virDomainDefMaybeAddController(virDomainDefPtr def, return 0; } +/* Returns the highest port number among all the virtio-serial channels + * using the controller with index idx (or -1 if no channel uses it). */ +static int +virDomainGetVirtioSerialMaxPort(virDomainDefPtr def, int idx) +{ + size_t i; + int maxport = -1; + for (i = 0; i < def->nchannels; i++) { + if (def->channels[i]->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_SERIAL && + def->channels[i]->info.addr.vioserial.controller == idx && + (int)def->channels[i]->info.addr.vioserial.port > maxport) + maxport = def->channels[i]->info.addr.vioserial.port; + } + return maxport; +} /* Parse a memory element located at XPATH within CTXT, and store the * result into MEM. If REQUIRED, then the value must exist; @@ -12233,18 +12248,13 @@ virDomainDefParseXML(xmlDocPtr xml, chr->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) chr->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_SERIAL; + /* assign next port available on controller */ if (chr->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_SERIAL && chr->info.addr.vioserial.port == 0) { - int maxport = 0; - size_t j; - for (j = 0; j < i; j++) { - virDomainChrDefPtr thischr = def->channels[j]; - if (thischr->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_SERIAL && - thischr->info.addr.vioserial.controller == chr->info.addr.vioserial.controller && - thischr->info.addr.vioserial.bus == chr->info.addr.vioserial.bus && - (int)thischr->info.addr.vioserial.port > maxport) - maxport = thischr->info.addr.vioserial.port; - } + int maxport = virDomainGetVirtioSerialMaxPort + (def, chr->info.addr.vioserial.controller); + if (maxport < 0) + maxport = 0; chr->info.addr.vioserial.port = maxport + 1; } } -- 1.8.3.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list