[Nbd] [PATCH 3/5] Add flush test
- To: nbd-general@lists.sourceforge.net
- Subject: [Nbd] [PATCH 3/5] Add flush test
- From: Alex Bligh <alex@...872...>
- Date: Tue, 17 May 2011 13:34:53 +0100
- Message-id: <1305635695-24058-3-git-send-email-alex@...872...>
- In-reply-to: <1305635695-24058-1-git-send-email-alex@...872...>
- References: <1305635695-24058-1-git-send-email-alex@...872...>
Signed-off-by: Alex Bligh <alex@...872...>
---
Makefile.am | 3 ++-
nbd-tester-client.c | 37 +++++++++++++++++++++++++++++++++----
simple_test | 13 +++++++++++++
3 files changed, 48 insertions(+), 5 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index f2da3e6..a99eb37 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -3,7 +3,7 @@ bin_PROGRAMS = nbd-server
sbin_PROGRAMS = @NBD_CLIENT_NAME@
EXTRA_PROGRAMS = nbd-client knbd-client
TESTS_ENVIRONMENT=$(srcdir)/simple_test
-TESTS = cmd cfg1 cfgmulti cfgnew cfgsize write
+TESTS = cmd cfg1 cfgmulti cfgnew cfgsize write flush
check_PROGRAMS = nbd-tester-client
knbd_client_SOURCES = nbd-client.c cliserv.h
nbd_client_SOURCES = nbd-client.c cliserv.h
@@ -22,3 +22,4 @@ cfgmulti:
cfgnew:
cfgsize:
write:
+flush:
diff --git a/nbd-tester-client.c b/nbd-tester-client.c
index 218b0bd..9f7714e 100644
--- a/nbd-tester-client.c
+++ b/nbd-tester-client.c
@@ -123,7 +123,7 @@ 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(gchar *hostname, int port, gchar* name, CONNECTION_TYPE ctype) {
+int setup_connection(gchar *hostname, int port, gchar* name, CONNECTION_TYPE ctype, int* serverflags) {
int sock;
struct hostent *host;
struct sockaddr_in addr;
@@ -196,6 +196,8 @@ int setup_connection(gchar *hostname, int port, gchar* name, CONNECTION_TYPE cty
uint16_t flags;
READ_ALL_ERRCHK(sock, buf, sizeof(uint16_t), err_open, "Could not read flags: %s", strerror(errno));
flags = ntohs(flags);
+ *serverflags = flags;
+ g_warning("Server flags are: %08x", flags);
READ_ALL_ERRCHK(sock, buf, 124, err_open, "Could not read reserved zeroes: %s", strerror(errno));
goto end;
err_open:
@@ -267,13 +269,14 @@ int oversize_test(gchar* hostname, int port, char* name, int sock,
struct nbd_reply rep;
int request=0;
int i=0;
+ int serverflags = 0;
pid_t mypid = getpid();
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, port, name, CONNECTION_TYPE_FULL))<0) {
+ if((sock=setup_connection(hostname, port, name, CONNECTION_TYPE_FULL, &serverflags))<0) {
g_warning("Could not open socket: %s", errstr);
retval=-1;
goto err;
@@ -344,21 +347,31 @@ int throughput_test(gchar* hostname, int port, char* name, int sock,
double speed;
char speedchar[2] = { '\0', '\0' };
int retval=0;
+ int serverflags = 0;
size_t tmp;
signed int do_write=TRUE;
pid_t mypid = getpid();
+
+ if (!(testflags & TEST_WRITE))
+ testflags &= ~TEST_FLUSH;
+
memset (writebuf, 'X', sizeof(1024));
size=0;
if(!sock_is_open) {
- if((sock=setup_connection(hostname, port, name, CONNECTION_TYPE_FULL))<0) {
+ if((sock=setup_connection(hostname, port, name, CONNECTION_TYPE_FULL, &serverflags))<0) {
g_warning("Could not open socket: %s", errstr);
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");
+ retval = -1;
+ goto err_open;
+ }
req.magic=htonl(NBD_REQUEST_MAGIC);
- req.type=htonl((testflags & TEST_WRITE)?NBD_CMD_WRITE:NBD_CMD_READ);
req.len=htonl(1024);
if(gettimeofday(&start, NULL)<0) {
retval=-1;
@@ -367,6 +380,11 @@ int throughput_test(gchar* hostname, int port, char* name, int sock,
}
for(i=0;i+1024<=size;i+=1024) {
if(do_write) {
+ int sendfua = (testflags & TEST_FLUSH) && ((i & 15) == 3);
+ int sendflush = (testflags & TEST_FLUSH) && ((i & 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) {
@@ -380,6 +398,17 @@ int throughput_test(gchar* hostname, int port, char* name, int sock,
}
}
printf("%d: Requests(+): %d\n", (int)mypid, ++requests);
+ if (sendflush) {
+ 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;
+ goto err_open;
+ }
+ printf("%d: Requests(+): %d\n", (int)mypid, ++requests);
+ }
}
do {
FD_ZERO(&set);
diff --git a/simple_test b/simple_test
index 53efb07..a01d3dc 100755
--- a/simple_test
+++ b/simple_test
@@ -112,6 +112,19 @@ EOF
./nbd-tester-client localhost -N export1 -w
retval=$?
;;
+ */flush)
+ # Test new-style exports
+ cat >nbd-server.conf <<EOF
+[generic]
+[export1]
+ exportname = $tmpnam
+EOF
+ ./nbd-server -C nbd-server.conf -p `pwd`/nbd-server.pid &
+ PID=$!
+ sleep 1
+ ./nbd-tester-client localhost -N export1 -w -f
+ retval=$?
+ ;;
*)
echo "E: unknown test $1"
exit 1
--
1.7.1
Reply to: