diff options
| author | Mike Snitzer <snitzer@redhat.com> | 2013-03-20 13:21:27 -0400 |
|---|---|---|
| committer | Alasdair G Kergon <agk@redhat.com> | 2013-03-20 13:21:27 -0400 |
| commit | 4e7f506f6429636115e2f58f9f97089acc62524a (patch) | |
| tree | 8758ebd6ee210ec303b661df775f31b3e9f45dd9 | |
| parent | e2e74d617eadc15f601983270c4f4a6935c5a943 (diff) | |
dm cache: policy change version from string to integer set
Separate dm cache policy version string into 3 unsigned numbers
corresponding to major, minor and patchlevel and store them at the end
of the on-disk metadata so we know which version of the policy generated
the hints in case a future version wants to use them differently.
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
| -rw-r--r-- | drivers/md/dm-cache-metadata.c | 15 | ||||
| -rw-r--r-- | drivers/md/dm-cache-policy-cleaner.c | 7 | ||||
| -rw-r--r-- | drivers/md/dm-cache-policy-internal.h | 2 | ||||
| -rw-r--r-- | drivers/md/dm-cache-policy-mq.c | 8 | ||||
| -rw-r--r-- | drivers/md/dm-cache-policy.c | 8 | ||||
| -rw-r--r-- | drivers/md/dm-cache-policy.h | 2 |
6 files changed, 36 insertions, 6 deletions
diff --git a/drivers/md/dm-cache-metadata.c b/drivers/md/dm-cache-metadata.c index 1bb91802b22a..74213d1f1db5 100644 --- a/drivers/md/dm-cache-metadata.c +++ b/drivers/md/dm-cache-metadata.c | |||
| @@ -83,6 +83,8 @@ struct cache_disk_superblock { | |||
| 83 | __le32 read_misses; | 83 | __le32 read_misses; |
| 84 | __le32 write_hits; | 84 | __le32 write_hits; |
| 85 | __le32 write_misses; | 85 | __le32 write_misses; |
| 86 | |||
| 87 | __le32 policy_version[CACHE_POLICY_VERSION_SIZE]; | ||
| 86 | } __packed; | 88 | } __packed; |
| 87 | 89 | ||
| 88 | struct dm_cache_metadata { | 90 | struct dm_cache_metadata { |
| @@ -109,6 +111,7 @@ struct dm_cache_metadata { | |||
| 109 | bool clean_when_opened:1; | 111 | bool clean_when_opened:1; |
| 110 | 112 | ||
| 111 | char policy_name[CACHE_POLICY_NAME_SIZE]; | 113 | char policy_name[CACHE_POLICY_NAME_SIZE]; |
| 114 | unsigned policy_version[CACHE_POLICY_VERSION_SIZE]; | ||
| 112 | size_t policy_hint_size; | 115 | size_t policy_hint_size; |
| 113 | struct dm_cache_statistics stats; | 116 | struct dm_cache_statistics stats; |
| 114 | }; | 117 | }; |
| @@ -268,7 +271,8 @@ static int __write_initial_superblock(struct dm_cache_metadata *cmd) | |||
| 268 | memset(disk_super->uuid, 0, sizeof(disk_super->uuid)); | 271 | memset(disk_super->uuid, 0, sizeof(disk_super->uuid)); |
| 269 | disk_super->magic = cpu_to_le64(CACHE_SUPERBLOCK_MAGIC); | 272 | disk_super->magic = cpu_to_le64(CACHE_SUPERBLOCK_MAGIC); |
| 270 | disk_super->version = cpu_to_le32(CACHE_VERSION); | 273 | disk_super->version = cpu_to_le32(CACHE_VERSION); |
| 271 | memset(disk_super->policy_name, 0, CACHE_POLICY_NAME_SIZE); | 274 | memset(disk_super->policy_name, 0, sizeof(disk_super->policy_name)); |
| 275 | memset(disk_super->policy_version, 0, sizeof(disk_super->policy_version)); | ||
| 272 | disk_super->policy_hint_size = 0; | 276 | disk_super->policy_hint_size = 0; |
| 273 | 277 | ||
| 274 | r = dm_sm_copy_root(cmd->metadata_sm, &disk_super->metadata_space_map_root, | 278 | r = dm_sm_copy_root(cmd->metadata_sm, &disk_super->metadata_space_map_root, |
| @@ -284,7 +288,6 @@ static int __write_initial_superblock(struct dm_cache_metadata *cmd) | |||
| 284 | disk_super->metadata_block_size = cpu_to_le32(DM_CACHE_METADATA_BLOCK_SIZE >> SECTOR_SHIFT); | 288 | disk_super->metadata_block_size = cpu_to_le32(DM_CACHE_METADATA_BLOCK_SIZE >> SECTOR_SHIFT); |
| 285 | disk_super->data_block_size = cpu_to_le32(cmd->data_block_size); | 289 | disk_super->data_block_size = cpu_to_le32(cmd->data_block_size); |
| 286 | disk_super->cache_blocks = cpu_to_le32(0); | 290 | disk_super->cache_blocks = cpu_to_le32(0); |
| 287 | memset(disk_super->policy_name, 0, sizeof(disk_super->policy_name)); | ||
| 288 | 291 | ||
| 289 | disk_super->read_hits = cpu_to_le32(0); | 292 | disk_super->read_hits = cpu_to_le32(0); |
| 290 | disk_super->read_misses = cpu_to_le32(0); | 293 | disk_super->read_misses = cpu_to_le32(0); |
| @@ -478,6 +481,9 @@ static void read_superblock_fields(struct dm_cache_metadata *cmd, | |||
| 478 | cmd->data_block_size = le32_to_cpu(disk_super->data_block_size); | 481 | cmd->data_block_size = le32_to_cpu(disk_super->data_block_size); |
| 479 | cmd->cache_blocks = to_cblock(le32_to_cpu(disk_super->cache_blocks)); | 482 | cmd->cache_blocks = to_cblock(le32_to_cpu(disk_super->cache_blocks)); |
| 480 | strncpy(cmd->policy_name, disk_super->policy_name, sizeof(cmd->policy_name)); | 483 | strncpy(cmd->policy_name, disk_super->policy_name, sizeof(cmd->policy_name)); |
| 484 | cmd->policy_version[0] = le32_to_cpu(disk_super->policy_version[0]); | ||
| 485 | cmd->policy_version[1] = le32_to_cpu(disk_super->policy_version[1]); | ||
| 486 | cmd->policy_version[2] = le32_to_cpu(disk_super->policy_version[2]); | ||
| 481 | cmd->policy_hint_size = le32_to_cpu(disk_super->policy_hint_size); | 487 | cmd->policy_hint_size = le32_to_cpu(disk_super->policy_hint_size); |
| 482 | 488 | ||
| 483 | cmd->stats.read_hits = le32_to_cpu(disk_super->read_hits); | 489 | cmd->stats.read_hits = le32_to_cpu(disk_super->read_hits); |
| @@ -572,6 +578,9 @@ static int __commit_transaction(struct dm_cache_metadata *cmd, | |||
| 572 | disk_super->discard_nr_blocks = cpu_to_le64(from_dblock(cmd->discard_nr_blocks)); | 578 | disk_super->discard_nr_blocks = cpu_to_le64(from_dblock(cmd->discard_nr_blocks)); |
| 573 | disk_super->cache_blocks = cpu_to_le32(from_cblock(cmd->cache_blocks)); | 579 | disk_super->cache_blocks = cpu_to_le32(from_cblock(cmd->cache_blocks)); |
| 574 | strncpy(disk_super->policy_name, cmd->policy_name, sizeof(disk_super->policy_name)); | 580 | strncpy(disk_super->policy_name, cmd->policy_name, sizeof(disk_super->policy_name)); |
| 581 | disk_super->policy_version[0] = cpu_to_le32(cmd->policy_version[0]); | ||
| 582 | disk_super->policy_version[1] = cpu_to_le32(cmd->policy_version[1]); | ||
| 583 | disk_super->policy_version[2] = cpu_to_le32(cmd->policy_version[2]); | ||
| 575 | 584 | ||
| 576 | disk_super->read_hits = cpu_to_le32(cmd->stats.read_hits); | 585 | disk_super->read_hits = cpu_to_le32(cmd->stats.read_hits); |
| 577 | disk_super->read_misses = cpu_to_le32(cmd->stats.read_misses); | 586 | disk_super->read_misses = cpu_to_le32(cmd->stats.read_misses); |
| @@ -1070,6 +1079,7 @@ static int begin_hints(struct dm_cache_metadata *cmd, struct dm_cache_policy *po | |||
| 1070 | __le32 value; | 1079 | __le32 value; |
| 1071 | size_t hint_size; | 1080 | size_t hint_size; |
| 1072 | const char *policy_name = dm_cache_policy_get_name(policy); | 1081 | const char *policy_name = dm_cache_policy_get_name(policy); |
| 1082 | const unsigned *policy_version = dm_cache_policy_get_version(policy); | ||
| 1073 | 1083 | ||
| 1074 | if (!policy_name[0] || | 1084 | if (!policy_name[0] || |
| 1075 | (strlen(policy_name) > sizeof(cmd->policy_name) - 1)) | 1085 | (strlen(policy_name) > sizeof(cmd->policy_name) - 1)) |
| @@ -1077,6 +1087,7 @@ static int begin_hints(struct dm_cache_metadata *cmd, struct dm_cache_policy *po | |||
| 1077 | 1087 | ||
| 1078 | if (strcmp(cmd->policy_name, policy_name)) { | 1088 | if (strcmp(cmd->policy_name, policy_name)) { |
| 1079 | strncpy(cmd->policy_name, policy_name, sizeof(cmd->policy_name)); | 1089 | strncpy(cmd->policy_name, policy_name, sizeof(cmd->policy_name)); |
| 1090 | memcpy(cmd->policy_version, policy_version, sizeof(cmd->policy_version)); | ||
| 1080 | 1091 | ||
| 1081 | hint_size = dm_cache_policy_get_hint_size(policy); | 1092 | hint_size = dm_cache_policy_get_hint_size(policy); |
| 1082 | if (!hint_size) | 1093 | if (!hint_size) |
diff --git a/drivers/md/dm-cache-policy-cleaner.c b/drivers/md/dm-cache-policy-cleaner.c index cc05d70b3cb8..b04d1f904d07 100644 --- a/drivers/md/dm-cache-policy-cleaner.c +++ b/drivers/md/dm-cache-policy-cleaner.c | |||
| @@ -17,7 +17,6 @@ | |||
| 17 | /*----------------------------------------------------------------*/ | 17 | /*----------------------------------------------------------------*/ |
| 18 | 18 | ||
| 19 | #define DM_MSG_PREFIX "cache cleaner" | 19 | #define DM_MSG_PREFIX "cache cleaner" |
| 20 | #define CLEANER_VERSION "1.0.0" | ||
| 21 | 20 | ||
| 22 | /* Cache entry struct. */ | 21 | /* Cache entry struct. */ |
| 23 | struct wb_cache_entry { | 22 | struct wb_cache_entry { |
| @@ -434,6 +433,7 @@ static struct dm_cache_policy *wb_create(dm_cblock_t cache_size, | |||
| 434 | 433 | ||
| 435 | static struct dm_cache_policy_type wb_policy_type = { | 434 | static struct dm_cache_policy_type wb_policy_type = { |
| 436 | .name = "cleaner", | 435 | .name = "cleaner", |
| 436 | .version = {1, 0, 0}, | ||
| 437 | .hint_size = 0, | 437 | .hint_size = 0, |
| 438 | .owner = THIS_MODULE, | 438 | .owner = THIS_MODULE, |
| 439 | .create = wb_create | 439 | .create = wb_create |
| @@ -446,7 +446,10 @@ static int __init wb_init(void) | |||
| 446 | if (r < 0) | 446 | if (r < 0) |
| 447 | DMERR("register failed %d", r); | 447 | DMERR("register failed %d", r); |
| 448 | else | 448 | else |
| 449 | DMINFO("version " CLEANER_VERSION " loaded"); | 449 | DMINFO("version %u.%u.%u loaded", |
| 450 | wb_policy_type.version[0], | ||
| 451 | wb_policy_type.version[1], | ||
| 452 | wb_policy_type.version[2]); | ||
| 450 | 453 | ||
| 451 | return r; | 454 | return r; |
| 452 | } | 455 | } |
diff --git a/drivers/md/dm-cache-policy-internal.h b/drivers/md/dm-cache-policy-internal.h index 52a75beeced5..0928abdc49f0 100644 --- a/drivers/md/dm-cache-policy-internal.h +++ b/drivers/md/dm-cache-policy-internal.h | |||
| @@ -117,6 +117,8 @@ void dm_cache_policy_destroy(struct dm_cache_policy *p); | |||
| 117 | */ | 117 | */ |
| 118 | const char *dm_cache_policy_get_name(struct dm_cache_policy *p); | 118 | const char *dm_cache_policy_get_name(struct dm_cache_policy *p); |
| 119 | 119 | ||
| 120 | const unsigned *dm_cache_policy_get_version(struct dm_cache_policy *p); | ||
| 121 | |||
| 120 | size_t dm_cache_policy_get_hint_size(struct dm_cache_policy *p); | 122 | size_t dm_cache_policy_get_hint_size(struct dm_cache_policy *p); |
| 121 | 123 | ||
| 122 | /*----------------------------------------------------------------*/ | 124 | /*----------------------------------------------------------------*/ |
diff --git a/drivers/md/dm-cache-policy-mq.c b/drivers/md/dm-cache-policy-mq.c index 964153255076..dc112a7137fe 100644 --- a/drivers/md/dm-cache-policy-mq.c +++ b/drivers/md/dm-cache-policy-mq.c | |||
| @@ -14,7 +14,6 @@ | |||
| 14 | #include <linux/vmalloc.h> | 14 | #include <linux/vmalloc.h> |
| 15 | 15 | ||
| 16 | #define DM_MSG_PREFIX "cache-policy-mq" | 16 | #define DM_MSG_PREFIX "cache-policy-mq" |
| 17 | #define MQ_VERSION "1.0.0" | ||
| 18 | 17 | ||
| 19 | static struct kmem_cache *mq_entry_cache; | 18 | static struct kmem_cache *mq_entry_cache; |
| 20 | 19 | ||
| @@ -1133,6 +1132,7 @@ bad_cache_alloc: | |||
| 1133 | 1132 | ||
| 1134 | static struct dm_cache_policy_type mq_policy_type = { | 1133 | static struct dm_cache_policy_type mq_policy_type = { |
| 1135 | .name = "mq", | 1134 | .name = "mq", |
| 1135 | .version = {1, 0, 0}, | ||
| 1136 | .hint_size = 4, | 1136 | .hint_size = 4, |
| 1137 | .owner = THIS_MODULE, | 1137 | .owner = THIS_MODULE, |
| 1138 | .create = mq_create | 1138 | .create = mq_create |
| @@ -1140,6 +1140,7 @@ static struct dm_cache_policy_type mq_policy_type = { | |||
| 1140 | 1140 | ||
| 1141 | static struct dm_cache_policy_type default_policy_type = { | 1141 | static struct dm_cache_policy_type default_policy_type = { |
| 1142 | .name = "default", | 1142 | .name = "default", |
| 1143 | .version = {1, 0, 0}, | ||
| 1143 | .hint_size = 4, | 1144 | .hint_size = 4, |
| 1144 | .owner = THIS_MODULE, | 1145 | .owner = THIS_MODULE, |
| 1145 | .create = mq_create | 1146 | .create = mq_create |
| @@ -1164,7 +1165,10 @@ static int __init mq_init(void) | |||
| 1164 | 1165 | ||
| 1165 | r = dm_cache_policy_register(&default_policy_type); | 1166 | r = dm_cache_policy_register(&default_policy_type); |
| 1166 | if (!r) { | 1167 | if (!r) { |
| 1167 | DMINFO("version " MQ_VERSION " loaded"); | 1168 | DMINFO("version %u.%u.%u loaded", |
| 1169 | mq_policy_type.version[0], | ||
| 1170 | mq_policy_type.version[1], | ||
| 1171 | mq_policy_type.version[2]); | ||
| 1168 | return 0; | 1172 | return 0; |
| 1169 | } | 1173 | } |
| 1170 | 1174 | ||
diff --git a/drivers/md/dm-cache-policy.c b/drivers/md/dm-cache-policy.c index 2cbf5fdaac52..21c03c570c06 100644 --- a/drivers/md/dm-cache-policy.c +++ b/drivers/md/dm-cache-policy.c | |||
| @@ -150,6 +150,14 @@ const char *dm_cache_policy_get_name(struct dm_cache_policy *p) | |||
| 150 | } | 150 | } |
| 151 | EXPORT_SYMBOL_GPL(dm_cache_policy_get_name); | 151 | EXPORT_SYMBOL_GPL(dm_cache_policy_get_name); |
| 152 | 152 | ||
| 153 | const unsigned *dm_cache_policy_get_version(struct dm_cache_policy *p) | ||
| 154 | { | ||
| 155 | struct dm_cache_policy_type *t = p->private; | ||
| 156 | |||
| 157 | return t->version; | ||
| 158 | } | ||
| 159 | EXPORT_SYMBOL_GPL(dm_cache_policy_get_version); | ||
| 160 | |||
| 153 | size_t dm_cache_policy_get_hint_size(struct dm_cache_policy *p) | 161 | size_t dm_cache_policy_get_hint_size(struct dm_cache_policy *p) |
| 154 | { | 162 | { |
| 155 | struct dm_cache_policy_type *t = p->private; | 163 | struct dm_cache_policy_type *t = p->private; |
diff --git a/drivers/md/dm-cache-policy.h b/drivers/md/dm-cache-policy.h index f0f51b260544..558bdfdabf5f 100644 --- a/drivers/md/dm-cache-policy.h +++ b/drivers/md/dm-cache-policy.h | |||
| @@ -196,6 +196,7 @@ struct dm_cache_policy { | |||
| 196 | * We maintain a little register of the different policy types. | 196 | * We maintain a little register of the different policy types. |
| 197 | */ | 197 | */ |
| 198 | #define CACHE_POLICY_NAME_SIZE 16 | 198 | #define CACHE_POLICY_NAME_SIZE 16 |
| 199 | #define CACHE_POLICY_VERSION_SIZE 3 | ||
| 199 | 200 | ||
| 200 | struct dm_cache_policy_type { | 201 | struct dm_cache_policy_type { |
| 201 | /* For use by the register code only. */ | 202 | /* For use by the register code only. */ |
| @@ -206,6 +207,7 @@ struct dm_cache_policy_type { | |||
| 206 | * what gets passed on the target line to select your policy. | 207 | * what gets passed on the target line to select your policy. |
| 207 | */ | 208 | */ |
| 208 | char name[CACHE_POLICY_NAME_SIZE]; | 209 | char name[CACHE_POLICY_NAME_SIZE]; |
| 210 | unsigned version[CACHE_POLICY_VERSION_SIZE]; | ||
| 209 | 211 | ||
| 210 | /* | 212 | /* |
| 211 | * Policies may store a hint for each each cache block. | 213 | * Policies may store a hint for each each cache block. |
