Daniel P. Berrangé <berra...@redhat.com> writes: > On Mon, Oct 30, 2023 at 07:51:34PM -0300, Fabiano Rosas wrote: >> I could use some advice on how to solve this situation. The fdset code >> at monitor/fds.c and the add-fd command don't seem to be usable outside >> the original use-case of passing fds with different open flags. >> >> There are several problems, the biggest one being that there's no way to >> manipulate the set of file descriptors aside from asking for duplication >> of an fd that matches a particular set of flags. >> >> That doesn't work for us because the two fds we need (one for main >> channel, other for secondary channels) will have the same open flags. So >> the fdset code will always return the first one it finds in the set. > > QEMU may want multiple FDs *internally*, but IMHO that fact should > not be exposed to mgmt applications. It would be valid for a QEMU > impl to share the same FD across multiple threads, or have a different > FD for each thread. All threads are using pread/pwrite, so it is safe > for them to use the same FD if they desire. It is a private impl choice > for QEMU at any given point in time and could change over time. >
Sure, I don't disagree. However up until last week we had a seemingly usable "add-fd" command that allows the user to provide a *set of file descriptors* to QEMU. It's just now that we're learning that interface serves only a special use-case. > Thus from the POV of the mgmt app, QEMU is writing to a single file, no > matter how many threads are involved & thus it should only need to supply > a single FD for thta file. QEMU can then call 'dup()' on that FD as many > times as it desires, and use fcntl() to toggle O_DIRECT if and when > it needs to. Ok, so I think the way to go here is for QEMU to receive a file + offset instead of an FD. That way QEMU can have adequate control of the resources for the migration. I don't remember why we went on the FD tangent. Is it not acceptable for libvirt to provide the file name + offset? >> Another problem (or feature) of the fdset code is that it only removes >> an fd when qmp_remove_fd() is called if the VM runstate is RUNNING, >> which means that the migration code cannot remove the fds after use >> reliably. We need to be able to remove them to make sure we use the >> correct fds in a subsequent migration. > > The "easy" option is to just add a new API that does what you want. > Maybe during review someone will then point out why the orgianl > API works the way it does. Hehe so I'll add a qmp_actually_remove_fd() =)