2019-07-31 15:57:31 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2019-06-24 07:22:54 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2019 HUAWEI, Inc.
|
2020-07-13 13:09:44 +00:00
|
|
|
* https://www.huawei.com/
|
2019-06-24 07:22:54 +00:00
|
|
|
* Created by Gao Xiang <gaoxiang25@huawei.com>
|
|
|
|
*/
|
|
|
|
#ifndef __EROFS_FS_COMPRESS_H
|
|
|
|
#define __EROFS_FS_COMPRESS_H
|
|
|
|
|
2019-06-24 07:22:55 +00:00
|
|
|
#include "internal.h"
|
|
|
|
|
|
|
|
enum {
|
|
|
|
Z_EROFS_COMPRESSION_SHIFTED = Z_EROFS_COMPRESSION_MAX,
|
|
|
|
Z_EROFS_COMPRESSION_RUNTIME_MAX
|
|
|
|
};
|
|
|
|
|
|
|
|
struct z_erofs_decompress_req {
|
2019-06-24 07:22:56 +00:00
|
|
|
struct super_block *sb;
|
2019-06-24 07:22:55 +00:00
|
|
|
struct page **in, **out;
|
|
|
|
|
|
|
|
unsigned short pageofs_out;
|
|
|
|
unsigned int inputsize, outputsize;
|
|
|
|
|
|
|
|
/* indicate the algorithm will be used for decompression */
|
|
|
|
unsigned int alg;
|
|
|
|
bool inplace_io, partial_decoding;
|
|
|
|
};
|
|
|
|
|
2020-12-08 09:58:32 +00:00
|
|
|
/* some special page->private (unsigned long, see below) */
|
|
|
|
#define Z_EROFS_SHORTLIVED_PAGE (-1UL << 2)
|
2020-12-09 12:37:17 +00:00
|
|
|
#define Z_EROFS_PREALLOCATED_PAGE (-2UL << 2)
|
2020-12-08 09:58:32 +00:00
|
|
|
|
2019-06-24 07:22:54 +00:00
|
|
|
/*
|
2020-12-08 09:58:32 +00:00
|
|
|
* For all pages in a pcluster, page->private should be one of
|
|
|
|
* Type Last 2bits page->private
|
|
|
|
* short-lived page 00 Z_EROFS_SHORTLIVED_PAGE
|
2020-12-09 12:37:17 +00:00
|
|
|
* preallocated page (tryalloc) 00 Z_EROFS_PREALLOCATED_PAGE
|
2020-12-08 09:58:32 +00:00
|
|
|
* cached/managed page 00 pointer to z_erofs_pcluster
|
|
|
|
* online page (file-backed, 01/10/11 sub-index << 2 | count
|
|
|
|
* some pages can be used for inplace I/O)
|
|
|
|
*
|
|
|
|
* page->mapping should be one of
|
|
|
|
* Type page->mapping
|
|
|
|
* short-lived page NULL
|
2020-12-09 12:37:17 +00:00
|
|
|
* preallocated page NULL
|
2020-12-08 09:58:32 +00:00
|
|
|
* cached/managed page non-NULL or NULL (invalidated/truncated page)
|
|
|
|
* online page non-NULL
|
|
|
|
*
|
|
|
|
* For all managed pages, PG_private should be set with 1 extra refcount,
|
|
|
|
* which is used for page reclaim / migration.
|
2019-06-24 07:22:54 +00:00
|
|
|
*/
|
|
|
|
|
2020-12-08 09:58:32 +00:00
|
|
|
/*
|
|
|
|
* short-lived pages are pages directly from buddy system with specific
|
|
|
|
* page->private (no need to set PagePrivate since these are non-LRU /
|
|
|
|
* non-movable pages and bypass reclaim / migration code).
|
|
|
|
*/
|
|
|
|
static inline bool z_erofs_is_shortlived_page(struct page *page)
|
2019-06-24 07:22:54 +00:00
|
|
|
{
|
2020-12-08 09:58:32 +00:00
|
|
|
if (page->private != Z_EROFS_SHORTLIVED_PAGE)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
DBG_BUGON(page->mapping);
|
|
|
|
return true;
|
2019-06-24 07:22:54 +00:00
|
|
|
}
|
|
|
|
|
2020-12-08 09:58:32 +00:00
|
|
|
static inline bool z_erofs_put_shortlivedpage(struct list_head *pagepool,
|
|
|
|
struct page *page)
|
2019-06-24 07:22:54 +00:00
|
|
|
{
|
2020-12-08 09:58:32 +00:00
|
|
|
if (!z_erofs_is_shortlived_page(page))
|
2019-06-24 07:22:54 +00:00
|
|
|
return false;
|
|
|
|
|
2020-12-08 09:58:32 +00:00
|
|
|
/* short-lived pages should not be used by others at the same time */
|
|
|
|
if (page_ref_count(page) > 1) {
|
2019-06-24 07:22:54 +00:00
|
|
|
put_page(page);
|
2020-12-08 09:58:32 +00:00
|
|
|
} else {
|
|
|
|
/* follow the pcluster rule above. */
|
|
|
|
set_page_private(page, 0);
|
2019-06-24 07:22:54 +00:00
|
|
|
list_add(&page->lru, pagepool);
|
2020-12-08 09:58:32 +00:00
|
|
|
}
|
2019-06-24 07:22:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-06-24 07:22:55 +00:00
|
|
|
int z_erofs_decompress(struct z_erofs_decompress_req *rq,
|
|
|
|
struct list_head *pagepool);
|
|
|
|
|
2019-06-24 07:22:54 +00:00
|
|
|
#endif
|
|
|
|
|