flexnbd status: Add the size of the backing file, in bytes

This will be handy information if you're querying flexnbd for migration
stats, particularly.
This commit is contained in:
nick
2013-07-08 10:11:18 +01:00
parent f556f298b1
commit dee0bb27d6
3 changed files with 52 additions and 5 deletions

View File

@@ -5,12 +5,17 @@
#include <check.h>
void prepare_server( struct server* serve )
{
serve->mirror = NULL;
}
START_TEST( test_status_create )
{
struct server server;
struct status *status = NULL;
server.mirror = NULL;
prepare_server( &server );
status = status_create( &server );
fail_if( NULL == status, "Status wasn't allocated" );
@@ -23,7 +28,7 @@ START_TEST( test_gets_has_control )
struct server server;
struct status * status;
server.mirror = NULL;
prepare_server( &server );
server.success = 1;
status = status_create( &server );
@@ -38,7 +43,7 @@ START_TEST( test_gets_is_mirroring )
struct server server;
struct status * status;
server.mirror = NULL;
prepare_server( &server );
status = status_create( &server );
fail_if( status->is_mirroring, "is_mirroring was set" );
status_destroy( status );
@@ -55,7 +60,7 @@ START_TEST( test_gets_migration_pass )
struct server server;
struct status * status;
server.mirror = NULL;
prepare_server( &server );
status = status_create( &server );
fail_if( status->migration_pass != 0, "migration_pass was set" );
status_destroy( status );
@@ -75,7 +80,7 @@ START_TEST( test_gets_pid )
struct server server;
struct status * status;
server.mirror = NULL;
prepare_server( &server );
status = status_create( &server );
fail_unless( getpid() == status->pid, "Pid wasn't gathered" );
@@ -84,6 +89,21 @@ START_TEST( test_gets_pid )
}
END_TEST
START_TEST( test_gets_size )
{
struct server server;
struct status * status;
prepare_server( &server );
server.size = 1024;
status = status_create( &server );
fail_unless( 1024 == status->size, "Size wasn't gathered" );
status_destroy( status );
}
END_TEST
START_TEST( test_renders_has_control )
{
@@ -158,6 +178,23 @@ START_TEST( test_renders_pid )
}
END_TEST
START_TEST( test_renders_size )
{
struct status status;
int fds[2];
pipe(fds);
char buf[1024] = {0};
status.size = ( (uint64_t)1 << 33 );
status_write( &status, fds[1] );
fail_unless( read_until_newline( fds[0], buf, 1024 ) > 0,
"Couldn't read the result" );
char *found = strstr( buf, "size=8589934592" );
fail_if( NULL == found, "size=8589934592 not found" );
}
END_TEST
START_TEST( test_renders_migration_pass )
{
struct status status;
@@ -199,11 +236,13 @@ Suite *status_suite(void)
tcase_add_test(tc_create, test_gets_has_control);
tcase_add_test(tc_create, test_gets_is_mirroring);
tcase_add_test(tc_create, test_gets_pid);
tcase_add_test(tc_create, test_gets_size);
tcase_add_test(tc_create, test_gets_migration_pass);
tcase_add_test(tc_render, test_renders_has_control);
tcase_add_test(tc_render, test_renders_is_mirroring);
tcase_add_test(tc_render, test_renders_pid);
tcase_add_test(tc_render, test_renders_size);
tcase_add_test(tc_render, test_renders_migration_pass);
suite_add_tcase(s, tc_create);