Skip to contentSkip to conversation

fstests: add a test case for btrfs get_subvol_info ioctl

PATCH In review Qu Wenruo 2 participants 2 messages Jun 18 – Jun 19 Btrfs file system

lore
Share & tools
lore

Qu Wenruo

author
#0 lore raw

PATCH v2 1/1 fstests: add a test case for btrfs get_subvol_info ioctl

There is a regression caused by upstream kernel commit 538e5bdbc899 ("btrfs: add 32-bit compat ioctl for BTRFS_IOC_GET_SUBVOL_INFO"), where the unprivileged get_subvol_info ioctl is returning incorrect results.

Unfortunately that bug is not covered by fstests, and only exposed by btrfs-progs libbtrfsutil python tests, which is not a short run.

So add a new test case for such btrfs ioctl:

- Introduce a helper program, btrfs_ioctl
Which will call the dedicated ioctl, print all of its structure members.

For now only get_subvol_info is supported, but it can be easily appended for new ones.

- Mkfs and create a subvolume on btrfs

- Use "_btrfs_get_subvolid()" to grab the subvolid
That function is utilizing "btrfs subvolume list" to grab the info, which is not utilizing the unprivileged ioctl.

- Use "btrfs_ioctl get_subvol_info" to grab the subvolid

- Compare the two subvolids

This should be enough to detect the regression.

---
Changelog:
v2:
- Fix an incorrect bracket for timestamp output
It's only a style problem, all the call sites are passing a subvol_info structure directly, so it doesn't cause any problem.

- Fix the incorrect uuid output

- Fix the return value when not enough args are provided

- Add a missing newline for the message of open() failure

---
 .gitignore          |   1 +
 src/Makefile        |   2 +-
 src/btrfs_ioctl.c   | 104 ++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/351     |  47 ++++++++++++++++++++
 tests/btrfs/351.out |   2 +
 5 files changed, 155 insertions(+), 1 deletion(-)
 create mode 100644 src/btrfs_ioctl.c
 create mode 100755 tests/btrfs/351
 create mode 100644 tests/btrfs/351.out
.gitignore +1 -0
index dd77ee30..0b6b9452 100644
@@ -215,6 +215,7 @@ tags
 /src/file_attr
 /src/truncate
 /src/t_btrfs_received_uuid_ioctl
+/src/btrfs_ioctl
 
 # Symlinked files
 /tests/generic/035.out
src/Makefile +1 -1
index 31ac43b2..76cf50c3 100644
@@ -36,7 +36,7 @@ LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize preallo_rw_pattern_reader \
 	fscrypt-crypt-util bulkstat_null_ocount splice-test chprojid_fail \
 	detached_mounts_propagation ext4_resize t_readdir_3 splice2pipe \
 	uuid_ioctl t_snapshot_deleted_subvolume fiemap-fault min_dio_alignment \
-	rw_hint fs-monitor
+	rw_hint fs-monitor btrfs_ioctl
 
 EXTRA_EXECS = dmerror fill2attr fill2fs fill2fs_check scaleread.sh \
 	      btrfs_crc32c_forged_name.py popdir.pl popattr.py \
src/btrfs_ioctl.c new file +104 -0

104 lines not on this page · raw message

tests/btrfs/351 new file +47 -0

47 lines not on this page · raw message

tests/btrfs/351.out new file +2 -0
new file mode 100644
index 00000000..49b14639
@@ -0,0 +1,2 @@
+QA output created by 351
+Silence is golden
Signature · 1 line
2.51.2
Reviewed-by on v2 1/1
#1 lore raw
Quoted 11 lines

v2:
- Fix an incorrect bracket for timestamp output
It's only a style problem, all the call sites are passing a subvol_info structure directly, so it doesn't cause any problem.

- Fix the incorrect uuid output

- Fix the return value when not enough args are provided

- Add a missing newline for the message of open() failure

LGTM.