bdev/ocssd: Extract common operation from from_disk_lba() and lba_in_range()

Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: Ifd6b2b76c80d7b12bffdff6f9684b6c8dc3e3ed5
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/5131
Community-CI: Broadcom CI
Community-CI: Mellanox Build Bot
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Shuhei Matsumoto 2020-11-16 18:45:40 +09:00 committed by Tomasz Zawadzki
parent ddc03b4584
commit 74438fc588

View File

@ -277,6 +277,19 @@ bdev_ocssd_translate_lba(struct ocssd_bdev *ocssd_bdev, uint64_t lba, uint64_t *
*chk = (lba / addr_shift) % geo->num_chk;
}
static uint64_t
bdev_ocssd_to_parallel_unit(const struct spdk_ocssd_geometry_data *geometry,
const struct bdev_ocssd_lba_offsets *offsets,
uint64_t lba)
{
uint64_t pu, grp;
pu = (lba >> offsets->pu) & ((1 << geometry->lbaf.pu_len) - 1);
grp = (lba >> offsets->grp) & ((1 << geometry->lbaf.grp_len) - 1);
return grp * geometry->num_pu + pu;
}
static uint64_t
bdev_ocssd_from_disk_lba(struct ocssd_bdev *ocssd_bdev, uint64_t lba)
{
@ -284,14 +297,13 @@ bdev_ocssd_from_disk_lba(struct ocssd_bdev *ocssd_bdev, uint64_t lba)
const struct spdk_ocssd_geometry_data *geometry = &ocssd_ns->geometry;
const struct bdev_ocssd_lba_offsets *offsets = &ocssd_ns->lba_offsets;
const struct bdev_ocssd_range *range = &ocssd_bdev->range;
uint64_t lbk, chk, pu, grp, punit;
uint64_t lbk, chk, punit;
lbk = (lba >> offsets->lbk) & ((1 << geometry->lbaf.lbk_len) - 1);
chk = (lba >> offsets->chk) & ((1 << geometry->lbaf.chk_len) - 1);
pu = (lba >> offsets->pu) & ((1 << geometry->lbaf.pu_len) - 1);
grp = (lba >> offsets->grp) & ((1 << geometry->lbaf.grp_len) - 1);
punit = grp * geometry->num_pu + pu - range->begin;
punit = bdev_ocssd_to_parallel_unit(geometry, offsets, lba);
punit -= range->begin;
return lbk + punit * geometry->clba + chk * geometry->clba *
ocssd_range_num_parallel_units(range);
@ -319,11 +331,9 @@ bdev_ocssd_lba_in_range(struct ocssd_bdev *ocssd_bdev, uint64_t lba)
const struct spdk_ocssd_geometry_data *geometry = &ocssd_ns->geometry;
const struct bdev_ocssd_lba_offsets *offsets = &ocssd_ns->lba_offsets;
const struct bdev_ocssd_range *range = &ocssd_bdev->range;
uint64_t pu, grp, punit;
uint64_t punit;
pu = (lba >> offsets->pu) & ((1 << geometry->lbaf.pu_len) - 1);
grp = (lba >> offsets->grp) & ((1 << geometry->lbaf.grp_len) - 1);
punit = grp * geometry->num_pu + pu;
punit = bdev_ocssd_to_parallel_unit(geometry, offsets, lba);
return punit >= range->begin && punit <= range->end;
}