From: Darrick J. Wong Date: Sat, 23 Mar 2019 01:10:22 +0000 (-0700) Subject: xfs: prohibit fstrim in norecovery mode X-Git-Tag: Ubuntu-5.10.0-12.13~5706^2~1 X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=ed79dac98c5e9f8471456afe2cc09a3912586b52;p=mirror_ubuntu-hirsute-kernel.git xfs: prohibit fstrim in norecovery mode The xfs fstrim implementation uses the free space btrees to find free space that can be discarded. If we haven't recovered the log, the bnobt will be stale and we absolutely *cannot* use stale metadata to zap the underlying storage. Signed-off-by: Darrick J. Wong Reviewed-by: Eric Sandeen --- diff --git a/fs/xfs/xfs_discard.c b/fs/xfs/xfs_discard.c index 93f07edafd81..9ee2a7d02e70 100644 --- a/fs/xfs/xfs_discard.c +++ b/fs/xfs/xfs_discard.c @@ -161,6 +161,14 @@ xfs_ioc_trim( return -EPERM; if (!blk_queue_discard(q)) return -EOPNOTSUPP; + + /* + * We haven't recovered the log, so we cannot use our bnobt-guided + * storage zapping commands. + */ + if (mp->m_flags & XFS_MOUNT_NORECOVERY) + return -EROFS; + if (copy_from_user(&range, urange, sizeof(range))) return -EFAULT;