* [PATCH 1/4] f2fs_io: add write
@ 2019-02-20 17:07 Jaegeuk Kim
2019-02-20 17:07 ` [PATCH 2/4] f2fs_io: add read Jaegeuk Kim
` (4 more replies)
0 siblings, 5 replies; 8+ messages in thread
From: Jaegeuk Kim @ 2019-02-20 17:07 UTC (permalink / raw)
To: linux-f2fs-devel; +Cc: Jaegeuk Kim
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
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/4] f2fs_io: add read
2019-02-20 17:07 [PATCH 1/4] f2fs_io: add write Jaegeuk Kim
@ 2019-02-20 17:07 ` Jaegeuk Kim
2019-02-20 17:07 ` [PATCH 3/4] f2fs_io: add fiemap Jaegeuk Kim
` (3 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Jaegeuk Kim @ 2019-02-20 17:07 UTC (permalink / raw)
To: linux-f2fs-devel; +Cc: Jaegeuk Kim
From: Jaegeuk Kim <jaegeuk@google.com>
f2fs_io read [chunk_size in 4kb] [offset in chunk_size] [count] [IO] [print_nbytes] [file_path]
Read data in file_path and print nbytes
IO can be
buffered : buffered IO
dio : direct IO
Change-Id: I912adc4f443c3656ad067d29a1e2f581b79d28e6
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
---
tools/f2fs_io/f2fs_io.c | 86 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 86 insertions(+)
diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c
index 0515108..d09f732 100644
--- a/tools/f2fs_io/f2fs_io.c
+++ b/tools/f2fs_io/f2fs_io.c
@@ -214,6 +214,91 @@ static void do_write(int argc, char **argv, const struct cmd_desc *cmd)
exit(0);
}
+#define read_desc "read data from file"
+#define read_help \
+"f2fs_io read [chunk_size in 4kb] [offset in chunk_size] [count] [IO] [print_nbytes] [file_path]\n\n" \
+"Read data in file_path and print nbytes\n" \
+"IO can be\n" \
+" buffered : buffered IO\n" \
+" dio : direct IO\n" \
+
+static void do_read(int argc, char **argv, const struct cmd_desc *cmd)
+{
+ u64 buf_size = 0, ret = 0, read_cnt = 0;
+ loff_t offset;
+ char *buf = NULL;
+ char *print_buf = NULL;
+ unsigned bs, count, i, print_bytes;
+ int flags = 0;
+ int fd;
+
+ 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], "buffered")) {
+ flags |= O_DIRECT;
+ } else if (strcmp(argv[4], "dio")) {
+ fputs("Wrong IO type\n\n", stderr);
+ exit(1);
+ }
+
+ print_bytes = atoi(argv[5]);
+ if (print_bytes > buf_size) {
+ fputs("Print_nbytes should be less then chunk_size in kb\n\n", stderr);
+ exit(1);
+ }
+ print_buf = malloc(print_bytes);
+ if (!print_buf) {
+ fputs("Memory alloc failed\n\n", stderr);
+ exit(1);
+ }
+
+ fd = open(argv[6], O_RDONLY | flags);
+ if (fd == -1) {
+ fputs("Open failed\n\n", stderr);
+ exit(1);
+ }
+
+ for (i = 0; i < count; i++) {
+ ret = pread(fd, buf, buf_size, offset + buf_size * i);
+ if (ret != buf_size)
+ break;
+
+ read_cnt += ret;
+ if (i == 0)
+ memcpy(print_buf, buf, print_bytes);
+ }
+ printf("Read %lu bytes and print %d bytes:\n", read_cnt, print_bytes);
+ printf("%08lx : ", offset);
+ for (i = 1; i <= print_bytes; i++) {
+ printf("%02x", print_buf[i - 1]);
+ if (i % 16 == 0)
+ printf("\n%08lx : ", offset + 16 * i);
+ else if (i % 2 == 0)
+ printf(" ");
+ }
+ printf("\n");
+ 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 }
@@ -224,6 +309,7 @@ const struct cmd_desc cmd_list[] = {
CMD(shutdown),
CMD(pinfile),
CMD(write),
+ CMD(read),
{ NULL, NULL, NULL, NULL, 0 }
};
--
2.19.0.605.g01d371f741-goog
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 3/4] f2fs_io: add fiemap
2019-02-20 17:07 [PATCH 1/4] f2fs_io: add write Jaegeuk Kim
2019-02-20 17:07 ` [PATCH 2/4] f2fs_io: add read Jaegeuk Kim
@ 2019-02-20 17:07 ` Jaegeuk Kim
2019-02-20 17:07 ` [PATCH 4/4] f2fs_io: add gc_urgent Jaegeuk Kim
` (2 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Jaegeuk Kim @ 2019-02-20 17:07 UTC (permalink / raw)
To: linux-f2fs-devel; +Cc: Jaegeuk Kim
From: Jaegeuk Kim <jaegeuk@google.com>
f2fs_io fiemap [offset in 4kb] [count] [file_path]
Change-Id: Iee9e8b742ada6a12a9f761b3a6de8d82a60e1b59
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
---
tools/f2fs_io/f2fs_io.c | 61 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 61 insertions(+)
diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c
index d09f732..70fde6e 100644
--- a/tools/f2fs_io/f2fs_io.c
+++ b/tools/f2fs_io/f2fs_io.c
@@ -9,6 +9,15 @@
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
+#ifndef _LARGEFILE_SOURCE
+#define _LARGEFILE_SOURCE
+#endif
+#ifndef _LARGEFILE64_SOURCE
+#define _LARGEFILE64_SOURCE
+#endif
+#ifndef O_LARGEFILE
+#define O_LARGEFILE 0
+#endif
#include <stdio.h>
#include <fcntl.h>
@@ -299,6 +308,57 @@ static void do_read(int argc, char **argv, const struct cmd_desc *cmd)
exit(0);
}
+struct file_ext {
+ __u32 f_pos;
+ __u32 start_blk;
+ __u32 end_blk;
+ __u32 blk_count;
+};
+
+#ifndef FIBMAP
+#define FIBMAP _IO(0x00, 1) /* bmap access */
+#endif
+
+#define fiemap_desc "get block address in file"
+#define fiemap_help \
+"f2fs_io fiemap [offset in 4kb] [count] [file_path]\n\n"\
+
+static void do_fiemap(int argc, char **argv, const struct cmd_desc *cmd)
+{
+ loff_t offset;
+ u32 blknum;
+ unsigned count, i;
+ int fd;
+
+ if (argc != 4) {
+ fputs("Excess arguments\n\n", stderr);
+ fputs(cmd->cmd_help, stderr);
+ exit(1);
+ }
+
+ offset = atoi(argv[1]);
+ count = atoi(argv[2]);
+
+ fd = open(argv[3], O_RDONLY | O_LARGEFILE);
+ if (fd == -1) {
+ fputs("Open failed\n\n", stderr);
+ exit(1);
+ }
+
+ printf("Fiemap: offset = %08lx len = %d\n", offset, count);
+ for (i = 0; i < count; i++) {
+ blknum = offset + i;
+
+ if (ioctl(fd, FIBMAP, &blknum) < 0) {
+ fputs("FIBMAP failed\n\n", stderr);
+ exit(1);
+ }
+ printf("%u ", blknum);
+ }
+ printf("\n");
+ 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 }
@@ -310,6 +370,7 @@ const struct cmd_desc cmd_list[] = {
CMD(pinfile),
CMD(write),
CMD(read),
+ CMD(fiemap),
{ NULL, NULL, NULL, NULL, 0 }
};
--
2.19.0.605.g01d371f741-goog
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 4/4] f2fs_io: add gc_urgent
2019-02-20 17:07 [PATCH 1/4] f2fs_io: add write Jaegeuk Kim
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 ` Jaegeuk Kim
2019-02-28 1:23 ` [PATCH 1/4] f2fs_io: add write Chao Yu
2019-02-28 1:35 ` Chao Yu
4 siblings, 0 replies; 8+ messages in thread
From: Jaegeuk Kim @ 2019-02-20 17:07 UTC (permalink / raw)
To: linux-f2fs-devel; +Cc: Jaegeuk Kim
e.g.,
f2fs_io gc_urgent dm-4 [start/end/run] [time in sec]
This controls sysfs/gc_urgent to run f2fs_gc urgently.
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
tools/f2fs_io/f2fs_io.c | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c
index 70fde6e..cb28ff8 100644
--- a/tools/f2fs_io/f2fs_io.c
+++ b/tools/f2fs_io/f2fs_io.c
@@ -359,6 +359,40 @@ static void do_fiemap(int argc, char **argv, const struct cmd_desc *cmd)
exit(0);
}
+#define gc_urgent_desc "start/end/run gc_urgent for given time period"
+#define gc_urgent_help \
+"f2fs_io gc_urgent $dev [start/end/run] [time in sec]\n\n"\
+" - f2fs_io gc_urgent sda21 start\n" \
+" - f2fs_io gc_urgent sda21 end\n" \
+" - f2fs_io gc_urgent sda21 run 10\n" \
+
+static void do_gc_urgent(int argc, char **argv, const struct cmd_desc *cmd)
+{
+ char command[255];
+
+ if (argc == 3 && !strcmp(argv[2], "start")) {
+ printf("gc_urgent: start on %s\n", argv[1]);
+ sprintf(command, "echo %d > %s/%s/gc_urgent", 1, "/sys/fs/f2fs/", argv[1]);
+ system(command);
+ } else if (argc == 3 && !strcmp(argv[2], "end")) {
+ printf("gc_urgent: end on %s\n", argv[1]);
+ sprintf(command, "echo %d > %s/%s/gc_urgent", 0, "/sys/fs/f2fs/", argv[1]);
+ system(command);
+ } else if (argc == 4 && !strcmp(argv[2], "run")) {
+ printf("gc_urgent: start on %s for %d secs\n", argv[1], atoi(argv[3]));
+ sprintf(command, "echo %d > %s/%s/gc_urgent", 1, "/sys/fs/f2fs/", argv[1]);
+ system(command);
+ sleep(atoi(argv[3]));
+ printf("gc_urgent: end on %s for %d secs\n", argv[1], atoi(argv[3]));
+ sprintf(command, "echo %d > %s/%s/gc_urgent", 0, "/sys/fs/f2fs/", argv[1]);
+ system(command);
+ } else {
+ fputs("Excess arguments\n\n", stderr);
+ fputs(cmd->cmd_help, stderr);
+ exit(1);
+ }
+}
+
#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 }
@@ -371,6 +405,7 @@ const struct cmd_desc cmd_list[] = {
CMD(write),
CMD(read),
CMD(fiemap),
+ CMD(gc_urgent),
{ NULL, NULL, NULL, NULL, 0 }
};
--
2.19.0.605.g01d371f741-goog
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 1/4] f2fs_io: add write
2019-02-20 17:07 [PATCH 1/4] f2fs_io: add write Jaegeuk Kim
` (2 preceding siblings ...)
2019-02-20 17:07 ` [PATCH 4/4] f2fs_io: add gc_urgent Jaegeuk Kim
@ 2019-02-28 1:23 ` Chao Yu
2019-02-28 3:12 ` Jaegeuk Kim
2019-02-28 1:35 ` Chao Yu
4 siblings, 1 reply; 8+ messages in thread
From: Chao Yu @ 2019-02-28 1:23 UTC (permalink / raw)
To: Jaegeuk Kim, linux-f2fs-devel; +Cc: Jaegeuk Kim
On 2019/2/21 1:07, Jaegeuk Kim wrote:
> 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();
Just assigning first 4 bytes is enough? do we need assign the whole buffer?
Thanks,
> +
> + /* 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 }
> };
>
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/4] f2fs_io: add write
2019-02-20 17:07 [PATCH 1/4] f2fs_io: add write Jaegeuk Kim
` (3 preceding siblings ...)
2019-02-28 1:23 ` [PATCH 1/4] f2fs_io: add write Chao Yu
@ 2019-02-28 1:35 ` Chao Yu
2019-02-28 3:11 ` Jaegeuk Kim
4 siblings, 1 reply; 8+ messages in thread
From: Chao Yu @ 2019-02-28 1:35 UTC (permalink / raw)
To: Jaegeuk Kim, linux-f2fs-devel; +Cc: Jaegeuk Kim
On 2019/2/21 1:07, Jaegeuk Kim wrote:
> 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);
> + }
should be
if (!strcmp(, dio)) {
flags |= O_DIRECT;
} else if (strcmp(, buffered)) {
fputs();
}
> +
> + 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 }
> };
>
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/4] f2fs_io: add write
2019-02-28 1:35 ` Chao Yu
@ 2019-02-28 3:11 ` Jaegeuk Kim
0 siblings, 0 replies; 8+ messages in thread
From: Jaegeuk Kim @ 2019-02-28 3:11 UTC (permalink / raw)
To: Chao Yu; +Cc: Jaegeuk Kim, linux-f2fs-devel
On 02/28, Chao Yu wrote:
> On 2019/2/21 1:07, Jaegeuk Kim wrote:
> > 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);
> > + }
>
> should be
>
> if (!strcmp(, dio)) {
> flags |= O_DIRECT;
> } else if (strcmp(, buffered)) {
> fputs();
> }
Yeah, right. I'll write another patch, since I merged it too early.
>
> > +
> > + 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 }
> > };
> >
> >
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/4] f2fs_io: add write
2019-02-28 1:23 ` [PATCH 1/4] f2fs_io: add write Chao Yu
@ 2019-02-28 3:12 ` Jaegeuk Kim
0 siblings, 0 replies; 8+ messages in thread
From: Jaegeuk Kim @ 2019-02-28 3:12 UTC (permalink / raw)
To: Chao Yu; +Cc: Jaegeuk Kim, linux-f2fs-devel
On 02/28, Chao Yu wrote:
> On 2019/2/21 1:07, Jaegeuk Kim wrote:
> > 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();
>
> Just assigning first 4 bytes is enough? do we need assign the whole buffer?
First 4 bytes to have the given content would be enough, since we're dealing
with 4KB blocks all the time.
>
> Thanks,
>
> > +
> > + /* 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 }
> > };
> >
> >
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2019-02-28 3:12 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-02-20 17:07 [PATCH 1/4] f2fs_io: add write Jaegeuk Kim
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).