[Ocfs2-test-devel] [PATCH 4/4] Ocfs2-test: Enhance reflink_test with aio testing.

Tristan Ye tristan.ye at oracle.com
Wed Jun 23 04:06:49 PDT 2010


Idea here is to make generic write_at(recognized as an atomic write in reflink test,
which is widely used almost in all of the testcases) become aio-aware, that way, the
existing testing semantics and scenarios for basic or odirect tests still are available
for us when we enable aio testing flag, besides, we also do a verfication after each
aio_write by issuing a pread() immediatly to validate the asynchronous writing.

Signed-off-by: Tristan Ye <tristan.ye at oracle.com>
---
 programs/reflink_tests/Makefile             |   10 ++++-
 programs/reflink_tests/multi_reflink_test.c |    8 +++-
 programs/reflink_tests/reflink_test.c       |    8 +++-
 programs/reflink_tests/reflink_test.h       |    3 +
 programs/reflink_tests/reflink_test_utils.c |   58 +++++++++++++++++++++++++--
 5 files changed, 77 insertions(+), 10 deletions(-)

diff --git a/programs/reflink_tests/Makefile b/programs/reflink_tests/Makefile
index d2f2110..1133504 100755
--- a/programs/reflink_tests/Makefile
+++ b/programs/reflink_tests/Makefile
@@ -8,6 +8,12 @@ CFLAGS = -O2 -Wall -g $(OCFS2_CFLAGS)
 
 CFLAGS += $(EXTRA_CFLAGS)
 
+INCLUDES = -I$(TOPDIR)/programs/libocfs2test
+
+CFLAGS += $(INCLUDES)
+
+LIBO2TEST = $(TOPDIR)/programs/libocfs2test/libocfs2test.a
+
 ifdef NO_REFLINK
 CFLAGS += -DNO_REFLINK
 endif
@@ -49,10 +55,10 @@ BIN_EXTRA = reflink_test_run.sh multi_reflink_test_run.sh reflink_files.sh
 BIN_PROGRAMS = reflink_test multi_reflink_test
 
 reflink_test: $(SINGLE_SOURCES)
-	$(LINK) $(OCFS2_LIBS)
+	$(LINK) $(OCFS2_LIBS) $(LIBO2TEST) -laio
 
 multi_reflink_test: $(MULTI_SOURCES)
-	$(MPI_LINK) $(OCFS2_LIBS)
+	$(MPI_LINK) $(OCFS2_LIBS) $(LIBO2TEST) -laio
 
 include $(TOPDIR)/Postamble.make
 
diff --git a/programs/reflink_tests/multi_reflink_test.c b/programs/reflink_tests/multi_reflink_test.c
index 6c951af..494279d 100755
--- a/programs/reflink_tests/multi_reflink_test.c
+++ b/programs/reflink_tests/multi_reflink_test.c
@@ -117,7 +117,7 @@ static void usage(void)
 {
        root_printf("Usage: multi_reflink_test [-i iteration] [-l file_size] "
 	       "[-p refcount_tree_pairs] [-n reflink_nums] <-w work_place> "
-	       "[-f] [-x] [-r] [-m] [-y] [-s] [-c] [-O]\n"
+	       "[-f] [-x] [-r] [-m] [-y] [-s] [-c] [-O] [-A]\n"
 	       "iteration specify the running times.\n"
 	       "file_size specify the size of original file.\n"
 	       "reflink_nums specify the number of reflinks.\n"
@@ -130,6 +130,7 @@ static void usage(void)
 	       "-s specify the stress test.\n"
 	       "-c specify the comprehensive test.here need 6 ranks at least.\n"
 	       "-O specify O_DIRECT test.\n"
+	       "-A specify asynchronous io test.\n"
 	       "-m specify the mmap test.\n");
 
 	MPI_Finalize();
@@ -142,7 +143,7 @@ int parse_opts(int argc, char **argv)
 	int c;
 
 	while (1) {
-		c = getopt(argc, argv, "I:i:w:OfFrRmMyYcCsSW:n:N:l:L:p:P:x:X:");
+		c = getopt(argc, argv, "I:i:w:OAfFrRmMyYcCsSW:n:N:l:L:p:P:x:X:");
 		if (c == -1)
 			break;
 
@@ -179,6 +180,9 @@ int parse_opts(int argc, char **argv)
 		case 'O':
 			test_flags |= ODCT_TEST;
 			break;
+		case 'A':
+			test_flags |= ASIO_TEST;
+			break;
 		case 'r':
 		case 'R':
 			test_flags |= RAND_TEST;
diff --git a/programs/reflink_tests/reflink_test.c b/programs/reflink_tests/reflink_test.c
index c0221ec..121f768 100755
--- a/programs/reflink_tests/reflink_test.c
+++ b/programs/reflink_tests/reflink_test.c
@@ -108,7 +108,7 @@ static void usage(void)
 	printf("Usage: reflink_tests [-i iteration] <-n ref_counts> "
 	       "<-p refcount_tree_pairs> <-l file_size> <-d disk> "
 	       "<-w workplace> -f -b [-c conc_procs] -m -s -r [-x xattr_nums]"
-	       " [-h holes_num] [-o holes_filling_log] -O -D <child_nums> -I -H -T\n\n"
+	       " [-h holes_num] [-o holes_filling_log] -O -A -D <child_nums> -I -H -T\n\n"
 	       "-f enable basic feature test.\n"
 	       "-b enable boundary test.\n"
 	       "-c enable concurrent tests with conc_procs processes.\n"
@@ -116,6 +116,7 @@ static void usage(void)
 	       "-r enable random test.\n"
 	       "-s enable stress test.\n"
 	       "-O enable O_DIRECT test.\n"
+	       "-A enable asynchronous io test.\n"
 	       "-D enable destructive test.\n"
 	       "-v enable verification for destructive test.\n"
 	       "-H enable CoW verification test for punching holes.\n"
@@ -143,7 +144,7 @@ static int parse_opts(int argc, char **argv)
 
 	while (1) {
 		c = getopt(argc, argv,
-			   "i:d:w:IOfFbBsSrRHTmMW:n:N:"
+			   "i:d:w:IOAfFbBsSrRHTmMW:n:N:"
 			   "l:L:c:C:p:x:X:h:o:v:a:P:D:");
 		if (c == -1)
 			break;
@@ -169,6 +170,9 @@ static int parse_opts(int argc, char **argv)
 		case 'O':
 			test_flags |= ODCT_TEST;
 			break;
+		case 'A':
+			test_flags |= ASIO_TEST;
+			break;
 		case 'D':
 			test_flags |= DSCV_TEST;
 			child_nums = atol(optarg);
diff --git a/programs/reflink_tests/reflink_test.h b/programs/reflink_tests/reflink_test.h
index 5f864f2..10006d0 100755
--- a/programs/reflink_tests/reflink_test.h
+++ b/programs/reflink_tests/reflink_test.h
@@ -51,6 +51,8 @@
 #include <ocfs2/byteorder.h>
 #include "crc32table.h"
 
+#include "aio.h"
+
 #define OCFS2_MAX_FILENAME_LEN	255
 #define FILE_RW_FLAGS		(O_CREAT|O_RDWR)
 #define FILE_RO_FLAGS		(O_RDONLY)
@@ -79,6 +81,7 @@
 #define VERI_TEST		0x00002000
 #define PUNH_TEST		0x00004000
 #define TRUC_TEST		0x00008000
+#define ASIO_TEST		0x00010000
 
 #define MPI_RET_SUCCESS		0
 #define MPI_RET_FAILED		1
diff --git a/programs/reflink_tests/reflink_test_utils.c b/programs/reflink_tests/reflink_test_utils.c
index a55d6da..9286229 100755
--- a/programs/reflink_tests/reflink_test_utils.c
+++ b/programs/reflink_tests/reflink_test_utils.c
@@ -21,6 +21,7 @@
  */
 
 #include "reflink_test.h"
+//#include "/tmp/ocfs2-test/programs/libocfs2test/aio.h"
 
 extern char *orig_pattern;
 extern int test_flags;
@@ -205,15 +206,58 @@ int mmap_read_at_file(char *pathname, void *buf, size_t count,
 
 int write_at(int fd, const void *buf, size_t count, off_t offset)
 {
-	int ret;
+	int ret, i;
 	size_t bytes_write;
+	struct o2test_aio o2a;
+	char *buf_cmp = NULL;
+	unsigned long long *ubuf = (unsigned long long *)buf;
+        unsigned long long *ubuf_cmp = NULL;
+
+	if (test_flags & ASIO_TEST) {
+
+		buf_cmp = (char *)malloc(count);
+
+		ret = o2test_aio_setup(&o2a, 1);
+		if (ret < 0)
+			goto bail;
+
+		ret = o2test_aio_pwrite(&o2a, fd, (void *)buf, count, offset);
+		if (ret < 0)
+			goto bail;
+
+		ret = o2test_aio_query(&o2a, 1, 1);
+		if(ret < 0)
+			goto bail;
+
+		ret = pread(fd, buf_cmp, count, offset);
+		if (ret < 0) {
+			ret = errno;
+			fprintf(stderr, "pread error %d: \"%s\"\n", ret,
+				strerror(ret));
+			ret = -1;
+			goto bail;
+		}
+
+		if (memcmp(buf, buf_cmp, count)) {
+
+			ubuf_cmp = (unsigned long long *)buf_cmp;
+			for (i = 0; i < count / sizeof(unsigned long long); i++)
+				printf("%d: 0x%llx[aio_write]  0x%llx[pread]\n",
+				       i, ubuf[i], ubuf_cmp[i]);
+		}
+
+		ret = o2test_aio_destroy(&o2a);
+
+		goto bail;
+	}
 
 	ret = pwrite(fd, buf, count, offset);
 
 	if (ret < 0) {
 		ret = errno;
 		fprintf(stderr, "write error %d: \"%s\"\n", ret, strerror(ret));
-		return -1;
+		ret = -1;
+		goto bail;
 	}
 
 	bytes_write = ret;
@@ -226,13 +270,19 @@ int write_at(int fd, const void *buf, size_t count, off_t offset)
 			ret = errno;
 			fprintf(stderr, "write error %d: \"%s\"\n", ret,
 				strerror(ret));
-			return -1;
+			ret = -1;
+			goto bail;
 		}
 
 		bytes_write += ret;
 	}
 
-	return 0;
+	ret = 0;
+bail:
+	if (buf_cmp)
+		free(buf_cmp);
+
+	return ret;
 }
 
 int write_at_file(char *pathname, const void *buf, size_t count,
-- 
1.5.5




More information about the Ocfs2-test-devel mailing list