Fix two bugs in mirroring.

First, Leaving off the source address caused a segfault in the
command-sending process because there was no NULL check on the ARGV
entry.

Second, while the migration thread sent a signal to the server to close
on successful completion, it didn't wait until the close actually
happened before releasing the IO lock.  This meant that any client
thread waiting on that IO lock could have a read or a write queued up
which could succeed despite the server shutdown.  This would have meant
dataloss as the guest would see a successful write to the wrong instance
of the file.  This patch adds a noddy serve_wait_for_close() function
which the mirror_runner calls to ensure that any clients will reject
operations they're waiting to complete.

This patch also adds a simple scenario test for migration, and fixes
TempFileWriter#read_original.
This commit is contained in:
Alex Young
2012-06-13 13:44:21 +01:00
parent b986f6b63e
commit 7d1c15b07a
7 changed files with 139 additions and 21 deletions

View File

@@ -58,6 +58,9 @@ void* mirror_runner(void* serve_params_uncast)
const int last_pass = mirror_maximum_passes-1;
int pass;
struct server *serve = (struct server*) serve_params_uncast;
NULLCHECK( serve );
debug("Starting mirror" );
struct bitset_mapping *map = serve->mirror->dirty_map;
for (pass=0; pass < mirror_maximum_passes; pass++) {
@@ -135,8 +138,18 @@ void* mirror_runner(void* serve_params_uncast)
{
case ACTION_EXIT:
debug("exit!");
close(serve->mirror->client);
serve_signal_close( serve );
/* We have to wait until the server is closed before
* unlocking IO. This is because the client threads
* check to see if the server is still open before
* reading or writing inside their own locks. If we
* don't wait for the close, there's no way to guarantee
* the server thread will win the race and we risk the
* clients seeing a "successful" write to a dead disc
* image.
*/
serve_wait_for_close( serve );
info("Server closed, quitting after successful migration");
/* fall through */
case ACTION_NOTHING:
debug("nothing!");

View File

@@ -30,7 +30,9 @@ void do_remote_command(char* command, char* socket_name, int argc, char** argv)
write(remote, command, strlen(command));
write(remote, &newline, 1);
for (i=0; i<argc; i++) {
write(remote, argv[i], strlen(argv[i]));
if ( NULL != argv[i] ) {
write(remote, argv[i], strlen(argv[i]));
}
write(remote, &newline, 1);
}
write(remote, &newline, 1);

View File

@@ -559,6 +559,15 @@ void serve_signal_close( struct server * serve )
self_pipe_signal( serve->close_signal );
}
/* Block until the server closes the server_fd.
*/
void serve_wait_for_close( struct server * serve )
{
while( !fd_is_closed( serve->server_fd ) ){
usleep(10000);
}
}
/** Closes sockets, frees memory and waits for all client threads to finish */
void serve_cleanup(struct server* params,

View File

@@ -86,6 +86,7 @@ void server_dirty(struct server *serve, off64_t from, int len);
void server_lock_io( struct server * serve);
void server_unlock_io( struct server* serve );
void serve_signal_close( struct server *serve );
void serve_wait_for_close( struct server * serve );
void server_replace_acl( struct server *serve, struct acl * acl);