| .. | .. |
|---|
| 5 | 5 | * All Rights Reserved. |
|---|
| 6 | 6 | */ |
|---|
| 7 | 7 | #include "xfs.h" |
|---|
| 8 | +#include "xfs_shared.h" |
|---|
| 8 | 9 | #include "xfs_format.h" |
|---|
| 9 | 10 | #include "xfs_log_format.h" |
|---|
| 10 | 11 | #include "xfs_trans_resv.h" |
|---|
| 11 | 12 | #include "xfs_sb.h" |
|---|
| 12 | 13 | #include "xfs_mount.h" |
|---|
| 13 | | -#include "xfs_defer.h" |
|---|
| 14 | 14 | #include "xfs_inode.h" |
|---|
| 15 | 15 | #include "xfs_bmap.h" |
|---|
| 16 | | -#include "xfs_bmap_util.h" |
|---|
| 17 | 16 | #include "xfs_alloc.h" |
|---|
| 18 | 17 | #include "xfs_mru_cache.h" |
|---|
| 19 | | -#include "xfs_filestream.h" |
|---|
| 20 | 18 | #include "xfs_trace.h" |
|---|
| 21 | 19 | #include "xfs_ag_resv.h" |
|---|
| 22 | 20 | #include "xfs_trans.h" |
|---|
| 23 | | -#include "xfs_shared.h" |
|---|
| 21 | +#include "xfs_filestream.h" |
|---|
| 24 | 22 | |
|---|
| 25 | 23 | struct xfs_fstrm_item { |
|---|
| 26 | 24 | struct xfs_mru_cache_elem mru; |
|---|
| .. | .. |
|---|
| 35 | 33 | /* |
|---|
| 36 | 34 | * Allocation group filestream associations are tracked with per-ag atomic |
|---|
| 37 | 35 | * 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. |
|---|
| 71 | 37 | */ |
|---|
| 72 | 38 | int |
|---|
| 73 | 39 | xfs_filestream_peek_ag( |
|---|
| .. | .. |
|---|
| 161 | 127 | |
|---|
| 162 | 128 | if (!pag->pagf_init) { |
|---|
| 163 | 129 | 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; |
|---|
| 167 | 137 | } |
|---|
| 168 | 138 | } |
|---|
| 169 | | - |
|---|
| 170 | | - /* Might fail sometimes during the 1st pass with trylock set. */ |
|---|
| 171 | | - if (!pag->pagf_init) |
|---|
| 172 | | - goto next_ag; |
|---|
| 173 | 139 | |
|---|
| 174 | 140 | /* Keep track of the AG with the most free blocks. */ |
|---|
| 175 | 141 | if (pag->pagf_freeblks > maxfree) { |
|---|
| .. | .. |
|---|
| 377 | 343 | startag = (item->ag + 1) % mp->m_sb.sb_agcount; |
|---|
| 378 | 344 | } |
|---|
| 379 | 345 | |
|---|
| 380 | | - if (xfs_alloc_is_userdata(ap->datatype)) |
|---|
| 346 | + if (ap->datatype & XFS_ALLOC_USERDATA) |
|---|
| 381 | 347 | flags |= XFS_PICK_USERDATA; |
|---|
| 382 | 348 | if (ap->tp->t_flags & XFS_TRANS_LOWMODE) |
|---|
| 383 | 349 | flags |= XFS_PICK_LOWSPACE; |
|---|