From 17318cf6e42ef6b8d14e400eb1f6cc78dd668e1d Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Thu, 12 Sep 2019 10:15:42 -0600 Subject: [PATCH] engines/io_uring: fix crash with registerfiles=1 If used with a raw bdev, we're crashing in attempting to open a registered file before we have actually registered them. If we're called before files are registered, just open the file normally. This is done to query sizes etc, and we'll get the file closed after that anyway. The job open/close will use the right registered fd. Signed-off-by: Jens Axboe --- engines/io_uring.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/engines/io_uring.c b/engines/io_uring.c index 10cfe9f2..65f8e236 100644 --- a/engines/io_uring.c +++ b/engines/io_uring.c @@ -555,6 +555,7 @@ static int fio_ioring_post_init(struct thread_data *td) return 1; } + printf("files=%d\n", o->registerfiles); if (o->registerfiles) { err = fio_ioring_register_files(td); if (err) { @@ -613,7 +614,7 @@ static int fio_ioring_open_file(struct thread_data *td, struct fio_file *f) struct ioring_data *ld = td->io_ops_data; struct ioring_options *o = td->eo; - if (!o->registerfiles) + if (!ld || !o->registerfiles) return generic_open_file(td, f); f->fd = ld->fds[f->engine_pos]; @@ -622,9 +623,10 @@ static int fio_ioring_open_file(struct thread_data *td, struct fio_file *f) static int fio_ioring_close_file(struct thread_data *td, struct fio_file *f) { + struct ioring_data *ld = td->io_ops_data; struct ioring_options *o = td->eo; - if (!o->registerfiles) + if (!ld || !o->registerfiles) return generic_close_file(td, f); f->fd = -1; -- 2.25.1