Skip to contentSkip to conversation

Fix return value of make_filename() when no filename_format

PATCH In review [email protected] 2 participants 17 messages Mar 28, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/13 Fix return value of make_filename() when no filename_format

From: Tomohiro Kusumi <[email protected]>

This is unlikely to happen in the first place since ->filename_format has a default value, and option parser can also detect an empty string, but it should return buf which is sprintf'd right before returning.

A caller expects this function to return filename string (which is buf arg itself in this case), and it also doesn't handle NULL return.

---
 init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
init.c +1 -1
index 4a72255..6af6c45 100644
@@ -1121,7 +1121,7 @@ static char *make_filename(char *buf, size_t buf_size,struct thread_options *o,
 
 	if (!o->filename_format || !strlen(o->filename_format)) {
 		sprintf(buf, "%s.%d.%d", jobname, jobnum, filenum);
-		return NULL;
+		return buf;
 	}
 
 	for (f = &fpre_keywords[0]; f->keyword; f++)
Signature · 1 line
2.9.3
#1 lore raw

PATCH 2/13 Use GOLDEN_RATIO_PRIME

From: Tomohiro Kusumi <[email protected]>

Using this macro (originally for hash in Linux kernel) for rand seed instead of hard-coded value should make sense. rdma ioengine uses this for the seed as well.

---
 init.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
init.c +3 -2
index 6af6c45..eef5150 100644
@@ -26,6 +26,7 @@
 #include "idletime.h"
 #include "filelock.h"
 #include "steadystate.h"
+#include "hash.h"
 
 #include "oslib/getopt.h"
 #include "oslib/strcasestr.h"
@@ -1083,11 +1084,11 @@ static int setup_random_seeds(struct thread_data *td)
 
 	seed = td->o.rand_seed;
 	for (i = 0; i < 4; i++)
-		seed *= 0x9e370001UL;
+		seed *= GOLDEN_RATIO_PRIME;
 
 	for (i = 0; i < FIO_RAND_NR_OFFS; i++) {
 		td->rand_seeds[i] = seed * td->thread_number + i;
-		seed *= 0x9e370001UL;
+		seed *= GOLDEN_RATIO_PRIME;
 	}
 
 	td_fill_rand_seeds(td);
Signature · 1 line
2.9.3
#5 lore raw

PATCH 3/13 Test malloc result when allocation size is tunable

In reply to [email protected]

From: Tomohiro Kusumi <[email protected]>

The allocation size td->o.max_bs[DDIR_XXX] can be specified by user, so test the result although it can be over committed on some platforms. In theory allocation size could be as large as maximum of uint.

---
 filesetup.c | 9 +++++++++
 1 file changed, 9 insertions(+)
filesetup.c +9 -0
index bcf95bd..ce19cf0 100644
@@ -160,6 +160,10 @@ static int extend_file(struct thread_data *td, struct fio_file *f)
 	}
 
 	b = malloc(td->o.max_bs[DDIR_WRITE]);
+	if (!b) {
+		td_verror(td, errno, "malloc");
+		goto err;
+	}
 
 	left = f->real_file_size;
 	while (left && !td->terminate) {
@@ -243,6 +247,11 @@ static int pre_read_file(struct thread_data *td, struct fio_file *f)
 
 	bs = td->o.max_bs[DDIR_READ];
 	b = malloc(bs);
+	if (!b) {
+		td_verror(td, errno, "malloc");
+		ret = 1;
+		goto error;
+	}
 	memset(b, 0, bs);
 
 	if (lseek(f->fd, f->file_offset, SEEK_SET) < 0) {
Signature · 1 line
2.9.3
#6 lore raw

PATCH 4/13 Don't malloc more than necessary on extending/prereading file

In reply to [email protected]

From: Tomohiro Kusumi <[email protected]>

If td->o.max_bs[DDIR_XXX] were larger than file size to extend/preread, it only needs to malloc the file size.

Given that td->o.max_bs[DDIR_XXX] are tunable parameters, it's better not to malloc whatever size specified if needed size is smaller than that. Users could specify as large as maximum of uint.

I dropped "bs = td->o.max_bs[DDIR_WRITE];" inside the first while loop since now it works the same with or without this.

(This commit directly goes on top of the previous one)

---
 filesetup.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
filesetup.c +10 -5
index ce19cf0..9335dcd 100644
@@ -159,15 +159,18 @@ static int extend_file(struct thread_data *td, struct fio_file *f)
 		}
 	}
 
-	b = malloc(td->o.max_bs[DDIR_WRITE]);
+	left = f->real_file_size;
+	bs = td->o.max_bs[DDIR_WRITE];
+	if (bs > left)
+		bs = left;
+
+	b = malloc(bs);
 	if (!b) {
 		td_verror(td, errno, "malloc");
 		goto err;
 	}
 
-	left = f->real_file_size;
 	while (left && !td->terminate) {
-		bs = td->o.max_bs[DDIR_WRITE];
 		if (bs > left)
 			bs = left;
 
@@ -245,7 +248,11 @@ static int pre_read_file(struct thread_data *td, struct fio_file *f)
 
 	old_runstate = td_bump_runstate(td, TD_PRE_READING);
 
+	left = f->io_size;
 	bs = td->o.max_bs[DDIR_READ];
+	if (bs > left)
+		bs = left;
+
 	b = malloc(bs);
 	if (!b) {
 		td_verror(td, errno, "malloc");
@@ -261,8 +268,6 @@ static int pre_read_file(struct thread_data *td, struct fio_file *f)
 		goto error;
 	}
 
-	left = f->io_size;
-
 	while (left && !td->terminate) {
 		if (bs > left)
 			bs = left;
Signature · 1 line
2.9.3
#7 lore raw

PATCH 5/13 HOWTO: Mention niche detail of range format options

In reply to [email protected]

From: Tomohiro Kusumi <[email protected]>

---
 HOWTO | 2 ++
 1 file changed, 2 insertions(+)
HOWTO +2 -0
index cae95b7..80b9e75 100644
@@ -543,6 +543,8 @@ Parameter types
 
 	If the option accepts an upper and lower range, use a colon ':' or
 	minus '-' to separate such values. See :ref:`irange <irange>`.
+	If the lower value specified happens to be larger than the upper value,
+	two values are swapped.
 
 .. _bool:
 
Signature · 1 line
2.9.3
#8 lore raw

PATCH 6/13 Drop redundant "ignore invalidate option" message from 21c1b29e

In reply to [email protected]

From: Tomohiro Kusumi <[email protected]>

The message added by 21c1b29e ("fio: ignore invalidate option...") is correct in the sense that it resets invalidate= option, however since invalidation is enabled by default, this message appears whenever pre_read=1 is set (unless invalidate=0 is also explicitly set at the same time, which is unliekly).

This is annoying and shouldn't have been added. 21c1b29e updating HOWTO was enough, sorry.

---
 init.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
init.c +1 -4
index eef5150..c29a1b4 100644
@@ -766,11 +766,8 @@ static int fixup_options(struct thread_data *td)
 	}
 
 	if (o->pre_read) {
-		if (o->invalidate_cache) {
-			log_info("fio: ignore invalidate option for %s\n",
-				 o->name);
+		if (o->invalidate_cache)
 			o->invalidate_cache = 0;
-		}
 		if (td_ioengine_flagged(td, FIO_PIPEIO)) {
 			log_info("fio: cannot pre-read files with an IO engine"
 				 " that isn't seekable. Pre-read disabled.\n");
Signature · 1 line
2.9.3
#9 lore raw

PATCH 7/13 Ignore pre-read for FIO_NOIO td

In reply to [email protected]

From: Tomohiro Kusumi <[email protected]>

pre_read_file() should ignore FIO_NOIO (i.e. cpuio) in addition to FIO_PIPEIO. It does/should fail anyway since FIO_NOIO td is supposed to have -1 for fd for not supporting any I/O.

---
 filesetup.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
filesetup.c +2 -1
index 9335dcd..bd971e8 100644
@@ -235,7 +235,8 @@ static int pre_read_file(struct thread_data *td, struct fio_file *f)
 	unsigned int bs;
 	char *b;
 
-	if (td_ioengine_flagged(td, FIO_PIPEIO))
+	if (td_ioengine_flagged(td, FIO_PIPEIO) ||
+	    td_ioengine_flagged(td, FIO_NOIO))
 		return 0;
 
 	if (!fio_file_open(f)) {
Signature · 1 line
2.9.3
#10 lore raw

PATCH 8/13 Don't proceed with error set when failed to pre-read files/devices

In reply to [email protected]

From: Tomohiro Kusumi <[email protected]>

pre_read_files() never fails (never returns negative), and because of this behavior, fio threads can continue regardless of td_verror() call while prereading, and results in statistics with error in it, which is quite confusing as to how it should be interpreted for regular users.

This commit makes pre_read_files() return -1 if preread fails, and eventually aborts fio, which is also the case with some other options. It also changes non error return from 1 to 0, since all it matters is if it's <0 or not, and fio normally uses 0 for success.

Not sure what the proper way of fixing this is if it legitimately failed for some error on prereading though. Some options just print a message to indicate it's unsupported and continue normally withtout any error set.

---
 filesetup.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
filesetup.c +3 -2
index bd971e8..cd486ea 100644
@@ -1119,10 +1119,11 @@ int pre_read_files(struct thread_data *td)
 	dprint(FD_FILE, "pre_read files\n");
 
 	for_each_file(td, f, i) {
-		pre_read_file(td, f);
+		if (pre_read_file(td, f))
+			return -1;
 	}
 
-	return 1;
+	return 0;
 }
 
 static int __init_rand_distribution(struct thread_data *td, struct fio_file *f)
Signature · 1 line
2.9.3
#11 lore raw

PATCH 9/13 Ignore pre-read for character devices

In reply to [email protected]

From: Tomohiro Kusumi <[email protected]>

pre_read_file() could ignore a chrdev due to its purpose of providing unbuffered access to devices not limited to seekable disk devices, while the purpose of this function (i.e. pre_read= option) is to lseek(2) the given offset and page cache whatever read via read(2) which is basically for filesystems and blkdevs.

(This commit directly goes on top of the one before previous one)

---
 filesetup.c | 3 +++
 1 file changed, 3 insertions(+)
filesetup.c +3 -0
index cd486ea..612e794 100644
@@ -239,6 +239,9 @@ static int pre_read_file(struct thread_data *td, struct fio_file *f)
 	    td_ioengine_flagged(td, FIO_NOIO))
 		return 0;
 
+	if (f->filetype == FIO_TYPE_CHAR)
+		return 0;
+
 	if (!fio_file_open(f)) {
 		if (td->io_ops->open_file(td, f)) {
 			log_err("fio: cannot pre-read, failed to open file\n");
Signature · 1 line
2.9.3
#12 lore raw

PATCH 10/13 Drop prototype of unused function td_io_sync()

In reply to [email protected]

From: Tomohiro Kusumi <[email protected]>

858a3d47 in 2006 has removed (actually renamed) this function, so this prototype hasn't been used since then.

---
 ioengine.h | 1 -
 1 file changed, 1 deletion(-)
ioengine.h +0 -1
index 7249df6..dc2c269 100644
@@ -190,7 +190,6 @@ typedef void (*get_ioengine_t)(struct ioengine_ops **);
 extern int __must_check td_io_init(struct thread_data *);
 extern int __must_check td_io_prep(struct thread_data *, struct io_u *);
 extern int __must_check td_io_queue(struct thread_data *, struct io_u *);
-extern int __must_check td_io_sync(struct thread_data *, struct fio_file *);
 extern int __must_check td_io_getevents(struct thread_data *, unsigned int, unsigned int, const struct timespec *);
 extern int __must_check td_io_commit(struct thread_data *);
 extern int __must_check td_io_open_file(struct thread_data *, struct fio_file *);
Signature · 1 line
2.9.3
#13 lore raw

PATCH 11/13 Separate io_u from ioengine [1/3] - add io_u.h

In reply to [email protected]

From: Tomohiro Kusumi <[email protected]>

Extract io_u related structures and functions from ioengine.h to a new header io_u.h which is intended to be a header for io_u.c (similar to the way there is io_u_queue.h for io_u_queue.c), since there isn't much reason for them to be a part of ioengine.h.

This commit does nothing other than separating them out (and make other related files include the new header).

Confirmed this compiles on Linux, Cygwin and several BSDs.

---
 fio.h      |   1 +
 io_u.h     | 179 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 ioengine.h | 172 +---------------------------------------------------------
 3 files changed, 181 insertions(+), 171 deletions(-)
 create mode 100644 io_u.h
fio.h +1 -0
index 52a9b75..806f7ed 100644
@@ -39,6 +39,7 @@
 #include "server.h"
 #include "stat.h"
 #include "flow.h"
+#include "io_u.h"
 #include "io_u_queue.h"
 #include "workqueue.h"
 #include "steadystate.h"
io_u.h new file +179 -0

179 lines not on this page · raw message

ioengine.h +1 -171

186 lines not on this page · raw message

Signature · 1 line
2.9.3
#14 lore raw

PATCH 12/13 Separate io_u from ioengine [2/3] - move io_u functions

In reply to [email protected]

From: Tomohiro Kusumi <[email protected]>

Move io_u functions from ioengines.c to io_u.c whose prototypes are now located in io_u.h after the previous commit.

Prior to the previous commit, ioengine.h originally separated io_u related function prototypes and ioengine related function prototypes (by comment) based on whether they invoke struct ioengine_ops member functions or not. Prototypes for these two functions have existed in io_u side, thus they should be moved to io_u.c respectively.

---
 io_u.c      | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 ioengines.c | 58 ----------------------------------------------------------
 2 files changed, 58 insertions(+), 58 deletions(-)
io_u.c +58 -0
index c6d814b..363bfe1 100644
@@ -2087,3 +2087,61 @@ void io_u_fill_buffer(struct thread_data *td, struct io_u *io_u,
 	io_u->buf_filled_len = 0;
 	fill_io_buffer(td, io_u->buf, min_write, max_bs);
 }
+
+static int do_sync_file_range(const struct thread_data *td,
+			      struct fio_file *f)
+{
+	off64_t offset, nbytes;
+
+	offset = f->first_write;
+	nbytes = f->last_write - f->first_write;
+
+	if (!nbytes)
+		return 0;
+
+	return sync_file_range(f->fd, offset, nbytes, td->o.sync_file_range);
+}
+
+int do_io_u_sync(const struct thread_data *td, struct io_u *io_u)
+{
+	int ret;
+
+	if (io_u->ddir == DDIR_SYNC) {
+		ret = fsync(io_u->file->fd);
+	} else if (io_u->ddir == DDIR_DATASYNC) {
+#ifdef CONFIG_FDATASYNC
+		ret = fdatasync(io_u->file->fd);
+#else
+		ret = io_u->xfer_buflen;
+		io_u->error = EINVAL;
+#endif
+	} else if (io_u->ddir == DDIR_SYNC_FILE_RANGE)
+		ret = do_sync_file_range(td, io_u->file);
+	else {
+		ret = io_u->xfer_buflen;
+		io_u->error = EINVAL;
+	}
+
+	if (ret < 0)
+		io_u->error = errno;
+
+	return ret;
+}
+
+int do_io_u_trim(const struct thread_data *td, struct io_u *io_u)
+{
+#ifndef FIO_HAVE_TRIM
+	io_u->error = EINVAL;
+	return 0;
+#else
+	struct fio_file *f = io_u->file;
+	int ret;
+
+	ret = os_trim(f->fd, io_u->offset, io_u->xfer_buflen);
+	if (!ret)
+		return io_u->xfer_buflen;
+
+	io_u->error = ret;
+	return 0;
+#endif
+}
ioengines.c +0 -58

64 lines not on this page · raw message

Signature · 1 line
2.9.3
#15 lore raw

PATCH 13/13 Separate io_u from ioengine [3/3] - rename ioengine.h to ioengines.h

In reply to [email protected]

From: Tomohiro Kusumi <[email protected]>

This is based on the previous commits which added a new header io_u.h and separated io_u related from ioengine.h and ioengines.c.

Since now that ioengine.h and ioengines.c are 1:1 in their contents (i.e. prototypes and implementation), they should be based on the same name as well.

This could possibly break outbox ioengines if they include ioengine.h, but all the inbox ones just include fio.h (probably because that's what engines/skeleton_external.c does), so the impact is probably limited, and fio doesn't guarantee anything to outbox ones anyway.

---
 fio.h                     | 2 +-
 ioengine.h => ioengines.h | 0
 iolog.h                   | 2 +-
 rate-submit.c             | 2 +-
 4 files changed, 3 insertions(+), 3 deletions(-)
 rename ioengine.h => ioengines.h (100%)
fio.h +1 -1
index 806f7ed..3955a81 100644
@@ -25,7 +25,7 @@
 #include "debug.h"
 #include "file.h"
 #include "io_ddir.h"
-#include "ioengine.h"
+#include "ioengines.h"
 #include "iolog.h"
 #include "helpers.h"
 #include "options.h"
ioengines.h renamed from ioengine.h +0 -0
similarity index 100%
rename from ioengine.h
rename to ioengines.h
iolog.h +1 -1
index 37f27bc..0733ad3 100644
@@ -4,7 +4,7 @@
 #include "lib/rbtree.h"
 #include "lib/ieee754.h"
 #include "flist.h"
-#include "ioengine.h"
+#include "ioengines.h"
 
 /*
  * Use for maintaining statistics
rate-submit.c +1 -1
index 4738dc4..fdbece6 100644
@@ -5,7 +5,7 @@
  *
  */
 #include "fio.h"
-#include "ioengine.h"
+#include "ioengines.h"
 #include "lib/getrusage.h"
 #include "rate-submit.h"
 
Signature · 1 line
2.9.3
#2 lore raw

Re: [PATCH 02/13] Use GOLDEN_RATIO_PRIME

In reply to [email protected]
Quoted 5 lines · On 03/28/2017 02:02 PM, [email protected] wrote:

From: Tomohiro Kusumi <[email protected]>

Using this macro (originally for hash in Linux kernel) for rand seed instead of hard-coded value should make sense. rdma ioengine uses this for the seed as well.

This will change the seed behavior for 64-bit builds. I don't think we should do that in the name of a cleanup.

Signature · 1 line
Jens Axboe
#16 lore raw
In reply to [email protected]
Quoted 8 lines · On Tue, Mar 28 2017, [email protected] wrote:

From: Tomohiro Kusumi <[email protected]>

This is unlikely to happen in the first place since ->filename_format has a default value, and option parser can also detect an empty string, but it should return buf which is sprintf'd right before returning.

A caller expects this function to return filename string (which is buf arg itself in this case), and it also doesn't handle NULL return.

Applied 1, and 3-13. Thanks!

Signature · 1 line
Jens Axboe
#3 lore raw

Re: [PATCH 02/13] Use GOLDEN_RATIO_PRIME

In reply to Jens Axboe

Hi

Sorry, I thought using 64bit version on 64bit was the intention..

2017-03-28 23:44 GMT+03:00 Jens Axboe <[email protected]>:

Quoted 13 lines · On 03/28/2017 02:02 PM, [email protected] wrote:
Quoted 5 lines

From: Tomohiro Kusumi <[email protected]>

Using this macro (originally for hash in Linux kernel) for rand seed instead of hard-coded value should make sense. rdma ioengine uses this for the seed as well.

This will change the seed behavior for 64-bit builds. I don't think we should do that in the name of a cleanup.

--
Jens Axboe

#4 lore raw

Re: [PATCH 02/13] Use GOLDEN_RATIO_PRIME

Quoted 3 lines · Tomohiro Kusumi

Hi

Sorry, I thought using 64bit version on 64bit was the intention..

It would certainly have been nicer from the get-go, but it's not what we currently have. And I don't want to change seeds just because. If we were changing them, using the better:

#define GOLDEN_RATIO_32 0x61C88647
#define GOLDEN_RATIO_64 0x61C8864680B583EBull

would be the way to go, though.

Signature · 1 line
Jens Axboe