Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2475855yba; Mon, 15 Apr 2019 12:26:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqx3xJNSxmhMHDiznJ3pL42U/qA+z9fjODa6WDk+/tcDLyoHR0CfV6QLdrCPiLl5bqNTd3Fq X-Received: by 2002:a17:902:e704:: with SMTP id co4mr36736989plb.30.1555356361012; Mon, 15 Apr 2019 12:26:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555356361; cv=none; d=google.com; s=arc-20160816; b=vl0kk9kVI5sKZ1hq7q//RMGJafrWol4Hwpf8dM3E55AgaZoTVyp1Xs33Z++Ibd09UE 5toCz6Paemz46ZcN0Zgc3caY+GnWni7N0uzWf0qS7rAuY6JHkGM3agzrdnq97WUzxJ4M ygCwKrmC3GQuSxhEuXOU/XJwxzra+FBlicbmMeZz2FOdugoX1MDu72+tUabP2TiK0rhM 0YpLhQP5JStErQSOH8JaKpvaTdjcy+cfjak7yYKLaBvgVQq6vibubtV/9wP3KbprrZaR m2WqLwnKaCYRGrAdasuQlioGttd+plTR/GC7S9g+wCQrEPkiL/JzCN87xmYpSEteRGFn aqIA== 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=aDBIvZ7IrqLDLqj1Gnk4pxcnnUMxjFY2cqUo/RzJ1z0=; b=uFYsrrIbZYUZsCdlKWCDcbn2wY+IraPTsE1o6pyOc5xTLALb0McpGt+UvIrNDkSgOA 8diZQDP2Qw3UPM9djN9aKL6Ymob6vXT0uWTyhpfdWyVaH9bSDCgA9gCcDhRwSdLsYTLq uTHEwDJoy+1ET2i0MPmVoFeMZTSByYvm0BtJoEsrJE72w+JgBipCPfjr/8rm8mLQVAN1 pXQWHlybRqZMCBkd8XPOVUxnMiFm5rhdXHZRd4cvUQf8Sfh9MSDanKX0ZgU2lrIldOdQ MnvdYMoEevH+N7y6tx8ldYeiFnJdXxeq1qjlz/z9t2P/o6eJleBtzuYk0b/KACIwOTXt UuDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=e3pwWAi4; 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 p1si41455911pls.64.2019.04.15.12.25.44; Mon, 15 Apr 2019 12:26:01 -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=e3pwWAi4; 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 S1730206AbfDOTHd (ORCPT + 99 others); Mon, 15 Apr 2019 15:07:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:42484 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730167AbfDOTHb (ORCPT ); Mon, 15 Apr 2019 15:07:31 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 2C2A3218A1; Mon, 15 Apr 2019 19:07:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555355250; bh=1qqleM0sgLl1R2lsuaYhMXyOLc0DiMeT6KBQK0do0ZU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e3pwWAi4IFifWg3RQMEnnQ8nQNDFcUgI1gT85iLmFA+n/eMFwNeuqWNcJklQNxG/i uVAwDFJE7qB1Q7RCn9Wmu0txJMxCqey7TspBGKia35Ytu5Na005CZrDTs68hzR3a0I 9Me8eP8I53H8V893uD2pqy8TCFl+YYwSyZVgWgX0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Darrick J. Wong" , Nikolay Borisov , Filipe Manana , David Sterba Subject: [PATCH 4.19 067/101] Btrfs: do not allow trimming when a fs is mounted with the nologreplay option Date: Mon, 15 Apr 2019 20:59:05 +0200 Message-Id: <20190415183744.027246561@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190415183740.341577907@linuxfoundation.org> References: <20190415183740.341577907@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: Filipe Manana commit f35f06c35560a86e841631f0243b83a984dc11a9 upstream. Whan a filesystem is mounted with the nologreplay mount option, which requires it to be mounted in RO mode as well, we can not allow discard on free space inside block groups, because log trees refer to extents that are not pinned in a block group's free space cache (pinning the extents is precisely the first phase of replaying a log tree). So do not allow the fitrim ioctl to do anything when the filesystem is mounted with the nologreplay option, because later it can be mounted RW without that option, which causes log replay to happen and result in either a failure to replay the log trees (leading to a mount failure), a crash or some silent corruption. Reported-by: Darrick J. Wong Fixes: 96da09192cda ("btrfs: Introduce new mount option to disable tree log replay") CC: stable@vger.kernel.org # 4.9+ Reviewed-by: Nikolay Borisov Signed-off-by: Filipe Manana Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/ioctl.c | 10 ++++++++++ 1 file changed, 10 insertions(+) --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -496,6 +496,16 @@ static noinline int btrfs_ioctl_fitrim(s if (!capable(CAP_SYS_ADMIN)) return -EPERM; + /* + * If the fs is mounted with nologreplay, which requires it to be + * mounted in RO mode as well, we can not allow discard on free space + * inside block groups, because log trees refer to extents that are not + * pinned in a block group's free space cache (pinning the extents is + * precisely the first phase of replaying a log tree). + */ + if (btrfs_test_opt(fs_info, NOLOGREPLAY)) + return -EROFS; + rcu_read_lock(); list_for_each_entry_rcu(device, &fs_info->fs_devices->devices, dev_list) {