@@ -136,10 +136,10 @@ xlog_prepare_iovec(
136
136
static void
137
137
xlog_grant_sub_space (
138
138
struct xlog * log ,
139
- atomic64_t * head ,
139
+ struct xlog_grant_head * head ,
140
140
int bytes )
141
141
{
142
- int64_t head_val = atomic64_read (head );
142
+ int64_t head_val = atomic64_read (& head -> grant );
143
143
int64_t new , old ;
144
144
145
145
do {
@@ -155,17 +155,17 @@ xlog_grant_sub_space(
155
155
156
156
old = head_val ;
157
157
new = xlog_assign_grant_head_val (cycle , space );
158
- head_val = atomic64_cmpxchg (head , old , new );
158
+ head_val = atomic64_cmpxchg (& head -> grant , old , new );
159
159
} while (head_val != old );
160
160
}
161
161
162
162
static void
163
163
xlog_grant_add_space (
164
164
struct xlog * log ,
165
- atomic64_t * head ,
165
+ struct xlog_grant_head * head ,
166
166
int bytes )
167
167
{
168
- int64_t head_val = atomic64_read (head );
168
+ int64_t head_val = atomic64_read (& head -> grant );
169
169
int64_t new , old ;
170
170
171
171
do {
@@ -184,7 +184,7 @@ xlog_grant_add_space(
184
184
185
185
old = head_val ;
186
186
new = xlog_assign_grant_head_val (cycle , space );
187
- head_val = atomic64_cmpxchg (head , old , new );
187
+ head_val = atomic64_cmpxchg (& head -> grant , old , new );
188
188
} while (head_val != old );
189
189
}
190
190
@@ -197,6 +197,63 @@ xlog_grant_head_init(
197
197
spin_lock_init (& head -> lock );
198
198
}
199
199
200
+ /*
201
+ * Return the space in the log between the tail and the head. The head
202
+ * is passed in the cycle/bytes formal parms. In the special case where
203
+ * the reserve head has wrapped passed the tail, this calculation is no
204
+ * longer valid. In this case, just return 0 which means there is no space
205
+ * in the log. This works for all places where this function is called
206
+ * with the reserve head. Of course, if the write head were to ever
207
+ * wrap the tail, we should blow up. Rather than catch this case here,
208
+ * we depend on other ASSERTions in other parts of the code. XXXmiken
209
+ *
210
+ * If reservation head is behind the tail, we have a problem. Warn about it,
211
+ * but then treat it as if the log is empty.
212
+ *
213
+ * If the log is shut down, the head and tail may be invalid or out of whack, so
214
+ * shortcut invalidity asserts in this case so that we don't trigger them
215
+ * falsely.
216
+ */
217
+ static int
218
+ xlog_grant_space_left (
219
+ struct xlog * log ,
220
+ struct xlog_grant_head * head )
221
+ {
222
+ int tail_bytes ;
223
+ int tail_cycle ;
224
+ int head_cycle ;
225
+ int head_bytes ;
226
+
227
+ xlog_crack_grant_head (& head -> grant , & head_cycle , & head_bytes );
228
+ xlog_crack_atomic_lsn (& log -> l_tail_lsn , & tail_cycle , & tail_bytes );
229
+ tail_bytes = BBTOB (tail_bytes );
230
+ if (tail_cycle == head_cycle && head_bytes >= tail_bytes )
231
+ return log -> l_logsize - (head_bytes - tail_bytes );
232
+ if (tail_cycle + 1 < head_cycle )
233
+ return 0 ;
234
+
235
+ /* Ignore potential inconsistency when shutdown. */
236
+ if (xlog_is_shutdown (log ))
237
+ return log -> l_logsize ;
238
+
239
+ if (tail_cycle < head_cycle ) {
240
+ ASSERT (tail_cycle == (head_cycle - 1 ));
241
+ return tail_bytes - head_bytes ;
242
+ }
243
+
244
+ /*
245
+ * The reservation head is behind the tail. In this case we just want to
246
+ * return the size of the log as the amount of space left.
247
+ */
248
+ xfs_alert (log -> l_mp , "xlog_grant_space_left: head behind tail" );
249
+ xfs_alert (log -> l_mp , " tail_cycle = %d, tail_bytes = %d" ,
250
+ tail_cycle , tail_bytes );
251
+ xfs_alert (log -> l_mp , " GH cycle = %d, GH bytes = %d" ,
252
+ head_cycle , head_bytes );
253
+ ASSERT (0 );
254
+ return log -> l_logsize ;
255
+ }
256
+
200
257
STATIC void
201
258
xlog_grant_head_wake_all (
202
259
struct xlog_grant_head * head )
@@ -277,7 +334,7 @@ xlog_grant_head_wait(
277
334
spin_lock (& head -> lock );
278
335
if (xlog_is_shutdown (log ))
279
336
goto shutdown ;
280
- } while (xlog_space_left (log , & head -> grant ) < need_bytes );
337
+ } while (xlog_grant_space_left (log , head ) < need_bytes );
281
338
282
339
list_del_init (& tic -> t_queue );
283
340
return 0 ;
@@ -322,7 +379,7 @@ xlog_grant_head_check(
322
379
* otherwise try to get some space for this transaction.
323
380
*/
324
381
* need_bytes = xlog_ticket_reservation (log , head , tic );
325
- free_bytes = xlog_space_left (log , & head -> grant );
382
+ free_bytes = xlog_grant_space_left (log , head );
326
383
if (!list_empty_careful (& head -> waiters )) {
327
384
spin_lock (& head -> lock );
328
385
if (!xlog_grant_head_wake (log , head , & free_bytes ) ||
@@ -396,7 +453,7 @@ xfs_log_regrant(
396
453
if (error )
397
454
goto out_error ;
398
455
399
- xlog_grant_add_space (log , & log -> l_write_head . grant , need_bytes );
456
+ xlog_grant_add_space (log , & log -> l_write_head , need_bytes );
400
457
trace_xfs_log_regrant_exit (log , tic );
401
458
xlog_verify_grant_tail (log );
402
459
return 0 ;
@@ -447,8 +504,8 @@ xfs_log_reserve(
447
504
if (error )
448
505
goto out_error ;
449
506
450
- xlog_grant_add_space (log , & log -> l_reserve_head . grant , need_bytes );
451
- xlog_grant_add_space (log , & log -> l_write_head . grant , need_bytes );
507
+ xlog_grant_add_space (log , & log -> l_reserve_head , need_bytes );
508
+ xlog_grant_add_space (log , & log -> l_write_head , need_bytes );
452
509
trace_xfs_log_reserve_exit (log , tic );
453
510
xlog_verify_grant_tail (log );
454
511
return 0 ;
@@ -1107,7 +1164,7 @@ xfs_log_space_wake(
1107
1164
ASSERT (!xlog_in_recovery (log ));
1108
1165
1109
1166
spin_lock (& log -> l_write_head .lock );
1110
- free_bytes = xlog_space_left (log , & log -> l_write_head . grant );
1167
+ free_bytes = xlog_grant_space_left (log , & log -> l_write_head );
1111
1168
xlog_grant_head_wake (log , & log -> l_write_head , & free_bytes );
1112
1169
spin_unlock (& log -> l_write_head .lock );
1113
1170
}
@@ -1116,7 +1173,7 @@ xfs_log_space_wake(
1116
1173
ASSERT (!xlog_in_recovery (log ));
1117
1174
1118
1175
spin_lock (& log -> l_reserve_head .lock );
1119
- free_bytes = xlog_space_left (log , & log -> l_reserve_head . grant );
1176
+ free_bytes = xlog_grant_space_left (log , & log -> l_reserve_head );
1120
1177
xlog_grant_head_wake (log , & log -> l_reserve_head , & free_bytes );
1121
1178
spin_unlock (& log -> l_reserve_head .lock );
1122
1179
}
@@ -1230,64 +1287,6 @@ xfs_log_cover(
1230
1287
return error ;
1231
1288
}
1232
1289
1233
- /*
1234
- * Return the space in the log between the tail and the head. The head
1235
- * is passed in the cycle/bytes formal parms. In the special case where
1236
- * the reserve head has wrapped passed the tail, this calculation is no
1237
- * longer valid. In this case, just return 0 which means there is no space
1238
- * in the log. This works for all places where this function is called
1239
- * with the reserve head. Of course, if the write head were to ever
1240
- * wrap the tail, we should blow up. Rather than catch this case here,
1241
- * we depend on other ASSERTions in other parts of the code. XXXmiken
1242
- *
1243
- * If reservation head is behind the tail, we have a problem. Warn about it,
1244
- * but then treat it as if the log is empty.
1245
- *
1246
- * If the log is shut down, the head and tail may be invalid or out of whack, so
1247
- * shortcut invalidity asserts in this case so that we don't trigger them
1248
- * falsely.
1249
- */
1250
- int
1251
- xlog_space_left (
1252
- struct xlog * log ,
1253
- atomic64_t * head )
1254
- {
1255
- int tail_bytes ;
1256
- int tail_cycle ;
1257
- int head_cycle ;
1258
- int head_bytes ;
1259
-
1260
- xlog_crack_grant_head (head , & head_cycle , & head_bytes );
1261
- xlog_crack_atomic_lsn (& log -> l_tail_lsn , & tail_cycle , & tail_bytes );
1262
- tail_bytes = BBTOB (tail_bytes );
1263
- if (tail_cycle == head_cycle && head_bytes >= tail_bytes )
1264
- return log -> l_logsize - (head_bytes - tail_bytes );
1265
- if (tail_cycle + 1 < head_cycle )
1266
- return 0 ;
1267
-
1268
- /* Ignore potential inconsistency when shutdown. */
1269
- if (xlog_is_shutdown (log ))
1270
- return log -> l_logsize ;
1271
-
1272
- if (tail_cycle < head_cycle ) {
1273
- ASSERT (tail_cycle == (head_cycle - 1 ));
1274
- return tail_bytes - head_bytes ;
1275
- }
1276
-
1277
- /*
1278
- * The reservation head is behind the tail. In this case we just want to
1279
- * return the size of the log as the amount of space left.
1280
- */
1281
- xfs_alert (log -> l_mp , "xlog_space_left: head behind tail" );
1282
- xfs_alert (log -> l_mp , " tail_cycle = %d, tail_bytes = %d" ,
1283
- tail_cycle , tail_bytes );
1284
- xfs_alert (log -> l_mp , " GH cycle = %d, GH bytes = %d" ,
1285
- head_cycle , head_bytes );
1286
- ASSERT (0 );
1287
- return log -> l_logsize ;
1288
- }
1289
-
1290
-
1291
1290
static void
1292
1291
xlog_ioend_work (
1293
1292
struct work_struct * work )
@@ -1881,8 +1880,8 @@ xlog_sync(
1881
1880
if (ticket ) {
1882
1881
ticket -> t_curr_res -= roundoff ;
1883
1882
} else {
1884
- xlog_grant_add_space (log , & log -> l_reserve_head . grant , roundoff );
1885
- xlog_grant_add_space (log , & log -> l_write_head . grant , roundoff );
1883
+ xlog_grant_add_space (log , & log -> l_reserve_head , roundoff );
1884
+ xlog_grant_add_space (log , & log -> l_write_head , roundoff );
1886
1885
}
1887
1886
1888
1887
/* put cycle number in every block */
@@ -2802,17 +2801,15 @@ xfs_log_ticket_regrant(
2802
2801
if (ticket -> t_cnt > 0 )
2803
2802
ticket -> t_cnt -- ;
2804
2803
2805
- xlog_grant_sub_space (log , & log -> l_reserve_head .grant ,
2806
- ticket -> t_curr_res );
2807
- xlog_grant_sub_space (log , & log -> l_write_head .grant ,
2808
- ticket -> t_curr_res );
2804
+ xlog_grant_sub_space (log , & log -> l_reserve_head , ticket -> t_curr_res );
2805
+ xlog_grant_sub_space (log , & log -> l_write_head , ticket -> t_curr_res );
2809
2806
ticket -> t_curr_res = ticket -> t_unit_res ;
2810
2807
2811
2808
trace_xfs_log_ticket_regrant_sub (log , ticket );
2812
2809
2813
2810
/* just return if we still have some of the pre-reserved space */
2814
2811
if (!ticket -> t_cnt ) {
2815
- xlog_grant_add_space (log , & log -> l_reserve_head . grant ,
2812
+ xlog_grant_add_space (log , & log -> l_reserve_head ,
2816
2813
ticket -> t_unit_res );
2817
2814
trace_xfs_log_ticket_regrant_exit (log , ticket );
2818
2815
@@ -2860,8 +2857,8 @@ xfs_log_ticket_ungrant(
2860
2857
bytes += ticket -> t_unit_res * ticket -> t_cnt ;
2861
2858
}
2862
2859
2863
- xlog_grant_sub_space (log , & log -> l_reserve_head . grant , bytes );
2864
- xlog_grant_sub_space (log , & log -> l_write_head . grant , bytes );
2860
+ xlog_grant_sub_space (log , & log -> l_reserve_head , bytes );
2861
+ xlog_grant_sub_space (log , & log -> l_write_head , bytes );
2865
2862
2866
2863
trace_xfs_log_ticket_ungrant_exit (log , ticket );
2867
2864
0 commit comments