-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an option to open with O_EXCL #1820
Comments
This addresses axboe#1820.
Fio already checks if the device is mounted, and will fail a write workload unless |
This addresses axboe#1820. Signed-off-by: Keith Reynolds <[email protected]>
I just clobbered a device by running fio on the base device (/dev/nvme1n1) while some partitions were mounted (the system was rebooted and linux shuffled the block device numbers; before the reboot nvme0 was the root disk and nvme1 was my test disk; I didn't notice that they had been swapped by the reboot.) Fio's mounted device check didn't catch that, because I gave it /dev/nvme1n1 rather than /dev/nvme1n1p1 as the filename; the mounted check would have worked in the latter case. Opening the base device with O_EXCL would have failed with EBUSY because of the mounted partitions. It's also possible on linux to mount a device in another namespace, which fio's device_is_mounted() check won't catch, but O_EXCL will. O_EXCL won't catch every possible conflict, as you point out, but it will catch several that the current check won't. |
That's a good point. I guess we could just augment the writeable open check with setting O_EXCL as well. That should provide more coverage, would've caught your case. |
I have a fork in which I'm working on fixing this; what I've got currently is a |
I don't like adding yet another option for this, since we already have one and it defaults to disallowing it. So I'd say if |
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]>
On linux, it can be difficult to determine if a drive is in use by other parts of the system, since it can be mounted in a non-default namespace or directly opened by an application. (This page describes some of the many ways a drive can be in use that can be difficult to find.) However, opening a block device with the
O_EXCL
flag causes the kernel to returnEBUSY
if the drive is in use.From open(2):
In general, the behavior of O_EXCL is undefined if it is used without O_CREAT. There is one exception: on Linux 2.6 and later, O_EXCL can be used without O_CREAT if pathname refers to a block device. If the block device is in use by the system (e.g., mounted), open() fails with the error EBUSY.
There should be an option to tell fio to use this flag, similar to the
direct
option.The text was updated successfully, but these errors were encountered: