[Ocfs2-test-devel] [PATCH 1/4] Ocfs2-test: Why not providing an option to reserve unwritten region before hole punching.

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


Current punch-holes test will only be performed against a sparse file
with written_pattern pieces, how about provide an option to make it
possible against a unwritten region?

Signed-off-by: Tristan Ye <tristan.ye at oracle.com>
---
 programs/fill_verify_holes/fill_holes.c  |   35 +++++++++++++++++++----------
 programs/fill_verify_holes/punch_holes.c |   35 ++++++++++++++++++++++++++++-
 2 files changed, 56 insertions(+), 14 deletions(-)

diff --git a/programs/fill_verify_holes/fill_holes.c b/programs/fill_verify_holes/fill_holes.c
index ce89746..14ac980 100644
--- a/programs/fill_verify_holes/fill_holes.c
+++ b/programs/fill_verify_holes/fill_holes.c
@@ -119,10 +119,29 @@ static int parse_opts(int argc, char **argv)
 	return 0;
 }
 
+static int resv_unwritten(int fd, uint64_t start, uint64_t len)
+{
+	int ret = 0;
+	struct ocfs2_space_resv sr;
+
+	memset(&sr, 0, sizeof(sr));
+	sr.l_whence = 0;
+	sr.l_start = start;
+	sr.l_len = len;
+
+	ret = ioctl(fd, OCFS2_IOC_RESVSP64, &sr);
+	if (ret == -1) {
+		fprintf(stderr, "ioctl error %d: \"%s\"\n",
+			errno, strerror(errno));
+		return -1;
+	}
+
+	return ret;
+}
+
 static int prep_file(char *name, unsigned long size)
 {
 	int ret, fd;
-	struct ocfs2_space_resv sr;
 
 	fd = open(name, O_RDWR|O_CREAT|O_TRUNC,
 		  S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
@@ -133,17 +152,9 @@ static int prep_file(char *name, unsigned long size)
 	}
 
 	if (create_unwritten) {
-		memset(&sr, 0, sizeof(sr));
-		sr.l_whence = 0;
-		sr.l_start = 0;
-		sr.l_len = size;
-
-		ret = ioctl(fd, OCFS2_IOC_RESVSP64, &sr);
-		if (ret == -1) {
-			fprintf(stderr, "ioctl error %d: \"%s\"\n",
-				errno, strerror(errno));
-			return -1;
-		}
+		ret = resv_unwritten(fd, 0, size);
+		if (ret)
+			return ret;
 	}
 
 	ret = ftruncate(fd, size);
diff --git a/programs/fill_verify_holes/punch_holes.c b/programs/fill_verify_holes/punch_holes.c
index 1fb0f2f..642be54 100644
--- a/programs/fill_verify_holes/punch_holes.c
+++ b/programs/fill_verify_holes/punch_holes.c
@@ -18,12 +18,13 @@
 
 static void usage(void)
 {
-	printf("punch_holes [-f] [-i ITER] [-o LOGFILE] [-r REPLAYLOG] FILE SIZE\n"
+	printf("punch_holes [-f] [-u] [-i ITER] [-o LOGFILE] [-r REPLAYLOG] FILE SIZE\n"
 	       "FILE is a path to a file\n"
 	       "SIZE is in bytes and must always be specified, even with a REPLAYLOG\n"
 	       "ITER defaults to 1000, unless REPLAYLOG is specified.\n"
 	       "LOGFILE defaults to stdout\n"
 	       "-f will result in logfile being flushed after every write\n"
+	       "-u will create an unwritten region instead of ftruncate\n"
 	       "REPLAYLOG is an optional file to generate values from\n\n"
 	       "FILE will be truncated to zero, then truncated out to SIZE\n"
 	       "A random series of characters will be written into the\n"
@@ -43,6 +44,7 @@ static char buf[MAX_WRITE_SIZE];
 
 static unsigned int max_iter = 1000;
 static unsigned int flush_output = 0;
+static unsigned int create_unwritten = 0;
 static char *fname = NULL;
 static char *logname = NULL;
 static char *replaylogname = NULL;
@@ -55,7 +57,7 @@ static int parse_opts(int argc, char **argv)
 	int c, iter_specified = 0;
 
 	while (1) {
-		c = getopt(argc, argv, "fi:o:r:");
+		c = getopt(argc, argv, "ufi:o:r:");
 		if (c == -1)
 			break;
 
@@ -63,6 +65,9 @@ static int parse_opts(int argc, char **argv)
 		case 'f':
 			flush_output = 1;
 			break;
+		case 'u':
+			create_unwritten = 1;
+			break;
 		case 'i':
 			max_iter = atoi(optarg);
 			iter_specified = 1;
@@ -190,6 +195,26 @@ static int do_write(int fd, struct write_unit *wu)
 	return 0;
 }
 
+static int resv_unwritten(int fd, uint64_t start, uint64_t len)
+{
+	int ret = 0;
+	struct ocfs2_space_resv sr;
+
+	memset(&sr, 0, sizeof(sr));
+	sr.l_whence = 0;
+	sr.l_start = start;
+	sr.l_len = len;
+
+	ret = ioctl(fd, OCFS2_IOC_RESVSP64, &sr);
+	if (ret == -1) {
+		fprintf(stderr, "ioctl error %d: \"%s\"\n",
+			errno, strerror(errno));
+		return -1;
+	}
+
+	return ret;
+}
+
 static int prep_file(char *name, unsigned long size)
 {
 	int ret, fd;
@@ -204,6 +229,12 @@ static int prep_file(char *name, unsigned long size)
 		return -1;
 	}
 
+	if (create_unwritten) {
+		ret = resv_unwritten(fd, 0, size);
+		if (ret)
+			return ret;
+	}
+
 	ret = ftruncate(fd, size);
 	if (ret == -1) {
 		close(fd);
-- 
1.5.5




More information about the Ocfs2-test-devel mailing list