Skip to content

Commit c9154a4

Browse files
bvanasscheaxboe
authored andcommitted
dm/dm-integrity: Combine request operation and flags
Combine the request operation type and request flags into a single argument. Improve static type checking by using the enum req_op type for variables that represent a request operation and the new blk_opf_t type for variables that represent request flags. Cc: Alasdair Kergon <[email protected]> Cc: Mike Snitzer <[email protected]> Cc: Eric Biggers <[email protected]> Cc: Mikulas Patocka <[email protected]> Signed-off-by: Bart Van Assche <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent eff17e5 commit c9154a4

File tree

1 file changed

+34
-29
lines changed

1 file changed

+34
-29
lines changed

drivers/md/dm-integrity.c

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -551,13 +551,14 @@ static int sb_mac(struct dm_integrity_c *ic, bool wr)
551551
return 0;
552552
}
553553

554-
static int sync_rw_sb(struct dm_integrity_c *ic, int op, int op_flags)
554+
static int sync_rw_sb(struct dm_integrity_c *ic, blk_opf_t opf)
555555
{
556556
struct dm_io_request io_req;
557557
struct dm_io_region io_loc;
558+
const enum req_op op = opf & REQ_OP_MASK;
558559
int r;
559560

560-
io_req.bi_opf = op | op_flags;
561+
io_req.bi_opf = opf;
561562
io_req.mem.type = DM_IO_KMEM;
562563
io_req.mem.ptr.addr = ic->sb;
563564
io_req.notify.fn = NULL;
@@ -1049,8 +1050,9 @@ static void complete_journal_io(unsigned long error, void *context)
10491050
complete_journal_op(comp);
10501051
}
10511052

1052-
static void rw_journal_sectors(struct dm_integrity_c *ic, int op, int op_flags,
1053-
unsigned sector, unsigned n_sectors, struct journal_completion *comp)
1053+
static void rw_journal_sectors(struct dm_integrity_c *ic, blk_opf_t opf,
1054+
unsigned sector, unsigned n_sectors,
1055+
struct journal_completion *comp)
10541056
{
10551057
struct dm_io_request io_req;
10561058
struct dm_io_region io_loc;
@@ -1066,7 +1068,7 @@ static void rw_journal_sectors(struct dm_integrity_c *ic, int op, int op_flags,
10661068
pl_index = sector >> (PAGE_SHIFT - SECTOR_SHIFT);
10671069
pl_offset = (sector << SECTOR_SHIFT) & (PAGE_SIZE - 1);
10681070

1069-
io_req.bi_opf = op | op_flags;
1071+
io_req.bi_opf = opf;
10701072
io_req.mem.type = DM_IO_PAGE_LIST;
10711073
if (ic->journal_io)
10721074
io_req.mem.ptr.pl = &ic->journal_io[pl_index];
@@ -1086,23 +1088,25 @@ static void rw_journal_sectors(struct dm_integrity_c *ic, int op, int op_flags,
10861088

10871089
r = dm_io(&io_req, 1, &io_loc, NULL);
10881090
if (unlikely(r)) {
1089-
dm_integrity_io_error(ic, op == REQ_OP_READ ? "reading journal" : "writing journal", r);
1091+
dm_integrity_io_error(ic, (opf & REQ_OP_MASK) == REQ_OP_READ ?
1092+
"reading journal" : "writing journal", r);
10901093
if (comp) {
10911094
WARN_ONCE(1, "asynchronous dm_io failed: %d", r);
10921095
complete_journal_io(-1UL, comp);
10931096
}
10941097
}
10951098
}
10961099

1097-
static void rw_journal(struct dm_integrity_c *ic, int op, int op_flags, unsigned section,
1098-
unsigned n_sections, struct journal_completion *comp)
1100+
static void rw_journal(struct dm_integrity_c *ic, blk_opf_t opf,
1101+
unsigned section, unsigned n_sections,
1102+
struct journal_completion *comp)
10991103
{
11001104
unsigned sector, n_sectors;
11011105

11021106
sector = section * ic->journal_section_sectors;
11031107
n_sectors = n_sections * ic->journal_section_sectors;
11041108

1105-
rw_journal_sectors(ic, op, op_flags, sector, n_sectors, comp);
1109+
rw_journal_sectors(ic, opf, sector, n_sectors, comp);
11061110
}
11071111

11081112
static void write_journal(struct dm_integrity_c *ic, unsigned commit_start, unsigned commit_sections)
@@ -1127,7 +1131,7 @@ static void write_journal(struct dm_integrity_c *ic, unsigned commit_start, unsi
11271131
for (i = 0; i < commit_sections; i++)
11281132
rw_section_mac(ic, commit_start + i, true);
11291133
}
1130-
rw_journal(ic, REQ_OP_WRITE, REQ_FUA | REQ_SYNC, commit_start,
1134+
rw_journal(ic, REQ_OP_WRITE | REQ_FUA | REQ_SYNC, commit_start,
11311135
commit_sections, &io_comp);
11321136
} else {
11331137
unsigned to_end;
@@ -1139,7 +1143,8 @@ static void write_journal(struct dm_integrity_c *ic, unsigned commit_start, unsi
11391143
crypt_comp_1.in_flight = (atomic_t)ATOMIC_INIT(0);
11401144
encrypt_journal(ic, true, commit_start, to_end, &crypt_comp_1);
11411145
if (try_wait_for_completion(&crypt_comp_1.comp)) {
1142-
rw_journal(ic, REQ_OP_WRITE, REQ_FUA, commit_start, to_end, &io_comp);
1146+
rw_journal(ic, REQ_OP_WRITE | REQ_FUA,
1147+
commit_start, to_end, &io_comp);
11431148
reinit_completion(&crypt_comp_1.comp);
11441149
crypt_comp_1.in_flight = (atomic_t)ATOMIC_INIT(0);
11451150
encrypt_journal(ic, true, 0, commit_sections - to_end, &crypt_comp_1);
@@ -1150,17 +1155,17 @@ static void write_journal(struct dm_integrity_c *ic, unsigned commit_start, unsi
11501155
crypt_comp_2.in_flight = (atomic_t)ATOMIC_INIT(0);
11511156
encrypt_journal(ic, true, 0, commit_sections - to_end, &crypt_comp_2);
11521157
wait_for_completion_io(&crypt_comp_1.comp);
1153-
rw_journal(ic, REQ_OP_WRITE, REQ_FUA, commit_start, to_end, &io_comp);
1158+
rw_journal(ic, REQ_OP_WRITE | REQ_FUA, commit_start, to_end, &io_comp);
11541159
wait_for_completion_io(&crypt_comp_2.comp);
11551160
}
11561161
} else {
11571162
for (i = 0; i < to_end; i++)
11581163
rw_section_mac(ic, commit_start + i, true);
1159-
rw_journal(ic, REQ_OP_WRITE, REQ_FUA, commit_start, to_end, &io_comp);
1164+
rw_journal(ic, REQ_OP_WRITE | REQ_FUA, commit_start, to_end, &io_comp);
11601165
for (i = 0; i < commit_sections - to_end; i++)
11611166
rw_section_mac(ic, i, true);
11621167
}
1163-
rw_journal(ic, REQ_OP_WRITE, REQ_FUA, 0, commit_sections - to_end, &io_comp);
1168+
rw_journal(ic, REQ_OP_WRITE | REQ_FUA, 0, commit_sections - to_end, &io_comp);
11641169
}
11651170

11661171
wait_for_completion_io(&io_comp.comp);
@@ -2622,7 +2627,7 @@ static void recalc_write_super(struct dm_integrity_c *ic)
26222627
if (dm_integrity_failed(ic))
26232628
return;
26242629

2625-
r = sync_rw_sb(ic, REQ_OP_WRITE, 0);
2630+
r = sync_rw_sb(ic, REQ_OP_WRITE);
26262631
if (unlikely(r))
26272632
dm_integrity_io_error(ic, "writing superblock", r);
26282633
}
@@ -2795,7 +2800,7 @@ static void bitmap_block_work(struct work_struct *w)
27952800
if (bio_list_empty(&waiting))
27962801
return;
27972802

2798-
rw_journal_sectors(ic, REQ_OP_WRITE, REQ_FUA | REQ_SYNC,
2803+
rw_journal_sectors(ic, REQ_OP_WRITE | REQ_FUA | REQ_SYNC,
27992804
bbs->idx * (BITMAP_BLOCK_SIZE >> SECTOR_SHIFT),
28002805
BITMAP_BLOCK_SIZE >> SECTOR_SHIFT, NULL);
28012806

@@ -2841,7 +2846,7 @@ static void bitmap_flush_work(struct work_struct *work)
28412846
block_bitmap_op(ic, ic->journal, 0, limit, BITMAP_OP_CLEAR);
28422847
block_bitmap_op(ic, ic->may_write_bitmap, 0, limit, BITMAP_OP_CLEAR);
28432848

2844-
rw_journal_sectors(ic, REQ_OP_WRITE, REQ_FUA | REQ_SYNC, 0,
2849+
rw_journal_sectors(ic, REQ_OP_WRITE | REQ_FUA | REQ_SYNC, 0,
28452850
ic->n_bitmap_blocks * (BITMAP_BLOCK_SIZE >> SECTOR_SHIFT), NULL);
28462851

28472852
spin_lock_irq(&ic->endio_wait.lock);
@@ -2913,7 +2918,7 @@ static void replay_journal(struct dm_integrity_c *ic)
29132918

29142919
if (!ic->just_formatted) {
29152920
DEBUG_print("reading journal\n");
2916-
rw_journal(ic, REQ_OP_READ, 0, 0, ic->journal_sections, NULL);
2921+
rw_journal(ic, REQ_OP_READ, 0, ic->journal_sections, NULL);
29172922
if (ic->journal_io)
29182923
DEBUG_bytes(lowmem_page_address(ic->journal_io[0].page), 64, "read journal");
29192924
if (ic->journal_io) {
@@ -3108,7 +3113,7 @@ static void dm_integrity_postsuspend(struct dm_target *ti)
31083113
/* set to 0 to test bitmap replay code */
31093114
init_journal(ic, 0, ic->journal_sections, 0);
31103115
ic->sb->flags &= ~cpu_to_le32(SB_FLAG_DIRTY_BITMAP);
3111-
r = sync_rw_sb(ic, REQ_OP_WRITE, REQ_FUA);
3116+
r = sync_rw_sb(ic, REQ_OP_WRITE | REQ_FUA);
31123117
if (unlikely(r))
31133118
dm_integrity_io_error(ic, "writing superblock", r);
31143119
#endif
@@ -3131,23 +3136,23 @@ static void dm_integrity_resume(struct dm_target *ti)
31313136
if (ic->provided_data_sectors > old_provided_data_sectors &&
31323137
ic->mode == 'B' &&
31333138
ic->sb->log2_blocks_per_bitmap_bit == ic->log2_blocks_per_bitmap_bit) {
3134-
rw_journal_sectors(ic, REQ_OP_READ, 0, 0,
3139+
rw_journal_sectors(ic, REQ_OP_READ, 0,
31353140
ic->n_bitmap_blocks * (BITMAP_BLOCK_SIZE >> SECTOR_SHIFT), NULL);
31363141
block_bitmap_op(ic, ic->journal, old_provided_data_sectors,
31373142
ic->provided_data_sectors - old_provided_data_sectors, BITMAP_OP_SET);
3138-
rw_journal_sectors(ic, REQ_OP_WRITE, REQ_FUA | REQ_SYNC, 0,
3143+
rw_journal_sectors(ic, REQ_OP_WRITE | REQ_FUA | REQ_SYNC, 0,
31393144
ic->n_bitmap_blocks * (BITMAP_BLOCK_SIZE >> SECTOR_SHIFT), NULL);
31403145
}
31413146

31423147
ic->sb->provided_data_sectors = cpu_to_le64(ic->provided_data_sectors);
3143-
r = sync_rw_sb(ic, REQ_OP_WRITE, REQ_FUA);
3148+
r = sync_rw_sb(ic, REQ_OP_WRITE | REQ_FUA);
31443149
if (unlikely(r))
31453150
dm_integrity_io_error(ic, "writing superblock", r);
31463151
}
31473152

31483153
if (ic->sb->flags & cpu_to_le32(SB_FLAG_DIRTY_BITMAP)) {
31493154
DEBUG_print("resume dirty_bitmap\n");
3150-
rw_journal_sectors(ic, REQ_OP_READ, 0, 0,
3155+
rw_journal_sectors(ic, REQ_OP_READ, 0,
31513156
ic->n_bitmap_blocks * (BITMAP_BLOCK_SIZE >> SECTOR_SHIFT), NULL);
31523157
if (ic->mode == 'B') {
31533158
if (ic->sb->log2_blocks_per_bitmap_bit == ic->log2_blocks_per_bitmap_bit &&
@@ -3166,7 +3171,7 @@ static void dm_integrity_resume(struct dm_target *ti)
31663171
block_bitmap_op(ic, ic->recalc_bitmap, 0, ic->provided_data_sectors, BITMAP_OP_SET);
31673172
block_bitmap_op(ic, ic->may_write_bitmap, 0, ic->provided_data_sectors, BITMAP_OP_SET);
31683173
block_bitmap_op(ic, ic->journal, 0, ic->provided_data_sectors, BITMAP_OP_SET);
3169-
rw_journal_sectors(ic, REQ_OP_WRITE, REQ_FUA | REQ_SYNC, 0,
3174+
rw_journal_sectors(ic, REQ_OP_WRITE | REQ_FUA | REQ_SYNC, 0,
31703175
ic->n_bitmap_blocks * (BITMAP_BLOCK_SIZE >> SECTOR_SHIFT), NULL);
31713176
ic->sb->flags |= cpu_to_le32(SB_FLAG_RECALCULATING);
31723177
ic->sb->recalc_sector = cpu_to_le64(0);
@@ -3182,7 +3187,7 @@ static void dm_integrity_resume(struct dm_target *ti)
31823187
replay_journal(ic);
31833188
ic->sb->flags &= ~cpu_to_le32(SB_FLAG_DIRTY_BITMAP);
31843189
}
3185-
r = sync_rw_sb(ic, REQ_OP_WRITE, REQ_FUA);
3190+
r = sync_rw_sb(ic, REQ_OP_WRITE | REQ_FUA);
31863191
if (unlikely(r))
31873192
dm_integrity_io_error(ic, "writing superblock", r);
31883193
} else {
@@ -3194,7 +3199,7 @@ static void dm_integrity_resume(struct dm_target *ti)
31943199
if (ic->mode == 'B') {
31953200
ic->sb->flags |= cpu_to_le32(SB_FLAG_DIRTY_BITMAP);
31963201
ic->sb->log2_blocks_per_bitmap_bit = ic->log2_blocks_per_bitmap_bit;
3197-
r = sync_rw_sb(ic, REQ_OP_WRITE, REQ_FUA);
3202+
r = sync_rw_sb(ic, REQ_OP_WRITE | REQ_FUA);
31983203
if (unlikely(r))
31993204
dm_integrity_io_error(ic, "writing superblock", r);
32003205

@@ -3210,7 +3215,7 @@ static void dm_integrity_resume(struct dm_target *ti)
32103215
block_bitmap_op(ic, ic->may_write_bitmap, le64_to_cpu(ic->sb->recalc_sector),
32113216
ic->provided_data_sectors - le64_to_cpu(ic->sb->recalc_sector), BITMAP_OP_SET);
32123217
}
3213-
rw_journal_sectors(ic, REQ_OP_WRITE, REQ_FUA | REQ_SYNC, 0,
3218+
rw_journal_sectors(ic, REQ_OP_WRITE | REQ_FUA | REQ_SYNC, 0,
32143219
ic->n_bitmap_blocks * (BITMAP_BLOCK_SIZE >> SECTOR_SHIFT), NULL);
32153220
}
32163221
}
@@ -4251,7 +4256,7 @@ static int dm_integrity_ctr(struct dm_target *ti, unsigned argc, char **argv)
42514256
goto bad;
42524257
}
42534258

4254-
r = sync_rw_sb(ic, REQ_OP_READ, 0);
4259+
r = sync_rw_sb(ic, REQ_OP_READ);
42554260
if (r) {
42564261
ti->error = "Error reading superblock";
42574262
goto bad;
@@ -4495,7 +4500,7 @@ static int dm_integrity_ctr(struct dm_target *ti, unsigned argc, char **argv)
44954500
ti->error = "Error initializing journal";
44964501
goto bad;
44974502
}
4498-
r = sync_rw_sb(ic, REQ_OP_WRITE, REQ_FUA);
4503+
r = sync_rw_sb(ic, REQ_OP_WRITE | REQ_FUA);
44994504
if (r) {
45004505
ti->error = "Error initializing superblock";
45014506
goto bad;

0 commit comments

Comments
 (0)