1

I'm switching some VMs from VNC display type to SPICE.

VNC display type offers a very handy to= parameter allowing QEMU to automatically use the first free port from a defined range:

-display vnc=127.0.0.1:0,to=100

Here QEMU will use ports between 5900 and 6000 for each new VNC display server.

What is the cleanest way to achieve such functionality with SPICE display (by the way I'm not using libvirt)?

Currently I'm on my way to script a test greping netstat output to find a yet unused port and pass it to:

-spice addr=127.0.0.1,port=${unused_port}

Without mentioning race conditions, I just find this method quite ugly compared to the VNC one. And since QEMU manpage does not seem very exhaustive (VNC to= parameter doesn't seem mentioned for instance), then I wonder if by any chance there is an equivalent parameter for SPICE?

1

It is (currently) not possible to let QEMU pick the next free port for SPICE. This happens because of an implementation detail: QEMU uses the spice_server_set_port which only accepts a single numeric parameter.

The best you can do now is to pick a port number outside QEMU and assign it as you do now.

If you find this too clumsy, consider using DNS to bind to the first free IP address + port available. The SPICE server code tries every address until it succeeds, so if you map local.test to 127.0.0.1, 127.0.0.2, 127.0.0.3, etc., then it will attempt to bind to each of these interfaces until one succeeds. Sounds awful, but it could be useful. Note that this method is only possible if you have no other service listening on the same port on the wildcard address.

  • Yes, that's what I saw in the Qemu source too: SPICE implements its own functions to open a listening port instead of relying on Qemu common ones as VNC does, hence the behaviour difference. – WhiteWinterWolf Aug 8 '15 at 14:28
  • 1
    I noticed that libvirt has an "auto" option for SPICE. It turns out that libvirt has a legacy option which treats "-1" as a special value for allocating a free port number using its internal port allocator. This functionality is similar to testing netstat yourself. – Lekensteyn Aug 8 '15 at 17:27
  • But it requires using libvirt as a supplementary layer over Qemu/KVM which I prefer to avoid. However I +1 your comment since it may help other people :). – WhiteWinterWolf Aug 8 '15 at 17:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.