Commit 9e843fdb authored by Evgeniy Kochetov's avatar Evgeniy Kochetov Committed by Tomasz Zawadzki
Browse files

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: default avatarEvgeniy Kochetov <evgeniik@nvidia.com>
Change-Id: I89c2d03d1982d66b9137a3a3653a98c361984fab
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/14528


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <smatsumoto@nvidia.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@nvidia.com>
parent 1c57fa1a
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -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 */
};
+1 −1
Original line number Diff line number Diff line
@@ -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
+19 −0
Original line number Diff line number Diff line
@@ -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;
+7 −0
Original line number Diff line number Diff line
@@ -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 *
+1 −1
Original line number Diff line number Diff line
@@ -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
Loading