diff options
Diffstat (limited to 'drivers/md')
-rw-r--r-- | drivers/md/dm-cache-metadata.c | 47 | ||||
-rw-r--r-- | drivers/md/dm-cache-metadata.h | 2 | ||||
-rw-r--r-- | drivers/md/dm-cache-target.c | 3 |
3 files changed, 39 insertions, 13 deletions
diff --git a/drivers/md/dm-cache-metadata.c b/drivers/md/dm-cache-metadata.c index 74213d1f1db5..83e995fece88 100644 --- a/drivers/md/dm-cache-metadata.c +++ b/drivers/md/dm-cache-metadata.c | |||
@@ -863,18 +863,43 @@ struct thunk { | |||
863 | bool hints_valid; | 863 | bool hints_valid; |
864 | }; | 864 | }; |
865 | 865 | ||
866 | static bool policy_unchanged(struct dm_cache_metadata *cmd, | ||
867 | struct dm_cache_policy *policy) | ||
868 | { | ||
869 | const char *policy_name = dm_cache_policy_get_name(policy); | ||
870 | const unsigned *policy_version = dm_cache_policy_get_version(policy); | ||
871 | size_t policy_hint_size = dm_cache_policy_get_hint_size(policy); | ||
872 | |||
873 | /* | ||
874 | * Ensure policy names match. | ||
875 | */ | ||
876 | if (strncmp(cmd->policy_name, policy_name, sizeof(cmd->policy_name))) | ||
877 | return false; | ||
878 | |||
879 | /* | ||
880 | * Ensure policy major versions match. | ||
881 | */ | ||
882 | if (cmd->policy_version[0] != policy_version[0]) | ||
883 | return false; | ||
884 | |||
885 | /* | ||
886 | * Ensure policy hint sizes match. | ||
887 | */ | ||
888 | if (cmd->policy_hint_size != policy_hint_size) | ||
889 | return false; | ||
890 | |||
891 | return true; | ||
892 | } | ||
893 | |||
866 | static bool hints_array_initialized(struct dm_cache_metadata *cmd) | 894 | static bool hints_array_initialized(struct dm_cache_metadata *cmd) |
867 | { | 895 | { |
868 | return cmd->hint_root && cmd->policy_hint_size; | 896 | return cmd->hint_root && cmd->policy_hint_size; |
869 | } | 897 | } |
870 | 898 | ||
871 | static bool hints_array_available(struct dm_cache_metadata *cmd, | 899 | static bool hints_array_available(struct dm_cache_metadata *cmd, |
872 | const char *policy_name) | 900 | struct dm_cache_policy *policy) |
873 | { | 901 | { |
874 | bool policy_names_match = !strncmp(cmd->policy_name, policy_name, | 902 | return cmd->clean_when_opened && policy_unchanged(cmd, policy) && |
875 | sizeof(cmd->policy_name)); | ||
876 | |||
877 | return cmd->clean_when_opened && policy_names_match && | ||
878 | hints_array_initialized(cmd); | 903 | hints_array_initialized(cmd); |
879 | } | 904 | } |
880 | 905 | ||
@@ -908,7 +933,8 @@ static int __load_mapping(void *context, uint64_t cblock, void *leaf) | |||
908 | return r; | 933 | return r; |
909 | } | 934 | } |
910 | 935 | ||
911 | static int __load_mappings(struct dm_cache_metadata *cmd, const char *policy_name, | 936 | static int __load_mappings(struct dm_cache_metadata *cmd, |
937 | struct dm_cache_policy *policy, | ||
912 | load_mapping_fn fn, void *context) | 938 | load_mapping_fn fn, void *context) |
913 | { | 939 | { |
914 | struct thunk thunk; | 940 | struct thunk thunk; |
@@ -918,18 +944,19 @@ static int __load_mappings(struct dm_cache_metadata *cmd, const char *policy_nam | |||
918 | 944 | ||
919 | thunk.cmd = cmd; | 945 | thunk.cmd = cmd; |
920 | thunk.respect_dirty_flags = cmd->clean_when_opened; | 946 | thunk.respect_dirty_flags = cmd->clean_when_opened; |
921 | thunk.hints_valid = hints_array_available(cmd, policy_name); | 947 | thunk.hints_valid = hints_array_available(cmd, policy); |
922 | 948 | ||
923 | return dm_array_walk(&cmd->info, cmd->root, __load_mapping, &thunk); | 949 | return dm_array_walk(&cmd->info, cmd->root, __load_mapping, &thunk); |
924 | } | 950 | } |
925 | 951 | ||
926 | int dm_cache_load_mappings(struct dm_cache_metadata *cmd, const char *policy_name, | 952 | int dm_cache_load_mappings(struct dm_cache_metadata *cmd, |
953 | struct dm_cache_policy *policy, | ||
927 | load_mapping_fn fn, void *context) | 954 | load_mapping_fn fn, void *context) |
928 | { | 955 | { |
929 | int r; | 956 | int r; |
930 | 957 | ||
931 | down_read(&cmd->root_lock); | 958 | down_read(&cmd->root_lock); |
932 | r = __load_mappings(cmd, policy_name, fn, context); | 959 | r = __load_mappings(cmd, policy, fn, context); |
933 | up_read(&cmd->root_lock); | 960 | up_read(&cmd->root_lock); |
934 | 961 | ||
935 | return r; | 962 | return r; |
@@ -1085,7 +1112,7 @@ static int begin_hints(struct dm_cache_metadata *cmd, struct dm_cache_policy *po | |||
1085 | (strlen(policy_name) > sizeof(cmd->policy_name) - 1)) | 1112 | (strlen(policy_name) > sizeof(cmd->policy_name) - 1)) |
1086 | return -EINVAL; | 1113 | return -EINVAL; |
1087 | 1114 | ||
1088 | if (strcmp(cmd->policy_name, policy_name)) { | 1115 | if (!policy_unchanged(cmd, policy)) { |
1089 | strncpy(cmd->policy_name, policy_name, sizeof(cmd->policy_name)); | 1116 | strncpy(cmd->policy_name, policy_name, sizeof(cmd->policy_name)); |
1090 | memcpy(cmd->policy_version, policy_version, sizeof(cmd->policy_version)); | 1117 | memcpy(cmd->policy_version, policy_version, sizeof(cmd->policy_version)); |
1091 | 1118 | ||
diff --git a/drivers/md/dm-cache-metadata.h b/drivers/md/dm-cache-metadata.h index 135864ea0eee..f45cef21f3d0 100644 --- a/drivers/md/dm-cache-metadata.h +++ b/drivers/md/dm-cache-metadata.h | |||
@@ -89,7 +89,7 @@ typedef int (*load_mapping_fn)(void *context, dm_oblock_t oblock, | |||
89 | dm_cblock_t cblock, bool dirty, | 89 | dm_cblock_t cblock, bool dirty, |
90 | uint32_t hint, bool hint_valid); | 90 | uint32_t hint, bool hint_valid); |
91 | int dm_cache_load_mappings(struct dm_cache_metadata *cmd, | 91 | int dm_cache_load_mappings(struct dm_cache_metadata *cmd, |
92 | const char *policy_name, | 92 | struct dm_cache_policy *policy, |
93 | load_mapping_fn fn, | 93 | load_mapping_fn fn, |
94 | void *context); | 94 | void *context); |
95 | 95 | ||
diff --git a/drivers/md/dm-cache-target.c b/drivers/md/dm-cache-target.c index ff267db60025..66120bd46d15 100644 --- a/drivers/md/dm-cache-target.c +++ b/drivers/md/dm-cache-target.c | |||
@@ -2369,8 +2369,7 @@ static int cache_preresume(struct dm_target *ti) | |||
2369 | } | 2369 | } |
2370 | 2370 | ||
2371 | if (!cache->loaded_mappings) { | 2371 | if (!cache->loaded_mappings) { |
2372 | r = dm_cache_load_mappings(cache->cmd, | 2372 | r = dm_cache_load_mappings(cache->cmd, cache->policy, |
2373 | dm_cache_policy_get_name(cache->policy), | ||
2374 | load_mapping, cache); | 2373 | load_mapping, cache); |
2375 | if (r) { | 2374 | if (r) { |
2376 | DMERR("could not load cache mappings"); | 2375 | DMERR("could not load cache mappings"); |