Skip to content

Commit

Permalink
blob: factor out mask loading into a function
Browse files Browse the repository at this point in the history
This is duplicated in three places; combine them into a shared helper
function.

Change-Id: I47682da8fa8b13134a6422c6a0e8a4d68f12ee36
Signed-off-by: Daniel Verkamp <[email protected]>
Reviewed-on: https://review.gerrithub.io/416257
Reviewed-by: Jim Harris <[email protected]>
Reviewed-by: Ben Walker <[email protected]>
Tested-by: SPDK Automated Test System <[email protected]>
  • Loading branch information
danielverkamp committed Jun 21, 2018
1 parent a7b25a6 commit f4a0187
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions lib/blob/blobstore.c
Original file line number Diff line number Diff line change
Expand Up @@ -2528,6 +2528,26 @@ _spdk_bs_set_mask(struct spdk_bit_array *array, struct spdk_bs_md_mask *mask)
}
}

static int
_spdk_bs_load_mask(struct spdk_bit_array **array_ptr, struct spdk_bs_md_mask *mask)
{
struct spdk_bit_array *array;
uint32_t i;

if (spdk_bit_array_resize(array_ptr, mask->length) < 0) {
return -ENOMEM;
}

array = *array_ptr;
for (i = 0; i < mask->length; i++) {
if (mask->mask[i / 8] & (1U << (i % 8))) {
spdk_bit_array_set(array, i);
}
}

return 0;
}

static void
_spdk_bs_write_super(spdk_bs_sequence_t *seq, struct spdk_blob_store *bs,
struct spdk_bs_super_block *super, spdk_bs_sequence_cpl cb_fn, void *cb_arg)
Expand Down Expand Up @@ -2665,7 +2685,6 @@ static void
_spdk_bs_load_used_blobids_cpl(spdk_bs_sequence_t *seq, void *cb_arg, int bserrno)
{
struct spdk_bs_load_ctx *ctx = cb_arg;
uint32_t i;
int rc;

/* The type must be correct */
Expand All @@ -2679,19 +2698,13 @@ _spdk_bs_load_used_blobids_cpl(spdk_bs_sequence_t *seq, void *cb_arg, int bserrn
* (in pages) of the metadata region */
assert(ctx->mask->length == ctx->super->md_len);

rc = spdk_bit_array_resize(&ctx->bs->used_blobids, ctx->mask->length);
rc = _spdk_bs_load_mask(&ctx->bs->used_blobids, ctx->mask);
if (rc < 0) {
spdk_dma_free(ctx->mask);
_spdk_bs_load_ctx_fail(seq, ctx, -ENOMEM);
_spdk_bs_load_ctx_fail(seq, ctx, rc);
return;
}

for (i = 0; i < ctx->mask->length; i++) {
if (ctx->mask->mask[i / 8] & (1U << (i % 8))) {
spdk_bit_array_set(ctx->bs->used_blobids, i);
}
}

_spdk_bs_load_complete(seq, ctx, bserrno);
}

Expand All @@ -2700,7 +2713,6 @@ _spdk_bs_load_used_clusters_cpl(spdk_bs_sequence_t *seq, void *cb_arg, int bserr
{
struct spdk_bs_load_ctx *ctx = cb_arg;
uint64_t lba, lba_count, mask_size;
uint32_t i;
int rc;

/* The type must be correct */
Expand All @@ -2711,19 +2723,13 @@ _spdk_bs_load_used_clusters_cpl(spdk_bs_sequence_t *seq, void *cb_arg, int bserr
/* The length of the mask must be exactly equal to the total number of clusters */
assert(ctx->mask->length == ctx->bs->total_clusters);

rc = spdk_bit_array_resize(&ctx->bs->used_clusters, ctx->bs->total_clusters);
rc = _spdk_bs_load_mask(&ctx->bs->used_clusters, ctx->mask);
if (rc < 0) {
spdk_dma_free(ctx->mask);
_spdk_bs_load_ctx_fail(seq, ctx, -ENOMEM);
_spdk_bs_load_ctx_fail(seq, ctx, rc);
return;
}

for (i = 0; i < ctx->mask->length; i++) {
if (ctx->mask->mask[i / 8] & (1U << (i % 8))) {
spdk_bit_array_set(ctx->bs->used_clusters, i);
}
}

ctx->bs->num_free_clusters = spdk_bit_array_count_clear(ctx->bs->used_clusters);
assert(ctx->bs->num_free_clusters <= ctx->bs->total_clusters);

Expand All @@ -2747,7 +2753,6 @@ _spdk_bs_load_used_pages_cpl(spdk_bs_sequence_t *seq, void *cb_arg, int bserrno)
{
struct spdk_bs_load_ctx *ctx = cb_arg;
uint64_t lba, lba_count, mask_size;
uint32_t i;
int rc;

/* The type must be correct */
Expand All @@ -2758,18 +2763,13 @@ _spdk_bs_load_used_pages_cpl(spdk_bs_sequence_t *seq, void *cb_arg, int bserrno)
/* The length of the mask must be exactly equal to the size (in pages) of the metadata region */
assert(ctx->mask->length == ctx->super->md_len);

rc = spdk_bit_array_resize(&ctx->bs->used_md_pages, ctx->mask->length);
rc = _spdk_bs_load_mask(&ctx->bs->used_md_pages, ctx->mask);
if (rc < 0) {
spdk_dma_free(ctx->mask);
_spdk_bs_load_ctx_fail(seq, ctx, -ENOMEM);
_spdk_bs_load_ctx_fail(seq, ctx, rc);
return;
}

for (i = 0; i < ctx->mask->length; i++) {
if (ctx->mask->mask[i / 8] & (1U << (i % 8))) {
spdk_bit_array_set(ctx->bs->used_md_pages, i);
}
}
spdk_dma_free(ctx->mask);

/* Read the used clusters mask */
Expand Down

0 comments on commit f4a0187

Please sign in to comment.