@@ -67,22 +67,28 @@ xfs_filestream_pick_ag(
67
67
xfs_extlen_t minfree , maxfree = 0 ;
68
68
xfs_agnumber_t agno ;
69
69
bool first_pass = true;
70
- int err ;
71
70
72
71
/* 2% of an AG's blocks must be free for it to be chosen. */
73
72
minfree = mp -> m_sb .sb_agblocks / 50 ;
74
73
75
74
restart :
76
75
for_each_perag_wrap (mp , start_agno , agno , pag ) {
76
+ int err ;
77
+
77
78
trace_xfs_filestream_scan (pag , pino );
79
+
78
80
* longest = 0 ;
79
81
err = xfs_bmap_longest_free_extent (pag , NULL , longest );
80
82
if (err ) {
81
- if (err != - EAGAIN )
82
- break ;
83
- /* Couldn't lock the AGF, skip this AG. */
84
- err = 0 ;
85
- continue ;
83
+ if (err == - EAGAIN ) {
84
+ /* Couldn't lock the AGF, skip this AG. */
85
+ err = 0 ;
86
+ continue ;
87
+ }
88
+ xfs_perag_rele (pag );
89
+ if (max_pag )
90
+ xfs_perag_rele (max_pag );
91
+ return err ;
86
92
}
87
93
88
94
/* Keep track of the AG with the most free blocks. */
@@ -107,64 +113,54 @@ xfs_filestream_pick_ag(
107
113
!(flags & XFS_PICK_USERDATA ) ||
108
114
(flags & XFS_PICK_LOWSPACE ))) {
109
115
/* Break out, retaining the reference on the AG. */
110
- break ;
116
+ if (max_pag )
117
+ xfs_perag_rele (max_pag );
118
+ goto done ;
111
119
}
112
120
}
113
121
114
122
/* Drop the reference on this AG, it's not usable. */
115
123
atomic_dec (& pag -> pagf_fstrms );
116
124
}
117
125
118
- if (err ) {
119
- xfs_perag_rele (pag );
120
- if (max_pag )
121
- xfs_perag_rele (max_pag );
122
- return err ;
126
+ /*
127
+ * Allow a second pass to give xfs_bmap_longest_free_extent() another
128
+ * attempt at locking AGFs that it might have skipped over before we
129
+ * fail.
130
+ */
131
+ if (first_pass ) {
132
+ first_pass = false;
133
+ goto restart ;
123
134
}
124
135
125
- if (!pag ) {
126
- /*
127
- * Allow a second pass to give xfs_bmap_longest_free_extent()
128
- * another attempt at locking AGFs that it might have skipped
129
- * over before we fail.
130
- */
131
- if (first_pass ) {
132
- first_pass = false;
133
- goto restart ;
134
- }
135
-
136
- /*
137
- * We must be low on data space, so run a final lowspace
138
- * optimised selection pass if we haven't already.
139
- */
140
- if (!(flags & XFS_PICK_LOWSPACE )) {
141
- flags |= XFS_PICK_LOWSPACE ;
142
- goto restart ;
143
- }
144
-
145
- /*
146
- * No unassociated AGs are available, so select the AG with the
147
- * most free space, regardless of whether it's already in use by
148
- * another filestream. It none suit, just use whatever AG we can
149
- * grab.
150
- */
151
- if (!max_pag ) {
152
- for_each_perag_wrap (args -> mp , 0 , start_agno , pag ) {
153
- max_pag = pag ;
154
- break ;
155
- }
136
+ /*
137
+ * We must be low on data space, so run a final lowspace optimised
138
+ * selection pass if we haven't already.
139
+ */
140
+ if (!(flags & XFS_PICK_LOWSPACE )) {
141
+ flags |= XFS_PICK_LOWSPACE ;
142
+ goto restart ;
143
+ }
156
144
157
- /* Bail if there are no AGs at all to select from. */
158
- if (!max_pag )
159
- return - ENOSPC ;
145
+ /*
146
+ * No unassociated AGs are available, so select the AG with the most
147
+ * free space, regardless of whether it's already in use by another
148
+ * filestream. It none suit, just use whatever AG we can grab.
149
+ */
150
+ if (!max_pag ) {
151
+ for_each_perag_wrap (args -> mp , 0 , start_agno , pag ) {
152
+ max_pag = pag ;
153
+ break ;
160
154
}
161
155
162
- pag = max_pag ;
163
- atomic_inc (& pag -> pagf_fstrms );
164
- } else if (max_pag ) {
165
- xfs_perag_rele (max_pag );
156
+ /* Bail if there are no AGs at all to select from. */
157
+ if (!max_pag )
158
+ return - ENOSPC ;
166
159
}
167
160
161
+ pag = max_pag ;
162
+ atomic_inc (& pag -> pagf_fstrms );
163
+ done :
168
164
trace_xfs_filestream_pick (pag , pino );
169
165
args -> pag = pag ;
170
166
return 0 ;
0 commit comments