[Ocfs2-tools-devel] [Ocfs2-test-devel] [PATCH 5/6] New set of inline-data testing tools:Add multiple-node MPI testing binary for regular file.

tristan.ye tristan.ye at oracle.com
Sat Aug 30 03:36:13 PDT 2008


It was created on the basis of existing inline-data.c by injecting the
MPI apis to make it runable among multiple nodes,it helps to perform a
concurrent rw operation among nodes upon one inlined file,also perform
multiple files operation separately.

Most of the testcases inside were similiar to original inline-data.c.


Signed-off-by: Tristan Ye <tristan.ye at oracle.com>
---


Index: ocfs2-test/programs/inline-data/multiple-inline-data.c
===================================================================
--- ocfs2-test/programs/inline-data/multiple-inline-data.c	(revision 0)
+++ ocfs2-test/programs/inline-data/multiple-inline-data.c	(revision 0)
@@ -0,0 +1,1363 @@
+/*
+ * XXX: A MPI compatible program to perform following test for
inline-data
+ * among multiple nodes concurrently,
+ *
+ * Verify I/O to/from files small enough to hold inline data. Includes
+ * some tests intended to force an inode out to an extent list,test
will be *
+ * [I] Tests of inline-data code. All tests read back the pattern
+ *     written to verify data integrity.
+ *    1) Write a pattern, read it back.
+ *    2) Shrink file by some bytes
+ *    3) Extend file again
+ *    4) Mmap file and read pattern
+ *    5) Reserve space inside of region
+ *    6) Punch hole in the middle
+ *
+ * [II] Tests intended to force data out of inode. Before each test,
+ *      we'll have to truncate to zero and re-write file.
+ *    1) Seek past EOF, write pattern.
+ *    2) Mmap and do a write inside of i_size
+ *    3) Extend file past min size
+ *    4) Resrve space past min size
+ *
+ * XXX: This could easily be turned into an mpi program, where a
+ * second node does the verification step.
+ */
+
+#define _XOPEN_SOURCE 600
+#define _GNU_SOURCE
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/vfs.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <limits.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <string.h>
+
+#include <ocfs2/ocfs2.h>
+
+#include <sys/ioctl.h>
+#include <inttypes.h>
+#include <linux/types.h>
+
+#include <mpi.h>
+
+#define PATTERN_SZ	8192
+#define HOSTNAME_MAX_SZ	255
+
+#define FILE_BUFFERED_RW_FLAGS  (O_CREAT|O_RDWR|O_TRUNC)
+#define FILE_MODE               (S_IRUSR|S_IWUSR|S_IXUSR|S_IROTH|\
+                                S_IWOTH|S_IXOTH|S_IRGRP|S_IWGRP|
S_IXGRP)
+
+#define WORK_PLACE	"multiple-inline-data-test"
+
+static char *prog;
+static char device[100];
+
+static ocfs2_filesys *fs = NULL;
+static struct ocfs2_super_block *ocfs2_sb = NULL;
+
+static char *pattern = NULL;
+static unsigned int max_inline_size;
+static char *read_buf = NULL;
+
+static unsigned long page_size;
+static unsigned int blocksize = 4096;
+static unsigned long clustersize;
+
+unsigned int id_count;
+unsigned long i_size;
+
+static char mount_point[255];
+static char work_place[255];
+static char dirent[255];
+static char file_name[255];
+
+static int iteration = 1;
+
+static int rank = -1, size;
+static char hostname[HOSTNAME_MAX_SZ];
+
+static unsigned long get_rand(unsigned long min, unsigned long max)
+{
+	if (min == 0 && max == 0)
+		return 0;
+
+	return min + (rand() % (max - min + 1));
+}
+
+static inline char rand_char(void)
+{
+	return 'A' + (char) get_rand(0, 25);
+}
+
+static void fill_pattern(int size)
+{
+	int i;
+
+	/*
+	 * Make sure that anything in the buffer past size is zero'd,
+	 * as a regular file should look.
+	 */
+	memset(pattern, 0, PATTERN_SZ);
+
+	for(i = 0; i < size; i++)
+		pattern[i] = rand_char();
+}
+
+static int truncate_pattern(int fd, unsigned int old_size,
+			    unsigned int new_size)
+{
+	int bytes = old_size - new_size;
+	int ret;
+
+	memset(pattern + new_size, 0, bytes);
+
+	ret = ftruncate(fd, new_size);
+	if (ret == -1) {
+		fprintf(stderr, "ftruncate error %d: \"%s\"\n",
+			ret, strerror(ret));
+		return -1;
+	}
+
+	return 0;
+}
+
+static int write_at(int fd, const void *buf, size_t count, off_t
offset);
+
+static int extend_pattern(int fd, unsigned int old_size,
+			  unsigned int new_size)
+{
+	int bytes = new_size - old_size;
+	int ret;
+	int i;
+
+	memset(pattern + old_size, 0, bytes);
+
+	ret = ftruncate(fd, new_size);
+	if (ret == -1) {
+		fprintf(stderr, "ftruncate error %d: \"%s\"\n",
+			ret, strerror(ret));
+		return -1;
+	}
+	
+	return 0;
+}
+
+static int try_ioctl(int which, int fd, unsigned int offset, unsigned
int count)
+{
+	struct ocfs2_space_resv sr;
+
+	memset(&sr, 0, sizeof(sr));
+	sr.l_whence = SEEK_SET;
+	sr.l_start = offset;
+	sr.l_len = count;
+
+	return ioctl(fd, which, &sr);
+}
+
+static int try_reserve(int fd, unsigned int offset, unsigned int count)
+{
+	int ret;
+
+	ret = try_ioctl(OCFS2_IOC_RESVSP, fd, offset, count);
+	if (ret == -1) {
+		ret = errno;
+		if (ret == ENOTTY)
+			return ret;
+		fprintf(stderr, "IOC_RESVSP error %d: \"%s\"\n",
+			ret, strerror(ret));
+		return -1;
+	}
+
+	return 0;
+}
+
+static int try_punch_hole(int fd, unsigned int offset, unsigned int
count)
+{
+	int ret;
+
+	memset(pattern + offset, 0, count);
+
+	ret = try_ioctl(OCFS2_IOC_UNRESVSP, fd, offset, count);
+	if (ret == -1) {
+		ret = errno;
+		if (ret == ENOTTY)
+			return ret;
+		fprintf(stderr, "IOC_UNRESVSP error %d: \"%s\"\n",
+			ret, strerror(ret));
+		return -1;
+	}
+
+	return 0;
+}
+
+static int mmap_write_at(int fd, const char *buf, size_t count, off_t
offset)
+{
+	unsigned int mmap_size = page_size;
+	unsigned int size = count + offset;
+	int i, j, ret;
+	char *region;
+
+	while (mmap_size < size)
+		mmap_size += page_size;
+
+	region = mmap(NULL, mmap_size, PROT_WRITE, MAP_SHARED, fd, 0);
+	if (region == MAP_FAILED) {
+		ret = errno;
+		fprintf(stderr, "mmap (write) error %d: \"%s\"\n", ret,
+			strerror(ret));
+		return -1;
+	}
+
+	j = 0;
+	for(i = offset; i < size; i++)
+		region[i] = buf[j++];
+
+	munmap(region, mmap_size);
+
+	return 0;
+}
+
+static int write_at(int fd, const void *buf, size_t count, off_t
offset)
+{
+	int ret;
+
+	ret = pwrite(fd, buf, count, offset);
+	if (ret < 0) {
+		ret = errno;
+		fprintf(stderr, "write error %d: \"%s\"\n", ret, strerror(ret));
+		return -1;
+	}
+	if (ret != count) {
+		fprintf(stderr, "Short write: wanted %d, got %d\n", count, ret);
+		return -1;
+	}
+
+	return 0;
+}
+
+static int prep_file_no_fill(unsigned int size, int open_direct)
+{
+	int fd, ret;
+	int flags = FILE_BUFFERED_RW_FLAGS;
+	size_t count = size;
+
+	if (open_direct) {
+		flags |= O_DIRECT;
+		count = blocksize;
+	}
+
+	fd = open(file_name, flags, FILE_MODE);
+	if (fd == -1) {
+		ret = errno;
+		fprintf(stderr, "open error %d: \"%s\"\n", ret, strerror(ret));
+		return -1;
+	}
+
+	ret = write_at(fd, pattern, count, 0);
+	if (ret)
+		return ret;
+
+	if (count > size) {
+		ret = ftruncate(fd, size);
+		if (ret) {
+			ret = errno;
+			fprintf(stderr, "truncate error %d: \"%s\"\n", ret,
+				strerror(ret));
+			return -1;
+		}
+	}
+
+	return fd;
+}
+
+static int prep_file(unsigned int size)
+{
+	fill_pattern(size);
+
+	return prep_file_no_fill(size, 0);
+}
+
+static int verify_pattern(int size, char *buf)
+{
+	int i;
+
+	for(i = 0; i < size; i++) {
+		if (buf[i] != pattern[i]) {
+			fprintf(stderr, "Verify failed at byte: %d\n", i);
+			return -1;
+		}
+	}
+	return 0;
+}
+
+static int __verify_pattern_fd(int fd, unsigned int size, int
direct_read)
+{
+	int ret;
+	unsigned int rd_size = size;
+
+	if (direct_read)
+		rd_size = blocksize;
+
+	ret = pread(fd, read_buf, rd_size, 0);
+	if (ret < 0) {
+		ret = errno;
+		fprintf(stderr, "read error %d: \"%s\"\n", ret, strerror(ret));
+		return -1;
+	}
+	if (ret != size) {
+		fprintf(stderr, "Short read: wanted %d, got %d\n", size, ret);
+		return -1;
+	}
+
+	return verify_pattern(size, read_buf);
+}
+
+static int verify_pattern_fd(int fd, unsigned int size)
+{
+	return __verify_pattern_fd(fd, size, 0);
+}
+
+static int verify_pattern_mmap(int fd, unsigned int size)
+{
+	int ret;
+	unsigned int mmap_size = page_size;
+	void *region;
+
+	while (mmap_size < size)
+		mmap_size += page_size;
+
+	region = mmap(NULL, mmap_size, PROT_READ, MAP_SHARED, fd, 0);
+	if (region == MAP_FAILED) {
+		ret = errno;
+		fprintf(stderr, "mmap (read) error %d: \"%s\"\n", ret,
+			strerror(ret));
+		return -1;
+	}
+
+	ret = verify_pattern(size, region);
+
+	munmap(region, mmap_size);
+
+	return 0;
+}
+
+static void usage(void)
+{
+	printf("Usage: inline-data [-i <iteration>] "
+	       "<-d <device>> <mount_point>\n"
+	       "Run a series of tests intended to verify I/O to and from\n"
+	       "files/dirs with inline data.\n\n"
+	       "iteration specify the running times.\n"
+	       "device and mount_point are mandatory.\n");
+
+	MPI_Finalize();
+
+	exit(1);
+}
+
+static void abort_printf(const char *fmt, ...)
+{
+	va_list ap;
+	
+	printf("%s (rank %d): ", hostname, rank);
+	va_start(ap, fmt);
+	vprintf(fmt, ap);
+
+	MPI_Abort(MPI_COMM_WORLD, 1);
+}
+
+static void root_printf(const char *fmt, ...)
+{
+	va_list ap;
+
+	if (rank == 0) {
+		va_start(ap, fmt);
+		vprintf(fmt, ap);
+	}
+}
+
+static int parse_opts(int argc, char **argv)
+{
+	int c;
+	while (1) {
+		c = getopt(argc, argv, "D:d:I:i:C:c:M:m:");
+		if (c == -1)
+			break;
+		switch (c) {
+		case 'i':
+		case 'I':
+			iteration = atol(optarg);
+			break;
+		case 'd':
+		case 'D':
+			strcpy(device, optarg);
+			break;
+		default:
+			break;
+		}
+	}
+	
+	if (strcmp(device, "") == 0)
+		return EINVAL;
+
+	if (argc - optind != 1)
+                return EINVAL;
+
+	strcpy(mount_point, argv[optind]);
+	if (mount_point[strlen(mount_point) - 1] == '/')
+		 mount_point[strlen(mount_point) - 1] = '\0';
+
+	return 0;
+
+}
+
+static int open_ocfs2_volume(char *device_name)
+{
+	int open_flags = OCFS2_FLAG_HEARTBEAT_DEV_OK | OCFS2_FLAG_RO;
+	int ret; 
+	ret = ocfs2_open(device_name, open_flags, 0, 0, &fs);
+	if (ret < 0) {
+		fprintf(stderr,"Not a ocfs2 volume!\n");
+		return ret;
+        }
+
+	ocfs2_sb = OCFS2_RAW_SB(fs->fs_super);
+	if (!(ocfs2_sb->s_feature_incompat &
OCFS2_FEATURE_INCOMPAT_INLINE_DATA)) {
+		fprintf(stderr,"Inline-data not supported"
+			" on this ocfs2 volume\n");
+		return -1;
+        }
+
+	blocksize = 1 << ocfs2_sb->s_blocksize_bits;
+	clustersize = 1 << ocfs2_sb->s_clustersize_bits;
+	max_inline_size = ocfs2_max_inline_data(blocksize);
+
+	return 0;
+}
+
+static int is_file_inlined(char *dirent_name, unsigned long *i_size,
+                           unsigned int *id_count)
+{
+        int ret;
+        uint64_t workplace_blk_no = 1;
+        uint64_t testfile_blk_no = 1;
+        char *buf = NULL;
+        struct ocfs2_dinode *di;
+        struct ocfs2_super_block *sb = OCFS2_RAW_SB(fs->fs_super);
+
+	sync();
+
+        ocfs2_malloc_block(fs->fs_io, &buf);
+
+        /*lookup worksplace inode*/
+        ret = ocfs2_lookup(fs, sb->s_root_blkno, WORK_PLACE,
+                           strlen(WORK_PLACE), NULL,
&workplace_blk_no);
+        if ( ret < 0 ) {
+                fprintf(stderr, "failed to lookup work_place(%s)'s"
+                        " inode blkno\n", work_place);
+                goto bail;
+        }
+
+        /*lookup file inode,then read*/
+        ret = ocfs2_lookup(fs, workplace_blk_no, dirent_name,
strlen(dirent_name),
+                           NULL, &testfile_blk_no);
+        if ( ret < 0 ) {
+
+                fprintf(stderr, "failed to lookup file(%s/%s)'s"
+                        " inode blkno\n", work_place, dirent_name);
+                goto bail;
+        }
+
+	ret = ocfs2_read_inode(fs, testfile_blk_no, buf);
+	if ( ret < 0 ) {
+		fprintf(stderr, "failed to read file(%s/%s/%s)'s"
+			" inode.\n", mount_point, WORK_PLACE, dirent_name);
+		goto bail;
+	}
+
+	di = (struct ocfs2_dinode *)buf;
+        *i_size = di->i_size;
+        *id_count = ((di->id2).i_data).id_count;
+
+        if (di->i_dyn_features & OCFS2_INLINE_DATA_FL) 
+		ret = 1;
+        else
+		ret = 0;
+bail:
+	if (buf)
+        	ocfs2_free(&buf);
+        return ret;
+}
+
+static int should_inlined_or_not(int is_inlined, int should_inlined,
int test_no)
+{
+	/* is_inlined represent if the ret is inlined or not
+	   while should_inlined represnt if we expect it inlined or not
+	*/
+	if (should_inlined) {
+		if (!is_inlined) {
+			fprintf(stderr, "After Test #%d, file %s should be "
+				"inlined here!\n", test_no, file_name);
+			fprintf(stderr, "File(%s): i_size = %d,id_count = %d\n",
+				file_name, i_size, id_count);
+			abort_printf("A extented file detected!\n");
+		}
+
+	} else {
+		if (is_inlined) {
+			fprintf(stderr, "After Test #%d, file %s should be "
+				"extented here!\n", test_no, file_name);
+			fprintf(stderr, "File(%s): i_size = %d,id_count = %d\n",
+				file_name, i_size, id_count);
+			abort_printf("A inlined file detected!\n");
+
+		}
+	}
+
+	return 0;
+}
+
+
+static int setup(int argc, char *argv[])
+{
+	int ret;
+
+	ret = MPI_Init(&argc, &argv);
+	if (ret != MPI_SUCCESS)
+		abort_printf("MPI_Init Failed!\n");
+
+	if (gethostname(hostname, HOSTNAME_MAX_SZ) < 0)
+		abort_printf("get hostname failed!\n");
+	
+	ret = MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+	if (ret != MPI_SUCCESS)
+		abort_printf("MPI_Comm_rank failed: %d\n", ret);
+
+	ret = MPI_Comm_size(MPI_COMM_WORLD,&size);
+	if (ret != MPI_SUCCESS)
+		abort_printf("MPI_Comm_size failed: %d\n", ret);
+
+	prog = strrchr(argv[0], '/');
+	if (prog == NULL)
+		prog = argv[0];
+	else
+		prog++;
+
+	if (parse_opts(argc, argv))
+		usage();
+
+	ret = open_ocfs2_volume(device);
+	if (ret < 0)
+		abort_printf("open ocfs2 volume failed!\n");
+
+	ret = posix_memalign((void *)&pattern, blocksize, PATTERN_SZ);
+	if (ret) {
+		fprintf(stderr, "posix_memalign error %d: \"%s\"\n",
+			ret, strerror(ret));
+		return 1;
+	}
+
+	ret = posix_memalign((void *)&read_buf, blocksize, PATTERN_SZ);
+	if (ret) {
+		fprintf(stderr, "posix_memalign error %d: \"%s\"\n",
+		ret, strerror(ret));
+		return 1;
+	}
+
+	srand(getpid());
+	page_size = sysconf(_SC_PAGESIZE);
+	snprintf(work_place, 255, "%s/%s",mount_point,WORK_PLACE);
+
+	if (rank == 0) { /*rank 0 setup the testing env*/
+		mkdir(work_place, FILE_MODE);
+	
+		root_printf("BlockSize:\t\t%d\nMax Inline Data Size:\t%d\n"
+	       	       "ClusterSize:\t\t%d\nPageSize:\t\t%d\nWorkingPlace:"
+		       "\t\t%s\n\n", blocksize, max_inline_size, clustersize,
+		       page_size, work_place);
+	}
+
+	return 0;
+}
+
+static int teardown(void)
+{
+	if (rank == 0)
+		rmdir(work_place);
+
+	MPI_Finalize();
+
+	return 0;
+}
+
+static void send_pattern_to_ranks(void)
+{
+	int i, ret;
+
+	MPI_Request request;
+	MPI_Status status;
+	
+	if (rank == 0) {
+		for (i = 1; i < size; i++) {
+			ret = MPI_Isend(pattern, PATTERN_SZ, MPI_BYTE, i, 1,
+					MPI_COMM_WORLD, &request);
+			if (ret != MPI_SUCCESS)
+				abort_printf("MPI_Isend failed!\n");
+			MPI_Wait(&request, &status);
+		}
+
+	} else {
+		ret = MPI_Isend(pattern, PATTERN_SZ, MPI_BYTE, 0, 1,
+				MPI_COMM_WORLD, &request);
+		if (ret != MPI_SUCCESS)
+			abort_printf("MPI_Isend failed!\n");
+		MPI_Wait(&request, &status);
+	}
+	
+}
+
+static void recv_pattern_from_ranks(void)
+{
+	int i, ret;
+
+	MPI_Request request;
+	MPI_Status status;
+
+	if (rank == 0) {
+		for (i = 1; i < size; i++) {
+			ret = MPI_Irecv(pattern, PATTERN_SZ, MPI_BYTE, i, 1,
+					MPI_COMM_WORLD, &request);
+			if (ret != MPI_SUCCESS)
+				abort_printf("MPI_Irecv failed!\n");
+			MPI_Wait(&request, &status);
+		}
+
+	} else {
+		ret = MPI_Irecv(pattern, PATTERN_SZ, MPI_BYTE, 0, 1,
+				MPI_COMM_WORLD, &request);
+		if (ret !=MPI_SUCCESS)
+			abort_printf("MPI_Irecv failed!\n");
+		MPI_Wait(&request, &status);
+	}
+	
+}
+
+
+static int test_regular_file(int test_no)
+{
+	int ret, fd, new_size, old_size, init_count, count, j, offset;
+	unsigned int test_num = 1;
+	int hole_gap = 2;
+
+	ret = MPI_Barrier(MPI_COMM_WORLD);
+	if (ret != MPI_SUCCESS)
+		abort_printf("MPI_Barrier failed: %d\n", ret);
+	
+	snprintf(dirent, 255, "multiple-inline-data-test-file");
+	snprintf(file_name, 255, "%s/%s", work_place, dirent);
+
+	root_printf("################Test Round %d :%s################\n",
+		    test_no, file_name);
+	
+	root_printf("Test  %d: Write basic pattern\n", test_num);
+
+	if (rank == 0) {
+		fd = prep_file(max_inline_size);
+		if (fd < 0)
+			abort_printf("prep_file failed!\n");
+		send_pattern_to_ranks();
+
+	} else {
+		recv_pattern_from_ranks();
+	}
+
+	/*wait completion of file creation by rank 0*/
+	ret = MPI_Barrier(MPI_COMM_WORLD);
+	if (ret != MPI_SUCCESS)
+		abort_printf("MPI_Barrier failed: %d\n", ret);
+	
+	if (rank != 0) {
+		fd = open(file_name, O_RDWR, FILE_MODE);
+		if (fd < 0)
+			abort_printf("open file failed!\n");
+	}
+	
+	ret = is_file_inlined(dirent, &i_size, &id_count);
+	should_inlined_or_not(ret, 1, test_num);
+	ret = verify_pattern_fd(fd, max_inline_size);
+	if (ret)
+		abort_printf("pattern verification failed!\n");
+	if (rank != 0)
+		close(fd);
+	test_num++;
+
+	ret = MPI_Barrier(MPI_COMM_WORLD);
+	if (ret != MPI_SUCCESS)
+		abort_printf("MPI_Barrier failed: %d\n", ret);
+	
+	root_printf("Test  %d: Rewrite portion of basic pattern\n", test_num);
+	offset = get_rand(0, max_inline_size - 1);
+	count = get_rand(1, max_inline_size - offset);
+	if (rank != 0) { /*none-root rank perfrom cocurrent write*/
+		fd = open(file_name, O_RDWR, FILE_MODE);
+		if (fd < 0)
+			abort_printf("open file failed!\n");
+		ret = write_at(fd, pattern + offset, count, offset);
+		if (ret)
+			abort_printf("write_at failed!\n");
+		send_pattern_to_ranks();
+
+	} else {
+		recv_pattern_from_ranks();
+	}
+
+	ret = MPI_Barrier(MPI_COMM_WORLD);
+	if (ret != MPI_SUCCESS)
+		abort_printf("MPI_Barrier failed: %d\n", ret);
+
+	ret = is_file_inlined(dirent, &i_size, &id_count);
+	should_inlined_or_not(ret, 1, test_num);
+
+	if (rank == 0) { /*rank 0 verify the pattern*/
+		ret = verify_pattern_fd(fd, max_inline_size);
+		if (ret)
+			abort_printf("pattern verification failed!\n");
+	}
+	if (rank != 0)
+		close(fd);
+	test_num++;
+
+	ret = MPI_Barrier(MPI_COMM_WORLD);
+        if (ret != MPI_SUCCESS)
+                abort_printf("MPI_Barrier failed: %d\n", ret);
+
+	root_printf("Test  %d: Reduce size with truncate\n", test_num);
+	old_size = max_inline_size;
+	new_size = max_inline_size / 2;
+	if (rank != 0) {
+		fd = open(file_name, O_RDWR, FILE_MODE);
+		if (fd < 0)
+			abort_printf("open file failed!\n");
+		ret = truncate_pattern(fd, old_size, new_size);
+		if (ret)
+			abort_printf("truncate pattern failed!\n");
+		send_pattern_to_ranks();
+
+	} else {
+		recv_pattern_from_ranks();
+
+	}
+
+	ret = MPI_Barrier(MPI_COMM_WORLD);
+	if (ret != MPI_SUCCESS)
+		abort_printf("MPI_Barrier failed: %d\n", ret);
+
+	ret = is_file_inlined(dirent, &i_size, &id_count);
+	should_inlined_or_not(ret, 1, test_num);
+	if (rank == 0) {
+		ret = verify_pattern_fd(fd, new_size);
+		if (ret)
+			abort_printf("pattern verification failed!\n");
+	}
+	if (rank != 0)
+		close(fd);
+	test_num++;
+
+	ret = MPI_Barrier(MPI_COMM_WORLD);
+	if (ret != MPI_SUCCESS)
+		abort_printf("MPI_Barrier failed: %d\n", ret);
+
+	root_printf("Test  %d: Extend file\n", test_num);
+	old_size = max_inline_size / 2;
+	new_size = max_inline_size;
+	if (rank != 0) {
+		fd = open(file_name, O_RDWR, FILE_MODE);
+		if (fd < 0)
+			abort_printf("open file failed!\n");
+		ret = extend_pattern(fd, old_size, new_size);
+		if (ret)
+			abort_printf("extend pattern failed!\n");
+		send_pattern_to_ranks();
+
+	} else {
+		recv_pattern_from_ranks();
+	}
+
+	ret = MPI_Barrier(MPI_COMM_WORLD);
+	if (ret != MPI_SUCCESS)
+		abort_printf("MPI_Barrier failed: %d\n", ret);
+
+	ret = is_file_inlined(dirent, &i_size, &id_count);
+	should_inlined_or_not(ret, 1, test_num);
+	if (rank == 0) {
+		ret = verify_pattern_fd(fd, new_size);
+		if (ret)
+			abort_printf("pattern verification failed!\n");
+	}
+	close(fd);
+	test_num++;
+
+	ret = MPI_Barrier(MPI_COMM_WORLD);
+	if (ret != MPI_SUCCESS)
+		abort_printf("MPI_Barrier failed: %d\n", ret);
+
+	root_printf("Test  %d: Double write, both extending\n", test_num);
+	count = max_inline_size / 2;
+	init_count = count / 2;
+	if (rank == 0) {
+		fill_pattern(count);
+		fd = prep_file_no_fill(init_count, 0);
+		if (fd < 0)
+			abort_printf("prep_file_no_fill failed!\n");
+		send_pattern_to_ranks();
+
+	} else {
+		recv_pattern_from_ranks();
+	}
+
+	ret = MPI_Barrier(MPI_COMM_WORLD);
+	if (ret != MPI_SUCCESS)
+		abort_printf("MPI_Barrier failed: %d\n", ret);
+
+	if (rank != 0) {
+		fd = open(file_name, O_RDWR, FILE_MODE);
+		if (fd < 0)
+			abort_printf("open file failed!\n");
+		offset = get_rand(1, init_count);
+		ret = write_at(fd, pattern + offset, count - offset, offset);
+		if (ret)
+			abort_printf("write_at failed!\n");
+		send_pattern_to_ranks();
+	} else {
+			
+		recv_pattern_from_ranks();
+	}
+
+	ret = MPI_Barrier(MPI_COMM_WORLD);
+	if (ret != MPI_SUCCESS)
+		abort_printf("MPI_Barrier failed: %d\n", ret);
+
+	ret = is_file_inlined(dirent, &i_size, &id_count);
+	should_inlined_or_not(ret, 1, test_num);
+	if (rank == 0) {
+		ret = verify_pattern_fd(fd, count);
+		if (ret)
+			abort_printf("verify pattern failed!\n");
+	}
+	close(fd);
+	test_num++;
+
+	ret = MPI_Barrier(MPI_COMM_WORLD);
+	if (ret != MPI_SUCCESS)
+		abort_printf("MPI_Barrier failed: %d\n", ret);
+	
+	root_printf("Test  %d: Fsync\n", test_num);
+	if (rank == 0) {
+		fd = prep_file(max_inline_size);
+		if (fd < 0)
+			abort_printf("prep file failed!\n");
+		send_pattern_to_ranks();
+	} else {
+
+		recv_pattern_from_ranks();
+	}
+	
+	ret = MPI_Barrier(MPI_COMM_WORLD);
+	if (ret != MPI_SUCCESS)
+		abort_printf("MPI_Barrier failed: %d\n", ret);
+	
+	if (rank != 0) {
+		fd = open(file_name ,O_RDWR, FILE_MODE);
+		if (fd < 0)
+			abort_printf("open file failed!\n");
+		ret = fsync(fd);
+		if (ret)
+			abort_printf("fsync failed!\n");
+		ret = verify_pattern_fd(fd, max_inline_size);
+		if (ret)
+			abort_printf("verify pattern failed!\n");
+		
+	}
+
+	ret = is_file_inlined(dirent, &i_size, &id_count);
+	should_inlined_or_not(ret, 1, test_num);
+	ret = verify_pattern_fd(fd, max_inline_size);
+	if (ret)
+		abort_printf("verify pattern failed!\n");
+	close(fd);
+	test_num++;
+
+	ret = MPI_Barrier(MPI_COMM_WORLD);
+	if (ret != MPI_SUCCESS)
+		abort_printf("MPI_Barrier failed: %d\n", ret);
+
+	root_printf("Test  %d: Fdatasync\n", test_num);
+	if (rank == 0) {
+		fd = prep_file(max_inline_size);
+		if (fd < 0)
+			abort_printf("prep file failed!\n");
+		send_pattern_to_ranks();
+	} else {
+		recv_pattern_from_ranks();
+	}
+
+	ret = MPI_Barrier(MPI_COMM_WORLD);
+	if (ret != MPI_SUCCESS)
+		abort_printf("MPI_Barrier failed: %d\n", ret);
+
+	if (rank != 0) {
+		fd = open(file_name, O_RDWR, FILE_MODE);
+		if (fd < 0)
+			abort_printf("open file failed!\n");
+		ret = fdatasync(fd);
+		if (ret)
+			abort_printf("fdataasync failed!\n");
+	}
+
+	ret = is_file_inlined(dirent, &i_size, &id_count);
+	should_inlined_or_not(ret, 1, test_num);
+	ret = verify_pattern_fd(fd, max_inline_size);
+	if (ret)
+		abort_printf("verify pattern failed!\n");
+	close(fd);
+	test_num++;
+
+	ret = MPI_Barrier(MPI_COMM_WORLD);
+	if (ret != MPI_SUCCESS)
+		abort_printf("MPI_Barrier failed: %d\n", ret);
+
+	root_printf("Test  %d: Mmap reads\n", test_num);
+	if (rank == 0) {
+        	fd = prep_file(max_inline_size);
+		if (fd < 0)
+			abort_printf("prep file failed!\n");
+		send_pattern_to_ranks();
+	} else {
+		recv_pattern_from_ranks();
+	}
+
+	ret = MPI_Barrier(MPI_COMM_WORLD);
+	if (ret != MPI_SUCCESS)
+		abort_printf("MPI_Barrier failed: %d\n", ret);
+
+	if (rank != 0) {
+		fd = open(file_name, O_RDWR, FILE_MODE);
+		if (fd < 0)
+			abort_printf("open file failed!\n");
+		for (j = 1; j <= max_inline_size; j++) {
+			ret = verify_pattern_mmap(fd, j);
+			if (ret)
+				abort_printf("verify mmap pattern failed!\n");
+		}
+	}
+
+	ret = is_file_inlined(dirent, &i_size, &id_count);
+	should_inlined_or_not(ret, 1, test_num);
+	if (rank != 0)
+		close(fd);
+	test_num++;
+
+	ret = MPI_Barrier(MPI_COMM_WORLD);
+	if (ret != MPI_SUCCESS)
+		abort_printf("MPI_Barrier failed: %d\n", ret);
+
+	root_printf("Test  %d: Reserve space\n", test_num);
+	if (rank !=0) {
+		fd = open(file_name, O_RDWR, FILE_MODE);
+		if (fd < 0)
+			abort_printf("open file failed!\n");
+		offset = get_rand(0, max_inline_size - 1);
+		count = get_rand(1, max_inline_size - offset);
+		ret = try_reserve(fd, offset, count);
+		if (ret != ENOTTY) {
+			if (ret)
+				abort_printf("try reserve failed!\n");
+
+			ret = verify_pattern_fd(fd, max_inline_size);
+			if (ret)
+				abort_printf("verify pattern failed!\n");
+			}
+	}
+
+	ret = is_file_inlined(dirent, &i_size, &id_count);
+	should_inlined_or_not(ret, 1, test_num);
+	close(fd);
+	test_num++;
+
+	ret = MPI_Barrier(MPI_COMM_WORLD);
+	if (ret != MPI_SUCCESS)
+		abort_printf("MPI_Barrier failed: %d\n", ret);
+	
+	
+	root_printf("Test  %d: Punch hole\n", test_num);
+	if (rank == 0) {
+		fd = prep_file(max_inline_size);
+		if (fd < 0)
+			abort_printf("prep file failed!\n");
+		send_pattern_to_ranks();
+	} else {
+		recv_pattern_from_ranks();
+	}
+	
+	ret = MPI_Barrier(MPI_COMM_WORLD);
+	if (ret != MPI_SUCCESS)
+		abort_printf("MPI_Barrier failed: %d\n", ret);
+
+	if (rank != 0) {
+		fd = open(file_name, O_RDWR, FILE_MODE);
+		if (fd < 0)
+			abort_printf("open file failed!\n");
+		offset = get_rand(0, max_inline_size - 1);
+		count = get_rand(1, max_inline_size - offset);
+		ret = try_punch_hole(fd, offset, count);
+		if (ret != ENOTTY) {
+			if (ret)
+				abort_printf("try punch hole failed!\n");	
+		}
+		send_pattern_to_ranks();
+	} else {
+		recv_pattern_from_ranks();
+	}
+
+	
+	ret = MPI_Barrier(MPI_COMM_WORLD);
+	if (ret != MPI_SUCCESS)
+		abort_printf("MPI_Barrier failed: %d\n", ret);
+	
+
+	ret = is_file_inlined(dirent ,&i_size, &id_count);
+	should_inlined_or_not(ret, 1, test_num);
+	close(fd);
+	test_num++;
+
+	ret = MPI_Barrier(MPI_COMM_WORLD);
+	if (ret != MPI_SUCCESS)
+		abort_printf("MPI_Barrier failed: %d\n", ret);
+	
+	
+	root_printf("Test  %d: Force expansion to extents via large write\n",
test_num);
+	if (rank == 0) {
+		fill_pattern(PATTERN_SZ);
+		fd = prep_file_no_fill(max_inline_size, 0);
+		if (fd < 0)
+			abort_printf("prep file no fill failed!\n");
+		send_pattern_to_ranks();
+
+	} else {
+		recv_pattern_from_ranks();
+	}
+
+	ret = MPI_Barrier(MPI_COMM_WORLD);
+        if (ret != MPI_SUCCESS)
+                abort_printf("MPI_Barrier failed: %d\n", ret);
+	
+	count = PATTERN_SZ - max_inline_size;
+	if (rank != 0) {
+		fd = open(file_name, O_RDWR, FILE_MODE);
+		if (fd < 0)
+			abort_printf("open file failed!\n");
+		ret = write_at(fd, &pattern[max_inline_size], count,
max_inline_size);
+		if (ret)
+			abort_printf("write at failed!\n");
+		send_pattern_to_ranks();
+	} else {
+		recv_pattern_from_ranks();
+	}
+	
+	ret = MPI_Barrier(MPI_COMM_WORLD);
+	if (ret != MPI_SUCCESS)
+		abort_printf("MPI_Barrier failed: %d\n", ret);
+
+	ret = is_file_inlined(dirent, &i_size, &id_count);
+	should_inlined_or_not(ret, 0, test_num);
+	if (rank == 0) {
+		ret = verify_pattern_fd(fd, PATTERN_SZ);
+		if (ret)
+			abort_printf("verfiy pattern failed!\n");
+	}
+	close(fd);
+	test_num++;
+
+	ret = MPI_Barrier(MPI_COMM_WORLD);
+	if (ret != MPI_SUCCESS)
+		abort_printf("MPI_Barrier failed: %d\n", ret);
+
+	
+	root_printf("Test  %d: Force expansion to extents via mmap write\n",
test_num);
+	if (rank == 0) {
+		fd = prep_file(max_inline_size);
+		if (fd < 0)
+			abort_printf("prep file failed!\n");
+		fill_pattern(max_inline_size);
+		ret = mmap_write_at(fd, pattern, max_inline_size, 0);
+		if (ret)
+			abort_printf("mmap write failed!\n");
+		send_pattern_to_ranks();
+	} else {
+		recv_pattern_from_ranks();
+	}
+	
+	ret = MPI_Barrier(MPI_COMM_WORLD);
+	if (ret != MPI_SUCCESS)
+		abort_printf("MPI_Barrier failed: %d\n", ret);
+	
+	if (rank != 0) {
+		fd = open(file_name, O_RDWR, FILE_MODE);
+		if (fd < 0)
+			abort_printf("open file failed!\n");
+		ret = verify_pattern_fd(fd, max_inline_size);
+		if (ret)
+			abort_printf("verify pattern failed!\n");
+	}
+	
+	ret = is_file_inlined(dirent, &i_size, &id_count);
+	should_inlined_or_not(ret, 0, test_num);
+	close(fd);
+	test_num++;
+
+	ret = MPI_Barrier(MPI_COMM_WORLD);
+	if (ret != MPI_SUCCESS)
+		abort_printf("MPI_Barrier failed: %d\n", ret);
+
+	root_printf("Test  %d: Force expansion to extents via large extend\n",
test_num);
+	if (rank == 0) {
+		fd = prep_file(max_inline_size);
+		if (fd < 0)
+			abort_printf("prep file failed!\n");
+		send_pattern_to_ranks();
+	} else {
+		recv_pattern_from_ranks();
+	}
+
+	ret = MPI_Barrier(MPI_COMM_WORLD);
+	if (ret != MPI_SUCCESS)
+		abort_printf("MPI_Barrier failed: %d\n", ret);
+
+	old_size = max_inline_size;
+	new_size = 2 * max_inline_size;
+
+	if (rank != 0) {
+		fd = open(file_name, O_RDWR, FILE_MODE);
+		if (fd < 0)
+			abort_printf("open file failed!\n");
+		ret = extend_pattern(fd, old_size, new_size);
+		if (ret)
+			abort_printf("extend pattern failed!\n");
+		send_pattern_to_ranks();
+	} else {
+		recv_pattern_from_ranks();
+	}
+
+	ret = MPI_Barrier(MPI_COMM_WORLD);
+	if (ret != MPI_SUCCESS)
+		abort_printf("MPI_Barrier failed: %d\n", ret);
+
+	ret = is_file_inlined(dirent, &i_size, &id_count);
+	should_inlined_or_not(ret, 0, test_num);
+	if (rank == 0) {
+		ret = verify_pattern_fd(fd, new_size);
+		if (ret)
+			abort_printf("verify pattern failed!\n");
+	}
+	close(fd);
+	test_num++;
+
+	ret = MPI_Barrier(MPI_COMM_WORLD);
+	if (ret != MPI_SUCCESS)
+		abort_printf("MPI_Barrier failed: %d\n", ret);
+
+	root_printf("Test  %d: Force expansion to extents via large
reservation\n", test_num);
+	if (rank == 0) {
+		fd = prep_file(max_inline_size);
+		if (fd < 0)
+			abort_printf("prep file failed!\n");
+		send_pattern_to_ranks();
+	} else {
+		recv_pattern_from_ranks();
+	}
+
+	ret = MPI_Barrier(MPI_COMM_WORLD);
+	if (ret != MPI_SUCCESS)
+		abort_printf("MPI_Barrier failed: %d\n", ret);
+
+	new_size = PATTERN_SZ;
+	if (rank != 0) {
+		fd = open(file_name, O_RDWR, FILE_MODE);
+		if (fd < 0)
+			abort_printf("open file failed!\n");
+		ret = try_reserve(fd, 0, new_size);
+		if (ret != ENOTTY) {
+			if (ret)
+				abort_printf("try reserve failed!\n");
+			ret = extend_pattern(fd, max_inline_size, new_size);
+			if (ret)
+				abort_printf("extend pattern failed!\n");
+			send_pattern_to_ranks();
+		}
+	} else {
+		recv_pattern_from_ranks();
+	}
+
+	ret = MPI_Barrier(MPI_COMM_WORLD);
+	if (ret != MPI_SUCCESS)
+		abort_printf("MPI_Barrier failed: %d\n", ret);
+
+	ret = is_file_inlined(dirent, &i_size, &id_count);
+	should_inlined_or_not(ret, 0, test_num);
+	if (rank == 0) {
+		ret = verify_pattern_fd(fd, new_size);
+		if (ret)
+			abort_printf("verify pattern failed!\n");
+	}
+	close(fd);
+	test_num++;
+	
+	ret = MPI_Barrier(MPI_COMM_WORLD);
+	if (ret != MPI_SUCCESS)
+		abort_printf("MPI_Barrier failed: %d\n", ret);
+
+	root_printf("Test  %d: O_DIRECT read\n", test_num);
+	if (rank == 0) {
+		fd = prep_file(max_inline_size);
+		if (fd < 0)
+			abort_printf("prep file failed!\n");
+		close(fd);
+		send_pattern_to_ranks();
+	} else {
+		recv_pattern_from_ranks();
+	}
+	
+	ret = MPI_Barrier(MPI_COMM_WORLD);
+	if (ret != MPI_SUCCESS)
+		abort_printf("MPI_Barrier failed: %d\n", ret);
+
+	if (rank != 0) {
+		fd = open(file_name, O_RDWR|O_DIRECT);
+		if (fd < 0)
+			abort_printf("open file failed with direct mode!\n");
+		ret = __verify_pattern_fd(fd, max_inline_size, 1);
+		if (ret)
+			abort_printf("_verify pattern failed!\n");
+	}
+
+	ret = is_file_inlined(dirent, &i_size, &id_count);
+	should_inlined_or_not(ret, 1, test_num);
+	close(fd);
+	test_num++;
+
+	ret = MPI_Barrier(MPI_COMM_WORLD);
+	if (ret != MPI_SUCCESS)
+		abort_printf("MPI_Barrier failed: %d\n", ret);
+	
+	root_printf("Test  %d: O_DIRECT write\n", test_num);
+	if (rank == 0) {
+		fill_pattern(max_inline_size);
+		fd = prep_file_no_fill(max_inline_size, 1);
+		if (fd < 0)
+			abort_printf("prep file no fill failed!\n");
+		send_pattern_to_ranks();
+	} else {
+		recv_pattern_from_ranks();
+	}
+
+	ret = MPI_Barrier(MPI_COMM_WORLD);
+	if (ret != MPI_SUCCESS)
+		abort_printf("MPI_Barrier failed: %d\n", ret);
+	
+	if (rank != 0) {
+		fd = open(file_name, O_RDWR, FILE_MODE);
+		if (fd < 0)
+			abort_printf("open file failed!\n");
+		ret = __verify_pattern_fd(fd, max_inline_size, 1);
+		if (ret)
+			abort_printf("__verify pattern failed!\n");
+		close(fd);
+	}
+	/*
+	ret = is_file_inlined(dirent, &i_size, &id_count);
+	should_inlined_or_not(ret, 0, test_num);
+	*/
+	test_num++;
+	close(fd);
+
+	ret = MPI_Barrier(MPI_COMM_WORLD);
+	if (ret != MPI_SUCCESS)
+		abort_printf("MPI_Barrier failed: %d\n", ret);
+
+	if (rank == 0)
+		unlink(file_name);
+
+	ret = MPI_Barrier(MPI_COMM_WORLD);
+	if (ret != MPI_SUCCESS)
+		abort_printf("MPI_Barrier failed: %d\n", ret);
+
+	root_printf("Test  %d: Multiple files\n", test_num);
+	snprintf(dirent, 255, "multiple-inline-data-test-file-%d", rank);
+	snprintf(file_name, 255, "%s/%s", work_place, dirent);
+	fd = prep_file(max_inline_size);
+
+	ret = MPI_Barrier(MPI_COMM_WORLD);
+	if (ret != MPI_SUCCESS)
+		abort_printf("MPI_Barrier failed: %d\n", ret);
+
+	offset = get_rand(0, max_inline_size - 1);
+	count = get_rand(1, max_inline_size - offset);
+	ret = write_at(fd, pattern + offset, count, offset);
+
+	ret = MPI_Barrier(MPI_COMM_WORLD);
+	if (ret != MPI_SUCCESS)
+		abort_printf("MPI_Barrier failed: %d\n", ret);
+	
+	ret = verify_pattern_fd(fd, max_inline_size);
+
+	ret = is_file_inlined(dirent, &i_size, &id_count);
+        should_inlined_or_not(ret, 1, test_num);
+		
+	close(fd);
+
+	ret = MPI_Barrier(MPI_COMM_WORLD);
+        if (ret != MPI_SUCCESS)
+                abort_printf("MPI_Barrier failed: %d\n", ret);
+	
+	unlink(file_name);
+
+	ret = MPI_Barrier(MPI_COMM_WORLD);
+	if (ret != MPI_SUCCESS)
+		abort_printf("MPI_Barrier failed: %d\n", ret);
+
+
+bail:
+	root_printf("All File I/O Tests Passed\n");
+
+	ret = MPI_Barrier(MPI_COMM_WORLD);
+	if (ret != MPI_SUCCESS)
+		abort_printf("MPI_Barrier failed: %d\n", ret);
+
+	return ret;
+}
+int main(int argc, char **argv)
+{
+	int ret;
+	int i;
+
+	ret = setup(argc,argv);
+	if (ret)
+		abort_printf("setup error!\n");
+
+	for (i = 0; i < iteration; i++) {
+		ret = test_regular_file(i);
+		if (ret)
+			abort_printf("test_regular_file error!\n");
+	}
+	
+	teardown();
+
+	return 0;
+}

Property changes on:
ocfs2-test/programs/inline-data/multiple-inline-data.c
___________________________________________________________________
Name: svn:executable
   + *





More information about the Ocfs2-tools-devel mailing list