Commit af05633d authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: convert __bch2_encrypt_bio() to darray

like the previous patch, kill use of bare arrays; the encryption code
likes to work in big batches, so this is a small performance
improvement.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent b7d8092a
...@@ -337,39 +337,42 @@ int __bch2_encrypt_bio(struct bch_fs *c, unsigned type, ...@@ -337,39 +337,42 @@ int __bch2_encrypt_bio(struct bch_fs *c, unsigned type,
{ {
struct bio_vec bv; struct bio_vec bv;
struct bvec_iter iter; struct bvec_iter iter;
struct scatterlist sgl[16], *sg = sgl; DARRAY_PREALLOCATED(struct scatterlist, 4) sgl;
size_t bytes = 0; size_t sgl_len = 0;
int ret = 0; int ret = 0;
if (!bch2_csum_type_is_encryption(type)) if (!bch2_csum_type_is_encryption(type))
return 0; return 0;
sg_init_table(sgl, ARRAY_SIZE(sgl)); darray_init(&sgl);
bio_for_each_segment(bv, bio, iter) { bio_for_each_segment(bv, bio, iter) {
if (sg == sgl + ARRAY_SIZE(sgl)) { struct scatterlist sg = {
sg_mark_end(sg - 1); .page_link = (unsigned long) bv.bv_page,
.offset = bv.bv_offset,
ret = do_encrypt_sg(c->chacha20, nonce, sgl, bytes); .length = bv.bv_len,
};
if (darray_push(&sgl, sg)) {
sg_mark_end(&darray_last(sgl));
ret = do_encrypt_sg(c->chacha20, nonce, sgl.data, sgl_len);
if (ret) if (ret)
return ret; goto err;
nonce = nonce_add(nonce, bytes); nonce = nonce_add(nonce, sgl_len);
bytes = 0; sgl_len = 0;
sgl.nr = 0;
sg_init_table(sgl, ARRAY_SIZE(sgl)); BUG_ON(darray_push(&sgl, sg));
sg = sgl;
} }
sg_set_page(sg++, bv.bv_page, bv.bv_len, bv.bv_offset); sgl_len += sg.length;
bytes += bv.bv_len;
}
if (sg != sgl) {
sg_mark_end(sg - 1);
return do_encrypt_sg(c->chacha20, nonce, sgl, bytes);
} }
sg_mark_end(&darray_last(sgl));
ret = do_encrypt_sg(c->chacha20, nonce, sgl.data, sgl_len);
err:
darray_exit(&sgl);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment