forked from Minki/linux
dm crypt: use shifts instead of sector_div
sector_div is very slow, so we introduce a variable sector_shift and use shift instead of sector_div. Signed-off-by: Mikulas Patocka <mpatocka@redhat.com> Signed-off-by: Mike Snitzer <snitzer@redhat.com>
This commit is contained in:
parent
c2bcb2b702
commit
ff3af92b44
@ -172,7 +172,8 @@ struct crypt_config {
|
||||
} iv_gen_private;
|
||||
sector_t iv_offset;
|
||||
unsigned int iv_size;
|
||||
unsigned int sector_size;
|
||||
unsigned short int sector_size;
|
||||
unsigned char sector_shift;
|
||||
|
||||
/* ESSIV: struct crypto_cipher *essiv_tfm */
|
||||
void *iv_private;
|
||||
@ -1062,7 +1063,7 @@ static int crypt_convert_block_aead(struct crypt_config *cc,
|
||||
dmreq = dmreq_of_req(cc, req);
|
||||
dmreq->iv_sector = ctx->cc_sector;
|
||||
if (test_bit(CRYPT_IV_LARGE_SECTORS, &cc->cipher_flags))
|
||||
sector_div(dmreq->iv_sector, cc->sector_size >> SECTOR_SHIFT);
|
||||
dmreq->iv_sector >>= cc->sector_shift;
|
||||
dmreq->ctx = ctx;
|
||||
|
||||
*org_tag_of_dmreq(cc, dmreq) = tag_offset;
|
||||
@ -1155,7 +1156,7 @@ static int crypt_convert_block_skcipher(struct crypt_config *cc,
|
||||
dmreq = dmreq_of_req(cc, req);
|
||||
dmreq->iv_sector = ctx->cc_sector;
|
||||
if (test_bit(CRYPT_IV_LARGE_SECTORS, &cc->cipher_flags))
|
||||
sector_div(dmreq->iv_sector, cc->sector_size >> SECTOR_SHIFT);
|
||||
dmreq->iv_sector >>= cc->sector_shift;
|
||||
dmreq->ctx = ctx;
|
||||
|
||||
*org_tag_of_dmreq(cc, dmreq) = tag_offset;
|
||||
@ -1290,7 +1291,7 @@ static int crypt_convert(struct crypt_config *cc,
|
||||
struct convert_context *ctx)
|
||||
{
|
||||
unsigned int tag_offset = 0;
|
||||
unsigned int sector_step = cc->sector_size / (1 << SECTOR_SHIFT);
|
||||
unsigned int sector_step = cc->sector_size >> SECTOR_SHIFT;
|
||||
int r;
|
||||
|
||||
atomic_set(&ctx->cc_pending, 1);
|
||||
@ -2575,13 +2576,14 @@ static int crypt_ctr_optional(struct dm_target *ti, unsigned int argc, char **ar
|
||||
cc->cipher_auth = kstrdup(sval, GFP_KERNEL);
|
||||
if (!cc->cipher_auth)
|
||||
return -ENOMEM;
|
||||
} else if (sscanf(opt_string, "sector_size:%u%c", &cc->sector_size, &dummy) == 1) {
|
||||
} else if (sscanf(opt_string, "sector_size:%hu%c", &cc->sector_size, &dummy) == 1) {
|
||||
if (cc->sector_size < (1 << SECTOR_SHIFT) ||
|
||||
cc->sector_size > 4096 ||
|
||||
(1 << ilog2(cc->sector_size) != cc->sector_size)) {
|
||||
(cc->sector_size & (cc->sector_size - 1))) {
|
||||
ti->error = "Invalid feature value for sector_size";
|
||||
return -EINVAL;
|
||||
}
|
||||
cc->sector_shift = __ffs(cc->sector_size) - SECTOR_SHIFT;
|
||||
} else if (!strcasecmp(opt_string, "iv_large_sectors"))
|
||||
set_bit(CRYPT_IV_LARGE_SECTORS, &cc->cipher_flags);
|
||||
else {
|
||||
@ -2625,6 +2627,7 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
|
||||
}
|
||||
cc->key_size = key_size;
|
||||
cc->sector_size = (1 << SECTOR_SHIFT);
|
||||
cc->sector_shift = 0;
|
||||
|
||||
ti->private = cc;
|
||||
|
||||
@ -2870,7 +2873,7 @@ static void crypt_status(struct dm_target *ti, status_type_t type,
|
||||
num_feature_args += !!ti->num_discard_bios;
|
||||
num_feature_args += test_bit(DM_CRYPT_SAME_CPU, &cc->flags);
|
||||
num_feature_args += test_bit(DM_CRYPT_NO_OFFLOAD, &cc->flags);
|
||||
num_feature_args += (cc->sector_size != (1 << SECTOR_SHIFT)) ? 1 : 0;
|
||||
num_feature_args += cc->sector_size != (1 << SECTOR_SHIFT);
|
||||
num_feature_args += test_bit(CRYPT_IV_LARGE_SECTORS, &cc->cipher_flags);
|
||||
if (cc->on_disk_tag_size)
|
||||
num_feature_args++;
|
||||
|
Loading…
Reference in New Issue
Block a user