rep.magic=ntohl(rep.magic);
rep.error=ntohl(rep.error);
if(rep.magic!=NBD_REPLY_MAGIC) {
- snprintf(errstr, errstr_len, "Received package with incorrect reply_magic. Index of sent packages is %lld (0x%llX), received handle is %lld (0x%llX). Received magic 0x%lX, expected 0x%lX", curhandle, curhandle, *((u64*)rep.handle), *((u64*)rep.handle), rep.magic, NBD_REPLY_MAGIC);
+ snprintf(errstr, errstr_len, "Received package with incorrect reply_magic. Index of sent packages is %lld (0x%llX), received handle is %lld (0x%llX). Received magic 0x%lX, expected 0x%lX", curhandle, curhandle, *((u64*)rep.handle), *((u64*)rep.handle), (long unsigned int)rep.magic, (long unsigned int)NBD_REPLY_MAGIC);
retval=-1;
goto end;
}
if(rep.error) {
- snprintf(errstr, errstr_len, "Received error from server: %ld (0x%lX). Handle is %lld (0x%llX).", rep.error, *((u64*)rep.handle), *((u64*)rep.handle));
+ snprintf(errstr, errstr_len, "Received error from server: %ld (0x%lX). Handle is %lld (0x%llX).", (long int)rep.error, (long unsigned int)rep.error, (long long int)(*((u64*)rep.handle)), *((u64*)rep.handle));
retval=-1;
goto end;
}
int requests=0;
fd_set set;
struct timeval tv;
+ struct timeval start;
+ struct timeval stop;
+ float timespan;
+ int speed;
+ char speedchar[2] = { '\0', '\0' };
int retval=0;
size_t tmp;
signed int do_write=TRUE;
+ size=0;
if(!sock_is_open) {
if((sock=setup_connection(hostname, port, CONNECTION_TYPE_CLISERV))<0) {
g_warning("Could not open socket: %s", errstr);
* this way, but, well. */
size=4096;
}
- size=0;
if((tmp=read_all(sock, &size, sizeof(u64)))<0) {
retval=-1;
snprintf(errstr, errstr_len, "Could not read from socket: %s", strerror(errno));
req.magic=htonl(NBD_REQUEST_MAGIC);
req.type=htonl(NBD_CMD_READ);
req.len=htonl(1024);
+ if(gettimeofday(&start, NULL)<0) {
+ retval=-1;
+ snprintf(errstr, errstr_len, "Could not measure start time: %s", strerror(errno));
+ goto err_open;
+ }
for(i=0;i+1024<=size;i+=1024) {
if(do_write) {
*((u64*)req.handle)=i;
printf("Requests(-): %d\n", --requests);
}
} while (requests);
+ if(gettimeofday(&stop, NULL)<0) {
+ retval=-1;
+ snprintf(errstr, errstr_len, "Could not measure end time: %s", strerror(errno));
+ goto err_open;
+ }
+ timespan=stop.tv_sec-start.tv_sec+(stop.tv_usec-start.tv_usec)/1000000;
+ speed=(int)(size/timespan);
+ if(speed>1024) {
+ speed>>=10;
+ speedchar[0]='K';
+ }
+ if(speed>1024) {
+ speed>>=10;
+ speedchar[0]='M';
+ }
+ if(speed>1024) {
+ speed>>=10;
+ speedchar[0]='G';
+ }
+ g_message("Throughput test complete. Took %.3f seconds to complete, %d%sB/s",timespan,speed,speedchar);
err_open:
if(close_sock) {
gchar *hostname;
long int p;
int port;
- int sock;
+ int sock=0;
if(argc<3) {
g_message("Not enough arguments");