Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 84586
b: refs/heads/master
c: 43d6903
h: refs/heads/master
v: v3
  • Loading branch information
Milan Broz authored and Alasdair G Kergon committed Feb 8, 2008
1 parent 4409f66 commit 5223fa5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: ddd42edfd8ec44595b1501318512bc29a36f015f
refs/heads/master: 43d6903482eec168b727bc4bf76a9f415257d862
21 changes: 21 additions & 0 deletions trunk/drivers/md/dm-crypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* This file is released under the GPL.
*/

#include <linux/completion.h>
#include <linux/err.h>
#include <linux/module.h>
#include <linux/init.h>
Expand All @@ -31,13 +32,15 @@
* context holding the current state of a multi-part conversion
*/
struct convert_context {
struct completion restart;
struct bio *bio_in;
struct bio *bio_out;
unsigned int offset_in;
unsigned int offset_out;
unsigned int idx_in;
unsigned int idx_out;
sector_t sector;
atomic_t pending;
};

/*
Expand Down Expand Up @@ -359,6 +362,15 @@ static void crypt_convert_init(struct crypt_config *cc,
ctx->idx_in = bio_in ? bio_in->bi_idx : 0;
ctx->idx_out = bio_out ? bio_out->bi_idx : 0;
ctx->sector = sector + cc->iv_offset;
init_completion(&ctx->restart);
/*
* Crypto operation can be asynchronous,
* ctx->pending is increased after request submission.
* We need to ensure that we don't call the crypt finish
* operation before pending got incremented
* (dependent on crypt submission return code).
*/
atomic_set(&ctx->pending, 2);
}

static int crypt_convert_block(struct crypt_config *cc,
Expand Down Expand Up @@ -418,6 +430,15 @@ static int crypt_convert(struct crypt_config *cc,
ctx->sector++;
}

/*
* If there are pending crypto operation run async
* code. Otherwise process return code synchronously.
* The step of 2 ensures that async finish doesn't
* call crypto finish too early.
*/
if (atomic_sub_return(2, &ctx->pending))
return -EINPROGRESS;

return r;
}

Expand Down

0 comments on commit 5223fa5

Please sign in to comment.