From cc468b0b1725d92e2dca382bb9c2e1f08946273f Mon Sep 17 00:00:00 2001 From: nick Date: Tue, 13 Aug 2013 12:30:18 +0100 Subject: [PATCH] control/mirror: Use uint64_t and strtoull to get max_Bps into the mirror --- src/control.c | 12 ++++++++++-- src/mirror.c | 10 +++++----- src/mirror.h | 6 +++--- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/control.c b/src/control.c index 76bb7d2..4482607 100644 --- a/src/control.c +++ b/src/control.c @@ -319,7 +319,7 @@ int control_mirror(struct control_client* client, int linesc, char** lines) struct flexnbd * flexnbd = client->flexnbd; union mysockaddr *connect_to = xmalloc( sizeof( union mysockaddr ) ); union mysockaddr *connect_from = NULL; - uint64_t max_Bps = 0; + uint64_t max_Bps = UINT64_MAX; int action_at_finish; int raw_port; @@ -367,7 +367,15 @@ int control_mirror(struct control_client* client, int linesc, char** lines) } if (linesc > 4) { - max_Bps = atoi(lines[4]); + errno = 0; + max_Bps = strtoull( lines[4], NULL, 10 ); + if ( errno == ERANGE ) { + write_socket( "1: max_bps out of range" ); + return -1; + } else if ( errno != 0 ) { + write_socket( "1: max_bps couldn't be parsed" ); + return -1; + } } diff --git a/src/mirror.c b/src/mirror.c index 2ae1159..85b6b48 100644 --- a/src/mirror.c +++ b/src/mirror.c @@ -82,8 +82,8 @@ struct mirror_ctrl { struct mirror * mirror_alloc( union mysockaddr * connect_to, union mysockaddr * connect_from, - int max_Bps, - int action_at_finish, + uint64_t max_Bps, + enum mirror_finish_action action_at_finish, struct mbox * commit_signal) { struct mirror * mirror; @@ -178,7 +178,7 @@ struct mirror * mirror_create( const char * filename, union mysockaddr * connect_to, union mysockaddr * connect_from, - int max_Bps, + uint64_t max_Bps, int action_at_finish, struct mbox * commit_signal) { @@ -816,8 +816,8 @@ struct mirror_super * mirror_super_create( const char * filename, union mysockaddr * connect_to, union mysockaddr * connect_from, - int max_Bps, - int action_at_finish, + uint64_t max_Bps, + enum mirror_finish_action action_at_finish, struct mbox * state_mbox) { struct mirror_super * super = xmalloc( sizeof( struct mirror_super) ); diff --git a/src/mirror.h b/src/mirror.h index 8986623..42414c3 100644 --- a/src/mirror.h +++ b/src/mirror.h @@ -73,7 +73,7 @@ struct mirror { /* Not used yet. Will be a limiter, used to restrict migration speed. * only dirty bytes (those going over the network) will be considered */ - off64_t max_bytes_per_second; + uint64_t max_bytes_per_second; enum mirror_finish_action action_at_finish; @@ -124,8 +124,8 @@ struct mirror_super * mirror_super_create( const char * filename, union mysockaddr * connect_to, union mysockaddr * connect_from, - int max_Bps, - int action_at_finish, + uint64_t max_Bps, + enum mirror_finish_action action_at_finish, struct mbox * state_mbox ); void * mirror_super_runner( void * serve_uncast );