diff --git a/lib/blob/blobstore.c b/lib/blob/blobstore.c index c9ba811c4..b172dcfda 100644 --- a/lib/blob/blobstore.c +++ b/lib/blob/blobstore.c @@ -1557,6 +1557,8 @@ _spdk_blob_resize(struct spdk_blob *blob, uint64_t sz) uint64_t lfc; /* lowest free cluster */ uint32_t lfmd; /* lowest free md page */ uint64_t num_clusters; + uint32_t *ep_tmp; + uint64_t new_num_ep = 0, current_num_ep = 0; struct spdk_blob_store *bs; bs = blob->bs; @@ -1578,6 +1580,13 @@ _spdk_blob_resize(struct spdk_blob *blob, uint64_t sz) num_clusters = blob->active.num_clusters; } + if (blob->use_extent_table) { + /* Round up since every cluster beyond current Extent Table size, + * requires new extent page. */ + new_num_ep = spdk_divide_round_up(sz, SPDK_EXTENTS_PER_EP); + current_num_ep = spdk_divide_round_up(num_clusters, SPDK_EXTENTS_PER_EP); + } + /* Do two passes - one to verify that we can obtain enough clusters * and md pages, another to actually claim them. */ @@ -1608,7 +1617,17 @@ _spdk_blob_resize(struct spdk_blob *blob, uint64_t sz) blob->active.clusters = tmp; blob->active.cluster_array_size = sz; - /* TODO: Expand the extents table, only if enough clusters were added */ + /* Expand the extents table, only if enough clusters were added */ + if (new_num_ep > current_num_ep && blob->use_extent_table) { + ep_tmp = realloc(blob->active.extent_pages, sizeof(*blob->active.extent_pages) * new_num_ep); + if (new_num_ep > 0 && ep_tmp == NULL) { + return -ENOMEM; + } + memset(ep_tmp + blob->active.extent_pages_array_size, 0, + sizeof(*blob->active.extent_pages) * (new_num_ep - blob->active.extent_pages_array_size)); + blob->active.extent_pages = ep_tmp; + blob->active.extent_pages_array_size = new_num_ep; + } } blob->state = SPDK_BLOB_STATE_DIRTY; @@ -1624,6 +1643,7 @@ _spdk_blob_resize(struct spdk_blob *blob, uint64_t sz) } blob->active.num_clusters = sz; + blob->active.num_extent_pages = new_num_ep; return 0; } diff --git a/lib/blob/blobstore.h b/lib/blob/blobstore.h index 57b451699..dc738e454 100644 --- a/lib/blob/blobstore.h +++ b/lib/blob/blobstore.h @@ -372,6 +372,10 @@ SPDK_STATIC_ASSERT(SPDK_BS_PAGE_SIZE == sizeof(struct spdk_blob_md_page), "Inval #define SPDK_BS_MAX_DESC_SIZE sizeof(((struct spdk_blob_md_page*)0)->descriptors) +/* TODO: Set to low amount for purpose of testing */ +/* Maximum number of LBA's a single Extent Page can fit */ +#define SPDK_EXTENTS_PER_EP 100 + #define SPDK_BS_SUPER_BLOCK_SIG "SPDKBLOB" struct spdk_bs_super_block {