aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xfs/xfs_log.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/xfs/xfs_log.c')
-rw-r--r--fs/xfs/xfs_log.c416
1 files changed, 200 insertions, 216 deletions
diff --git a/fs/xfs/xfs_log.c b/fs/xfs/xfs_log.c
index 77c12715a7d0..b3ac3805d3c4 100644
--- a/fs/xfs/xfs_log.c
+++ b/fs/xfs/xfs_log.c
@@ -399,10 +399,10 @@ xfs_log_notify(xfs_mount_t *mp, /* mount of partition */
399{ 399{
400 xlog_t *log = mp->m_log; 400 xlog_t *log = mp->m_log;
401 xlog_in_core_t *iclog = (xlog_in_core_t *)iclog_hndl; 401 xlog_in_core_t *iclog = (xlog_in_core_t *)iclog_hndl;
402 int abortflg, spl; 402 int abortflg;
403 403
404 cb->cb_next = NULL; 404 cb->cb_next = NULL;
405 spl = LOG_LOCK(log); 405 spin_lock(&log->l_icloglock);
406 abortflg = (iclog->ic_state & XLOG_STATE_IOERROR); 406 abortflg = (iclog->ic_state & XLOG_STATE_IOERROR);
407 if (!abortflg) { 407 if (!abortflg) {
408 ASSERT_ALWAYS((iclog->ic_state == XLOG_STATE_ACTIVE) || 408 ASSERT_ALWAYS((iclog->ic_state == XLOG_STATE_ACTIVE) ||
@@ -411,7 +411,7 @@ xfs_log_notify(xfs_mount_t *mp, /* mount of partition */
411 *(iclog->ic_callback_tail) = cb; 411 *(iclog->ic_callback_tail) = cb;
412 iclog->ic_callback_tail = &(cb->cb_next); 412 iclog->ic_callback_tail = &(cb->cb_next);
413 } 413 }
414 LOG_UNLOCK(log, spl); 414 spin_unlock(&log->l_icloglock);
415 return abortflg; 415 return abortflg;
416} /* xfs_log_notify */ 416} /* xfs_log_notify */
417 417
@@ -498,11 +498,14 @@ xfs_log_reserve(xfs_mount_t *mp,
498 * Return error or zero. 498 * Return error or zero.
499 */ 499 */
500int 500int
501xfs_log_mount(xfs_mount_t *mp, 501xfs_log_mount(
502 xfs_buftarg_t *log_target, 502 xfs_mount_t *mp,
503 xfs_daddr_t blk_offset, 503 xfs_buftarg_t *log_target,
504 int num_bblks) 504 xfs_daddr_t blk_offset,
505 int num_bblks)
505{ 506{
507 int error;
508
506 if (!(mp->m_flags & XFS_MOUNT_NORECOVERY)) 509 if (!(mp->m_flags & XFS_MOUNT_NORECOVERY))
507 cmn_err(CE_NOTE, "XFS mounting filesystem %s", mp->m_fsname); 510 cmn_err(CE_NOTE, "XFS mounting filesystem %s", mp->m_fsname);
508 else { 511 else {
@@ -515,11 +518,21 @@ xfs_log_mount(xfs_mount_t *mp,
515 mp->m_log = xlog_alloc_log(mp, log_target, blk_offset, num_bblks); 518 mp->m_log = xlog_alloc_log(mp, log_target, blk_offset, num_bblks);
516 519
517 /* 520 /*
521 * Initialize the AIL now we have a log.
522 */
523 spin_lock_init(&mp->m_ail_lock);
524 error = xfs_trans_ail_init(mp);
525 if (error) {
526 cmn_err(CE_WARN, "XFS: AIL initialisation failed: error %d", error);
527 goto error;
528 }
529
530 /*
518 * skip log recovery on a norecovery mount. pretend it all 531 * skip log recovery on a norecovery mount. pretend it all
519 * just worked. 532 * just worked.
520 */ 533 */
521 if (!(mp->m_flags & XFS_MOUNT_NORECOVERY)) { 534 if (!(mp->m_flags & XFS_MOUNT_NORECOVERY)) {
522 int error, readonly = (mp->m_flags & XFS_MOUNT_RDONLY); 535 int readonly = (mp->m_flags & XFS_MOUNT_RDONLY);
523 536
524 if (readonly) 537 if (readonly)
525 mp->m_flags &= ~XFS_MOUNT_RDONLY; 538 mp->m_flags &= ~XFS_MOUNT_RDONLY;
@@ -530,8 +543,7 @@ xfs_log_mount(xfs_mount_t *mp,
530 mp->m_flags |= XFS_MOUNT_RDONLY; 543 mp->m_flags |= XFS_MOUNT_RDONLY;
531 if (error) { 544 if (error) {
532 cmn_err(CE_WARN, "XFS: log mount/recovery failed: error %d", error); 545 cmn_err(CE_WARN, "XFS: log mount/recovery failed: error %d", error);
533 xlog_dealloc_log(mp->m_log); 546 goto error;
534 return error;
535 } 547 }
536 } 548 }
537 549
@@ -540,6 +552,9 @@ xfs_log_mount(xfs_mount_t *mp,
540 552
541 /* End mounting message in xfs_log_mount_finish */ 553 /* End mounting message in xfs_log_mount_finish */
542 return 0; 554 return 0;
555error:
556 xfs_log_unmount_dealloc(mp);
557 return error;
543} /* xfs_log_mount */ 558} /* xfs_log_mount */
544 559
545/* 560/*
@@ -606,7 +621,6 @@ xfs_log_unmount_write(xfs_mount_t *mp)
606 xfs_log_ticket_t tic = NULL; 621 xfs_log_ticket_t tic = NULL;
607 xfs_lsn_t lsn; 622 xfs_lsn_t lsn;
608 int error; 623 int error;
609 SPLDECL(s);
610 624
611 /* the data section must be 32 bit size aligned */ 625 /* the data section must be 32 bit size aligned */
612 struct { 626 struct {
@@ -659,24 +673,24 @@ xfs_log_unmount_write(xfs_mount_t *mp)
659 } 673 }
660 674
661 675
662 s = LOG_LOCK(log); 676 spin_lock(&log->l_icloglock);
663 iclog = log->l_iclog; 677 iclog = log->l_iclog;
664 iclog->ic_refcnt++; 678 iclog->ic_refcnt++;
665 LOG_UNLOCK(log, s); 679 spin_unlock(&log->l_icloglock);
666 xlog_state_want_sync(log, iclog); 680 xlog_state_want_sync(log, iclog);
667 (void) xlog_state_release_iclog(log, iclog); 681 (void) xlog_state_release_iclog(log, iclog);
668 682
669 s = LOG_LOCK(log); 683 spin_lock(&log->l_icloglock);
670 if (!(iclog->ic_state == XLOG_STATE_ACTIVE || 684 if (!(iclog->ic_state == XLOG_STATE_ACTIVE ||
671 iclog->ic_state == XLOG_STATE_DIRTY)) { 685 iclog->ic_state == XLOG_STATE_DIRTY)) {
672 if (!XLOG_FORCED_SHUTDOWN(log)) { 686 if (!XLOG_FORCED_SHUTDOWN(log)) {
673 sv_wait(&iclog->ic_forcesema, PMEM, 687 sv_wait(&iclog->ic_forcesema, PMEM,
674 &log->l_icloglock, s); 688 &log->l_icloglock, s);
675 } else { 689 } else {
676 LOG_UNLOCK(log, s); 690 spin_unlock(&log->l_icloglock);
677 } 691 }
678 } else { 692 } else {
679 LOG_UNLOCK(log, s); 693 spin_unlock(&log->l_icloglock);
680 } 694 }
681 if (tic) { 695 if (tic) {
682 xlog_trace_loggrant(log, tic, "unmount rec"); 696 xlog_trace_loggrant(log, tic, "unmount rec");
@@ -697,15 +711,15 @@ xfs_log_unmount_write(xfs_mount_t *mp)
697 * a file system that went into forced_shutdown as 711 * a file system that went into forced_shutdown as
698 * the result of an unmount.. 712 * the result of an unmount..
699 */ 713 */
700 s = LOG_LOCK(log); 714 spin_lock(&log->l_icloglock);
701 iclog = log->l_iclog; 715 iclog = log->l_iclog;
702 iclog->ic_refcnt++; 716 iclog->ic_refcnt++;
703 LOG_UNLOCK(log, s); 717 spin_unlock(&log->l_icloglock);
704 718
705 xlog_state_want_sync(log, iclog); 719 xlog_state_want_sync(log, iclog);
706 (void) xlog_state_release_iclog(log, iclog); 720 (void) xlog_state_release_iclog(log, iclog);
707 721
708 s = LOG_LOCK(log); 722 spin_lock(&log->l_icloglock);
709 723
710 if ( ! ( iclog->ic_state == XLOG_STATE_ACTIVE 724 if ( ! ( iclog->ic_state == XLOG_STATE_ACTIVE
711 || iclog->ic_state == XLOG_STATE_DIRTY 725 || iclog->ic_state == XLOG_STATE_DIRTY
@@ -714,7 +728,7 @@ xfs_log_unmount_write(xfs_mount_t *mp)
714 sv_wait(&iclog->ic_forcesema, PMEM, 728 sv_wait(&iclog->ic_forcesema, PMEM,
715 &log->l_icloglock, s); 729 &log->l_icloglock, s);
716 } else { 730 } else {
717 LOG_UNLOCK(log, s); 731 spin_unlock(&log->l_icloglock);
718 } 732 }
719 } 733 }
720 734
@@ -723,10 +737,14 @@ xfs_log_unmount_write(xfs_mount_t *mp)
723 737
724/* 738/*
725 * Deallocate log structures for unmount/relocation. 739 * Deallocate log structures for unmount/relocation.
740 *
741 * We need to stop the aild from running before we destroy
742 * and deallocate the log as the aild references the log.
726 */ 743 */
727void 744void
728xfs_log_unmount_dealloc(xfs_mount_t *mp) 745xfs_log_unmount_dealloc(xfs_mount_t *mp)
729{ 746{
747 xfs_trans_ail_destroy(mp);
730 xlog_dealloc_log(mp->m_log); 748 xlog_dealloc_log(mp->m_log);
731} 749}
732 750
@@ -762,20 +780,18 @@ xfs_log_move_tail(xfs_mount_t *mp,
762 xlog_ticket_t *tic; 780 xlog_ticket_t *tic;
763 xlog_t *log = mp->m_log; 781 xlog_t *log = mp->m_log;
764 int need_bytes, free_bytes, cycle, bytes; 782 int need_bytes, free_bytes, cycle, bytes;
765 SPLDECL(s);
766 783
767 if (XLOG_FORCED_SHUTDOWN(log)) 784 if (XLOG_FORCED_SHUTDOWN(log))
768 return; 785 return;
769 ASSERT(!XFS_FORCED_SHUTDOWN(mp));
770 786
771 if (tail_lsn == 0) { 787 if (tail_lsn == 0) {
772 /* needed since sync_lsn is 64 bits */ 788 /* needed since sync_lsn is 64 bits */
773 s = LOG_LOCK(log); 789 spin_lock(&log->l_icloglock);
774 tail_lsn = log->l_last_sync_lsn; 790 tail_lsn = log->l_last_sync_lsn;
775 LOG_UNLOCK(log, s); 791 spin_unlock(&log->l_icloglock);
776 } 792 }
777 793
778 s = GRANT_LOCK(log); 794 spin_lock(&log->l_grant_lock);
779 795
780 /* Also an invalid lsn. 1 implies that we aren't passing in a valid 796 /* Also an invalid lsn. 1 implies that we aren't passing in a valid
781 * tail_lsn. 797 * tail_lsn.
@@ -824,7 +840,7 @@ xfs_log_move_tail(xfs_mount_t *mp,
824 tic = tic->t_next; 840 tic = tic->t_next;
825 } while (tic != log->l_reserve_headq); 841 } while (tic != log->l_reserve_headq);
826 } 842 }
827 GRANT_UNLOCK(log, s); 843 spin_unlock(&log->l_grant_lock);
828} /* xfs_log_move_tail */ 844} /* xfs_log_move_tail */
829 845
830/* 846/*
@@ -836,14 +852,13 @@ xfs_log_move_tail(xfs_mount_t *mp,
836int 852int
837xfs_log_need_covered(xfs_mount_t *mp) 853xfs_log_need_covered(xfs_mount_t *mp)
838{ 854{
839 SPLDECL(s);
840 int needed = 0, gen; 855 int needed = 0, gen;
841 xlog_t *log = mp->m_log; 856 xlog_t *log = mp->m_log;
842 857
843 if (!xfs_fs_writable(mp)) 858 if (!xfs_fs_writable(mp))
844 return 0; 859 return 0;
845 860
846 s = LOG_LOCK(log); 861 spin_lock(&log->l_icloglock);
847 if (((log->l_covered_state == XLOG_STATE_COVER_NEED) || 862 if (((log->l_covered_state == XLOG_STATE_COVER_NEED) ||
848 (log->l_covered_state == XLOG_STATE_COVER_NEED2)) 863 (log->l_covered_state == XLOG_STATE_COVER_NEED2))
849 && !xfs_trans_first_ail(mp, &gen) 864 && !xfs_trans_first_ail(mp, &gen)
@@ -856,7 +871,7 @@ xfs_log_need_covered(xfs_mount_t *mp)
856 } 871 }
857 needed = 1; 872 needed = 1;
858 } 873 }
859 LOG_UNLOCK(log, s); 874 spin_unlock(&log->l_icloglock);
860 return needed; 875 return needed;
861} 876}
862 877
@@ -881,17 +896,16 @@ xfs_lsn_t
881xlog_assign_tail_lsn(xfs_mount_t *mp) 896xlog_assign_tail_lsn(xfs_mount_t *mp)
882{ 897{
883 xfs_lsn_t tail_lsn; 898 xfs_lsn_t tail_lsn;
884 SPLDECL(s);
885 xlog_t *log = mp->m_log; 899 xlog_t *log = mp->m_log;
886 900
887 tail_lsn = xfs_trans_tail_ail(mp); 901 tail_lsn = xfs_trans_tail_ail(mp);
888 s = GRANT_LOCK(log); 902 spin_lock(&log->l_grant_lock);
889 if (tail_lsn != 0) { 903 if (tail_lsn != 0) {
890 log->l_tail_lsn = tail_lsn; 904 log->l_tail_lsn = tail_lsn;
891 } else { 905 } else {
892 tail_lsn = log->l_tail_lsn = log->l_last_sync_lsn; 906 tail_lsn = log->l_tail_lsn = log->l_last_sync_lsn;
893 } 907 }
894 GRANT_UNLOCK(log, s); 908 spin_unlock(&log->l_grant_lock);
895 909
896 return tail_lsn; 910 return tail_lsn;
897} /* xlog_assign_tail_lsn */ 911} /* xlog_assign_tail_lsn */
@@ -911,7 +925,7 @@ xlog_assign_tail_lsn(xfs_mount_t *mp)
911 * the tail. The details of this case are described below, but the end 925 * the tail. The details of this case are described below, but the end
912 * result is that we return the size of the log as the amount of space left. 926 * result is that we return the size of the log as the amount of space left.
913 */ 927 */
914int 928STATIC int
915xlog_space_left(xlog_t *log, int cycle, int bytes) 929xlog_space_left(xlog_t *log, int cycle, int bytes)
916{ 930{
917 int free_bytes; 931 int free_bytes;
@@ -1165,7 +1179,7 @@ xlog_alloc_log(xfs_mount_t *mp,
1165 log->l_flags |= XLOG_ACTIVE_RECOVERY; 1179 log->l_flags |= XLOG_ACTIVE_RECOVERY;
1166 1180
1167 log->l_prev_block = -1; 1181 log->l_prev_block = -1;
1168 ASSIGN_ANY_LSN_HOST(log->l_tail_lsn, 1, 0); 1182 log->l_tail_lsn = xlog_assign_lsn(1, 0);
1169 /* log->l_tail_lsn = 0x100000000LL; cycle = 1; current block = 0 */ 1183 /* log->l_tail_lsn = 0x100000000LL; cycle = 1; current block = 0 */
1170 log->l_last_sync_lsn = log->l_tail_lsn; 1184 log->l_last_sync_lsn = log->l_tail_lsn;
1171 log->l_curr_cycle = 1; /* 0 is bad since this is initial value */ 1185 log->l_curr_cycle = 1; /* 0 is bad since this is initial value */
@@ -1193,8 +1207,8 @@ xlog_alloc_log(xfs_mount_t *mp,
1193 ASSERT(XFS_BUF_VALUSEMA(bp) <= 0); 1207 ASSERT(XFS_BUF_VALUSEMA(bp) <= 0);
1194 log->l_xbuf = bp; 1208 log->l_xbuf = bp;
1195 1209
1196 spinlock_init(&log->l_icloglock, "iclog"); 1210 spin_lock_init(&log->l_icloglock);
1197 spinlock_init(&log->l_grant_lock, "grhead_iclog"); 1211 spin_lock_init(&log->l_grant_lock);
1198 initnsema(&log->l_flushsema, 0, "ic-flush"); 1212 initnsema(&log->l_flushsema, 0, "ic-flush");
1199 xlog_state_ticket_alloc(log); /* wait until after icloglock inited */ 1213 xlog_state_ticket_alloc(log); /* wait until after icloglock inited */
1200 1214
@@ -1231,12 +1245,12 @@ xlog_alloc_log(xfs_mount_t *mp,
1231 1245
1232 head = &iclog->ic_header; 1246 head = &iclog->ic_header;
1233 memset(head, 0, sizeof(xlog_rec_header_t)); 1247 memset(head, 0, sizeof(xlog_rec_header_t));
1234 INT_SET(head->h_magicno, ARCH_CONVERT, XLOG_HEADER_MAGIC_NUM); 1248 head->h_magicno = cpu_to_be32(XLOG_HEADER_MAGIC_NUM);
1235 INT_SET(head->h_version, ARCH_CONVERT, 1249 head->h_version = cpu_to_be32(
1236 XFS_SB_VERSION_HASLOGV2(&log->l_mp->m_sb) ? 2 : 1); 1250 XFS_SB_VERSION_HASLOGV2(&log->l_mp->m_sb) ? 2 : 1);
1237 INT_SET(head->h_size, ARCH_CONVERT, log->l_iclog_size); 1251 head->h_size = cpu_to_be32(log->l_iclog_size);
1238 /* new fields */ 1252 /* new fields */
1239 INT_SET(head->h_fmt, ARCH_CONVERT, XLOG_FMT); 1253 head->h_fmt = cpu_to_be32(XLOG_FMT);
1240 memcpy(&head->h_fs_uuid, &mp->m_sb.sb_uuid, sizeof(uuid_t)); 1254 memcpy(&head->h_fs_uuid, &mp->m_sb.sb_uuid, sizeof(uuid_t));
1241 1255
1242 1256
@@ -1293,7 +1307,7 @@ xlog_commit_record(xfs_mount_t *mp,
1293 * pushes on an lsn which is further along in the log once we reach the high 1307 * pushes on an lsn which is further along in the log once we reach the high
1294 * water mark. In this manner, we would be creating a low water mark. 1308 * water mark. In this manner, we would be creating a low water mark.
1295 */ 1309 */
1296void 1310STATIC void
1297xlog_grant_push_ail(xfs_mount_t *mp, 1311xlog_grant_push_ail(xfs_mount_t *mp,
1298 int need_bytes) 1312 int need_bytes)
1299{ 1313{
@@ -1305,11 +1319,10 @@ xlog_grant_push_ail(xfs_mount_t *mp,
1305 int threshold_block; /* block in lsn we'd like to be at */ 1319 int threshold_block; /* block in lsn we'd like to be at */
1306 int threshold_cycle; /* lsn cycle we'd like to be at */ 1320 int threshold_cycle; /* lsn cycle we'd like to be at */
1307 int free_threshold; 1321 int free_threshold;
1308 SPLDECL(s);
1309 1322
1310 ASSERT(BTOBB(need_bytes) < log->l_logBBsize); 1323 ASSERT(BTOBB(need_bytes) < log->l_logBBsize);
1311 1324
1312 s = GRANT_LOCK(log); 1325 spin_lock(&log->l_grant_lock);
1313 free_bytes = xlog_space_left(log, 1326 free_bytes = xlog_space_left(log,
1314 log->l_grant_reserve_cycle, 1327 log->l_grant_reserve_cycle,
1315 log->l_grant_reserve_bytes); 1328 log->l_grant_reserve_bytes);
@@ -1331,8 +1344,7 @@ xlog_grant_push_ail(xfs_mount_t *mp,
1331 threshold_block -= log->l_logBBsize; 1344 threshold_block -= log->l_logBBsize;
1332 threshold_cycle += 1; 1345 threshold_cycle += 1;
1333 } 1346 }
1334 ASSIGN_ANY_LSN_HOST(threshold_lsn, threshold_cycle, 1347 threshold_lsn = xlog_assign_lsn(threshold_cycle, threshold_block);
1335 threshold_block);
1336 1348
1337 /* Don't pass in an lsn greater than the lsn of the last 1349 /* Don't pass in an lsn greater than the lsn of the last
1338 * log record known to be on disk. 1350 * log record known to be on disk.
@@ -1340,7 +1352,7 @@ xlog_grant_push_ail(xfs_mount_t *mp,
1340 if (XFS_LSN_CMP(threshold_lsn, log->l_last_sync_lsn) > 0) 1352 if (XFS_LSN_CMP(threshold_lsn, log->l_last_sync_lsn) > 0)
1341 threshold_lsn = log->l_last_sync_lsn; 1353 threshold_lsn = log->l_last_sync_lsn;
1342 } 1354 }
1343 GRANT_UNLOCK(log, s); 1355 spin_unlock(&log->l_grant_lock);
1344 1356
1345 /* 1357 /*
1346 * Get the transaction layer to kick the dirty buffers out to 1358 * Get the transaction layer to kick the dirty buffers out to
@@ -1378,19 +1390,18 @@ xlog_grant_push_ail(xfs_mount_t *mp,
1378 * is added immediately before calling bwrite(). 1390 * is added immediately before calling bwrite().
1379 */ 1391 */
1380 1392
1381int 1393STATIC int
1382xlog_sync(xlog_t *log, 1394xlog_sync(xlog_t *log,
1383 xlog_in_core_t *iclog) 1395 xlog_in_core_t *iclog)
1384{ 1396{
1385 xfs_caddr_t dptr; /* pointer to byte sized element */ 1397 xfs_caddr_t dptr; /* pointer to byte sized element */
1386 xfs_buf_t *bp; 1398 xfs_buf_t *bp;
1387 int i, ops; 1399 int i;
1388 uint count; /* byte count of bwrite */ 1400 uint count; /* byte count of bwrite */
1389 uint count_init; /* initial count before roundup */ 1401 uint count_init; /* initial count before roundup */
1390 int roundoff; /* roundoff to BB or stripe */ 1402 int roundoff; /* roundoff to BB or stripe */
1391 int split = 0; /* split write into two regions */ 1403 int split = 0; /* split write into two regions */
1392 int error; 1404 int error;
1393 SPLDECL(s);
1394 int v2 = XFS_SB_VERSION_HASLOGV2(&log->l_mp->m_sb); 1405 int v2 = XFS_SB_VERSION_HASLOGV2(&log->l_mp->m_sb);
1395 1406
1396 XFS_STATS_INC(xs_log_writes); 1407 XFS_STATS_INC(xs_log_writes);
@@ -1415,30 +1426,26 @@ xlog_sync(xlog_t *log,
1415 roundoff < BBTOB(1))); 1426 roundoff < BBTOB(1)));
1416 1427
1417 /* move grant heads by roundoff in sync */ 1428 /* move grant heads by roundoff in sync */
1418 s = GRANT_LOCK(log); 1429 spin_lock(&log->l_grant_lock);
1419 xlog_grant_add_space(log, roundoff); 1430 xlog_grant_add_space(log, roundoff);
1420 GRANT_UNLOCK(log, s); 1431 spin_unlock(&log->l_grant_lock);
1421 1432
1422 /* put cycle number in every block */ 1433 /* put cycle number in every block */
1423 xlog_pack_data(log, iclog, roundoff); 1434 xlog_pack_data(log, iclog, roundoff);
1424 1435
1425 /* real byte length */ 1436 /* real byte length */
1426 if (v2) { 1437 if (v2) {
1427 INT_SET(iclog->ic_header.h_len, 1438 iclog->ic_header.h_len =
1428 ARCH_CONVERT, 1439 cpu_to_be32(iclog->ic_offset + roundoff);
1429 iclog->ic_offset + roundoff);
1430 } else { 1440 } else {
1431 INT_SET(iclog->ic_header.h_len, ARCH_CONVERT, iclog->ic_offset); 1441 iclog->ic_header.h_len =
1442 cpu_to_be32(iclog->ic_offset);
1432 } 1443 }
1433 1444
1434 /* put ops count in correct order */
1435 ops = iclog->ic_header.h_num_logops;
1436 INT_SET(iclog->ic_header.h_num_logops, ARCH_CONVERT, ops);
1437
1438 bp = iclog->ic_bp; 1445 bp = iclog->ic_bp;
1439 ASSERT(XFS_BUF_FSPRIVATE2(bp, unsigned long) == (unsigned long)1); 1446 ASSERT(XFS_BUF_FSPRIVATE2(bp, unsigned long) == (unsigned long)1);
1440 XFS_BUF_SET_FSPRIVATE2(bp, (unsigned long)2); 1447 XFS_BUF_SET_FSPRIVATE2(bp, (unsigned long)2);
1441 XFS_BUF_SET_ADDR(bp, BLOCK_LSN(INT_GET(iclog->ic_header.h_lsn, ARCH_CONVERT))); 1448 XFS_BUF_SET_ADDR(bp, BLOCK_LSN(be64_to_cpu(iclog->ic_header.h_lsn)));
1442 1449
1443 XFS_STATS_ADD(xs_log_blocks, BTOBB(count)); 1450 XFS_STATS_ADD(xs_log_blocks, BTOBB(count));
1444 1451
@@ -1501,10 +1508,10 @@ xlog_sync(xlog_t *log,
1501 * a new cycle. Watch out for the header magic number 1508 * a new cycle. Watch out for the header magic number
1502 * case, though. 1509 * case, though.
1503 */ 1510 */
1504 for (i=0; i<split; i += BBSIZE) { 1511 for (i = 0; i < split; i += BBSIZE) {
1505 INT_MOD(*(uint *)dptr, ARCH_CONVERT, +1); 1512 be32_add((__be32 *)dptr, 1);
1506 if (INT_GET(*(uint *)dptr, ARCH_CONVERT) == XLOG_HEADER_MAGIC_NUM) 1513 if (be32_to_cpu(*(__be32 *)dptr) == XLOG_HEADER_MAGIC_NUM)
1507 INT_MOD(*(uint *)dptr, ARCH_CONVERT, +1); 1514 be32_add((__be32 *)dptr, 1);
1508 dptr += BBSIZE; 1515 dptr += BBSIZE;
1509 } 1516 }
1510 1517
@@ -1527,14 +1534,13 @@ xlog_sync(xlog_t *log,
1527/* 1534/*
1528 * Deallocate a log structure 1535 * Deallocate a log structure
1529 */ 1536 */
1530void 1537STATIC void
1531xlog_dealloc_log(xlog_t *log) 1538xlog_dealloc_log(xlog_t *log)
1532{ 1539{
1533 xlog_in_core_t *iclog, *next_iclog; 1540 xlog_in_core_t *iclog, *next_iclog;
1534 xlog_ticket_t *tic, *next_tic; 1541 xlog_ticket_t *tic, *next_tic;
1535 int i; 1542 int i;
1536 1543
1537
1538 iclog = log->l_iclog; 1544 iclog = log->l_iclog;
1539 for (i=0; i<log->l_iclog_bufs; i++) { 1545 for (i=0; i<log->l_iclog_bufs; i++) {
1540 sv_destroy(&iclog->ic_forcesema); 1546 sv_destroy(&iclog->ic_forcesema);
@@ -1565,7 +1571,7 @@ xlog_dealloc_log(xlog_t *log)
1565 tic = log->l_unmount_free; 1571 tic = log->l_unmount_free;
1566 while (tic) { 1572 while (tic) {
1567 next_tic = tic->t_next; 1573 next_tic = tic->t_next;
1568 kmem_free(tic, NBPP); 1574 kmem_free(tic, PAGE_SIZE);
1569 tic = next_tic; 1575 tic = next_tic;
1570 } 1576 }
1571 } 1577 }
@@ -1592,14 +1598,12 @@ xlog_state_finish_copy(xlog_t *log,
1592 int record_cnt, 1598 int record_cnt,
1593 int copy_bytes) 1599 int copy_bytes)
1594{ 1600{
1595 SPLDECL(s); 1601 spin_lock(&log->l_icloglock);
1596 1602
1597 s = LOG_LOCK(log); 1603 be32_add(&iclog->ic_header.h_num_logops, record_cnt);
1598
1599 iclog->ic_header.h_num_logops += record_cnt;
1600 iclog->ic_offset += copy_bytes; 1604 iclog->ic_offset += copy_bytes;
1601 1605
1602 LOG_UNLOCK(log, s); 1606 spin_unlock(&log->l_icloglock);
1603} /* xlog_state_finish_copy */ 1607} /* xlog_state_finish_copy */
1604 1608
1605 1609
@@ -1752,7 +1756,7 @@ xlog_print_tic_res(xfs_mount_t *mp, xlog_ticket_t *ticket)
1752 * we don't update ic_offset until the end when we know exactly how many 1756 * we don't update ic_offset until the end when we know exactly how many
1753 * bytes have been written out. 1757 * bytes have been written out.
1754 */ 1758 */
1755int 1759STATIC int
1756xlog_write(xfs_mount_t * mp, 1760xlog_write(xfs_mount_t * mp,
1757 xfs_log_iovec_t reg[], 1761 xfs_log_iovec_t reg[],
1758 int nentries, 1762 int nentries,
@@ -1823,7 +1827,7 @@ xlog_write(xfs_mount_t * mp,
1823 1827
1824 /* start_lsn is the first lsn written to. That's all we need. */ 1828 /* start_lsn is the first lsn written to. That's all we need. */
1825 if (! *start_lsn) 1829 if (! *start_lsn)
1826 *start_lsn = INT_GET(iclog->ic_header.h_lsn, ARCH_CONVERT); 1830 *start_lsn = be64_to_cpu(iclog->ic_header.h_lsn);
1827 1831
1828 /* This loop writes out as many regions as can fit in the amount 1832 /* This loop writes out as many regions as can fit in the amount
1829 * of space which was allocated by xlog_state_get_iclog_space(). 1833 * of space which was allocated by xlog_state_get_iclog_space().
@@ -1839,7 +1843,7 @@ xlog_write(xfs_mount_t * mp,
1839 */ 1843 */
1840 if (ticket->t_flags & XLOG_TIC_INITED) { 1844 if (ticket->t_flags & XLOG_TIC_INITED) {
1841 logop_head = (xlog_op_header_t *)ptr; 1845 logop_head = (xlog_op_header_t *)ptr;
1842 INT_SET(logop_head->oh_tid, ARCH_CONVERT, ticket->t_tid); 1846 logop_head->oh_tid = cpu_to_be32(ticket->t_tid);
1843 logop_head->oh_clientid = ticket->t_clientid; 1847 logop_head->oh_clientid = ticket->t_clientid;
1844 logop_head->oh_len = 0; 1848 logop_head->oh_len = 0;
1845 logop_head->oh_flags = XLOG_START_TRANS; 1849 logop_head->oh_flags = XLOG_START_TRANS;
@@ -1853,7 +1857,7 @@ xlog_write(xfs_mount_t * mp,
1853 1857
1854 /* Copy log operation header directly into data section */ 1858 /* Copy log operation header directly into data section */
1855 logop_head = (xlog_op_header_t *)ptr; 1859 logop_head = (xlog_op_header_t *)ptr;
1856 INT_SET(logop_head->oh_tid, ARCH_CONVERT, ticket->t_tid); 1860 logop_head->oh_tid = cpu_to_be32(ticket->t_tid);
1857 logop_head->oh_clientid = ticket->t_clientid; 1861 logop_head->oh_clientid = ticket->t_clientid;
1858 logop_head->oh_res2 = 0; 1862 logop_head->oh_res2 = 0;
1859 1863
@@ -1888,13 +1892,14 @@ xlog_write(xfs_mount_t * mp,
1888 1892
1889 copy_off = partial_copy_len; 1893 copy_off = partial_copy_len;
1890 if (need_copy <= iclog->ic_size - log_offset) { /*complete write */ 1894 if (need_copy <= iclog->ic_size - log_offset) { /*complete write */
1891 INT_SET(logop_head->oh_len, ARCH_CONVERT, copy_len = need_copy); 1895 copy_len = need_copy;
1896 logop_head->oh_len = cpu_to_be32(copy_len);
1892 if (partial_copy) 1897 if (partial_copy)
1893 logop_head->oh_flags|= (XLOG_END_TRANS|XLOG_WAS_CONT_TRANS); 1898 logop_head->oh_flags|= (XLOG_END_TRANS|XLOG_WAS_CONT_TRANS);
1894 partial_copy_len = partial_copy = 0; 1899 partial_copy_len = partial_copy = 0;
1895 } else { /* partial write */ 1900 } else { /* partial write */
1896 copy_len = iclog->ic_size - log_offset; 1901 copy_len = iclog->ic_size - log_offset;
1897 INT_SET(logop_head->oh_len, ARCH_CONVERT, copy_len); 1902 logop_head->oh_len = cpu_to_be32(copy_len);
1898 logop_head->oh_flags |= XLOG_CONTINUE_TRANS; 1903 logop_head->oh_flags |= XLOG_CONTINUE_TRANS;
1899 if (partial_copy) 1904 if (partial_copy)
1900 logop_head->oh_flags |= XLOG_WAS_CONT_TRANS; 1905 logop_head->oh_flags |= XLOG_WAS_CONT_TRANS;
@@ -1992,7 +1997,8 @@ xlog_state_clean_log(xlog_t *log)
1992 * We don't need to cover the dummy. 1997 * We don't need to cover the dummy.
1993 */ 1998 */
1994 if (!changed && 1999 if (!changed &&
1995 (INT_GET(iclog->ic_header.h_num_logops, ARCH_CONVERT) == XLOG_COVER_OPS)) { 2000 (be32_to_cpu(iclog->ic_header.h_num_logops) ==
2001 XLOG_COVER_OPS)) {
1996 changed = 1; 2002 changed = 1;
1997 } else { 2003 } else {
1998 /* 2004 /*
@@ -2060,7 +2066,7 @@ xlog_get_lowest_lsn(
2060 lowest_lsn = 0; 2066 lowest_lsn = 0;
2061 do { 2067 do {
2062 if (!(lsn_log->ic_state & (XLOG_STATE_ACTIVE|XLOG_STATE_DIRTY))) { 2068 if (!(lsn_log->ic_state & (XLOG_STATE_ACTIVE|XLOG_STATE_DIRTY))) {
2063 lsn = INT_GET(lsn_log->ic_header.h_lsn, ARCH_CONVERT); 2069 lsn = be64_to_cpu(lsn_log->ic_header.h_lsn);
2064 if ((lsn && !lowest_lsn) || 2070 if ((lsn && !lowest_lsn) ||
2065 (XFS_LSN_CMP(lsn, lowest_lsn) < 0)) { 2071 (XFS_LSN_CMP(lsn, lowest_lsn) < 0)) {
2066 lowest_lsn = lsn; 2072 lowest_lsn = lsn;
@@ -2089,9 +2095,8 @@ xlog_state_do_callback(
2089 int funcdidcallbacks; /* flag: function did callbacks */ 2095 int funcdidcallbacks; /* flag: function did callbacks */
2090 int repeats; /* for issuing console warnings if 2096 int repeats; /* for issuing console warnings if
2091 * looping too many times */ 2097 * looping too many times */
2092 SPLDECL(s);
2093 2098
2094 s = LOG_LOCK(log); 2099 spin_lock(&log->l_icloglock);
2095 first_iclog = iclog = log->l_iclog; 2100 first_iclog = iclog = log->l_iclog;
2096 ioerrors = 0; 2101 ioerrors = 0;
2097 funcdidcallbacks = 0; 2102 funcdidcallbacks = 0;
@@ -2136,7 +2141,7 @@ xlog_state_do_callback(
2136 * to DO_CALLBACK, we will not process it when 2141 * to DO_CALLBACK, we will not process it when
2137 * we retry since a previous iclog is in the 2142 * we retry since a previous iclog is in the
2138 * CALLBACK and the state cannot change since 2143 * CALLBACK and the state cannot change since
2139 * we are holding the LOG_LOCK. 2144 * we are holding the l_icloglock.
2140 */ 2145 */
2141 if (!(iclog->ic_state & 2146 if (!(iclog->ic_state &
2142 (XLOG_STATE_DONE_SYNC | 2147 (XLOG_STATE_DONE_SYNC |
@@ -2162,11 +2167,9 @@ xlog_state_do_callback(
2162 */ 2167 */
2163 2168
2164 lowest_lsn = xlog_get_lowest_lsn(log); 2169 lowest_lsn = xlog_get_lowest_lsn(log);
2165 if (lowest_lsn && ( 2170 if (lowest_lsn &&
2166 XFS_LSN_CMP( 2171 XFS_LSN_CMP(lowest_lsn,
2167 lowest_lsn, 2172 be64_to_cpu(iclog->ic_header.h_lsn)) < 0) {
2168 INT_GET(iclog->ic_header.h_lsn, ARCH_CONVERT)
2169 )<0)) {
2170 iclog = iclog->ic_next; 2173 iclog = iclog->ic_next;
2171 continue; /* Leave this iclog for 2174 continue; /* Leave this iclog for
2172 * another thread */ 2175 * another thread */
@@ -2174,19 +2177,18 @@ xlog_state_do_callback(
2174 2177
2175 iclog->ic_state = XLOG_STATE_CALLBACK; 2178 iclog->ic_state = XLOG_STATE_CALLBACK;
2176 2179
2177 LOG_UNLOCK(log, s); 2180 spin_unlock(&log->l_icloglock);
2178 2181
2179 /* l_last_sync_lsn field protected by 2182 /* l_last_sync_lsn field protected by
2180 * GRANT_LOCK. Don't worry about iclog's lsn. 2183 * l_grant_lock. Don't worry about iclog's lsn.
2181 * No one else can be here except us. 2184 * No one else can be here except us.
2182 */ 2185 */
2183 s = GRANT_LOCK(log); 2186 spin_lock(&log->l_grant_lock);
2184 ASSERT(XFS_LSN_CMP( 2187 ASSERT(XFS_LSN_CMP(log->l_last_sync_lsn,
2185 log->l_last_sync_lsn, 2188 be64_to_cpu(iclog->ic_header.h_lsn)) <= 0);
2186 INT_GET(iclog->ic_header.h_lsn, ARCH_CONVERT) 2189 log->l_last_sync_lsn =
2187 )<=0); 2190 be64_to_cpu(iclog->ic_header.h_lsn);
2188 log->l_last_sync_lsn = INT_GET(iclog->ic_header.h_lsn, ARCH_CONVERT); 2191 spin_unlock(&log->l_grant_lock);
2189 GRANT_UNLOCK(log, s);
2190 2192
2191 /* 2193 /*
2192 * Keep processing entries in the callback list 2194 * Keep processing entries in the callback list
@@ -2195,7 +2197,7 @@ xlog_state_do_callback(
2195 * empty and change the state to DIRTY so that 2197 * empty and change the state to DIRTY so that
2196 * we don't miss any more callbacks being added. 2198 * we don't miss any more callbacks being added.
2197 */ 2199 */
2198 s = LOG_LOCK(log); 2200 spin_lock(&log->l_icloglock);
2199 } else { 2201 } else {
2200 ioerrors++; 2202 ioerrors++;
2201 } 2203 }
@@ -2204,14 +2206,14 @@ xlog_state_do_callback(
2204 while (cb) { 2206 while (cb) {
2205 iclog->ic_callback_tail = &(iclog->ic_callback); 2207 iclog->ic_callback_tail = &(iclog->ic_callback);
2206 iclog->ic_callback = NULL; 2208 iclog->ic_callback = NULL;
2207 LOG_UNLOCK(log, s); 2209 spin_unlock(&log->l_icloglock);
2208 2210
2209 /* perform callbacks in the order given */ 2211 /* perform callbacks in the order given */
2210 for (; cb; cb = cb_next) { 2212 for (; cb; cb = cb_next) {
2211 cb_next = cb->cb_next; 2213 cb_next = cb->cb_next;
2212 cb->cb_func(cb->cb_arg, aborted); 2214 cb->cb_func(cb->cb_arg, aborted);
2213 } 2215 }
2214 s = LOG_LOCK(log); 2216 spin_lock(&log->l_icloglock);
2215 cb = iclog->ic_callback; 2217 cb = iclog->ic_callback;
2216 } 2218 }
2217 2219
@@ -2258,7 +2260,7 @@ xlog_state_do_callback(
2258 * 2260 *
2259 * SYNCING - i/o completion will go through logs 2261 * SYNCING - i/o completion will go through logs
2260 * DONE_SYNC - interrupt thread should be waiting for 2262 * DONE_SYNC - interrupt thread should be waiting for
2261 * LOG_LOCK 2263 * l_icloglock
2262 * IOERROR - give up hope all ye who enter here 2264 * IOERROR - give up hope all ye who enter here
2263 */ 2265 */
2264 if (iclog->ic_state == XLOG_STATE_WANT_SYNC || 2266 if (iclog->ic_state == XLOG_STATE_WANT_SYNC ||
@@ -2276,7 +2278,7 @@ xlog_state_do_callback(
2276 flushcnt = log->l_flushcnt; 2278 flushcnt = log->l_flushcnt;
2277 log->l_flushcnt = 0; 2279 log->l_flushcnt = 0;
2278 } 2280 }
2279 LOG_UNLOCK(log, s); 2281 spin_unlock(&log->l_icloglock);
2280 while (flushcnt--) 2282 while (flushcnt--)
2281 vsema(&log->l_flushsema); 2283 vsema(&log->l_flushsema);
2282} /* xlog_state_do_callback */ 2284} /* xlog_state_do_callback */
@@ -2296,15 +2298,14 @@ xlog_state_do_callback(
2296 * global state machine log lock. Assume that the calls to cvsema won't 2298 * global state machine log lock. Assume that the calls to cvsema won't
2297 * take a long time. At least we know it won't sleep. 2299 * take a long time. At least we know it won't sleep.
2298 */ 2300 */
2299void 2301STATIC void
2300xlog_state_done_syncing( 2302xlog_state_done_syncing(
2301 xlog_in_core_t *iclog, 2303 xlog_in_core_t *iclog,
2302 int aborted) 2304 int aborted)
2303{ 2305{
2304 xlog_t *log = iclog->ic_log; 2306 xlog_t *log = iclog->ic_log;
2305 SPLDECL(s);
2306 2307
2307 s = LOG_LOCK(log); 2308 spin_lock(&log->l_icloglock);
2308 2309
2309 ASSERT(iclog->ic_state == XLOG_STATE_SYNCING || 2310 ASSERT(iclog->ic_state == XLOG_STATE_SYNCING ||
2310 iclog->ic_state == XLOG_STATE_IOERROR); 2311 iclog->ic_state == XLOG_STATE_IOERROR);
@@ -2320,7 +2321,7 @@ xlog_state_done_syncing(
2320 */ 2321 */
2321 if (iclog->ic_state != XLOG_STATE_IOERROR) { 2322 if (iclog->ic_state != XLOG_STATE_IOERROR) {
2322 if (--iclog->ic_bwritecnt == 1) { 2323 if (--iclog->ic_bwritecnt == 1) {
2323 LOG_UNLOCK(log, s); 2324 spin_unlock(&log->l_icloglock);
2324 return; 2325 return;
2325 } 2326 }
2326 iclog->ic_state = XLOG_STATE_DONE_SYNC; 2327 iclog->ic_state = XLOG_STATE_DONE_SYNC;
@@ -2332,7 +2333,7 @@ xlog_state_done_syncing(
2332 * I/O, the others get to wait for the result. 2333 * I/O, the others get to wait for the result.
2333 */ 2334 */
2334 sv_broadcast(&iclog->ic_writesema); 2335 sv_broadcast(&iclog->ic_writesema);
2335 LOG_UNLOCK(log, s); 2336 spin_unlock(&log->l_icloglock);
2336 xlog_state_do_callback(log, aborted, iclog); /* also cleans log */ 2337 xlog_state_do_callback(log, aborted, iclog); /* also cleans log */
2337} /* xlog_state_done_syncing */ 2338} /* xlog_state_done_syncing */
2338 2339
@@ -2357,7 +2358,7 @@ xlog_state_done_syncing(
2357 * needs to be incremented, depending on the amount of data which 2358 * needs to be incremented, depending on the amount of data which
2358 * is copied. 2359 * is copied.
2359 */ 2360 */
2360int 2361STATIC int
2361xlog_state_get_iclog_space(xlog_t *log, 2362xlog_state_get_iclog_space(xlog_t *log,
2362 int len, 2363 int len,
2363 xlog_in_core_t **iclogp, 2364 xlog_in_core_t **iclogp,
@@ -2365,23 +2366,22 @@ xlog_state_get_iclog_space(xlog_t *log,
2365 int *continued_write, 2366 int *continued_write,
2366 int *logoffsetp) 2367 int *logoffsetp)
2367{ 2368{
2368 SPLDECL(s);
2369 int log_offset; 2369 int log_offset;
2370 xlog_rec_header_t *head; 2370 xlog_rec_header_t *head;
2371 xlog_in_core_t *iclog; 2371 xlog_in_core_t *iclog;
2372 int error; 2372 int error;
2373 2373
2374restart: 2374restart:
2375 s = LOG_LOCK(log); 2375 spin_lock(&log->l_icloglock);
2376 if (XLOG_FORCED_SHUTDOWN(log)) { 2376 if (XLOG_FORCED_SHUTDOWN(log)) {
2377 LOG_UNLOCK(log, s); 2377 spin_unlock(&log->l_icloglock);
2378 return XFS_ERROR(EIO); 2378 return XFS_ERROR(EIO);
2379 } 2379 }
2380 2380
2381 iclog = log->l_iclog; 2381 iclog = log->l_iclog;
2382 if (! (iclog->ic_state == XLOG_STATE_ACTIVE)) { 2382 if (! (iclog->ic_state == XLOG_STATE_ACTIVE)) {
2383 log->l_flushcnt++; 2383 log->l_flushcnt++;
2384 LOG_UNLOCK(log, s); 2384 spin_unlock(&log->l_icloglock);
2385 xlog_trace_iclog(iclog, XLOG_TRACE_SLEEP_FLUSH); 2385 xlog_trace_iclog(iclog, XLOG_TRACE_SLEEP_FLUSH);
2386 XFS_STATS_INC(xs_log_noiclogs); 2386 XFS_STATS_INC(xs_log_noiclogs);
2387 /* Ensure that log writes happen */ 2387 /* Ensure that log writes happen */
@@ -2404,8 +2404,9 @@ restart:
2404 xlog_tic_add_region(ticket, 2404 xlog_tic_add_region(ticket,
2405 log->l_iclog_hsize, 2405 log->l_iclog_hsize,
2406 XLOG_REG_TYPE_LRHEADER); 2406 XLOG_REG_TYPE_LRHEADER);
2407 INT_SET(head->h_cycle, ARCH_CONVERT, log->l_curr_cycle); 2407 head->h_cycle = cpu_to_be32(log->l_curr_cycle);
2408 ASSIGN_LSN(head->h_lsn, log); 2408 head->h_lsn = cpu_to_be64(
2409 xlog_assign_lsn(log->l_curr_cycle, log->l_curr_block));
2409 ASSERT(log->l_curr_block >= 0); 2410 ASSERT(log->l_curr_block >= 0);
2410 } 2411 }
2411 2412
@@ -2423,12 +2424,12 @@ restart:
2423 2424
2424 /* If I'm the only one writing to this iclog, sync it to disk */ 2425 /* If I'm the only one writing to this iclog, sync it to disk */
2425 if (iclog->ic_refcnt == 1) { 2426 if (iclog->ic_refcnt == 1) {
2426 LOG_UNLOCK(log, s); 2427 spin_unlock(&log->l_icloglock);
2427 if ((error = xlog_state_release_iclog(log, iclog))) 2428 if ((error = xlog_state_release_iclog(log, iclog)))
2428 return error; 2429 return error;
2429 } else { 2430 } else {
2430 iclog->ic_refcnt--; 2431 iclog->ic_refcnt--;
2431 LOG_UNLOCK(log, s); 2432 spin_unlock(&log->l_icloglock);
2432 } 2433 }
2433 goto restart; 2434 goto restart;
2434 } 2435 }
@@ -2449,7 +2450,7 @@ restart:
2449 *iclogp = iclog; 2450 *iclogp = iclog;
2450 2451
2451 ASSERT(iclog->ic_offset <= iclog->ic_size); 2452 ASSERT(iclog->ic_offset <= iclog->ic_size);
2452 LOG_UNLOCK(log, s); 2453 spin_unlock(&log->l_icloglock);
2453 2454
2454 *logoffsetp = log_offset; 2455 *logoffsetp = log_offset;
2455 return 0; 2456 return 0;
@@ -2467,7 +2468,6 @@ xlog_grant_log_space(xlog_t *log,
2467{ 2468{
2468 int free_bytes; 2469 int free_bytes;
2469 int need_bytes; 2470 int need_bytes;
2470 SPLDECL(s);
2471#ifdef DEBUG 2471#ifdef DEBUG
2472 xfs_lsn_t tail_lsn; 2472 xfs_lsn_t tail_lsn;
2473#endif 2473#endif
@@ -2479,7 +2479,7 @@ xlog_grant_log_space(xlog_t *log,
2479#endif 2479#endif
2480 2480
2481 /* Is there space or do we need to sleep? */ 2481 /* Is there space or do we need to sleep? */
2482 s = GRANT_LOCK(log); 2482 spin_lock(&log->l_grant_lock);
2483 xlog_trace_loggrant(log, tic, "xlog_grant_log_space: enter"); 2483 xlog_trace_loggrant(log, tic, "xlog_grant_log_space: enter");
2484 2484
2485 /* something is already sleeping; insert new transaction at end */ 2485 /* something is already sleeping; insert new transaction at end */
@@ -2502,7 +2502,7 @@ xlog_grant_log_space(xlog_t *log,
2502 */ 2502 */
2503 xlog_trace_loggrant(log, tic, 2503 xlog_trace_loggrant(log, tic,
2504 "xlog_grant_log_space: wake 1"); 2504 "xlog_grant_log_space: wake 1");
2505 s = GRANT_LOCK(log); 2505 spin_lock(&log->l_grant_lock);
2506 } 2506 }
2507 if (tic->t_flags & XFS_LOG_PERM_RESERV) 2507 if (tic->t_flags & XFS_LOG_PERM_RESERV)
2508 need_bytes = tic->t_unit_res*tic->t_ocnt; 2508 need_bytes = tic->t_unit_res*tic->t_ocnt;
@@ -2524,14 +2524,14 @@ redo:
2524 sv_wait(&tic->t_sema, PINOD|PLTWAIT, &log->l_grant_lock, s); 2524 sv_wait(&tic->t_sema, PINOD|PLTWAIT, &log->l_grant_lock, s);
2525 2525
2526 if (XLOG_FORCED_SHUTDOWN(log)) { 2526 if (XLOG_FORCED_SHUTDOWN(log)) {
2527 s = GRANT_LOCK(log); 2527 spin_lock(&log->l_grant_lock);
2528 goto error_return; 2528 goto error_return;
2529 } 2529 }
2530 2530
2531 xlog_trace_loggrant(log, tic, 2531 xlog_trace_loggrant(log, tic,
2532 "xlog_grant_log_space: wake 2"); 2532 "xlog_grant_log_space: wake 2");
2533 xlog_grant_push_ail(log->l_mp, need_bytes); 2533 xlog_grant_push_ail(log->l_mp, need_bytes);
2534 s = GRANT_LOCK(log); 2534 spin_lock(&log->l_grant_lock);
2535 goto redo; 2535 goto redo;
2536 } else if (tic->t_flags & XLOG_TIC_IN_Q) 2536 } else if (tic->t_flags & XLOG_TIC_IN_Q)
2537 xlog_del_ticketq(&log->l_reserve_headq, tic); 2537 xlog_del_ticketq(&log->l_reserve_headq, tic);
@@ -2553,7 +2553,7 @@ redo:
2553#endif 2553#endif
2554 xlog_trace_loggrant(log, tic, "xlog_grant_log_space: exit"); 2554 xlog_trace_loggrant(log, tic, "xlog_grant_log_space: exit");
2555 xlog_verify_grant_head(log, 1); 2555 xlog_verify_grant_head(log, 1);
2556 GRANT_UNLOCK(log, s); 2556 spin_unlock(&log->l_grant_lock);
2557 return 0; 2557 return 0;
2558 2558
2559 error_return: 2559 error_return:
@@ -2567,7 +2567,7 @@ redo:
2567 */ 2567 */
2568 tic->t_curr_res = 0; 2568 tic->t_curr_res = 0;
2569 tic->t_cnt = 0; /* ungrant will give back unit_res * t_cnt. */ 2569 tic->t_cnt = 0; /* ungrant will give back unit_res * t_cnt. */
2570 GRANT_UNLOCK(log, s); 2570 spin_unlock(&log->l_grant_lock);
2571 return XFS_ERROR(EIO); 2571 return XFS_ERROR(EIO);
2572} /* xlog_grant_log_space */ 2572} /* xlog_grant_log_space */
2573 2573
@@ -2581,7 +2581,6 @@ STATIC int
2581xlog_regrant_write_log_space(xlog_t *log, 2581xlog_regrant_write_log_space(xlog_t *log,
2582 xlog_ticket_t *tic) 2582 xlog_ticket_t *tic)
2583{ 2583{
2584 SPLDECL(s);
2585 int free_bytes, need_bytes; 2584 int free_bytes, need_bytes;
2586 xlog_ticket_t *ntic; 2585 xlog_ticket_t *ntic;
2587#ifdef DEBUG 2586#ifdef DEBUG
@@ -2599,7 +2598,7 @@ xlog_regrant_write_log_space(xlog_t *log,
2599 panic("regrant Recovery problem"); 2598 panic("regrant Recovery problem");
2600#endif 2599#endif
2601 2600
2602 s = GRANT_LOCK(log); 2601 spin_lock(&log->l_grant_lock);
2603 xlog_trace_loggrant(log, tic, "xlog_regrant_write_log_space: enter"); 2602 xlog_trace_loggrant(log, tic, "xlog_regrant_write_log_space: enter");
2604 2603
2605 if (XLOG_FORCED_SHUTDOWN(log)) 2604 if (XLOG_FORCED_SHUTDOWN(log))
@@ -2638,14 +2637,14 @@ xlog_regrant_write_log_space(xlog_t *log,
2638 /* If we're shutting down, this tic is already 2637 /* If we're shutting down, this tic is already
2639 * off the queue */ 2638 * off the queue */
2640 if (XLOG_FORCED_SHUTDOWN(log)) { 2639 if (XLOG_FORCED_SHUTDOWN(log)) {
2641 s = GRANT_LOCK(log); 2640 spin_lock(&log->l_grant_lock);
2642 goto error_return; 2641 goto error_return;
2643 } 2642 }
2644 2643
2645 xlog_trace_loggrant(log, tic, 2644 xlog_trace_loggrant(log, tic,
2646 "xlog_regrant_write_log_space: wake 1"); 2645 "xlog_regrant_write_log_space: wake 1");
2647 xlog_grant_push_ail(log->l_mp, tic->t_unit_res); 2646 xlog_grant_push_ail(log->l_mp, tic->t_unit_res);
2648 s = GRANT_LOCK(log); 2647 spin_lock(&log->l_grant_lock);
2649 } 2648 }
2650 } 2649 }
2651 2650
@@ -2665,14 +2664,14 @@ redo:
2665 2664
2666 /* If we're shutting down, this tic is already off the queue */ 2665 /* If we're shutting down, this tic is already off the queue */
2667 if (XLOG_FORCED_SHUTDOWN(log)) { 2666 if (XLOG_FORCED_SHUTDOWN(log)) {
2668 s = GRANT_LOCK(log); 2667 spin_lock(&log->l_grant_lock);
2669 goto error_return; 2668 goto error_return;
2670 } 2669 }
2671 2670
2672 xlog_trace_loggrant(log, tic, 2671 xlog_trace_loggrant(log, tic,
2673 "xlog_regrant_write_log_space: wake 2"); 2672 "xlog_regrant_write_log_space: wake 2");
2674 xlog_grant_push_ail(log->l_mp, need_bytes); 2673 xlog_grant_push_ail(log->l_mp, need_bytes);
2675 s = GRANT_LOCK(log); 2674 spin_lock(&log->l_grant_lock);
2676 goto redo; 2675 goto redo;
2677 } else if (tic->t_flags & XLOG_TIC_IN_Q) 2676 } else if (tic->t_flags & XLOG_TIC_IN_Q)
2678 xlog_del_ticketq(&log->l_write_headq, tic); 2677 xlog_del_ticketq(&log->l_write_headq, tic);
@@ -2689,7 +2688,7 @@ redo:
2689 2688
2690 xlog_trace_loggrant(log, tic, "xlog_regrant_write_log_space: exit"); 2689 xlog_trace_loggrant(log, tic, "xlog_regrant_write_log_space: exit");
2691 xlog_verify_grant_head(log, 1); 2690 xlog_verify_grant_head(log, 1);
2692 GRANT_UNLOCK(log, s); 2691 spin_unlock(&log->l_grant_lock);
2693 return 0; 2692 return 0;
2694 2693
2695 2694
@@ -2704,7 +2703,7 @@ redo:
2704 */ 2703 */
2705 tic->t_curr_res = 0; 2704 tic->t_curr_res = 0;
2706 tic->t_cnt = 0; /* ungrant will give back unit_res * t_cnt. */ 2705 tic->t_cnt = 0; /* ungrant will give back unit_res * t_cnt. */
2707 GRANT_UNLOCK(log, s); 2706 spin_unlock(&log->l_grant_lock);
2708 return XFS_ERROR(EIO); 2707 return XFS_ERROR(EIO);
2709} /* xlog_regrant_write_log_space */ 2708} /* xlog_regrant_write_log_space */
2710 2709
@@ -2720,14 +2719,12 @@ STATIC void
2720xlog_regrant_reserve_log_space(xlog_t *log, 2719xlog_regrant_reserve_log_space(xlog_t *log,
2721 xlog_ticket_t *ticket) 2720 xlog_ticket_t *ticket)
2722{ 2721{
2723 SPLDECL(s);
2724
2725 xlog_trace_loggrant(log, ticket, 2722 xlog_trace_loggrant(log, ticket,
2726 "xlog_regrant_reserve_log_space: enter"); 2723 "xlog_regrant_reserve_log_space: enter");
2727 if (ticket->t_cnt > 0) 2724 if (ticket->t_cnt > 0)
2728 ticket->t_cnt--; 2725 ticket->t_cnt--;
2729 2726
2730 s = GRANT_LOCK(log); 2727 spin_lock(&log->l_grant_lock);
2731 xlog_grant_sub_space(log, ticket->t_curr_res); 2728 xlog_grant_sub_space(log, ticket->t_curr_res);
2732 ticket->t_curr_res = ticket->t_unit_res; 2729 ticket->t_curr_res = ticket->t_unit_res;
2733 xlog_tic_reset_res(ticket); 2730 xlog_tic_reset_res(ticket);
@@ -2737,7 +2734,7 @@ xlog_regrant_reserve_log_space(xlog_t *log,
2737 2734
2738 /* just return if we still have some of the pre-reserved space */ 2735 /* just return if we still have some of the pre-reserved space */
2739 if (ticket->t_cnt > 0) { 2736 if (ticket->t_cnt > 0) {
2740 GRANT_UNLOCK(log, s); 2737 spin_unlock(&log->l_grant_lock);
2741 return; 2738 return;
2742 } 2739 }
2743 2740
@@ -2745,7 +2742,7 @@ xlog_regrant_reserve_log_space(xlog_t *log,
2745 xlog_trace_loggrant(log, ticket, 2742 xlog_trace_loggrant(log, ticket,
2746 "xlog_regrant_reserve_log_space: exit"); 2743 "xlog_regrant_reserve_log_space: exit");
2747 xlog_verify_grant_head(log, 0); 2744 xlog_verify_grant_head(log, 0);
2748 GRANT_UNLOCK(log, s); 2745 spin_unlock(&log->l_grant_lock);
2749 ticket->t_curr_res = ticket->t_unit_res; 2746 ticket->t_curr_res = ticket->t_unit_res;
2750 xlog_tic_reset_res(ticket); 2747 xlog_tic_reset_res(ticket);
2751} /* xlog_regrant_reserve_log_space */ 2748} /* xlog_regrant_reserve_log_space */
@@ -2769,12 +2766,10 @@ STATIC void
2769xlog_ungrant_log_space(xlog_t *log, 2766xlog_ungrant_log_space(xlog_t *log,
2770 xlog_ticket_t *ticket) 2767 xlog_ticket_t *ticket)
2771{ 2768{
2772 SPLDECL(s);
2773
2774 if (ticket->t_cnt > 0) 2769 if (ticket->t_cnt > 0)
2775 ticket->t_cnt--; 2770 ticket->t_cnt--;
2776 2771
2777 s = GRANT_LOCK(log); 2772 spin_lock(&log->l_grant_lock);
2778 xlog_trace_loggrant(log, ticket, "xlog_ungrant_log_space: enter"); 2773 xlog_trace_loggrant(log, ticket, "xlog_ungrant_log_space: enter");
2779 2774
2780 xlog_grant_sub_space(log, ticket->t_curr_res); 2775 xlog_grant_sub_space(log, ticket->t_curr_res);
@@ -2791,7 +2786,7 @@ xlog_ungrant_log_space(xlog_t *log,
2791 2786
2792 xlog_trace_loggrant(log, ticket, "xlog_ungrant_log_space: exit"); 2787 xlog_trace_loggrant(log, ticket, "xlog_ungrant_log_space: exit");
2793 xlog_verify_grant_head(log, 1); 2788 xlog_verify_grant_head(log, 1);
2794 GRANT_UNLOCK(log, s); 2789 spin_unlock(&log->l_grant_lock);
2795 xfs_log_move_tail(log->l_mp, 1); 2790 xfs_log_move_tail(log->l_mp, 1);
2796} /* xlog_ungrant_log_space */ 2791} /* xlog_ungrant_log_space */
2797 2792
@@ -2799,15 +2794,13 @@ xlog_ungrant_log_space(xlog_t *log,
2799/* 2794/*
2800 * Atomically put back used ticket. 2795 * Atomically put back used ticket.
2801 */ 2796 */
2802void 2797STATIC void
2803xlog_state_put_ticket(xlog_t *log, 2798xlog_state_put_ticket(xlog_t *log,
2804 xlog_ticket_t *tic) 2799 xlog_ticket_t *tic)
2805{ 2800{
2806 unsigned long s; 2801 spin_lock(&log->l_icloglock);
2807
2808 s = LOG_LOCK(log);
2809 xlog_ticket_put(log, tic); 2802 xlog_ticket_put(log, tic);
2810 LOG_UNLOCK(log, s); 2803 spin_unlock(&log->l_icloglock);
2811} /* xlog_state_put_ticket */ 2804} /* xlog_state_put_ticket */
2812 2805
2813/* 2806/*
@@ -2819,19 +2812,18 @@ xlog_state_put_ticket(xlog_t *log,
2819 * 2812 *
2820 * 2813 *
2821 */ 2814 */
2822int 2815STATIC int
2823xlog_state_release_iclog(xlog_t *log, 2816xlog_state_release_iclog(xlog_t *log,
2824 xlog_in_core_t *iclog) 2817 xlog_in_core_t *iclog)
2825{ 2818{
2826 SPLDECL(s);
2827 int sync = 0; /* do we sync? */ 2819 int sync = 0; /* do we sync? */
2828 2820
2829 xlog_assign_tail_lsn(log->l_mp); 2821 xlog_assign_tail_lsn(log->l_mp);
2830 2822
2831 s = LOG_LOCK(log); 2823 spin_lock(&log->l_icloglock);
2832 2824
2833 if (iclog->ic_state & XLOG_STATE_IOERROR) { 2825 if (iclog->ic_state & XLOG_STATE_IOERROR) {
2834 LOG_UNLOCK(log, s); 2826 spin_unlock(&log->l_icloglock);
2835 return XFS_ERROR(EIO); 2827 return XFS_ERROR(EIO);
2836 } 2828 }
2837 2829
@@ -2843,12 +2835,12 @@ xlog_state_release_iclog(xlog_t *log,
2843 iclog->ic_state == XLOG_STATE_WANT_SYNC) { 2835 iclog->ic_state == XLOG_STATE_WANT_SYNC) {
2844 sync++; 2836 sync++;
2845 iclog->ic_state = XLOG_STATE_SYNCING; 2837 iclog->ic_state = XLOG_STATE_SYNCING;
2846 INT_SET(iclog->ic_header.h_tail_lsn, ARCH_CONVERT, log->l_tail_lsn); 2838 iclog->ic_header.h_tail_lsn = cpu_to_be64(log->l_tail_lsn);
2847 xlog_verify_tail_lsn(log, iclog, log->l_tail_lsn); 2839 xlog_verify_tail_lsn(log, iclog, log->l_tail_lsn);
2848 /* cycle incremented when incrementing curr_block */ 2840 /* cycle incremented when incrementing curr_block */
2849 } 2841 }
2850 2842
2851 LOG_UNLOCK(log, s); 2843 spin_unlock(&log->l_icloglock);
2852 2844
2853 /* 2845 /*
2854 * We let the log lock go, so it's possible that we hit a log I/O 2846 * We let the log lock go, so it's possible that we hit a log I/O
@@ -2881,7 +2873,7 @@ xlog_state_switch_iclogs(xlog_t *log,
2881 if (!eventual_size) 2873 if (!eventual_size)
2882 eventual_size = iclog->ic_offset; 2874 eventual_size = iclog->ic_offset;
2883 iclog->ic_state = XLOG_STATE_WANT_SYNC; 2875 iclog->ic_state = XLOG_STATE_WANT_SYNC;
2884 INT_SET(iclog->ic_header.h_prev_block, ARCH_CONVERT, log->l_prev_block); 2876 iclog->ic_header.h_prev_block = cpu_to_be32(log->l_prev_block);
2885 log->l_prev_block = log->l_curr_block; 2877 log->l_prev_block = log->l_curr_block;
2886 log->l_prev_cycle = log->l_curr_cycle; 2878 log->l_prev_cycle = log->l_curr_cycle;
2887 2879
@@ -2939,13 +2931,12 @@ xlog_state_sync_all(xlog_t *log, uint flags, int *log_flushed)
2939{ 2931{
2940 xlog_in_core_t *iclog; 2932 xlog_in_core_t *iclog;
2941 xfs_lsn_t lsn; 2933 xfs_lsn_t lsn;
2942 SPLDECL(s);
2943 2934
2944 s = LOG_LOCK(log); 2935 spin_lock(&log->l_icloglock);
2945 2936
2946 iclog = log->l_iclog; 2937 iclog = log->l_iclog;
2947 if (iclog->ic_state & XLOG_STATE_IOERROR) { 2938 if (iclog->ic_state & XLOG_STATE_IOERROR) {
2948 LOG_UNLOCK(log, s); 2939 spin_unlock(&log->l_icloglock);
2949 return XFS_ERROR(EIO); 2940 return XFS_ERROR(EIO);
2950 } 2941 }
2951 2942
@@ -2978,15 +2969,15 @@ xlog_state_sync_all(xlog_t *log, uint flags, int *log_flushed)
2978 * the previous sync. 2969 * the previous sync.
2979 */ 2970 */
2980 iclog->ic_refcnt++; 2971 iclog->ic_refcnt++;
2981 lsn = INT_GET(iclog->ic_header.h_lsn, ARCH_CONVERT); 2972 lsn = be64_to_cpu(iclog->ic_header.h_lsn);
2982 xlog_state_switch_iclogs(log, iclog, 0); 2973 xlog_state_switch_iclogs(log, iclog, 0);
2983 LOG_UNLOCK(log, s); 2974 spin_unlock(&log->l_icloglock);
2984 2975
2985 if (xlog_state_release_iclog(log, iclog)) 2976 if (xlog_state_release_iclog(log, iclog))
2986 return XFS_ERROR(EIO); 2977 return XFS_ERROR(EIO);
2987 *log_flushed = 1; 2978 *log_flushed = 1;
2988 s = LOG_LOCK(log); 2979 spin_lock(&log->l_icloglock);
2989 if (INT_GET(iclog->ic_header.h_lsn, ARCH_CONVERT) == lsn && 2980 if (be64_to_cpu(iclog->ic_header.h_lsn) == lsn &&
2990 iclog->ic_state != XLOG_STATE_DIRTY) 2981 iclog->ic_state != XLOG_STATE_DIRTY)
2991 goto maybe_sleep; 2982 goto maybe_sleep;
2992 else 2983 else
@@ -3011,12 +3002,12 @@ maybe_sleep:
3011 if (flags & XFS_LOG_SYNC) { 3002 if (flags & XFS_LOG_SYNC) {
3012 /* 3003 /*
3013 * We must check if we're shutting down here, before 3004 * We must check if we're shutting down here, before
3014 * we wait, while we're holding the LOG_LOCK. 3005 * we wait, while we're holding the l_icloglock.
3015 * Then we check again after waking up, in case our 3006 * Then we check again after waking up, in case our
3016 * sleep was disturbed by a bad news. 3007 * sleep was disturbed by a bad news.
3017 */ 3008 */
3018 if (iclog->ic_state & XLOG_STATE_IOERROR) { 3009 if (iclog->ic_state & XLOG_STATE_IOERROR) {
3019 LOG_UNLOCK(log, s); 3010 spin_unlock(&log->l_icloglock);
3020 return XFS_ERROR(EIO); 3011 return XFS_ERROR(EIO);
3021 } 3012 }
3022 XFS_STATS_INC(xs_log_force_sleep); 3013 XFS_STATS_INC(xs_log_force_sleep);
@@ -3033,7 +3024,7 @@ maybe_sleep:
3033 } else { 3024 } else {
3034 3025
3035no_sleep: 3026no_sleep:
3036 LOG_UNLOCK(log, s); 3027 spin_unlock(&log->l_icloglock);
3037 } 3028 }
3038 return 0; 3029 return 0;
3039} /* xlog_state_sync_all */ 3030} /* xlog_state_sync_all */
@@ -3051,7 +3042,7 @@ no_sleep:
3051 * If filesystem activity goes to zero, the iclog will get flushed only by 3042 * If filesystem activity goes to zero, the iclog will get flushed only by
3052 * bdflush(). 3043 * bdflush().
3053 */ 3044 */
3054int 3045STATIC int
3055xlog_state_sync(xlog_t *log, 3046xlog_state_sync(xlog_t *log,
3056 xfs_lsn_t lsn, 3047 xfs_lsn_t lsn,
3057 uint flags, 3048 uint flags,
@@ -3059,26 +3050,24 @@ xlog_state_sync(xlog_t *log,
3059{ 3050{
3060 xlog_in_core_t *iclog; 3051 xlog_in_core_t *iclog;
3061 int already_slept = 0; 3052 int already_slept = 0;
3062 SPLDECL(s);
3063
3064 3053
3065try_again: 3054try_again:
3066 s = LOG_LOCK(log); 3055 spin_lock(&log->l_icloglock);
3067 iclog = log->l_iclog; 3056 iclog = log->l_iclog;
3068 3057
3069 if (iclog->ic_state & XLOG_STATE_IOERROR) { 3058 if (iclog->ic_state & XLOG_STATE_IOERROR) {
3070 LOG_UNLOCK(log, s); 3059 spin_unlock(&log->l_icloglock);
3071 return XFS_ERROR(EIO); 3060 return XFS_ERROR(EIO);
3072 } 3061 }
3073 3062
3074 do { 3063 do {
3075 if (INT_GET(iclog->ic_header.h_lsn, ARCH_CONVERT) != lsn) { 3064 if (be64_to_cpu(iclog->ic_header.h_lsn) != lsn) {
3076 iclog = iclog->ic_next; 3065 iclog = iclog->ic_next;
3077 continue; 3066 continue;
3078 } 3067 }
3079 3068
3080 if (iclog->ic_state == XLOG_STATE_DIRTY) { 3069 if (iclog->ic_state == XLOG_STATE_DIRTY) {
3081 LOG_UNLOCK(log, s); 3070 spin_unlock(&log->l_icloglock);
3082 return 0; 3071 return 0;
3083 } 3072 }
3084 3073
@@ -3113,11 +3102,11 @@ try_again:
3113 } else { 3102 } else {
3114 iclog->ic_refcnt++; 3103 iclog->ic_refcnt++;
3115 xlog_state_switch_iclogs(log, iclog, 0); 3104 xlog_state_switch_iclogs(log, iclog, 0);
3116 LOG_UNLOCK(log, s); 3105 spin_unlock(&log->l_icloglock);
3117 if (xlog_state_release_iclog(log, iclog)) 3106 if (xlog_state_release_iclog(log, iclog))
3118 return XFS_ERROR(EIO); 3107 return XFS_ERROR(EIO);
3119 *log_flushed = 1; 3108 *log_flushed = 1;
3120 s = LOG_LOCK(log); 3109 spin_lock(&log->l_icloglock);
3121 } 3110 }
3122 } 3111 }
3123 3112
@@ -3129,7 +3118,7 @@ try_again:
3129 * gotten a log write error. 3118 * gotten a log write error.
3130 */ 3119 */
3131 if (iclog->ic_state & XLOG_STATE_IOERROR) { 3120 if (iclog->ic_state & XLOG_STATE_IOERROR) {
3132 LOG_UNLOCK(log, s); 3121 spin_unlock(&log->l_icloglock);
3133 return XFS_ERROR(EIO); 3122 return XFS_ERROR(EIO);
3134 } 3123 }
3135 XFS_STATS_INC(xs_log_force_sleep); 3124 XFS_STATS_INC(xs_log_force_sleep);
@@ -3143,13 +3132,13 @@ try_again:
3143 return XFS_ERROR(EIO); 3132 return XFS_ERROR(EIO);
3144 *log_flushed = 1; 3133 *log_flushed = 1;
3145 } else { /* just return */ 3134 } else { /* just return */
3146 LOG_UNLOCK(log, s); 3135 spin_unlock(&log->l_icloglock);
3147 } 3136 }
3148 return 0; 3137 return 0;
3149 3138
3150 } while (iclog != log->l_iclog); 3139 } while (iclog != log->l_iclog);
3151 3140
3152 LOG_UNLOCK(log, s); 3141 spin_unlock(&log->l_icloglock);
3153 return 0; 3142 return 0;
3154} /* xlog_state_sync */ 3143} /* xlog_state_sync */
3155 3144
@@ -3158,12 +3147,10 @@ try_again:
3158 * Called when we want to mark the current iclog as being ready to sync to 3147 * Called when we want to mark the current iclog as being ready to sync to
3159 * disk. 3148 * disk.
3160 */ 3149 */
3161void 3150STATIC void
3162xlog_state_want_sync(xlog_t *log, xlog_in_core_t *iclog) 3151xlog_state_want_sync(xlog_t *log, xlog_in_core_t *iclog)
3163{ 3152{
3164 SPLDECL(s); 3153 spin_lock(&log->l_icloglock);
3165
3166 s = LOG_LOCK(log);
3167 3154
3168 if (iclog->ic_state == XLOG_STATE_ACTIVE) { 3155 if (iclog->ic_state == XLOG_STATE_ACTIVE) {
3169 xlog_state_switch_iclogs(log, iclog, 0); 3156 xlog_state_switch_iclogs(log, iclog, 0);
@@ -3172,7 +3159,7 @@ xlog_state_want_sync(xlog_t *log, xlog_in_core_t *iclog)
3172 (XLOG_STATE_WANT_SYNC|XLOG_STATE_IOERROR)); 3159 (XLOG_STATE_WANT_SYNC|XLOG_STATE_IOERROR));
3173 } 3160 }
3174 3161
3175 LOG_UNLOCK(log, s); 3162 spin_unlock(&log->l_icloglock);
3176} /* xlog_state_want_sync */ 3163} /* xlog_state_want_sync */
3177 3164
3178 3165
@@ -3193,16 +3180,15 @@ xlog_state_ticket_alloc(xlog_t *log)
3193 xlog_ticket_t *t_list; 3180 xlog_ticket_t *t_list;
3194 xlog_ticket_t *next; 3181 xlog_ticket_t *next;
3195 xfs_caddr_t buf; 3182 xfs_caddr_t buf;
3196 uint i = (NBPP / sizeof(xlog_ticket_t)) - 2; 3183 uint i = (PAGE_SIZE / sizeof(xlog_ticket_t)) - 2;
3197 SPLDECL(s);
3198 3184
3199 /* 3185 /*
3200 * The kmem_zalloc may sleep, so we shouldn't be holding the 3186 * The kmem_zalloc may sleep, so we shouldn't be holding the
3201 * global lock. XXXmiken: may want to use zone allocator. 3187 * global lock. XXXmiken: may want to use zone allocator.
3202 */ 3188 */
3203 buf = (xfs_caddr_t) kmem_zalloc(NBPP, KM_SLEEP); 3189 buf = (xfs_caddr_t) kmem_zalloc(PAGE_SIZE, KM_SLEEP);
3204 3190
3205 s = LOG_LOCK(log); 3191 spin_lock(&log->l_icloglock);
3206 3192
3207 /* Attach 1st ticket to Q, so we can keep track of allocated memory */ 3193 /* Attach 1st ticket to Q, so we can keep track of allocated memory */
3208 t_list = (xlog_ticket_t *)buf; 3194 t_list = (xlog_ticket_t *)buf;
@@ -3231,7 +3217,7 @@ xlog_state_ticket_alloc(xlog_t *log)
3231 } 3217 }
3232 t_list->t_next = NULL; 3218 t_list->t_next = NULL;
3233 log->l_tail = t_list; 3219 log->l_tail = t_list;
3234 LOG_UNLOCK(log, s); 3220 spin_unlock(&log->l_icloglock);
3235} /* xlog_state_ticket_alloc */ 3221} /* xlog_state_ticket_alloc */
3236 3222
3237 3223
@@ -3273,7 +3259,7 @@ xlog_ticket_put(xlog_t *log,
3273/* 3259/*
3274 * Grab ticket off freelist or allocation some more 3260 * Grab ticket off freelist or allocation some more
3275 */ 3261 */
3276xlog_ticket_t * 3262STATIC xlog_ticket_t *
3277xlog_ticket_get(xlog_t *log, 3263xlog_ticket_get(xlog_t *log,
3278 int unit_bytes, 3264 int unit_bytes,
3279 int cnt, 3265 int cnt,
@@ -3282,15 +3268,14 @@ xlog_ticket_get(xlog_t *log,
3282{ 3268{
3283 xlog_ticket_t *tic; 3269 xlog_ticket_t *tic;
3284 uint num_headers; 3270 uint num_headers;
3285 SPLDECL(s);
3286 3271
3287 alloc: 3272 alloc:
3288 if (log->l_freelist == NULL) 3273 if (log->l_freelist == NULL)
3289 xlog_state_ticket_alloc(log); /* potentially sleep */ 3274 xlog_state_ticket_alloc(log); /* potentially sleep */
3290 3275
3291 s = LOG_LOCK(log); 3276 spin_lock(&log->l_icloglock);
3292 if (log->l_freelist == NULL) { 3277 if (log->l_freelist == NULL) {
3293 LOG_UNLOCK(log, s); 3278 spin_unlock(&log->l_icloglock);
3294 goto alloc; 3279 goto alloc;
3295 } 3280 }
3296 tic = log->l_freelist; 3281 tic = log->l_freelist;
@@ -3298,7 +3283,7 @@ xlog_ticket_get(xlog_t *log,
3298 if (log->l_freelist == NULL) 3283 if (log->l_freelist == NULL)
3299 log->l_tail = NULL; 3284 log->l_tail = NULL;
3300 log->l_ticket_cnt--; 3285 log->l_ticket_cnt--;
3301 LOG_UNLOCK(log, s); 3286 spin_unlock(&log->l_icloglock);
3302 3287
3303 /* 3288 /*
3304 * Permanent reservations have up to 'cnt'-1 active log operations 3289 * Permanent reservations have up to 'cnt'-1 active log operations
@@ -3473,10 +3458,9 @@ xlog_verify_iclog(xlog_t *log,
3473 __uint8_t clientid; 3458 __uint8_t clientid;
3474 int len, i, j, k, op_len; 3459 int len, i, j, k, op_len;
3475 int idx; 3460 int idx;
3476 SPLDECL(s);
3477 3461
3478 /* check validity of iclog pointers */ 3462 /* check validity of iclog pointers */
3479 s = LOG_LOCK(log); 3463 spin_lock(&log->l_icloglock);
3480 icptr = log->l_iclog; 3464 icptr = log->l_iclog;
3481 for (i=0; i < log->l_iclog_bufs; i++) { 3465 for (i=0; i < log->l_iclog_bufs; i++) {
3482 if (icptr == NULL) 3466 if (icptr == NULL)
@@ -3485,21 +3469,21 @@ xlog_verify_iclog(xlog_t *log,
3485 } 3469 }
3486 if (icptr != log->l_iclog) 3470 if (icptr != log->l_iclog)
3487 xlog_panic("xlog_verify_iclog: corrupt iclog ring"); 3471 xlog_panic("xlog_verify_iclog: corrupt iclog ring");
3488 LOG_UNLOCK(log, s); 3472 spin_unlock(&log->l_icloglock);
3489 3473
3490 /* check log magic numbers */ 3474 /* check log magic numbers */
3491 ptr = (xfs_caddr_t) &(iclog->ic_header); 3475 if (be32_to_cpu(iclog->ic_header.h_magicno) != XLOG_HEADER_MAGIC_NUM)
3492 if (INT_GET(*(uint *)ptr, ARCH_CONVERT) != XLOG_HEADER_MAGIC_NUM)
3493 xlog_panic("xlog_verify_iclog: invalid magic num"); 3476 xlog_panic("xlog_verify_iclog: invalid magic num");
3494 3477
3495 for (ptr += BBSIZE; ptr < ((xfs_caddr_t)&(iclog->ic_header))+count; 3478 ptr = (xfs_caddr_t) &iclog->ic_header;
3479 for (ptr += BBSIZE; ptr < ((xfs_caddr_t)&iclog->ic_header) + count;
3496 ptr += BBSIZE) { 3480 ptr += BBSIZE) {
3497 if (INT_GET(*(uint *)ptr, ARCH_CONVERT) == XLOG_HEADER_MAGIC_NUM) 3481 if (be32_to_cpu(*(__be32 *)ptr) == XLOG_HEADER_MAGIC_NUM)
3498 xlog_panic("xlog_verify_iclog: unexpected magic num"); 3482 xlog_panic("xlog_verify_iclog: unexpected magic num");
3499 } 3483 }
3500 3484
3501 /* check fields */ 3485 /* check fields */
3502 len = INT_GET(iclog->ic_header.h_num_logops, ARCH_CONVERT); 3486 len = be32_to_cpu(iclog->ic_header.h_num_logops);
3503 ptr = iclog->ic_datap; 3487 ptr = iclog->ic_datap;
3504 base_ptr = ptr; 3488 base_ptr = ptr;
3505 ophead = (xlog_op_header_t *)ptr; 3489 ophead = (xlog_op_header_t *)ptr;
@@ -3517,9 +3501,11 @@ xlog_verify_iclog(xlog_t *log,
3517 if (idx >= (XLOG_HEADER_CYCLE_SIZE / BBSIZE)) { 3501 if (idx >= (XLOG_HEADER_CYCLE_SIZE / BBSIZE)) {
3518 j = idx / (XLOG_HEADER_CYCLE_SIZE / BBSIZE); 3502 j = idx / (XLOG_HEADER_CYCLE_SIZE / BBSIZE);
3519 k = idx % (XLOG_HEADER_CYCLE_SIZE / BBSIZE); 3503 k = idx % (XLOG_HEADER_CYCLE_SIZE / BBSIZE);
3520 clientid = GET_CLIENT_ID(xhdr[j].hic_xheader.xh_cycle_data[k], ARCH_CONVERT); 3504 clientid = xlog_get_client_id(
3505 xhdr[j].hic_xheader.xh_cycle_data[k]);
3521 } else { 3506 } else {
3522 clientid = GET_CLIENT_ID(iclog->ic_header.h_cycle_data[idx], ARCH_CONVERT); 3507 clientid = xlog_get_client_id(
3508 iclog->ic_header.h_cycle_data[idx]);
3523 } 3509 }
3524 } 3510 }
3525 if (clientid != XFS_TRANSACTION && clientid != XFS_LOG) 3511 if (clientid != XFS_TRANSACTION && clientid != XFS_LOG)
@@ -3531,16 +3517,16 @@ xlog_verify_iclog(xlog_t *log,
3531 field_offset = (__psint_t) 3517 field_offset = (__psint_t)
3532 ((xfs_caddr_t)&(ophead->oh_len) - base_ptr); 3518 ((xfs_caddr_t)&(ophead->oh_len) - base_ptr);
3533 if (syncing == B_FALSE || (field_offset & 0x1ff)) { 3519 if (syncing == B_FALSE || (field_offset & 0x1ff)) {
3534 op_len = INT_GET(ophead->oh_len, ARCH_CONVERT); 3520 op_len = be32_to_cpu(ophead->oh_len);
3535 } else { 3521 } else {
3536 idx = BTOBBT((__psint_t)&ophead->oh_len - 3522 idx = BTOBBT((__psint_t)&ophead->oh_len -
3537 (__psint_t)iclog->ic_datap); 3523 (__psint_t)iclog->ic_datap);
3538 if (idx >= (XLOG_HEADER_CYCLE_SIZE / BBSIZE)) { 3524 if (idx >= (XLOG_HEADER_CYCLE_SIZE / BBSIZE)) {
3539 j = idx / (XLOG_HEADER_CYCLE_SIZE / BBSIZE); 3525 j = idx / (XLOG_HEADER_CYCLE_SIZE / BBSIZE);
3540 k = idx % (XLOG_HEADER_CYCLE_SIZE / BBSIZE); 3526 k = idx % (XLOG_HEADER_CYCLE_SIZE / BBSIZE);
3541 op_len = INT_GET(xhdr[j].hic_xheader.xh_cycle_data[k], ARCH_CONVERT); 3527 op_len = be32_to_cpu(xhdr[j].hic_xheader.xh_cycle_data[k]);
3542 } else { 3528 } else {
3543 op_len = INT_GET(iclog->ic_header.h_cycle_data[idx], ARCH_CONVERT); 3529 op_len = be32_to_cpu(iclog->ic_header.h_cycle_data[idx]);
3544 } 3530 }
3545 } 3531 }
3546 ptr += sizeof(xlog_op_header_t) + op_len; 3532 ptr += sizeof(xlog_op_header_t) + op_len;
@@ -3549,7 +3535,7 @@ xlog_verify_iclog(xlog_t *log,
3549#endif 3535#endif
3550 3536
3551/* 3537/*
3552 * Mark all iclogs IOERROR. LOG_LOCK is held by the caller. 3538 * Mark all iclogs IOERROR. l_icloglock is held by the caller.
3553 */ 3539 */
3554STATIC int 3540STATIC int
3555xlog_state_ioerror( 3541xlog_state_ioerror(
@@ -3597,8 +3583,6 @@ xfs_log_force_umount(
3597 xlog_t *log; 3583 xlog_t *log;
3598 int retval; 3584 int retval;
3599 int dummy; 3585 int dummy;
3600 SPLDECL(s);
3601 SPLDECL(s2);
3602 3586
3603 log = mp->m_log; 3587 log = mp->m_log;
3604 3588
@@ -3627,8 +3611,8 @@ xfs_log_force_umount(
3627 * before we mark the filesystem SHUTDOWN and wake 3611 * before we mark the filesystem SHUTDOWN and wake
3628 * everybody up to tell the bad news. 3612 * everybody up to tell the bad news.
3629 */ 3613 */
3630 s = GRANT_LOCK(log); 3614 spin_lock(&log->l_grant_lock);
3631 s2 = LOG_LOCK(log); 3615 spin_lock(&log->l_icloglock);
3632 mp->m_flags |= XFS_MOUNT_FS_SHUTDOWN; 3616 mp->m_flags |= XFS_MOUNT_FS_SHUTDOWN;
3633 XFS_BUF_DONE(mp->m_sb_bp); 3617 XFS_BUF_DONE(mp->m_sb_bp);
3634 /* 3618 /*
@@ -3644,7 +3628,7 @@ xfs_log_force_umount(
3644 */ 3628 */
3645 if (logerror) 3629 if (logerror)
3646 retval = xlog_state_ioerror(log); 3630 retval = xlog_state_ioerror(log);
3647 LOG_UNLOCK(log, s2); 3631 spin_unlock(&log->l_icloglock);
3648 3632
3649 /* 3633 /*
3650 * We don't want anybody waiting for log reservations 3634 * We don't want anybody waiting for log reservations
@@ -3667,7 +3651,7 @@ xfs_log_force_umount(
3667 tic = tic->t_next; 3651 tic = tic->t_next;
3668 } while (tic != log->l_write_headq); 3652 } while (tic != log->l_write_headq);
3669 } 3653 }
3670 GRANT_UNLOCK(log, s); 3654 spin_unlock(&log->l_grant_lock);
3671 3655
3672 if (! (log->l_iclog->ic_state & XLOG_STATE_IOERROR)) { 3656 if (! (log->l_iclog->ic_state & XLOG_STATE_IOERROR)) {
3673 ASSERT(!logerror); 3657 ASSERT(!logerror);
@@ -3676,9 +3660,9 @@ xfs_log_force_umount(
3676 * log down completely. 3660 * log down completely.
3677 */ 3661 */
3678 xlog_state_sync_all(log, XFS_LOG_FORCE|XFS_LOG_SYNC, &dummy); 3662 xlog_state_sync_all(log, XFS_LOG_FORCE|XFS_LOG_SYNC, &dummy);
3679 s2 = LOG_LOCK(log); 3663 spin_lock(&log->l_icloglock);
3680 retval = xlog_state_ioerror(log); 3664 retval = xlog_state_ioerror(log);
3681 LOG_UNLOCK(log, s2); 3665 spin_unlock(&log->l_icloglock);
3682 } 3666 }
3683 /* 3667 /*
3684 * Wake up everybody waiting on xfs_log_force. 3668 * Wake up everybody waiting on xfs_log_force.
@@ -3691,13 +3675,13 @@ xfs_log_force_umount(
3691 { 3675 {
3692 xlog_in_core_t *iclog; 3676 xlog_in_core_t *iclog;
3693 3677
3694 s = LOG_LOCK(log); 3678 spin_lock(&log->l_icloglock);
3695 iclog = log->l_iclog; 3679 iclog = log->l_iclog;
3696 do { 3680 do {
3697 ASSERT(iclog->ic_callback == 0); 3681 ASSERT(iclog->ic_callback == 0);
3698 iclog = iclog->ic_next; 3682 iclog = iclog->ic_next;
3699 } while (iclog != log->l_iclog); 3683 } while (iclog != log->l_iclog);
3700 LOG_UNLOCK(log, s); 3684 spin_unlock(&log->l_icloglock);
3701 } 3685 }
3702#endif 3686#endif
3703 /* return non-zero if log IOERROR transition had already happened */ 3687 /* return non-zero if log IOERROR transition had already happened */