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>
16 #include <linux/refcount.h>
18 /*----------------------------------------------------------------*/
20 #define DM_MSG_PREFIX "cache metadata"
22 #define CACHE_SUPERBLOCK_MAGIC 06142003
23 #define CACHE_SUPERBLOCK_LOCATION 0
26 * defines a range of metadata versions that this module can handle.
28 #define MIN_CACHE_VERSION 1
29 #define MAX_CACHE_VERSION 2
32 * 3 for btree insert +
33 * 2 for btree lookup used within space map
35 #define CACHE_MAX_CONCURRENT_LOCKS 5
36 #define SPACE_MAP_ROOT_SIZE 128
38 enum superblock_flag_bits
{
39 /* for spotting crashes that would invalidate the dirty bitset */
41 /* metadata must be checked using the tools */
46 * Each mapping from cache block -> origin block carries a set of flags.
50 * A valid mapping. Because we're using an array we clear this
51 * flag for an non existant mapping.
56 * The data on the cache is different from that on the origin.
57 * This flag is only used by metadata format 1.
62 struct cache_disk_superblock
{
71 __u8 policy_name
[CACHE_POLICY_NAME_SIZE
];
72 __le32 policy_hint_size
;
74 __u8 metadata_space_map_root
[SPACE_MAP_ROOT_SIZE
];
79 __le64 discard_block_size
;
80 __le64 discard_nr_blocks
;
82 __le32 data_block_size
;
83 __le32 metadata_block_size
;
87 __le32 compat_ro_flags
;
88 __le32 incompat_flags
;
95 __le32 policy_version
[CACHE_POLICY_VERSION_SIZE
];
98 * Metadata format 2 fields.
103 struct dm_cache_metadata
{
104 refcount_t ref_count
;
105 struct list_head list
;
108 struct block_device
*bdev
;
109 struct dm_block_manager
*bm
;
110 struct dm_space_map
*metadata_sm
;
111 struct dm_transaction_manager
*tm
;
113 struct dm_array_info info
;
114 struct dm_array_info hint_info
;
115 struct dm_disk_bitset discard_info
;
117 struct rw_semaphore root_lock
;
120 dm_block_t hint_root
;
121 dm_block_t discard_root
;
123 sector_t discard_block_size
;
124 dm_dblock_t discard_nr_blocks
;
126 sector_t data_block_size
;
127 dm_cblock_t cache_blocks
;
129 bool clean_when_opened
:1;
131 char policy_name
[CACHE_POLICY_NAME_SIZE
];
132 unsigned policy_version
[CACHE_POLICY_VERSION_SIZE
];
133 size_t policy_hint_size
;
134 struct dm_cache_statistics stats
;
137 * Reading the space map root can fail, so we read it into this
138 * buffer before the superblock is locked and updated.
140 __u8 metadata_space_map_root
[SPACE_MAP_ROOT_SIZE
];
143 * Set if a transaction has to be aborted but the attempt to roll
144 * back to the previous (good) transaction failed. The only
145 * metadata operation permissible in this state is the closing of
151 * Metadata format 2 fields.
153 dm_block_t dirty_root
;
154 struct dm_disk_bitset dirty_info
;
157 * These structures are used when loading metadata. They're too
158 * big to put on the stack.
160 struct dm_array_cursor mapping_cursor
;
161 struct dm_array_cursor hint_cursor
;
162 struct dm_bitset_cursor dirty_cursor
;
165 /*-------------------------------------------------------------------
166 * superblock validator
167 *-----------------------------------------------------------------*/
169 #define SUPERBLOCK_CSUM_XOR 9031977
171 static void sb_prepare_for_write(struct dm_block_validator
*v
,
173 size_t sb_block_size
)
175 struct cache_disk_superblock
*disk_super
= dm_block_data(b
);
177 disk_super
->blocknr
= cpu_to_le64(dm_block_location(b
));
178 disk_super
->csum
= cpu_to_le32(dm_bm_checksum(&disk_super
->flags
,
179 sb_block_size
- sizeof(__le32
),
180 SUPERBLOCK_CSUM_XOR
));
183 static int check_metadata_version(struct cache_disk_superblock
*disk_super
)
185 uint32_t metadata_version
= le32_to_cpu(disk_super
->version
);
187 if (metadata_version
< MIN_CACHE_VERSION
|| metadata_version
> MAX_CACHE_VERSION
) {
188 DMERR("Cache metadata version %u found, but only versions between %u and %u supported.",
189 metadata_version
, MIN_CACHE_VERSION
, MAX_CACHE_VERSION
);
196 static int sb_check(struct dm_block_validator
*v
,
198 size_t sb_block_size
)
200 struct cache_disk_superblock
*disk_super
= dm_block_data(b
);
203 if (dm_block_location(b
) != le64_to_cpu(disk_super
->blocknr
)) {
204 DMERR("sb_check failed: blocknr %llu: wanted %llu",
205 le64_to_cpu(disk_super
->blocknr
),
206 (unsigned long long)dm_block_location(b
));
210 if (le64_to_cpu(disk_super
->magic
) != CACHE_SUPERBLOCK_MAGIC
) {
211 DMERR("sb_check failed: magic %llu: wanted %llu",
212 le64_to_cpu(disk_super
->magic
),
213 (unsigned long long)CACHE_SUPERBLOCK_MAGIC
);
217 csum_le
= cpu_to_le32(dm_bm_checksum(&disk_super
->flags
,
218 sb_block_size
- sizeof(__le32
),
219 SUPERBLOCK_CSUM_XOR
));
220 if (csum_le
!= disk_super
->csum
) {
221 DMERR("sb_check failed: csum %u: wanted %u",
222 le32_to_cpu(csum_le
), le32_to_cpu(disk_super
->csum
));
226 return check_metadata_version(disk_super
);
229 static struct dm_block_validator sb_validator
= {
230 .name
= "superblock",
231 .prepare_for_write
= sb_prepare_for_write
,
235 /*----------------------------------------------------------------*/
237 static int superblock_read_lock(struct dm_cache_metadata
*cmd
,
238 struct dm_block
**sblock
)
240 return dm_bm_read_lock(cmd
->bm
, CACHE_SUPERBLOCK_LOCATION
,
241 &sb_validator
, sblock
);
244 static int superblock_lock_zero(struct dm_cache_metadata
*cmd
,
245 struct dm_block
**sblock
)
247 return dm_bm_write_lock_zero(cmd
->bm
, CACHE_SUPERBLOCK_LOCATION
,
248 &sb_validator
, sblock
);
251 static int superblock_lock(struct dm_cache_metadata
*cmd
,
252 struct dm_block
**sblock
)
254 return dm_bm_write_lock(cmd
->bm
, CACHE_SUPERBLOCK_LOCATION
,
255 &sb_validator
, sblock
);
258 /*----------------------------------------------------------------*/
260 static int __superblock_all_zeroes(struct dm_block_manager
*bm
, bool *result
)
265 __le64
*data_le
, zero
= cpu_to_le64(0);
266 unsigned sb_block_size
= dm_bm_block_size(bm
) / sizeof(__le64
);
269 * We can't use a validator here - it may be all zeroes.
271 r
= dm_bm_read_lock(bm
, CACHE_SUPERBLOCK_LOCATION
, NULL
, &b
);
275 data_le
= dm_block_data(b
);
277 for (i
= 0; i
< sb_block_size
; i
++) {
278 if (data_le
[i
] != zero
) {
289 static void __setup_mapping_info(struct dm_cache_metadata
*cmd
)
291 struct dm_btree_value_type vt
;
294 vt
.size
= sizeof(__le64
);
298 dm_array_info_init(&cmd
->info
, cmd
->tm
, &vt
);
300 if (cmd
->policy_hint_size
) {
301 vt
.size
= sizeof(__le32
);
302 dm_array_info_init(&cmd
->hint_info
, cmd
->tm
, &vt
);
306 static int __save_sm_root(struct dm_cache_metadata
*cmd
)
311 r
= dm_sm_root_size(cmd
->metadata_sm
, &metadata_len
);
315 return dm_sm_copy_root(cmd
->metadata_sm
, &cmd
->metadata_space_map_root
,
319 static void __copy_sm_root(struct dm_cache_metadata
*cmd
,
320 struct cache_disk_superblock
*disk_super
)
322 memcpy(&disk_super
->metadata_space_map_root
,
323 &cmd
->metadata_space_map_root
,
324 sizeof(cmd
->metadata_space_map_root
));
327 static bool separate_dirty_bits(struct dm_cache_metadata
*cmd
)
329 return cmd
->version
>= 2;
332 static int __write_initial_superblock(struct dm_cache_metadata
*cmd
)
335 struct dm_block
*sblock
;
336 struct cache_disk_superblock
*disk_super
;
337 sector_t bdev_size
= i_size_read(cmd
->bdev
->bd_inode
) >> SECTOR_SHIFT
;
339 /* FIXME: see if we can lose the max sectors limit */
340 if (bdev_size
> DM_CACHE_METADATA_MAX_SECTORS
)
341 bdev_size
= DM_CACHE_METADATA_MAX_SECTORS
;
343 r
= dm_tm_pre_commit(cmd
->tm
);
348 * dm_sm_copy_root() can fail. So we need to do it before we start
349 * updating the superblock.
351 r
= __save_sm_root(cmd
);
355 r
= superblock_lock_zero(cmd
, &sblock
);
359 disk_super
= dm_block_data(sblock
);
360 disk_super
->flags
= 0;
361 memset(disk_super
->uuid
, 0, sizeof(disk_super
->uuid
));
362 disk_super
->magic
= cpu_to_le64(CACHE_SUPERBLOCK_MAGIC
);
363 disk_super
->version
= cpu_to_le32(cmd
->version
);
364 memset(disk_super
->policy_name
, 0, sizeof(disk_super
->policy_name
));
365 memset(disk_super
->policy_version
, 0, sizeof(disk_super
->policy_version
));
366 disk_super
->policy_hint_size
= 0;
368 __copy_sm_root(cmd
, disk_super
);
370 disk_super
->mapping_root
= cpu_to_le64(cmd
->root
);
371 disk_super
->hint_root
= cpu_to_le64(cmd
->hint_root
);
372 disk_super
->discard_root
= cpu_to_le64(cmd
->discard_root
);
373 disk_super
->discard_block_size
= cpu_to_le64(cmd
->discard_block_size
);
374 disk_super
->discard_nr_blocks
= cpu_to_le64(from_dblock(cmd
->discard_nr_blocks
));
375 disk_super
->metadata_block_size
= cpu_to_le32(DM_CACHE_METADATA_BLOCK_SIZE
);
376 disk_super
->data_block_size
= cpu_to_le32(cmd
->data_block_size
);
377 disk_super
->cache_blocks
= cpu_to_le32(0);
379 disk_super
->read_hits
= cpu_to_le32(0);
380 disk_super
->read_misses
= cpu_to_le32(0);
381 disk_super
->write_hits
= cpu_to_le32(0);
382 disk_super
->write_misses
= cpu_to_le32(0);
384 if (separate_dirty_bits(cmd
))
385 disk_super
->dirty_root
= cpu_to_le64(cmd
->dirty_root
);
387 return dm_tm_commit(cmd
->tm
, sblock
);
390 static int __format_metadata(struct dm_cache_metadata
*cmd
)
394 r
= dm_tm_create_with_sm(cmd
->bm
, CACHE_SUPERBLOCK_LOCATION
,
395 &cmd
->tm
, &cmd
->metadata_sm
);
397 DMERR("tm_create_with_sm failed");
401 __setup_mapping_info(cmd
);
403 r
= dm_array_empty(&cmd
->info
, &cmd
->root
);
407 if (separate_dirty_bits(cmd
)) {
408 dm_disk_bitset_init(cmd
->tm
, &cmd
->dirty_info
);
409 r
= dm_bitset_empty(&cmd
->dirty_info
, &cmd
->dirty_root
);
414 dm_disk_bitset_init(cmd
->tm
, &cmd
->discard_info
);
415 r
= dm_bitset_empty(&cmd
->discard_info
, &cmd
->discard_root
);
419 cmd
->discard_block_size
= 0;
420 cmd
->discard_nr_blocks
= 0;
422 r
= __write_initial_superblock(cmd
);
426 cmd
->clean_when_opened
= true;
430 dm_tm_destroy(cmd
->tm
);
431 dm_sm_destroy(cmd
->metadata_sm
);
436 static int __check_incompat_features(struct cache_disk_superblock
*disk_super
,
437 struct dm_cache_metadata
*cmd
)
439 uint32_t incompat_flags
, features
;
441 incompat_flags
= le32_to_cpu(disk_super
->incompat_flags
);
442 features
= incompat_flags
& ~DM_CACHE_FEATURE_INCOMPAT_SUPP
;
444 DMERR("could not access metadata due to unsupported optional features (%lx).",
445 (unsigned long)features
);
450 * Check for read-only metadata to skip the following RDWR checks.
452 if (get_disk_ro(cmd
->bdev
->bd_disk
))
455 features
= le32_to_cpu(disk_super
->compat_ro_flags
) & ~DM_CACHE_FEATURE_COMPAT_RO_SUPP
;
457 DMERR("could not access metadata RDWR due to unsupported optional features (%lx).",
458 (unsigned long)features
);
465 static int __open_metadata(struct dm_cache_metadata
*cmd
)
468 struct dm_block
*sblock
;
469 struct cache_disk_superblock
*disk_super
;
470 unsigned long sb_flags
;
472 r
= superblock_read_lock(cmd
, &sblock
);
474 DMERR("couldn't read lock superblock");
478 disk_super
= dm_block_data(sblock
);
480 /* Verify the data block size hasn't changed */
481 if (le32_to_cpu(disk_super
->data_block_size
) != cmd
->data_block_size
) {
482 DMERR("changing the data block size (from %u to %llu) is not supported",
483 le32_to_cpu(disk_super
->data_block_size
),
484 (unsigned long long)cmd
->data_block_size
);
489 r
= __check_incompat_features(disk_super
, cmd
);
493 r
= dm_tm_open_with_sm(cmd
->bm
, CACHE_SUPERBLOCK_LOCATION
,
494 disk_super
->metadata_space_map_root
,
495 sizeof(disk_super
->metadata_space_map_root
),
496 &cmd
->tm
, &cmd
->metadata_sm
);
498 DMERR("tm_open_with_sm failed");
502 __setup_mapping_info(cmd
);
503 dm_disk_bitset_init(cmd
->tm
, &cmd
->dirty_info
);
504 dm_disk_bitset_init(cmd
->tm
, &cmd
->discard_info
);
505 sb_flags
= le32_to_cpu(disk_super
->flags
);
506 cmd
->clean_when_opened
= test_bit(CLEAN_SHUTDOWN
, &sb_flags
);
507 dm_bm_unlock(sblock
);
512 dm_bm_unlock(sblock
);
516 static int __open_or_format_metadata(struct dm_cache_metadata
*cmd
,
520 bool unformatted
= false;
522 r
= __superblock_all_zeroes(cmd
->bm
, &unformatted
);
527 return format_device
? __format_metadata(cmd
) : -EPERM
;
529 return __open_metadata(cmd
);
532 static int __create_persistent_data_objects(struct dm_cache_metadata
*cmd
,
533 bool may_format_device
)
536 cmd
->bm
= dm_block_manager_create(cmd
->bdev
, DM_CACHE_METADATA_BLOCK_SIZE
<< SECTOR_SHIFT
,
537 CACHE_MAX_CONCURRENT_LOCKS
);
538 if (IS_ERR(cmd
->bm
)) {
539 DMERR("could not create block manager");
540 return PTR_ERR(cmd
->bm
);
543 r
= __open_or_format_metadata(cmd
, may_format_device
);
545 dm_block_manager_destroy(cmd
->bm
);
550 static void __destroy_persistent_data_objects(struct dm_cache_metadata
*cmd
)
552 dm_sm_destroy(cmd
->metadata_sm
);
553 dm_tm_destroy(cmd
->tm
);
554 dm_block_manager_destroy(cmd
->bm
);
557 typedef unsigned long (*flags_mutator
)(unsigned long);
559 static void update_flags(struct cache_disk_superblock
*disk_super
,
560 flags_mutator mutator
)
562 uint32_t sb_flags
= mutator(le32_to_cpu(disk_super
->flags
));
563 disk_super
->flags
= cpu_to_le32(sb_flags
);
566 static unsigned long set_clean_shutdown(unsigned long flags
)
568 set_bit(CLEAN_SHUTDOWN
, &flags
);
572 static unsigned long clear_clean_shutdown(unsigned long flags
)
574 clear_bit(CLEAN_SHUTDOWN
, &flags
);
578 static void read_superblock_fields(struct dm_cache_metadata
*cmd
,
579 struct cache_disk_superblock
*disk_super
)
581 cmd
->version
= le32_to_cpu(disk_super
->version
);
582 cmd
->flags
= le32_to_cpu(disk_super
->flags
);
583 cmd
->root
= le64_to_cpu(disk_super
->mapping_root
);
584 cmd
->hint_root
= le64_to_cpu(disk_super
->hint_root
);
585 cmd
->discard_root
= le64_to_cpu(disk_super
->discard_root
);
586 cmd
->discard_block_size
= le64_to_cpu(disk_super
->discard_block_size
);
587 cmd
->discard_nr_blocks
= to_dblock(le64_to_cpu(disk_super
->discard_nr_blocks
));
588 cmd
->data_block_size
= le32_to_cpu(disk_super
->data_block_size
);
589 cmd
->cache_blocks
= to_cblock(le32_to_cpu(disk_super
->cache_blocks
));
590 strncpy(cmd
->policy_name
, disk_super
->policy_name
, sizeof(cmd
->policy_name
));
591 cmd
->policy_version
[0] = le32_to_cpu(disk_super
->policy_version
[0]);
592 cmd
->policy_version
[1] = le32_to_cpu(disk_super
->policy_version
[1]);
593 cmd
->policy_version
[2] = le32_to_cpu(disk_super
->policy_version
[2]);
594 cmd
->policy_hint_size
= le32_to_cpu(disk_super
->policy_hint_size
);
596 cmd
->stats
.read_hits
= le32_to_cpu(disk_super
->read_hits
);
597 cmd
->stats
.read_misses
= le32_to_cpu(disk_super
->read_misses
);
598 cmd
->stats
.write_hits
= le32_to_cpu(disk_super
->write_hits
);
599 cmd
->stats
.write_misses
= le32_to_cpu(disk_super
->write_misses
);
601 if (separate_dirty_bits(cmd
))
602 cmd
->dirty_root
= le64_to_cpu(disk_super
->dirty_root
);
604 cmd
->changed
= false;
608 * The mutator updates the superblock flags.
610 static int __begin_transaction_flags(struct dm_cache_metadata
*cmd
,
611 flags_mutator mutator
)
614 struct cache_disk_superblock
*disk_super
;
615 struct dm_block
*sblock
;
617 r
= superblock_lock(cmd
, &sblock
);
621 disk_super
= dm_block_data(sblock
);
622 update_flags(disk_super
, mutator
);
623 read_superblock_fields(cmd
, disk_super
);
624 dm_bm_unlock(sblock
);
626 return dm_bm_flush(cmd
->bm
);
629 static int __begin_transaction(struct dm_cache_metadata
*cmd
)
632 struct cache_disk_superblock
*disk_super
;
633 struct dm_block
*sblock
;
636 * We re-read the superblock every time. Shouldn't need to do this
639 r
= superblock_read_lock(cmd
, &sblock
);
643 disk_super
= dm_block_data(sblock
);
644 read_superblock_fields(cmd
, disk_super
);
645 dm_bm_unlock(sblock
);
650 static int __commit_transaction(struct dm_cache_metadata
*cmd
,
651 flags_mutator mutator
)
654 struct cache_disk_superblock
*disk_super
;
655 struct dm_block
*sblock
;
658 * We need to know if the cache_disk_superblock exceeds a 512-byte sector.
660 BUILD_BUG_ON(sizeof(struct cache_disk_superblock
) > 512);
662 if (separate_dirty_bits(cmd
)) {
663 r
= dm_bitset_flush(&cmd
->dirty_info
, cmd
->dirty_root
,
669 r
= dm_bitset_flush(&cmd
->discard_info
, cmd
->discard_root
,
674 r
= dm_tm_pre_commit(cmd
->tm
);
678 r
= __save_sm_root(cmd
);
682 r
= superblock_lock(cmd
, &sblock
);
686 disk_super
= dm_block_data(sblock
);
688 disk_super
->flags
= cpu_to_le32(cmd
->flags
);
690 update_flags(disk_super
, mutator
);
692 disk_super
->mapping_root
= cpu_to_le64(cmd
->root
);
693 if (separate_dirty_bits(cmd
))
694 disk_super
->dirty_root
= cpu_to_le64(cmd
->dirty_root
);
695 disk_super
->hint_root
= cpu_to_le64(cmd
->hint_root
);
696 disk_super
->discard_root
= cpu_to_le64(cmd
->discard_root
);
697 disk_super
->discard_block_size
= cpu_to_le64(cmd
->discard_block_size
);
698 disk_super
->discard_nr_blocks
= cpu_to_le64(from_dblock(cmd
->discard_nr_blocks
));
699 disk_super
->cache_blocks
= cpu_to_le32(from_cblock(cmd
->cache_blocks
));
700 strncpy(disk_super
->policy_name
, cmd
->policy_name
, sizeof(disk_super
->policy_name
));
701 disk_super
->policy_version
[0] = cpu_to_le32(cmd
->policy_version
[0]);
702 disk_super
->policy_version
[1] = cpu_to_le32(cmd
->policy_version
[1]);
703 disk_super
->policy_version
[2] = cpu_to_le32(cmd
->policy_version
[2]);
705 disk_super
->read_hits
= cpu_to_le32(cmd
->stats
.read_hits
);
706 disk_super
->read_misses
= cpu_to_le32(cmd
->stats
.read_misses
);
707 disk_super
->write_hits
= cpu_to_le32(cmd
->stats
.write_hits
);
708 disk_super
->write_misses
= cpu_to_le32(cmd
->stats
.write_misses
);
709 __copy_sm_root(cmd
, disk_super
);
711 return dm_tm_commit(cmd
->tm
, sblock
);
714 /*----------------------------------------------------------------*/
717 * The mappings are held in a dm-array that has 64-bit values stored in
718 * little-endian format. The index is the cblock, the high 48bits of the
719 * value are the oblock and the low 16 bit the flags.
721 #define FLAGS_MASK ((1 << 16) - 1)
723 static __le64
pack_value(dm_oblock_t block
, unsigned flags
)
725 uint64_t value
= from_oblock(block
);
727 value
= value
| (flags
& FLAGS_MASK
);
728 return cpu_to_le64(value
);
731 static void unpack_value(__le64 value_le
, dm_oblock_t
*block
, unsigned *flags
)
733 uint64_t value
= le64_to_cpu(value_le
);
734 uint64_t b
= value
>> 16;
735 *block
= to_oblock(b
);
736 *flags
= value
& FLAGS_MASK
;
739 /*----------------------------------------------------------------*/
741 static struct dm_cache_metadata
*metadata_open(struct block_device
*bdev
,
742 sector_t data_block_size
,
743 bool may_format_device
,
744 size_t policy_hint_size
,
745 unsigned metadata_version
)
748 struct dm_cache_metadata
*cmd
;
750 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
752 DMERR("could not allocate metadata struct");
753 return ERR_PTR(-ENOMEM
);
756 cmd
->version
= metadata_version
;
757 refcount_set(&cmd
->ref_count
, 1);
758 init_rwsem(&cmd
->root_lock
);
760 cmd
->data_block_size
= data_block_size
;
761 cmd
->cache_blocks
= 0;
762 cmd
->policy_hint_size
= policy_hint_size
;
764 cmd
->fail_io
= false;
766 r
= __create_persistent_data_objects(cmd
, may_format_device
);
772 r
= __begin_transaction_flags(cmd
, clear_clean_shutdown
);
774 dm_cache_metadata_close(cmd
);
782 * We keep a little list of ref counted metadata objects to prevent two
783 * different target instances creating separate bufio instances. This is
784 * an issue if a table is reloaded before the suspend.
786 static DEFINE_MUTEX(table_lock
);
787 static LIST_HEAD(table
);
789 static struct dm_cache_metadata
*lookup(struct block_device
*bdev
)
791 struct dm_cache_metadata
*cmd
;
793 list_for_each_entry(cmd
, &table
, list
)
794 if (cmd
->bdev
== bdev
) {
795 refcount_inc(&cmd
->ref_count
);
802 static struct dm_cache_metadata
*lookup_or_open(struct block_device
*bdev
,
803 sector_t data_block_size
,
804 bool may_format_device
,
805 size_t policy_hint_size
,
806 unsigned metadata_version
)
808 struct dm_cache_metadata
*cmd
, *cmd2
;
810 mutex_lock(&table_lock
);
812 mutex_unlock(&table_lock
);
817 cmd
= metadata_open(bdev
, data_block_size
, may_format_device
,
818 policy_hint_size
, metadata_version
);
820 mutex_lock(&table_lock
);
823 mutex_unlock(&table_lock
);
824 __destroy_persistent_data_objects(cmd
);
828 list_add(&cmd
->list
, &table
);
829 mutex_unlock(&table_lock
);
835 static bool same_params(struct dm_cache_metadata
*cmd
, sector_t data_block_size
)
837 if (cmd
->data_block_size
!= data_block_size
) {
838 DMERR("data_block_size (%llu) different from that in metadata (%llu)",
839 (unsigned long long) data_block_size
,
840 (unsigned long long) cmd
->data_block_size
);
847 struct dm_cache_metadata
*dm_cache_metadata_open(struct block_device
*bdev
,
848 sector_t data_block_size
,
849 bool may_format_device
,
850 size_t policy_hint_size
,
851 unsigned metadata_version
)
853 struct dm_cache_metadata
*cmd
= lookup_or_open(bdev
, data_block_size
, may_format_device
,
854 policy_hint_size
, metadata_version
);
856 if (!IS_ERR(cmd
) && !same_params(cmd
, data_block_size
)) {
857 dm_cache_metadata_close(cmd
);
858 return ERR_PTR(-EINVAL
);
864 void dm_cache_metadata_close(struct dm_cache_metadata
*cmd
)
866 if (refcount_dec_and_test(&cmd
->ref_count
)) {
867 mutex_lock(&table_lock
);
868 list_del(&cmd
->list
);
869 mutex_unlock(&table_lock
);
872 __destroy_persistent_data_objects(cmd
);
878 * Checks that the given cache block is either unmapped or clean.
880 static int block_clean_combined_dirty(struct dm_cache_metadata
*cmd
, dm_cblock_t b
,
888 r
= dm_array_get_value(&cmd
->info
, cmd
->root
, from_cblock(b
), &value
);
892 unpack_value(value
, &ob
, &flags
);
893 *result
= !((flags
& M_VALID
) && (flags
& M_DIRTY
));
898 static int blocks_are_clean_combined_dirty(struct dm_cache_metadata
*cmd
,
899 dm_cblock_t begin
, dm_cblock_t end
,
905 while (begin
!= end
) {
906 r
= block_clean_combined_dirty(cmd
, begin
, result
);
908 DMERR("block_clean_combined_dirty failed");
913 DMERR("cache block %llu is dirty",
914 (unsigned long long) from_cblock(begin
));
918 begin
= to_cblock(from_cblock(begin
) + 1);
924 static int blocks_are_clean_separate_dirty(struct dm_cache_metadata
*cmd
,
925 dm_cblock_t begin
, dm_cblock_t end
,
932 r
= dm_bitset_cursor_begin(&cmd
->dirty_info
, cmd
->dirty_root
,
933 from_cblock(cmd
->cache_blocks
), &cmd
->dirty_cursor
);
935 DMERR("%s: dm_bitset_cursor_begin for dirty failed", __func__
);
939 r
= dm_bitset_cursor_skip(&cmd
->dirty_cursor
, from_cblock(begin
));
941 DMERR("%s: dm_bitset_cursor_skip for dirty failed", __func__
);
942 dm_bitset_cursor_end(&cmd
->dirty_cursor
);
946 while (begin
!= end
) {
948 * We assume that unmapped blocks have their dirty bit
951 dirty_flag
= dm_bitset_cursor_get_value(&cmd
->dirty_cursor
);
953 DMERR("%s: cache block %llu is dirty", __func__
,
954 (unsigned long long) from_cblock(begin
));
955 dm_bitset_cursor_end(&cmd
->dirty_cursor
);
960 begin
= to_cblock(from_cblock(begin
) + 1);
964 r
= dm_bitset_cursor_next(&cmd
->dirty_cursor
);
966 DMERR("%s: dm_bitset_cursor_next for dirty failed", __func__
);
967 dm_bitset_cursor_end(&cmd
->dirty_cursor
);
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
);
1636 r
= __commit_transaction(cmd
, mutator
);
1640 r
= __begin_transaction(cmd
);
1646 int dm_cache_get_free_metadata_block_count(struct dm_cache_metadata
*cmd
,
1653 r
= dm_sm_get_nr_free(cmd
->metadata_sm
, result
);
1659 int dm_cache_get_metadata_dev_size(struct dm_cache_metadata
*cmd
,
1666 r
= dm_sm_get_nr_blocks(cmd
->metadata_sm
, result
);
1672 /*----------------------------------------------------------------*/
1674 static int get_hint(uint32_t index
, void *value_le
, void *context
)
1677 struct dm_cache_policy
*policy
= context
;
1679 value
= policy_get_hint(policy
, to_cblock(index
));
1680 *((__le32
*) value_le
) = cpu_to_le32(value
);
1686 * It's quicker to always delete the hint array, and recreate with
1689 static int write_hints(struct dm_cache_metadata
*cmd
, struct dm_cache_policy
*policy
)
1693 const char *policy_name
= dm_cache_policy_get_name(policy
);
1694 const unsigned *policy_version
= dm_cache_policy_get_version(policy
);
1696 if (!policy_name
[0] ||
1697 (strlen(policy_name
) > sizeof(cmd
->policy_name
) - 1))
1700 strncpy(cmd
->policy_name
, policy_name
, sizeof(cmd
->policy_name
));
1701 memcpy(cmd
->policy_version
, policy_version
, sizeof(cmd
->policy_version
));
1703 hint_size
= dm_cache_policy_get_hint_size(policy
);
1705 return 0; /* short-circuit hints initialization */
1706 cmd
->policy_hint_size
= hint_size
;
1708 if (cmd
->hint_root
) {
1709 r
= dm_array_del(&cmd
->hint_info
, cmd
->hint_root
);
1714 return dm_array_new(&cmd
->hint_info
, &cmd
->hint_root
,
1715 from_cblock(cmd
->cache_blocks
),
1719 int dm_cache_write_hints(struct dm_cache_metadata
*cmd
, struct dm_cache_policy
*policy
)
1724 r
= write_hints(cmd
, policy
);
1730 int dm_cache_metadata_all_clean(struct dm_cache_metadata
*cmd
, bool *result
)
1735 r
= blocks_are_unmapped_or_clean(cmd
, 0, cmd
->cache_blocks
, result
);
1741 void dm_cache_metadata_set_read_only(struct dm_cache_metadata
*cmd
)
1743 WRITE_LOCK_VOID(cmd
);
1744 dm_bm_set_read_only(cmd
->bm
);
1748 void dm_cache_metadata_set_read_write(struct dm_cache_metadata
*cmd
)
1750 WRITE_LOCK_VOID(cmd
);
1751 dm_bm_set_read_write(cmd
->bm
);
1755 int dm_cache_metadata_set_needs_check(struct dm_cache_metadata
*cmd
)
1758 struct dm_block
*sblock
;
1759 struct cache_disk_superblock
*disk_super
;
1762 set_bit(NEEDS_CHECK
, &cmd
->flags
);
1764 r
= superblock_lock(cmd
, &sblock
);
1766 DMERR("couldn't read superblock");
1770 disk_super
= dm_block_data(sblock
);
1771 disk_super
->flags
= cpu_to_le32(cmd
->flags
);
1773 dm_bm_unlock(sblock
);
1780 int dm_cache_metadata_needs_check(struct dm_cache_metadata
*cmd
, bool *result
)
1783 *result
= !!test_bit(NEEDS_CHECK
, &cmd
->flags
);
1789 int dm_cache_metadata_abort(struct dm_cache_metadata
*cmd
)
1794 __destroy_persistent_data_objects(cmd
);
1795 r
= __create_persistent_data_objects(cmd
, false);
1797 cmd
->fail_io
= true;