lib/Kernel/block_dev.pm

is_block_device

is_block_device(@devices);

Asserts that each device in the list exists as a block device. Dies if any device is not found, allowing the test to fail if a block device is not detected on the SUT.

record_storage_info

record_storage_info();

Records block device layout into the openQA test log as a diagnostic snapshot.

get_block_dev_kernel_name

my $kernel_name = get_block_dev_kernel_name($dev);

Returns the kernel name of a block device, for example nvme0n1 for /dev/disk/by-id/nvme-.... This is the name in /sys/class/block and in kernel messages.

get_block_dev_size

my $bytes = get_block_dev_size($dev);

Returns the size of a block device in bytes.

get_block_dev_pci_device

my $pci = get_block_dev_pci_device($dev);

Returns the sysfs path of the PCI device of a block device, for example /sys/devices/pci0000:00/0000:00:01.0 for an NVMe disk or the SATA controller for a SATA disk. If there are PCI bridges, this is the PCI device closest to the disk. Dies if the block device is not under a PCI device in sysfs, for example a loop or device mapper device.

create_loop_backing_file

create_loop_backing_file($path, $size, %opts);

Creates a loop device backing file with proper Btrfs host handling.

Arguments: $path - Full path to the backing file (e.g., '/opt/xfstests/test_dev') $size - Size specification (e.g., '5G', '1024M') %opts - Optional parameters: timeout => timeout in seconds (default: 300)

This function creates an empty file, applies chattr +C to disable CoW and compression on Btrfs hosts (no-op on other filesystems), then uses fallocate to allocate the requested space.

The chattr +C flag must be set on an empty file before data is written to prevent Btrfs host filesystem issues: - CoW disabled: prevents physical space explosion during overwrites - Compression disabled: ensures full physical space allocation - Safe for all test filesystems (xfs, btrfs, ext4, overlay, nfs)

Returns: nothing (dies on error via assert_script_run)

attach_loop_device

attach_loop_device($backing_file, %opts);

Attaches a loop device to a backing file and returns the loop device path.

Arguments: $backing_file - Path to the backing file %opts - Optional parameters: loop_dev => specific loop device path (e.g., '/dev/loop100') If not provided, uses 'losetup -f' to find next free device timeout => timeout in seconds (default: 300)

Returns: the loop device path (e.g., '/dev/loop0')

create_zoned_nullblk

create_zoned_nullblk(%opts);

Creates a zoned null_blk device via configfs.

Arguments: %opts - Optional parameters: blocksize => block size in bytes (default: 4096) zone_size => zone size in MB (default: 256) zone_nr_conv => number of conventional zones (default: 4) zone_nr_seq => number of sequential zones (default: 16) timeout => timeout in seconds (default: 300)

This function loads the null_blk module with nr_devices=0, finds the first available null_blk device index, creates and configures the zoned device through configfs, enables it, and sets the mq-deadline scheduler.

Returns: the device path (e.g., '/dev/nullb0')

start_block_trace

start_block_trace($dev, $log);
start_block_trace($dev, $log, $mask);

Start a background blktrace on a block device, piped into blkparse, to record the requests reaching the device while a test runs. Use stop_block_trace to end it and count_block_writes to evaluate the result.

Arguments: $dev - Block device to trace (e.g. '/dev/loop0') $log - Path of the blkparse output file to write $mask - Optional blktrace action mask (default: write)

blktrace needs debugfs, so it gets mounted if it is not available yet.

Returns: the blktrace pid

stop_block_trace

stop_block_trace();

Stop the trace started by start_block_trace. blktrace is interrupted rather than killed, so that it closes the pipe and blkparse flushes its output.

count_block_writes

count_block_writes($log);

Count the write requests in a blkparse output file and return the number. The RWBS field of an event holds W followed by optional modifiers like S for sync or M for metadata, the summary lines at the end of the file spell the direction out and are not counted.