@@ -67,22 +67,28 @@ xfs_filestream_pick_ag(
6767 xfs_extlen_t minfree , maxfree = 0 ;
6868 xfs_agnumber_t agno ;
6969 bool first_pass = true;
70- int err ;
7170
7271 /* 2% of an AG's blocks must be free for it to be chosen. */
7372 minfree = mp -> m_sb .sb_agblocks / 50 ;
7473
7574restart :
7675 for_each_perag_wrap (mp , start_agno , agno , pag ) {
76+ int err ;
77+
7778 trace_xfs_filestream_scan (pag , pino );
79+
7880 * longest = 0 ;
7981 err = xfs_bmap_longest_free_extent (pag , NULL , longest );
8082 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 ;
8692 }
8793
8894 /* Keep track of the AG with the most free blocks. */
@@ -107,64 +113,54 @@ xfs_filestream_pick_ag(
107113 !(flags & XFS_PICK_USERDATA ) ||
108114 (flags & XFS_PICK_LOWSPACE ))) {
109115 /* Break out, retaining the reference on the AG. */
110- break ;
116+ if (max_pag )
117+ xfs_perag_rele (max_pag );
118+ goto done ;
111119 }
112120 }
113121
114122 /* Drop the reference on this AG, it's not usable. */
115123 atomic_dec (& pag -> pagf_fstrms );
116124 }
117125
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 ;
123134 }
124135
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+ }
156144
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 ;
160154 }
161155
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 ;
166159 }
167160
161+ pag = max_pag ;
162+ atomic_inc (& pag -> pagf_fstrms );
163+ done :
168164 trace_xfs_filestream_pick (pag , pino );
169165 args -> pag = pag ;
170166 return 0 ;
0 commit comments