Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp313227ybi; Wed, 29 May 2019 22:04:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqyj8p/khHEW4xruhRCZGi05Gpb895te/UOkEkhhQvJ6red4GjE+F0nJ/pAXZSk9Qf+XvKD5 X-Received: by 2002:a17:90a:6348:: with SMTP id v8mr1983883pjs.34.1559192645582; Wed, 29 May 2019 22:04:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559192645; cv=none; d=google.com; s=arc-20160816; b=MdYg/S6xpJNM9k4x5VPl/BFkUabnrw9KFrdeq0b6Od6uetcW94F6lQRAJkpU5OWiT2 UkK2z2B6yF4PXzJxHm7GW/er7IzeMXkg8QAOnEh+EcyyWQ0bnPWR6EIdoQjQjaUrqr4c MPpNdWv/fJTiZL+YmMT8jpv9/+Cw7+v42LQMFbFJsiqapgbcUPJhs8DQx8X3Zq54QGu5 7UBrCLPytNfy07lpuiMsgFv5qNHW2kC+WyMNY5i9PhkOT9aonVtI+YRzOIp4+iHJjK/Z +e/M04GVcP3hHxY9jWlulXIC4UKG9jjXf3mYv3iXeHT/Wy3scGFer0pBuM/8NJc+ZGXr 8n6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=o/GRoOgUek4BOg/bl82uZylf1c0f5L/Mb8TPbB1ZvWk=; b=cXorqARf8tMm+rQ47FGYmCbcL+V4dy7hFLBl449uOP/X73YlZzGb3qGy1O9Ts/xd8C 1KHBumnslQIl573ODrPtlS/QdI10P+CkWnzrZw0uypIj70vlSOcMBCvh3LGYBCdN7hvx FArajIyRj5tIne07cu4ctRe7TZKLh+j/iUtUdVleT07TtVG+Fzb6sv8a1SRHE5NdYEKH WoNWC0K/i1uf6AJtI++zlafj1Zvw14NbhWuVeETcYivlAU2FQTBElfHOo/5vE+hYgC8u 66EgMjvDXecZKvJxsrkJC2B8WOCWKM2jzDE4c4RVhDK/4E1sv8dluvcorU0094nIogoY dSHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xFFzJIJZ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f61si1931647pje.44.2019.05.29.22.03.48; Wed, 29 May 2019 22:04:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xFFzJIJZ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389218AbfE3FAY (ORCPT + 99 others); Thu, 30 May 2019 01:00:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:44432 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727615AbfE3DJc (ORCPT ); Wed, 29 May 2019 23:09:32 -0400 Received: from localhost (ip67-88-213-2.z213-88-67.customer.algx.net [67.88.213.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 19FA824481; Thu, 30 May 2019 03:09:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559185772; bh=aNQ7m6pVjPpcwkmbpDyRhE8MoPoAKBxGV94to5iTdfE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xFFzJIJZkRiUwwn0ctTXA0Hmp+ryb6WPHmtqwtO0tjfiP4txTFOBlKxgu8uuF3O/p /GpgZzg8J9y8HwvYQqnuuDJ+9VvboJLsfInKi4AWW4++etG+w0fbzpo77Isev/xYUq KI5GbbY+aAwUUoLVm+1apAnuEXqVaMp4oXMHQve8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Johnny Chang , David Sterba Subject: [PATCH 5.1 024/405] btrfs: Check the compression level before getting a workspace Date: Wed, 29 May 2019 20:00:22 -0700 Message-Id: <20190530030541.864967520@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190530030540.291644921@linuxfoundation.org> References: <20190530030540.291644921@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Johnny Chang commit 2b90883c561ddcc641741c2e4df1f702a4f2acb8 upstream. When a file's compression property is set as zlib or zstd but leave the compression mount option not be set, that means btrfs will try to compress the file with default compression level. But in btrfs_compress_pages(), it calls get_workspace() with level = 0. This will return a workspace with a wrong compression level. For zlib, the compression level in the workspace will be 0 (that means "store only"). And for zstd, the compression in the workspace will be 1, not the default level 3. How to reproduce: mkfs -t btrfs /dev/sdb mount /dev/sdb /mnt/ mkdir /mnt/zlib btrfs property set /mnt/zlib/ compression zlib dd if=/dev/zero of=/mnt/zlib/compression-friendly-file-10M bs=1M count=10 sync btrfs-debugfs -f /mnt/zlib/compression-friendly-file-10M btrfs-debugfs output: * before: ... (258 9961472): ram 524288 disk 1106247680 disk_size 524288 file: ... extents 20 disk size 10485760 logical size 10485760 ratio 1.00 * after: ... (258 10354688): ram 131072 disk 14217216 disk_size 4096 file: ... extents 80 disk size 327680 logical size 10485760 ratio 32.00 The steps for zstd are similar, but need to put a debugging message to show the level of the return workspace in zstd_get_workspace(). This commit adds a check of the compression level before getting a workspace by set_level(). CC: stable@vger.kernel.org # 5.1+ Signed-off-by: Johnny Chang Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/compression.c | 1 + 1 file changed, 1 insertion(+) --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c @@ -1009,6 +1009,7 @@ int btrfs_compress_pages(unsigned int ty struct list_head *workspace; int ret; + level = btrfs_compress_op[type]->set_level(level); workspace = get_workspace(type, level); ret = btrfs_compress_op[type]->compress_pages(workspace, mapping, start, pages,