/* Encrypt / decrypt data from one bio to another one (can be the same one)  */
static int crypt_convert(struct crypt_config *cc, struct convert_context *ctx)
/* Encrypt / decrypt data from one bio to another one (can be the same one)  */
static int crypt_convert(struct crypt_config *cc, struct convert_context *ctx)
{
	int r;
	atomic_set(&ctx->pending, 1);
	while(ctx->idx_in < ctx->bio_in->bi_vcnt &&
	      ctx->idx_out < ctx->bio_out->bi_vcnt) {
		crypt_alloc_req(cc, ctx);
		atomic_inc(&ctx->pending);
		r = crypt_convert_block(cc, ctx, cc->req);
		switch (r) {
		case -EBUSY:
			wait_for_completion(&ctx->restart);
			INIT_COMPLETION(ctx->restart);
		case -EINPROGRESS:
			cc->req = NULL;
			ctx->sector++;
			continue;
		case 0:
			atomic_dec(&ctx->pending);
			ctx->sector++;
			cond_resched();
			continue;
		default:
			atomic_dec(&ctx->pending);
			return r;
		}
	}
	return 0;
}