From patchwork Sat May 20 16:49:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timofey Titovets X-Patchwork-Id: 9738683 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 183CA6041F for ; Sat, 20 May 2017 16:50:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0A04C285C5 for ; Sat, 20 May 2017 16:50:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F34D628685; Sat, 20 May 2017 16:50:19 +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=-4.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_HI,RCVD_IN_SORBS_SPAM, RCVD_IN_SORBS_WEB,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 9504228644 for ; Sat, 20 May 2017 16:50:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756345AbdETQuN (ORCPT ); Sat, 20 May 2017 12:50:13 -0400 Received: from mail-lf0-f66.google.com ([209.85.215.66]:34032 "EHLO mail-lf0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756326AbdETQuL (ORCPT ); Sat, 20 May 2017 12:50:11 -0400 Received: by mail-lf0-f66.google.com with SMTP id q24so2172252lfb.1 for ; Sat, 20 May 2017 09:50:10 -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=urhPGGkgXeQrsqxT85xgnJu4oLPUIXQvGCgB5oJV4cc=; b=ljx2FFYkHRbyeUnyG4Z5gznQnHxCktFbC6RXzkgmkVCT3/yQJ0321qwYmlEKeBJ4KQ tZGzEMlr5UsUkskITs2Ez2WfhHGXDGeg6F1cdKz94ZO0lGmiNmp2gvdfTQxyY/jZJMIl Or6HtZk/QROsElrjhLK9MgpO3DZyDsaAZ9svgvy8hQ9SrVHPE5DG4w3vs2jscwbkAdQ5 LB/5iiVmz7uYpodHRgm4eWu2J8qbZaEWhGRO0znBJ8RXM5TD3lrskhgZXYuBLWHFupS3 S+rFBWJsrMuY9JQ2tgjYJewKXoYJivn2vf/hZ4qJ0uEiSUXX0h5qIbEB7TWHteAdK3zH 7v+A== 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=urhPGGkgXeQrsqxT85xgnJu4oLPUIXQvGCgB5oJV4cc=; b=a3YBRvSbkDz3SlWEjZyQmLtr/D6o6sv7o81VZiWmAKarOn7muaPi8cFHKst5C+rIF/ rie+nKbkkWvp4euBr5f2rwcxhd3qtSk9nMBy9nMP+tOyTTwPbGQQyaoswP5d+HQ01b+x GmIR/hS2evAkeJKD/Y/CZBCDcfw460fK6M8VVo2q8Gyz8N78qhZm7eZpaL/Zi5SF+z2O L8kZLOYCOQbC00zc/IKIcZQketLk+BPACu/UEAKq+A+fKbW4hjLMBPnBrdDG05+oVJrR 584D/7BGTr5jC+APj/VI6+h2CXlwr3yzN/ZWKz9/5oZ+182ayYCRt7owLbUgVeRCQwZ2 89mQ== X-Gm-Message-State: AODbwcAaX6X69ZrXcps12awcoUsdAytKLgY7ysuuqKLXMtdB6JXC4fcO hVsU41G0wZc7bQ== X-Received: by 10.25.210.6 with SMTP id j6mr3987576lfg.21.1495299009932; Sat, 20 May 2017 09:50:09 -0700 (PDT) Received: from localhost.localdomain ([93.84.29.37]) by smtp.gmail.com with ESMTPSA id d78sm1580118lfd.21.2017.05.20.09.50.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 20 May 2017 09:50:09 -0700 (PDT) From: Timofey Titovets To: linux-btrfs@vger.kernel.org Cc: Timofey Titovets Subject: [PATCH v2 2/2] Btrfs: compression must free at least PAGE_SIZE Date: Sat, 20 May 2017 19:49:53 +0300 Message-Id: <20170520164953.7344-3-nefelim4ag@gmail.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170520164953.7344-1-nefelim4ag@gmail.com> References: <20170520164953.7344-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. So make logic better and make check that compression free at least one PAGE_SIZE, because in another case it useless to store this data compressed Signed-off-by: Timofey Titovets --- fs/btrfs/lzo.c | 5 ++++- fs/btrfs/zlib.c | 3 ++- 2 files changed, 6 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..7f38bc3c 100644 --- a/fs/btrfs/lzo.c +++ b/fs/btrfs/lzo.c @@ -229,8 +229,11 @@ 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 PAGE_SIZE */ + if (tot_out + PAGE_SIZE => 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..2b04259b 100644 --- a/fs/btrfs/zlib.c +++ b/fs/btrfs/zlib.c @@ -191,7 +191,8 @@ 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 PAGE_SIZE */ + if (workspace->strm.total_out + PAGE_SIZE >= workspace->strm.total_in) { ret = -E2BIG; goto out; }