fio icon indicating copy to clipboard operation
fio copied to clipboard

linux: use O_EXCL when opening a file for write

Open keithr-mext opened this issue 1 year ago • 2 comments

On linux systems, opening a device with O_EXCL will fail with EBUSY if the drive is in use. For example, if a partition is mounted on /dev/nvme1n1p1, the current mounted filesystem check will allow running write workloads on /dev/nvme1n1 even if allow_mounted_write is zero. Opening /dev/nvme1n1 with O_EXCL will fail with EBUSY in that case. Add O_EXCL when opening a file with O_WRONLY or O_RDWR on linux systems.

Fixes: https://github.com/axboe/fio/issues/1820 Signed-of-by: Keith Reynolds [email protected]

keithr-mext avatar Sep 28 '24 03:09 keithr-mext

The changes to xnvme will require a similar change to use O_EXCL in that library; I'm planning to submit one to them. Regardless of that, passing the correct access bits for the type of I/O fio will be doing seems better to me.

keithr-mext avatar Sep 28 '24 07:09 keithr-mext

@keithr-mext I really like the idea of this pull request because I'm sure it would saved people a lot of heartache. A quick of search of the fio bug tracker shows at least the following requests for something like this:

  • https://github.com/axboe/fio/issues/1007
  • https://github.com/axboe/fio/issues/1382

and I'm sure there are many cases where accidents have happened and data destroyed.

However even if this pull request were to be rebased my concern is that jobs like:

fio --name=exclusive_dev  --rw=write --numjobs=2 --filename=/dev/vdz
fio --name=exclusive_file --rw=write --numjobs=2 --filename=/tmp/fio.tmp --size=4k

go on to fail with "Device or resource busy" / "File exists". If you can think of a way round this I'd be all for this being controlled by allow_mounted_write.

@axboe To sidestep the above would you be OK if this were turned into a seperate option even if it wasn't possible to turn it on by default?

sitsofe avatar Aug 23 '25 09:08 sitsofe