Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <dchinner@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>

authored by

Dave Chinner and committed by
Chandan Babu R
de302cea 551bf13b

+77 -82
+77 -80
fs/xfs/xfs_log.c
··· 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 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 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 ··· 195 195 xlog_assign_grant_head(&head->grant, 1, 0); 196 196 INIT_LIST_HEAD(&head->waiters); 197 197 spin_lock_init(&head->lock); 198 + } 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; 198 255 } 199 256 200 257 STATIC void ··· 334 277 spin_lock(&head->lock); 335 278 if (xlog_is_shutdown(log)) 336 279 goto shutdown; 337 - } while (xlog_space_left(log, &head->grant) < need_bytes); 280 + } while (xlog_grant_space_left(log, head) < need_bytes); 338 281 339 282 list_del_init(&tic->t_queue); 340 283 return 0; ··· 379 322 * otherwise try to get some space for this transaction. 380 323 */ 381 324 *need_bytes = xlog_ticket_reservation(log, head, tic); 382 - free_bytes = xlog_space_left(log, &head->grant); 325 + free_bytes = xlog_grant_space_left(log, head); 383 326 if (!list_empty_careful(&head->waiters)) { 384 327 spin_lock(&head->lock); 385 328 if (!xlog_grant_head_wake(log, head, &free_bytes) || ··· 453 396 if (error) 454 397 goto out_error; 455 398 456 - xlog_grant_add_space(log, &log->l_write_head.grant, need_bytes); 399 + xlog_grant_add_space(log, &log->l_write_head, need_bytes); 457 400 trace_xfs_log_regrant_exit(log, tic); 458 401 xlog_verify_grant_tail(log); 459 402 return 0; ··· 504 447 if (error) 505 448 goto out_error; 506 449 507 - xlog_grant_add_space(log, &log->l_reserve_head.grant, need_bytes); 508 - xlog_grant_add_space(log, &log->l_write_head.grant, need_bytes); 450 + xlog_grant_add_space(log, &log->l_reserve_head, need_bytes); 451 + xlog_grant_add_space(log, &log->l_write_head, need_bytes); 509 452 trace_xfs_log_reserve_exit(log, tic); 510 453 xlog_verify_grant_tail(log); 511 454 return 0; ··· 1164 1107 ASSERT(!xlog_in_recovery(log)); 1165 1108 1166 1109 spin_lock(&log->l_write_head.lock); 1167 - free_bytes = xlog_space_left(log, &log->l_write_head.grant); 1110 + free_bytes = xlog_grant_space_left(log, &log->l_write_head); 1168 1111 xlog_grant_head_wake(log, &log->l_write_head, &free_bytes); 1169 1112 spin_unlock(&log->l_write_head.lock); 1170 1113 } ··· 1173 1116 ASSERT(!xlog_in_recovery(log)); 1174 1117 1175 1118 spin_lock(&log->l_reserve_head.lock); 1176 - free_bytes = xlog_space_left(log, &log->l_reserve_head.grant); 1119 + free_bytes = xlog_grant_space_left(log, &log->l_reserve_head); 1177 1120 xlog_grant_head_wake(log, &log->l_reserve_head, &free_bytes); 1178 1121 spin_unlock(&log->l_reserve_head.lock); 1179 1122 } ··· 1286 1229 1287 1230 return error; 1288 1231 } 1289 - 1290 - /* 1291 - * Return the space in the log between the tail and the head. The head 1292 - * is passed in the cycle/bytes formal parms. In the special case where 1293 - * the reserve head has wrapped passed the tail, this calculation is no 1294 - * longer valid. In this case, just return 0 which means there is no space 1295 - * in the log. This works for all places where this function is called 1296 - * with the reserve head. Of course, if the write head were to ever 1297 - * wrap the tail, we should blow up. Rather than catch this case here, 1298 - * we depend on other ASSERTions in other parts of the code. XXXmiken 1299 - * 1300 - * If reservation head is behind the tail, we have a problem. Warn about it, 1301 - * but then treat it as if the log is empty. 1302 - * 1303 - * If the log is shut down, the head and tail may be invalid or out of whack, so 1304 - * shortcut invalidity asserts in this case so that we don't trigger them 1305 - * falsely. 1306 - */ 1307 - int 1308 - xlog_space_left( 1309 - struct xlog *log, 1310 - atomic64_t *head) 1311 - { 1312 - int tail_bytes; 1313 - int tail_cycle; 1314 - int head_cycle; 1315 - int head_bytes; 1316 - 1317 - xlog_crack_grant_head(head, &head_cycle, &head_bytes); 1318 - xlog_crack_atomic_lsn(&log->l_tail_lsn, &tail_cycle, &tail_bytes); 1319 - tail_bytes = BBTOB(tail_bytes); 1320 - if (tail_cycle == head_cycle && head_bytes >= tail_bytes) 1321 - return log->l_logsize - (head_bytes - tail_bytes); 1322 - if (tail_cycle + 1 < head_cycle) 1323 - return 0; 1324 - 1325 - /* Ignore potential inconsistency when shutdown. */ 1326 - if (xlog_is_shutdown(log)) 1327 - return log->l_logsize; 1328 - 1329 - if (tail_cycle < head_cycle) { 1330 - ASSERT(tail_cycle == (head_cycle - 1)); 1331 - return tail_bytes - head_bytes; 1332 - } 1333 - 1334 - /* 1335 - * The reservation head is behind the tail. In this case we just want to 1336 - * return the size of the log as the amount of space left. 1337 - */ 1338 - xfs_alert(log->l_mp, "xlog_space_left: head behind tail"); 1339 - xfs_alert(log->l_mp, " tail_cycle = %d, tail_bytes = %d", 1340 - tail_cycle, tail_bytes); 1341 - xfs_alert(log->l_mp, " GH cycle = %d, GH bytes = %d", 1342 - head_cycle, head_bytes); 1343 - ASSERT(0); 1344 - return log->l_logsize; 1345 - } 1346 - 1347 1232 1348 1233 static void 1349 1234 xlog_ioend_work( ··· 1880 1881 if (ticket) { 1881 1882 ticket->t_curr_res -= roundoff; 1882 1883 } else { 1883 - xlog_grant_add_space(log, &log->l_reserve_head.grant, roundoff); 1884 - xlog_grant_add_space(log, &log->l_write_head.grant, roundoff); 1884 + xlog_grant_add_space(log, &log->l_reserve_head, roundoff); 1885 + xlog_grant_add_space(log, &log->l_write_head, roundoff); 1885 1886 } 1886 1887 1887 1888 /* put cycle number in every block */ ··· 2801 2802 if (ticket->t_cnt > 0) 2802 2803 ticket->t_cnt--; 2803 2804 2804 - xlog_grant_sub_space(log, &log->l_reserve_head.grant, 2805 - ticket->t_curr_res); 2806 - xlog_grant_sub_space(log, &log->l_write_head.grant, 2807 - ticket->t_curr_res); 2805 + xlog_grant_sub_space(log, &log->l_reserve_head, ticket->t_curr_res); 2806 + xlog_grant_sub_space(log, &log->l_write_head, ticket->t_curr_res); 2808 2807 ticket->t_curr_res = ticket->t_unit_res; 2809 2808 2810 2809 trace_xfs_log_ticket_regrant_sub(log, ticket); 2811 2810 2812 2811 /* just return if we still have some of the pre-reserved space */ 2813 2812 if (!ticket->t_cnt) { 2814 - xlog_grant_add_space(log, &log->l_reserve_head.grant, 2813 + xlog_grant_add_space(log, &log->l_reserve_head, 2815 2814 ticket->t_unit_res); 2816 2815 trace_xfs_log_ticket_regrant_exit(log, ticket); 2817 2816 ··· 2857 2860 bytes += ticket->t_unit_res*ticket->t_cnt; 2858 2861 } 2859 2862 2860 - xlog_grant_sub_space(log, &log->l_reserve_head.grant, bytes); 2861 - xlog_grant_sub_space(log, &log->l_write_head.grant, bytes); 2863 + xlog_grant_sub_space(log, &log->l_reserve_head, bytes); 2864 + xlog_grant_sub_space(log, &log->l_write_head, bytes); 2862 2865 2863 2866 trace_xfs_log_ticket_ungrant_exit(log, ticket); 2864 2867
-2
fs/xfs/xfs_log_priv.h
··· 573 573 atomic64_set(head, xlog_assign_grant_head_val(cycle, space)); 574 574 } 575 575 576 - int xlog_space_left(struct xlog *log, atomic64_t *head); 577 - 578 576 /* 579 577 * Committed Item List interfaces 580 578 */