Skip to content

Commit 7af81cd

Browse files
committed
Merge tag 'for-5.13/dm-changes' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm
Pull device mapper updates from Mike Snitzer: - Improve scalability of DM's device hash by switching to rbtree - Extend DM ioctl's DM_LIST_DEVICES_CMD handling to include UUID and allow filtering based on name or UUID prefix. - Various small fixes for typos, warnings, unused function, or needlessly exported interfaces. - Remove needless request_queue NULL pointer checks in DM thin and cache targets. - Remove unnecessary loop in DM core's __split_and_process_bio(). - Remove DM core's dm_vcalloc() and just use kvcalloc or kvmalloc_array instead (depending whether zeroing is useful). - Fix request-based DM's double free of blk_mq_tag_set in device remove after table load fails. - Improve DM persistent data performance on non-x86 by fixing packed structs to have a stated alignment. Also remove needless extra work from redundant calls to sm_disk_get_nr_free() and a paranoid BUG_ON() that caused duplicate checksum calculation. - Fix missing goto in DM integrity's bitmap_flush_interval error handling. - Add "reset_recalculate" feature flag to DM integrity. - Improve DM integrity by leveraging discard support to avoid needless re-writing of metadata and also use discard support to improve hash recalculation. - Fix race with DM raid target's reshape and MD raid4/5/6 resync that resulted in inconsistant reshape state during table reloads. - Update DM raid target to temove unnecessary discard limits for raid0 and raid10 now that MD has optimized discard handling for both raid levels. * tag 'for-5.13/dm-changes' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm: (26 commits) dm raid: remove unnecessary discard limits for raid0 and raid10 dm rq: fix double free of blk_mq_tag_set in dev remove after table load fails dm integrity: use discard support when recalculating dm integrity: increase RECALC_SECTORS to improve recalculate speed dm integrity: don't re-write metadata if discarding same blocks dm raid: fix inconclusive reshape layout on fast raid4/5/6 table reload sequences dm raid: fix fall-through warning in rs_check_takeover() for Clang dm clone metadata: remove unused function dm integrity: fix missing goto in bitmap_flush_interval error handling dm: replace dm_vcalloc() dm space map common: fix division bug in sm_ll_find_free_block() dm persistent data: packed struct should have an aligned() attribute too dm btree spine: remove paranoid node_check call in node_prep_for_write() dm space map disk: remove redundant calls to sm_disk_get_nr_free() dm integrity: add the "reset_recalculate" feature flag dm persistent data: remove unused return from exit_shadow_spine() dm cache: remove needless request_queue NULL pointer checks dm thin: remove needless request_queue NULL pointer check dm: unexport dm_{get,put}_table_device dm ebs: fix a few typos ...
2 parents 152d32a + ca4a4e9 commit 7af81cd

21 files changed

+372
-271
lines changed

drivers/md/dm-cache-target.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3387,7 +3387,7 @@ static bool origin_dev_supports_discard(struct block_device *origin_bdev)
33873387
{
33883388
struct request_queue *q = bdev_get_queue(origin_bdev);
33893389

3390-
return q && blk_queue_discard(q);
3390+
return blk_queue_discard(q);
33913391
}
33923392

33933393
/*

drivers/md/dm-clone-metadata.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,6 @@ static inline int superblock_read_lock(struct dm_clone_metadata *cmd,
276276
return dm_bm_read_lock(cmd->bm, SUPERBLOCK_LOCATION, &sb_validator, sblock);
277277
}
278278

279-
static inline int superblock_write_lock(struct dm_clone_metadata *cmd,
280-
struct dm_block **sblock)
281-
{
282-
return dm_bm_write_lock(cmd->bm, SUPERBLOCK_LOCATION, &sb_validator, sblock);
283-
}
284-
285279
static inline int superblock_write_lock_zero(struct dm_clone_metadata *cmd,
286280
struct dm_block **sblock)
287281
{

drivers/md/dm-ebs-target.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ struct ebs_c {
2828
spinlock_t lock; /* Guard bios input list above. */
2929
sector_t start; /* <start> table line argument, see ebs_ctr below. */
3030
unsigned int e_bs; /* Emulated block size in sectors exposed to upper layer. */
31-
unsigned int u_bs; /* Underlying block size in sectors retrievd from/set on lower layer device. */
31+
unsigned int u_bs; /* Underlying block size in sectors retrieved from/set on lower layer device. */
3232
unsigned char block_shift; /* bitshift sectors -> blocks used in dm-bufio API. */
3333
bool u_bs_set:1; /* Flag to indicate underlying block size is set on table line. */
3434
};
@@ -43,7 +43,7 @@ static inline sector_t __block_mod(sector_t sector, unsigned int bs)
4343
return sector & (bs - 1);
4444
}
4545

46-
/* Return number of blocks for a bio, accounting for misalignement of start and end sectors. */
46+
/* Return number of blocks for a bio, accounting for misalignment of start and end sectors. */
4747
static inline unsigned int __nr_blocks(struct ebs_c *ec, struct bio *bio)
4848
{
4949
sector_t end_sector = __block_mod(bio->bi_iter.bi_sector, ec->u_bs) + bio_sectors(bio);
@@ -171,7 +171,7 @@ static void __ebs_forget_bio(struct ebs_c *ec, struct bio *bio)
171171
dm_bufio_forget_buffers(ec->bufio, __sector_to_block(ec, sector), blocks);
172172
}
173173

174-
/* Worker funtion to process incoming bios. */
174+
/* Worker function to process incoming bios. */
175175
static void __ebs_process_bios(struct work_struct *ws)
176176
{
177177
int r;

drivers/md/dm-integrity.c

Lines changed: 55 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#define MIN_LOG2_INTERLEAVE_SECTORS 3
3636
#define MAX_LOG2_INTERLEAVE_SECTORS 31
3737
#define METADATA_WORKQUEUE_MAX_ACTIVE 16
38-
#define RECALC_SECTORS 8192
38+
#define RECALC_SECTORS 32768
3939
#define RECALC_WRITE_SUPER 16
4040
#define BITMAP_BLOCK_SIZE 4096 /* don't change it */
4141
#define BITMAP_FLUSH_INTERVAL (10 * HZ)
@@ -262,6 +262,7 @@ struct dm_integrity_c {
262262
bool journal_uptodate;
263263
bool just_formatted;
264264
bool recalculate_flag;
265+
bool reset_recalculate_flag;
265266
bool discard;
266267
bool fix_padding;
267268
bool fix_hmac;
@@ -1428,8 +1429,10 @@ static int dm_integrity_rw_tag(struct dm_integrity_c *ic, unsigned char *tag, se
14281429
if (op == TAG_READ) {
14291430
memcpy(tag, dp, to_copy);
14301431
} else if (op == TAG_WRITE) {
1431-
memcpy(dp, tag, to_copy);
1432-
dm_bufio_mark_partial_buffer_dirty(b, *metadata_offset, *metadata_offset + to_copy);
1432+
if (memcmp(dp, tag, to_copy)) {
1433+
memcpy(dp, tag, to_copy);
1434+
dm_bufio_mark_partial_buffer_dirty(b, *metadata_offset, *metadata_offset + to_copy);
1435+
}
14331436
} else {
14341437
/* e.g.: op == TAG_CMP */
14351438

@@ -2686,26 +2689,30 @@ static void integrity_recalc(struct work_struct *w)
26862689
if (unlikely(dm_integrity_failed(ic)))
26872690
goto err;
26882691

2689-
io_req.bi_op = REQ_OP_READ;
2690-
io_req.bi_op_flags = 0;
2691-
io_req.mem.type = DM_IO_VMA;
2692-
io_req.mem.ptr.addr = ic->recalc_buffer;
2693-
io_req.notify.fn = NULL;
2694-
io_req.client = ic->io;
2695-
io_loc.bdev = ic->dev->bdev;
2696-
io_loc.sector = get_data_sector(ic, area, offset);
2697-
io_loc.count = n_sectors;
2692+
if (!ic->discard) {
2693+
io_req.bi_op = REQ_OP_READ;
2694+
io_req.bi_op_flags = 0;
2695+
io_req.mem.type = DM_IO_VMA;
2696+
io_req.mem.ptr.addr = ic->recalc_buffer;
2697+
io_req.notify.fn = NULL;
2698+
io_req.client = ic->io;
2699+
io_loc.bdev = ic->dev->bdev;
2700+
io_loc.sector = get_data_sector(ic, area, offset);
2701+
io_loc.count = n_sectors;
26982702

2699-
r = dm_io(&io_req, 1, &io_loc, NULL);
2700-
if (unlikely(r)) {
2701-
dm_integrity_io_error(ic, "reading data", r);
2702-
goto err;
2703-
}
2703+
r = dm_io(&io_req, 1, &io_loc, NULL);
2704+
if (unlikely(r)) {
2705+
dm_integrity_io_error(ic, "reading data", r);
2706+
goto err;
2707+
}
27042708

2705-
t = ic->recalc_tags;
2706-
for (i = 0; i < n_sectors; i += ic->sectors_per_block) {
2707-
integrity_sector_checksum(ic, logical_sector + i, ic->recalc_buffer + (i << SECTOR_SHIFT), t);
2708-
t += ic->tag_size;
2709+
t = ic->recalc_tags;
2710+
for (i = 0; i < n_sectors; i += ic->sectors_per_block) {
2711+
integrity_sector_checksum(ic, logical_sector + i, ic->recalc_buffer + (i << SECTOR_SHIFT), t);
2712+
t += ic->tag_size;
2713+
}
2714+
} else {
2715+
t = ic->recalc_tags + (n_sectors >> ic->sb->log2_sectors_per_block) * ic->tag_size;
27092716
}
27102717

27112718
metadata_block = get_metadata_sector_and_offset(ic, area, offset, &metadata_offset);
@@ -3134,7 +3141,8 @@ static void dm_integrity_resume(struct dm_target *ti)
31343141
rw_journal_sectors(ic, REQ_OP_READ, 0, 0,
31353142
ic->n_bitmap_blocks * (BITMAP_BLOCK_SIZE >> SECTOR_SHIFT), NULL);
31363143
if (ic->mode == 'B') {
3137-
if (ic->sb->log2_blocks_per_bitmap_bit == ic->log2_blocks_per_bitmap_bit) {
3144+
if (ic->sb->log2_blocks_per_bitmap_bit == ic->log2_blocks_per_bitmap_bit &&
3145+
!ic->reset_recalculate_flag) {
31383146
block_bitmap_copy(ic, ic->recalc_bitmap, ic->journal);
31393147
block_bitmap_copy(ic, ic->may_write_bitmap, ic->journal);
31403148
if (!block_bitmap_op(ic, ic->journal, 0, ic->provided_data_sectors,
@@ -3156,7 +3164,8 @@ static void dm_integrity_resume(struct dm_target *ti)
31563164
}
31573165
} else {
31583166
if (!(ic->sb->log2_blocks_per_bitmap_bit == ic->log2_blocks_per_bitmap_bit &&
3159-
block_bitmap_op(ic, ic->journal, 0, ic->provided_data_sectors, BITMAP_OP_TEST_ALL_CLEAR))) {
3167+
block_bitmap_op(ic, ic->journal, 0, ic->provided_data_sectors, BITMAP_OP_TEST_ALL_CLEAR)) ||
3168+
ic->reset_recalculate_flag) {
31603169
ic->sb->flags |= cpu_to_le32(SB_FLAG_RECALCULATING);
31613170
ic->sb->recalc_sector = cpu_to_le64(0);
31623171
}
@@ -3169,6 +3178,10 @@ static void dm_integrity_resume(struct dm_target *ti)
31693178
dm_integrity_io_error(ic, "writing superblock", r);
31703179
} else {
31713180
replay_journal(ic);
3181+
if (ic->reset_recalculate_flag) {
3182+
ic->sb->flags |= cpu_to_le32(SB_FLAG_RECALCULATING);
3183+
ic->sb->recalc_sector = cpu_to_le64(0);
3184+
}
31723185
if (ic->mode == 'B') {
31733186
ic->sb->flags |= cpu_to_le32(SB_FLAG_DIRTY_BITMAP);
31743187
ic->sb->log2_blocks_per_bitmap_bit = ic->log2_blocks_per_bitmap_bit;
@@ -3242,6 +3255,7 @@ static void dm_integrity_status(struct dm_target *ti, status_type_t type,
32423255
arg_count += !!ic->meta_dev;
32433256
arg_count += ic->sectors_per_block != 1;
32443257
arg_count += !!(ic->sb->flags & cpu_to_le32(SB_FLAG_RECALCULATING));
3258+
arg_count += ic->reset_recalculate_flag;
32453259
arg_count += ic->discard;
32463260
arg_count += ic->mode == 'J';
32473261
arg_count += ic->mode == 'J';
@@ -3261,6 +3275,8 @@ static void dm_integrity_status(struct dm_target *ti, status_type_t type,
32613275
DMEMIT(" block_size:%u", ic->sectors_per_block << SECTOR_SHIFT);
32623276
if (ic->sb->flags & cpu_to_le32(SB_FLAG_RECALCULATING))
32633277
DMEMIT(" recalculate");
3278+
if (ic->reset_recalculate_flag)
3279+
DMEMIT(" reset_recalculate");
32643280
if (ic->discard)
32653281
DMEMIT(" allow_discards");
32663282
DMEMIT(" journal_sectors:%u", ic->initial_sectors - SB_SECTORS);
@@ -3914,7 +3930,7 @@ static int dm_integrity_ctr(struct dm_target *ti, unsigned argc, char **argv)
39143930
unsigned extra_args;
39153931
struct dm_arg_set as;
39163932
static const struct dm_arg _args[] = {
3917-
{0, 17, "Invalid number of feature args"},
3933+
{0, 18, "Invalid number of feature args"},
39183934
};
39193935
unsigned journal_sectors, interleave_sectors, buffer_sectors, journal_watermark, sync_msec;
39203936
bool should_write_sb;
@@ -4039,6 +4055,7 @@ static int dm_integrity_ctr(struct dm_target *ti, unsigned argc, char **argv)
40394055
if (val >= (uint64_t)UINT_MAX * 1000 / HZ) {
40404056
r = -EINVAL;
40414057
ti->error = "Invalid bitmap_flush_interval argument";
4058+
goto bad;
40424059
}
40434060
ic->bitmap_flush_interval = msecs_to_jiffies(val);
40444061
} else if (!strncmp(opt_string, "internal_hash:", strlen("internal_hash:"))) {
@@ -4058,6 +4075,9 @@ static int dm_integrity_ctr(struct dm_target *ti, unsigned argc, char **argv)
40584075
goto bad;
40594076
} else if (!strcmp(opt_string, "recalculate")) {
40604077
ic->recalculate_flag = true;
4078+
} else if (!strcmp(opt_string, "reset_recalculate")) {
4079+
ic->recalculate_flag = true;
4080+
ic->reset_recalculate_flag = true;
40614081
} else if (!strcmp(opt_string, "allow_discards")) {
40624082
ic->discard = true;
40634083
} else if (!strcmp(opt_string, "fix_padding")) {
@@ -4348,11 +4368,13 @@ static int dm_integrity_ctr(struct dm_target *ti, unsigned argc, char **argv)
43484368
goto bad;
43494369
}
43504370
INIT_WORK(&ic->recalc_work, integrity_recalc);
4351-
ic->recalc_buffer = vmalloc(RECALC_SECTORS << SECTOR_SHIFT);
4352-
if (!ic->recalc_buffer) {
4353-
ti->error = "Cannot allocate buffer for recalculating";
4354-
r = -ENOMEM;
4355-
goto bad;
4371+
if (!ic->discard) {
4372+
ic->recalc_buffer = vmalloc(RECALC_SECTORS << SECTOR_SHIFT);
4373+
if (!ic->recalc_buffer) {
4374+
ti->error = "Cannot allocate buffer for recalculating";
4375+
r = -ENOMEM;
4376+
goto bad;
4377+
}
43564378
}
43574379
ic->recalc_tags = kvmalloc_array(RECALC_SECTORS >> ic->sb->log2_sectors_per_block,
43584380
ic->tag_size, GFP_KERNEL);
@@ -4361,6 +4383,9 @@ static int dm_integrity_ctr(struct dm_target *ti, unsigned argc, char **argv)
43614383
r = -ENOMEM;
43624384
goto bad;
43634385
}
4386+
if (ic->discard)
4387+
memset(ic->recalc_tags, DISCARD_FILLER,
4388+
(RECALC_SECTORS >> ic->sb->log2_sectors_per_block) * ic->tag_size);
43644389
} else {
43654390
if (ic->sb->flags & cpu_to_le32(SB_FLAG_RECALCULATING)) {
43664391
ti->error = "Recalculate can only be specified with internal_hash";
@@ -4554,7 +4579,7 @@ static void dm_integrity_dtr(struct dm_target *ti)
45544579

45554580
static struct target_type integrity_target = {
45564581
.name = "integrity",
4557-
.version = {1, 7, 0},
4582+
.version = {1, 9, 0},
45584583
.module = THIS_MODULE,
45594584
.features = DM_TARGET_SINGLETON | DM_TARGET_INTEGRITY,
45604585
.ctr = dm_integrity_ctr,

0 commit comments

Comments
 (0)