Skip to content

Commit bc5b0c8

Browse files
Anuj Guptabrauner
authored andcommitted
block: fix lbmd_guard_tag_type assignment in FS_IOC_GETLBMD_CAP
The blk_get_meta_cap() implementation directly assigns bi->csum_type to the UAPI field lbmd_guard_tag_type. This is not right as the kernel enum blk_integrity_checksum values are not guaranteed to match the UAPI defined values. Fix this by explicitly mapping internal checksum types to UAPI-defined constants to ensure compatibility and correctness, especially for the devices using CRC64 PI. Fixes: 9eb22f7 ("fs: add ioctl to query metadata and protection info capabilities") Reported-by: Vincent Fu <[email protected]> Signed-off-by: Anuj Gupta <[email protected]> Link: https://lore.kernel.org/[email protected] Reviewed-by: Martin K. Petersen <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Jens Axboe <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent 42b0ef0 commit bc5b0c8

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

block/blk-integrity.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,21 @@ int blk_get_meta_cap(struct block_device *bdev, unsigned int cmd,
8383
if (meta_cap.lbmd_opaque_size && !bi->pi_offset)
8484
meta_cap.lbmd_opaque_offset = bi->pi_tuple_size;
8585

86-
meta_cap.lbmd_guard_tag_type = bi->csum_type;
86+
switch (bi->csum_type) {
87+
case BLK_INTEGRITY_CSUM_NONE:
88+
meta_cap.lbmd_guard_tag_type = LBMD_PI_CSUM_NONE;
89+
break;
90+
case BLK_INTEGRITY_CSUM_IP:
91+
meta_cap.lbmd_guard_tag_type = LBMD_PI_CSUM_IP;
92+
break;
93+
case BLK_INTEGRITY_CSUM_CRC:
94+
meta_cap.lbmd_guard_tag_type = LBMD_PI_CSUM_CRC16_T10DIF;
95+
break;
96+
case BLK_INTEGRITY_CSUM_CRC64:
97+
meta_cap.lbmd_guard_tag_type = LBMD_PI_CSUM_CRC64_NVME;
98+
break;
99+
}
100+
87101
if (bi->csum_type != BLK_INTEGRITY_CSUM_NONE)
88102
meta_cap.lbmd_app_tag_size = 2;
89103

0 commit comments

Comments
 (0)