From patchwork Thu May 25 18:12:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timofey Titovets X-Patchwork-Id: 9748877 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4EA9060390 for ; Thu, 25 May 2017 18:12:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 45D5B27E5A for ; Thu, 25 May 2017 18:12:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 38420281B7; Thu, 25 May 2017 18:12:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D1570280CF for ; Thu, 25 May 2017 18:12:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1762548AbdEYSMs (ORCPT ); Thu, 25 May 2017 14:12:48 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:36389 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1761841AbdEYSMo (ORCPT ); Thu, 25 May 2017 14:12:44 -0400 Received: by mail-wm0-f68.google.com with SMTP id k15so53738913wmh.3 for ; Thu, 25 May 2017 11:12:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=LX5OrWO+ncakiru2bnWYNbowK0ViSsQtFq9722UrUIU=; b=FXwBQ+Rv2PyY3ocIdxEFOf5i5AI6CXFl5kZSy20l+XgdXHvaJ3GMq07gSri03jTnSv uOiM4lWyyOwSWNWwLN4xSO6G1gbWqiL+WxJZuSY6ilXAKbX++jphSgJYPRmLt/faeeFP yraWqevMNSht8H+jcpHwL20KxvjRrSH+5lP4r9ScP/7coatWhspxKqvahk/V95sI3qA9 fyexPCojce5IoqHOd+ptEN96Gnn1cO8Rgq+dg0FbvutD5CjzSqmDkUBeUeCZl7dveRf6 OFzSV87v8ipiRzMlfuvxHNyqt4y1KEFy1eZT5PATfPgi5AKPokrPFeQItoagGPeHupPX 9ipw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=LX5OrWO+ncakiru2bnWYNbowK0ViSsQtFq9722UrUIU=; b=um24Q8Hjd61vfjPEp6lRl/OuM8NAfX2G9a5cfyOFwfBiWURqZbe5l3AGzc1KUJneYX p5KJ77I0r6HTyhTBvIlEk9f4tVHUGx47NJjH2TRTnBiCGV1phGBXKdhuZGs5I/yMwPZY qXz7BXfnCuKsg2kwsIJKcR5Zi7qK/t5KgCALkpNuIn6aZRlvChYruQD5KDw0bQYmkpBn O6wRNBx1RDK/0wIvg0m+r6MpomBuCswdKI8NJUgRe+Zro8ujJQWFiW0Np/a2pT0d5l6+ 1ojxcJMvYgHv0xPgv20IxTaNQ1IVBEz4K25JmzPEiLwtjH0M4iqC6cUlLAB9lK3mrYYF ZnLA== X-Gm-Message-State: AODbwcAcRppkmgWFHsWryWGN3o5Y9wuh2hpupW6BRDPXi4Ff1yF/R1lI IyPccaE/ESKLUg== X-Received: by 10.223.132.163 with SMTP id 32mr25177838wrg.154.1495735963332; Thu, 25 May 2017 11:12:43 -0700 (PDT) Received: from localhost.localdomain ([91.215.176.151]) by smtp.gmail.com with ESMTPSA id 201sm733298wmh.22.2017.05.25.11.12.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 May 2017 11:12:42 -0700 (PDT) From: Timofey Titovets To: linux-btrfs@vger.kernel.org Cc: Timofey Titovets Subject: [PATCH v4 2/2] Btrfs: compression must free at least one sector size Date: Thu, 25 May 2017 21:12:20 +0300 Message-Id: <20170525181220.24692-3-nefelim4ag@gmail.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170525181220.24692-1-nefelim4ag@gmail.com> References: <20170525181220.24692-1-nefelim4ag@gmail.com> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- fs/btrfs/lzo.c | 9 ++++++++- fs/btrfs/zlib.c | 7 ++++++- 2 files changed, 14 insertions(+), 2 deletions(-) -- 2.13.0 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html 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 #include #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 #include #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; }