提交 23b1faaa 编写于 作者: C Chao Yu 提交者: Jaegeuk Kim

f2fs: compress: add .{init,destroy}_decompress_ctx callback

Add below two callback interfaces in struct f2fs_compress_ops:

	int (*init_decompress_ctx)(struct decompress_io_ctx *dic);
	void (*destroy_decompress_ctx)(struct decompress_io_ctx *dic);

Which will be used by zstd compress algorithm later.

In addition, this patch adds callback function pointer check, so that
specified algorithm can avoid defining unneeded functions.
Signed-off-by: NChao Yu <yuchao0@huawei.com>
Signed-off-by: NJaegeuk Kim <jaegeuk@kernel.org>
上级 09ff4801
...@@ -20,6 +20,8 @@ struct f2fs_compress_ops { ...@@ -20,6 +20,8 @@ struct f2fs_compress_ops {
int (*init_compress_ctx)(struct compress_ctx *cc); int (*init_compress_ctx)(struct compress_ctx *cc);
void (*destroy_compress_ctx)(struct compress_ctx *cc); void (*destroy_compress_ctx)(struct compress_ctx *cc);
int (*compress_pages)(struct compress_ctx *cc); int (*compress_pages)(struct compress_ctx *cc);
int (*init_decompress_ctx)(struct decompress_io_ctx *dic);
void (*destroy_decompress_ctx)(struct decompress_io_ctx *dic);
int (*decompress_pages)(struct decompress_io_ctx *dic); int (*decompress_pages)(struct decompress_io_ctx *dic);
}; };
...@@ -332,9 +334,11 @@ static int f2fs_compress_pages(struct compress_ctx *cc) ...@@ -332,9 +334,11 @@ static int f2fs_compress_pages(struct compress_ctx *cc)
trace_f2fs_compress_pages_start(cc->inode, cc->cluster_idx, trace_f2fs_compress_pages_start(cc->inode, cc->cluster_idx,
cc->cluster_size, fi->i_compress_algorithm); cc->cluster_size, fi->i_compress_algorithm);
ret = cops->init_compress_ctx(cc); if (cops->init_compress_ctx) {
if (ret) ret = cops->init_compress_ctx(cc);
goto out; if (ret)
goto out;
}
max_len = COMPRESS_HEADER_SIZE + cc->clen; max_len = COMPRESS_HEADER_SIZE + cc->clen;
cc->nr_cpages = DIV_ROUND_UP(max_len, PAGE_SIZE); cc->nr_cpages = DIV_ROUND_UP(max_len, PAGE_SIZE);
...@@ -396,7 +400,8 @@ static int f2fs_compress_pages(struct compress_ctx *cc) ...@@ -396,7 +400,8 @@ static int f2fs_compress_pages(struct compress_ctx *cc)
cc->cpages[i] = NULL; cc->cpages[i] = NULL;
} }
cops->destroy_compress_ctx(cc); if (cops->destroy_compress_ctx)
cops->destroy_compress_ctx(cc);
cc->nr_cpages = nr_cpages; cc->nr_cpages = nr_cpages;
...@@ -416,7 +421,8 @@ static int f2fs_compress_pages(struct compress_ctx *cc) ...@@ -416,7 +421,8 @@ static int f2fs_compress_pages(struct compress_ctx *cc)
kfree(cc->cpages); kfree(cc->cpages);
cc->cpages = NULL; cc->cpages = NULL;
destroy_compress_ctx: destroy_compress_ctx:
cops->destroy_compress_ctx(cc); if (cops->destroy_compress_ctx)
cops->destroy_compress_ctx(cc);
out: out:
trace_f2fs_compress_pages_end(cc->inode, cc->cluster_idx, trace_f2fs_compress_pages_end(cc->inode, cc->cluster_idx,
cc->clen, ret); cc->clen, ret);
...@@ -450,10 +456,16 @@ void f2fs_decompress_pages(struct bio *bio, struct page *page, bool verity) ...@@ -450,10 +456,16 @@ void f2fs_decompress_pages(struct bio *bio, struct page *page, bool verity)
goto out_free_dic; goto out_free_dic;
} }
if (cops->init_decompress_ctx) {
ret = cops->init_decompress_ctx(dic);
if (ret)
goto out_free_dic;
}
dic->rbuf = vmap(dic->tpages, dic->cluster_size, VM_MAP, PAGE_KERNEL); dic->rbuf = vmap(dic->tpages, dic->cluster_size, VM_MAP, PAGE_KERNEL);
if (!dic->rbuf) { if (!dic->rbuf) {
ret = -ENOMEM; ret = -ENOMEM;
goto out_free_dic; goto destroy_decompress_ctx;
} }
dic->cbuf = vmap(dic->cpages, dic->nr_cpages, VM_MAP, PAGE_KERNEL_RO); dic->cbuf = vmap(dic->cpages, dic->nr_cpages, VM_MAP, PAGE_KERNEL_RO);
...@@ -476,6 +488,9 @@ void f2fs_decompress_pages(struct bio *bio, struct page *page, bool verity) ...@@ -476,6 +488,9 @@ void f2fs_decompress_pages(struct bio *bio, struct page *page, bool verity)
vunmap(dic->cbuf); vunmap(dic->cbuf);
out_vunmap_rbuf: out_vunmap_rbuf:
vunmap(dic->rbuf); vunmap(dic->rbuf);
destroy_decompress_ctx:
if (cops->destroy_decompress_ctx)
cops->destroy_decompress_ctx(dic);
out_free_dic: out_free_dic:
if (verity) if (verity)
refcount_set(&dic->ref, dic->nr_cpages); refcount_set(&dic->ref, dic->nr_cpages);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册