Skip to content

Commit 2ad65c9

Browse files
Anuj Guptakawasaki
authored andcommitted
fs: add ioctl to query protection info capabilities
Add a new ioctl, FS_IOC_GETPICAP, to query protection info (PI) capabilities. This ioctl returns information about the files integrity profile. This is useful for userspace applications to understand a files end-to-end data protection support and configure the I/O accordingly. For now this interface is only supported by block devices. However the design and placement of this ioctl in generic FS ioctl space allows us to extend it to work over files as well. This maybe useful when filesystems start supporting PI-aware layouts. A new structure struct fs_pi_cap is introduced, which contains the following fields: 1. fpc_flags: bitmask of capability flags. 2. fpc_interval: the data block interval (in bytes) for which the protection information is generated. 3. fpc_csum type: type of checksum used. 4. fpc_metadata_size: size (in bytes) of the metadata associated with each interval. 5. fpc_pi_size: size (in bytes) of the PI associated with each interval. 6. fpc_tag_size: size (in bytes) of tag information. 7. pi_offset: offset of protection information tuple within the metadata. 8. fpc_ref_tag_size: size in bytes of the reference tag. 9. fpc_storage_tag_size: size in bytes of the storage tag. 10. fpc_rsvd: reserved for future use. The internal logic to fetch the capability is encapsulated in a helper function blk_get_pi_cap(), which uses the blk_integrity profile associated with the device. The ioctl returns -EOPNOTSUPP, if CONFIG_BLK_DEV_INTEGRITY is not enabled. Signed-off-by: Anuj Gupta <[email protected]> Signed-off-by: Kanchan Joshi <[email protected]>
1 parent 76c7c44 commit 2ad65c9

4 files changed

Lines changed: 88 additions & 0 deletions

File tree

block/blk-integrity.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/scatterlist.h>
1414
#include <linux/export.h>
1515
#include <linux/slab.h>
16+
#include <linux/t10-pi.h>
1617

1718
#include "blk.h"
1819

@@ -54,6 +55,46 @@ int blk_rq_count_integrity_sg(struct request_queue *q, struct bio *bio)
5455
return segments;
5556
}
5657

58+
int blk_get_pi_cap(struct block_device *bdev, struct fs_pi_cap __user *argp)
59+
{
60+
struct blk_integrity *bi = blk_get_integrity(bdev->bd_disk);
61+
struct fs_pi_cap pi_cap = {};
62+
63+
if (!bi)
64+
goto out;
65+
66+
if (bi->flags & BLK_INTEGRITY_DEVICE_CAPABLE)
67+
pi_cap.fpc_flags |= FILE_PI_CAP_INTEGRITY;
68+
if (bi->flags & BLK_INTEGRITY_REF_TAG)
69+
pi_cap.fpc_flags |= FILE_PI_CAP_REFTAG;
70+
pi_cap.fpc_csum_type = bi->csum_type;
71+
pi_cap.fpc_metadata_size = bi->tuple_size;
72+
pi_cap.fpc_tag_size = bi->tag_size;
73+
pi_cap.fpc_interval = 1 << bi->interval_exp;
74+
pi_cap.fpc_pi_offset = bi->pi_offset;
75+
pi_cap.fpc_pi_size = bi->pi_size;
76+
if (bi->flags & BLK_INTEGRITY_REF_TAG) {
77+
switch (bi->csum_type) {
78+
case BLK_INTEGRITY_CSUM_CRC64:
79+
pi_cap.fpc_ref_tag_size =
80+
sizeof_field(struct crc64_pi_tuple, ref_tag);
81+
break;
82+
case BLK_INTEGRITY_CSUM_CRC:
83+
case BLK_INTEGRITY_CSUM_IP:
84+
pi_cap.fpc_ref_tag_size =
85+
sizeof_field(struct t10_pi_tuple, ref_tag);
86+
break;
87+
default:
88+
break;
89+
}
90+
}
91+
92+
out:
93+
if (copy_to_user(argp, &pi_cap, sizeof(struct fs_pi_cap)))
94+
return -EFAULT;
95+
return 0;
96+
}
97+
5798
/**
5899
* blk_rq_map_integrity_sg - Map integrity metadata into a scatterlist
59100
* @rq: request to map

block/ioctl.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/uaccess.h>
1414
#include <linux/pagemap.h>
1515
#include <linux/io_uring/cmd.h>
16+
#include <linux/blk-integrity.h>
1617
#include <uapi/linux/blkdev.h>
1718
#include "blk.h"
1819
#include "blk-crypto-internal.h"
@@ -643,6 +644,8 @@ static int blkdev_common_ioctl(struct block_device *bdev, blk_mode_t mode,
643644
return blkdev_pr_preempt(bdev, mode, argp, true);
644645
case IOC_PR_CLEAR:
645646
return blkdev_pr_clear(bdev, mode, argp);
647+
case FS_IOC_GETPICAP:
648+
return blk_get_pi_cap(bdev, argp);
646649
default:
647650
return -ENOIOCTLCMD;
648651
}

include/linux/blk-integrity.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ int blk_rq_map_integrity_sg(struct request *, struct scatterlist *);
2929
int blk_rq_count_integrity_sg(struct request_queue *, struct bio *);
3030
int blk_rq_integrity_map_user(struct request *rq, void __user *ubuf,
3131
ssize_t bytes);
32+
int blk_get_pi_cap(struct block_device *bdev, struct fs_pi_cap __user *argp);
3233

3334
static inline bool
3435
blk_integrity_queue_supports_integrity(struct request_queue *q)
@@ -92,6 +93,11 @@ static inline struct bio_vec rq_integrity_vec(struct request *rq)
9293
rq->bio->bi_integrity->bip_iter);
9394
}
9495
#else /* CONFIG_BLK_DEV_INTEGRITY */
96+
static inline int blk_get_pi_cap(struct block_device *bdev,
97+
struct fs_pi_cap __user *argp)
98+
{
99+
return -EOPNOTSUPP;
100+
}
95101
static inline int blk_rq_count_integrity_sg(struct request_queue *q,
96102
struct bio *b)
97103
{

include/uapi/linux/fs.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,42 @@ struct fs_sysfs_path {
9191
__u8 name[128];
9292
};
9393

94+
/* Protection info capability flags */
95+
#define FILE_PI_CAP_INTEGRITY (1 << 0)
96+
#define FILE_PI_CAP_REFTAG (1 << 1)
97+
98+
/* Checksum types for Protection Information */
99+
#define FS_PI_CSUM_NONE 0
100+
#define FS_PI_CSUM_IP 1
101+
#define FS_PI_CSUM_CRC16_T10DIF 2
102+
#define FS_PI_CSUM_CRC64_NVME 3
103+
104+
/*
105+
* struct fs_pi_cap - protection information(PI) capability descriptor
106+
* @fpc_flags: Bitmask of capability flags
107+
* @fpc_interval: Number of bytes of data per PI tuple
108+
* @fpc_csum_type: Checksum type
109+
* @fpc_metadata_size: Size in bytes of the metadata associated with each interval
110+
* @fpc_pi_size: Size in bytes of the PI associated with each interval
111+
* @fpc_tag_size: Size of the tag area within the tuple
112+
* @fpc_pi_offset: Offset of protection information tuple within the metadata
113+
* @fpc_ref_tag_size: Size in bytes of the reference tag
114+
* @fpc_storage_tag_size: Size in bytes of the storage tag
115+
* @fpc_rsvd: Reserved for future use
116+
*/
117+
struct fs_pi_cap {
118+
__u32 fpc_flags;
119+
__u16 fpc_interval;
120+
__u8 fpc_csum_type;
121+
__u8 fpc_metadata_size;
122+
__u8 fpc_pi_size;
123+
__u8 fpc_tag_size;
124+
__u8 fpc_pi_offset;
125+
__u8 fpc_ref_tag_size;
126+
__u8 fpc_storage_tag_size;
127+
__u8 fpc_rsvd[19];
128+
};
129+
94130
/* extent-same (dedupe) ioctls; these MUST match the btrfs ioctl definitions */
95131
#define FILE_DEDUPE_RANGE_SAME 0
96132
#define FILE_DEDUPE_RANGE_DIFFERS 1
@@ -247,6 +283,8 @@ struct fsxattr {
247283
* also /sys/kernel/debug/ for filesystems with debugfs exports
248284
*/
249285
#define FS_IOC_GETFSSYSFSPATH _IOR(0x15, 1, struct fs_sysfs_path)
286+
/* Get protection info capability details */
287+
#define FS_IOC_GETPICAP _IOR(0x15, 2, struct fs_pi_cap)
250288

251289
/*
252290
* Inode flags (FS_IOC_GETFLAGS / FS_IOC_SETFLAGS)

0 commit comments

Comments
 (0)