[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[Nbd] [PATCH] Fix whitespacing and indentation in nbd-tester-client.c



I realise whitespace changes are generally frowned on, but nbd-tester-client.c
is almost impossible to edit in (e.g.) emacs even in 'linux' mode, because
its whitespacing is inconsistent and does not follow the style of the rest
of the package.

This is a whitespace ONLY change and is the equivalent of running Lindent.
Lindent does:
  indent -npro -kr -i8 -ts8 -sob -l80 -ss -ncs -cp1 -il0 nbd-tester-client.c
on indent >= v2.2.10, and
  indent -npro -kr -i8 -ts8 -sob -l80 -ss -ncs -cp1 nbd-tester-client.c
otherwise. See:
  https://github.com/torvalds/linux/blob/master/scripts/Lindent

Signed-off-by: Alex Bligh <alex@...872...>
---
 tests/run/nbd-tester-client.c | 1181 +++++++++++++++++++++++------------------
 1 file changed, 675 insertions(+), 506 deletions(-)

diff --git a/tests/run/nbd-tester-client.c b/tests/run/nbd-tester-client.c
index 1b99fa8..592930e 100644
--- a/tests/run/nbd-tester-client.c
+++ b/tests/run/nbd-tester-client.c
@@ -43,13 +43,13 @@
 #include "cliserv.h"
 
 static gchar errstr[1024];
-const static int errstr_len=1023;
+const static int errstr_len = 1023;
 
 static uint64_t size;
 
 static int looseordering = 0;
 
-static gchar * transactionlog = "nbd-tester-client.tr";
+static gchar *transactionlog = "nbd-tester-client.tr";
 
 typedef enum {
 	CONNECTION_TYPE_NONE,
@@ -68,29 +68,29 @@ struct reqcontext {
 	uint64_t seq;
 	char orighandle[8];
 	struct nbd_request req;
-	struct reqcontext * next;
-	struct reqcontext * prev;
+	struct reqcontext *next;
+	struct reqcontext *prev;
 };
 
 struct rclist {
-	struct reqcontext * head;
-	struct reqcontext * tail;
+	struct reqcontext *head;
+	struct reqcontext *tail;
 	int numitems;
 };
 
 struct chunk {
-	char * buffer;
-	char * readptr;
-	char * writeptr;
+	char *buffer;
+	char *readptr;
+	char *writeptr;
 	uint64_t space;
 	uint64_t length;
-	struct chunk * next;
-	struct chunk * prev;
+	struct chunk *next;
+	struct chunk *prev;
 };
 
 struct chunklist {
-	struct chunk * head;
-	struct chunk * tail;
+	struct chunk *head;
+	struct chunk *tail;
 	int numitems;
 };
 
@@ -100,17 +100,18 @@ struct blkitem {
 	int32_t inflightw;
 };
 
-void rclist_unlink(struct rclist * l, struct reqcontext * p) {
+void rclist_unlink(struct rclist *l, struct reqcontext *p)
+{
 	if (p && l) {
-		struct reqcontext * prev = p->prev;
-		struct reqcontext * next = p->next;
-		
+		struct reqcontext *prev = p->prev;
+		struct reqcontext *next = p->next;
+
 		/* Fix link to previous */
 		if (prev)
 			prev->next = next;
 		else
 			l->head = next;
-		
+
 		if (next)
 			next->prev = prev;
 		else
@@ -119,11 +120,12 @@ void rclist_unlink(struct rclist * l, struct reqcontext * p) {
 		p->prev = NULL;
 		p->next = NULL;
 		l->numitems--;
-	}							
-}									
+	}
+}
 
 /* Add a new list item to the tail */
-void rclist_addtail(struct rclist * l, struct reqcontext * p) {
+void rclist_addtail(struct rclist *l, struct reqcontext *p)
+{
 	if (!p || !l)
 		return;
 	if (l->tail) {
@@ -144,17 +146,18 @@ void rclist_addtail(struct rclist * l, struct reqcontext * p) {
 	l->numitems++;
 }
 
-void chunklist_unlink(struct chunklist * l, struct chunk * p) {
+void chunklist_unlink(struct chunklist *l, struct chunk *p)
+{
 	if (p && l) {
-		struct chunk * prev = p->prev;
-		struct chunk * next = p->next;
-		
+		struct chunk *prev = p->prev;
+		struct chunk *next = p->next;
+
 		/* Fix link to previous */
 		if (prev)
 			prev->next = next;
 		else
 			l->head = next;
-		
+
 		if (next)
 			next->prev = prev;
 		else
@@ -163,11 +166,12 @@ void chunklist_unlink(struct chunklist * l, struct chunk * p) {
 		p->prev = NULL;
 		p->next = NULL;
 		l->numitems--;
-	}							
-}									
+	}
+}
 
 /* Add a new list item to the tail */
-void chunklist_addtail(struct chunklist * l, struct chunk * p) {
+void chunklist_addtail(struct chunklist *l, struct chunk *p)
+{
 	if (!p || !l)
 		return;
 	if (l->tail) {
@@ -189,13 +193,13 @@ void chunklist_addtail(struct chunklist * l, struct chunk * p) {
 }
 
 /* Add some new bytes to a chunklist */
-void addbuffer(struct chunklist * l, void * data, uint64_t len) {
-	void * buf;
-	uint64_t size = 64*1024;
-	struct chunk * pchunk;
+void addbuffer(struct chunklist *l, void *data, uint64_t len)
+{
+	void *buf;
+	uint64_t size = 64 * 1024;
+	struct chunk *pchunk;
 
-	while (len>0)
-	{
+	while (len > 0) {
 		/* First see if there is a current chunk, and if it has space */
 		if (l->tail && l->tail->space) {
 			uint64_t towrite = len;
@@ -209,11 +213,13 @@ void addbuffer(struct chunklist * l, void * data, uint64_t len) {
 			data += towrite;
 		}
 
-		if (len>0) {
+		if (len > 0) {
 			/* We still need to write more, so prepare a new chunk */
-			if ((NULL == (buf = malloc(size))) || (NULL == (pchunk = calloc(1, sizeof(struct chunk))))) {
+			if ((NULL == (buf = malloc(size)))
+			    || (NULL ==
+				(pchunk = calloc(1, sizeof(struct chunk))))) {
 				g_critical("Out of memory");
-				exit (1);
+				exit(1);
 			}
 
 			pchunk->buffer = buf;
@@ -227,15 +233,15 @@ void addbuffer(struct chunklist * l, void * data, uint64_t len) {
 }
 
 /* returns 0 on success, -1 on failure */
-int writebuffer(int fd, struct chunklist * l) {
+int writebuffer(int fd, struct chunklist *l)
+{
 
-	struct chunk * pchunk = NULL;
+	struct chunk *pchunk = NULL;
 	int res;
 	if (!l)
 		return 0;
 
-	while (!pchunk)
-	{
+	while (!pchunk) {
 		pchunk = l->head;
 		if (!pchunk)
 			return 0;
@@ -246,12 +252,12 @@ int writebuffer(int fd, struct chunklist * l) {
 			pchunk = NULL;
 		}
 	}
-	
+
 	/* OK we have a chunk with some data in */
 	res = write(fd, pchunk->readptr, pchunk->length);
-	if (res==0)
+	if (res == 0)
 		errno = EAGAIN;
-	if (res<=0)
+	if (res <= 0)
 		return -1;
 	pchunk->length -= res;
 	pchunk->readptr += res;
@@ -263,70 +269,74 @@ int writebuffer(int fd, struct chunklist * l) {
 	return 0;
 }
 
-
-
 #define TEST_WRITE (1<<0)
 #define TEST_FLUSH (1<<1)
 #define TEST_EXPECT_ERROR (1<<2)
 
-int timeval_subtract (struct timeval *result, struct timeval *x,
-		      struct timeval *y) {
+int timeval_subtract(struct timeval *result, struct timeval *x,
+		     struct timeval *y)
+{
 	if (x->tv_usec < y->tv_usec) {
 		int nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1;
 		y->tv_usec -= 1000000 * nsec;
 		y->tv_sec += nsec;
 	}
-	
+
 	if (x->tv_usec - y->tv_usec > 1000000) {
 		int nsec = (x->tv_usec - y->tv_usec) / 1000000;
 		y->tv_usec += 1000000 * nsec;
 		y->tv_sec -= nsec;
 	}
-	
+
 	result->tv_sec = x->tv_sec - y->tv_sec;
 	result->tv_usec = x->tv_usec - y->tv_usec;
-	
+
 	return x->tv_sec < y->tv_sec;
 }
 
-double timeval_diff_to_double (struct timeval * x, struct timeval * y) {
+double timeval_diff_to_double(struct timeval *x, struct timeval *y)
+{
 	struct timeval r;
 	timeval_subtract(&r, x, y);
-	return r.tv_sec * 1.0 + r.tv_usec/1000000.0;
+	return r.tv_sec * 1.0 + r.tv_usec / 1000000.0;
 }
 
-static inline int read_all(int f, void *buf, size_t len) {
+static inline int read_all(int f, void *buf, size_t len)
+{
 	ssize_t res;
-	size_t retval=0;
+	size_t retval = 0;
 
-	while(len>0) {
-		if((res=read(f, buf, len)) <=0) {
+	while (len > 0) {
+		if ((res = read(f, buf, len)) <= 0) {
 			if (!res)
-				errno=EAGAIN;
-			snprintf(errstr, errstr_len, "Read failed: %s", strerror(errno));
+				errno = EAGAIN;
+			snprintf(errstr, errstr_len, "Read failed: %s",
+				 strerror(errno));
 			return -1;
 		}
-		len-=res;
-		buf+=res;
-		retval+=res;
+		len -= res;
+		buf += res;
+		retval += res;
 	}
 	return retval;
 }
 
-static inline int write_all(int f, void *buf, size_t len) {
+static inline int write_all(int f, void *buf, size_t len)
+{
 	ssize_t res;
-	size_t retval=0;
+	size_t retval = 0;
 
-	while(len>0) {
-		if((res=write(f, buf, len)) <=0) {
+	while (len > 0) {
+		if ((res = write(f, buf, len)) <= 0) {
 			if (!res)
-				errno=EAGAIN;
-			snprintf(errstr, errstr_len, "Write failed: %s", strerror(errno));
+				errno = EAGAIN;
+			snprintf(errstr, errstr_len, "Write failed: %s",
+				 strerror(errno));
 			return -1;
 		}
-		len-=res;
-		buf+=res;
-		retval+=res;
+		len -= res;
+		buf += res;
+		retval += res;
 	}
 	return retval;
 }
@@ -337,7 +347,9 @@ static inline int write_all(int f, void *buf, size_t len) {
 #define WRITE_ALL_ERRCHK(f, buf, len, whereto, errmsg...) if((write_all(f, buf, len))<=0) { snprintf(errstr, errstr_len, ##errmsg); goto whereto; }
 #define WRITE_ALL_ERR_RT(f, buf, len, whereto, rval, errmsg...) if((write_all(f, buf, len))<=0) { snprintf(errstr, errstr_len, ##errmsg); retval = rval; goto whereto; }
 
-int setup_connection_common(int sock, char* name, CONNECTION_TYPE ctype, int* serverflags) {
+int setup_connection_common(int sock, char *name, CONNECTION_TYPE ctype,
+			    int *serverflags)
+{
 	char buf[256];
 	u64 tmp64;
 	uint64_t mymagic = (name ? opts_magic : cliserv_magic);
@@ -345,72 +357,87 @@ int setup_connection_common(int sock, char* name, CONNECTION_TYPE ctype, int* se
 	uint16_t handshakeflags = 0;
 	uint32_t negotiationflags = 0;
 
-	if(ctype<CONNECTION_TYPE_INIT_PASSWD)
+	if (ctype < CONNECTION_TYPE_INIT_PASSWD)
 		goto end;
-	READ_ALL_ERRCHK(sock, buf, strlen(INIT_PASSWD), err, "Could not read INIT_PASSWD: %s", strerror(errno));
-	if(strlen(buf)==0) {
+	READ_ALL_ERRCHK(sock, buf, strlen(INIT_PASSWD), err,
+			"Could not read INIT_PASSWD: %s", strerror(errno));
+	if (strlen(buf) == 0) {
 		snprintf(errstr, errstr_len, "Server closed connection");
 		goto err;
 	}
-	if(strncmp(buf, INIT_PASSWD, strlen(INIT_PASSWD))) {
+	if (strncmp(buf, INIT_PASSWD, strlen(INIT_PASSWD))) {
 		snprintf(errstr, errstr_len, "INIT_PASSWD does not match");
 		goto err;
 	}
-	if(ctype<CONNECTION_TYPE_CLISERV)
+	if (ctype < CONNECTION_TYPE_CLISERV)
 		goto end;
-	READ_ALL_ERRCHK(sock, &tmp64, sizeof(tmp64), err, "Could not read cliserv_magic: %s", strerror(errno));
-	tmp64=ntohll(tmp64);
-	if(tmp64 != mymagic) {
+	READ_ALL_ERRCHK(sock, &tmp64, sizeof(tmp64), err,
+			"Could not read cliserv_magic: %s", strerror(errno));
+	tmp64 = ntohll(tmp64);
+	if (tmp64 != mymagic) {
 		strncpy(errstr, "mymagic does not match", errstr_len);
 		goto err;
 	}
-	if(ctype<CONNECTION_TYPE_FULL)
+	if (ctype < CONNECTION_TYPE_FULL)
 		goto end;
-	if(!name) {
-		READ_ALL_ERRCHK(sock, &size, sizeof(size), err, "Could not read size: %s", strerror(errno));
-		size=ntohll(size);
-		READ_ALL_ERRCHK(sock, buf, 128, err, "Could not read data: %s", strerror(errno));
+	if (!name) {
+		READ_ALL_ERRCHK(sock, &size, sizeof(size), err,
+				"Could not read size: %s", strerror(errno));
+		size = ntohll(size);
+		READ_ALL_ERRCHK(sock, buf, 128, err, "Could not read data: %s",
+				strerror(errno));
 		goto end;
 	}
 	/* handshake flags */
-	READ_ALL_ERRCHK(sock, &handshakeflags, sizeof(handshakeflags), err, "Could not read reserved field: %s", strerror(errno));
+	READ_ALL_ERRCHK(sock, &handshakeflags, sizeof(handshakeflags), err,
+			"Could not read reserved field: %s", strerror(errno));
 	/* negotiation flags */
 	if (handshakeflags & NBD_FLAG_FIXED_NEWSTYLE)
 		negotiationflags |= NBD_FLAG_C_FIXED_NEWSTYLE;
-	WRITE_ALL_ERRCHK(sock, &negotiationflags, sizeof(negotiationflags), err, "Could not write reserved field: %s", strerror(errno));
+	WRITE_ALL_ERRCHK(sock, &negotiationflags, sizeof(negotiationflags), err,
+			 "Could not write reserved field: %s", strerror(errno));
 	/* magic */
 	tmp64 = htonll(opts_magic);
-	WRITE_ALL_ERRCHK(sock, &tmp64, sizeof(tmp64), err, "Could not write magic: %s", strerror(errno));
+	WRITE_ALL_ERRCHK(sock, &tmp64, sizeof(tmp64), err,
+			 "Could not write magic: %s", strerror(errno));
 	/* name */
 	tmp32 = htonl(NBD_OPT_EXPORT_NAME);
-	WRITE_ALL_ERRCHK(sock, &tmp32, sizeof(tmp32), err, "Could not write option: %s", strerror(errno));
-	tmp32 = htonl((uint32_t)strlen(name));
-	WRITE_ALL_ERRCHK(sock, &tmp32, sizeof(tmp32), err, "Could not write name length: %s", strerror(errno));
-	WRITE_ALL_ERRCHK(sock, name, strlen(name), err, "Could not write name:: %s", strerror(errno));
-	READ_ALL_ERRCHK(sock, &size, sizeof(size), err, "Could not read size: %s", strerror(errno));
+	WRITE_ALL_ERRCHK(sock, &tmp32, sizeof(tmp32), err,
+			 "Could not write option: %s", strerror(errno));
+	tmp32 = htonl((uint32_t) strlen(name));
+	WRITE_ALL_ERRCHK(sock, &tmp32, sizeof(tmp32), err,
+			 "Could not write name length: %s", strerror(errno));
+	WRITE_ALL_ERRCHK(sock, name, strlen(name), err,
+			 "Could not write name:: %s", strerror(errno));
+	READ_ALL_ERRCHK(sock, &size, sizeof(size), err,
+			"Could not read size: %s", strerror(errno));
 	size = ntohll(size);
 	uint16_t flags;
-	READ_ALL_ERRCHK(sock, &flags, sizeof(uint16_t), err, "Could not read flags: %s", strerror(errno));
+	READ_ALL_ERRCHK(sock, &flags, sizeof(uint16_t), err,
+			"Could not read flags: %s", strerror(errno));
 	flags = ntohs(flags);
 	*serverflags = flags;
-	READ_ALL_ERRCHK(sock, buf, 124, err, "Could not read reserved zeroes: %s", strerror(errno));
+	READ_ALL_ERRCHK(sock, buf, 124, err,
+			"Could not read reserved zeroes: %s", strerror(errno));
 	goto end;
 err:
 	close(sock);
-	sock=-1;
+	sock = -1;
 end:
 	return sock;
 }
 
-int setup_unix_connection(gchar* unixsock, gchar* name, CONNECTION_TYPE ctype, int* serverflags) {
+int setup_unix_connection(gchar * unixsock, gchar * name, CONNECTION_TYPE ctype,
+			  int *serverflags)
+{
 	struct sockaddr_un addr;
 	int sock;
 
 	sock = 0;
-	if(ctype<CONNECTION_TYPE_CONNECT) {
+	if (ctype < CONNECTION_TYPE_CONNECT) {
 		goto end;
 	}
-	if((sock=socket(AF_UNIX, SOCK_STREAM, 0))<0) {
+	if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
 		strncpy(errstr, strerror(errno), errstr_len);
 		goto err;
 	}
@@ -419,7 +446,7 @@ int setup_unix_connection(gchar* unixsock, gchar* name, CONNECTION_TYPE ctype, i
 	memset(&addr, 0, sizeof(struct sockaddr_un));
 	addr.sun_family = AF_UNIX;
 	strncpy(addr.sun_path, unixsock, sizeof addr.sun_path);
-	if(connect(sock, (struct sockaddr*)&addr, sizeof(addr))<0) {
+	if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
 		strncpy(errstr, strerror(errno), errstr_len);
 		goto err_open;
 	}
@@ -428,185 +455,226 @@ int setup_unix_connection(gchar* unixsock, gchar* name, CONNECTION_TYPE ctype, i
 err_open:
 	close(sock);
 err:
-	sock=-1;
+	sock = -1;
 end:
 	return sock;
 }
 
-int setup_inet_connection(gchar *hostname, int port, gchar* name, CONNECTION_TYPE ctype, int* serverflags) {
+int setup_inet_connection(gchar * hostname, int port, gchar * name,
+			  CONNECTION_TYPE ctype, int *serverflags)
+{
 	int sock;
 	struct hostent *host;
 	struct sockaddr_in addr;
 
-	sock=0;
-	if(ctype<CONNECTION_TYPE_CONNECT)
+	sock = 0;
+	if (ctype < CONNECTION_TYPE_CONNECT)
 		goto end;
-	if((sock=socket(PF_INET, SOCK_STREAM, IPPROTO_TCP))<0) {
+	if ((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
 		strncpy(errstr, strerror(errno), errstr_len);
 		goto err;
 	}
 	setmysockopt(sock);
-	if(!(host=gethostbyname(hostname))) {
+	if (!(host = gethostbyname(hostname))) {
 		strncpy(errstr, hstrerror(h_errno), errstr_len);
 		goto err_open;
 	}
-	addr.sin_family=AF_INET;
-	addr.sin_port=htons(port);
-	addr.sin_addr.s_addr=*((int *) host->h_addr);
-	if((connect(sock, (struct sockaddr *)&addr, sizeof(addr))<0)) {
+	addr.sin_family = AF_INET;
+	addr.sin_port = htons(port);
+	addr.sin_addr.s_addr = *((int *)host->h_addr);
+	if ((connect(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0)) {
 		strncpy(errstr, strerror(errno), errstr_len);
 		goto err_open;
 	}
-	sock=setup_connection_common(sock, name, ctype, serverflags);
+	sock = setup_connection_common(sock, name, ctype, serverflags);
 	goto end;
 err_open:
 	close(sock);
 err:
-	sock=-1;
+	sock = -1;
 end:
 	return sock;
 }
 
-int setup_connection(gchar* hostname, gchar* unixsock, int port, gchar* name, CONNECTION_TYPE ctype, int* serverflags) {
-	if(hostname != NULL) {
-		return setup_inet_connection(hostname, port, name, ctype, serverflags);
-	} else if(unixsock != NULL) {
-		return setup_unix_connection(unixsock, name, ctype, serverflags);
+int setup_connection(gchar * hostname, gchar * unixsock, int port, gchar * name,
+		     CONNECTION_TYPE ctype, int *serverflags)
+{
+	if (hostname != NULL) {
+		return setup_inet_connection(hostname, port, name, ctype,
+					     serverflags);
+	} else if (unixsock != NULL) {
+		return setup_unix_connection(unixsock, name, ctype,
+					     serverflags);
 	} else {
 		g_error("need a hostname or a unix domain socket!");
 		return -1;
 	}
 }
 
-int close_connection(int sock, CLOSE_TYPE type) {
+int close_connection(int sock, CLOSE_TYPE type)
+{
 	struct nbd_request req;
-	u64 counter=0;
-
-	switch(type) {
-		case CONNECTION_CLOSE_PROPERLY:
-			req.magic=htonl(NBD_REQUEST_MAGIC);
-			req.type=htonl(NBD_CMD_DISC);
-			memcpy(&(req.handle), &(counter), sizeof(counter));
-			counter++;
-			req.from=0;
-			req.len=0;
-			if(write(sock, &req, sizeof(req))<0) {
-				snprintf(errstr, errstr_len, "Could not write to socket: %s", strerror(errno));
-				return -1;
-			}
-		case CONNECTION_CLOSE_FAST:
-			if(close(sock)<0) {
-				snprintf(errstr, errstr_len, "Could not close socket: %s", strerror(errno));
-				return -1;
-			}
-			break;
-		default:
-			g_critical("Your compiler is on crack!"); /* or I am buggy */
+	u64 counter = 0;
+
+	switch (type) {
+	case CONNECTION_CLOSE_PROPERLY:
+		req.magic = htonl(NBD_REQUEST_MAGIC);
+		req.type = htonl(NBD_CMD_DISC);
+		memcpy(&(req.handle), &(counter), sizeof(counter));
+		counter++;
+		req.from = 0;
+		req.len = 0;
+		if (write(sock, &req, sizeof(req)) < 0) {
+			snprintf(errstr, errstr_len,
+				 "Could not write to socket: %s",
+				 strerror(errno));
+			return -1;
+		}
+	case CONNECTION_CLOSE_FAST:
+		if (close(sock) < 0) {
+			snprintf(errstr, errstr_len,
+				 "Could not close socket: %s", strerror(errno));
 			return -1;
+		}
+		break;
+	default:
+		g_critical("Your compiler is on crack!");	/* or I am buggy */
+		return -1;
 	}
 	return 0;
 }
 
-int read_packet_check_header(int sock, size_t datasize, long long int curhandle) {
+int read_packet_check_header(int sock, size_t datasize, long long int curhandle)
+{
 	struct nbd_reply rep;
-	int retval=0;
+	int retval = 0;
 	char buf[datasize];
 
-	READ_ALL_ERR_RT(sock, &rep, sizeof(rep), end, -1, "Could not read reply header: %s", strerror(errno));
-	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", (long long int)curhandle, (long long unsigned int)curhandle, (long long int)*((u64*)rep.handle), (long long unsigned int)*((u64*)rep.handle), (long unsigned int)rep.magic, (long unsigned int)NBD_REPLY_MAGIC);
-		retval=-1;
+	READ_ALL_ERR_RT(sock, &rep, sizeof(rep), end, -1,
+			"Could not read reply header: %s", strerror(errno));
+	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",
+			 (long long int)curhandle,
+			 (long long unsigned int)curhandle,
+			 (long long int)*((u64 *) rep.handle),
+			 (long long unsigned int)*((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).", (long int)rep.error, (long unsigned int)rep.error, (long long int)(*((u64*)rep.handle)), (long long unsigned int)*((u64*)rep.handle));
-		retval=-2;
+	if (rep.error) {
+		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)),
+			 (long long unsigned int)*((u64 *) rep.handle));
+		retval = -2;
 		goto end;
 	}
 	if (datasize)
-		READ_ALL_ERR_RT(sock, &buf, datasize, end, -1, "Could not read data: %s", strerror(errno));
+		READ_ALL_ERR_RT(sock, &buf, datasize, end, -1,
+				"Could not read data: %s", strerror(errno));
 
 end:
 	return retval;
 }
 
-int oversize_test(gchar* hostname, gchar* unixsock, int port, char* name, int sock,
-		  char sock_is_open, char close_sock, int testflags) {
-	int retval=0;
+int oversize_test(gchar * hostname, gchar * unixsock, int port, char *name,
+		  int sock, char sock_is_open, char close_sock, int testflags)
+{
+	int retval = 0;
 	struct nbd_request req;
 	struct nbd_reply rep;
-	int i=0;
+	int i = 0;
 	int serverflags = 0;
 	pid_t G_GNUC_UNUSED mypid = getpid();
-	char buf[((1024*1024)+sizeof(struct nbd_request)/2)<<1];
+	char buf[((1024 * 1024) + sizeof(struct nbd_request) / 2) << 1];
 	bool got_err;
 
 	/* This should work */
-	if(!sock_is_open) {
-		if((sock=setup_connection(hostname, unixsock, port, name, CONNECTION_TYPE_FULL, &serverflags))<0) {
+	if (!sock_is_open) {
+		if ((sock =
+		     setup_connection(hostname, unixsock, port, name,
+				      CONNECTION_TYPE_FULL,
+				      &serverflags)) < 0) {
 			g_warning("Could not open socket: %s", errstr);
-			retval=-1;
+			retval = -1;
 			goto err;
 		}
 	}
-	req.magic=htonl(NBD_REQUEST_MAGIC);
-	req.type=htonl(NBD_CMD_READ);
-	req.len=htonl(1024*1024);
-	memcpy(&(req.handle),&i,sizeof(i));
-	req.from=htonll(i);
-	WRITE_ALL_ERR_RT(sock, &req, sizeof(req), err, -1, "Could not write request: %s", strerror(errno));
+	req.magic = htonl(NBD_REQUEST_MAGIC);
+	req.type = htonl(NBD_CMD_READ);
+	req.len = htonl(1024 * 1024);
+	memcpy(&(req.handle), &i, sizeof(i));
+	req.from = htonll(i);
+	WRITE_ALL_ERR_RT(sock, &req, sizeof(req), err, -1,
+			 "Could not write request: %s", strerror(errno));
 	printf("%d: testing oversized request: %d: ", getpid(), ntohl(req.len));
-	READ_ALL_ERR_RT(sock, &rep, sizeof(struct nbd_reply), err, -1, "Could not read reply header: %s", strerror(errno));
-	READ_ALL_ERR_RT(sock, &buf, ntohl(req.len), err, -1, "Could not read data: %s", strerror(errno));
-	if(rep.error) {
-		snprintf(errstr, errstr_len, "Received unexpected error: %d", rep.error);
-		retval=-1;
+	READ_ALL_ERR_RT(sock, &rep, sizeof(struct nbd_reply), err, -1,
+			"Could not read reply header: %s", strerror(errno));
+	READ_ALL_ERR_RT(sock, &buf, ntohl(req.len), err, -1,
+			"Could not read data: %s", strerror(errno));
+	if (rep.error) {
+		snprintf(errstr, errstr_len, "Received unexpected error: %d",
+			 rep.error);
+		retval = -1;
 		goto err;
 	} else {
 		printf("OK\n");
 	}
 	/* This probably should not work */
-	i++; req.from=htonll(i);
+	i++;
+	req.from = htonll(i);
 	req.len = htonl(ntohl(req.len) + sizeof(struct nbd_request) / 2);
-	WRITE_ALL_ERR_RT(sock, &req, sizeof(req), err, -1, "Could not write request: %s", strerror(errno));
+	WRITE_ALL_ERR_RT(sock, &req, sizeof(req), err, -1,
+			 "Could not write request: %s", strerror(errno));
 	printf("%d: testing oversized request: %d: ", getpid(), ntohl(req.len));
-	READ_ALL_ERR_RT(sock, &rep, sizeof(struct nbd_reply), err, -1, "Could not read reply header: %s", strerror(errno));
-	READ_ALL_ERR_RT(sock, &buf, ntohl(req.len), err, -1, "Could not read data: %s", strerror(errno));
-	if(rep.error) {
+	READ_ALL_ERR_RT(sock, &rep, sizeof(struct nbd_reply), err, -1,
+			"Could not read reply header: %s", strerror(errno));
+	READ_ALL_ERR_RT(sock, &buf, ntohl(req.len), err, -1,
+			"Could not read data: %s", strerror(errno));
+	if (rep.error) {
 		printf("Received expected error\n");
-		got_err=true;
+		got_err = true;
 	} else {
 		printf("OK\n");
-		got_err=false;
+		got_err = false;
 	}
 	/* ... unless this works, too */
-	i++; req.from=htonll(i);
+	i++;
+	req.from = htonll(i);
 	req.len = htonl(ntohl(req.len) << 1);
-	WRITE_ALL_ERR_RT(sock, &req, sizeof(req), err, -1, "Could not write request: %s", strerror(errno));
+	WRITE_ALL_ERR_RT(sock, &req, sizeof(req), err, -1,
+			 "Could not write request: %s", strerror(errno));
 	printf("%d: testing oversized request: %d: ", getpid(), ntohl(req.len));
-	READ_ALL_ERR_RT(sock, &rep, sizeof(struct nbd_reply), err, -1, "Could not read reply header: %s", strerror(errno));
-	READ_ALL_ERR_RT(sock, &buf, ntohl(req.len), err, -1, "Could not read data: %s", strerror(errno));
-	if(rep.error) {
+	READ_ALL_ERR_RT(sock, &rep, sizeof(struct nbd_reply), err, -1,
+			"Could not read reply header: %s", strerror(errno));
+	READ_ALL_ERR_RT(sock, &buf, ntohl(req.len), err, -1,
+			"Could not read data: %s", strerror(errno));
+	if (rep.error) {
 		printf("error\n");
 	} else {
 		printf("OK\n");
 	}
-	if((rep.error && !got_err) || (!rep.error && got_err)) {
+	if ((rep.error && !got_err) || (!rep.error && got_err)) {
 		printf("Received unexpected error\n");
-		retval=-1;
+		retval = -1;
 	}
-  err:
+err:
 	return retval;
 }
 
-int throughput_test(gchar* hostname, gchar* unixsock, int port, char* name, int sock,
-		    char sock_is_open, char close_sock, int testflags) {
+int throughput_test(gchar * hostname, gchar * unixsock, int port, char *name,
+		    int sock, char sock_is_open, char close_sock, int testflags)
+{
 	long long int i;
 	char writebuf[1024];
 	struct nbd_request req;
-	int requests=0;
+	int requests = 0;
 	fd_set set;
 	struct timeval tv;
 	struct timeval start;
@@ -614,65 +682,75 @@ int throughput_test(gchar* hostname, gchar* unixsock, int port, char* name, int
 	double timespan;
 	double speed;
 	char speedchar[2] = { '\0', '\0' };
-	int retval=0;
+	int retval = 0;
 	int serverflags = 0;
-	signed int do_write=TRUE;
+	signed int do_write = TRUE;
 	pid_t mypid = getpid();
 
-
 	if (!(testflags & TEST_WRITE))
 		testflags &= ~TEST_FLUSH;
 
-	memset (writebuf, 'X', 1024);
-	size=0;
-	if(!sock_is_open) {
-		if((sock=setup_connection(hostname, unixsock, port, name, CONNECTION_TYPE_FULL, &serverflags))<0) {
+	memset(writebuf, 'X', 1024);
+	size = 0;
+	if (!sock_is_open) {
+		if ((sock =
+		     setup_connection(hostname, unixsock, port, name,
+				      CONNECTION_TYPE_FULL,
+				      &serverflags)) < 0) {
 			g_warning("Could not open socket: %s", errstr);
-			retval=-1;
+			retval = -1;
 			goto err;
 		}
 	}
-	if ((testflags & TEST_FLUSH) && ((serverflags & (NBD_FLAG_SEND_FLUSH | NBD_FLAG_SEND_FUA))
-					 != (NBD_FLAG_SEND_FLUSH | NBD_FLAG_SEND_FUA))) {
-		snprintf(errstr, errstr_len, "Server did not supply flush capability flags");
+	if ((testflags & TEST_FLUSH)
+	    && ((serverflags & (NBD_FLAG_SEND_FLUSH | NBD_FLAG_SEND_FUA))
+		!= (NBD_FLAG_SEND_FLUSH | NBD_FLAG_SEND_FUA))) {
+		snprintf(errstr, errstr_len,
+			 "Server did not supply flush capability flags");
 		retval = -1;
 		goto err_open;
 	}
-	req.magic=htonl(NBD_REQUEST_MAGIC);
-	req.len=htonl(1024);
-	if(gettimeofday(&start, NULL)<0) {
-		retval=-1;
-		snprintf(errstr, errstr_len, "Could not measure start time: %s", strerror(errno));
+	req.magic = htonl(NBD_REQUEST_MAGIC);
+	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;
 	}
 	int printer = 0;
-	for(i=0;i+1024<=size;i+=1024) {
-		if(do_write) {
-			int sendfua = (testflags & TEST_FLUSH) && (((i>>10) & 15) == 3);
-			int sendflush = (testflags & TEST_FLUSH) && (((i>>10) & 15) == 11);
-			req.type=htonl((testflags & TEST_WRITE)?NBD_CMD_WRITE:NBD_CMD_READ);
+	for (i = 0; i + 1024 <= size; i += 1024) {
+		if (do_write) {
+			int sendfua = (testflags & TEST_FLUSH)
+			    && (((i >> 10) & 15) == 3);
+			int sendflush = (testflags & TEST_FLUSH)
+			    && (((i >> 10) & 15) == 11);
+			req.type =
+			    htonl((testflags & TEST_WRITE) ? NBD_CMD_WRITE :
+				  NBD_CMD_READ);
 			if (sendfua)
-				req.type = htonl(NBD_CMD_WRITE | NBD_CMD_FLAG_FUA);
-			memcpy(&(req.handle),&i,sizeof(i));
-			req.from=htonll(i);
-			if (write_all(sock, &req, sizeof(req)) <0) {
-				retval=-1;
+				req.type =
+				    htonl(NBD_CMD_WRITE | NBD_CMD_FLAG_FUA);
+			memcpy(&(req.handle), &i, sizeof(i));
+			req.from = htonll(i);
+			if (write_all(sock, &req, sizeof(req)) < 0) {
+				retval = -1;
 				goto err_open;
 			}
 			if (testflags & TEST_WRITE) {
-				if (write_all(sock, writebuf, 1024) <0) {
-					retval=-1;
+				if (write_all(sock, writebuf, 1024) < 0) {
+					retval = -1;
 					goto err_open;
 				}
 			}
 			++requests;
 			if (sendflush) {
-				long long int j = i ^ (1LL<<63);
+				long long int j = i ^ (1LL << 63);
 				req.type = htonl(NBD_CMD_FLUSH);
-				memcpy(&(req.handle),&j,sizeof(j));
-				req.from=0;
-				if (write_all(sock, &req, sizeof(req)) <0) {
-					retval=-1;
+				memcpy(&(req.handle), &j, sizeof(j));
+				req.from = 0;
+				if (write_all(sock, &req, sizeof(req)) < 0) {
+					retval = -1;
 					goto err_open;
 				}
 				++requests;
@@ -681,23 +759,28 @@ int throughput_test(gchar* hostname, gchar* unixsock, int port, char* name, int
 		do {
 			FD_ZERO(&set);
 			FD_SET(sock, &set);
-			tv.tv_sec=0;
-			tv.tv_usec=0;
-			select(sock+1, &set, NULL, NULL, &tv);
-			if(FD_ISSET(sock, &set)) {
+			tv.tv_sec = 0;
+			tv.tv_usec = 0;
+			select(sock + 1, &set, NULL, NULL, &tv);
+			if (FD_ISSET(sock, &set)) {
 				/* Okay, there's something ready for
 				 * reading here */
 				int rv;
-				if((rv=read_packet_check_header(sock, (testflags & TEST_WRITE)?0:1024, i))<0) {
-					if(!(testflags & TEST_EXPECT_ERROR) || rv != -2) {
-						retval=-1;
+				if ((rv =
+				     read_packet_check_header(sock,
+							      (testflags &
+							       TEST_WRITE) ? 0 :
+							      1024, i)) < 0) {
+					if (!(testflags & TEST_EXPECT_ERROR)
+					    || rv != -2) {
+						retval = -1;
 					} else {
 						printf("\n");
 					}
 					goto err_open;
 				} else {
-					if(testflags & TEST_EXPECT_ERROR) {
-						retval=-1;
+					if (testflags & TEST_EXPECT_ERROR) {
+						retval = -1;
 						goto err_open;
 					}
 				}
@@ -708,16 +791,18 @@ int throughput_test(gchar* hostname, gchar* unixsock, int port, char* name, int
 		 * passed, whichever comes first*/
 		FD_ZERO(&set);
 		FD_SET(sock, &set);
-		tv.tv_sec=1;
-		tv.tv_usec=0;
-		do_write=select(sock+1,NULL,&set,NULL,&tv);
-		if(!do_write) printf("Select finished\n");
-		if(do_write<0) {
-			snprintf(errstr, errstr_len, "select: %s", strerror(errno));
-			retval=-1;
+		tv.tv_sec = 1;
+		tv.tv_usec = 0;
+		do_write = select(sock + 1, NULL, &set, NULL, &tv);
+		if (!do_write)
+			printf("Select finished\n");
+		if (do_write < 0) {
+			snprintf(errstr, errstr_len, "select: %s",
+				 strerror(errno));
+			retval = -1;
 			goto err_open;
 		}
-		if(!(printer++ % 10)) {
+		if (!(printer++ % 10)) {
 			printf("%d: Requests: %d  \r", (int)mypid, requests);
 		}
 	}
@@ -725,43 +810,50 @@ int throughput_test(gchar* hostname, gchar* unixsock, int port, char* name, int
 	do {
 		FD_ZERO(&set);
 		FD_SET(sock, &set);
-		tv.tv_sec=0;
-		tv.tv_usec=0;
-		select(sock+1, &set, NULL, NULL, &tv);
-		if(FD_ISSET(sock, &set)) {
+		tv.tv_sec = 0;
+		tv.tv_usec = 0;
+		select(sock + 1, &set, NULL, NULL, &tv);
+		if (FD_ISSET(sock, &set)) {
 			/* Okay, there's something ready for
 			 * reading here */
-			read_packet_check_header(sock, (testflags & TEST_WRITE)?0:1024, i);
+			read_packet_check_header(sock,
+						 (testflags & TEST_WRITE) ? 0 :
+						 1024, i);
 			--requests;
 		}
-		if(!(printer++ % 10)) {
+		if (!(printer++ % 10)) {
 			printf("%d: Requests: %d  \r", (int)mypid, requests);
 		}
 	} while (requests);
 	printf("%d: Requests: %d  \n", (int)mypid, requests);
-	if(gettimeofday(&stop, NULL)<0) {
-		retval=-1;
-		snprintf(errstr, errstr_len, "Could not measure end time: %s", strerror(errno));
+	if (gettimeofday(&stop, NULL) < 0) {
+		retval = -1;
+		snprintf(errstr, errstr_len, "Could not measure end time: %s",
+			 strerror(errno));
 		goto err_open;
 	}
-	timespan=timeval_diff_to_double(&stop, &start);
-	speed=size/timespan;
-	if(speed>1024) {
-		speed=speed/1024.0;
-		speedchar[0]='K';
+	timespan = timeval_diff_to_double(&stop, &start);
+	speed = size / timespan;
+	if (speed > 1024) {
+		speed = speed / 1024.0;
+		speedchar[0] = 'K';
 	}
-	if(speed>1024) {
-		speed=speed/1024.0;
-		speedchar[0]='M';
+	if (speed > 1024) {
+		speed = speed / 1024.0;
+		speedchar[0] = 'M';
 	}
-	if(speed>1024) {
-		speed=speed/1024.0;
-		speedchar[0]='G';
+	if (speed > 1024) {
+		speed = speed / 1024.0;
+		speedchar[0] = 'G';
 	}
-	g_message("%d: Throughput %s test (%s flushes) complete. Took %.3f seconds to complete, %.3f%sib/s", (int)getpid(), (testflags & TEST_WRITE)?"write":"read", (testflags & TEST_FLUSH)?"with":"without", timespan, speed, speedchar);
+	g_message
+	    ("%d: Throughput %s test (%s flushes) complete. Took %.3f seconds to complete, %.3f%sib/s",
+	     (int)getpid(), (testflags & TEST_WRITE) ? "write" : "read",
+	     (testflags & TEST_FLUSH) ? "with" : "without", timespan, speed,
+	     speedchar);
 
 err_open:
-	if(close_sock) {
+	if (close_sock) {
 		close_connection(sock, CONNECTION_CLOSE_PROPERLY);
 	}
 err:
@@ -773,73 +865,76 @@ err:
  * only on handle and blknum. The first word is blknum, and the second handle, for ease
  * of understanding. Things with handle 0 are blank.
  */
-static inline void makebuf(char *buf, uint64_t seq, uint64_t blknum) {
-	uint64_t x = ((uint64_t)blknum) ^ (seq << 32) ^ (seq >> 32);
-	uint64_t* p = (uint64_t*)buf;
+static inline void makebuf(char *buf, uint64_t seq, uint64_t blknum)
+{
+	uint64_t x = ((uint64_t) blknum) ^ (seq << 32) ^ (seq >> 32);
+	uint64_t *p = (uint64_t *) buf;
 	int i;
 	if (!seq) {
 		bzero(buf, 512);
 		return;
 	}
-	for (i = 0; i<512/sizeof(uint64_t); i++) {
+	for (i = 0; i < 512 / sizeof(uint64_t); i++) {
 		int s;
 		*(p++) = x;
-		x+=0xFEEDA1ECDEADBEEFULL+i+(((uint64_t)i)<<56);
+		x += 0xFEEDA1ECDEADBEEFULL + i + (((uint64_t) i) << 56);
 		s = x & 63;
-		x = x ^ (x<<s) ^ (x>>(64-s)) ^ 0xAA55AA55AA55AA55ULL ^ seq;
+		x = x ^ (x << s) ^ (x >> (64 - s)) ^ 0xAA55AA55AA55AA55ULL ^
+		    seq;
 	}
 }
-		
-static inline int checkbuf(char *buf, uint64_t seq, uint64_t blknum) {
-	uint64_t cmp[64]; // 512/8 = 64
+
+static inline int checkbuf(char *buf, uint64_t seq, uint64_t blknum)
+{
+	uint64_t cmp[64];	// 512/8 = 64
 	makebuf((char *)cmp, seq, blknum);
-	return memcmp(cmp, buf, 512)?-1:0;
+	return memcmp(cmp, buf, 512) ? -1 : 0;
 }
 
-static inline void dumpcommand(char * text, uint32_t command)
+static inline void dumpcommand(char *text, uint32_t command)
 {
 #ifdef DEBUG_COMMANDS
-	command=ntohl(command);
-	char * ctext;
+	command = ntohl(command);
+	char *ctext;
 	switch (command & NBD_CMD_MASK_COMMAND) {
 	case NBD_CMD_READ:
-		ctext="NBD_CMD_READ";
+		ctext = "NBD_CMD_READ";
 		break;
 	case NBD_CMD_WRITE:
-		ctext="NBD_CMD_WRITE";
+		ctext = "NBD_CMD_WRITE";
 		break;
 	case NBD_CMD_DISC:
-		ctext="NBD_CMD_DISC";
+		ctext = "NBD_CMD_DISC";
 		break;
 	case NBD_CMD_FLUSH:
-		ctext="NBD_CMD_FLUSH";
+		ctext = "NBD_CMD_FLUSH";
 		break;
 	default:
-		ctext="UNKNOWN";
+		ctext = "UNKNOWN";
 		break;
 	}
 	printf("%s: %s [%s] (0x%08x)\n",
 	       text,
-	       ctext,
-	       (command & NBD_CMD_FLAG_FUA)?"FUA":"NONE",
-	       command);
+	       ctext, (command & NBD_CMD_FLAG_FUA) ? "FUA" : "NONE", command);
 #endif
 }
 
 /* return an unused handle */
-uint64_t getrandomhandle(GHashTable *phash) {
+uint64_t getrandomhandle(GHashTable * phash)
+{
 	uint64_t handle = 0;
 	int i;
 	do {
 		/* RAND_MAX may be as low as 2^15 */
-		for (i= 1 ; i<=5; i++)
-			handle ^= random() ^ (handle << 15); 
+		for (i = 1; i <= 5; i++)
+			handle ^= random() ^ (handle << 15);
 	} while (g_hash_table_lookup(phash, &handle));
 	return handle;
 }
 
-int integrity_test(gchar* hostname, gchar* unixsock, int port, char* name, int sock,
-		   char sock_is_open, char close_sock, int testflags) {
+int integrity_test(gchar * hostname, gchar * unixsock, int port, char *name,
+		   int sock, char sock_is_open, char close_sock, int testflags)
+{
 	struct nbd_reply rep;
 	fd_set rset;
 	fd_set wset;
@@ -849,28 +944,31 @@ int integrity_test(gchar* hostname, gchar* unixsock, int port, char* name, int s
 	double timespan;
 	double speed;
 	char speedchar[2] = { '\0', '\0' };
-	int retval=-1;
+	int retval = -1;
 	int serverflags = 0;
 	pid_t G_GNUC_UNUSED mypid = getpid();
 	int blkhashfd = -1;
-	char *blkhashname=NULL;
+	char *blkhashname = NULL;
 	struct blkitem *blkhash = NULL;
-	int logfd=-1;
-	uint64_t seq=1;
-	uint64_t processed=0;
-	uint64_t printer=0;
-	uint64_t xfer=0;
+	int logfd = -1;
+	uint64_t seq = 1;
+	uint64_t processed = 0;
+	uint64_t printer = 0;
+	uint64_t xfer = 0;
 	int readtransactionfile = 1;
 	int blocked = 0;
-	struct rclist txqueue={NULL, NULL, 0};
-	struct rclist inflight={NULL, NULL, 0};
-	struct chunklist txbuf={NULL, NULL, 0};
+	struct rclist txqueue = { NULL, NULL, 0 };
+	struct rclist inflight = { NULL, NULL, 0 };
+	struct chunklist txbuf = { NULL, NULL, 0 };
 
 	GHashTable *handlehash = g_hash_table_new(g_int64_hash, g_int64_equal);
 
-	size=0;
-	if(!sock_is_open) {
-		if((sock=setup_connection(hostname, unixsock, port, name, CONNECTION_TYPE_FULL, &serverflags))<0) {
+	size = 0;
+	if (!sock_is_open) {
+		if ((sock =
+		     setup_connection(hostname, unixsock, port, name,
+				      CONNECTION_TYPE_FULL,
+				      &serverflags)) < 0) {
 			g_warning("Could not open socket: %s", errstr);
 			goto err;
 		}
@@ -878,19 +976,20 @@ int integrity_test(gchar* hostname, gchar* unixsock, int port, char* name, int s
 
 	if ((serverflags & (NBD_FLAG_SEND_FLUSH | NBD_FLAG_SEND_FUA))
 	    != (NBD_FLAG_SEND_FLUSH | NBD_FLAG_SEND_FUA))
-		g_warning("Server flags do not support FLUSH and FUA - these may error");
+		g_warning
+		    ("Server flags do not support FLUSH and FUA - these may error");
 
 #ifdef HAVE_MKSTEMP
-	blkhashname=strdup("/tmp/blkarray-XXXXXX");
+	blkhashname = strdup("/tmp/blkarray-XXXXXX");
 	if (!blkhashname || (-1 == (blkhashfd = mkstemp(blkhashname)))) {
 		g_warning("Could not open temp file: %s", strerror(errno));
 		goto err;
 	}
 #else
 	/* use tmpnam here to avoid further feature test nightmare */
-	if (-1 == (blkhashfd = open(blkhashname=strdup(tmpnam(NULL)),
+	if (-1 == (blkhashfd = open(blkhashname = strdup(tmpnam(NULL)),
 				    O_CREAT | O_RDWR,
-				    S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH))) {
+				    S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH))) {
 		g_warning("Could not open temp file: %s", strerror(errno));
 		goto err;
 	}
@@ -901,7 +1000,9 @@ int integrity_test(gchar* hostname, gchar* unixsock, int port, char* name, int s
 		goto err;
 	}
 
-	if (-1 == lseek(blkhashfd, (off_t)((size>>9)*sizeof(struct blkitem)), SEEK_SET)) {
+	if (-1 ==
+	    lseek(blkhashfd, (off_t) ((size >> 9) * sizeof(struct blkitem)),
+		  SEEK_SET)) {
 		g_warning("Could not llseek temp file: %s", strerror(errno));
 		goto err;
 	}
@@ -912,36 +1013,35 @@ int integrity_test(gchar* hostname, gchar* unixsock, int port, char* name, int s
 	}
 
 	if (NULL == (blkhash = mmap(NULL,
-				    (size>>9)*sizeof(struct blkitem),
+				    (size >> 9) * sizeof(struct blkitem),
 				    PROT_READ | PROT_WRITE,
-				    MAP_SHARED,
-				    blkhashfd,
-				    0))) {
+				    MAP_SHARED, blkhashfd, 0))) {
 		g_warning("Could not mmap temp file: %s", strerror(errno));
 		goto err;
 	}
 
-	if (-1 == (logfd = open(transactionlog, O_RDONLY)))
-	{
+	if (-1 == (logfd = open(transactionlog, O_RDONLY))) {
 		g_warning("Could open log file: %s", strerror(errno));
 		goto err;
 	}
-		
-	if(gettimeofday(&start, NULL)<0) {
-		snprintf(errstr, errstr_len, "Could not measure start time: %s", strerror(errno));
+
+	if (gettimeofday(&start, NULL) < 0) {
+		snprintf(errstr, errstr_len, "Could not measure start time: %s",
+			 strerror(errno));
 		goto err_open;
 	}
 
-	while (readtransactionfile || txqueue.numitems || txbuf.numitems || inflight.numitems) {
+	while (readtransactionfile || txqueue.numitems || txbuf.numitems
+	       || inflight.numitems) {
 		int ret;
 
 		uint32_t magic;
-                uint32_t command;
-                uint64_t from;
-                uint32_t len;
-		struct reqcontext * prc;
+		uint32_t command;
+		uint64_t from;
+		uint32_t len;
+		struct reqcontext *prc;
 
-		*errstr=0;
+		*errstr = 0;
 
 		FD_ZERO(&wset);
 		FD_ZERO(&rset);
@@ -951,13 +1051,16 @@ int integrity_test(gchar* hostname, gchar* unixsock, int port, char* name, int s
 			FD_SET(sock, &wset);
 		if (inflight.numitems)
 			FD_SET(sock, &rset);
-		tv.tv_sec=5;
-		tv.tv_usec=0;
-		ret = select(1+((sock>logfd)?sock:logfd), &rset, &wset, NULL, &tv);
+		tv.tv_sec = 5;
+		tv.tv_usec = 0;
+		ret =
+		    select(1 + ((sock > logfd) ? sock : logfd), &rset, &wset,
+			   NULL, &tv);
 		if (ret == 0) {
-			snprintf(errstr, errstr_len, "Timeout reading from socket");
+			snprintf(errstr, errstr_len,
+				 "Timeout reading from socket");
 			goto err_open;
-		} else if (ret<0) {
+		} else if (ret < 0) {
 			g_warning("Could not mmap temp file: %s", errstr);
 			goto err;
 		}
@@ -965,7 +1068,7 @@ int integrity_test(gchar* hostname, gchar* unixsock, int port, char* name, int s
 
 		/* Get a command from the transaction log */
 		if (FD_ISSET(logfd, &rset)) {
-			
+
 			/* Read a request or reply from the transaction file */
 			READ_ALL_ERRCHK(logfd,
 					&magic,
@@ -976,67 +1079,77 @@ int integrity_test(gchar* hostname, gchar* unixsock, int port, char* name, int s
 			magic = ntohl(magic);
 			switch (magic) {
 			case NBD_REQUEST_MAGIC:
-				if (NULL == (prc = calloc(1, sizeof(struct reqcontext)))) {
-					snprintf(errstr, errstr_len, "Could not allocate request");
+				if (NULL ==
+				    (prc =
+				     calloc(1, sizeof(struct reqcontext)))) {
+					snprintf(errstr, errstr_len,
+						 "Could not allocate request");
 					goto err_open;
 				}
 				READ_ALL_ERRCHK(logfd,
-						sizeof(magic)+(char *)&(prc->req),
-						sizeof(struct nbd_request)-sizeof(magic),
-						err_open,
+						sizeof(magic) +
+						(char *)&(prc->req),
+						sizeof(struct nbd_request) -
+						sizeof(magic), err_open,
 						"Could not read transaction log: %s",
 						strerror(errno));
 				prc->req.magic = htonl(NBD_REQUEST_MAGIC);
 				memcpy(prc->orighandle, prc->req.handle, 8);
-				prc->seq=seq++;
-				if ((ntohl(prc->req.type) & NBD_CMD_MASK_COMMAND) == NBD_CMD_DISC) {
+				prc->seq = seq++;
+				if ((ntohl(prc->req.type) &
+				     NBD_CMD_MASK_COMMAND) == NBD_CMD_DISC) {
 					/* no more to read; don't enqueue as no reply
 					 * we will disconnect manually at the end
 					 */
 					readtransactionfile = 0;
-					free (prc);
+					free(prc);
 				} else {
-					dumpcommand("Enqueuing command", prc->req.type);
+					dumpcommand("Enqueuing command",
+						    prc->req.type);
 					rclist_addtail(&txqueue, prc);
 				}
 				prc = NULL;
 				break;
 			case NBD_REPLY_MAGIC:
 				READ_ALL_ERRCHK(logfd,
-						sizeof(magic)+(char *)(&rep),
-						sizeof(struct nbd_reply)-sizeof(magic),
-						err_open,
+						sizeof(magic) + (char *)(&rep),
+						sizeof(struct nbd_reply) -
+						sizeof(magic), err_open,
 						"Could not read transaction log: %s",
 						strerror(errno));
 
 				if (rep.error) {
-					snprintf(errstr, errstr_len, "Transaction log file contained errored transaction");
+					snprintf(errstr, errstr_len,
+						 "Transaction log file contained errored transaction");
 					goto err_open;
 				}
-					
+
 				/* We do not need to consume data on a read reply as there is
 				 * none in the log */
 				break;
 			default:
-				snprintf(errstr, errstr_len, "Could not measure start time: %08x", magic);
+				snprintf(errstr, errstr_len,
+					 "Could not measure start time: %08x",
+					 magic);
 				goto err_open;
 			}
 		}
 
 		/* See if we have a write we can do */
-		if (FD_ISSET(sock, &wset))
-		{
+		if (FD_ISSET(sock, &wset)) {
 			if ((!(txqueue.head) && !(txbuf.head)) || blocked)
-				g_warning("Socket write FD set but we shouldn't have been interested");
+				g_warning
+				    ("Socket write FD set but we shouldn't have been interested");
 
 			/* If there is no buffered data, generate some */
-			if (!blocked && !(txbuf.head) && (NULL != (prc = txqueue.head)))
-			{
+			if (!blocked && !(txbuf.head)
+			    && (NULL != (prc = txqueue.head))) {
 				if (ntohl(prc->req.magic) != NBD_REQUEST_MAGIC) {
-					g_warning("Asked to write a request without a magic number");
+					g_warning
+					    ("Asked to write a request without a magic number");
 					goto err_open;
 				}
-					
+
 				command = ntohl(prc->req.type);
 				from = ntohll(prc->req.from);
 				len = ntohl(prc->req.len);
@@ -1046,24 +1159,31 @@ int integrity_test(gchar* hostname, gchar* unixsock, int port, char* name, int s
 				 * command is a write, and there is an inflight read or write, then
 				 * we need to leave the command alone and signal that we are blocked
 				 */
-				
-				if (!looseordering)
-				{
+
+				if (!looseordering) {
 					uint64_t cfrom;
 					uint32_t clen;
 					cfrom = from;
 					clen = len;
 					while (clen > 0) {
-						uint64_t blknum = cfrom>>9;
-						if (cfrom>=size) {
-							snprintf(errstr, errstr_len, "offset %llx beyond size %llx",
-								 (long long int) cfrom, (long long int)size);
+						uint64_t blknum = cfrom >> 9;
+						if (cfrom >= size) {
+							snprintf(errstr,
+								 errstr_len,
+								 "offset %llx beyond size %llx",
+								 (long long int)
+								 cfrom,
+								 (long long int)
+								 size);
 							goto err_open;
 						}
 						if (blkhash[blknum].inflightw ||
-						    (blkhash[blknum].inflightr &&
-						     ((command & NBD_CMD_MASK_COMMAND)==NBD_CMD_WRITE))) {
-							blocked=1;
+						    (blkhash[blknum].inflightr
+						     &&
+						     ((command &
+						       NBD_CMD_MASK_COMMAND) ==
+						      NBD_CMD_WRITE))) {
+							blocked = 1;
 							break;
 						}
 						cfrom += 512;
@@ -1076,21 +1196,29 @@ int integrity_test(gchar* hostname, gchar* unixsock, int port, char* name, int s
 
 				rclist_unlink(&txqueue, prc);
 				rclist_addtail(&inflight, prc);
-				
+
 				dumpcommand("Sending command", prc->req.type);
 				/* we rewrite the handle as they otherwise may not be unique */
-				*((uint64_t*)(prc->req.handle))=getrandomhandle(handlehash);
-				g_hash_table_insert(handlehash, prc->req.handle, prc);
-				addbuffer(&txbuf, &(prc->req), sizeof(struct nbd_request));
+				*((uint64_t *) (prc->req.handle)) =
+				    getrandomhandle(handlehash);
+				g_hash_table_insert(handlehash, prc->req.handle,
+						    prc);
+				addbuffer(&txbuf, &(prc->req),
+					  sizeof(struct nbd_request));
 				switch (command & NBD_CMD_MASK_COMMAND) {
 				case NBD_CMD_WRITE:
-					xfer+=len;
-					while (len > 0)	{
-						uint64_t blknum = from>>9;
+					xfer += len;
+					while (len > 0) {
+						uint64_t blknum = from >> 9;
 						char dbuf[512];
-						if (from>=size) {
-							snprintf(errstr, errstr_len, "offset %llx beyond size %llx",
-								 (long long int) from, (long long int)size);
+						if (from >= size) {
+							snprintf(errstr,
+								 errstr_len,
+								 "offset %llx beyond size %llx",
+								 (long long int)
+								 from,
+								 (long long int)
+								 size);
 							goto err_open;
 						}
 						(blkhash[blknum].inflightw)++;
@@ -1102,12 +1230,17 @@ int integrity_test(gchar* hostname, gchar* unixsock, int port, char* name, int s
 					}
 					break;
 				case NBD_CMD_READ:
-					xfer+=len;
-					while (len > 0)	{
-						uint64_t blknum = from>>9;
-						if (from>=size) {
-							snprintf(errstr, errstr_len, "offset %llx beyond size %llx",
-								 (long long int) from, (long long int)size);
+					xfer += len;
+					while (len > 0) {
+						uint64_t blknum = from >> 9;
+						if (from >= size) {
+							snprintf(errstr,
+								 errstr_len,
+								 "offset %llx beyond size %llx",
+								 (long long int)
+								 from,
+								 (long long int)
+								 size);
 							goto err_open;
 						}
 						(blkhash[blknum].inflightr)++;
@@ -1119,25 +1252,29 @@ int integrity_test(gchar* hostname, gchar* unixsock, int port, char* name, int s
 				case NBD_CMD_FLUSH:
 					break;
 				default:
-					snprintf(errstr, errstr_len, "Incomprehensible command: %08x", command);
+					snprintf(errstr, errstr_len,
+						 "Incomprehensible command: %08x",
+						 command);
 					goto err_open;
 					break;
 				}
-				
+
 				prc = NULL;
 			}
-		skipdequeue:
+skipdequeue:
 
 			/* there should be some now */
-			if (writebuffer(sock, &txbuf)<0) {
-				snprintf(errstr, errstr_len, "Failed to write to socket buffer: %s", strerror(errno));
+			if (writebuffer(sock, &txbuf) < 0) {
+				snprintf(errstr, errstr_len,
+					 "Failed to write to socket buffer: %s",
+					 strerror(errno));
 				goto err_open;
 			}
-			
+
 		}
 
 		/* See if there is a reply to be processed from the socket */
-		if(FD_ISSET(sock, &rset)) {
+		if (FD_ISSET(sock, &rset)) {
 			/* Okay, there's something ready for
 			 * reading here */
 
@@ -1147,47 +1284,60 @@ int integrity_test(gchar* hostname, gchar* unixsock, int port, char* name, int s
 					err_open,
 					"Could not read from server socket: %s",
 					strerror(errno));
-			
+
 			if (rep.magic != htonl(NBD_REPLY_MAGIC)) {
-				snprintf(errstr, errstr_len, "Bad magic from server");
+				snprintf(errstr, errstr_len,
+					 "Bad magic from server");
 				goto err_open;
 			}
-			
+
 			if (rep.error) {
-				snprintf(errstr, errstr_len, "Server errored a transaction");
+				snprintf(errstr, errstr_len,
+					 "Server errored a transaction");
 				goto err_open;
 			}
-				
+
 			uint64_t handle;
-			memcpy(&handle,rep.handle,8);
+			memcpy(&handle, rep.handle, 8);
 			prc = g_hash_table_lookup(handlehash, &handle);
 			if (!prc) {
-				snprintf(errstr, errstr_len, "Unrecognised handle in reply: 0x%llX", *(long long unsigned int*)(rep.handle));
+				snprintf(errstr, errstr_len,
+					 "Unrecognised handle in reply: 0x%llX",
+					 *(long long unsigned int *)(rep.
+								     handle));
 				goto err_open;
 			}
 			if (!g_hash_table_remove(handlehash, &handle)) {
-				snprintf(errstr, errstr_len, "Could not remove handle from hash: 0x%llX", *(long long unsigned int*)(rep.handle));
+				snprintf(errstr, errstr_len,
+					 "Could not remove handle from hash: 0x%llX",
+					 *(long long unsigned int *)(rep.
+								     handle));
 				goto err_open;
 			}
 
 			if (prc->req.magic != htonl(NBD_REQUEST_MAGIC)) {
-				snprintf(errstr, errstr_len, "Bad magic in inflight data: %08x", prc->req.magic);
+				snprintf(errstr, errstr_len,
+					 "Bad magic in inflight data: %08x",
+					 prc->req.magic);
 				goto err_open;
 			}
-			
-			dumpcommand("Processing reply to command", prc->req.type);
+
+			dumpcommand("Processing reply to command",
+				    prc->req.type);
 			command = ntohl(prc->req.type);
 			from = ntohll(prc->req.from);
 			len = ntohl(prc->req.len);
-			
+
 			switch (command & NBD_CMD_MASK_COMMAND) {
 			case NBD_CMD_READ:
-				while (len > 0)	{
-					uint64_t blknum = from>>9;
+				while (len > 0) {
+					uint64_t blknum = from >> 9;
 					char dbuf[512];
-					if (from>=size) {
-						snprintf(errstr, errstr_len, "offset %llx beyond size %llx",
-							 (long long int) from, (long long int)size);
+					if (from >= size) {
+						snprintf(errstr, errstr_len,
+							 "offset %llx beyond size %llx",
+							 (long long int)from,
+							 (long long int)size);
 						goto err_open;
 					}
 					READ_ALL_ERRCHK(sock,
@@ -1196,36 +1346,44 @@ int integrity_test(gchar* hostname, gchar* unixsock, int port, char* name, int s
 							err_open,
 							"Could not read data: %s",
 							strerror(errno));
-					if (--(blkhash[blknum].inflightr) <0 ) {
-						snprintf(errstr, errstr_len, "Received a read reply for offset %llx when not in flight",
-							 (long long int) from);
+					if (--(blkhash[blknum].inflightr) < 0) {
+						snprintf(errstr, errstr_len,
+							 "Received a read reply for offset %llx when not in flight",
+							 (long long int)from);
 						goto err_open;
 					}
 					/* work out what we was written */
-					if (checkbuf(dbuf, blkhash[blknum].seq, blknum)) {
-						snprintf(errstr, errstr_len, "Bad reply data: I wanted blk %08x, seq %08x but I got (at a guess) blk %08x, seq %08x",
-							 (unsigned int) blknum,
+					if (checkbuf
+					    (dbuf, blkhash[blknum].seq,
+					     blknum)) {
+						snprintf(errstr, errstr_len,
+							 "Bad reply data: I wanted blk %08x, seq %08x but I got (at a guess) blk %08x, seq %08x",
+							 (unsigned int)blknum,
 							 blkhash[blknum].seq,
-							 ((uint32_t *)(dbuf))[0],
-							 ((uint32_t *)(dbuf))[1]
-							 );
+							 ((uint32_t
+							   *) (dbuf))[0],
+							 ((uint32_t
+							   *) (dbuf))[1]
+						    );
 						goto err_open;
-						
+
 					}
 					from += 512;
 					len -= 512;
 				}
 				break;
 			case NBD_CMD_WRITE:
-				/* subsequent reads should get data with this seq*/
-				while (len > 0)	{
-					uint64_t blknum = from>>9;
-					if (--(blkhash[blknum].inflightw) <0 ) {
-						snprintf(errstr, errstr_len, "Received a write reply for offset %llx when not in flight",
-							 (long long int) from);
+				/* subsequent reads should get data with this seq */
+				while (len > 0) {
+					uint64_t blknum = from >> 9;
+					if (--(blkhash[blknum].inflightw) < 0) {
+						snprintf(errstr, errstr_len,
+							 "Received a write reply for offset %llx when not in flight",
+							 (long long int)from);
 						goto err_open;
 					}
-					blkhash[blknum].seq=(uint32_t)(prc->seq);
+					blkhash[blknum].seq =
+					    (uint32_t) (prc->seq);
 					from += 512;
 					len -= 512;
 				}
@@ -1236,154 +1394,165 @@ int integrity_test(gchar* hostname, gchar* unixsock, int port, char* name, int s
 			blocked = 0;
 			processed++;
 			rclist_unlink(&inflight, prc);
-			prc->req.magic=0; /* so a duplicate reply is detected */
+			prc->req.magic = 0;	/* so a duplicate reply is detected */
 			free(prc);
 		}
 
-		if (!(printer++ % 1000) || !(readtransactionfile || txqueue.numitems || inflight.numitems) )
-			printf("%d: Seq %08lld Queued: %08d Inflight: %08d Done: %08lld\r",
-			       (int)mypid,
-			       (long long int) seq,
-			       txqueue.numitems,
-			       inflight.numitems,
-			       (long long int) processed);
+		if (!(printer++ % 1000)
+		    || !(readtransactionfile || txqueue.numitems
+			 || inflight.numitems))
+			printf
+			    ("%d: Seq %08lld Queued: %08d Inflight: %08d Done: %08lld\r",
+			     (int)mypid, (long long int)seq, txqueue.numitems,
+			     inflight.numitems, (long long int)processed);
 
 	}
 
 	printf("\n");
 
-	if (gettimeofday(&stop, NULL)<0) {
-		snprintf(errstr, errstr_len, "Could not measure end time: %s", strerror(errno));
+	if (gettimeofday(&stop, NULL) < 0) {
+		snprintf(errstr, errstr_len, "Could not measure end time: %s",
+			 strerror(errno));
 		goto err_open;
 	}
-	timespan=timeval_diff_to_double(&stop, &start);
-	speed=xfer/timespan;
-	if(speed>1024) {
-		speed=speed/1024.0;
-		speedchar[0]='K';
+	timespan = timeval_diff_to_double(&stop, &start);
+	speed = xfer / timespan;
+	if (speed > 1024) {
+		speed = speed / 1024.0;
+		speedchar[0] = 'K';
 	}
-	if(speed>1024) {
-		speed=speed/1024.0;
-		speedchar[0]='M';
+	if (speed > 1024) {
+		speed = speed / 1024.0;
+		speedchar[0] = 'M';
 	}
-	if(speed>1024) {
-		speed=speed/1024.0;
-		speedchar[0]='G';
+	if (speed > 1024) {
+		speed = speed / 1024.0;
+		speedchar[0] = 'G';
 	}
-	g_message("%d: Integrity %s test complete. Took %.3f seconds to complete, %.3f%sib/s", (int)getpid(), (testflags & TEST_WRITE)?"write":"read", timespan, speed, speedchar);
+	g_message
+	    ("%d: Integrity %s test complete. Took %.3f seconds to complete, %.3f%sib/s",
+	     (int)getpid(), (testflags & TEST_WRITE) ? "write" : "read",
+	     timespan, speed, speedchar);
 
 	retval = 0;
 
 err_open:
-	if(close_sock) {
+	if (close_sock) {
 		close_connection(sock, CONNECTION_CLOSE_PROPERLY);
 	}
 err:
 	if (size && blkhash)
-		munmap(blkhash, (size>>9)*sizeof(struct blkitem));
+		munmap(blkhash, (size >> 9) * sizeof(struct blkitem));
 
 	if (blkhashfd != -1)
-		close (blkhashfd);
+		close(blkhashfd);
 
 	if (logfd != -1)
-		close (logfd);
+		close(logfd);
 
 	if (blkhashname)
 		free(blkhashname);
 
 	if (*errstr)
-		g_warning("%s",errstr);
+		g_warning("%s", errstr);
 
 	g_hash_table_destroy(handlehash);
 
 	return retval;
 }
 
-void handle_nonopt(char* opt, gchar** hostname, long int* p) {
-	static int nonopt=0;
+void handle_nonopt(char *opt, gchar ** hostname, long int *p)
+{
+	static int nonopt = 0;
 
-	switch(nonopt) {
-		case 0:
-			*hostname=g_strdup(opt);
-			nonopt++;
-			break;
-		case 1:
-			*p=(strtol(opt, NULL, 0));
-			if(*p==LONG_MIN||*p==LONG_MAX) {
-				g_critical("Could not parse port number: %s", strerror(errno));
-				exit(EXIT_FAILURE);
-			}
-			break;
+	switch (nonopt) {
+	case 0:
+		*hostname = g_strdup(opt);
+		nonopt++;
+		break;
+	case 1:
+		*p = (strtol(opt, NULL, 0));
+		if (*p == LONG_MIN || *p == LONG_MAX) {
+			g_critical("Could not parse port number: %s",
+				   strerror(errno));
+			exit(EXIT_FAILURE);
+		}
+		break;
 	}
 }
 
-typedef int (*testfunc)(gchar*, gchar*, int, char*, int, char, char, int);
+typedef int (*testfunc) (gchar *, gchar *, int, char *, int, char, char, int);
 
-int main(int argc, char**argv) {
-	gchar *hostname=NULL, *unixsock=NULL;
+int main(int argc, char **argv)
+{
+	gchar *hostname = NULL, *unixsock = NULL;
 	long int p = 0;
-	char* name = NULL;
-	int sock=0;
+	char *name = NULL;
+	int sock = 0;
 	int c;
-	int testflags=0;
+	int testflags = 0;
 	testfunc test = throughput_test;
 
 	/* Ignore SIGPIPE as we want to pick up the error from write() */
-	signal (SIGPIPE, SIG_IGN);
+	signal(SIGPIPE, SIG_IGN);
 
-	errstr[errstr_len]='\0';
+	errstr[errstr_len] = '\0';
 
-	if(argc<3) {
+	if (argc < 3) {
 		g_message("%d: Not enough arguments", (int)getpid());
-		g_message("%d: Usage: %s <hostname> <port>", (int)getpid(), argv[0]);
-		g_message("%d: Or: %s <hostname> -N <exportname> [<port>]", (int)getpid(), argv[0]);
-		g_message("%d: Or: %s -u <unix socket> -N <exportname>", (int)getpid(), argv[0]);
+		g_message("%d: Usage: %s <hostname> <port>", (int)getpid(),
+			  argv[0]);
+		g_message("%d: Or: %s <hostname> -N <exportname> [<port>]",
+			  (int)getpid(), argv[0]);
+		g_message("%d: Or: %s -u <unix socket> -N <exportname>",
+			  (int)getpid(), argv[0]);
 		exit(EXIT_FAILURE);
 	}
 	logging(MY_NAME);
-	while((c=getopt(argc, argv, "-FN:t:owfilu:"))>=0) {
-		switch(c) {
-			case 1:
-				handle_nonopt(optarg, &hostname, &p);
-				break;
-			case 'N':
-				name=g_strdup(optarg);
-				if(!p) {
-					p = 10809;
-				}
-				break;
-			case 'F':
-				testflags|=TEST_EXPECT_ERROR;
-				break;
-			case 't':
-				transactionlog=g_strdup(optarg);
-				break;
-			case 'o':
-				test=oversize_test;
-				break;
-			case 'l':
-				looseordering=1;
-				break;
-			case 'w':
-				testflags|=TEST_WRITE;
-				break;
-			case 'f':
-				testflags|=TEST_FLUSH;
-				break;
-			case 'i':
-				test=integrity_test;
-				break;
-			case 'u':
-				unixsock=g_strdup(optarg);
-				break;
+	while ((c = getopt(argc, argv, "-FN:t:owfilu:")) >= 0) {
+		switch (c) {
+		case 1:
+			handle_nonopt(optarg, &hostname, &p);
+			break;
+		case 'N':
+			name = g_strdup(optarg);
+			if (!p) {
+				p = 10809;
+			}
+			break;
+		case 'F':
+			testflags |= TEST_EXPECT_ERROR;
+			break;
+		case 't':
+			transactionlog = g_strdup(optarg);
+			break;
+		case 'o':
+			test = oversize_test;
+			break;
+		case 'l':
+			looseordering = 1;
+			break;
+		case 'w':
+			testflags |= TEST_WRITE;
+			break;
+		case 'f':
+			testflags |= TEST_FLUSH;
+			break;
+		case 'i':
+			test = integrity_test;
+			break;
+		case 'u':
+			unixsock = g_strdup(optarg);
+			break;
 		}
 	}
 
-	while(optind < argc) {
+	while (optind < argc) {
 		handle_nonopt(argv[optind++], &hostname, &p);
 	}
 
-	if(test(hostname, unixsock, (int)p, name, sock, FALSE, TRUE, testflags)<0) {
+	if (test(hostname, unixsock, (int)p, name, sock, FALSE, TRUE, testflags)
+	    < 0) {
 		g_warning("Could not run test: %s", errstr);
 		exit(EXIT_FAILURE);
 	}
-- 
1.9.1




Reply to: