Merge commit '4bce0b88b10ed790ad3669ce4ff61c945cd655eb' into HEAD

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
migration: unify stdio-based QEMUFile operations

Now that qemu_fseek does not exist anymore, there is no reason to do
an fseek before fread/fwrite when operating on an stdio file.
Thus, unify the get/put_buffer callbacks used by qemu_fopen
with those used for pipes.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
migration: consolidate QEMUFile methods in a single QEMUFileOps struct

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
migration: add qemu_get_fd

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
migration: replace qemu_stdio_fd with qemu_get_fd

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
migration: clean up server sockets and handlers before invoking process_incoming_migration

A first step towards making a common "suffix" for all migration protocols,
and moving it to process_incoming_migration.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
migration: use migrate_fd_close in migrate_fd_cleanup

migrate_fd_cleanup will usually close the file descriptor via
buffered_file_close's call to migrate_fd_close.  However, in the case
of s->file == NULL it is "inlining" migrate_fd_close (almost: there is a
direct close() instead of using s->close(s)).  To fix the inconsistency
and clean up the code, allow multiple calls to migrate_fd_close and use
the function in migrate_fd_cleanup.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
migration: use closesocket, not close

Windows requires this.  Migration does not quite work under Windows
but let's be uniform across QEMU.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
migration: xxx_close will only be called once

No need to test s->fd again, it is tested in the caller.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
migration: close socket QEMUFile from socket_close

The common suffix now is process_incoming_migration+qemu_fclose.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
migration: move qemu_fclose to process_incoming_migration

The common suffix is now just process_incoming_migration.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
migration: handle EAGAIN while reading QEMUFile

This will never happen right now (the assertion would fail).  The
next patch will set the socket or pipe in non-blocking mode, thus
enabling this part of the code.

Coroutines can just stop whenever they want with qemu_coroutine_yield.
As soon as select tells the main loop that the migration stream is
readable, the coroutine is re-entered directly in qemu_get_buffer,
where it will read more data and pass it to the loading routines.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
migration: move process_incoming_migration to a coroutine

The final part of incoming migration, which now consists of
process_incoming_migration for all protocols, is thus made non-blocking.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
9p-synth: fix read-side critical sections

The read-side critical sections in 9p-synth currently only include the
navigation of the list.  This is incorrect; it works for two reasons,
first obviously because rcu_read_lock/unlock are still no-ops; second,
because elements of the list are never deleted from the list (only added).
In fact, only adding items is the reason why rcu_read_lock/unlock can
be left as no-ops.

If items were deleted, they could be reclaimed as soon as the read-side
critical section ends.  So, the read-side critical section must include
all _usage_ of the node we got from the list too.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
9pfs-synth: use regular mutex

Even with the fix in the previous patch, the lockless handling of paths
in 9pfs-synth is wrong.  Paths can outlive rcu_read_unlock arbitrarily
via the V9fsPath objects that 9pfs-synth creates.  This would require
a reference counting mechanism that is not there and is quite hard to
retrofit.

It seems to me that this was a premature optimization, so replace
everything with a simple mutex.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
ff

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
stop/cont

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>