librbd/cache/pwl: handle invalid ImageCacheState json
get_json_format() and create_image_cache_state() attempt to get
particular keys which could result in an unhandled std::runtime_error
exception. Conversely, ImageCacheState constructor just swallows that
exception which could leave the newly constructed object incorrectly
initialized. Avoid doing parsing in the constructor and introduce
init_from_config() and init_from_metadata() methods instead.
While at it, move everything out from under "persistent_cache" key.
Also fix init_state_json_write test case which stopped working now
that types are enforced by json_spirit.
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
(cherry picked from commit
7678ee2490965a8a73c02a47283adaa5036dbcab)