Skip to content

Conversation

@keithr-mext
Copy link

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: #1820
Signed-of-by: Keith Reynolds [email protected]

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: axboe#1820
Signed-of-by: Keith Reynolds <[email protected]>
@keithr-mext
Copy link
Author

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.

@sitsofe
Copy link
Collaborator

sitsofe commented Aug 23, 2025

@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:

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 sitsofe added the needreporterinfo Waiting on information from the issue reporter label Aug 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needreporterinfo Waiting on information from the issue reporter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add an option to open with O_EXCL

2 participants