X-Git-Url: http://git.alex.org.uk diff --git a/nbd-tester-client.c b/nbd-tester-client.c index 40a6363..f97a4ee 100644 --- a/nbd-tester-client.c +++ b/nbd-tester-client.c @@ -23,6 +23,7 @@ */ #include #include +#include #include #include #include @@ -40,6 +41,8 @@ static gchar errstr[1024]; const static int errstr_len=1024; +static uint64_t size; + typedef enum { CONNECTION_TYPE_NONE, CONNECTION_TYPE_CONNECT, @@ -69,12 +72,14 @@ inline int read_all(int f, void *buf, size_t len) { return retval; } -int setup_connection(gchar *hostname, int port, CONNECTION_TYPE ctype) { +int setup_connection(gchar *hostname, int port, gchar* name, CONNECTION_TYPE ctype) { int sock; struct hostent *host; struct sockaddr_in addr; char buf[256]; + uint64_t mymagic = (name ? opts_magic : cliserv_magic); u64 tmp64; + uint32_t tmp32 = 0; sock=0; if(ctype1024) { speed>>=10; @@ -313,7 +384,7 @@ int throughput_test(gchar* hostname, int port, int sock, char sock_is_open, char speed>>=10; speedchar[0]='G'; } - g_message("Throughput test complete. Took %.3f seconds to complete, %d%sB/s",timespan,speed,speedchar); + g_message("%d: Throughput test complete. Took %.3f seconds to complete, %d%siB/s", (int)getpid(), timespan,speed,speedchar); err_open: if(close_sock) { @@ -323,28 +394,56 @@ err: return retval; } +typedef int (*testfunc)(gchar*, int, char*, int, char, char); + int main(int argc, char**argv) { gchar *hostname; - long int p; - int port; + long int p = 0; + char* name = NULL; int sock=0; + char c; + bool want_port = TRUE; + int nonopt=0; + testfunc test = throughput_test; if(argc<3) { - g_message("Not enough arguments"); - g_message("Usage: %s ", argv[0]); + g_message("%d: Not enough arguments", (int)getpid()); + g_message("%d: Usage: %s ", (int)getpid(), argv[0]); + g_message("%d: Or: %s -N ", (int)getpid(), argv[0]); exit(EXIT_FAILURE); } logging(); - hostname=g_strdup(argv[1]); - p=(strtol(argv[2], NULL, 0)); - if(p==LONG_MIN||p==LONG_MAX) { - g_critical("Could not parse port number: %s", strerror(errno)); - exit(EXIT_FAILURE); + while((c=getopt(argc, argv, "-N:o"))>=0) { + switch(c) { + case 1: + switch(nonopt) { + case 0: + hostname=g_strdup(optarg); + nonopt++; + break; + case 1: + if(want_port) + p=(strtol(argv[2], NULL, 0)); + if(p==LONG_MIN||p==LONG_MAX) { + g_critical("Could not parse port number: %s", strerror(errno)); + exit(EXIT_FAILURE); + } + break; + } + break; + case 'N': + name=g_strdup(optarg); + p = 10809; + want_port = false; + break; + case 'o': + test=oversize_test; + break; + } } - port=(int)p; - if(throughput_test(hostname, port, sock, FALSE, TRUE)<0) { - g_warning("Could not run throughput test: %s", errstr); + if(test(hostname, (int)p, name, sock, FALSE, TRUE)<0) { + g_warning("Could not run test: %s", errstr); exit(EXIT_FAILURE); }