All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jaegeuk Kim <jaegeuk@kernel.org>
To: linux-f2fs-devel@lists.sourceforge.net
Cc: Jaegeuk Kim <jaegeuk@google.com>
Subject: [PATCH 1/4] f2fs_io: add write
Date: Wed, 20 Feb 2019 09:07:42 -0800	[thread overview]
Message-ID: <20190220170745.7328-1-jaegeuk@kernel.org> (raw)

From: Jaegeuk Kim <jaegeuk@google.com>

f2fs_io write [chunk_size in 4kb] [offset in chunk_size] [count] [pattern] [IO] [file_path]

Write given patten data in file_path
pattern can be
  zero     : zeros
  inc_num  : incrementing numbers
  rand     : random numbers
IO can be
  buffered : buffered IO
  dio      : direct IO

Change-Id: Icc866d5b9933423639d1d0e4d5e556ddf4f15feb
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
---
 tools/f2fs_io/f2fs_io.c | 88 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 88 insertions(+)

diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c
index c39273e..0515108 100644
--- a/tools/f2fs_io/f2fs_io.c
+++ b/tools/f2fs_io/f2fs_io.c
@@ -15,8 +15,12 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <time.h>
+#include <string.h>
 #include <signal.h>
 #include <termios.h>
+#include <sys/types.h>
+#include <sys/stat.h>
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -127,6 +131,89 @@ static void do_pinfile(int argc, char **argv, const struct cmd_desc *cmd)
 	exit(0);
 }
 
+#define write_desc "write data into file"
+#define write_help					\
+"f2fs_io write [chunk_size in 4kb] [offset in chunk_size] [count] [pattern] [IO] [file_path]\n\n"	\
+"Write given patten data in file_path\n"		\
+"pattern can be\n"					\
+"  zero     : zeros\n"					\
+"  inc_num  : incrementing numbers\n"			\
+"  rand     : random numbers\n"				\
+"IO can be\n"						\
+"  buffered : buffered IO\n"				\
+"  dio      : direct IO\n"				\
+
+static void do_write(int argc, char **argv, const struct cmd_desc *cmd)
+{
+	u64 buf_size = 0, inc_num = 0, ret = 0, written = 0;
+	loff_t offset;
+	char *buf = NULL;
+	unsigned bs, count, i;
+	int flags = 0;
+	int fd;
+
+	srand(time(0));
+
+	if (argc != 7) {
+		fputs("Excess arguments\n\n", stderr);
+		fputs(cmd->cmd_help, stderr);
+		exit(1);
+	}
+
+	bs = atoi(argv[1]);
+	if (bs > 1024) {
+		fputs("Too big chunk size - limit: 4MB\n\n", stderr);
+		exit(1);
+	}
+	buf_size = bs * 4096;
+
+	offset = atoi(argv[2]) * buf_size;
+
+	buf = aligned_alloc(4096, buf_size);
+	if (!buf) {
+		fputs("Memory alloc failed\n\n", stderr);
+		exit(1);
+	}
+	count = atoi(argv[3]);
+
+	if (!strcmp(argv[4], "zero")) {
+		memset(buf, 0, buf_size);
+	} else if (strcmp(argv[4], "inc_num") &&
+			strcmp(argv[4], "rand")) {
+		fputs("Wrong pattern type\n\n", stderr);
+		exit(1);
+	}
+
+	if (!strcmp(argv[5], "buffered")) {
+		flags |= O_DIRECT;
+	} else if (strcmp(argv[5], "dio")) {
+		fputs("Wrong IO type\n\n", stderr);
+		exit(1);
+	}
+
+	fd = open(argv[6], O_CREAT | O_WRONLY | flags, 0755);
+	if (fd == -1) {
+		fputs("Open failed\n\n", stderr);
+		exit(1);
+	}
+
+	for (i = 0; i < count; i++) {
+		if (!strcmp(argv[4], "inc_num"))
+			*(int *)buf = inc_num++;
+		else if (!strcmp(argv[4], "rand"))
+			*(int *)buf = rand();
+
+		/* write data */
+		ret = pwrite(fd, buf, buf_size, offset + buf_size * i);
+		if (ret != buf_size)
+			break;
+		written += ret;
+	}
+
+	printf("Written %lu bytes with pattern=%s\n", written, argv[4]);
+	exit(0);
+}
+
 #define CMD_HIDDEN 	0x0001
 #define CMD(name) { #name, do_##name, name##_desc, name##_help, 0 }
 #define _CMD(name) { #name, do_##name, NULL, NULL, CMD_HIDDEN }
@@ -136,6 +223,7 @@ const struct cmd_desc cmd_list[] = {
 	_CMD(help),
 	CMD(shutdown),
 	CMD(pinfile),
+	CMD(write),
 	{ NULL, NULL, NULL, NULL, 0 }
 };
 
-- 
2.19.0.605.g01d371f741-goog

             reply	other threads:[~2019-02-20 17:07 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-20 17:07 Jaegeuk Kim [this message]
2019-02-20 17:07 ` [PATCH 2/4] f2fs_io: add read Jaegeuk Kim
2019-02-20 17:07 ` [PATCH 3/4] f2fs_io: add fiemap Jaegeuk Kim
2019-02-20 17:07 ` [PATCH 4/4] f2fs_io: add gc_urgent Jaegeuk Kim
2019-02-28  1:23 ` [PATCH 1/4] f2fs_io: add write Chao Yu
2019-02-28  3:12   ` Jaegeuk Kim
2019-02-28  1:35 ` Chao Yu
2019-02-28  3:11   ` Jaegeuk Kim

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190220170745.7328-1-jaegeuk@kernel.org \
    --to=jaegeuk@kernel.org \
    --cc=jaegeuk@google.com \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.