Skip to content

Commit 23b1faa

Browse files
chaseyuJaegeuk Kim
authored andcommitted
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: Chao Yu <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent 09ff480 commit 23b1faa

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

fs/f2fs/compress.c

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ struct f2fs_compress_ops {
2020
int (*init_compress_ctx)(struct compress_ctx *cc);
2121
void (*destroy_compress_ctx)(struct compress_ctx *cc);
2222
int (*compress_pages)(struct compress_ctx *cc);
23+
int (*init_decompress_ctx)(struct decompress_io_ctx *dic);
24+
void (*destroy_decompress_ctx)(struct decompress_io_ctx *dic);
2325
int (*decompress_pages)(struct decompress_io_ctx *dic);
2426
};
2527

@@ -332,9 +334,11 @@ static int f2fs_compress_pages(struct compress_ctx *cc)
332334
trace_f2fs_compress_pages_start(cc->inode, cc->cluster_idx,
333335
cc->cluster_size, fi->i_compress_algorithm);
334336

335-
ret = cops->init_compress_ctx(cc);
336-
if (ret)
337-
goto out;
337+
if (cops->init_compress_ctx) {
338+
ret = cops->init_compress_ctx(cc);
339+
if (ret)
340+
goto out;
341+
}
338342

339343
max_len = COMPRESS_HEADER_SIZE + cc->clen;
340344
cc->nr_cpages = DIV_ROUND_UP(max_len, PAGE_SIZE);
@@ -396,7 +400,8 @@ static int f2fs_compress_pages(struct compress_ctx *cc)
396400
cc->cpages[i] = NULL;
397401
}
398402

399-
cops->destroy_compress_ctx(cc);
403+
if (cops->destroy_compress_ctx)
404+
cops->destroy_compress_ctx(cc);
400405

401406
cc->nr_cpages = nr_cpages;
402407

@@ -416,7 +421,8 @@ static int f2fs_compress_pages(struct compress_ctx *cc)
416421
kfree(cc->cpages);
417422
cc->cpages = NULL;
418423
destroy_compress_ctx:
419-
cops->destroy_compress_ctx(cc);
424+
if (cops->destroy_compress_ctx)
425+
cops->destroy_compress_ctx(cc);
420426
out:
421427
trace_f2fs_compress_pages_end(cc->inode, cc->cluster_idx,
422428
cc->clen, ret);
@@ -450,10 +456,16 @@ void f2fs_decompress_pages(struct bio *bio, struct page *page, bool verity)
450456
goto out_free_dic;
451457
}
452458

459+
if (cops->init_decompress_ctx) {
460+
ret = cops->init_decompress_ctx(dic);
461+
if (ret)
462+
goto out_free_dic;
463+
}
464+
453465
dic->rbuf = vmap(dic->tpages, dic->cluster_size, VM_MAP, PAGE_KERNEL);
454466
if (!dic->rbuf) {
455467
ret = -ENOMEM;
456-
goto out_free_dic;
468+
goto destroy_decompress_ctx;
457469
}
458470

459471
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)
476488
vunmap(dic->cbuf);
477489
out_vunmap_rbuf:
478490
vunmap(dic->rbuf);
491+
destroy_decompress_ctx:
492+
if (cops->destroy_decompress_ctx)
493+
cops->destroy_decompress_ctx(dic);
479494
out_free_dic:
480495
if (verity)
481496
refcount_set(&dic->ref, dic->nr_cpages);

0 commit comments

Comments
 (0)