From: Ammar Faizi <[email protected]>
To: Jens Axboe <[email protected]>
Cc: Ammar Faizi <[email protected]>,
Alviro Iskandar Setiawan <[email protected]>,
Niklas Cassel <[email protected]>,
fio Mailing List <[email protected]>,
GNU/Weeb Mailing List <[email protected]>
Subject: [PATCH v1 6/8] blktrace: Add ENOMEM handling in `trace_add_open_close_event()` and its callers
Date: Fri, 29 Apr 2022 07:47:03 +0700 [thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
From: Ammar Faizi <[email protected]>
When this function hits ENOMEM, there is no way to notify the callers
that we fail to allocate the memory. This changes the return value of
`trace_add_open_close_event()` to `int` so we can tell the caller if
it hits ENOMEM. Also, fix the callers to handle this error case.
Signed-off-by: Ammar Faizi <[email protected]>
---
blktrace.c | 34 ++++++++++++++++++++++++++--------
1 file changed, 26 insertions(+), 8 deletions(-)
diff --git a/blktrace.c b/blktrace.c
index 95adf698..98ba25d1 100644
--- a/blktrace.c
+++ b/blktrace.c
@@ -80,14 +80,14 @@ bool is_blktrace(const char *filename, int *need_swap)
#define FMAJOR(dev) ((unsigned int) ((dev) >> FMINORBITS))
#define FMINOR(dev) ((unsigned int) ((dev) & FMINORMASK))
-static void trace_add_open_close_event(struct thread_data *td, int fileno,
- enum file_log_act action)
+static int trace_add_open_close_event(struct thread_data *td, int fileno,
+ enum file_log_act action)
{
struct io_piece *ipo;
ipo = calloc(1, sizeof(*ipo));
if (!ipo)
- return;
+ return -ENOMEM;
init_ipo(ipo);
@@ -95,6 +95,7 @@ static void trace_add_open_close_event(struct thread_data *td, int fileno,
ipo->fileno = fileno;
ipo->file_action = action;
flist_add_tail(&ipo->list, &td->io_log_list);
+ return 0;
}
static int trace_add_file(struct thread_data *td, __u32 device,
@@ -124,6 +125,7 @@ static int trace_add_file(struct thread_data *td, __u32 device,
strcpy(dev, "/dev");
if (blktrace_lookup_device(td->o.replay_redirect, dev, maj, min)) {
int fileno;
+ int err;
if (td->o.replay_redirect)
dprint(FD_BLKTRACE, "device lookup: %d/%d\n overridden"
@@ -137,7 +139,9 @@ static int trace_add_file(struct thread_data *td, __u32 device,
td->o.open_files++;
td->files[fileno]->major = maj;
td->files[fileno]->minor = min;
- trace_add_open_close_event(td, fileno, FIO_LOG_OPEN_FILE);
+ err = trace_add_open_close_event(td, fileno, FIO_LOG_OPEN_FILE);
+ if (err < 0)
+ return err;
cache->fileno = fileno;
}
@@ -217,12 +221,15 @@ static bool handle_trace_discard(struct thread_data *td,
if (td->o.replay_skip & (1u << DDIR_TRIM))
return false;
+ fileno = trace_add_file(td, t->device, cache);
+ if (fileno < 0)
+ return false;
+
ipo = calloc(1, sizeof(*ipo));
if (!ipo)
return false;
init_ipo(ipo);
- fileno = trace_add_file(td, t->device, cache);
ios[DDIR_TRIM]++;
if (t->bytes > bs[DDIR_TRIM])
@@ -261,6 +268,8 @@ static bool handle_trace_fs(struct thread_data *td, struct blk_io_trace *t,
int fileno;
fileno = trace_add_file(td, t->device, cache);
+ if (fileno < 0)
+ return false;
rw = (t->action & BLK_TC_ACT(BLK_TC_WRITE)) != 0;
@@ -297,12 +306,15 @@ static bool handle_trace_flush(struct thread_data *td, struct blk_io_trace *t,
if (td->o.replay_skip & (1u << DDIR_SYNC))
return false;
+ fileno = trace_add_file(td, t->device, cache);
+ if (fileno < 0)
+ return false;
+
ipo = calloc(1, sizeof(*ipo));
if (!ipo)
return false;
init_ipo(ipo);
- fileno = trace_add_file(td, t->device, cache);
ipo->delay = ttime / 1000;
ipo->ddir = DDIR_SYNC;
@@ -560,8 +572,14 @@ bool read_blktrace(struct thread_data* td)
return true;
}
- for_each_file(td, fiof, i)
- trace_add_open_close_event(td, fiof->fileno, FIO_LOG_CLOSE_FILE);
+ for_each_file(td, fiof, i) {
+ int err;
+
+ err = trace_add_open_close_event(td, fiof->fileno,
+ FIO_LOG_CLOSE_FILE);
+ if (err < 0)
+ goto err;
+ }
fclose(td->io_log_rfile);
td->io_log_rfile = NULL;
--
Ammar Faizi
next prev parent reply other threads:[~2022-04-29 0:47 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-29 0:46 [PATCH v1 0/8] fio error handling fixes Ammar Faizi
2022-04-29 0:46 ` [PATCH v1 1/8] cgroup: Add ENOMEM handling on a `malloc()` call Ammar Faizi
2022-04-29 18:20 ` Vincent Fu
2022-04-30 3:25 ` Alviro Iskandar Setiawan
2022-04-29 0:46 ` [PATCH v1 2/8] stat: Add ENOMEM handling on `malloc()` / `calloc()` calls Ammar Faizi
2022-04-29 0:47 ` [PATCH v1 3/8] engines/net: Add ENOMEM handling on a `malloc()` call Ammar Faizi
2022-04-29 18:20 ` Vincent Fu
2022-04-29 0:47 ` [PATCH v1 4/8] blktrace: Fix broken error handling in `merge_blktrace_iologs()` Ammar Faizi
2022-04-29 0:47 ` [PATCH v1 5/8] blktrace: Add ENOMEM handling when allocating @ipo Ammar Faizi
2022-04-29 0:47 ` Ammar Faizi [this message]
2022-04-29 0:47 ` [PATCH v1 7/8] client: Add ENOMEM handling on `realloc()` calls Ammar Faizi
2022-04-29 0:47 ` [PATCH v1 8/8] client: Add ENOMEM handling on `malloc()`, `calloc()` and `strdup()` calls Ammar Faizi
2022-04-30 13:08 ` Jens Axboe
2022-04-29 18:21 ` [PATCH v1 0/8] fio error handling fixes Jens Axboe
2022-04-29 20:15 ` Ammar Faizi
2022-04-29 20:37 ` Jens Axboe
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 \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox