Skip to content

Commit

Permalink
feat(snapshot): get lba from snapshot which is ancestor of current blob
Browse files Browse the repository at this point in the history
Signed-off-by: Hrudaya <[email protected]>
  • Loading branch information
hrudaya21 committed Dec 21, 2023
1 parent 226fad7 commit be46585
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
46 changes: 43 additions & 3 deletions lib/blob/blobstore.c
Original file line number Diff line number Diff line change
Expand Up @@ -2777,6 +2777,42 @@ blob_calculate_lba_and_lba_count(struct spdk_blob *blob, uint64_t io_unit, uint6
}
}

static inline bool
blob_ancestor_calc_lba_and_lba_count(struct spdk_blob *blob, uint64_t io_unit, uint64_t length,
uint64_t *lba, uint64_t *lba_count)
{
struct spdk_blob *orig_blob = blob;
*lba_count = length;
if (!bs_io_unit_is_allocated(orig_blob, io_unit)) {
if (orig_blob->parent_id == SPDK_BLOBID_INVALID) {
goto error;
} else {
while (blob->parent_id != SPDK_BLOBID_INVALID) {
spdk_blob_id blob_id = blob->parent_id;
blob = blob_lookup(blob->bs, blob_id);
if (blob == NULL) {
return false;
} else {
if (!bs_io_unit_is_allocated(blob, io_unit)) {
continue;
}
*lba = bs_blob_io_unit_to_lba(blob, io_unit);
return true;
}
}
goto error;
}
} else {
*lba = bs_blob_io_unit_to_lba(blob, io_unit);
return true;
}
error:
assert(orig_blob->back_bs_dev != NULL);
*lba = bs_io_unit_to_back_dev_lba(orig_blob, io_unit);
*lba_count = bs_io_unit_to_back_dev_lba(orig_blob, *lba_count);
return false;
}

struct op_split_ctx {
struct spdk_blob *blob;
struct spdk_io_channel *channel;
Expand Down Expand Up @@ -3239,13 +3275,17 @@ blob_request_submit_rw_iov(struct spdk_blob *blob, struct spdk_io_channel *_chan

return;
}

is_allocated = blob_calculate_lba_and_lba_count(blob, offset, length, &lba, &lba_count);
if (read & ((ext_io_flags & FLAG_READ_ALLOCATED) == FLAG_READ_ALLOCATED)) {
is_allocated = blob_ancestor_calc_lba_and_lba_count(blob, offset, length, &lba, &lba_count);
} else {
is_allocated = blob_calculate_lba_and_lba_count(blob, offset, length, &lba, &lba_count);
}

if (read) {
spdk_bs_sequence_t *seq;

if (ext_io_flags & SPDK_NVME_IO_FLAGS_UNWRITTEN_READ_FAIL) {
if (((ext_io_flags & FLAG_READ_ALLOCATED) == FLAG_READ_ALLOCATED) &
SPDK_NVME_IO_FLAGS_UNWRITTEN_READ_FAIL) {
if (!is_allocated) {
/* ETXTBSY was chosen to indicate read of unwritten block.
* It is not used by SPDK, so it should be fine. */
Expand Down
4 changes: 4 additions & 0 deletions lib/blob/blobstore.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@ enum spdk_blob_op_type {
SPDK_BLOB_READV,
};

/** ext io flag type */
enum spdk_blob_ext_io_type {
FLAG_READ_ALLOCATED = 1,
};
/* back bs_dev */

#define BLOB_SNAPSHOT "SNAP"
Expand Down

0 comments on commit be46585

Please sign in to comment.