[libvirt] [PATCH v1 4/7] qemu: Allow regeneration of aliases

Daniel P. Berrange berrange at redhat.com
Fri Sep 22 08:43:39 UTC 2017


On Fri, Sep 22, 2017 at 10:25:46AM +0200, Peter Krempa wrote:
> On Fri, Sep 22, 2017 at 10:18:02 +0200, Michal Privoznik wrote:
> > On 09/21/2017 07:18 PM, Daniel P. Berrange wrote:
> > > On Thu, Sep 21, 2017 at 06:05:19PM +0200, Peter Krempa wrote:
> > >> On Thu, Sep 21, 2017 at 16:47:08 +0200, Michal Privoznik wrote:
> > >>> In the near future the qemuAssignDeviceAliases() function is
> > >>> going to be called multiple times: once at the domain define
> > >>> time, then in domain prepare phase. To avoid regenerating the
> > >>> same aliases the second time we need to be able to tell the
> > >>> function which time it is being called.
> > >>>
> > >>> Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
> > >>> ---
> > >>>  src/qemu/qemu_alias.c   | 113 ++++++++++++++++++++++++++++++++++++++++++++++--
> > >>>  src/qemu/qemu_alias.h   |   4 +-
> > >>>  src/qemu/qemu_driver.c  |   2 +-
> > >>>  src/qemu/qemu_process.c |   2 +-
> > >>>  tests/qemuhotplugtest.c |   2 +-
> > >>>  5 files changed, 115 insertions(+), 8 deletions(-)
> > >>>
> > 
> > >> So if you want to make aliases persistent, at least this will not work
> > >> properly with device coldplug.
> > 
> > Ah, good point.
> > 
> > >>
> > >> If you have two devices, detach the first one, then the second one moves
> > >> to index 0 but will still have alias ending with 1. Then if you cold-add
> > >> another device that will be put into index 1, and when starting the VM
> > >> it will get assigned the same alias as the one which has the old one.
> > >>
> > >> This applies to all devices where the alias depends on the ordering.
> > > 
> > > Yep, we would need to maintain a  hash table remembering all currently
> > > assigned aliases, and then increment the counter until we find a free
> > > one for that dev type.
> > 
> > Alternatively, every time we want to assign an alias for a device we
> > traverse its siblings and see if it's taken.
> > 
> > for (i = 0; ; i++) {
> >     alias = "device$i";
> >     for (j = 0; j < def->ndevice; j++) {
> >         if (STREQ(def->device[j]->info.alias, alias))
> >             continue;
> >         break
> >     }
> >     if (j != def->ndevice) {
> >         /* alias is free */
> >         device->alias = alias;
> >         break;
> >     }
> > }
> 
> You can also generate them of a global sequence number. Qemu does not
> care that they are not consecutive. It might trigger some OCD based eye
> twitching, but it's way less yucky.

Yeah a single global counter would be reasonable IMHO. Still has a little
cpu time to initialize it when libvirtd starts up & loads persistent
configs, but that's not unreasonable.


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|




More information about the libvir-list mailing list