From 66ff06fe0e7bdf62d11af25fddf236c5049f1cec Mon Sep 17 00:00:00 2001 From: Alex Young Date: Mon, 16 Jul 2012 11:21:56 +0100 Subject: [PATCH] Block a second mirror attempt If a second mirror command is run while the first is still going, flexnbd needs to prevent the second because we only have one dirty map. Also, the shutdown becomes Complicated if we allow more than one mirror at a time. --- src/control.c | 48 +++++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/src/control.c b/src/control.c index d36c25b..a756f4c 100644 --- a/src/control.c +++ b/src/control.c @@ -361,29 +361,35 @@ int control_mirror(struct control_client* client, int linesc, char** lines) flexnbd_lock_switch( flexnbd ); { struct server * serve = flexnbd_server(flexnbd); - serve->mirror_super = mirror_super_create( - serve->filename, - connect_to, - connect_from, - max_Bps , - action_at_finish, - client->mirror_state_mbox ); - serve->mirror = serve->mirror_super->mirror; - FATAL_IF( 0 != pthread_create( - &serve->mirror_super->thread, - NULL, - mirror_super_runner, - serve - ), - "Failed to create mirror thread" - ); + if ( serve->mirror_super ) { + warn( "Tried to start a second mirror run" ); + write_socket( "1: mirror already running" ); + } else { + serve->mirror_super = mirror_super_create( + serve->filename, + connect_to, + connect_from, + max_Bps , + action_at_finish, + client->mirror_state_mbox ); + serve->mirror = serve->mirror_super->mirror; - debug("Control thread mirror super waiting"); - enum mirror_state state = - control_client_mirror_wait( client ); - debug("Control thread writing response"); - control_write_mirror_response( state, client->socket ); + FATAL_IF( 0 != pthread_create( + &serve->mirror_super->thread, + NULL, + mirror_super_runner, + serve + ), + "Failed to create mirror thread" + ); + + debug("Control thread mirror super waiting"); + enum mirror_state state = + control_client_mirror_wait( client ); + debug("Control thread writing response"); + control_write_mirror_response( state, client->socket ); + } } debug( "Control thread unlocking switch" ); flexnbd_unlock_switch( flexnbd );