blob: Add support for crc of super block.

Change-Id: I424833a0af6e5e8265c03c168b9dfdbae1a49cd8
Signed-off-by: Cunyin Chang <cunyin.chang@intel.com>
Reviewed-on: https://review.gerrithub.io/378233
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Cunyin Chang 2017-09-13 11:09:22 +08:00 committed by Jim Harris
parent 38c19cd275
commit 29bcd5a90d
4 changed files with 50 additions and 5 deletions

View File

@ -176,7 +176,7 @@ It contains basic information about the blobstore. The metadata region
is the remainder of cluster 0 and may extend to additional clusters. is the remainder of cluster 0 and may extend to additional clusters.
<super-block> ::= <sb-version> <sb-len> <sb-super-blob> <sb-params> <super-block> ::= <sb-version> <sb-len> <sb-super-blob> <sb-params>
<sb-metadata-start> <sb-metadata-len> <sb-metadata-start> <sb-metadata-len> <crc>
<sb-version> ::= u32 <sb-version> ::= u32
<sb-len> ::= u32 # Length of this super block, in bytes. Starts from the <sb-len> ::= u32 # Length of this super block, in bytes. Starts from the
# beginning of this structure. # beginning of this structure.
@ -185,6 +185,7 @@ is the remainder of cluster 0 and may extend to additional clusters.
<sb-md-start> ::= u64 # Metadata start location, in pages <sb-md-start> ::= u64 # Metadata start location, in pages
<sb-md-len> ::= u64 # Metadata length, in pages <sb-md-len> ::= u64 # Metadata length, in pages
<crc> ::= u32 # Crc for super block
The `<sb-params>` data contains parameters specified by the user when the blob The `<sb-params>` data contains parameters specified by the user when the blob
store was initially formatted. store was initially formatted.

View File

@ -1548,6 +1548,7 @@ static void
_spdk_bs_load_super_cpl(spdk_bs_sequence_t *seq, void *cb_arg, int bserrno) _spdk_bs_load_super_cpl(spdk_bs_sequence_t *seq, void *cb_arg, int bserrno)
{ {
struct spdk_bs_load_ctx *ctx = cb_arg; struct spdk_bs_load_ctx *ctx = cb_arg;
uint32_t crc;
if (ctx->super->version != SPDK_BS_VERSION) { if (ctx->super->version != SPDK_BS_VERSION) {
spdk_dma_free(ctx->super); spdk_dma_free(ctx->super);
@ -1566,6 +1567,15 @@ _spdk_bs_load_super_cpl(spdk_bs_sequence_t *seq, void *cb_arg, int bserrno)
return; return;
} }
crc = _spdk_blob_md_page_calc_crc(ctx->super);
if (crc != ctx->super->crc) {
spdk_dma_free(ctx->super);
_spdk_bs_free(ctx->bs);
free(ctx);
spdk_bs_sequence_finish(seq, -EILSEQ);
return;
}
if (ctx->super->clean != 1) { if (ctx->super->clean != 1) {
/* TODO: ONLY CLEAN SHUTDOWN IS CURRENTLY SUPPORTED. /* TODO: ONLY CLEAN SHUTDOWN IS CURRENTLY SUPPORTED.
* All of the necessary data to recover is available * All of the necessary data to recover is available
@ -1580,7 +1590,7 @@ _spdk_bs_load_super_cpl(spdk_bs_sequence_t *seq, void *cb_arg, int bserrno)
} }
ctx->super->clean = 0; ctx->super->clean = 0;
ctx->super->crc = _spdk_blob_md_page_calc_crc(ctx->super);
spdk_bs_sequence_write(seq, ctx->super, _spdk_bs_page_to_lba(ctx->bs, 0), spdk_bs_sequence_write(seq, ctx->super, _spdk_bs_page_to_lba(ctx->bs, 0),
_spdk_bs_byte_to_lba(ctx->bs, sizeof(*ctx->super)), _spdk_bs_byte_to_lba(ctx->bs, sizeof(*ctx->super)),
_spdk_bs_load_write_super_cpl, ctx); _spdk_bs_load_write_super_cpl, ctx);
@ -1781,6 +1791,7 @@ spdk_bs_init(struct spdk_bs_dev *dev, struct spdk_bs_opts *o,
ctx->super->md_len = bs->md_len; ctx->super->md_len = bs->md_len;
num_md_pages += bs->md_len; num_md_pages += bs->md_len;
ctx->super->crc = _spdk_blob_md_page_calc_crc(ctx->super);
/* Claim all of the clusters used by the metadata */ /* Claim all of the clusters used by the metadata */
for (i = 0; i < divide_round_up(num_md_pages, bs->pages_per_cluster); i++) { for (i = 0; i < divide_round_up(num_md_pages, bs->pages_per_cluster); i++) {
_spdk_bs_claim_cluster(bs, i); _spdk_bs_claim_cluster(bs, i);
@ -1838,7 +1849,7 @@ _spdk_bs_unload_write_used_clusters_cpl(spdk_bs_sequence_t *seq, void *cb_arg, i
/* Update the values in the super block */ /* Update the values in the super block */
ctx->super->super_blob = ctx->bs->super_blob; ctx->super->super_blob = ctx->bs->super_blob;
ctx->super->clean = 1; ctx->super->clean = 1;
ctx->super->crc = _spdk_blob_md_page_calc_crc(ctx->super);
spdk_bs_sequence_write(seq, ctx->super, _spdk_bs_page_to_lba(ctx->bs, 0), spdk_bs_sequence_write(seq, ctx->super, _spdk_bs_page_to_lba(ctx->bs, 0),
_spdk_bs_byte_to_lba(ctx->bs, sizeof(*ctx->super)), _spdk_bs_byte_to_lba(ctx->bs, sizeof(*ctx->super)),
_spdk_bs_unload_write_super_cpl, ctx); _spdk_bs_unload_write_super_cpl, ctx);

View File

@ -253,7 +253,8 @@ struct spdk_bs_super_block {
uint32_t md_start; /* Offset from beginning of disk, in pages */ uint32_t md_start; /* Offset from beginning of disk, in pages */
uint32_t md_len; /* Count, in pages */ uint32_t md_len; /* Count, in pages */
uint8_t reserved[4040]; uint8_t reserved[4036];
uint32_t crc;
}; };
SPDK_STATIC_ASSERT(sizeof(struct spdk_bs_super_block) == 0x1000, "Invalid super block size"); SPDK_STATIC_ASSERT(sizeof(struct spdk_bs_super_block) == 0x1000, "Invalid super block size");

View File

@ -1234,6 +1234,37 @@ blob_crc(void)
g_bs = NULL; g_bs = NULL;
} }
static void
super_block_crc(void)
{
struct spdk_bs_dev *dev;
struct spdk_bs_super_block *super_block;
dev = init_dev();
spdk_bs_init(dev, NULL, bs_op_with_handle_complete, NULL);
CU_ASSERT(g_bserrno == 0);
SPDK_CU_ASSERT_FATAL(g_bs != NULL);
spdk_bs_unload(g_bs, bs_op_complete, NULL);
CU_ASSERT(g_bserrno == 0);
g_bs = NULL;
super_block = (struct spdk_bs_super_block *)g_dev_buffer;
super_block->crc = 0;
dev = init_dev();
g_scheduler_delay = true;
/* Load an existing blob store */
spdk_bs_load(dev, bs_op_with_handle_complete, NULL);
CU_ASSERT(g_bserrno == -EILSEQ);
_bs_flush_scheduler();
CU_ASSERT(TAILQ_EMPTY(&g_scheduled_ops));
g_scheduler_delay = false;
}
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
CU_pSuite suite = NULL; CU_pSuite suite = NULL;
@ -1268,7 +1299,8 @@ int main(int argc, char **argv)
CU_add_test(suite, "bs_cluster_sz", bs_cluster_sz) == NULL || CU_add_test(suite, "bs_cluster_sz", bs_cluster_sz) == NULL ||
CU_add_test(suite, "bs_resize_md", bs_resize_md) == NULL || CU_add_test(suite, "bs_resize_md", bs_resize_md) == NULL ||
CU_add_test(suite, "blob_serialize", blob_serialize) == NULL || CU_add_test(suite, "blob_serialize", blob_serialize) == NULL ||
CU_add_test(suite, "blob_crc", blob_crc) == NULL CU_add_test(suite, "blob_crc", blob_crc) == NULL ||
CU_add_test(suite, "super_block_crc", super_block_crc) == NULL
) { ) {
CU_cleanup_registry(); CU_cleanup_registry();
return CU_get_error(); return CU_get_error();