From 385c9027dbfd2a268a18d43b0f9c849f7e4b830f Mon Sep 17 00:00:00 2001 From: nick Date: Wed, 14 Aug 2013 13:30:25 +0100 Subject: [PATCH] flexnbd status: display mirror->max_bytes_per_second as mirror_speed_limit --- src/status.c | 9 ++++----- src/status.h | 1 + tests/unit/check_status.c | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/status.c b/src/status.c index 06e6620..13f0690 100644 --- a/src/status.c +++ b/src/status.c @@ -28,14 +28,10 @@ struct status * status_create( struct server * serve ) status->migration_duration = 0; } status->migration_duration /= 1000; - status->migration_speed = serve->mirror->all_dirty / ( status->migration_duration + 1 ); - - + status->migration_speed_limit = serve->mirror->max_bytes_per_second; } - - server_unlock_start_mirror( serve ); return status; @@ -63,6 +59,9 @@ int status_write( struct status * status, int fd ) PRINT_UINT64( pass_clean_bytes ); PRINT_UINT64( migration_speed ); PRINT_UINT64( migration_duration ); + if ( status->migration_speed_limit < UINT64_MAX ) { + PRINT_UINT64( migration_speed_limit ); + }; } dprintf(fd, "\n"); diff --git a/src/status.h b/src/status.h index 761635f..412c22d 100644 --- a/src/status.h +++ b/src/status.h @@ -80,6 +80,7 @@ struct status { uint64_t migration_duration; uint64_t migration_speed; + uint64_t migration_speed_limit; }; /** Create a status object for the given server. */ diff --git a/tests/unit/check_status.c b/tests/unit/check_status.c index fc8bb9b..ba9805c 100644 --- a/tests/unit/check_status.c +++ b/tests/unit/check_status.c @@ -125,6 +125,7 @@ START_TEST( test_gets_migration_statistics ) server->mirror->this_pass_clean = 2048; server->mirror->this_pass_dirty = 4096; server->mirror->all_dirty = 16384; + server->mirror->max_bytes_per_second = 32768; /* we have a bit of a time dependency here */ server->mirror->migration_started = monotonic_time_ms(); @@ -146,6 +147,8 @@ START_TEST( test_gets_migration_statistics ) "migration_speed not calculated correctly" ); + fail_unless( 32768 == status->migration_speed_limit, "migration_speed_limit not read" ); + status_destroy( status ); destroy_mock_server( server ); @@ -285,6 +288,7 @@ START_TEST( test_renders_migration_statistics ) status.pass_clean_bytes = 4096; status.migration_duration = 8; status.migration_speed = 40000000; + status.migration_speed_limit = 40000001; status_write( &status, fds[1] ); @@ -300,6 +304,8 @@ START_TEST( test_renders_migration_statistics ) fail_if( NULL != found, "migration_duration output when not migrating" ); found = strstr( buf, "migration_speed" ); fail_if( NULL != found, "migration_speed output when not migrating" ); + found = strstr( buf, "migration_speed_limit" ); + fail_if( NULL != found, "migration_speed_limit output when not migrating" ); status.is_mirroring = 1; status_write( &status, fds[1] ); @@ -314,6 +320,18 @@ START_TEST( test_renders_migration_statistics ) fail_if( NULL == found, "migration_duration not output when migrating" ); found = strstr( buf, "migration_speed=40000000" ); fail_if( NULL == found, "migration_speed not output when migrating" ); + found = strstr( buf, "migration_speed_limit=40000001" ); + fail_if( NULL == found, "migration_speed_limit not output when migrating" ); + + status.migration_speed_limit = UINT64_MAX; + status_write( &status, fds[1] ); + + fail_unless( read_until_newline( fds[0], buf, 1024 ) > 0, + "Couldn't read the result" ); + + found = strstr( buf, "migration_speed_limit" ); + fail_if( NULL != found, "migration_speed_limit output when no migration limit was set" ); + } END_TEST