Skip to content

Commit c808161

Browse files
Milan Brozkergon
authored andcommitted
dm crypt: tidy ctx pending
Move the initialisation of ctx->pending into one place, at the start of crypt_convert(). Introduce crypt_finished to indicate whether or not the encryption is finished, for use in a later patch. No functional change. Signed-off-by: Milan Broz <[email protected]> Signed-off-by: Alasdair G Kergon <[email protected]>
1 parent 4e59409 commit c808161

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

drivers/md/dm-crypt.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,6 @@ static void crypt_convert_init(struct crypt_config *cc,
333333
ctx->idx_out = bio_out ? bio_out->bi_idx : 0;
334334
ctx->sector = sector + cc->iv_offset;
335335
init_completion(&ctx->restart);
336-
atomic_set(&ctx->pending, 1);
337336
}
338337

339338
static int crypt_convert_block(struct crypt_config *cc,
@@ -408,6 +407,8 @@ static int crypt_convert(struct crypt_config *cc,
408407
{
409408
int r;
410409

410+
atomic_set(&ctx->pending, 1);
411+
411412
while(ctx->idx_in < ctx->bio_in->bi_vcnt &&
412413
ctx->idx_out < ctx->bio_out->bi_vcnt) {
413414

@@ -694,6 +695,7 @@ static void kcryptd_crypt_write_convert(struct dm_crypt_io *io)
694695
{
695696
struct crypt_config *cc = io->target->private;
696697
struct bio *clone;
698+
int crypt_finished;
697699
unsigned remaining = io->base_bio->bi_size;
698700
int r;
699701

@@ -721,19 +723,23 @@ static void kcryptd_crypt_write_convert(struct dm_crypt_io *io)
721723

722724
crypt_inc_pending(io);
723725
r = crypt_convert(cc, &io->ctx);
726+
crypt_finished = atomic_dec_and_test(&io->ctx.pending);
724727

725-
if (atomic_dec_and_test(&io->ctx.pending)) {
726-
/* processed, no running async crypto */
728+
/* Encryption was already finished, submit io now */
729+
if (crypt_finished) {
727730
kcryptd_crypt_write_io_submit(io, r, 0);
731+
732+
/*
733+
* If there was an error, do not try next fragments.
734+
* For async, error is processed in async handler.
735+
*/
728736
if (unlikely(r < 0))
729737
break;
730738
}
731739

732740
/* out of memory -> run queues */
733741
if (unlikely(remaining)) {
734-
/* wait for async crypto then reinitialize pending */
735742
wait_event(cc->writeq, !atomic_read(&io->ctx.pending));
736-
atomic_set(&io->ctx.pending, 1);
737743
congestion_wait(WRITE, HZ/100);
738744
}
739745
}

0 commit comments

Comments
 (0)