Skip to content

Commit 261b67f

Browse files
calebsanderaxboe
authored andcommitted
selftests: ublk: add utility to get block device metadata size
Some block device integrity parameters are available in sysfs, but others are only accessible using the FS_IOC_GETLBMD_CAP ioctl. Add a metadata_size utility program to print out the logical block metadata size, PI offset, and PI size within the metadata. Example output: $ metadata_size /dev/ublkb0 metadata_size: 64 pi_offset: 56 pi_tuple_size: 8 Signed-off-by: Caleb Sander Mateos <csander@purestorage.com> Reviewed-by: Ming Lei <ming.lei@redhat.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent c1d7c0f commit 261b67f

2 files changed

Lines changed: 39 additions & 2 deletions

File tree

tools/testing/selftests/ublk/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,13 @@ TEST_PROGS += test_stress_05.sh
4949
TEST_PROGS += test_stress_06.sh
5050
TEST_PROGS += test_stress_07.sh
5151

52-
TEST_GEN_PROGS_EXTENDED = kublk
52+
TEST_GEN_PROGS_EXTENDED = kublk metadata_size
53+
STANDALONE_UTILS := metadata_size.c
5354

5455
LOCAL_HDRS += $(wildcard *.h)
5556
include ../lib.mk
5657

57-
$(TEST_GEN_PROGS_EXTENDED): $(wildcard *.c)
58+
$(OUTPUT)/kublk: $(filter-out $(STANDALONE_UTILS),$(wildcard *.c))
5859

5960
check:
6061
shellcheck -x -f gcc *.sh
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
#include <fcntl.h>
3+
#include <linux/fs.h>
4+
#include <stdio.h>
5+
#include <sys/ioctl.h>
6+
7+
int main(int argc, char **argv)
8+
{
9+
struct logical_block_metadata_cap cap = {};
10+
const char *filename;
11+
int fd;
12+
int result;
13+
14+
if (argc != 2) {
15+
fprintf(stderr, "Usage: %s BLOCK_DEVICE\n", argv[0]);
16+
return 1;
17+
}
18+
19+
filename = argv[1];
20+
fd = open(filename, O_RDONLY);
21+
if (fd < 0) {
22+
perror(filename);
23+
return 1;
24+
}
25+
26+
result = ioctl(fd, FS_IOC_GETLBMD_CAP, &cap);
27+
if (result < 0) {
28+
perror("ioctl");
29+
return 1;
30+
}
31+
32+
printf("metadata_size: %u\n", cap.lbmd_size);
33+
printf("pi_offset: %u\n", cap.lbmd_pi_offset);
34+
printf("pi_tuple_size: %u\n", cap.lbmd_pi_size);
35+
return 0;
36+
}

0 commit comments

Comments
 (0)