2 * Test client to test the NBD server. Doesn't do anything useful, except
3 * checking that the server does, actually, work.
5 * Note that the only 'real' test is to check the client against a kernel. If
6 * it works here but does not work in the kernel, then that's most likely a bug
7 * in this program and/or in nbd-server.
9 * Copyright(c) 2006 Wouter Verhelst
11 * This program is Free Software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the Free
13 * Software Foundation, in version 2.
15 * This program is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
20 * You should have received a copy of the GNU General Public License along with
21 * this program; if not, write to the Free Software Foundation, Inc., 51
22 * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 #include <sys/types.h>
30 #include <sys/socket.h>
38 #include <netinet/in.h>
41 #define MY_NAME "nbd-tester-client"
44 static gchar errstr[1024];
45 const static int errstr_len=1024;
49 static gchar * transactionlog = "nbd-tester-client.tr";
53 CONNECTION_TYPE_CONNECT,
54 CONNECTION_TYPE_INIT_PASSWD,
55 CONNECTION_TYPE_CLISERV,
60 CONNECTION_CLOSE_PROPERLY,
61 CONNECTION_CLOSE_FAST,
66 struct nbd_request req;
67 struct reqcontext * next;
68 struct reqcontext * prev;
72 struct reqcontext * head;
73 struct reqcontext * tail;
77 void rclist_unlink(struct rclist * l, struct reqcontext * p) {
79 struct reqcontext * prev = p->prev;
80 struct reqcontext * next = p->next;
82 /* Fix link to previous */
99 /* Add a new list item to the tail */
100 void rclist_addtail(struct rclist * l, struct reqcontext * p)
106 g_warning("addtail found list tail has a next pointer");
113 g_warning("addtail found no list tail but a list head");
122 #define TEST_WRITE (1<<0)
123 #define TEST_FLUSH (1<<1)
125 int timeval_subtract (struct timeval *result, struct timeval *x,
127 if (x->tv_usec < y->tv_usec) {
128 int nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1;
129 y->tv_usec -= 1000000 * nsec;
133 if (x->tv_usec - y->tv_usec > 1000000) {
134 int nsec = (x->tv_usec - y->tv_usec) / 1000000;
135 y->tv_usec += 1000000 * nsec;
139 result->tv_sec = x->tv_sec - y->tv_sec;
140 result->tv_usec = x->tv_usec - y->tv_usec;
142 return x->tv_sec < y->tv_sec;
145 double timeval_diff_to_double (struct timeval * x, struct timeval * y) {
147 timeval_subtract(&r, x, y);
148 return r.tv_sec * 1.0 + r.tv_usec/1000000.0;
151 static inline int read_all(int f, void *buf, size_t len) {
156 if((res=read(f, buf, len)) <=0) {
159 snprintf(errstr, errstr_len, "Read failed: %s", strerror(errno));
169 static inline int write_all(int f, void *buf, size_t len) {
174 if((res=write(f, buf, len)) <=0) {
177 snprintf(errstr, errstr_len, "Write failed: %s", strerror(errno));
187 #define READ_ALL_ERRCHK(f, buf, len, whereto, errmsg...) if((read_all(f, buf, len))<=0) { snprintf(errstr, errstr_len, ##errmsg); goto whereto; }
188 #define READ_ALL_ERR_RT(f, buf, len, whereto, rval, errmsg...) if((read_all(f, buf, len))<=0) { snprintf(errstr, errstr_len, ##errmsg); retval = rval; goto whereto; }
190 #define WRITE_ALL_ERRCHK(f, buf, len, whereto, errmsg...) if((write_all(f, buf, len))<=0) { snprintf(errstr, errstr_len, ##errmsg); goto whereto; }
191 #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; }
193 int setup_connection(gchar *hostname, int port, gchar* name, CONNECTION_TYPE ctype, int* serverflags) {
195 struct hostent *host;
196 struct sockaddr_in addr;
198 uint64_t mymagic = (name ? opts_magic : cliserv_magic);
203 if(ctype<CONNECTION_TYPE_CONNECT)
205 if((sock=socket(PF_INET, SOCK_STREAM, IPPROTO_TCP))<0) {
206 strncpy(errstr, strerror(errno), errstr_len);
210 if(!(host=gethostbyname(hostname))) {
211 strncpy(errstr, strerror(errno), errstr_len);
214 addr.sin_family=AF_INET;
215 addr.sin_port=htons(port);
216 addr.sin_addr.s_addr=*((int *) host->h_addr);
217 if((connect(sock, (struct sockaddr *)&addr, sizeof(addr))<0)) {
218 strncpy(errstr, strerror(errno), errstr_len);
221 if(ctype<CONNECTION_TYPE_INIT_PASSWD)
223 READ_ALL_ERRCHK(sock, buf, strlen(INIT_PASSWD), err_open, "Could not read INIT_PASSWD: %s", strerror(errno));
225 snprintf(errstr, errstr_len, "Server closed connection");
228 if(strncmp(buf, INIT_PASSWD, strlen(INIT_PASSWD))) {
229 snprintf(errstr, errstr_len, "INIT_PASSWD does not match");
232 if(ctype<CONNECTION_TYPE_CLISERV)
234 READ_ALL_ERRCHK(sock, &tmp64, sizeof(tmp64), err_open, "Could not read cliserv_magic: %s", strerror(errno));
236 if(tmp64 != mymagic) {
237 strncpy(errstr, "mymagic does not match", errstr_len);
240 if(ctype<CONNECTION_TYPE_FULL)
243 READ_ALL_ERRCHK(sock, &size, sizeof(size), err_open, "Could not read size: %s", strerror(errno));
245 READ_ALL_ERRCHK(sock, buf, 128, err_open, "Could not read data: %s", strerror(errno));
249 READ_ALL_ERRCHK(sock, buf, sizeof(uint16_t), err_open, "Could not read reserved field: %s", strerror(errno));
251 WRITE_ALL_ERRCHK(sock, &tmp32, sizeof(tmp32), err_open, "Could not write reserved field: %s", strerror(errno));
253 tmp64 = htonll(opts_magic);
254 WRITE_ALL_ERRCHK(sock, &tmp64, sizeof(tmp64), err_open, "Could not write magic: %s", strerror(errno));
256 tmp32 = htonl(NBD_OPT_EXPORT_NAME);
257 WRITE_ALL_ERRCHK(sock, &tmp32, sizeof(tmp32), err_open, "Could not write option: %s", strerror(errno));
258 tmp32 = htonl((uint32_t)strlen(name));
259 WRITE_ALL_ERRCHK(sock, &tmp32, sizeof(tmp32), err_open, "Could not write name length: %s", strerror(errno));
260 WRITE_ALL_ERRCHK(sock, name, strlen(name), err_open, "Could not write name:: %s", strerror(errno));
261 READ_ALL_ERRCHK(sock, &size, sizeof(size), err_open, "Could not read size: %s", strerror(errno));
264 READ_ALL_ERRCHK(sock, &flags, sizeof(uint16_t), err_open, "Could not read flags: %s", strerror(errno));
265 flags = ntohs(flags);
266 *serverflags = flags;
267 READ_ALL_ERRCHK(sock, buf, 124, err_open, "Could not read reserved zeroes: %s", strerror(errno));
277 int close_connection(int sock, CLOSE_TYPE type) {
278 struct nbd_request req;
282 case CONNECTION_CLOSE_PROPERLY:
283 req.magic=htonl(NBD_REQUEST_MAGIC);
284 req.type=htonl(NBD_CMD_DISC);
285 memcpy(&(req.handle), &(counter), sizeof(counter));
289 if(write(sock, &req, sizeof(req))<0) {
290 snprintf(errstr, errstr_len, "Could not write to socket: %s", strerror(errno));
293 case CONNECTION_CLOSE_FAST:
295 snprintf(errstr, errstr_len, "Could not close socket: %s", strerror(errno));
300 g_critical("Your compiler is on crack!"); /* or I am buggy */
306 int read_packet_check_header(int sock, size_t datasize, long long int curhandle) {
307 struct nbd_reply rep;
311 READ_ALL_ERR_RT(sock, &rep, sizeof(rep), end, -1, "Could not read reply header: %s", strerror(errno));
312 rep.magic=ntohl(rep.magic);
313 rep.error=ntohl(rep.error);
314 if(rep.magic!=NBD_REPLY_MAGIC) {
315 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);
320 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));
325 READ_ALL_ERR_RT(sock, &buf, datasize, end, -1, "Could not read data: %s", strerror(errno));
331 int oversize_test(gchar* hostname, int port, char* name, int sock,
332 char sock_is_open, char close_sock, int testflags) {
334 struct nbd_request req;
335 struct nbd_reply rep;
338 pid_t G_GNUC_UNUSED mypid = getpid();
339 char buf[((1024*1024)+sizeof(struct nbd_request)/2)<<1];
342 /* This should work */
344 if((sock=setup_connection(hostname, port, name, CONNECTION_TYPE_FULL, &serverflags))<0) {
345 g_warning("Could not open socket: %s", errstr);
350 req.magic=htonl(NBD_REQUEST_MAGIC);
351 req.type=htonl(NBD_CMD_READ);
352 req.len=htonl(1024*1024);
353 memcpy(&(req.handle),&i,sizeof(i));
355 WRITE_ALL_ERR_RT(sock, &req, sizeof(req), err, -1, "Could not write request: %s", strerror(errno));
356 printf("%d: testing oversized request: %d: ", getpid(), ntohl(req.len));
357 READ_ALL_ERR_RT(sock, &rep, sizeof(struct nbd_reply), err, -1, "Could not read reply header: %s", strerror(errno));
358 READ_ALL_ERR_RT(sock, &buf, ntohl(req.len), err, -1, "Could not read data: %s", strerror(errno));
360 snprintf(errstr, errstr_len, "Received unexpected error: %d", rep.error);
366 /* This probably should not work */
367 i++; req.from=htonll(i);
368 req.len = htonl(ntohl(req.len) + sizeof(struct nbd_request) / 2);
369 WRITE_ALL_ERR_RT(sock, &req, sizeof(req), err, -1, "Could not write request: %s", strerror(errno));
370 printf("%d: testing oversized request: %d: ", getpid(), ntohl(req.len));
371 READ_ALL_ERR_RT(sock, &rep, sizeof(struct nbd_reply), err, -1, "Could not read reply header: %s", strerror(errno));
372 READ_ALL_ERR_RT(sock, &buf, ntohl(req.len), err, -1, "Could not read data: %s", strerror(errno));
374 printf("Received expected error\n");
380 /* ... unless this works, too */
381 i++; req.from=htonll(i);
382 req.len = htonl(ntohl(req.len) << 1);
383 WRITE_ALL_ERR_RT(sock, &req, sizeof(req), err, -1, "Could not write request: %s", strerror(errno));
384 printf("%d: testing oversized request: %d: ", getpid(), ntohl(req.len));
385 READ_ALL_ERR_RT(sock, &rep, sizeof(struct nbd_reply), err, -1, "Could not read reply header: %s", strerror(errno));
386 READ_ALL_ERR_RT(sock, &buf, ntohl(req.len), err, -1, "Could not read data: %s", strerror(errno));
392 if((rep.error && !got_err) || (!rep.error && got_err)) {
393 printf("Received unexpected error\n");
400 int throughput_test(gchar* hostname, int port, char* name, int sock,
401 char sock_is_open, char close_sock, int testflags) {
404 struct nbd_request req;
408 struct timeval start;
412 char speedchar[2] = { '\0', '\0' };
415 signed int do_write=TRUE;
416 pid_t mypid = getpid();
419 if (!(testflags & TEST_WRITE))
420 testflags &= ~TEST_FLUSH;
422 memset (writebuf, 'X', 1024);
425 if((sock=setup_connection(hostname, port, name, CONNECTION_TYPE_FULL, &serverflags))<0) {
426 g_warning("Could not open socket: %s", errstr);
431 if ((testflags & TEST_FLUSH) && ((serverflags & (NBD_FLAG_SEND_FLUSH | NBD_FLAG_SEND_FUA))
432 != (NBD_FLAG_SEND_FLUSH | NBD_FLAG_SEND_FUA))) {
433 snprintf(errstr, errstr_len, "Server did not supply flush capability flags");
437 req.magic=htonl(NBD_REQUEST_MAGIC);
439 if(gettimeofday(&start, NULL)<0) {
441 snprintf(errstr, errstr_len, "Could not measure start time: %s", strerror(errno));
444 for(i=0;i+1024<=size;i+=1024) {
446 int sendfua = (testflags & TEST_FLUSH) && (((i>>10) & 15) == 3);
447 int sendflush = (testflags & TEST_FLUSH) && (((i>>10) & 15) == 11);
448 req.type=htonl((testflags & TEST_WRITE)?NBD_CMD_WRITE:NBD_CMD_READ);
450 req.type = htonl(NBD_CMD_WRITE | NBD_CMD_FLAG_FUA);
451 memcpy(&(req.handle),&i,sizeof(i));
453 if (write_all(sock, &req, sizeof(req)) <0) {
457 if (testflags & TEST_WRITE) {
458 if (write_all(sock, writebuf, 1024) <0) {
463 printf("%d: Requests(+): %d\n", (int)mypid, ++requests);
465 long long int j = i ^ (1LL<<63);
466 req.type = htonl(NBD_CMD_FLUSH);
467 memcpy(&(req.handle),&j,sizeof(j));
469 if (write_all(sock, &req, sizeof(req)) <0) {
473 printf("%d: Requests(+): %d\n", (int)mypid, ++requests);
481 select(sock+1, &set, NULL, NULL, &tv);
482 if(FD_ISSET(sock, &set)) {
483 /* Okay, there's something ready for
485 if(read_packet_check_header(sock, (testflags & TEST_WRITE)?0:1024, i)<0) {
489 printf("%d: Requests(-): %d\n", (int)mypid, --requests);
491 } while FD_ISSET(sock, &set);
492 /* Now wait until we can write again or until a second have
493 * passed, whichever comes first*/
498 do_write=select(sock+1,NULL,&set,NULL,&tv);
499 if(!do_write) printf("Select finished\n");
501 snprintf(errstr, errstr_len, "select: %s", strerror(errno));
506 /* Now empty the read buffer */
512 select(sock+1, &set, NULL, NULL, &tv);
513 if(FD_ISSET(sock, &set)) {
514 /* Okay, there's something ready for
516 read_packet_check_header(sock, (testflags & TEST_WRITE)?0:1024, i);
517 printf("%d: Requests(-): %d\n", (int)mypid, --requests);
520 if(gettimeofday(&stop, NULL)<0) {
522 snprintf(errstr, errstr_len, "Could not measure end time: %s", strerror(errno));
525 timespan=timeval_diff_to_double(&stop, &start);
539 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);
543 close_connection(sock, CONNECTION_CLOSE_PROPERLY);
550 * fill 512 byte buffer 'buf' with a hashed selection of interesting data based
551 * only on handle and blknum. The first word is blknum, and the second handle, for ease
552 * of understanding. Things with handle 0 are blank.
554 static inline void makebuf(char *buf, uint64_t seq, uint64_t blknum) {
555 uint64_t x = ((uint64_t)blknum) ^ (seq << 32) ^ (seq >> 32);
556 uint64_t* p = (uint64_t*)buf;
562 for (i = 0; i<512/sizeof(uint64_t); i++) {
565 x+=0xFEEDA1ECDEADBEEFULL+i+(((uint64_t)i)<<56);
567 x = x ^ (x<<s) ^ (x>>(64-s)) ^ 0xAA55AA55AA55AA55ULL ^ seq;
571 static inline int checkbuf(char *buf, uint64_t seq, uint64_t blknum) {
573 makebuf(cmp, seq, blknum);
574 return memcmp(cmp, buf, 512)?-1:0;
577 static inline void dumpcommand(char * text, uint32_t command)
579 #ifdef DEBUG_COMMANDS
580 command=ntohl(command);
582 switch (command & NBD_CMD_MASK_COMMAND) {
584 ctext="NBD_CMD_READ";
587 ctext="NBD_CMD_WRITE";
590 ctext="NBD_CMD_DISC";
593 ctext="NBD_CMD_FLUSH";
599 printf("%s: %s [%s] (0x%08x)\n",
602 (command & NBD_CMD_FLAG_FUA)?"FUA":"NONE",
607 int integrity_test(gchar* hostname, int port, char* name, int sock,
608 char sock_is_open, char close_sock, int testflags) {
609 struct nbd_reply rep;
613 struct timeval start;
617 char speedchar[2] = { '\0', '\0' };
620 pid_t G_GNUC_UNUSED mypid = getpid();
622 char *blkhashname=NULL;
623 uint32_t *blkhash = NULL;
626 uint64_t processed=0;
628 int readtransactionfile = 1;
629 struct rclist txqueue={NULL, NULL, 0};
630 struct rclist inflight={NULL, NULL, 0};
634 if((sock=setup_connection(hostname, port, name, CONNECTION_TYPE_FULL, &serverflags))<0) {
635 g_warning("Could not open socket: %s", errstr);
641 if ((serverflags & (NBD_FLAG_SEND_FLUSH | NBD_FLAG_SEND_FUA))
642 != (NBD_FLAG_SEND_FLUSH | NBD_FLAG_SEND_FUA))
643 g_warning("Server flags do not support FLUSH and FUA - these may error");
646 blkhashname=strdup("/tmp/blkarray-XXXXXX");
647 if (!blkhashname || (-1 == (blkhashfd = mkstemp(blkhashname)))) {
648 g_warning("Could not open temp file: %s", strerror(errno));
653 /* use tmpnam here to avoid further feature test nightmare */
654 if (-1 == (blkhashfd = open(blkhashname=strdup(tmpnam(NULL)),
656 S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH))) {
657 g_warning("Could not open temp file: %s", strerror(errno));
662 /* Ensure space freed if we die */
663 if (-1 == unlink(blkhashname)) {
664 g_warning("Could not unlink temp file: %s", strerror(errno));
669 if (-1 == lseek(blkhashfd, (off_t)((size>>9)<<2), SEEK_SET)) {
670 g_warning("Could not llseek temp file: %s", strerror(errno));
675 if (-1 == write(blkhashfd, "\0", 1)) {
676 g_warning("Could not write temp file: %s", strerror(errno));
681 if (NULL == (blkhash = mmap(NULL,
683 PROT_READ | PROT_WRITE,
687 g_warning("Could not mmap temp file: %s", strerror(errno));
692 if (-1 == (logfd = open(transactionlog, O_RDONLY)))
694 g_warning("Could open log file: %s", strerror(errno));
699 if(gettimeofday(&start, NULL)<0) {
701 snprintf(errstr, errstr_len, "Could not measure start time: %s", strerror(errno));
705 while (readtransactionfile || txqueue.numitems || inflight.numitems) {
712 struct reqcontext * prc;
718 if (readtransactionfile)
719 FD_SET(logfd, &rset);
720 if (txqueue.numitems)
722 if (inflight.numitems)
726 ret = select(1+((sock>logfd)?sock:logfd), &rset, &wset, NULL, &tv);
729 snprintf(errstr, errstr_len, "Timeout reading from socket");
732 g_warning("Could not mmap temp file: %s", errstr);
736 /* We know we've got at least one thing to do here then */
738 /* Get a command from the transaction log */
739 if (FD_ISSET(logfd, &rset)) {
741 /* Read a request or reply from the transaction file */
742 READ_ALL_ERRCHK(logfd,
746 "Could not read transaction log: %s",
748 magic = ntohl(magic);
750 case NBD_REQUEST_MAGIC:
751 if (NULL == (prc = calloc(1, sizeof(struct reqcontext)))) {
753 snprintf(errstr, errstr_len, "Could not allocate request");
756 READ_ALL_ERRCHK(logfd,
757 sizeof(magic)+(char *)&(prc->req),
758 sizeof(struct nbd_request)-sizeof(magic),
760 "Could not read transaction log: %s",
762 prc->req.magic = htonl(NBD_REQUEST_MAGIC);
764 if ((ntohl(prc->req.type) & NBD_CMD_MASK_COMMAND) == NBD_CMD_DISC) {
765 /* no more to read; don't enqueue as no reply
766 * we will disconnect manually at the end
768 readtransactionfile = 0;
771 dumpcommand("Enqueuing command", prc->req.type);
772 rclist_addtail(&txqueue, prc);
776 case NBD_REPLY_MAGIC:
777 READ_ALL_ERRCHK(logfd,
778 sizeof(magic)+(char *)(&rep),
779 sizeof(struct nbd_reply)-sizeof(magic),
781 "Could not read transaction log: %s",
786 snprintf(errstr, errstr_len, "Transaction log file contained errored transaction");
790 /* We do not need to consume data on a read reply as there is
795 snprintf(errstr, errstr_len, "Could not measure start time: %08x", magic);
800 /* See if we have a write we can do */
801 if (FD_ISSET(sock, &wset))
805 g_warning("Socket write FD set but we shouldn't have been interested");
809 rclist_unlink(&txqueue, prc);
810 rclist_addtail(&inflight, prc);
812 if (ntohl(prc->req.magic) != NBD_REQUEST_MAGIC) {
814 g_warning("Asked to write a reply without a magic number");
818 dumpcommand("Sending command", prc->req.type);
819 command = ntohl(prc->req.type);
820 from = ntohll(prc->req.from);
821 len = ntohl(prc->req.len);
822 /* we rewrite the handle as they otherwise may not be unique */
823 *((uint64_t*)(prc->req.handle))=htonll((uint64_t)prc);
824 WRITE_ALL_ERRCHK(sock,
826 sizeof(struct nbd_request),
828 "Could not write command: %s",
830 switch (command & NBD_CMD_MASK_COMMAND) {
833 uint64_t blknum = from>>9;
836 snprintf(errstr, errstr_len, "offset %llx beyond size %llx",
837 (long long int) from, (long long int)size);
840 /* work out what we should be writing */
841 makebuf(dbuf, prc->seq, blknum);
842 WRITE_ALL_ERRCHK(sock,
846 "Could not write data: %s",
858 snprintf(errstr, errstr_len, "Incomprehensible command: %08x", command);
868 /* See if there is a reply to be processed from the socket */
869 if(FD_ISSET(sock, &rset)) {
870 /* Okay, there's something ready for
873 READ_ALL_ERRCHK(sock,
875 sizeof(struct nbd_reply),
877 "Could not read from server socket: %s",
880 if (rep.magic != htonl(NBD_REPLY_MAGIC)) {
882 snprintf(errstr, errstr_len, "Bad magic from server");
888 snprintf(errstr, errstr_len, "Server errored a transaction");
892 prc=(struct reqcontext *)ntohll(*((uint64_t *)rep.handle));
893 if (prc->req.magic != htonl(NBD_REQUEST_MAGIC)) {
895 snprintf(errstr, errstr_len, "Bad magic in inflight data: %08x", prc->req.magic);
899 dumpcommand("Processing reply to command", prc->req.type);
900 command = ntohl(prc->req.type);
901 from = ntohll(prc->req.from);
902 len = ntohl(prc->req.len);
904 switch (command & NBD_CMD_MASK_COMMAND) {
907 uint64_t blknum = from>>9;
910 snprintf(errstr, errstr_len, "offset %llx beyond size %llx",
911 (long long int) from, (long long int)size);
914 READ_ALL_ERRCHK(sock,
918 "Could not read data: %s",
920 /* work out what we was written */
921 if (checkbuf(dbuf, blkhash[blknum], blknum))
924 snprintf(errstr, errstr_len, "Bad reply data: seq %08x", blkhash[blknum]);
933 /* subsequent reads should get data with this seq*/
935 uint64_t blknum = from>>9;
936 blkhash[blknum]=(uint32_t)(prc->seq);
946 rclist_unlink(&inflight, prc);
947 prc->req.magic=0; /* so a duplicate reply is detected */
951 if (!(printer++ % 10000) || !(readtransactionfile || txqueue.numitems || inflight.numitems) )
952 printf("%d: Seq %08lld Queued: %08d Inflight: %08d Done: %08lld\n",
957 (long long int) processed);
961 if (gettimeofday(&stop, NULL)<0) {
963 snprintf(errstr, errstr_len, "Could not measure end time: %s", strerror(errno));
966 timespan=timeval_diff_to_double(&stop, &start);
980 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);
984 close_connection(sock, CONNECTION_CLOSE_PROPERLY);
988 munmap(blkhash, (size>>9)<<2);
1000 g_warning("%s",errstr);
1005 typedef int (*testfunc)(gchar*, int, char*, int, char, char, int);
1007 int main(int argc, char**argv) {
1013 bool want_port = TRUE;
1016 testfunc test = throughput_test;
1019 g_message("%d: Not enough arguments", (int)getpid());
1020 g_message("%d: Usage: %s <hostname> <port>", (int)getpid(), argv[0]);
1021 g_message("%d: Or: %s <hostname> -N <exportname>", (int)getpid(), argv[0]);
1025 while((c=getopt(argc, argv, "-N:t:owfi"))>=0) {
1030 hostname=g_strdup(optarg);
1035 p=(strtol(argv[2], NULL, 0));
1036 if(p==LONG_MIN||p==LONG_MAX) {
1037 g_critical("Could not parse port number: %s", strerror(errno));
1044 name=g_strdup(optarg);
1049 transactionlog=g_strdup(optarg);
1055 testflags|=TEST_WRITE;
1058 testflags|=TEST_FLUSH;
1061 test=integrity_test;
1066 if(test(hostname, (int)p, name, sock, FALSE, TRUE, testflags)<0) {
1067 g_warning("Could not run test: %s", errstr);