@@ -64,25 +64,31 @@ xfs_filestream_pick_ag(
6464 struct xfs_perag * pag ;
6565 struct xfs_perag * max_pag = NULL ;
6666 xfs_extlen_t minlen = * longest ;
67- xfs_extlen_t free = 0 , minfree , maxfree = 0 ;
67+ 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,66 +113,57 @@ xfs_filestream_pick_ag(
107113 !(flags & XFS_PICK_USERDATA ) ||
108114 (flags & XFS_PICK_LOWSPACE ))) {
109115 /* Break out, retaining the reference on the AG. */
110- free = pag -> pagf_freeblks ;
111- break ;
116+ if (max_pag )
117+ xfs_perag_rele (max_pag );
118+ goto done ;
112119 }
113120 }
114121
115122 /* Drop the reference on this AG, it's not usable. */
116123 atomic_dec (& pag -> pagf_fstrms );
117124 }
118125
119- if (err ) {
120- xfs_perag_rele (pag );
121- if (max_pag )
122- xfs_perag_rele (max_pag );
123- 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 ;
124134 }
125135
126- if (!pag ) {
127- /*
128- * Allow a second pass to give xfs_bmap_longest_free_extent()
129- * another attempt at locking AGFs that it might have skipped
130- * over before we fail.
131- */
132- if (first_pass ) {
133- first_pass = false;
134- goto restart ;
135- }
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+ }
136144
137- /*
138- * We must be low on data space, so run a final lowspace
139- * optimised selection pass if we haven't already.
140- */
141- if (!(flags & XFS_PICK_LOWSPACE )) {
142- flags |= XFS_PICK_LOWSPACE ;
143- goto restart ;
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 ;
144154 }
145155
146- /*
147- * No unassociated AGs are available, so select the AG with the
148- * most free space, regardless of whether it's already in use by
149- * another filestream. It none suit, just use whatever AG we can
150- * grab.
151- */
152- if (!max_pag ) {
153- for_each_perag_wrap (args -> mp , 0 , start_agno , args -> pag )
154- break ;
155- atomic_inc (& args -> pag -> pagf_fstrms );
156- * longest = 0 ;
157- } else {
158- pag = max_pag ;
159- free = maxfree ;
160- atomic_inc (& pag -> pagf_fstrms );
161- }
162- } else if (max_pag ) {
163- xfs_perag_rele (max_pag );
156+ /* Bail if there are no AGs at all to select from. */
157+ if (!max_pag )
158+ return - ENOSPC ;
164159 }
165160
166- trace_xfs_filestream_pick (pag , pino , free );
161+ pag = max_pag ;
162+ atomic_inc (& pag -> pagf_fstrms );
163+ done :
164+ trace_xfs_filestream_pick (pag , pino );
167165 args -> pag = pag ;
168166 return 0 ;
169-
170167}
171168
172169static struct xfs_inode *
0 commit comments