On 27.09.2013 11:36, Wangyufei (A) wrote: > Yes, I get your point. > > this_port = QEMUD_MIGRATION_FIRST_PORT + port++; > if (port == QEMUD_MIGRATION_NUM_PORTS) > port = 0; In fact this won't work either. What if this_port is already taken by another app? virPortAllocator ensures such situation won't happen (*). Michal (*) Okay, I should rather say 'virPortAllocator minimizes the chance of race' as there is still a small window for race. The virPortAllocator is used for allocating a VNC port, for instance. So whenever a domain with autoport for VNC is start, a free port is searched and bind()-ed. Then, the port number is put onto qemu cmd line. And here comes the race: libvirtd fork()s and close all FDs that are not to be transferred to the qemu process. After this the execve("qemu", ...) is called. So the race window begins at the FDs closing and ends when qemu decide to bind() to the given port. But there's no better way to do this (until qemu learns that VNC port socket can be passed as a FD). -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list