Merge pull request #214 from mmichal10/detect-old-cache-metadata
Detect old cache metadata
This commit is contained in:
commit
999f3f7245
@ -39,6 +39,9 @@ typedef enum {
|
||||
/** No metadata found on device */
|
||||
OCF_ERR_NO_METADATA,
|
||||
|
||||
/** Cache metadata found on device */
|
||||
OCF_ERR_METADATA_FOUND,
|
||||
|
||||
/** Invalid volume type */
|
||||
OCF_ERR_INVAL_VOLUME_TYPE,
|
||||
|
||||
|
@ -922,8 +922,23 @@ static void _ocf_mngt_attach_load_properties_end(void *priv, int error,
|
||||
|
||||
context->metadata.status = error;
|
||||
|
||||
if (error)
|
||||
if (error) {
|
||||
/*
|
||||
* If --load option wasn't used and old metadata doesn't exist on the
|
||||
* device, dismiss error.
|
||||
*/
|
||||
if (error == -OCF_ERR_NO_METADATA &&
|
||||
cache->device->init_mode != ocf_init_mode_load)
|
||||
OCF_PL_NEXT_RET(context->pipeline);
|
||||
else
|
||||
OCF_PL_FINISH_RET(context->pipeline, error);
|
||||
} else if (cache->device->init_mode != ocf_init_mode_load) {
|
||||
/*
|
||||
* To prevent silent metadata overriding, return error if old metadata
|
||||
* was detected but --load flag wasn't used.
|
||||
*/
|
||||
OCF_PL_FINISH_RET(context->pipeline, -OCF_ERR_METADATA_FOUND);
|
||||
}
|
||||
|
||||
context->metadata.shutdown_status = properties->shutdown_status;
|
||||
context->metadata.dirty_flushed = properties->dirty_flushed;
|
||||
@ -949,6 +964,9 @@ static void _ocf_mngt_attach_load_properties(ocf_pipeline_t pipeline,
|
||||
context->metadata.dirty_flushed = DIRTY_FLUSHED;
|
||||
context->metadata.line_size = context->cfg.cache_line_size;
|
||||
|
||||
if (context->cfg.force)
|
||||
OCF_PL_NEXT_RET(context->pipeline);
|
||||
|
||||
if (cache->device->init_mode == ocf_init_mode_metadata_volatile)
|
||||
OCF_PL_NEXT_RET(context->pipeline);
|
||||
|
||||
|
@ -20,6 +20,7 @@ class OcfErrorCode(IntEnum):
|
||||
OCF_ERR_NO_LOCK = auto()
|
||||
OCF_ERR_METADATA_VER = auto()
|
||||
OCF_ERR_NO_METADATA = auto()
|
||||
OCF_ERR_METADATA_FOUND = auto()
|
||||
OCF_ERR_INVAL_VOLUME_TYPE = auto()
|
||||
OCF_ERR_UNKNOWN = auto()
|
||||
OCF_ERR_TOO_MANY_CACHES = auto()
|
||||
|
@ -62,7 +62,7 @@ def test_start_corrupted_metadata_lba(pyocf_ctx):
|
||||
def test_load_cache_no_preexisting_data(pyocf_ctx):
|
||||
cache_device = Volume(S.from_MiB(30))
|
||||
|
||||
with pytest.raises(OcfError, match="OCF_ERR_START_CACHE_FAIL"):
|
||||
with pytest.raises(OcfError, match="OCF_ERR_NO_METADATA"):
|
||||
cache = Cache.load_from_device(cache_device)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user