2018-04-04 01:23:33 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2010-10-25 15:12:26 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2008 Oracle. All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/slab.h>
|
2017-05-31 23:21:15 +08:00
|
|
|
#include <linux/mm.h>
|
2010-10-25 15:12:26 +08:00
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/pagemap.h>
|
|
|
|
#include <linux/bio.h>
|
|
|
|
#include <linux/lzo.h>
|
2017-05-26 15:44:59 +08:00
|
|
|
#include <linux/refcount.h>
|
2010-10-25 15:12:26 +08:00
|
|
|
#include "compression.h"
|
|
|
|
|
|
|
|
#define LZO_LEN 4
|
|
|
|
|
2018-05-17 13:10:01 +08:00
|
|
|
/*
|
|
|
|
* Btrfs LZO compression format
|
|
|
|
*
|
|
|
|
* Regular and inlined LZO compressed data extents consist of:
|
|
|
|
*
|
|
|
|
* 1. Header
|
|
|
|
* Fixed size. LZO_LEN (4) bytes long, LE32.
|
|
|
|
* Records the total size (including the header) of compressed data.
|
|
|
|
*
|
|
|
|
* 2. Segment(s)
|
|
|
|
* Variable size. Each segment includes one segment header, followd by data
|
|
|
|
* payload.
|
|
|
|
* One regular LZO compressed extent can have one or more segments.
|
|
|
|
* For inlined LZO compressed extent, only one segment is allowed.
|
|
|
|
* One segment represents at most one page of uncompressed data.
|
|
|
|
*
|
|
|
|
* 2.1 Segment header
|
|
|
|
* Fixed size. LZO_LEN (4) bytes long, LE32.
|
|
|
|
* Records the total size of the segment (not including the header).
|
|
|
|
* Segment header never crosses page boundary, thus it's possible to
|
|
|
|
* have at most 3 padding zeros at the end of the page.
|
|
|
|
*
|
|
|
|
* 2.2 Data Payload
|
|
|
|
* Variable size. Size up limit should be lzo1x_worst_compress(PAGE_SIZE)
|
|
|
|
* which is 4419 for a 4KiB page.
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* Page 1:
|
|
|
|
* 0 0x2 0x4 0x6 0x8 0xa 0xc 0xe 0x10
|
|
|
|
* 0x0000 | Header | SegHdr 01 | Data payload 01 ... |
|
|
|
|
* ...
|
|
|
|
* 0x0ff0 | SegHdr N | Data payload N ... |00|
|
|
|
|
* ^^ padding zeros
|
|
|
|
* Page 2:
|
|
|
|
* 0x1000 | SegHdr N+1| Data payload N+1 ... |
|
|
|
|
*/
|
|
|
|
|
2010-10-25 15:12:26 +08:00
|
|
|
struct workspace {
|
|
|
|
void *mem;
|
2013-06-06 21:38:50 +08:00
|
|
|
void *buf; /* where decompressed data goes */
|
|
|
|
void *cbuf; /* where compressed data goes */
|
2010-10-25 15:12:26 +08:00
|
|
|
struct list_head list;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void lzo_free_workspace(struct list_head *ws)
|
|
|
|
{
|
|
|
|
struct workspace *workspace = list_entry(ws, struct workspace, list);
|
|
|
|
|
2017-05-31 23:21:15 +08:00
|
|
|
kvfree(workspace->buf);
|
|
|
|
kvfree(workspace->cbuf);
|
|
|
|
kvfree(workspace->mem);
|
2010-10-25 15:12:26 +08:00
|
|
|
kfree(workspace);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct list_head *lzo_alloc_workspace(void)
|
|
|
|
{
|
|
|
|
struct workspace *workspace;
|
|
|
|
|
2017-05-31 23:21:15 +08:00
|
|
|
workspace = kzalloc(sizeof(*workspace), GFP_KERNEL);
|
2010-10-25 15:12:26 +08:00
|
|
|
if (!workspace)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
2017-05-31 23:21:15 +08:00
|
|
|
workspace->mem = kvmalloc(LZO1X_MEM_COMPRESS, GFP_KERNEL);
|
|
|
|
workspace->buf = kvmalloc(lzo1x_worst_compress(PAGE_SIZE), GFP_KERNEL);
|
|
|
|
workspace->cbuf = kvmalloc(lzo1x_worst_compress(PAGE_SIZE), GFP_KERNEL);
|
2010-10-25 15:12:26 +08:00
|
|
|
if (!workspace->mem || !workspace->buf || !workspace->cbuf)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&workspace->list);
|
|
|
|
|
|
|
|
return &workspace->list;
|
|
|
|
fail:
|
|
|
|
lzo_free_workspace(&workspace->list);
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void write_compress_length(char *buf, size_t len)
|
|
|
|
{
|
|
|
|
__le32 dlen;
|
|
|
|
|
|
|
|
dlen = cpu_to_le32(len);
|
|
|
|
memcpy(buf, &dlen, LZO_LEN);
|
|
|
|
}
|
|
|
|
|
2017-02-15 00:58:04 +08:00
|
|
|
static inline size_t read_compress_length(const char *buf)
|
2010-10-25 15:12:26 +08:00
|
|
|
{
|
|
|
|
__le32 dlen;
|
|
|
|
|
|
|
|
memcpy(&dlen, buf, LZO_LEN);
|
|
|
|
return le32_to_cpu(dlen);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int lzo_compress_pages(struct list_head *ws,
|
|
|
|
struct address_space *mapping,
|
2017-02-15 02:04:07 +08:00
|
|
|
u64 start,
|
2010-10-25 15:12:26 +08:00
|
|
|
struct page **pages,
|
|
|
|
unsigned long *out_pages,
|
|
|
|
unsigned long *total_in,
|
2017-02-15 02:45:05 +08:00
|
|
|
unsigned long *total_out)
|
2010-10-25 15:12:26 +08:00
|
|
|
{
|
|
|
|
struct workspace *workspace = list_entry(ws, struct workspace, list);
|
|
|
|
int ret = 0;
|
|
|
|
char *data_in;
|
|
|
|
char *cpage_out;
|
|
|
|
int nr_pages = 0;
|
|
|
|
struct page *in_page = NULL;
|
|
|
|
struct page *out_page = NULL;
|
|
|
|
unsigned long bytes_left;
|
2017-02-15 02:04:07 +08:00
|
|
|
unsigned long len = *total_out;
|
2017-02-15 02:04:07 +08:00
|
|
|
unsigned long nr_dest_pages = *out_pages;
|
2017-02-15 02:45:05 +08:00
|
|
|
const unsigned long max_out = nr_dest_pages * PAGE_SIZE;
|
2010-10-25 15:12:26 +08:00
|
|
|
size_t in_len;
|
|
|
|
size_t out_len;
|
|
|
|
char *buf;
|
|
|
|
unsigned long tot_in = 0;
|
|
|
|
unsigned long tot_out = 0;
|
|
|
|
unsigned long pg_bytes_left;
|
|
|
|
unsigned long out_offset;
|
|
|
|
unsigned long bytes;
|
|
|
|
|
|
|
|
*out_pages = 0;
|
|
|
|
*total_out = 0;
|
|
|
|
*total_in = 0;
|
|
|
|
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 20:29:47 +08:00
|
|
|
in_page = find_get_page(mapping, start >> PAGE_SHIFT);
|
2010-10-25 15:12:26 +08:00
|
|
|
data_in = kmap(in_page);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* store the size of all chunks of compressed data in
|
|
|
|
* the first 4 bytes
|
|
|
|
*/
|
|
|
|
out_page = alloc_page(GFP_NOFS | __GFP_HIGHMEM);
|
|
|
|
if (out_page == NULL) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
cpage_out = kmap(out_page);
|
|
|
|
out_offset = LZO_LEN;
|
|
|
|
tot_out = LZO_LEN;
|
|
|
|
pages[0] = out_page;
|
|
|
|
nr_pages = 1;
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 20:29:47 +08:00
|
|
|
pg_bytes_left = PAGE_SIZE - LZO_LEN;
|
2010-10-25 15:12:26 +08:00
|
|
|
|
|
|
|
/* compress at most one page of data each time */
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 20:29:47 +08:00
|
|
|
in_len = min(len, PAGE_SIZE);
|
2010-10-25 15:12:26 +08:00
|
|
|
while (tot_in < len) {
|
|
|
|
ret = lzo1x_1_compress(data_in, in_len, workspace->cbuf,
|
|
|
|
&out_len, workspace->mem);
|
|
|
|
if (ret != LZO_E_OK) {
|
2017-05-26 02:12:19 +08:00
|
|
|
pr_debug("BTRFS: lzo in loop returned %d\n",
|
2010-10-25 15:12:26 +08:00
|
|
|
ret);
|
2014-05-10 05:15:08 +08:00
|
|
|
ret = -EIO;
|
2010-10-25 15:12:26 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* store the size of this chunk of compressed data */
|
|
|
|
write_compress_length(cpage_out + out_offset, out_len);
|
|
|
|
tot_out += LZO_LEN;
|
|
|
|
out_offset += LZO_LEN;
|
|
|
|
pg_bytes_left -= LZO_LEN;
|
|
|
|
|
|
|
|
tot_in += in_len;
|
|
|
|
tot_out += out_len;
|
|
|
|
|
|
|
|
/* copy bytes from the working buffer into the pages */
|
|
|
|
buf = workspace->cbuf;
|
|
|
|
while (out_len) {
|
|
|
|
bytes = min_t(unsigned long, pg_bytes_left, out_len);
|
|
|
|
|
|
|
|
memcpy(cpage_out + out_offset, buf, bytes);
|
|
|
|
|
|
|
|
out_len -= bytes;
|
|
|
|
pg_bytes_left -= bytes;
|
|
|
|
buf += bytes;
|
|
|
|
out_offset += bytes;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* we need another page for writing out.
|
|
|
|
*
|
|
|
|
* Note if there's less than 4 bytes left, we just
|
|
|
|
* skip to a new page.
|
|
|
|
*/
|
|
|
|
if ((out_len == 0 && pg_bytes_left < LZO_LEN) ||
|
|
|
|
pg_bytes_left == 0) {
|
|
|
|
if (pg_bytes_left) {
|
|
|
|
memset(cpage_out + out_offset, 0,
|
|
|
|
pg_bytes_left);
|
|
|
|
tot_out += pg_bytes_left;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we're done, don't allocate new page */
|
|
|
|
if (out_len == 0 && tot_in >= len)
|
|
|
|
break;
|
|
|
|
|
|
|
|
kunmap(out_page);
|
|
|
|
if (nr_pages == nr_dest_pages) {
|
|
|
|
out_page = NULL;
|
2014-05-10 05:15:08 +08:00
|
|
|
ret = -E2BIG;
|
2010-10-25 15:12:26 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
out_page = alloc_page(GFP_NOFS | __GFP_HIGHMEM);
|
|
|
|
if (out_page == NULL) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
cpage_out = kmap(out_page);
|
|
|
|
pages[nr_pages++] = out_page;
|
|
|
|
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 20:29:47 +08:00
|
|
|
pg_bytes_left = PAGE_SIZE;
|
2010-10-25 15:12:26 +08:00
|
|
|
out_offset = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we're making it bigger, give up */
|
2013-07-02 02:33:39 +08:00
|
|
|
if (tot_in > 8192 && tot_in < tot_out) {
|
2014-05-10 05:15:08 +08:00
|
|
|
ret = -E2BIG;
|
2010-10-25 15:12:26 +08:00
|
|
|
goto out;
|
2013-07-02 02:33:39 +08:00
|
|
|
}
|
2010-10-25 15:12:26 +08:00
|
|
|
|
|
|
|
/* we're all done */
|
|
|
|
if (tot_in >= len)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (tot_out > max_out)
|
|
|
|
break;
|
|
|
|
|
|
|
|
bytes_left = len - tot_in;
|
|
|
|
kunmap(in_page);
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 20:29:47 +08:00
|
|
|
put_page(in_page);
|
2010-10-25 15:12:26 +08:00
|
|
|
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 20:29:47 +08:00
|
|
|
start += PAGE_SIZE;
|
|
|
|
in_page = find_get_page(mapping, start >> PAGE_SHIFT);
|
2010-10-25 15:12:26 +08:00
|
|
|
data_in = kmap(in_page);
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 20:29:47 +08:00
|
|
|
in_len = min(bytes_left, PAGE_SIZE);
|
2010-10-25 15:12:26 +08:00
|
|
|
}
|
|
|
|
|
2017-05-30 07:18:04 +08:00
|
|
|
if (tot_out >= tot_in) {
|
|
|
|
ret = -E2BIG;
|
2010-10-25 15:12:26 +08:00
|
|
|
goto out;
|
2017-05-30 07:18:04 +08:00
|
|
|
}
|
2010-10-25 15:12:26 +08:00
|
|
|
|
|
|
|
/* store the size of all chunks of compressed data */
|
|
|
|
cpage_out = kmap(pages[0]);
|
|
|
|
write_compress_length(cpage_out, tot_out);
|
|
|
|
|
|
|
|
kunmap(pages[0]);
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
*total_out = tot_out;
|
|
|
|
*total_in = tot_in;
|
|
|
|
out:
|
|
|
|
*out_pages = nr_pages;
|
|
|
|
if (out_page)
|
|
|
|
kunmap(out_page);
|
|
|
|
|
|
|
|
if (in_page) {
|
|
|
|
kunmap(in_page);
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 20:29:47 +08:00
|
|
|
put_page(in_page);
|
2010-10-25 15:12:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-05-26 15:44:59 +08:00
|
|
|
static int lzo_decompress_bio(struct list_head *ws, struct compressed_bio *cb)
|
2010-10-25 15:12:26 +08:00
|
|
|
{
|
|
|
|
struct workspace *workspace = list_entry(ws, struct workspace, list);
|
2010-11-08 15:22:19 +08:00
|
|
|
int ret = 0, ret2;
|
2010-10-25 15:12:26 +08:00
|
|
|
char *data_in;
|
|
|
|
unsigned long page_in_index = 0;
|
2017-05-26 15:44:59 +08:00
|
|
|
size_t srclen = cb->compressed_len;
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 20:29:47 +08:00
|
|
|
unsigned long total_pages_in = DIV_ROUND_UP(srclen, PAGE_SIZE);
|
2010-10-25 15:12:26 +08:00
|
|
|
unsigned long buf_start;
|
|
|
|
unsigned long buf_offset = 0;
|
|
|
|
unsigned long bytes;
|
|
|
|
unsigned long working_bytes;
|
|
|
|
size_t in_len;
|
|
|
|
size_t out_len;
|
2018-05-15 14:57:51 +08:00
|
|
|
const size_t max_segment_len = lzo1x_worst_compress(PAGE_SIZE);
|
2010-10-25 15:12:26 +08:00
|
|
|
unsigned long in_offset;
|
|
|
|
unsigned long in_page_bytes_left;
|
|
|
|
unsigned long tot_in;
|
|
|
|
unsigned long tot_out;
|
|
|
|
unsigned long tot_len;
|
|
|
|
char *buf;
|
2011-02-16 14:06:41 +08:00
|
|
|
bool may_late_unmap, need_unmap;
|
2017-05-26 15:44:59 +08:00
|
|
|
struct page **pages_in = cb->compressed_pages;
|
|
|
|
u64 disk_start = cb->start;
|
|
|
|
struct bio *orig_bio = cb->orig_bio;
|
2010-10-25 15:12:26 +08:00
|
|
|
|
|
|
|
data_in = kmap(pages_in[0]);
|
|
|
|
tot_len = read_compress_length(data_in);
|
2018-05-15 14:57:51 +08:00
|
|
|
/*
|
|
|
|
* Compressed data header check.
|
|
|
|
*
|
|
|
|
* The real compressed size can't exceed the maximum extent length, and
|
|
|
|
* all pages should be used (whole unused page with just the segment
|
|
|
|
* header is not possible). If this happens it means the compressed
|
|
|
|
* extent is corrupted.
|
|
|
|
*/
|
|
|
|
if (tot_len > min_t(size_t, BTRFS_MAX_COMPRESSED, srclen) ||
|
|
|
|
tot_len < srclen - PAGE_SIZE) {
|
|
|
|
ret = -EUCLEAN;
|
|
|
|
goto done;
|
|
|
|
}
|
2010-10-25 15:12:26 +08:00
|
|
|
|
|
|
|
tot_in = LZO_LEN;
|
|
|
|
in_offset = LZO_LEN;
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 20:29:47 +08:00
|
|
|
in_page_bytes_left = PAGE_SIZE - LZO_LEN;
|
2010-10-25 15:12:26 +08:00
|
|
|
|
|
|
|
tot_out = 0;
|
|
|
|
|
|
|
|
while (tot_in < tot_len) {
|
|
|
|
in_len = read_compress_length(data_in + in_offset);
|
|
|
|
in_page_bytes_left -= LZO_LEN;
|
|
|
|
in_offset += LZO_LEN;
|
|
|
|
tot_in += LZO_LEN;
|
|
|
|
|
2018-05-15 14:57:51 +08:00
|
|
|
/*
|
|
|
|
* Segment header check.
|
|
|
|
*
|
|
|
|
* The segment length must not exceed the maximum LZO
|
|
|
|
* compression size, nor the total compressed size.
|
|
|
|
*/
|
|
|
|
if (in_len > max_segment_len || tot_in + in_len > tot_len) {
|
|
|
|
ret = -EUCLEAN;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2010-10-25 15:12:26 +08:00
|
|
|
tot_in += in_len;
|
|
|
|
working_bytes = in_len;
|
2011-02-16 14:06:41 +08:00
|
|
|
may_late_unmap = need_unmap = false;
|
2010-10-25 15:12:26 +08:00
|
|
|
|
|
|
|
/* fast path: avoid using the working buffer */
|
|
|
|
if (in_page_bytes_left >= in_len) {
|
|
|
|
buf = data_in + in_offset;
|
|
|
|
bytes = in_len;
|
2011-02-16 14:06:41 +08:00
|
|
|
may_late_unmap = true;
|
2010-10-25 15:12:26 +08:00
|
|
|
goto cont;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* copy bytes from the pages into the working buffer */
|
|
|
|
buf = workspace->cbuf;
|
|
|
|
buf_offset = 0;
|
|
|
|
while (working_bytes) {
|
|
|
|
bytes = min(working_bytes, in_page_bytes_left);
|
|
|
|
|
|
|
|
memcpy(buf + buf_offset, data_in + in_offset, bytes);
|
|
|
|
buf_offset += bytes;
|
|
|
|
cont:
|
|
|
|
working_bytes -= bytes;
|
|
|
|
in_page_bytes_left -= bytes;
|
|
|
|
in_offset += bytes;
|
|
|
|
|
|
|
|
/* check if we need to pick another page */
|
|
|
|
if ((working_bytes == 0 && in_page_bytes_left < LZO_LEN)
|
|
|
|
|| in_page_bytes_left == 0) {
|
|
|
|
tot_in += in_page_bytes_left;
|
|
|
|
|
|
|
|
if (working_bytes == 0 && tot_in >= tot_len)
|
|
|
|
break;
|
|
|
|
|
2011-02-16 14:06:41 +08:00
|
|
|
if (page_in_index + 1 >= total_pages_in) {
|
2014-05-10 05:15:08 +08:00
|
|
|
ret = -EIO;
|
2010-10-25 15:12:26 +08:00
|
|
|
goto done;
|
|
|
|
}
|
2011-02-16 14:06:41 +08:00
|
|
|
|
|
|
|
if (may_late_unmap)
|
|
|
|
need_unmap = true;
|
|
|
|
else
|
|
|
|
kunmap(pages_in[page_in_index]);
|
|
|
|
|
|
|
|
data_in = kmap(pages_in[++page_in_index]);
|
2010-10-25 15:12:26 +08:00
|
|
|
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 20:29:47 +08:00
|
|
|
in_page_bytes_left = PAGE_SIZE;
|
2010-10-25 15:12:26 +08:00
|
|
|
in_offset = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-15 14:57:51 +08:00
|
|
|
out_len = max_segment_len;
|
2010-10-25 15:12:26 +08:00
|
|
|
ret = lzo1x_decompress_safe(buf, in_len, workspace->buf,
|
|
|
|
&out_len);
|
2011-02-16 14:06:41 +08:00
|
|
|
if (need_unmap)
|
|
|
|
kunmap(pages_in[page_in_index - 1]);
|
2010-10-25 15:12:26 +08:00
|
|
|
if (ret != LZO_E_OK) {
|
2016-09-20 22:05:01 +08:00
|
|
|
pr_warn("BTRFS: decompress failed\n");
|
2014-05-10 05:15:08 +08:00
|
|
|
ret = -EIO;
|
2010-10-25 15:12:26 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
buf_start = tot_out;
|
|
|
|
tot_out += out_len;
|
|
|
|
|
2010-11-08 15:22:19 +08:00
|
|
|
ret2 = btrfs_decompress_buf2page(workspace->buf, buf_start,
|
2016-11-25 16:07:46 +08:00
|
|
|
tot_out, disk_start, orig_bio);
|
2010-11-08 15:22:19 +08:00
|
|
|
if (ret2 == 0)
|
2010-10-25 15:12:26 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
done:
|
2011-02-16 14:06:41 +08:00
|
|
|
kunmap(pages_in[page_in_index]);
|
2014-11-30 21:56:33 +08:00
|
|
|
if (!ret)
|
2016-11-25 16:07:46 +08:00
|
|
|
zero_fill_bio(orig_bio);
|
2010-10-25 15:12:26 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int lzo_decompress(struct list_head *ws, unsigned char *data_in,
|
|
|
|
struct page *dest_page,
|
|
|
|
unsigned long start_byte,
|
|
|
|
size_t srclen, size_t destlen)
|
|
|
|
{
|
|
|
|
struct workspace *workspace = list_entry(ws, struct workspace, list);
|
|
|
|
size_t in_len;
|
|
|
|
size_t out_len;
|
2018-05-17 14:10:29 +08:00
|
|
|
size_t max_segment_len = lzo1x_worst_compress(PAGE_SIZE);
|
2010-10-25 15:12:26 +08:00
|
|
|
int ret = 0;
|
|
|
|
char *kaddr;
|
|
|
|
unsigned long bytes;
|
|
|
|
|
2018-05-17 14:10:29 +08:00
|
|
|
if (srclen < LZO_LEN || srclen > max_segment_len + LZO_LEN * 2)
|
|
|
|
return -EUCLEAN;
|
2010-10-25 15:12:26 +08:00
|
|
|
|
2018-05-17 14:10:29 +08:00
|
|
|
in_len = read_compress_length(data_in);
|
|
|
|
if (in_len != srclen)
|
|
|
|
return -EUCLEAN;
|
2010-10-25 15:12:26 +08:00
|
|
|
data_in += LZO_LEN;
|
|
|
|
|
|
|
|
in_len = read_compress_length(data_in);
|
2018-05-17 14:10:29 +08:00
|
|
|
if (in_len != srclen - LZO_LEN * 2) {
|
|
|
|
ret = -EUCLEAN;
|
|
|
|
goto out;
|
|
|
|
}
|
2010-10-25 15:12:26 +08:00
|
|
|
data_in += LZO_LEN;
|
|
|
|
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 20:29:47 +08:00
|
|
|
out_len = PAGE_SIZE;
|
2010-10-25 15:12:26 +08:00
|
|
|
ret = lzo1x_decompress_safe(data_in, in_len, workspace->buf, &out_len);
|
|
|
|
if (ret != LZO_E_OK) {
|
2016-09-20 22:05:01 +08:00
|
|
|
pr_warn("BTRFS: decompress failed!\n");
|
2014-05-10 05:15:08 +08:00
|
|
|
ret = -EIO;
|
2010-10-25 15:12:26 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (out_len < start_byte) {
|
2014-05-10 05:15:08 +08:00
|
|
|
ret = -EIO;
|
2010-10-25 15:12:26 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2014-11-30 21:56:33 +08:00
|
|
|
/*
|
|
|
|
* the caller is already checking against PAGE_SIZE, but lets
|
|
|
|
* move this check closer to the memcpy/memset
|
|
|
|
*/
|
|
|
|
destlen = min_t(unsigned long, destlen, PAGE_SIZE);
|
2010-10-25 15:12:26 +08:00
|
|
|
bytes = min_t(unsigned long, destlen, out_len - start_byte);
|
|
|
|
|
2011-11-25 23:14:28 +08:00
|
|
|
kaddr = kmap_atomic(dest_page);
|
2010-10-25 15:12:26 +08:00
|
|
|
memcpy(kaddr, workspace->buf + start_byte, bytes);
|
2014-11-30 21:56:33 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* btrfs_getblock is doing a zero on the tail of the page too,
|
|
|
|
* but this will cover anything missing from the decompressed
|
|
|
|
* data.
|
|
|
|
*/
|
|
|
|
if (bytes < destlen)
|
|
|
|
memset(kaddr+bytes, 0, destlen-bytes);
|
2011-11-25 23:14:28 +08:00
|
|
|
kunmap_atomic(kaddr);
|
2010-10-25 15:12:26 +08:00
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-09-15 23:36:57 +08:00
|
|
|
static void lzo_set_level(struct list_head *ws, unsigned int type)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-01-03 01:23:10 +08:00
|
|
|
const struct btrfs_compress_op btrfs_lzo_compress = {
|
2010-10-25 15:12:26 +08:00
|
|
|
.alloc_workspace = lzo_alloc_workspace,
|
|
|
|
.free_workspace = lzo_free_workspace,
|
|
|
|
.compress_pages = lzo_compress_pages,
|
2016-11-25 16:07:46 +08:00
|
|
|
.decompress_bio = lzo_decompress_bio,
|
2010-10-25 15:12:26 +08:00
|
|
|
.decompress = lzo_decompress,
|
2017-09-15 23:36:57 +08:00
|
|
|
.set_level = lzo_set_level,
|
2010-10-25 15:12:26 +08:00
|
|
|
};
|