blob: Add translate_lba operation
New `translate_lba` operation allows to translate blob lba to lba on the underlying bdev. It recurses down the whole chain of bs_dev's. The operation may fail to do the translation when blob lba is not backed by the real bdev. For example, when we eventually hit zeroes device in the chain. This operation is used in the next commit to get source LBA for copy operation. Signed-off-by: Evgeniy Kochetov <evgeniik@nvidia.com> Change-Id: I89c2d03d1982d66b9137a3a3653a98c361984fab Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/14528 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Shuhei Matsumoto <smatsumoto@nvidia.com> Reviewed-by: Aleksey Marchuk <alexeymar@nvidia.com>
This commit is contained in:
parent
1c57fa1a95
commit
9e843fdbd1
@ -197,6 +197,15 @@ struct spdk_bs_dev {
|
||||
|
||||
bool (*is_zeroes)(struct spdk_bs_dev *dev, uint64_t lba, uint64_t lba_count);
|
||||
|
||||
/* Translate blob lba to lba on the underlying bdev.
|
||||
* This operation recurses down the whole chain of bs_dev's.
|
||||
* Returns true and initializes value of base_lba on success.
|
||||
* Returns false on failure.
|
||||
* The function may fail when blob lba is not backed by the bdev lba.
|
||||
* For example, when we eventually hit zeroes device in the chain.
|
||||
*/
|
||||
bool (*translate_lba)(struct spdk_bs_dev *dev, uint64_t lba, uint64_t *base_lba);
|
||||
|
||||
uint64_t blockcnt;
|
||||
uint32_t blocklen; /* In bytes */
|
||||
};
|
||||
|
@ -6,7 +6,7 @@
|
||||
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..)
|
||||
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
|
||||
|
||||
SO_VER := 8
|
||||
SO_VER := 9
|
||||
SO_MINOR := 0
|
||||
|
||||
C_SRCS = blobstore.c request.c zeroes.c blob_bs_dev.c
|
||||
|
@ -136,6 +136,24 @@ blob_bs_is_zeroes(struct spdk_bs_dev *dev, uint64_t lba, uint64_t lba_count)
|
||||
bs_io_unit_to_back_dev_lba(blob, lba_count));
|
||||
}
|
||||
|
||||
static bool
|
||||
blob_bs_translate_lba(struct spdk_bs_dev *dev, uint64_t lba, uint64_t *base_lba)
|
||||
{
|
||||
struct spdk_blob_bs_dev *b = (struct spdk_blob_bs_dev *)dev;
|
||||
struct spdk_blob *blob = b->blob;
|
||||
|
||||
assert(base_lba != NULL);
|
||||
if (bs_io_unit_is_allocated(blob, lba)) {
|
||||
*base_lba = bs_blob_io_unit_to_lba(blob, lba);
|
||||
return true;
|
||||
}
|
||||
|
||||
assert(blob->back_bs_dev != NULL);
|
||||
return blob->back_bs_dev->translate_lba(blob->back_bs_dev,
|
||||
bs_io_unit_to_back_dev_lba(blob, lba),
|
||||
base_lba);
|
||||
}
|
||||
|
||||
struct spdk_bs_dev *
|
||||
bs_create_blob_bs_dev(struct spdk_blob *blob)
|
||||
{
|
||||
@ -161,6 +179,7 @@ bs_create_blob_bs_dev(struct spdk_blob *blob)
|
||||
b->bs_dev.write_zeroes = blob_bs_dev_write_zeroes;
|
||||
b->bs_dev.unmap = blob_bs_dev_unmap;
|
||||
b->bs_dev.is_zeroes = blob_bs_is_zeroes;
|
||||
b->bs_dev.translate_lba = blob_bs_translate_lba;
|
||||
b->blob = blob;
|
||||
|
||||
return &b->bs_dev;
|
||||
|
@ -124,6 +124,12 @@ zeroes_is_zeroes(struct spdk_bs_dev *dev, uint64_t lba, uint64_t lba_count)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
zeroes_translate_lba(struct spdk_bs_dev *dev, uint64_t lba, uint64_t *base_lba)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
static struct spdk_bs_dev g_zeroes_bs_dev = {
|
||||
.blockcnt = UINT64_MAX,
|
||||
.blocklen = 512,
|
||||
@ -139,6 +145,7 @@ static struct spdk_bs_dev g_zeroes_bs_dev = {
|
||||
.write_zeroes = zeroes_write_zeroes,
|
||||
.unmap = zeroes_unmap,
|
||||
.is_zeroes = zeroes_is_zeroes,
|
||||
.translate_lba = zeroes_translate_lba,
|
||||
};
|
||||
|
||||
struct spdk_bs_dev *
|
||||
|
@ -6,7 +6,7 @@
|
||||
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..)
|
||||
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
|
||||
|
||||
SO_VER := 7
|
||||
SO_VER := 8
|
||||
SO_MINOR := 0
|
||||
|
||||
C_SRCS = blobfs.c tree.c
|
||||
|
@ -6,7 +6,7 @@
|
||||
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..)
|
||||
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
|
||||
|
||||
SO_VER := 7
|
||||
SO_VER := 8
|
||||
SO_MINOR := 0
|
||||
|
||||
C_SRCS = lvol.c
|
||||
|
@ -6,7 +6,7 @@
|
||||
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../..)
|
||||
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
|
||||
|
||||
SO_VER := 8
|
||||
SO_VER := 9
|
||||
SO_MINOR := 0
|
||||
|
||||
C_SRCS = blob_bdev.c
|
||||
|
@ -360,6 +360,13 @@ bdev_blob_is_zeroes(struct spdk_bs_dev *dev, uint64_t lba, uint64_t lba_count)
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool
|
||||
bdev_blob_translate_lba(struct spdk_bs_dev *dev, uint64_t lba, uint64_t *base_lba)
|
||||
{
|
||||
*base_lba = lba;
|
||||
return true;
|
||||
}
|
||||
|
||||
static void
|
||||
blob_bdev_init(struct blob_bdev *b, struct spdk_bdev_desc *desc)
|
||||
{
|
||||
@ -385,6 +392,7 @@ blob_bdev_init(struct blob_bdev *b, struct spdk_bdev_desc *desc)
|
||||
b->bs_dev.unmap = bdev_blob_unmap;
|
||||
b->bs_dev.get_base_bdev = bdev_blob_get_base_bdev;
|
||||
b->bs_dev.is_zeroes = bdev_blob_is_zeroes;
|
||||
b->bs_dev.translate_lba = bdev_blob_translate_lba;
|
||||
}
|
||||
|
||||
int
|
||||
|
Loading…
Reference in New Issue
Block a user