Skip to content

Commit de302ce

Browse files
Dave ChinnerChandan Babu R
authored andcommitted
xfs: pass the full grant head to accounting functions
Because we are going to need them soon. API change only, no logic changes. Signed-off-by: Dave Chinner <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Chandan Babu R <[email protected]>
1 parent 551bf13 commit de302ce

File tree

2 files changed

+77
-82
lines changed

2 files changed

+77
-82
lines changed

fs/xfs/xfs_log.c

Lines changed: 77 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@ xlog_prepare_iovec(
136136
static void
137137
xlog_grant_sub_space(
138138
struct xlog *log,
139-
atomic64_t *head,
139+
struct xlog_grant_head *head,
140140
int bytes)
141141
{
142-
int64_t head_val = atomic64_read(head);
142+
int64_t head_val = atomic64_read(&head->grant);
143143
int64_t new, old;
144144

145145
do {
@@ -155,17 +155,17 @@ xlog_grant_sub_space(
155155

156156
old = head_val;
157157
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);
159159
} while (head_val != old);
160160
}
161161

162162
static void
163163
xlog_grant_add_space(
164164
struct xlog *log,
165-
atomic64_t *head,
165+
struct xlog_grant_head *head,
166166
int bytes)
167167
{
168-
int64_t head_val = atomic64_read(head);
168+
int64_t head_val = atomic64_read(&head->grant);
169169
int64_t new, old;
170170

171171
do {
@@ -184,7 +184,7 @@ xlog_grant_add_space(
184184

185185
old = head_val;
186186
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);
188188
} while (head_val != old);
189189
}
190190

@@ -197,6 +197,63 @@ xlog_grant_head_init(
197197
spin_lock_init(&head->lock);
198198
}
199199

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+
200257
STATIC void
201258
xlog_grant_head_wake_all(
202259
struct xlog_grant_head *head)
@@ -277,7 +334,7 @@ xlog_grant_head_wait(
277334
spin_lock(&head->lock);
278335
if (xlog_is_shutdown(log))
279336
goto shutdown;
280-
} while (xlog_space_left(log, &head->grant) < need_bytes);
337+
} while (xlog_grant_space_left(log, head) < need_bytes);
281338

282339
list_del_init(&tic->t_queue);
283340
return 0;
@@ -322,7 +379,7 @@ xlog_grant_head_check(
322379
* otherwise try to get some space for this transaction.
323380
*/
324381
*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);
326383
if (!list_empty_careful(&head->waiters)) {
327384
spin_lock(&head->lock);
328385
if (!xlog_grant_head_wake(log, head, &free_bytes) ||
@@ -396,7 +453,7 @@ xfs_log_regrant(
396453
if (error)
397454
goto out_error;
398455

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);
400457
trace_xfs_log_regrant_exit(log, tic);
401458
xlog_verify_grant_tail(log);
402459
return 0;
@@ -447,8 +504,8 @@ xfs_log_reserve(
447504
if (error)
448505
goto out_error;
449506

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);
452509
trace_xfs_log_reserve_exit(log, tic);
453510
xlog_verify_grant_tail(log);
454511
return 0;
@@ -1107,7 +1164,7 @@ xfs_log_space_wake(
11071164
ASSERT(!xlog_in_recovery(log));
11081165

11091166
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);
11111168
xlog_grant_head_wake(log, &log->l_write_head, &free_bytes);
11121169
spin_unlock(&log->l_write_head.lock);
11131170
}
@@ -1116,7 +1173,7 @@ xfs_log_space_wake(
11161173
ASSERT(!xlog_in_recovery(log));
11171174

11181175
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);
11201177
xlog_grant_head_wake(log, &log->l_reserve_head, &free_bytes);
11211178
spin_unlock(&log->l_reserve_head.lock);
11221179
}
@@ -1230,64 +1287,6 @@ xfs_log_cover(
12301287
return error;
12311288
}
12321289

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-
12911290
static void
12921291
xlog_ioend_work(
12931292
struct work_struct *work)
@@ -1881,8 +1880,8 @@ xlog_sync(
18811880
if (ticket) {
18821881
ticket->t_curr_res -= roundoff;
18831882
} 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);
18861885
}
18871886

18881887
/* put cycle number in every block */
@@ -2802,17 +2801,15 @@ xfs_log_ticket_regrant(
28022801
if (ticket->t_cnt > 0)
28032802
ticket->t_cnt--;
28042803

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);
28092806
ticket->t_curr_res = ticket->t_unit_res;
28102807

28112808
trace_xfs_log_ticket_regrant_sub(log, ticket);
28122809

28132810
/* just return if we still have some of the pre-reserved space */
28142811
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,
28162813
ticket->t_unit_res);
28172814
trace_xfs_log_ticket_regrant_exit(log, ticket);
28182815

@@ -2860,8 +2857,8 @@ xfs_log_ticket_ungrant(
28602857
bytes += ticket->t_unit_res*ticket->t_cnt;
28612858
}
28622859

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);
28652862

28662863
trace_xfs_log_ticket_ungrant_exit(log, ticket);
28672864

fs/xfs/xfs_log_priv.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,8 +573,6 @@ xlog_assign_grant_head(atomic64_t *head, int cycle, int space)
573573
atomic64_set(head, xlog_assign_grant_head_val(cycle, space));
574574
}
575575

576-
int xlog_space_left(struct xlog *log, atomic64_t *head);
577-
578576
/*
579577
* Committed Item List interfaces
580578
*/

0 commit comments

Comments
 (0)