Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Copyright (C) 2019 HUAWEI, Inc.
0004  *             https://www.huawei.com/
0005  */
0006 #ifndef __EROFS_FS_COMPRESS_H
0007 #define __EROFS_FS_COMPRESS_H
0008 
0009 #include "internal.h"
0010 
0011 struct z_erofs_decompress_req {
0012     struct super_block *sb;
0013     struct page **in, **out;
0014 
0015     unsigned short pageofs_in, pageofs_out;
0016     unsigned int inputsize, outputsize;
0017 
0018     /* indicate the algorithm will be used for decompression */
0019     unsigned int alg;
0020     bool inplace_io, partial_decoding, fillgaps;
0021 };
0022 
0023 struct z_erofs_decompressor {
0024     int (*decompress)(struct z_erofs_decompress_req *rq,
0025               struct page **pagepool);
0026     char *name;
0027 };
0028 
0029 /* some special page->private (unsigned long, see below) */
0030 #define Z_EROFS_SHORTLIVED_PAGE     (-1UL << 2)
0031 #define Z_EROFS_PREALLOCATED_PAGE   (-2UL << 2)
0032 
0033 /*
0034  * For all pages in a pcluster, page->private should be one of
0035  * Type                         Last 2bits      page->private
0036  * short-lived page             00              Z_EROFS_SHORTLIVED_PAGE
0037  * preallocated page (tryalloc) 00              Z_EROFS_PREALLOCATED_PAGE
0038  * cached/managed page          00              pointer to z_erofs_pcluster
0039  * online page (file-backed,    01/10/11        sub-index << 2 | count
0040  *              some pages can be used for inplace I/O)
0041  *
0042  * page->mapping should be one of
0043  * Type                 page->mapping
0044  * short-lived page     NULL
0045  * preallocated page    NULL
0046  * cached/managed page  non-NULL or NULL (invalidated/truncated page)
0047  * online page          non-NULL
0048  *
0049  * For all managed pages, PG_private should be set with 1 extra refcount,
0050  * which is used for page reclaim / migration.
0051  */
0052 
0053 /*
0054  * short-lived pages are pages directly from buddy system with specific
0055  * page->private (no need to set PagePrivate since these are non-LRU /
0056  * non-movable pages and bypass reclaim / migration code).
0057  */
0058 static inline bool z_erofs_is_shortlived_page(struct page *page)
0059 {
0060     if (page->private != Z_EROFS_SHORTLIVED_PAGE)
0061         return false;
0062 
0063     DBG_BUGON(page->mapping);
0064     return true;
0065 }
0066 
0067 static inline bool z_erofs_put_shortlivedpage(struct page **pagepool,
0068                           struct page *page)
0069 {
0070     if (!z_erofs_is_shortlived_page(page))
0071         return false;
0072 
0073     /* short-lived pages should not be used by others at the same time */
0074     if (page_ref_count(page) > 1) {
0075         put_page(page);
0076     } else {
0077         /* follow the pcluster rule above. */
0078         erofs_pagepool_add(pagepool, page);
0079     }
0080     return true;
0081 }
0082 
0083 #define MNGD_MAPPING(sbi)   ((sbi)->managed_cache->i_mapping)
0084 static inline bool erofs_page_is_managed(const struct erofs_sb_info *sbi,
0085                      struct page *page)
0086 {
0087     return page->mapping == MNGD_MAPPING(sbi);
0088 }
0089 
0090 int z_erofs_fixup_insize(struct z_erofs_decompress_req *rq, const char *padbuf,
0091              unsigned int padbufsize);
0092 int z_erofs_decompress(struct z_erofs_decompress_req *rq,
0093                struct page **pagepool);
0094 
0095 /* prototypes for specific algorithms */
0096 int z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq,
0097                 struct page **pagepool);
0098 #endif