提交 c9154a4c 编写于 作者: B Bart Van Assche 提交者: Jens Axboe

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 <agk@redhat.com>
Cc: Mike Snitzer <snitzer@kernel.org>
Cc: Eric Biggers <ebiggers@google.com>
Cc: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: NBart Van Assche <bvanassche@acm.org>
Link: https://lore.kernel.org/r/20220714180729.1065367-27-bvanassche@acm.orgSigned-off-by: NJens Axboe <axboe@kernel.dk>
上级 eff17e51
...@@ -551,13 +551,14 @@ static int sb_mac(struct dm_integrity_c *ic, bool wr) ...@@ -551,13 +551,14 @@ static int sb_mac(struct dm_integrity_c *ic, bool wr)
return 0; return 0;
} }
static int sync_rw_sb(struct dm_integrity_c *ic, int op, int op_flags) static int sync_rw_sb(struct dm_integrity_c *ic, blk_opf_t opf)
{ {
struct dm_io_request io_req; struct dm_io_request io_req;
struct dm_io_region io_loc; struct dm_io_region io_loc;
const enum req_op op = opf & REQ_OP_MASK;
int r; int r;
io_req.bi_opf = op | op_flags; io_req.bi_opf = opf;
io_req.mem.type = DM_IO_KMEM; io_req.mem.type = DM_IO_KMEM;
io_req.mem.ptr.addr = ic->sb; io_req.mem.ptr.addr = ic->sb;
io_req.notify.fn = NULL; io_req.notify.fn = NULL;
...@@ -1049,8 +1050,9 @@ static void complete_journal_io(unsigned long error, void *context) ...@@ -1049,8 +1050,9 @@ static void complete_journal_io(unsigned long error, void *context)
complete_journal_op(comp); complete_journal_op(comp);
} }
static void rw_journal_sectors(struct dm_integrity_c *ic, int op, int op_flags, static void rw_journal_sectors(struct dm_integrity_c *ic, blk_opf_t opf,
unsigned sector, unsigned n_sectors, struct journal_completion *comp) unsigned sector, unsigned n_sectors,
struct journal_completion *comp)
{ {
struct dm_io_request io_req; struct dm_io_request io_req;
struct dm_io_region io_loc; 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, ...@@ -1066,7 +1068,7 @@ static void rw_journal_sectors(struct dm_integrity_c *ic, int op, int op_flags,
pl_index = sector >> (PAGE_SHIFT - SECTOR_SHIFT); pl_index = sector >> (PAGE_SHIFT - SECTOR_SHIFT);
pl_offset = (sector << SECTOR_SHIFT) & (PAGE_SIZE - 1); pl_offset = (sector << SECTOR_SHIFT) & (PAGE_SIZE - 1);
io_req.bi_opf = op | op_flags; io_req.bi_opf = opf;
io_req.mem.type = DM_IO_PAGE_LIST; io_req.mem.type = DM_IO_PAGE_LIST;
if (ic->journal_io) if (ic->journal_io)
io_req.mem.ptr.pl = &ic->journal_io[pl_index]; io_req.mem.ptr.pl = &ic->journal_io[pl_index];
...@@ -1086,7 +1088,8 @@ static void rw_journal_sectors(struct dm_integrity_c *ic, int op, int op_flags, ...@@ -1086,7 +1088,8 @@ static void rw_journal_sectors(struct dm_integrity_c *ic, int op, int op_flags,
r = dm_io(&io_req, 1, &io_loc, NULL); r = dm_io(&io_req, 1, &io_loc, NULL);
if (unlikely(r)) { if (unlikely(r)) {
dm_integrity_io_error(ic, op == REQ_OP_READ ? "reading journal" : "writing journal", r); dm_integrity_io_error(ic, (opf & REQ_OP_MASK) == REQ_OP_READ ?
"reading journal" : "writing journal", r);
if (comp) { if (comp) {
WARN_ONCE(1, "asynchronous dm_io failed: %d", r); WARN_ONCE(1, "asynchronous dm_io failed: %d", r);
complete_journal_io(-1UL, comp); complete_journal_io(-1UL, comp);
...@@ -1094,15 +1097,16 @@ static void rw_journal_sectors(struct dm_integrity_c *ic, int op, int op_flags, ...@@ -1094,15 +1097,16 @@ static void rw_journal_sectors(struct dm_integrity_c *ic, int op, int op_flags,
} }
} }
static void rw_journal(struct dm_integrity_c *ic, int op, int op_flags, unsigned section, static void rw_journal(struct dm_integrity_c *ic, blk_opf_t opf,
unsigned n_sections, struct journal_completion *comp) unsigned section, unsigned n_sections,
struct journal_completion *comp)
{ {
unsigned sector, n_sectors; unsigned sector, n_sectors;
sector = section * ic->journal_section_sectors; sector = section * ic->journal_section_sectors;
n_sectors = n_sections * ic->journal_section_sectors; n_sectors = n_sections * ic->journal_section_sectors;
rw_journal_sectors(ic, op, op_flags, sector, n_sectors, comp); rw_journal_sectors(ic, opf, sector, n_sectors, comp);
} }
static void write_journal(struct dm_integrity_c *ic, unsigned commit_start, unsigned commit_sections) 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 ...@@ -1127,7 +1131,7 @@ static void write_journal(struct dm_integrity_c *ic, unsigned commit_start, unsi
for (i = 0; i < commit_sections; i++) for (i = 0; i < commit_sections; i++)
rw_section_mac(ic, commit_start + i, true); rw_section_mac(ic, commit_start + i, true);
} }
rw_journal(ic, REQ_OP_WRITE, REQ_FUA | REQ_SYNC, commit_start, rw_journal(ic, REQ_OP_WRITE | REQ_FUA | REQ_SYNC, commit_start,
commit_sections, &io_comp); commit_sections, &io_comp);
} else { } else {
unsigned to_end; unsigned to_end;
...@@ -1139,7 +1143,8 @@ static void write_journal(struct dm_integrity_c *ic, unsigned commit_start, unsi ...@@ -1139,7 +1143,8 @@ static void write_journal(struct dm_integrity_c *ic, unsigned commit_start, unsi
crypt_comp_1.in_flight = (atomic_t)ATOMIC_INIT(0); crypt_comp_1.in_flight = (atomic_t)ATOMIC_INIT(0);
encrypt_journal(ic, true, commit_start, to_end, &crypt_comp_1); encrypt_journal(ic, true, commit_start, to_end, &crypt_comp_1);
if (try_wait_for_completion(&crypt_comp_1.comp)) { if (try_wait_for_completion(&crypt_comp_1.comp)) {
rw_journal(ic, REQ_OP_WRITE, REQ_FUA, commit_start, to_end, &io_comp); rw_journal(ic, REQ_OP_WRITE | REQ_FUA,
commit_start, to_end, &io_comp);
reinit_completion(&crypt_comp_1.comp); reinit_completion(&crypt_comp_1.comp);
crypt_comp_1.in_flight = (atomic_t)ATOMIC_INIT(0); crypt_comp_1.in_flight = (atomic_t)ATOMIC_INIT(0);
encrypt_journal(ic, true, 0, commit_sections - to_end, &crypt_comp_1); 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 ...@@ -1150,17 +1155,17 @@ static void write_journal(struct dm_integrity_c *ic, unsigned commit_start, unsi
crypt_comp_2.in_flight = (atomic_t)ATOMIC_INIT(0); crypt_comp_2.in_flight = (atomic_t)ATOMIC_INIT(0);
encrypt_journal(ic, true, 0, commit_sections - to_end, &crypt_comp_2); encrypt_journal(ic, true, 0, commit_sections - to_end, &crypt_comp_2);
wait_for_completion_io(&crypt_comp_1.comp); wait_for_completion_io(&crypt_comp_1.comp);
rw_journal(ic, REQ_OP_WRITE, REQ_FUA, commit_start, to_end, &io_comp); rw_journal(ic, REQ_OP_WRITE | REQ_FUA, commit_start, to_end, &io_comp);
wait_for_completion_io(&crypt_comp_2.comp); wait_for_completion_io(&crypt_comp_2.comp);
} }
} else { } else {
for (i = 0; i < to_end; i++) for (i = 0; i < to_end; i++)
rw_section_mac(ic, commit_start + i, true); rw_section_mac(ic, commit_start + i, true);
rw_journal(ic, REQ_OP_WRITE, REQ_FUA, commit_start, to_end, &io_comp); rw_journal(ic, REQ_OP_WRITE | REQ_FUA, commit_start, to_end, &io_comp);
for (i = 0; i < commit_sections - to_end; i++) for (i = 0; i < commit_sections - to_end; i++)
rw_section_mac(ic, i, true); rw_section_mac(ic, i, true);
} }
rw_journal(ic, REQ_OP_WRITE, REQ_FUA, 0, commit_sections - to_end, &io_comp); rw_journal(ic, REQ_OP_WRITE | REQ_FUA, 0, commit_sections - to_end, &io_comp);
} }
wait_for_completion_io(&io_comp.comp); wait_for_completion_io(&io_comp.comp);
...@@ -2622,7 +2627,7 @@ static void recalc_write_super(struct dm_integrity_c *ic) ...@@ -2622,7 +2627,7 @@ static void recalc_write_super(struct dm_integrity_c *ic)
if (dm_integrity_failed(ic)) if (dm_integrity_failed(ic))
return; return;
r = sync_rw_sb(ic, REQ_OP_WRITE, 0); r = sync_rw_sb(ic, REQ_OP_WRITE);
if (unlikely(r)) if (unlikely(r))
dm_integrity_io_error(ic, "writing superblock", r); dm_integrity_io_error(ic, "writing superblock", r);
} }
...@@ -2795,7 +2800,7 @@ static void bitmap_block_work(struct work_struct *w) ...@@ -2795,7 +2800,7 @@ static void bitmap_block_work(struct work_struct *w)
if (bio_list_empty(&waiting)) if (bio_list_empty(&waiting))
return; return;
rw_journal_sectors(ic, REQ_OP_WRITE, REQ_FUA | REQ_SYNC, rw_journal_sectors(ic, REQ_OP_WRITE | REQ_FUA | REQ_SYNC,
bbs->idx * (BITMAP_BLOCK_SIZE >> SECTOR_SHIFT), bbs->idx * (BITMAP_BLOCK_SIZE >> SECTOR_SHIFT),
BITMAP_BLOCK_SIZE >> SECTOR_SHIFT, NULL); BITMAP_BLOCK_SIZE >> SECTOR_SHIFT, NULL);
...@@ -2841,7 +2846,7 @@ static void bitmap_flush_work(struct work_struct *work) ...@@ -2841,7 +2846,7 @@ static void bitmap_flush_work(struct work_struct *work)
block_bitmap_op(ic, ic->journal, 0, limit, BITMAP_OP_CLEAR); block_bitmap_op(ic, ic->journal, 0, limit, BITMAP_OP_CLEAR);
block_bitmap_op(ic, ic->may_write_bitmap, 0, limit, BITMAP_OP_CLEAR); block_bitmap_op(ic, ic->may_write_bitmap, 0, limit, BITMAP_OP_CLEAR);
rw_journal_sectors(ic, REQ_OP_WRITE, REQ_FUA | REQ_SYNC, 0, rw_journal_sectors(ic, REQ_OP_WRITE | REQ_FUA | REQ_SYNC, 0,
ic->n_bitmap_blocks * (BITMAP_BLOCK_SIZE >> SECTOR_SHIFT), NULL); ic->n_bitmap_blocks * (BITMAP_BLOCK_SIZE >> SECTOR_SHIFT), NULL);
spin_lock_irq(&ic->endio_wait.lock); spin_lock_irq(&ic->endio_wait.lock);
...@@ -2913,7 +2918,7 @@ static void replay_journal(struct dm_integrity_c *ic) ...@@ -2913,7 +2918,7 @@ static void replay_journal(struct dm_integrity_c *ic)
if (!ic->just_formatted) { if (!ic->just_formatted) {
DEBUG_print("reading journal\n"); DEBUG_print("reading journal\n");
rw_journal(ic, REQ_OP_READ, 0, 0, ic->journal_sections, NULL); rw_journal(ic, REQ_OP_READ, 0, ic->journal_sections, NULL);
if (ic->journal_io) if (ic->journal_io)
DEBUG_bytes(lowmem_page_address(ic->journal_io[0].page), 64, "read journal"); DEBUG_bytes(lowmem_page_address(ic->journal_io[0].page), 64, "read journal");
if (ic->journal_io) { if (ic->journal_io) {
...@@ -3108,7 +3113,7 @@ static void dm_integrity_postsuspend(struct dm_target *ti) ...@@ -3108,7 +3113,7 @@ static void dm_integrity_postsuspend(struct dm_target *ti)
/* set to 0 to test bitmap replay code */ /* set to 0 to test bitmap replay code */
init_journal(ic, 0, ic->journal_sections, 0); init_journal(ic, 0, ic->journal_sections, 0);
ic->sb->flags &= ~cpu_to_le32(SB_FLAG_DIRTY_BITMAP); ic->sb->flags &= ~cpu_to_le32(SB_FLAG_DIRTY_BITMAP);
r = sync_rw_sb(ic, REQ_OP_WRITE, REQ_FUA); r = sync_rw_sb(ic, REQ_OP_WRITE | REQ_FUA);
if (unlikely(r)) if (unlikely(r))
dm_integrity_io_error(ic, "writing superblock", r); dm_integrity_io_error(ic, "writing superblock", r);
#endif #endif
...@@ -3131,23 +3136,23 @@ static void dm_integrity_resume(struct dm_target *ti) ...@@ -3131,23 +3136,23 @@ static void dm_integrity_resume(struct dm_target *ti)
if (ic->provided_data_sectors > old_provided_data_sectors && if (ic->provided_data_sectors > old_provided_data_sectors &&
ic->mode == 'B' && ic->mode == 'B' &&
ic->sb->log2_blocks_per_bitmap_bit == ic->log2_blocks_per_bitmap_bit) { ic->sb->log2_blocks_per_bitmap_bit == ic->log2_blocks_per_bitmap_bit) {
rw_journal_sectors(ic, REQ_OP_READ, 0, 0, rw_journal_sectors(ic, REQ_OP_READ, 0,
ic->n_bitmap_blocks * (BITMAP_BLOCK_SIZE >> SECTOR_SHIFT), NULL); ic->n_bitmap_blocks * (BITMAP_BLOCK_SIZE >> SECTOR_SHIFT), NULL);
block_bitmap_op(ic, ic->journal, old_provided_data_sectors, block_bitmap_op(ic, ic->journal, old_provided_data_sectors,
ic->provided_data_sectors - old_provided_data_sectors, BITMAP_OP_SET); ic->provided_data_sectors - old_provided_data_sectors, BITMAP_OP_SET);
rw_journal_sectors(ic, REQ_OP_WRITE, REQ_FUA | REQ_SYNC, 0, rw_journal_sectors(ic, REQ_OP_WRITE | REQ_FUA | REQ_SYNC, 0,
ic->n_bitmap_blocks * (BITMAP_BLOCK_SIZE >> SECTOR_SHIFT), NULL); ic->n_bitmap_blocks * (BITMAP_BLOCK_SIZE >> SECTOR_SHIFT), NULL);
} }
ic->sb->provided_data_sectors = cpu_to_le64(ic->provided_data_sectors); ic->sb->provided_data_sectors = cpu_to_le64(ic->provided_data_sectors);
r = sync_rw_sb(ic, REQ_OP_WRITE, REQ_FUA); r = sync_rw_sb(ic, REQ_OP_WRITE | REQ_FUA);
if (unlikely(r)) if (unlikely(r))
dm_integrity_io_error(ic, "writing superblock", r); dm_integrity_io_error(ic, "writing superblock", r);
} }
if (ic->sb->flags & cpu_to_le32(SB_FLAG_DIRTY_BITMAP)) { if (ic->sb->flags & cpu_to_le32(SB_FLAG_DIRTY_BITMAP)) {
DEBUG_print("resume dirty_bitmap\n"); DEBUG_print("resume dirty_bitmap\n");
rw_journal_sectors(ic, REQ_OP_READ, 0, 0, rw_journal_sectors(ic, REQ_OP_READ, 0,
ic->n_bitmap_blocks * (BITMAP_BLOCK_SIZE >> SECTOR_SHIFT), NULL); ic->n_bitmap_blocks * (BITMAP_BLOCK_SIZE >> SECTOR_SHIFT), NULL);
if (ic->mode == 'B') { if (ic->mode == 'B') {
if (ic->sb->log2_blocks_per_bitmap_bit == ic->log2_blocks_per_bitmap_bit && 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) ...@@ -3166,7 +3171,7 @@ static void dm_integrity_resume(struct dm_target *ti)
block_bitmap_op(ic, ic->recalc_bitmap, 0, ic->provided_data_sectors, BITMAP_OP_SET); block_bitmap_op(ic, ic->recalc_bitmap, 0, ic->provided_data_sectors, BITMAP_OP_SET);
block_bitmap_op(ic, ic->may_write_bitmap, 0, ic->provided_data_sectors, BITMAP_OP_SET); block_bitmap_op(ic, ic->may_write_bitmap, 0, ic->provided_data_sectors, BITMAP_OP_SET);
block_bitmap_op(ic, ic->journal, 0, ic->provided_data_sectors, BITMAP_OP_SET); block_bitmap_op(ic, ic->journal, 0, ic->provided_data_sectors, BITMAP_OP_SET);
rw_journal_sectors(ic, REQ_OP_WRITE, REQ_FUA | REQ_SYNC, 0, rw_journal_sectors(ic, REQ_OP_WRITE | REQ_FUA | REQ_SYNC, 0,
ic->n_bitmap_blocks * (BITMAP_BLOCK_SIZE >> SECTOR_SHIFT), NULL); ic->n_bitmap_blocks * (BITMAP_BLOCK_SIZE >> SECTOR_SHIFT), NULL);
ic->sb->flags |= cpu_to_le32(SB_FLAG_RECALCULATING); ic->sb->flags |= cpu_to_le32(SB_FLAG_RECALCULATING);
ic->sb->recalc_sector = cpu_to_le64(0); ic->sb->recalc_sector = cpu_to_le64(0);
...@@ -3182,7 +3187,7 @@ static void dm_integrity_resume(struct dm_target *ti) ...@@ -3182,7 +3187,7 @@ static void dm_integrity_resume(struct dm_target *ti)
replay_journal(ic); replay_journal(ic);
ic->sb->flags &= ~cpu_to_le32(SB_FLAG_DIRTY_BITMAP); ic->sb->flags &= ~cpu_to_le32(SB_FLAG_DIRTY_BITMAP);
} }
r = sync_rw_sb(ic, REQ_OP_WRITE, REQ_FUA); r = sync_rw_sb(ic, REQ_OP_WRITE | REQ_FUA);
if (unlikely(r)) if (unlikely(r))
dm_integrity_io_error(ic, "writing superblock", r); dm_integrity_io_error(ic, "writing superblock", r);
} else { } else {
...@@ -3194,7 +3199,7 @@ static void dm_integrity_resume(struct dm_target *ti) ...@@ -3194,7 +3199,7 @@ static void dm_integrity_resume(struct dm_target *ti)
if (ic->mode == 'B') { if (ic->mode == 'B') {
ic->sb->flags |= cpu_to_le32(SB_FLAG_DIRTY_BITMAP); ic->sb->flags |= cpu_to_le32(SB_FLAG_DIRTY_BITMAP);
ic->sb->log2_blocks_per_bitmap_bit = ic->log2_blocks_per_bitmap_bit; ic->sb->log2_blocks_per_bitmap_bit = ic->log2_blocks_per_bitmap_bit;
r = sync_rw_sb(ic, REQ_OP_WRITE, REQ_FUA); r = sync_rw_sb(ic, REQ_OP_WRITE | REQ_FUA);
if (unlikely(r)) if (unlikely(r))
dm_integrity_io_error(ic, "writing superblock", r); dm_integrity_io_error(ic, "writing superblock", r);
...@@ -3210,7 +3215,7 @@ static void dm_integrity_resume(struct dm_target *ti) ...@@ -3210,7 +3215,7 @@ static void dm_integrity_resume(struct dm_target *ti)
block_bitmap_op(ic, ic->may_write_bitmap, le64_to_cpu(ic->sb->recalc_sector), block_bitmap_op(ic, ic->may_write_bitmap, le64_to_cpu(ic->sb->recalc_sector),
ic->provided_data_sectors - le64_to_cpu(ic->sb->recalc_sector), BITMAP_OP_SET); ic->provided_data_sectors - le64_to_cpu(ic->sb->recalc_sector), BITMAP_OP_SET);
} }
rw_journal_sectors(ic, REQ_OP_WRITE, REQ_FUA | REQ_SYNC, 0, rw_journal_sectors(ic, REQ_OP_WRITE | REQ_FUA | REQ_SYNC, 0,
ic->n_bitmap_blocks * (BITMAP_BLOCK_SIZE >> SECTOR_SHIFT), NULL); ic->n_bitmap_blocks * (BITMAP_BLOCK_SIZE >> SECTOR_SHIFT), NULL);
} }
} }
...@@ -4251,7 +4256,7 @@ static int dm_integrity_ctr(struct dm_target *ti, unsigned argc, char **argv) ...@@ -4251,7 +4256,7 @@ static int dm_integrity_ctr(struct dm_target *ti, unsigned argc, char **argv)
goto bad; goto bad;
} }
r = sync_rw_sb(ic, REQ_OP_READ, 0); r = sync_rw_sb(ic, REQ_OP_READ);
if (r) { if (r) {
ti->error = "Error reading superblock"; ti->error = "Error reading superblock";
goto bad; goto bad;
...@@ -4495,7 +4500,7 @@ static int dm_integrity_ctr(struct dm_target *ti, unsigned argc, char **argv) ...@@ -4495,7 +4500,7 @@ static int dm_integrity_ctr(struct dm_target *ti, unsigned argc, char **argv)
ti->error = "Error initializing journal"; ti->error = "Error initializing journal";
goto bad; goto bad;
} }
r = sync_rw_sb(ic, REQ_OP_WRITE, REQ_FUA); r = sync_rw_sb(ic, REQ_OP_WRITE | REQ_FUA);
if (r) { if (r) {
ti->error = "Error initializing superblock"; ti->error = "Error initializing superblock";
goto bad; goto bad;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册