All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] backend: fix switch_ioscheduler()
@ 2021-04-14 11:10 Damien Le Moal
  2021-04-14 14:23 ` Jens Axboe
  0 siblings, 1 reply; 3+ messages in thread
From: Damien Le Moal @ 2021-04-14 11:10 UTC (permalink / raw)
  To: fio, Jens Axboe

If the first file specified for a job is not a block device file, the
ioscheduler option cannot be used. Trying to use this option can cause a
crash as that file du (struct disk_util) field is NULL. Prevent such
crash and signal the error by testing the file type, allowing only files
with the type FIO_TYPE_BLOCK to proceed with switching the IO scheduler.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
---
 backend.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/backend.c b/backend.c
index 52b4ca7e..18372a92 100644
--- a/backend.c
+++ b/backend.c
@@ -1356,6 +1356,12 @@ static int switch_ioscheduler(struct thread_data *td)
 		return 0;
 
 	assert(td->files && td->files[0]);
+	if (td->files[0]->filetype != FIO_TYPE_BLOCK) {
+		log_err("fio: cannot switch IO scheduler with file %s\n",
+			td->files[0]->file_name);
+		return -1;
+	}
+
 	sprintf(tmp, "%s/queue/scheduler", td->files[0]->du->sysfs_root);
 
 	f = fopen(tmp, "r+");
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] backend: fix switch_ioscheduler()
  2021-04-14 11:10 [PATCH] backend: fix switch_ioscheduler() Damien Le Moal
@ 2021-04-14 14:23 ` Jens Axboe
  2021-04-14 22:16   ` Damien Le Moal
  0 siblings, 1 reply; 3+ messages in thread
From: Jens Axboe @ 2021-04-14 14:23 UTC (permalink / raw)
  To: Damien Le Moal, fio

On 4/14/21 5:10 AM, Damien Le Moal wrote:
> If the first file specified for a job is not a block device file, the
> ioscheduler option cannot be used. Trying to use this option can cause a
> crash as that file du (struct disk_util) field is NULL. Prevent such
> crash and signal the error by testing the file type, allowing only files
> with the type FIO_TYPE_BLOCK to proceed with switching the IO scheduler.

I wonder if this shouldn't be a for_each_file() loop, and just skipping
file types that aren't FIO_TYPE_BLOCK, moving the actual switching into
a helper?

-- 
Jens Axboe



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] backend: fix switch_ioscheduler()
  2021-04-14 14:23 ` Jens Axboe
@ 2021-04-14 22:16   ` Damien Le Moal
  0 siblings, 0 replies; 3+ messages in thread
From: Damien Le Moal @ 2021-04-14 22:16 UTC (permalink / raw)
  To: Jens Axboe, fio

On 2021/04/14 23:23, Jens Axboe wrote:
> On 4/14/21 5:10 AM, Damien Le Moal wrote:
>> If the first file specified for a job is not a block device file, the
>> ioscheduler option cannot be used. Trying to use this option can cause a
>> crash as that file du (struct disk_util) field is NULL. Prevent such
>> crash and signal the error by testing the file type, allowing only files
>> with the type FIO_TYPE_BLOCK to proceed with switching the IO scheduler.
> 
> I wonder if this shouldn't be a for_each_file() loop, and just skipping
> file types that aren't FIO_TYPE_BLOCK, moving the actual switching into
> a helper?
> 

Indeed, that would be more correct. Will send a v2.

-- 
Damien Le Moal
Western Digital Research


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-04-14 22:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-14 11:10 [PATCH] backend: fix switch_ioscheduler() Damien Le Moal
2021-04-14 14:23 ` Jens Axboe
2021-04-14 22:16   ` Damien Le Moal

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.