mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-04-03 08:46:32 -04:00
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>
This commit is contained in:
committed by
Jens Axboe
parent
c1d7c0f9cd
commit
261b67f4e3
@@ -49,12 +49,13 @@ TEST_PROGS += test_stress_05.sh
|
|||||||
TEST_PROGS += test_stress_06.sh
|
TEST_PROGS += test_stress_06.sh
|
||||||
TEST_PROGS += test_stress_07.sh
|
TEST_PROGS += test_stress_07.sh
|
||||||
|
|
||||||
TEST_GEN_PROGS_EXTENDED = kublk
|
TEST_GEN_PROGS_EXTENDED = kublk metadata_size
|
||||||
|
STANDALONE_UTILS := metadata_size.c
|
||||||
|
|
||||||
LOCAL_HDRS += $(wildcard *.h)
|
LOCAL_HDRS += $(wildcard *.h)
|
||||||
include ../lib.mk
|
include ../lib.mk
|
||||||
|
|
||||||
$(TEST_GEN_PROGS_EXTENDED): $(wildcard *.c)
|
$(OUTPUT)/kublk: $(filter-out $(STANDALONE_UTILS),$(wildcard *.c))
|
||||||
|
|
||||||
check:
|
check:
|
||||||
shellcheck -x -f gcc *.sh
|
shellcheck -x -f gcc *.sh
|
||||||
|
|||||||
36
tools/testing/selftests/ublk/metadata_size.c
Normal file
36
tools/testing/selftests/ublk/metadata_size.c
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-2.0
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <linux/fs.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
struct logical_block_metadata_cap cap = {};
|
||||||
|
const char *filename;
|
||||||
|
int fd;
|
||||||
|
int result;
|
||||||
|
|
||||||
|
if (argc != 2) {
|
||||||
|
fprintf(stderr, "Usage: %s BLOCK_DEVICE\n", argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
filename = argv[1];
|
||||||
|
fd = open(filename, O_RDONLY);
|
||||||
|
if (fd < 0) {
|
||||||
|
perror(filename);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
result = ioctl(fd, FS_IOC_GETLBMD_CAP, &cap);
|
||||||
|
if (result < 0) {
|
||||||
|
perror("ioctl");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("metadata_size: %u\n", cap.lbmd_size);
|
||||||
|
printf("pi_offset: %u\n", cap.lbmd_pi_offset);
|
||||||
|
printf("pi_tuple_size: %u\n", cap.lbmd_pi_size);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user