File fs_mark-Allow-creating-files-filled-with-random-bytes.patch of Package fs_mark

From 2cb75826dd7f28dc8481dd696cc2a587f3c9a559 Mon Sep 17 00:00:00 2001
From: David Sterba <dsterba@suse.cz>
Date: Mon, 13 Jun 2011 18:09:02 +0200
Subject: [PATCH] Allow creating files filled with random bytes

---
 fs_mark.c |   35 ++++++++++++++++++++++++++++++-----
 fs_mark.h |    2 ++
 2 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/fs_mark.c b/fs_mark.c
index a6bea34..b9cdb7c 100644
--- a/fs_mark.c
+++ b/fs_mark.c
@@ -61,7 +61,7 @@ void cleanup_exit(void)
 void usage(void)
 {
 	fprintf(stderr,
-		"Usage: fs_mark\n%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s",
+		"Usage: fs_mark\n%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s",
 		"\t-h <print usage and exit>\n",
 		"\t-k <keep files after each iteration>\n",
 		"\t-F <run until FS full>\n",
@@ -76,6 +76,7 @@ void usage(void)
 		"\t[-n number (of files per iteration)]\n",
 		"\t[-p number (of total bytes file names)]\n",
 		"\t[-r number (of random bytes in file names)]\n",
+		"\t[-R number (fill data with pseudorandom bytes, seeded with number, 0 seeds from time)]\n",
 		"\t[-s byte_count (size in bytes of each file)]\n",
 		"\t[-t number (of total threads)]\n",
 		"\t[-w number (of bytes per write() syscall)]\n");
@@ -94,7 +95,7 @@ void process_args(int argc, char **argv, char **envp)
 	 * Parse all of the options that the user specified.
 	 */
 	while ((ret =
-		getopt(argc, argv, "vhkFr:S:N:D:d:l:L:n:p:s:t:w:")) != EOF) {
+		getopt(argc, argv, "vhkFr:S:N:D:d:l:L:n:p:s:t:w:R:")) != EOF) {
 		switch (ret) {
 		case 'v':	/* verbose stats */
 			verbose_stats = 1;
@@ -179,6 +180,12 @@ void process_args(int argc, char **argv, char **envp)
 		case 'r':	/* Use random file names */
 			rand_len = atoi(optarg);
 			break;
+		case 'R':	/* Fill files with random data */
+			rand_seed = atoi(optarg);
+			zero_filled_files = 0;
+			if (!rand_seed)
+				rand_seed = time(NULL);
+			break;
 
 		case 'S':	/* Turn off sync and fsync */
 			sync_method_type = atoi(optarg);
@@ -433,6 +440,20 @@ void setup_file_name(int file_index, pid_t my_pid)
 	return;
 }
 
+static void init_io_buffer() {
+	if (zero_filled_files)
+		memset(io_buffer, 0, io_buffer_size);
+	else {
+		int i;
+		char *b = io_buffer;
+
+		srandom(rand_seed);
+		for (i = 0; i < io_buffer_size; i++)
+			*b++ = random();
+	}
+}
+
+
 /*
  * Setup and initial state
  */
@@ -469,9 +490,9 @@ void setup(pid_t pid)
 	}
 
 	/*
-	 * Clear the io_buffer
+	 * Initialize io_buffer, zero- or random- filled
 	 */
-	memset(io_buffer, 0, io_buffer_size);
+	init_io_buffer();
 
 	/*
 	 * Create my high level test directory
@@ -533,7 +554,7 @@ unsigned long long get_bytes_free(char *dir_name)
 }
 
 /*
- * This routine opens, writes the amount of (zero filled) data to a file.
+ * This routine opens, writes the amount of data to a file.
  * It chunks IO requests into the specified buffer size.  The data is just zeroed, 
  * nothing in the kernel inspects the contents of the buffer on its way to disk.
  */
@@ -1227,6 +1248,10 @@ void print_run_info(FILE * log_fp, int argc, char **argv)
 		file_size, io_buffer_size);
 	fprintf(log_fp,
 		"#\tApp overhead is time in microseconds spent in the test not doing file writing related system calls.\n");
+	if (zero_filled_files)
+		fprintf(log_fp, "#\tFiles will be zero filled\n");
+	else
+		fprintf(log_fp, "#\tFiles will be filled with pseudorandom bytes, seeded with %u\n", rand_seed);
 
 	if (log_fp != stdout)
 		fprintf(log_fp, "#");
diff --git a/fs_mark.h b/fs_mark.h
index 0cb26a3..c06ac7d 100644
--- a/fs_mark.h
+++ b/fs_mark.h
@@ -106,6 +106,8 @@ unsigned int	file_size = DEFAULT_FILE_SIZE;	/* File size to create during run  *
 int	num_files = DEFAULT_NUM_FILES;		/* Number of times to test each file size */
 int	name_len = DEFAULT_NAME_LEN;		/* Number of characters in a filename */
 int	rand_len = DEFAULT_RAND_NAME;		/* Number of random characters in a filename */
+int     zero_filled_files = 1;			/* Force zero filled files by default */
+unsigned int rand_seed = 0;			/* Seed for random number generator, 0 will call time(NULL) */
 
 /*
  * Variables to control how many subdirectories & how to fill them
-- 
1.7.3.4

openSUSE Build Service is sponsored by