hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/fs/xfs/xfs_discard.c
....@@ -4,19 +4,18 @@
44 * All Rights Reserved.
55 */
66 #include "xfs.h"
7
+#include "xfs_shared.h"
78 #include "xfs_format.h"
89 #include "xfs_log_format.h"
910 #include "xfs_trans_resv.h"
1011 #include "xfs_sb.h"
1112 #include "xfs_mount.h"
12
-#include "xfs_quota.h"
13
-#include "xfs_inode.h"
1413 #include "xfs_btree.h"
1514 #include "xfs_alloc_btree.h"
1615 #include "xfs_alloc.h"
16
+#include "xfs_discard.h"
1717 #include "xfs_error.h"
1818 #include "xfs_extent_busy.h"
19
-#include "xfs_discard.h"
2019 #include "xfs_trace.h"
2120 #include "xfs_log.h"
2221
....@@ -32,6 +31,7 @@
3231 struct block_device *bdev = mp->m_ddev_targp->bt_bdev;
3332 struct xfs_btree_cur *cur;
3433 struct xfs_buf *agbp;
34
+ struct xfs_agf *agf;
3535 struct xfs_perag *pag;
3636 int error;
3737 int i;
....@@ -46,16 +46,16 @@
4646 xfs_log_force(mp, XFS_LOG_SYNC);
4747
4848 error = xfs_alloc_read_agf(mp, NULL, agno, 0, &agbp);
49
- if (error || !agbp)
49
+ if (error)
5050 goto out_put_perag;
51
+ agf = agbp->b_addr;
5152
5253 cur = xfs_allocbt_init_cursor(mp, NULL, agbp, agno, XFS_BTNUM_CNT);
5354
5455 /*
5556 * Look up the longest btree in the AGF and start with it.
5657 */
57
- error = xfs_alloc_lookup_ge(cur, 0,
58
- be32_to_cpu(XFS_BUF_TO_AGF(agbp)->agf_longest), &i);
58
+ error = xfs_alloc_lookup_ge(cur, 0, be32_to_cpu(agf->agf_longest), &i);
5959 if (error)
6060 goto out_del_cursor;
6161
....@@ -72,8 +72,11 @@
7272 error = xfs_alloc_get_rec(cur, &fbno, &flen, &i);
7373 if (error)
7474 goto out_del_cursor;
75
- XFS_WANT_CORRUPTED_GOTO(mp, i == 1, out_del_cursor);
76
- ASSERT(flen <= be32_to_cpu(XFS_BUF_TO_AGF(agbp)->agf_longest));
75
+ if (XFS_IS_CORRUPT(mp, i != 1)) {
76
+ error = -EFSCORRUPTED;
77
+ goto out_del_cursor;
78
+ }
79
+ ASSERT(flen <= be32_to_cpu(agf->agf_longest));
7780
7881 /*
7982 * use daddr format for all range/len calculations as that is
....@@ -161,9 +164,19 @@
161164 return -EPERM;
162165 if (!blk_queue_discard(q))
163166 return -EOPNOTSUPP;
167
+
168
+ /*
169
+ * We haven't recovered the log, so we cannot use our bnobt-guided
170
+ * storage zapping commands.
171
+ */
172
+ if (mp->m_flags & XFS_MOUNT_NORECOVERY)
173
+ return -EROFS;
174
+
164175 if (copy_from_user(&range, urange, sizeof(range)))
165176 return -EFAULT;
166177
178
+ range.minlen = max_t(u64, granularity, range.minlen);
179
+ minlen = BTOBB(range.minlen);
167180 /*
168181 * Truncating down the len isn't actually quite correct, but using
169182 * BBTOB would mean we trivially get overflows for values
....@@ -178,7 +191,6 @@
178191
179192 start = BTOBB(range.start);
180193 end = start + BTOBBT(range.len) - 1;
181
- minlen = BTOBB(max_t(u64, granularity, range.minlen));
182194
183195 if (end > XFS_FSB_TO_BB(mp, mp->m_sb.sb_dblocks) - 1)
184196 end = XFS_FSB_TO_BB(mp, mp->m_sb.sb_dblocks)- 1;