From: Timofey Titovets <nefelim4ag@gmail.com>
To: linux-btrfs@vger.kernel.org
Cc: Timofey Titovets <nefelim4ag@gmail.com>
Subject: [PATCH v4 2/2] Btrfs: compression must free at least one sector size
Date: Thu, 25 May 2017 21:12:20 +0300 [thread overview]
Message-ID: <20170525181220.24692-3-nefelim4ag@gmail.com> (raw)
In-Reply-To: <20170525181220.24692-1-nefelim4ag@gmail.com>
Btrfs already skip store of data where compression didn't
free at least one byte. Let's make logic better and make check
that compression free at least one sector size
because in another case it useless to store this data compressed
Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
---
fs/btrfs/lzo.c | 9 ++++++++-
fs/btrfs/zlib.c | 7 ++++++-
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/fs/btrfs/lzo.c b/fs/btrfs/lzo.c
index bd0b0938..4aafae6f 100644
--- a/fs/btrfs/lzo.c
+++ b/fs/btrfs/lzo.c
@@ -26,6 +26,7 @@
#include <linux/bio.h>
#include <linux/lzo.h>
#include "compression.h"
+#include "ctree.h"
#define LZO_LEN 4
@@ -99,6 +100,7 @@ static int lzo_compress_pages(struct list_head *ws,
int nr_pages = 0;
struct page *in_page = NULL;
struct page *out_page = NULL;
+ u32 sectorsize;
unsigned long bytes_left;
unsigned long len = *total_out;
unsigned long nr_dest_pages = *out_pages;
@@ -229,8 +231,13 @@ static int lzo_compress_pages(struct list_head *ws,
in_len = min(bytes_left, PAGE_SIZE);
}
- if (tot_out > tot_in)
+ /* Compression must save at least one sectorsize */
+ sectorsize = btrfs_inode_sectorsize(mapping->host);
+
+ if (tot_out + sectorsize > tot_in) {
+ ret = -E2BIG;
goto out;
+ }
/* store the size of all chunks of compressed data */
cpage_out = kmap(pages[0]);
diff --git a/fs/btrfs/zlib.c b/fs/btrfs/zlib.c
index 135b1082..f9957248 100644
--- a/fs/btrfs/zlib.c
+++ b/fs/btrfs/zlib.c
@@ -31,6 +31,7 @@
#include <linux/pagemap.h>
#include <linux/bio.h>
#include "compression.h"
+#include "ctree.h"
struct workspace {
z_stream strm;
@@ -86,6 +87,7 @@ static int zlib_compress_pages(struct list_head *ws,
int nr_pages = 0;
struct page *in_page = NULL;
struct page *out_page = NULL;
+ u32 sectorsize;
unsigned long bytes_left;
unsigned long len = *total_out;
unsigned long nr_dest_pages = *out_pages;
@@ -191,7 +193,10 @@ static int zlib_compress_pages(struct list_head *ws,
goto out;
}
- if (workspace->strm.total_out >= workspace->strm.total_in) {
+ /* Compression must save at least one sectorsize */
+ sectorsize = btrfs_inode_sectorsize(mapping->host);
+
+ if (workspace->strm.total_out + sectorsize > workspace->strm.total_in) {
ret = -E2BIG;
goto out;
}
--
2.13.0
next prev parent reply other threads:[~2017-05-25 18:12 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-25 18:12 [PATCH v4 0/2] Btrfs: compression fixes Timofey Titovets
2017-05-25 18:12 ` [PATCH v4 1/2] Btrfs: lzo.c pr_debug() deflate->lzo Timofey Titovets
2017-05-29 14:24 ` David Sterba
2017-05-25 18:12 ` Timofey Titovets [this message]
2017-05-29 14:23 ` [PATCH v4 2/2] Btrfs: compression must free at least one sector size David Sterba
2017-05-29 18:16 ` Timofey Titovets
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170525181220.24692-3-nefelim4ag@gmail.com \
--to=nefelim4ag@gmail.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).