Lines Matching refs:ctx
81 void f2fs_release_crypto_ctx(struct f2fs_crypto_ctx *ctx) in f2fs_release_crypto_ctx() argument
85 if (ctx->flags & F2FS_WRITE_PATH_FL && ctx->w.bounce_page) { in f2fs_release_crypto_ctx()
86 mempool_free(ctx->w.bounce_page, f2fs_bounce_page_pool); in f2fs_release_crypto_ctx()
87 ctx->w.bounce_page = NULL; in f2fs_release_crypto_ctx()
89 ctx->w.control_page = NULL; in f2fs_release_crypto_ctx()
90 if (ctx->flags & F2FS_CTX_REQUIRES_FREE_ENCRYPT_FL) { in f2fs_release_crypto_ctx()
91 kmem_cache_free(f2fs_crypto_ctx_cachep, ctx); in f2fs_release_crypto_ctx()
94 list_add(&ctx->free_list, &f2fs_free_crypto_ctxs); in f2fs_release_crypto_ctx()
110 struct f2fs_crypto_ctx *ctx = NULL; in f2fs_get_crypto_ctx() local
128 ctx = list_first_entry_or_null(&f2fs_free_crypto_ctxs, in f2fs_get_crypto_ctx()
130 if (ctx) in f2fs_get_crypto_ctx()
131 list_del(&ctx->free_list); in f2fs_get_crypto_ctx()
133 if (!ctx) { in f2fs_get_crypto_ctx()
134 ctx = kmem_cache_zalloc(f2fs_crypto_ctx_cachep, GFP_NOFS); in f2fs_get_crypto_ctx()
135 if (!ctx) in f2fs_get_crypto_ctx()
137 ctx->flags |= F2FS_CTX_REQUIRES_FREE_ENCRYPT_FL; in f2fs_get_crypto_ctx()
139 ctx->flags &= ~F2FS_CTX_REQUIRES_FREE_ENCRYPT_FL; in f2fs_get_crypto_ctx()
141 ctx->flags &= ~F2FS_WRITE_PATH_FL; in f2fs_get_crypto_ctx()
142 return ctx; in f2fs_get_crypto_ctx()
151 struct f2fs_crypto_ctx *ctx = in completion_pages() local
153 struct bio *bio = ctx->r.bio; in completion_pages()
159 int ret = f2fs_decrypt(ctx, page); in completion_pages()
168 f2fs_release_crypto_ctx(ctx); in completion_pages()
172 void f2fs_end_io_crypto_work(struct f2fs_crypto_ctx *ctx, struct bio *bio) in f2fs_end_io_crypto_work() argument
174 INIT_WORK(&ctx->r.work, completion_pages); in f2fs_end_io_crypto_work()
175 ctx->r.bio = bio; in f2fs_end_io_crypto_work()
176 queue_work(f2fs_read_workqueue, &ctx->r.work); in f2fs_end_io_crypto_work()
211 struct f2fs_crypto_ctx *ctx; in f2fs_crypto_initialize() local
213 ctx = kmem_cache_zalloc(f2fs_crypto_ctx_cachep, GFP_KERNEL); in f2fs_crypto_initialize()
214 if (!ctx) in f2fs_crypto_initialize()
216 list_add(&ctx->free_list, &f2fs_free_crypto_ctxs); in f2fs_crypto_initialize()
275 struct f2fs_crypto_ctx *ctx; in f2fs_restore_and_release_control_page() local
284 ctx = (struct f2fs_crypto_ctx *)page_private(bounce_page); in f2fs_restore_and_release_control_page()
287 *page = ctx->w.control_page; in f2fs_restore_and_release_control_page()
294 struct f2fs_crypto_ctx *ctx = in f2fs_restore_control_page() local
300 f2fs_release_crypto_ctx(ctx); in f2fs_restore_control_page()
323 static int f2fs_page_crypto(struct f2fs_crypto_ctx *ctx, in f2fs_page_crypto() argument
379 static struct page *alloc_bounce_page(struct f2fs_crypto_ctx *ctx) in alloc_bounce_page() argument
381 ctx->w.bounce_page = mempool_alloc(f2fs_bounce_page_pool, GFP_NOWAIT); in alloc_bounce_page()
382 if (ctx->w.bounce_page == NULL) in alloc_bounce_page()
384 ctx->flags |= F2FS_WRITE_PATH_FL; in alloc_bounce_page()
385 return ctx->w.bounce_page; in alloc_bounce_page()
406 struct f2fs_crypto_ctx *ctx; in f2fs_encrypt() local
412 ctx = f2fs_get_crypto_ctx(inode); in f2fs_encrypt()
413 if (IS_ERR(ctx)) in f2fs_encrypt()
414 return (struct page *)ctx; in f2fs_encrypt()
417 ciphertext_page = alloc_bounce_page(ctx); in f2fs_encrypt()
421 ctx->w.control_page = plaintext_page; in f2fs_encrypt()
422 err = f2fs_page_crypto(ctx, inode, F2FS_ENCRYPT, plaintext_page->index, in f2fs_encrypt()
430 set_page_private(ciphertext_page, (unsigned long)ctx); in f2fs_encrypt()
435 f2fs_release_crypto_ctx(ctx); in f2fs_encrypt()
450 int f2fs_decrypt(struct f2fs_crypto_ctx *ctx, struct page *page) in f2fs_decrypt() argument
454 return f2fs_page_crypto(ctx, page->mapping->host, in f2fs_decrypt()
464 struct f2fs_crypto_ctx *ctx = f2fs_get_crypto_ctx(inode); in f2fs_decrypt_one() local
467 if (IS_ERR(ctx)) in f2fs_decrypt_one()
468 return PTR_ERR(ctx); in f2fs_decrypt_one()
469 ret = f2fs_decrypt(ctx, page); in f2fs_decrypt_one()
470 f2fs_release_crypto_ctx(ctx); in f2fs_decrypt_one()