Skip to content

Commit 78ae466

Browse files
calebsanderkawasaki
authored andcommitted
t10-pi: reduce ref tag code duplication
t10_pi_ref_tag() and ext_pi_ref_tag() are identical except for the final truncation of the ref tag to 32 or 48 bits. Factor out a helper full_pi_ref_tag() to return the untruncated ref tag and use it in t10_pi_ref_tag() and ext_pi_ref_tag(). Signed-off-by: Caleb Sander Mateos <[email protected]> Reviewed-by: Anuj Gupta <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]>
1 parent 59ca59b commit 78ae466

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

include/linux/t10-pi.h

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <linux/types.h>
66
#include <linux/blk-mq.h>
7+
#include <linux/wordpart.h>
78

89
/*
910
* A T10 PI-capable target device can be formatted with different
@@ -25,6 +26,16 @@ enum t10_dif_type {
2526
T10_PI_TYPE3_PROTECTION = 0x3,
2627
};
2728

29+
static inline u64 full_pi_ref_tag(const struct request *rq)
30+
{
31+
unsigned int shift = ilog2(queue_logical_block_size(rq->q));
32+
33+
if (IS_ENABLED(CONFIG_BLK_DEV_INTEGRITY) &&
34+
rq->q->limits.integrity.interval_exp)
35+
shift = rq->q->limits.integrity.interval_exp;
36+
return blk_rq_pos(rq) >> (shift - SECTOR_SHIFT);
37+
}
38+
2839
/*
2940
* T10 Protection Information tuple.
3041
*/
@@ -39,12 +50,7 @@ struct t10_pi_tuple {
3950

4051
static inline u32 t10_pi_ref_tag(struct request *rq)
4152
{
42-
unsigned int shift = ilog2(queue_logical_block_size(rq->q));
43-
44-
if (IS_ENABLED(CONFIG_BLK_DEV_INTEGRITY) &&
45-
rq->q->limits.integrity.interval_exp)
46-
shift = rq->q->limits.integrity.interval_exp;
47-
return blk_rq_pos(rq) >> (shift - SECTOR_SHIFT) & 0xffffffff;
53+
return lower_32_bits(full_pi_ref_tag(rq));
4854
}
4955

5056
struct crc64_pi_tuple {
@@ -64,12 +70,7 @@ static inline u64 lower_48_bits(u64 n)
6470

6571
static inline u64 ext_pi_ref_tag(struct request *rq)
6672
{
67-
unsigned int shift = ilog2(queue_logical_block_size(rq->q));
68-
69-
if (IS_ENABLED(CONFIG_BLK_DEV_INTEGRITY) &&
70-
rq->q->limits.integrity.interval_exp)
71-
shift = rq->q->limits.integrity.interval_exp;
72-
return lower_48_bits(blk_rq_pos(rq) >> (shift - SECTOR_SHIFT));
73+
return lower_48_bits(full_pi_ref_tag(rq));
7374
}
7475

7576
#endif

0 commit comments

Comments
 (0)