Commit 4196ac08c023c6dab90c3fa460d9c06deaa304c4

Authored by Dave Chinner
Committed by Alex Elder
1 parent a862e0fdcb

xfs: Convert filestreams code to use per-ag get/put routines

Use xfs_perag_get() and xfs_perag_put() in the filestreams code.

Signed-off-by: Dave Chinner <david@fromorbit.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Alex Elder <aelder@sgi.com>

Showing 2 changed files with 36 additions and 10 deletions Side-by-side Diff

fs/xfs/xfs_filestream.c
... ... @@ -140,6 +140,7 @@
140 140 int flags,
141 141 xfs_extlen_t minlen)
142 142 {
  143 + int streams, max_streams;
143 144 int err, trylock, nscan;
144 145 xfs_extlen_t longest, free, minfree, maxfree = 0;
145 146 xfs_agnumber_t ag, max_ag = NULLAGNUMBER;
146 147  
147 148  
148 149  
... ... @@ -155,15 +156,15 @@
155 156 trylock = XFS_ALLOC_FLAG_TRYLOCK;
156 157  
157 158 for (nscan = 0; 1; nscan++) {
  159 + pag = xfs_perag_get(mp, ag);
  160 + TRACE_AG_SCAN(mp, ag, atomic_read(&pag->pagf_fstrms));
158 161  
159   - TRACE_AG_SCAN(mp, ag, xfs_filestream_peek_ag(mp, ag));
160   -
161   - pag = mp->m_perag + ag;
162   -
163 162 if (!pag->pagf_init) {
164 163 err = xfs_alloc_pagf_init(mp, NULL, ag, trylock);
165   - if (err && !trylock)
  164 + if (err && !trylock) {
  165 + xfs_perag_put(pag);
166 166 return err;
  167 + }
167 168 }
168 169  
169 170 /* Might fail sometimes during the 1st pass with trylock set. */
... ... @@ -173,6 +174,7 @@
173 174 /* Keep track of the AG with the most free blocks. */
174 175 if (pag->pagf_freeblks > maxfree) {
175 176 maxfree = pag->pagf_freeblks;
  177 + max_streams = atomic_read(&pag->pagf_fstrms);
176 178 max_ag = ag;
177 179 }
178 180  
... ... @@ -195,6 +197,8 @@
195 197  
196 198 /* Break out, retaining the reference on the AG. */
197 199 free = pag->pagf_freeblks;
  200 + streams = atomic_read(&pag->pagf_fstrms);
  201 + xfs_perag_put(pag);
198 202 *agp = ag;
199 203 break;
200 204 }
... ... @@ -202,6 +206,7 @@
202 206 /* Drop the reference on this AG, it's not usable. */
203 207 xfs_filestream_put_ag(mp, ag);
204 208 next_ag:
  209 + xfs_perag_put(pag);
205 210 /* Move to the next AG, wrapping to AG 0 if necessary. */
206 211 if (++ag >= mp->m_sb.sb_agcount)
207 212 ag = 0;
... ... @@ -229,6 +234,7 @@
229 234 if (max_ag != NULLAGNUMBER) {
230 235 xfs_filestream_get_ag(mp, max_ag);
231 236 TRACE_AG_PICK1(mp, max_ag, maxfree);
  237 + streams = max_streams;
232 238 free = maxfree;
233 239 *agp = max_ag;
234 240 break;
... ... @@ -240,8 +246,7 @@
240 246 return 0;
241 247 }
242 248  
243   - TRACE_AG_PICK2(mp, startag, *agp, xfs_filestream_peek_ag(mp, *agp),
244   - free, nscan, flags);
  249 + TRACE_AG_PICK2(mp, startag, *agp, streams, free, nscan, flags);
245 250  
246 251 return 0;
247 252 }
fs/xfs/xfs_filestream.h
... ... @@ -79,12 +79,21 @@
79 79 * the cache that reference per-ag array elements that have since been
80 80 * reallocated.
81 81 */
  82 +/*
  83 + * xfs_filestream_peek_ag is only used in tracing code
  84 + */
82 85 static inline int
83 86 xfs_filestream_peek_ag(
84 87 xfs_mount_t *mp,
85 88 xfs_agnumber_t agno)
86 89 {
87   - return atomic_read(&mp->m_perag[agno].pagf_fstrms);
  90 + struct xfs_perag *pag;
  91 + int ret;
  92 +
  93 + pag = xfs_perag_get(mp, agno);
  94 + ret = atomic_read(&pag->pagf_fstrms);
  95 + xfs_perag_put(pag);
  96 + return ret;
88 97 }
89 98  
90 99 static inline int
... ... @@ -92,7 +101,13 @@
92 101 xfs_mount_t *mp,
93 102 xfs_agnumber_t agno)
94 103 {
95   - return atomic_inc_return(&mp->m_perag[agno].pagf_fstrms);
  104 + struct xfs_perag *pag;
  105 + int ret;
  106 +
  107 + pag = xfs_perag_get(mp, agno);
  108 + ret = atomic_inc_return(&pag->pagf_fstrms);
  109 + xfs_perag_put(pag);
  110 + return ret;
96 111 }
97 112  
98 113 static inline int
... ... @@ -100,7 +115,13 @@
100 115 xfs_mount_t *mp,
101 116 xfs_agnumber_t agno)
102 117 {
103   - return atomic_dec_return(&mp->m_perag[agno].pagf_fstrms);
  118 + struct xfs_perag *pag;
  119 + int ret;
  120 +
  121 + pag = xfs_perag_get(mp, agno);
  122 + ret = atomic_dec_return(&pag->pagf_fstrms);
  123 + xfs_perag_put(pag);
  124 + return ret;
104 125 }
105 126  
106 127 /* allocation selection flags */