From patchwork Sat May 20 18:40:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timofey Titovets X-Patchwork-Id: 9738737 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 B923E601C2 for ; Sat, 20 May 2017 18:41:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AB69728514 for ; Sat, 20 May 2017 18:41:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A019E28552; Sat, 20 May 2017 18:41:01 +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 5651E28514 for ; Sat, 20 May 2017 18:41:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753531AbdETSk7 (ORCPT ); Sat, 20 May 2017 14:40:59 -0400 Received: from mail-lf0-f68.google.com ([209.85.215.68]:36341 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750940AbdETSkz (ORCPT ); Sat, 20 May 2017 14:40:55 -0400 Received: by mail-lf0-f68.google.com with SMTP id h4so2283293lfj.3 for ; Sat, 20 May 2017 11:40:54 -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=iM0mRELA4/F4ujvGF68UDCU1wPhjX94WFQ0nZk2HQdc=; b=h9c2TXho4hwSjRcIgxET6oxxCvylZRsfipRbRyWhfSQodyC/ndZw8/5w2lki5YgS3s DkOwkJaT2KESLx8922n9ZpIlumggXceyBkxMvBKSr9FkkgyYqVhFjGEGDtYfZec/yFtO 1+X23F6OK0Sh8l7oOxlgpqBdHqi0DakL5I7EAS6PXpYFV5UYMhgfm1MEhY0bqQ1CpHt6 x3Y7K7VW1oZcGGhDR4AvfGBeuMABOBsUXTpNFzjL09qIaRA2MiVaxdxN9QpFi2dVMe4m kwpu+4RnDFmZyCZUEEk+9/fF8jyHQxTw3CcDm09AqVKQtpxg/WRZ4DqOt0o5xJ+h18bn 68qQ== 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=iM0mRELA4/F4ujvGF68UDCU1wPhjX94WFQ0nZk2HQdc=; b=r/BlbKJxFvCMkmIezZV5cDA/5IMxKNb0j8c6jxhEv/csdWSZLGTSaia3jtI0YD4IZy u6HSqw/EAG9jUeJ8uDfplDmOojjbgzVgOY7tO4rePYbGRsBYqByoCpTWznnwgBm+OKEO F+cBRrA+zcVvMX35wjd1n/tJunWZyt9u7+MC+L8xMr3uzVcje35o38vzJ/DT5Gk/aPvj YxjVsfqebxeJdFuR75GjAAE4aDGlDKGm+k4IZw9/OZZsZ3v1VdfwZn4s0luoOKq5611r A1HFNFFGm2lhLVMw8vLirxE6W3PAKJlvDnMkzZRDvKYm6debU7AQ8seybYiSICU2cWiQ TeGQ== X-Gm-Message-State: AODbwcCm+J8hpuUPqmDV7qhuWvRem1+23SVL3bYRbwxuXmKOTtPnpdRp ogzhXz4gndqdMw== X-Received: by 10.46.83.12 with SMTP id h12mr3997086ljb.28.1495305653504; Sat, 20 May 2017 11:40:53 -0700 (PDT) Received: from localhost.localdomain ([93.84.29.37]) by smtp.gmail.com with ESMTPSA id w69sm1598646lff.45.2017.05.20.11.40.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 20 May 2017 11:40:53 -0700 (PDT) From: Timofey Titovets To: linux-btrfs@vger.kernel.org Cc: Timofey Titovets Subject: [PATCH v3 2/2] Btrfs: compression must free at least PAGE_SIZE Date: Sat, 20 May 2017 21:40:39 +0300 Message-Id: <20170520184039.31362-3-nefelim4ag@gmail.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170520184039.31362-1-nefelim4ag@gmail.com> References: <20170520184039.31362-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..39678499 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..11e117b5 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; }