Skip to content

backend: warn before write to block devices with recognizable content - #2144

Open
WengRan wants to merge 1 commit into
axboe:masterfrom
WengRan:blkdev-write-safety-check
Open

backend: warn before write to block devices with recognizable content#2144
WengRan wants to merge 1 commit into
axboe:masterfrom
WengRan:blkdev-write-safety-check

Conversation

@WengRan

@WengRan WengRan commented Sep 4, 2026

Copy link
Copy Markdown

backend: warn before write to block devices with recognizable content

fio currently protects against writing to mounted devices, but a job
file pointing at the wrong raw block device silently destroys whatever
lives there: partition tables, unmounted file systems, LVM physical
volumes, LUKS headers, swap areas and RAID members are all overwritten
without warning. A single filename typo can be catastrophic and there
is no way to get the data back.
This PR adds a write safety check for block devices, built on libblkid:

  • Before any file is opened, every block device targeted by a write
    job is probed (read-only, separate fd)
  • If recognizable content is found, fio reports what the device
    contains in human-readable form, e.g.
    fio: /dev/sda contains a GPT partition table, writing may damage it.
  • Interactive runs prompt continue anyway? (y/N) and abort before
    touching any file unless the user confirms.
  • Non-interactive runs (stdin is not a tty, e.g. scripts, CI) only
    warn and continue, so existing automation is unaffected.

Signed-off-by: wengjianing 1528193783@qq.com

fio currently overwrites unmounted block devices without warning,
which can destroy partition tables, filesystems, LVM PVs, or LUKS
headers due to a simple job file typo. The existing mount check
only covers mounted devices, leaving all others unprotected.

Use libblkid to probe target block devices for write jobs before
opening any file. In interactive runs, prompt for confirmation and
abort on rejection; in non-interactive runs, warn and continue to
avoid breaking scripts and CI. The existing allow_mounted_write
option is reused as an escape hatch to skip the check.

Probing is read-only on a separate fd; all error paths fall back to
"nothing detected", ensuring fio never fails or alters devices due
to the check itself. The feature compiles out entirely without
libblkid. Warnings are deduplicated per device across numjobs, and
the periodic status line is suspended during input wait to avoid
clobbering the prompt.

Signed-off-by: wengjianing <1528193783@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant