dm-cache-metadata.c (a9d45396f5956d0b615c7ae3b936afd888351a47) | dm-cache-metadata.c (5a32083d03fb543f63489b2946c4948398579ba0) |
---|---|
1/* 2 * Copyright (C) 2012 Red Hat, Inc. 3 * 4 * This file is released under the GPL. 5 */ 6 7#include "dm-cache-metadata.h" 8 --- 106 unchanged lines hidden (view full) --- 115 dm_cblock_t cache_blocks; 116 bool changed:1; 117 bool clean_when_opened:1; 118 119 char policy_name[CACHE_POLICY_NAME_SIZE]; 120 unsigned policy_version[CACHE_POLICY_VERSION_SIZE]; 121 size_t policy_hint_size; 122 struct dm_cache_statistics stats; | 1/* 2 * Copyright (C) 2012 Red Hat, Inc. 3 * 4 * This file is released under the GPL. 5 */ 6 7#include "dm-cache-metadata.h" 8 --- 106 unchanged lines hidden (view full) --- 115 dm_cblock_t cache_blocks; 116 bool changed:1; 117 bool clean_when_opened:1; 118 119 char policy_name[CACHE_POLICY_NAME_SIZE]; 120 unsigned policy_version[CACHE_POLICY_VERSION_SIZE]; 121 size_t policy_hint_size; 122 struct dm_cache_statistics stats; |
123 124 /* 125 * Reading the space map root can fail, so we read it into this 126 * buffer before the superblock is locked and updated. 127 */ 128 __u8 metadata_space_map_root[SPACE_MAP_ROOT_SIZE]; |
|
123}; 124 125/*------------------------------------------------------------------- 126 * superblock validator 127 *-----------------------------------------------------------------*/ 128 129#define SUPERBLOCK_CSUM_XOR 9031977 130 --- 124 unchanged lines hidden (view full) --- 255 dm_array_info_init(&cmd->info, cmd->tm, &vt); 256 257 if (cmd->policy_hint_size) { 258 vt.size = sizeof(__le32); 259 dm_array_info_init(&cmd->hint_info, cmd->tm, &vt); 260 } 261} 262 | 129}; 130 131/*------------------------------------------------------------------- 132 * superblock validator 133 *-----------------------------------------------------------------*/ 134 135#define SUPERBLOCK_CSUM_XOR 9031977 136 --- 124 unchanged lines hidden (view full) --- 261 dm_array_info_init(&cmd->info, cmd->tm, &vt); 262 263 if (cmd->policy_hint_size) { 264 vt.size = sizeof(__le32); 265 dm_array_info_init(&cmd->hint_info, cmd->tm, &vt); 266 } 267} 268 |
269static int __save_sm_root(struct dm_cache_metadata *cmd) 270{ 271 int r; 272 size_t metadata_len; 273 274 r = dm_sm_root_size(cmd->metadata_sm, &metadata_len); 275 if (r < 0) 276 return r; 277 278 return dm_sm_copy_root(cmd->metadata_sm, &cmd->metadata_space_map_root, 279 metadata_len); 280} 281 282static void __copy_sm_root(struct dm_cache_metadata *cmd, 283 struct cache_disk_superblock *disk_super) 284{ 285 memcpy(&disk_super->metadata_space_map_root, 286 &cmd->metadata_space_map_root, 287 sizeof(cmd->metadata_space_map_root)); 288} 289 |
|
263static int __write_initial_superblock(struct dm_cache_metadata *cmd) 264{ 265 int r; 266 struct dm_block *sblock; | 290static int __write_initial_superblock(struct dm_cache_metadata *cmd) 291{ 292 int r; 293 struct dm_block *sblock; |
267 size_t metadata_len; | |
268 struct cache_disk_superblock *disk_super; 269 sector_t bdev_size = i_size_read(cmd->bdev->bd_inode) >> SECTOR_SHIFT; 270 271 /* FIXME: see if we can lose the max sectors limit */ 272 if (bdev_size > DM_CACHE_METADATA_MAX_SECTORS) 273 bdev_size = DM_CACHE_METADATA_MAX_SECTORS; 274 | 294 struct cache_disk_superblock *disk_super; 295 sector_t bdev_size = i_size_read(cmd->bdev->bd_inode) >> SECTOR_SHIFT; 296 297 /* FIXME: see if we can lose the max sectors limit */ 298 if (bdev_size > DM_CACHE_METADATA_MAX_SECTORS) 299 bdev_size = DM_CACHE_METADATA_MAX_SECTORS; 300 |
275 r = dm_sm_root_size(cmd->metadata_sm, &metadata_len); | 301 r = dm_tm_pre_commit(cmd->tm); |
276 if (r < 0) 277 return r; 278 | 302 if (r < 0) 303 return r; 304 |
279 r = dm_tm_pre_commit(cmd->tm); 280 if (r < 0) | 305 /* 306 * dm_sm_copy_root() can fail. So we need to do it before we start 307 * updating the superblock. 308 */ 309 r = __save_sm_root(cmd); 310 if (r) |
281 return r; 282 283 r = superblock_lock_zero(cmd, &sblock); 284 if (r) 285 return r; 286 287 disk_super = dm_block_data(sblock); 288 disk_super->flags = 0; 289 memset(disk_super->uuid, 0, sizeof(disk_super->uuid)); 290 disk_super->magic = cpu_to_le64(CACHE_SUPERBLOCK_MAGIC); 291 disk_super->version = cpu_to_le32(MAX_CACHE_VERSION); 292 memset(disk_super->policy_name, 0, sizeof(disk_super->policy_name)); 293 memset(disk_super->policy_version, 0, sizeof(disk_super->policy_version)); 294 disk_super->policy_hint_size = 0; 295 | 311 return r; 312 313 r = superblock_lock_zero(cmd, &sblock); 314 if (r) 315 return r; 316 317 disk_super = dm_block_data(sblock); 318 disk_super->flags = 0; 319 memset(disk_super->uuid, 0, sizeof(disk_super->uuid)); 320 disk_super->magic = cpu_to_le64(CACHE_SUPERBLOCK_MAGIC); 321 disk_super->version = cpu_to_le32(MAX_CACHE_VERSION); 322 memset(disk_super->policy_name, 0, sizeof(disk_super->policy_name)); 323 memset(disk_super->policy_version, 0, sizeof(disk_super->policy_version)); 324 disk_super->policy_hint_size = 0; 325 |
296 r = dm_sm_copy_root(cmd->metadata_sm, &disk_super->metadata_space_map_root, 297 metadata_len); 298 if (r < 0) 299 goto bad_locked; | 326 __copy_sm_root(cmd, disk_super); |
300 301 disk_super->mapping_root = cpu_to_le64(cmd->root); 302 disk_super->hint_root = cpu_to_le64(cmd->hint_root); 303 disk_super->discard_root = cpu_to_le64(cmd->discard_root); 304 disk_super->discard_block_size = cpu_to_le64(cmd->discard_block_size); 305 disk_super->discard_nr_blocks = cpu_to_le64(from_oblock(cmd->discard_nr_blocks)); 306 disk_super->metadata_block_size = cpu_to_le32(DM_CACHE_METADATA_BLOCK_SIZE >> SECTOR_SHIFT); 307 disk_super->data_block_size = cpu_to_le32(cmd->data_block_size); 308 disk_super->cache_blocks = cpu_to_le32(0); 309 310 disk_super->read_hits = cpu_to_le32(0); 311 disk_super->read_misses = cpu_to_le32(0); 312 disk_super->write_hits = cpu_to_le32(0); 313 disk_super->write_misses = cpu_to_le32(0); 314 315 return dm_tm_commit(cmd->tm, sblock); | 327 328 disk_super->mapping_root = cpu_to_le64(cmd->root); 329 disk_super->hint_root = cpu_to_le64(cmd->hint_root); 330 disk_super->discard_root = cpu_to_le64(cmd->discard_root); 331 disk_super->discard_block_size = cpu_to_le64(cmd->discard_block_size); 332 disk_super->discard_nr_blocks = cpu_to_le64(from_oblock(cmd->discard_nr_blocks)); 333 disk_super->metadata_block_size = cpu_to_le32(DM_CACHE_METADATA_BLOCK_SIZE >> SECTOR_SHIFT); 334 disk_super->data_block_size = cpu_to_le32(cmd->data_block_size); 335 disk_super->cache_blocks = cpu_to_le32(0); 336 337 disk_super->read_hits = cpu_to_le32(0); 338 disk_super->read_misses = cpu_to_le32(0); 339 disk_super->write_hits = cpu_to_le32(0); 340 disk_super->write_misses = cpu_to_le32(0); 341 342 return dm_tm_commit(cmd->tm, sblock); |
316 317bad_locked: 318 dm_bm_unlock(sblock); 319 return r; | |
320} 321 322static int __format_metadata(struct dm_cache_metadata *cmd) 323{ 324 int r; 325 326 r = dm_tm_create_with_sm(cmd->bm, CACHE_SUPERBLOCK_LOCATION, 327 &cmd->tm, &cmd->metadata_sm); --- 227 unchanged lines hidden (view full) --- 555 556 return 0; 557} 558 559static int __commit_transaction(struct dm_cache_metadata *cmd, 560 flags_mutator mutator) 561{ 562 int r; | 343} 344 345static int __format_metadata(struct dm_cache_metadata *cmd) 346{ 347 int r; 348 349 r = dm_tm_create_with_sm(cmd->bm, CACHE_SUPERBLOCK_LOCATION, 350 &cmd->tm, &cmd->metadata_sm); --- 227 unchanged lines hidden (view full) --- 578 579 return 0; 580} 581 582static int __commit_transaction(struct dm_cache_metadata *cmd, 583 flags_mutator mutator) 584{ 585 int r; |
563 size_t metadata_len; | |
564 struct cache_disk_superblock *disk_super; 565 struct dm_block *sblock; 566 567 /* 568 * We need to know if the cache_disk_superblock exceeds a 512-byte sector. 569 */ 570 BUILD_BUG_ON(sizeof(struct cache_disk_superblock) > 512); 571 572 r = dm_bitset_flush(&cmd->discard_info, cmd->discard_root, 573 &cmd->discard_root); 574 if (r) 575 return r; 576 577 r = dm_tm_pre_commit(cmd->tm); 578 if (r < 0) 579 return r; 580 | 586 struct cache_disk_superblock *disk_super; 587 struct dm_block *sblock; 588 589 /* 590 * We need to know if the cache_disk_superblock exceeds a 512-byte sector. 591 */ 592 BUILD_BUG_ON(sizeof(struct cache_disk_superblock) > 512); 593 594 r = dm_bitset_flush(&cmd->discard_info, cmd->discard_root, 595 &cmd->discard_root); 596 if (r) 597 return r; 598 599 r = dm_tm_pre_commit(cmd->tm); 600 if (r < 0) 601 return r; 602 |
581 r = dm_sm_root_size(cmd->metadata_sm, &metadata_len); 582 if (r < 0) | 603 r = __save_sm_root(cmd); 604 if (r) |
583 return r; 584 585 r = superblock_lock(cmd, &sblock); 586 if (r) 587 return r; 588 589 disk_super = dm_block_data(sblock); 590 --- 10 unchanged lines hidden (view full) --- 601 disk_super->policy_version[0] = cpu_to_le32(cmd->policy_version[0]); 602 disk_super->policy_version[1] = cpu_to_le32(cmd->policy_version[1]); 603 disk_super->policy_version[2] = cpu_to_le32(cmd->policy_version[2]); 604 605 disk_super->read_hits = cpu_to_le32(cmd->stats.read_hits); 606 disk_super->read_misses = cpu_to_le32(cmd->stats.read_misses); 607 disk_super->write_hits = cpu_to_le32(cmd->stats.write_hits); 608 disk_super->write_misses = cpu_to_le32(cmd->stats.write_misses); | 605 return r; 606 607 r = superblock_lock(cmd, &sblock); 608 if (r) 609 return r; 610 611 disk_super = dm_block_data(sblock); 612 --- 10 unchanged lines hidden (view full) --- 623 disk_super->policy_version[0] = cpu_to_le32(cmd->policy_version[0]); 624 disk_super->policy_version[1] = cpu_to_le32(cmd->policy_version[1]); 625 disk_super->policy_version[2] = cpu_to_le32(cmd->policy_version[2]); 626 627 disk_super->read_hits = cpu_to_le32(cmd->stats.read_hits); 628 disk_super->read_misses = cpu_to_le32(cmd->stats.read_misses); 629 disk_super->write_hits = cpu_to_le32(cmd->stats.write_hits); 630 disk_super->write_misses = cpu_to_le32(cmd->stats.write_misses); |
631 __copy_sm_root(cmd, disk_super); |
|
609 | 632 |
610 r = dm_sm_copy_root(cmd->metadata_sm, &disk_super->metadata_space_map_root, 611 metadata_len); 612 if (r < 0) { 613 dm_bm_unlock(sblock); 614 return r; 615 } 616 | |
617 return dm_tm_commit(cmd->tm, sblock); 618} 619 620/*----------------------------------------------------------------*/ 621 622/* 623 * The mappings are held in a dm-array that has 64-bit values stored in 624 * little-endian format. The index is the cblock, the high 48bits of the --- 651 unchanged lines hidden --- | 633 return dm_tm_commit(cmd->tm, sblock); 634} 635 636/*----------------------------------------------------------------*/ 637 638/* 639 * The mappings are held in a dm-array that has 64-bit values stored in 640 * little-endian format. The index is the cblock, the high 48bits of the --- 651 unchanged lines hidden --- |