fio: add FIO_RO_NEEDS_RW_OPEN ioengine flag
authorVincent Fu <vincent.fu@samsung.com>
Fri, 3 Feb 2023 14:54:50 +0000 (09:54 -0500)
committerVincent Fu <vincent.fu@samsung.com>
Fri, 3 Feb 2023 18:26:32 +0000 (13:26 -0500)
Some oddball cases like sg/bsg require devices to be opened for writing
in order to do read commands. So fio has been opening character devices
in rw mode for read workloads. However, nvme generic character devices
do not need (and may refuse) a writeable open for read workloads. So
instead of always opening character devices in rw mode, open devices in
rw mode for read workloads only if the ioengine has the
FIO_RO_NEEDS_RW_OPEN flag.

Link: https://lore.kernel.org/fio/20230203123421.126720-1-joshi.k@samsung.com/
Signed-off-by: Vincent Fu <vincent.fu@samsung.com>
engines/sg.c
filesetup.c
ioengines.h

index 24783374cba3086a72bb530a7ed854a2ca4a8a17..0bb5be4a9d64f6195a0165eee8f8e54e279f1ded 100644 (file)
@@ -1428,7 +1428,7 @@ static struct ioengine_ops ioengine = {
        .open_file      = fio_sgio_open,
        .close_file     = fio_sgio_close,
        .get_file_size  = fio_sgio_get_file_size,
-       .flags          = FIO_SYNCIO | FIO_RAWIO,
+       .flags          = FIO_SYNCIO | FIO_RAWIO | FIO_RO_NEEDS_RW_OPEN,
        .options        = options,
        .option_struct_size     = sizeof(struct sg_options)
 };
index 1d3cc5ad9e004f1f25d862d4e9316e2ee0f68b94..cb7047c5afe58019809802a0a8cb77e6e400f507 100644 (file)
@@ -768,7 +768,7 @@ open_again:
                else
                        from_hash = file_lookup_open(f, flags);
        } else if (td_read(td)) {
-               if (f->filetype == FIO_TYPE_CHAR && !read_only)
+               if (td_ioengine_flagged(td, FIO_RO_NEEDS_RW_OPEN) && !read_only)
                        flags |= O_RDWR;
                else
                        flags |= O_RDONLY;
index d43540d0f6032c480008a86d1d07f69b807f9341..2cb9743e8ec9ccae19b7de02f9f713ab0f373350 100644 (file)
@@ -89,6 +89,8 @@ enum fio_ioengine_flags {
                        = 1 << 16,      /* async ioengine with commit function that sets issue_time */
        FIO_SKIPPABLE_IOMEM_ALLOC
                        = 1 << 17,      /* skip iomem_alloc & iomem_free if job sets mem/iomem */
+       FIO_RO_NEEDS_RW_OPEN
+                       = 1 << 18,      /* open files in rw mode even if we have a read job */
 };
 
 /*