nvmet: add lba to sect conversion helpers

In this preparation patch, we add helpers to convert lbas to sectors &
sectors to lba. This is needed to eliminate code duplication in the ZBD
backend.

Use these helpers in the block device backend.

Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Reviewed-by: Damien Le Moal <damien.lemoal@wdc.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
This commit is contained in:
Chaitanya Kulkarni 2021-01-11 20:26:16 -08:00 committed by Christoph Hellwig
parent 3c7b224f19
commit 193fcf371f
2 changed files with 13 additions and 5 deletions

View File

@ -256,8 +256,7 @@ static void nvmet_bdev_execute_rw(struct nvmet_req *req)
if (is_pci_p2pdma_page(sg_page(req->sg))) if (is_pci_p2pdma_page(sg_page(req->sg)))
op |= REQ_NOMERGE; op |= REQ_NOMERGE;
sector = le64_to_cpu(req->cmd->rw.slba); sector = nvmet_lba_to_sect(req->ns, req->cmd->rw.slba);
sector <<= (req->ns->blksize_shift - 9);
if (req->transfer_len <= NVMET_MAX_INLINE_DATA_LEN) { if (req->transfer_len <= NVMET_MAX_INLINE_DATA_LEN) {
bio = &req->b.inline_bio; bio = &req->b.inline_bio;
@ -345,7 +344,7 @@ static u16 nvmet_bdev_discard_range(struct nvmet_req *req,
int ret; int ret;
ret = __blkdev_issue_discard(ns->bdev, ret = __blkdev_issue_discard(ns->bdev,
le64_to_cpu(range->slba) << (ns->blksize_shift - 9), nvmet_lba_to_sect(ns, range->slba),
le32_to_cpu(range->nlb) << (ns->blksize_shift - 9), le32_to_cpu(range->nlb) << (ns->blksize_shift - 9),
GFP_KERNEL, 0, bio); GFP_KERNEL, 0, bio);
if (ret && ret != -EOPNOTSUPP) { if (ret && ret != -EOPNOTSUPP) {
@ -414,8 +413,7 @@ static void nvmet_bdev_execute_write_zeroes(struct nvmet_req *req)
if (!nvmet_check_transfer_len(req, 0)) if (!nvmet_check_transfer_len(req, 0))
return; return;
sector = le64_to_cpu(write_zeroes->slba) << sector = nvmet_lba_to_sect(req->ns, write_zeroes->slba);
(req->ns->blksize_shift - 9);
nr_sector = (((sector_t)le16_to_cpu(write_zeroes->length) + 1) << nr_sector = (((sector_t)le16_to_cpu(write_zeroes->length) + 1) <<
(req->ns->blksize_shift - 9)); (req->ns->blksize_shift - 9));

View File

@ -603,4 +603,14 @@ static inline bool nvmet_ns_has_pi(struct nvmet_ns *ns)
return ns->pi_type && ns->metadata_size == sizeof(struct t10_pi_tuple); return ns->pi_type && ns->metadata_size == sizeof(struct t10_pi_tuple);
} }
static inline __le64 nvmet_sect_to_lba(struct nvmet_ns *ns, sector_t sect)
{
return cpu_to_le64(sect >> (ns->blksize_shift - SECTOR_SHIFT));
}
static inline sector_t nvmet_lba_to_sect(struct nvmet_ns *ns, __le64 lba)
{
return le64_to_cpu(lba) << (ns->blksize_shift - SECTOR_SHIFT);
}
#endif /* _NVMET_H */ #endif /* _NVMET_H */