2 * Copyright (C) 2012 Red Hat, Inc.
4 * This file is released under the GPL.
7 #include "dm-cache-metadata.h"
9 #include "persistent-data/dm-array.h"
10 #include "persistent-data/dm-bitset.h"
11 #include "persistent-data/dm-space-map.h"
12 #include "persistent-data/dm-space-map-disk.h"
13 #include "persistent-data/dm-transaction-manager.h"
15 #include <linux/device-mapper.h>
17 /*----------------------------------------------------------------*/
19 #define DM_MSG_PREFIX "cache metadata"
21 #define CACHE_SUPERBLOCK_MAGIC 06142003
22 #define CACHE_SUPERBLOCK_LOCATION 0
25 * defines a range of metadata versions that this module can handle.
27 #define MIN_CACHE_VERSION 1
28 #define MAX_CACHE_VERSION 2
30 #define CACHE_METADATA_CACHE_SIZE 64
33 * 3 for btree insert +
34 * 2 for btree lookup used within space map
36 #define CACHE_MAX_CONCURRENT_LOCKS 5
37 #define SPACE_MAP_ROOT_SIZE 128
39 enum superblock_flag_bits
{
40 /* for spotting crashes that would invalidate the dirty bitset */
42 /* metadata must be checked using the tools */
47 * Each mapping from cache block -> origin block carries a set of flags.
51 * A valid mapping. Because we're using an array we clear this
52 * flag for an non existant mapping.
57 * The data on the cache is different from that on the origin.
58 * This flag is only used by metadata format 1.
63 struct cache_disk_superblock
{
72 __u8 policy_name
[CACHE_POLICY_NAME_SIZE
];
73 __le32 policy_hint_size
;
75 __u8 metadata_space_map_root
[SPACE_MAP_ROOT_SIZE
];
80 __le64 discard_block_size
;
81 __le64 discard_nr_blocks
;
83 __le32 data_block_size
;
84 __le32 metadata_block_size
;
88 __le32 compat_ro_flags
;
89 __le32 incompat_flags
;
96 __le32 policy_version
[CACHE_POLICY_VERSION_SIZE
];
99 * Metadata format 2 fields.
104 struct dm_cache_metadata
{
106 struct list_head list
;
109 struct block_device
*bdev
;
110 struct dm_block_manager
*bm
;
111 struct dm_space_map
*metadata_sm
;
112 struct dm_transaction_manager
*tm
;
114 struct dm_array_info info
;
115 struct dm_array_info hint_info
;
116 struct dm_disk_bitset discard_info
;
118 struct rw_semaphore root_lock
;
121 dm_block_t hint_root
;
122 dm_block_t discard_root
;
124 sector_t discard_block_size
;
125 dm_dblock_t discard_nr_blocks
;
127 sector_t data_block_size
;
128 dm_cblock_t cache_blocks
;
130 bool clean_when_opened
:1;
132 char policy_name
[CACHE_POLICY_NAME_SIZE
];
133 unsigned policy_version
[CACHE_POLICY_VERSION_SIZE
];
134 size_t policy_hint_size
;
135 struct dm_cache_statistics stats
;
138 * Reading the space map root can fail, so we read it into this
139 * buffer before the superblock is locked and updated.
141 __u8 metadata_space_map_root
[SPACE_MAP_ROOT_SIZE
];
144 * Set if a transaction has to be aborted but the attempt to roll
145 * back to the previous (good) transaction failed. The only
146 * metadata operation permissible in this state is the closing of
152 * Metadata format 2 fields.
154 dm_block_t dirty_root
;
155 struct dm_disk_bitset dirty_info
;
158 * These structures are used when loading metadata. They're too
159 * big to put on the stack.
161 struct dm_array_cursor mapping_cursor
;
162 struct dm_array_cursor hint_cursor
;
163 struct dm_bitset_cursor dirty_cursor
;
166 /*-------------------------------------------------------------------
167 * superblock validator
168 *-----------------------------------------------------------------*/
170 #define SUPERBLOCK_CSUM_XOR 9031977
172 static void sb_prepare_for_write(struct dm_block_validator
*v
,
174 size_t sb_block_size
)
176 struct cache_disk_superblock
*disk_super
= dm_block_data(b
);
178 disk_super
->blocknr
= cpu_to_le64(dm_block_location(b
));
179 disk_super
->csum
= cpu_to_le32(dm_bm_checksum(&disk_super
->flags
,
180 sb_block_size
- sizeof(__le32
),
181 SUPERBLOCK_CSUM_XOR
));
184 static int check_metadata_version(struct cache_disk_superblock
*disk_super
)
186 uint32_t metadata_version
= le32_to_cpu(disk_super
->version
);
188 if (metadata_version
< MIN_CACHE_VERSION
|| metadata_version
> MAX_CACHE_VERSION
) {
189 DMERR("Cache metadata version %u found, but only versions between %u and %u supported.",
190 metadata_version
, MIN_CACHE_VERSION
, MAX_CACHE_VERSION
);
197 static int sb_check(struct dm_block_validator
*v
,
199 size_t sb_block_size
)
201 struct cache_disk_superblock
*disk_super
= dm_block_data(b
);
204 if (dm_block_location(b
) != le64_to_cpu(disk_super
->blocknr
)) {
205 DMERR("sb_check failed: blocknr %llu: wanted %llu",
206 le64_to_cpu(disk_super
->blocknr
),
207 (unsigned long long)dm_block_location(b
));
211 if (le64_to_cpu(disk_super
->magic
) != CACHE_SUPERBLOCK_MAGIC
) {
212 DMERR("sb_check failed: magic %llu: wanted %llu",
213 le64_to_cpu(disk_super
->magic
),
214 (unsigned long long)CACHE_SUPERBLOCK_MAGIC
);
218 csum_le
= cpu_to_le32(dm_bm_checksum(&disk_super
->flags
,
219 sb_block_size
- sizeof(__le32
),
220 SUPERBLOCK_CSUM_XOR
));
221 if (csum_le
!= disk_super
->csum
) {
222 DMERR("sb_check failed: csum %u: wanted %u",
223 le32_to_cpu(csum_le
), le32_to_cpu(disk_super
->csum
));
227 return check_metadata_version(disk_super
);
230 static struct dm_block_validator sb_validator
= {
231 .name
= "superblock",
232 .prepare_for_write
= sb_prepare_for_write
,
236 /*----------------------------------------------------------------*/
238 static int superblock_read_lock(struct dm_cache_metadata
*cmd
,
239 struct dm_block
**sblock
)
241 return dm_bm_read_lock(cmd
->bm
, CACHE_SUPERBLOCK_LOCATION
,
242 &sb_validator
, sblock
);
245 static int superblock_lock_zero(struct dm_cache_metadata
*cmd
,
246 struct dm_block
**sblock
)
248 return dm_bm_write_lock_zero(cmd
->bm
, CACHE_SUPERBLOCK_LOCATION
,
249 &sb_validator
, sblock
);
252 static int superblock_lock(struct dm_cache_metadata
*cmd
,
253 struct dm_block
**sblock
)
255 return dm_bm_write_lock(cmd
->bm
, CACHE_SUPERBLOCK_LOCATION
,
256 &sb_validator
, sblock
);
259 /*----------------------------------------------------------------*/
261 static int __superblock_all_zeroes(struct dm_block_manager
*bm
, bool *result
)
266 __le64
*data_le
, zero
= cpu_to_le64(0);
267 unsigned sb_block_size
= dm_bm_block_size(bm
) / sizeof(__le64
);
270 * We can't use a validator here - it may be all zeroes.
272 r
= dm_bm_read_lock(bm
, CACHE_SUPERBLOCK_LOCATION
, NULL
, &b
);
276 data_le
= dm_block_data(b
);
278 for (i
= 0; i
< sb_block_size
; i
++) {
279 if (data_le
[i
] != zero
) {
290 static void __setup_mapping_info(struct dm_cache_metadata
*cmd
)
292 struct dm_btree_value_type vt
;
295 vt
.size
= sizeof(__le64
);
299 dm_array_info_init(&cmd
->info
, cmd
->tm
, &vt
);
301 if (cmd
->policy_hint_size
) {
302 vt
.size
= sizeof(__le32
);
303 dm_array_info_init(&cmd
->hint_info
, cmd
->tm
, &vt
);
307 static int __save_sm_root(struct dm_cache_metadata
*cmd
)
312 r
= dm_sm_root_size(cmd
->metadata_sm
, &metadata_len
);
316 return dm_sm_copy_root(cmd
->metadata_sm
, &cmd
->metadata_space_map_root
,
320 static void __copy_sm_root(struct dm_cache_metadata
*cmd
,
321 struct cache_disk_superblock
*disk_super
)
323 memcpy(&disk_super
->metadata_space_map_root
,
324 &cmd
->metadata_space_map_root
,
325 sizeof(cmd
->metadata_space_map_root
));
328 static bool separate_dirty_bits(struct dm_cache_metadata
*cmd
)
330 return cmd
->version
>= 2;
333 static int __write_initial_superblock(struct dm_cache_metadata
*cmd
)
336 struct dm_block
*sblock
;
337 struct cache_disk_superblock
*disk_super
;
338 sector_t bdev_size
= i_size_read(cmd
->bdev
->bd_inode
) >> SECTOR_SHIFT
;
340 /* FIXME: see if we can lose the max sectors limit */
341 if (bdev_size
> DM_CACHE_METADATA_MAX_SECTORS
)
342 bdev_size
= DM_CACHE_METADATA_MAX_SECTORS
;
344 r
= dm_tm_pre_commit(cmd
->tm
);
349 * dm_sm_copy_root() can fail. So we need to do it before we start
350 * updating the superblock.
352 r
= __save_sm_root(cmd
);
356 r
= superblock_lock_zero(cmd
, &sblock
);
360 disk_super
= dm_block_data(sblock
);
361 disk_super
->flags
= 0;
362 memset(disk_super
->uuid
, 0, sizeof(disk_super
->uuid
));
363 disk_super
->magic
= cpu_to_le64(CACHE_SUPERBLOCK_MAGIC
);
364 disk_super
->version
= cpu_to_le32(cmd
->version
);
365 memset(disk_super
->policy_name
, 0, sizeof(disk_super
->policy_name
));
366 memset(disk_super
->policy_version
, 0, sizeof(disk_super
->policy_version
));
367 disk_super
->policy_hint_size
= 0;
369 __copy_sm_root(cmd
, disk_super
);
371 disk_super
->mapping_root
= cpu_to_le64(cmd
->root
);
372 disk_super
->hint_root
= cpu_to_le64(cmd
->hint_root
);
373 disk_super
->discard_root
= cpu_to_le64(cmd
->discard_root
);
374 disk_super
->discard_block_size
= cpu_to_le64(cmd
->discard_block_size
);
375 disk_super
->discard_nr_blocks
= cpu_to_le64(from_dblock(cmd
->discard_nr_blocks
));
376 disk_super
->metadata_block_size
= cpu_to_le32(DM_CACHE_METADATA_BLOCK_SIZE
);
377 disk_super
->data_block_size
= cpu_to_le32(cmd
->data_block_size
);
378 disk_super
->cache_blocks
= cpu_to_le32(0);
380 disk_super
->read_hits
= cpu_to_le32(0);
381 disk_super
->read_misses
= cpu_to_le32(0);
382 disk_super
->write_hits
= cpu_to_le32(0);
383 disk_super
->write_misses
= cpu_to_le32(0);
385 if (separate_dirty_bits(cmd
))
386 disk_super
->dirty_root
= cpu_to_le64(cmd
->dirty_root
);
388 return dm_tm_commit(cmd
->tm
, sblock
);
391 static int __format_metadata(struct dm_cache_metadata
*cmd
)
395 r
= dm_tm_create_with_sm(cmd
->bm
, CACHE_SUPERBLOCK_LOCATION
,
396 &cmd
->tm
, &cmd
->metadata_sm
);
398 DMERR("tm_create_with_sm failed");
402 __setup_mapping_info(cmd
);
404 r
= dm_array_empty(&cmd
->info
, &cmd
->root
);
408 if (separate_dirty_bits(cmd
)) {
409 dm_disk_bitset_init(cmd
->tm
, &cmd
->dirty_info
);
410 r
= dm_bitset_empty(&cmd
->dirty_info
, &cmd
->dirty_root
);
415 dm_disk_bitset_init(cmd
->tm
, &cmd
->discard_info
);
416 r
= dm_bitset_empty(&cmd
->discard_info
, &cmd
->discard_root
);
420 cmd
->discard_block_size
= 0;
421 cmd
->discard_nr_blocks
= 0;
423 r
= __write_initial_superblock(cmd
);
427 cmd
->clean_when_opened
= true;
431 dm_tm_destroy(cmd
->tm
);
432 dm_sm_destroy(cmd
->metadata_sm
);
437 static int __check_incompat_features(struct cache_disk_superblock
*disk_super
,
438 struct dm_cache_metadata
*cmd
)
440 uint32_t incompat_flags
, features
;
442 incompat_flags
= le32_to_cpu(disk_super
->incompat_flags
);
443 features
= incompat_flags
& ~DM_CACHE_FEATURE_INCOMPAT_SUPP
;
445 DMERR("could not access metadata due to unsupported optional features (%lx).",
446 (unsigned long)features
);
451 * Check for read-only metadata to skip the following RDWR checks.
453 if (get_disk_ro(cmd
->bdev
->bd_disk
))
456 features
= le32_to_cpu(disk_super
->compat_ro_flags
) & ~DM_CACHE_FEATURE_COMPAT_RO_SUPP
;
458 DMERR("could not access metadata RDWR due to unsupported optional features (%lx).",
459 (unsigned long)features
);
466 static int __open_metadata(struct dm_cache_metadata
*cmd
)
469 struct dm_block
*sblock
;
470 struct cache_disk_superblock
*disk_super
;
471 unsigned long sb_flags
;
473 r
= superblock_read_lock(cmd
, &sblock
);
475 DMERR("couldn't read lock superblock");
479 disk_super
= dm_block_data(sblock
);
481 /* Verify the data block size hasn't changed */
482 if (le32_to_cpu(disk_super
->data_block_size
) != cmd
->data_block_size
) {
483 DMERR("changing the data block size (from %u to %llu) is not supported",
484 le32_to_cpu(disk_super
->data_block_size
),
485 (unsigned long long)cmd
->data_block_size
);
490 r
= __check_incompat_features(disk_super
, cmd
);
494 r
= dm_tm_open_with_sm(cmd
->bm
, CACHE_SUPERBLOCK_LOCATION
,
495 disk_super
->metadata_space_map_root
,
496 sizeof(disk_super
->metadata_space_map_root
),
497 &cmd
->tm
, &cmd
->metadata_sm
);
499 DMERR("tm_open_with_sm failed");
503 __setup_mapping_info(cmd
);
504 dm_disk_bitset_init(cmd
->tm
, &cmd
->dirty_info
);
505 dm_disk_bitset_init(cmd
->tm
, &cmd
->discard_info
);
506 sb_flags
= le32_to_cpu(disk_super
->flags
);
507 cmd
->clean_when_opened
= test_bit(CLEAN_SHUTDOWN
, &sb_flags
);
508 dm_bm_unlock(sblock
);
513 dm_bm_unlock(sblock
);
517 static int __open_or_format_metadata(struct dm_cache_metadata
*cmd
,
521 bool unformatted
= false;
523 r
= __superblock_all_zeroes(cmd
->bm
, &unformatted
);
528 return format_device
? __format_metadata(cmd
) : -EPERM
;
530 return __open_metadata(cmd
);
533 static int __create_persistent_data_objects(struct dm_cache_metadata
*cmd
,
534 bool may_format_device
)
537 cmd
->bm
= dm_block_manager_create(cmd
->bdev
, DM_CACHE_METADATA_BLOCK_SIZE
<< SECTOR_SHIFT
,
538 CACHE_METADATA_CACHE_SIZE
,
539 CACHE_MAX_CONCURRENT_LOCKS
);
540 if (IS_ERR(cmd
->bm
)) {
541 DMERR("could not create block manager");
542 return PTR_ERR(cmd
->bm
);
545 r
= __open_or_format_metadata(cmd
, may_format_device
);
547 dm_block_manager_destroy(cmd
->bm
);
552 static void __destroy_persistent_data_objects(struct dm_cache_metadata
*cmd
)
554 dm_sm_destroy(cmd
->metadata_sm
);
555 dm_tm_destroy(cmd
->tm
);
556 dm_block_manager_destroy(cmd
->bm
);
559 typedef unsigned long (*flags_mutator
)(unsigned long);
561 static void update_flags(struct cache_disk_superblock
*disk_super
,
562 flags_mutator mutator
)
564 uint32_t sb_flags
= mutator(le32_to_cpu(disk_super
->flags
));
565 disk_super
->flags
= cpu_to_le32(sb_flags
);
568 static unsigned long set_clean_shutdown(unsigned long flags
)
570 set_bit(CLEAN_SHUTDOWN
, &flags
);
574 static unsigned long clear_clean_shutdown(unsigned long flags
)
576 clear_bit(CLEAN_SHUTDOWN
, &flags
);
580 static void read_superblock_fields(struct dm_cache_metadata
*cmd
,
581 struct cache_disk_superblock
*disk_super
)
583 cmd
->version
= le32_to_cpu(disk_super
->version
);
584 cmd
->flags
= le32_to_cpu(disk_super
->flags
);
585 cmd
->root
= le64_to_cpu(disk_super
->mapping_root
);
586 cmd
->hint_root
= le64_to_cpu(disk_super
->hint_root
);
587 cmd
->discard_root
= le64_to_cpu(disk_super
->discard_root
);
588 cmd
->discard_block_size
= le64_to_cpu(disk_super
->discard_block_size
);
589 cmd
->discard_nr_blocks
= to_dblock(le64_to_cpu(disk_super
->discard_nr_blocks
));
590 cmd
->data_block_size
= le32_to_cpu(disk_super
->data_block_size
);
591 cmd
->cache_blocks
= to_cblock(le32_to_cpu(disk_super
->cache_blocks
));
592 strncpy(cmd
->policy_name
, disk_super
->policy_name
, sizeof(cmd
->policy_name
));
593 cmd
->policy_version
[0] = le32_to_cpu(disk_super
->policy_version
[0]);
594 cmd
->policy_version
[1] = le32_to_cpu(disk_super
->policy_version
[1]);
595 cmd
->policy_version
[2] = le32_to_cpu(disk_super
->policy_version
[2]);
596 cmd
->policy_hint_size
= le32_to_cpu(disk_super
->policy_hint_size
);
598 cmd
->stats
.read_hits
= le32_to_cpu(disk_super
->read_hits
);
599 cmd
->stats
.read_misses
= le32_to_cpu(disk_super
->read_misses
);
600 cmd
->stats
.write_hits
= le32_to_cpu(disk_super
->write_hits
);
601 cmd
->stats
.write_misses
= le32_to_cpu(disk_super
->write_misses
);
603 if (separate_dirty_bits(cmd
))
604 cmd
->dirty_root
= le64_to_cpu(disk_super
->dirty_root
);
606 cmd
->changed
= false;
610 * The mutator updates the superblock flags.
612 static int __begin_transaction_flags(struct dm_cache_metadata
*cmd
,
613 flags_mutator mutator
)
616 struct cache_disk_superblock
*disk_super
;
617 struct dm_block
*sblock
;
619 r
= superblock_lock(cmd
, &sblock
);
623 disk_super
= dm_block_data(sblock
);
624 update_flags(disk_super
, mutator
);
625 read_superblock_fields(cmd
, disk_super
);
626 dm_bm_unlock(sblock
);
628 return dm_bm_flush(cmd
->bm
);
631 static int __begin_transaction(struct dm_cache_metadata
*cmd
)
634 struct cache_disk_superblock
*disk_super
;
635 struct dm_block
*sblock
;
638 * We re-read the superblock every time. Shouldn't need to do this
641 r
= superblock_read_lock(cmd
, &sblock
);
645 disk_super
= dm_block_data(sblock
);
646 read_superblock_fields(cmd
, disk_super
);
647 dm_bm_unlock(sblock
);
652 static int __commit_transaction(struct dm_cache_metadata
*cmd
,
653 flags_mutator mutator
)
656 struct cache_disk_superblock
*disk_super
;
657 struct dm_block
*sblock
;
660 * We need to know if the cache_disk_superblock exceeds a 512-byte sector.
662 BUILD_BUG_ON(sizeof(struct cache_disk_superblock
) > 512);
664 if (separate_dirty_bits(cmd
)) {
665 r
= dm_bitset_flush(&cmd
->dirty_info
, cmd
->dirty_root
,
671 r
= dm_bitset_flush(&cmd
->discard_info
, cmd
->discard_root
,
676 r
= dm_tm_pre_commit(cmd
->tm
);
680 r
= __save_sm_root(cmd
);
684 r
= superblock_lock(cmd
, &sblock
);
688 disk_super
= dm_block_data(sblock
);
690 disk_super
->flags
= cpu_to_le32(cmd
->flags
);
692 update_flags(disk_super
, mutator
);
694 disk_super
->mapping_root
= cpu_to_le64(cmd
->root
);
695 if (separate_dirty_bits(cmd
))
696 disk_super
->dirty_root
= cpu_to_le64(cmd
->dirty_root
);
697 disk_super
->hint_root
= cpu_to_le64(cmd
->hint_root
);
698 disk_super
->discard_root
= cpu_to_le64(cmd
->discard_root
);
699 disk_super
->discard_block_size
= cpu_to_le64(cmd
->discard_block_size
);
700 disk_super
->discard_nr_blocks
= cpu_to_le64(from_dblock(cmd
->discard_nr_blocks
));
701 disk_super
->cache_blocks
= cpu_to_le32(from_cblock(cmd
->cache_blocks
));
702 strncpy(disk_super
->policy_name
, cmd
->policy_name
, sizeof(disk_super
->policy_name
));
703 disk_super
->policy_version
[0] = cpu_to_le32(cmd
->policy_version
[0]);
704 disk_super
->policy_version
[1] = cpu_to_le32(cmd
->policy_version
[1]);
705 disk_super
->policy_version
[2] = cpu_to_le32(cmd
->policy_version
[2]);
707 disk_super
->read_hits
= cpu_to_le32(cmd
->stats
.read_hits
);
708 disk_super
->read_misses
= cpu_to_le32(cmd
->stats
.read_misses
);
709 disk_super
->write_hits
= cpu_to_le32(cmd
->stats
.write_hits
);
710 disk_super
->write_misses
= cpu_to_le32(cmd
->stats
.write_misses
);
711 __copy_sm_root(cmd
, disk_super
);
713 return dm_tm_commit(cmd
->tm
, sblock
);
716 /*----------------------------------------------------------------*/
719 * The mappings are held in a dm-array that has 64-bit values stored in
720 * little-endian format. The index is the cblock, the high 48bits of the
721 * value are the oblock and the low 16 bit the flags.
723 #define FLAGS_MASK ((1 << 16) - 1)
725 static __le64
pack_value(dm_oblock_t block
, unsigned flags
)
727 uint64_t value
= from_oblock(block
);
729 value
= value
| (flags
& FLAGS_MASK
);
730 return cpu_to_le64(value
);
733 static void unpack_value(__le64 value_le
, dm_oblock_t
*block
, unsigned *flags
)
735 uint64_t value
= le64_to_cpu(value_le
);
736 uint64_t b
= value
>> 16;
737 *block
= to_oblock(b
);
738 *flags
= value
& FLAGS_MASK
;
741 /*----------------------------------------------------------------*/
743 static struct dm_cache_metadata
*metadata_open(struct block_device
*bdev
,
744 sector_t data_block_size
,
745 bool may_format_device
,
746 size_t policy_hint_size
,
747 unsigned metadata_version
)
750 struct dm_cache_metadata
*cmd
;
752 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
754 DMERR("could not allocate metadata struct");
755 return ERR_PTR(-ENOMEM
);
758 cmd
->version
= metadata_version
;
759 atomic_set(&cmd
->ref_count
, 1);
760 init_rwsem(&cmd
->root_lock
);
762 cmd
->data_block_size
= data_block_size
;
763 cmd
->cache_blocks
= 0;
764 cmd
->policy_hint_size
= policy_hint_size
;
766 cmd
->fail_io
= false;
768 r
= __create_persistent_data_objects(cmd
, may_format_device
);
774 r
= __begin_transaction_flags(cmd
, clear_clean_shutdown
);
776 dm_cache_metadata_close(cmd
);
784 * We keep a little list of ref counted metadata objects to prevent two
785 * different target instances creating separate bufio instances. This is
786 * an issue if a table is reloaded before the suspend.
788 static DEFINE_MUTEX(table_lock
);
789 static LIST_HEAD(table
);
791 static struct dm_cache_metadata
*lookup(struct block_device
*bdev
)
793 struct dm_cache_metadata
*cmd
;
795 list_for_each_entry(cmd
, &table
, list
)
796 if (cmd
->bdev
== bdev
) {
797 atomic_inc(&cmd
->ref_count
);
804 static struct dm_cache_metadata
*lookup_or_open(struct block_device
*bdev
,
805 sector_t data_block_size
,
806 bool may_format_device
,
807 size_t policy_hint_size
,
808 unsigned metadata_version
)
810 struct dm_cache_metadata
*cmd
, *cmd2
;
812 mutex_lock(&table_lock
);
814 mutex_unlock(&table_lock
);
819 cmd
= metadata_open(bdev
, data_block_size
, may_format_device
,
820 policy_hint_size
, metadata_version
);
822 mutex_lock(&table_lock
);
825 mutex_unlock(&table_lock
);
826 __destroy_persistent_data_objects(cmd
);
830 list_add(&cmd
->list
, &table
);
831 mutex_unlock(&table_lock
);
837 static bool same_params(struct dm_cache_metadata
*cmd
, sector_t data_block_size
)
839 if (cmd
->data_block_size
!= data_block_size
) {
840 DMERR("data_block_size (%llu) different from that in metadata (%llu)",
841 (unsigned long long) data_block_size
,
842 (unsigned long long) cmd
->data_block_size
);
849 struct dm_cache_metadata
*dm_cache_metadata_open(struct block_device
*bdev
,
850 sector_t data_block_size
,
851 bool may_format_device
,
852 size_t policy_hint_size
,
853 unsigned metadata_version
)
855 struct dm_cache_metadata
*cmd
= lookup_or_open(bdev
, data_block_size
, may_format_device
,
856 policy_hint_size
, metadata_version
);
858 if (!IS_ERR(cmd
) && !same_params(cmd
, data_block_size
)) {
859 dm_cache_metadata_close(cmd
);
860 return ERR_PTR(-EINVAL
);
866 void dm_cache_metadata_close(struct dm_cache_metadata
*cmd
)
868 if (atomic_dec_and_test(&cmd
->ref_count
)) {
869 mutex_lock(&table_lock
);
870 list_del(&cmd
->list
);
871 mutex_unlock(&table_lock
);
874 __destroy_persistent_data_objects(cmd
);
880 * Checks that the given cache block is either unmapped or clean.
882 static int block_clean_combined_dirty(struct dm_cache_metadata
*cmd
, dm_cblock_t b
,
890 r
= dm_array_get_value(&cmd
->info
, cmd
->root
, from_cblock(b
), &value
);
894 unpack_value(value
, &ob
, &flags
);
895 *result
= !((flags
& M_VALID
) && (flags
& M_DIRTY
));
900 static int blocks_are_clean_combined_dirty(struct dm_cache_metadata
*cmd
,
901 dm_cblock_t begin
, dm_cblock_t end
,
907 while (begin
!= end
) {
908 r
= block_clean_combined_dirty(cmd
, begin
, result
);
910 DMERR("block_clean_combined_dirty failed");
915 DMERR("cache block %llu is dirty",
916 (unsigned long long) from_cblock(begin
));
920 begin
= to_cblock(from_cblock(begin
) + 1);
926 static int blocks_are_clean_separate_dirty(struct dm_cache_metadata
*cmd
,
927 dm_cblock_t begin
, dm_cblock_t end
,
934 r
= dm_bitset_cursor_begin(&cmd
->dirty_info
, cmd
->dirty_root
,
935 from_cblock(begin
), &cmd
->dirty_cursor
);
937 DMERR("%s: dm_bitset_cursor_begin for dirty failed", __func__
);
941 r
= dm_bitset_cursor_skip(&cmd
->dirty_cursor
, from_cblock(begin
));
943 DMERR("%s: dm_bitset_cursor_skip for dirty failed", __func__
);
944 dm_bitset_cursor_end(&cmd
->dirty_cursor
);
948 while (begin
!= end
) {
950 * We assume that unmapped blocks have their dirty bit
953 dirty_flag
= dm_bitset_cursor_get_value(&cmd
->dirty_cursor
);
955 DMERR("%s: cache block %llu is dirty", __func__
,
956 (unsigned long long) from_cblock(begin
));
957 dm_bitset_cursor_end(&cmd
->dirty_cursor
);
962 r
= dm_bitset_cursor_next(&cmd
->dirty_cursor
);
964 DMERR("%s: dm_bitset_cursor_next for dirty failed", __func__
);
965 dm_bitset_cursor_end(&cmd
->dirty_cursor
);
969 begin
= to_cblock(from_cblock(begin
) + 1);
972 dm_bitset_cursor_end(&cmd
->dirty_cursor
);
977 static int blocks_are_unmapped_or_clean(struct dm_cache_metadata
*cmd
,
978 dm_cblock_t begin
, dm_cblock_t end
,
981 if (separate_dirty_bits(cmd
))
982 return blocks_are_clean_separate_dirty(cmd
, begin
, end
, result
);
984 return blocks_are_clean_combined_dirty(cmd
, begin
, end
, result
);
987 static bool cmd_write_lock(struct dm_cache_metadata
*cmd
)
989 down_write(&cmd
->root_lock
);
990 if (cmd
->fail_io
|| dm_bm_is_read_only(cmd
->bm
)) {
991 up_write(&cmd
->root_lock
);
997 #define WRITE_LOCK(cmd) \
999 if (!cmd_write_lock((cmd))) \
1003 #define WRITE_LOCK_VOID(cmd) \
1005 if (!cmd_write_lock((cmd))) \
1009 #define WRITE_UNLOCK(cmd) \
1010 up_write(&(cmd)->root_lock)
1012 static bool cmd_read_lock(struct dm_cache_metadata
*cmd
)
1014 down_read(&cmd
->root_lock
);
1016 up_read(&cmd
->root_lock
);
1022 #define READ_LOCK(cmd) \
1024 if (!cmd_read_lock((cmd))) \
1028 #define READ_LOCK_VOID(cmd) \
1030 if (!cmd_read_lock((cmd))) \
1034 #define READ_UNLOCK(cmd) \
1035 up_read(&(cmd)->root_lock)
1037 int dm_cache_resize(struct dm_cache_metadata
*cmd
, dm_cblock_t new_cache_size
)
1041 __le64 null_mapping
= pack_value(0, 0);
1044 __dm_bless_for_disk(&null_mapping
);
1046 if (from_cblock(new_cache_size
) < from_cblock(cmd
->cache_blocks
)) {
1047 r
= blocks_are_unmapped_or_clean(cmd
, new_cache_size
, cmd
->cache_blocks
, &clean
);
1049 __dm_unbless_for_disk(&null_mapping
);
1054 DMERR("unable to shrink cache due to dirty blocks");
1056 __dm_unbless_for_disk(&null_mapping
);
1061 r
= dm_array_resize(&cmd
->info
, cmd
->root
, from_cblock(cmd
->cache_blocks
),
1062 from_cblock(new_cache_size
),
1063 &null_mapping
, &cmd
->root
);
1067 if (separate_dirty_bits(cmd
)) {
1068 r
= dm_bitset_resize(&cmd
->dirty_info
, cmd
->dirty_root
,
1069 from_cblock(cmd
->cache_blocks
), from_cblock(new_cache_size
),
1070 false, &cmd
->dirty_root
);
1075 cmd
->cache_blocks
= new_cache_size
;
1076 cmd
->changed
= true;
1084 int dm_cache_discard_bitset_resize(struct dm_cache_metadata
*cmd
,
1085 sector_t discard_block_size
,
1086 dm_dblock_t new_nr_entries
)
1091 r
= dm_bitset_resize(&cmd
->discard_info
,
1093 from_dblock(cmd
->discard_nr_blocks
),
1094 from_dblock(new_nr_entries
),
1095 false, &cmd
->discard_root
);
1097 cmd
->discard_block_size
= discard_block_size
;
1098 cmd
->discard_nr_blocks
= new_nr_entries
;
1101 cmd
->changed
= true;
1107 static int __set_discard(struct dm_cache_metadata
*cmd
, dm_dblock_t b
)
1109 return dm_bitset_set_bit(&cmd
->discard_info
, cmd
->discard_root
,
1110 from_dblock(b
), &cmd
->discard_root
);
1113 static int __clear_discard(struct dm_cache_metadata
*cmd
, dm_dblock_t b
)
1115 return dm_bitset_clear_bit(&cmd
->discard_info
, cmd
->discard_root
,
1116 from_dblock(b
), &cmd
->discard_root
);
1119 static int __discard(struct dm_cache_metadata
*cmd
,
1120 dm_dblock_t dblock
, bool discard
)
1124 r
= (discard
? __set_discard
: __clear_discard
)(cmd
, dblock
);
1128 cmd
->changed
= true;
1132 int dm_cache_set_discard(struct dm_cache_metadata
*cmd
,
1133 dm_dblock_t dblock
, bool discard
)
1138 r
= __discard(cmd
, dblock
, discard
);
1144 static int __load_discards(struct dm_cache_metadata
*cmd
,
1145 load_discard_fn fn
, void *context
)
1149 struct dm_bitset_cursor c
;
1151 if (from_dblock(cmd
->discard_nr_blocks
) == 0)
1155 if (cmd
->clean_when_opened
) {
1156 r
= dm_bitset_flush(&cmd
->discard_info
, cmd
->discard_root
, &cmd
->discard_root
);
1160 r
= dm_bitset_cursor_begin(&cmd
->discard_info
, cmd
->discard_root
,
1161 from_dblock(cmd
->discard_nr_blocks
), &c
);
1165 for (b
= 0; b
< from_dblock(cmd
->discard_nr_blocks
); b
++) {
1166 r
= fn(context
, cmd
->discard_block_size
, to_dblock(b
),
1167 dm_bitset_cursor_get_value(&c
));
1172 dm_bitset_cursor_end(&c
);
1175 for (b
= 0; b
< from_dblock(cmd
->discard_nr_blocks
); b
++) {
1176 r
= fn(context
, cmd
->discard_block_size
, to_dblock(b
), false);
1185 int dm_cache_load_discards(struct dm_cache_metadata
*cmd
,
1186 load_discard_fn fn
, void *context
)
1191 r
= __load_discards(cmd
, fn
, context
);
1197 int dm_cache_size(struct dm_cache_metadata
*cmd
, dm_cblock_t
*result
)
1200 *result
= cmd
->cache_blocks
;
1206 static int __remove(struct dm_cache_metadata
*cmd
, dm_cblock_t cblock
)
1209 __le64 value
= pack_value(0, 0);
1211 __dm_bless_for_disk(&value
);
1212 r
= dm_array_set_value(&cmd
->info
, cmd
->root
, from_cblock(cblock
),
1213 &value
, &cmd
->root
);
1217 cmd
->changed
= true;
1221 int dm_cache_remove_mapping(struct dm_cache_metadata
*cmd
, dm_cblock_t cblock
)
1226 r
= __remove(cmd
, cblock
);
1232 static int __insert(struct dm_cache_metadata
*cmd
,
1233 dm_cblock_t cblock
, dm_oblock_t oblock
)
1236 __le64 value
= pack_value(oblock
, M_VALID
);
1237 __dm_bless_for_disk(&value
);
1239 r
= dm_array_set_value(&cmd
->info
, cmd
->root
, from_cblock(cblock
),
1240 &value
, &cmd
->root
);
1244 cmd
->changed
= true;
1248 int dm_cache_insert_mapping(struct dm_cache_metadata
*cmd
,
1249 dm_cblock_t cblock
, dm_oblock_t oblock
)
1254 r
= __insert(cmd
, cblock
, oblock
);
1264 struct dm_cache_metadata
*cmd
;
1265 bool respect_dirty_flags
;
1269 static bool policy_unchanged(struct dm_cache_metadata
*cmd
,
1270 struct dm_cache_policy
*policy
)
1272 const char *policy_name
= dm_cache_policy_get_name(policy
);
1273 const unsigned *policy_version
= dm_cache_policy_get_version(policy
);
1274 size_t policy_hint_size
= dm_cache_policy_get_hint_size(policy
);
1277 * Ensure policy names match.
1279 if (strncmp(cmd
->policy_name
, policy_name
, sizeof(cmd
->policy_name
)))
1283 * Ensure policy major versions match.
1285 if (cmd
->policy_version
[0] != policy_version
[0])
1289 * Ensure policy hint sizes match.
1291 if (cmd
->policy_hint_size
!= policy_hint_size
)
1297 static bool hints_array_initialized(struct dm_cache_metadata
*cmd
)
1299 return cmd
->hint_root
&& cmd
->policy_hint_size
;
1302 static bool hints_array_available(struct dm_cache_metadata
*cmd
,
1303 struct dm_cache_policy
*policy
)
1305 return cmd
->clean_when_opened
&& policy_unchanged(cmd
, policy
) &&
1306 hints_array_initialized(cmd
);
1309 static int __load_mapping_v1(struct dm_cache_metadata
*cmd
,
1310 uint64_t cb
, bool hints_valid
,
1311 struct dm_array_cursor
*mapping_cursor
,
1312 struct dm_array_cursor
*hint_cursor
,
1313 load_mapping_fn fn
, void *context
)
1320 __le64
*mapping_value_le
;
1321 __le32
*hint_value_le
;
1326 dm_array_cursor_get_value(mapping_cursor
, (void **) &mapping_value_le
);
1327 memcpy(&mapping
, mapping_value_le
, sizeof(mapping
));
1328 unpack_value(mapping
, &oblock
, &flags
);
1330 if (flags
& M_VALID
) {
1332 dm_array_cursor_get_value(hint_cursor
, (void **) &hint_value_le
);
1333 memcpy(&hint
, hint_value_le
, sizeof(hint
));
1336 r
= fn(context
, oblock
, to_cblock(cb
), flags
& M_DIRTY
,
1337 le32_to_cpu(hint
), hints_valid
);
1339 DMERR("policy couldn't load cache block %llu",
1340 (unsigned long long) from_cblock(to_cblock(cb
)));
1347 static int __load_mapping_v2(struct dm_cache_metadata
*cmd
,
1348 uint64_t cb
, bool hints_valid
,
1349 struct dm_array_cursor
*mapping_cursor
,
1350 struct dm_array_cursor
*hint_cursor
,
1351 struct dm_bitset_cursor
*dirty_cursor
,
1352 load_mapping_fn fn
, void *context
)
1359 __le64
*mapping_value_le
;
1360 __le32
*hint_value_le
;
1366 dm_array_cursor_get_value(mapping_cursor
, (void **) &mapping_value_le
);
1367 memcpy(&mapping
, mapping_value_le
, sizeof(mapping
));
1368 unpack_value(mapping
, &oblock
, &flags
);
1370 if (flags
& M_VALID
) {
1372 dm_array_cursor_get_value(hint_cursor
, (void **) &hint_value_le
);
1373 memcpy(&hint
, hint_value_le
, sizeof(hint
));
1376 dirty
= dm_bitset_cursor_get_value(dirty_cursor
);
1377 r
= fn(context
, oblock
, to_cblock(cb
), dirty
,
1378 le32_to_cpu(hint
), hints_valid
);
1380 DMERR("policy couldn't load cache block %llu",
1381 (unsigned long long) from_cblock(to_cblock(cb
)));
1388 static int __load_mappings(struct dm_cache_metadata
*cmd
,
1389 struct dm_cache_policy
*policy
,
1390 load_mapping_fn fn
, void *context
)
1395 bool hints_valid
= hints_array_available(cmd
, policy
);
1397 if (from_cblock(cmd
->cache_blocks
) == 0)
1401 r
= dm_array_cursor_begin(&cmd
->info
, cmd
->root
, &cmd
->mapping_cursor
);
1406 r
= dm_array_cursor_begin(&cmd
->hint_info
, cmd
->hint_root
, &cmd
->hint_cursor
);
1408 dm_array_cursor_end(&cmd
->mapping_cursor
);
1413 if (separate_dirty_bits(cmd
)) {
1414 r
= dm_bitset_cursor_begin(&cmd
->dirty_info
, cmd
->dirty_root
,
1415 from_cblock(cmd
->cache_blocks
),
1416 &cmd
->dirty_cursor
);
1418 dm_array_cursor_end(&cmd
->hint_cursor
);
1419 dm_array_cursor_end(&cmd
->mapping_cursor
);
1424 for (cb
= 0; ; cb
++) {
1425 if (separate_dirty_bits(cmd
))
1426 r
= __load_mapping_v2(cmd
, cb
, hints_valid
,
1427 &cmd
->mapping_cursor
,
1432 r
= __load_mapping_v1(cmd
, cb
, hints_valid
,
1433 &cmd
->mapping_cursor
, &cmd
->hint_cursor
,
1439 * We need to break out before we move the cursors.
1441 if (cb
>= (from_cblock(cmd
->cache_blocks
) - 1))
1444 r
= dm_array_cursor_next(&cmd
->mapping_cursor
);
1446 DMERR("dm_array_cursor_next for mapping failed");
1451 r
= dm_array_cursor_next(&cmd
->hint_cursor
);
1453 DMERR("dm_array_cursor_next for hint failed");
1458 if (separate_dirty_bits(cmd
)) {
1459 r
= dm_bitset_cursor_next(&cmd
->dirty_cursor
);
1461 DMERR("dm_bitset_cursor_next for dirty failed");
1467 dm_array_cursor_end(&cmd
->mapping_cursor
);
1469 dm_array_cursor_end(&cmd
->hint_cursor
);
1471 if (separate_dirty_bits(cmd
))
1472 dm_bitset_cursor_end(&cmd
->dirty_cursor
);
1477 int dm_cache_load_mappings(struct dm_cache_metadata
*cmd
,
1478 struct dm_cache_policy
*policy
,
1479 load_mapping_fn fn
, void *context
)
1484 r
= __load_mappings(cmd
, policy
, fn
, context
);
1490 static int __dump_mapping(void *context
, uint64_t cblock
, void *leaf
)
1497 memcpy(&value
, leaf
, sizeof(value
));
1498 unpack_value(value
, &oblock
, &flags
);
1503 static int __dump_mappings(struct dm_cache_metadata
*cmd
)
1505 return dm_array_walk(&cmd
->info
, cmd
->root
, __dump_mapping
, NULL
);
1508 void dm_cache_dump(struct dm_cache_metadata
*cmd
)
1510 READ_LOCK_VOID(cmd
);
1511 __dump_mappings(cmd
);
1515 int dm_cache_changed_this_transaction(struct dm_cache_metadata
*cmd
)
1526 static int __dirty(struct dm_cache_metadata
*cmd
, dm_cblock_t cblock
, bool dirty
)
1533 r
= dm_array_get_value(&cmd
->info
, cmd
->root
, from_cblock(cblock
), &value
);
1537 unpack_value(value
, &oblock
, &flags
);
1539 if (((flags
& M_DIRTY
) && dirty
) || (!(flags
& M_DIRTY
) && !dirty
))
1540 /* nothing to be done */
1543 value
= pack_value(oblock
, (flags
& ~M_DIRTY
) | (dirty
? M_DIRTY
: 0));
1544 __dm_bless_for_disk(&value
);
1546 r
= dm_array_set_value(&cmd
->info
, cmd
->root
, from_cblock(cblock
),
1547 &value
, &cmd
->root
);
1551 cmd
->changed
= true;
1556 static int __set_dirty_bits_v1(struct dm_cache_metadata
*cmd
, unsigned nr_bits
, unsigned long *bits
)
1560 for (i
= 0; i
< nr_bits
; i
++) {
1561 r
= __dirty(cmd
, to_cblock(i
), test_bit(i
, bits
));
1569 static int is_dirty_callback(uint32_t index
, bool *value
, void *context
)
1571 unsigned long *bits
= context
;
1572 *value
= test_bit(index
, bits
);
1576 static int __set_dirty_bits_v2(struct dm_cache_metadata
*cmd
, unsigned nr_bits
, unsigned long *bits
)
1580 /* nr_bits is really just a sanity check */
1581 if (nr_bits
!= from_cblock(cmd
->cache_blocks
)) {
1582 DMERR("dirty bitset is wrong size");
1586 r
= dm_bitset_del(&cmd
->dirty_info
, cmd
->dirty_root
);
1590 cmd
->changed
= true;
1591 return dm_bitset_new(&cmd
->dirty_info
, &cmd
->dirty_root
, nr_bits
, is_dirty_callback
, bits
);
1594 int dm_cache_set_dirty_bits(struct dm_cache_metadata
*cmd
,
1596 unsigned long *bits
)
1601 if (separate_dirty_bits(cmd
))
1602 r
= __set_dirty_bits_v2(cmd
, nr_bits
, bits
);
1604 r
= __set_dirty_bits_v1(cmd
, nr_bits
, bits
);
1610 void dm_cache_metadata_get_stats(struct dm_cache_metadata
*cmd
,
1611 struct dm_cache_statistics
*stats
)
1613 READ_LOCK_VOID(cmd
);
1614 *stats
= cmd
->stats
;
1618 void dm_cache_metadata_set_stats(struct dm_cache_metadata
*cmd
,
1619 struct dm_cache_statistics
*stats
)
1621 WRITE_LOCK_VOID(cmd
);
1622 cmd
->stats
= *stats
;
1626 int dm_cache_commit(struct dm_cache_metadata
*cmd
, bool clean_shutdown
)
1629 flags_mutator mutator
= (clean_shutdown
? set_clean_shutdown
:
1630 clear_clean_shutdown
);
1633 r
= __commit_transaction(cmd
, mutator
);
1637 r
= __begin_transaction(cmd
);
1644 int dm_cache_get_free_metadata_block_count(struct dm_cache_metadata
*cmd
,
1650 r
= dm_sm_get_nr_free(cmd
->metadata_sm
, result
);
1656 int dm_cache_get_metadata_dev_size(struct dm_cache_metadata
*cmd
,
1662 r
= dm_sm_get_nr_blocks(cmd
->metadata_sm
, result
);
1668 /*----------------------------------------------------------------*/
1670 static int get_hint(uint32_t index
, void *value_le
, void *context
)
1673 struct dm_cache_policy
*policy
= context
;
1675 value
= policy_get_hint(policy
, to_cblock(index
));
1676 *((__le32
*) value_le
) = cpu_to_le32(value
);
1682 * It's quicker to always delete the hint array, and recreate with
1685 static int write_hints(struct dm_cache_metadata
*cmd
, struct dm_cache_policy
*policy
)
1689 const char *policy_name
= dm_cache_policy_get_name(policy
);
1690 const unsigned *policy_version
= dm_cache_policy_get_version(policy
);
1692 if (!policy_name
[0] ||
1693 (strlen(policy_name
) > sizeof(cmd
->policy_name
) - 1))
1696 strncpy(cmd
->policy_name
, policy_name
, sizeof(cmd
->policy_name
));
1697 memcpy(cmd
->policy_version
, policy_version
, sizeof(cmd
->policy_version
));
1699 hint_size
= dm_cache_policy_get_hint_size(policy
);
1701 return 0; /* short-circuit hints initialization */
1702 cmd
->policy_hint_size
= hint_size
;
1704 if (cmd
->hint_root
) {
1705 r
= dm_array_del(&cmd
->hint_info
, cmd
->hint_root
);
1710 return dm_array_new(&cmd
->hint_info
, &cmd
->hint_root
,
1711 from_cblock(cmd
->cache_blocks
),
1715 int dm_cache_write_hints(struct dm_cache_metadata
*cmd
, struct dm_cache_policy
*policy
)
1720 r
= write_hints(cmd
, policy
);
1726 int dm_cache_metadata_all_clean(struct dm_cache_metadata
*cmd
, bool *result
)
1731 r
= blocks_are_unmapped_or_clean(cmd
, 0, cmd
->cache_blocks
, result
);
1737 void dm_cache_metadata_set_read_only(struct dm_cache_metadata
*cmd
)
1739 WRITE_LOCK_VOID(cmd
);
1740 dm_bm_set_read_only(cmd
->bm
);
1744 void dm_cache_metadata_set_read_write(struct dm_cache_metadata
*cmd
)
1746 WRITE_LOCK_VOID(cmd
);
1747 dm_bm_set_read_write(cmd
->bm
);
1751 int dm_cache_metadata_set_needs_check(struct dm_cache_metadata
*cmd
)
1754 struct dm_block
*sblock
;
1755 struct cache_disk_superblock
*disk_super
;
1758 set_bit(NEEDS_CHECK
, &cmd
->flags
);
1760 r
= superblock_lock(cmd
, &sblock
);
1762 DMERR("couldn't read superblock");
1766 disk_super
= dm_block_data(sblock
);
1767 disk_super
->flags
= cpu_to_le32(cmd
->flags
);
1769 dm_bm_unlock(sblock
);
1776 int dm_cache_metadata_needs_check(struct dm_cache_metadata
*cmd
, bool *result
)
1779 *result
= !!test_bit(NEEDS_CHECK
, &cmd
->flags
);
1785 int dm_cache_metadata_abort(struct dm_cache_metadata
*cmd
)
1790 __destroy_persistent_data_objects(cmd
);
1791 r
= __create_persistent_data_objects(cmd
, false);
1793 cmd
->fail_io
= true;