hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/fs/xfs/xfs_filestream.c
....@@ -5,22 +5,20 @@
55 * All Rights Reserved.
66 */
77 #include "xfs.h"
8
+#include "xfs_shared.h"
89 #include "xfs_format.h"
910 #include "xfs_log_format.h"
1011 #include "xfs_trans_resv.h"
1112 #include "xfs_sb.h"
1213 #include "xfs_mount.h"
13
-#include "xfs_defer.h"
1414 #include "xfs_inode.h"
1515 #include "xfs_bmap.h"
16
-#include "xfs_bmap_util.h"
1716 #include "xfs_alloc.h"
1817 #include "xfs_mru_cache.h"
19
-#include "xfs_filestream.h"
2018 #include "xfs_trace.h"
2119 #include "xfs_ag_resv.h"
2220 #include "xfs_trans.h"
23
-#include "xfs_shared.h"
21
+#include "xfs_filestream.h"
2422
2523 struct xfs_fstrm_item {
2624 struct xfs_mru_cache_elem mru;
....@@ -35,39 +33,7 @@
3533 /*
3634 * Allocation group filestream associations are tracked with per-ag atomic
3735 * counters. These counters allow xfs_filestream_pick_ag() to tell whether a
38
- * particular AG already has active filestreams associated with it. The mount
39
- * point's m_peraglock is used to protect these counters from per-ag array
40
- * re-allocation during a growfs operation. When xfs_growfs_data_private() is
41
- * about to reallocate the array, it calls xfs_filestream_flush() with the
42
- * m_peraglock held in write mode.
43
- *
44
- * Since xfs_mru_cache_flush() guarantees that all the free functions for all
45
- * the cache elements have finished executing before it returns, it's safe for
46
- * the free functions to use the atomic counters without m_peraglock protection.
47
- * This allows the implementation of xfs_fstrm_free_func() to be agnostic about
48
- * whether it was called with the m_peraglock held in read mode, write mode or
49
- * not held at all. The race condition this addresses is the following:
50
- *
51
- * - The work queue scheduler fires and pulls a filestream directory cache
52
- * element off the LRU end of the cache for deletion, then gets pre-empted.
53
- * - A growfs operation grabs the m_peraglock in write mode, flushes all the
54
- * remaining items from the cache and reallocates the mount point's per-ag
55
- * array, resetting all the counters to zero.
56
- * - The work queue thread resumes and calls the free function for the element
57
- * it started cleaning up earlier. In the process it decrements the
58
- * filestreams counter for an AG that now has no references.
59
- *
60
- * With a shrinkfs feature, the above scenario could panic the system.
61
- *
62
- * All other uses of the following macros should be protected by either the
63
- * m_peraglock held in read mode, or the cache's internal locking exposed by the
64
- * interval between a call to xfs_mru_cache_lookup() and a call to
65
- * xfs_mru_cache_done(). In addition, the m_peraglock must be held in read mode
66
- * when new elements are added to the cache.
67
- *
68
- * Combined, these locking rules ensure that no associations will ever exist in
69
- * the cache that reference per-ag array elements that have since been
70
- * reallocated.
36
+ * particular AG already has active filestreams associated with it.
7137 */
7238 int
7339 xfs_filestream_peek_ag(
....@@ -161,15 +127,15 @@
161127
162128 if (!pag->pagf_init) {
163129 err = xfs_alloc_pagf_init(mp, NULL, ag, trylock);
164
- if (err && !trylock) {
165
- xfs_perag_put(pag);
166
- return err;
130
+ if (err) {
131
+ if (err != -EAGAIN) {
132
+ xfs_perag_put(pag);
133
+ return err;
134
+ }
135
+ /* Couldn't lock the AGF, skip this AG. */
136
+ goto next_ag;
167137 }
168138 }
169
-
170
- /* Might fail sometimes during the 1st pass with trylock set. */
171
- if (!pag->pagf_init)
172
- goto next_ag;
173139
174140 /* Keep track of the AG with the most free blocks. */
175141 if (pag->pagf_freeblks > maxfree) {
....@@ -377,7 +343,7 @@
377343 startag = (item->ag + 1) % mp->m_sb.sb_agcount;
378344 }
379345
380
- if (xfs_alloc_is_userdata(ap->datatype))
346
+ if (ap->datatype & XFS_ALLOC_USERDATA)
381347 flags |= XFS_PICK_USERDATA;
382348 if (ap->tp->t_flags & XFS_TRANS_LOWMODE)
383349 flags |= XFS_PICK_LOWSPACE;