aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xfs/xfs_log_recover.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/xfs/xfs_log_recover.c')
-rw-r--r--fs/xfs/xfs_log_recover.c197
1 files changed, 92 insertions, 105 deletions
diff --git a/fs/xfs/xfs_log_recover.c b/fs/xfs/xfs_log_recover.c
index 851eca8a7150..b82d5d4d2462 100644
--- a/fs/xfs/xfs_log_recover.c
+++ b/fs/xfs/xfs_log_recover.c
@@ -198,7 +198,7 @@ xlog_header_check_dump(
198 cmn_err(CE_DEBUG, " log : uuid = "); 198 cmn_err(CE_DEBUG, " log : uuid = ");
199 for (b = 0; b < 16; b++) 199 for (b = 0; b < 16; b++)
200 cmn_err(CE_DEBUG, "%02x",((uchar_t *)&head->h_fs_uuid)[b]); 200 cmn_err(CE_DEBUG, "%02x",((uchar_t *)&head->h_fs_uuid)[b]);
201 cmn_err(CE_DEBUG, ", fmt = %d\n", INT_GET(head->h_fmt, ARCH_CONVERT)); 201 cmn_err(CE_DEBUG, ", fmt = %d\n", be32_to_cpu(head->h_fmt));
202} 202}
203#else 203#else
204#define xlog_header_check_dump(mp, head) 204#define xlog_header_check_dump(mp, head)
@@ -212,14 +212,14 @@ xlog_header_check_recover(
212 xfs_mount_t *mp, 212 xfs_mount_t *mp,
213 xlog_rec_header_t *head) 213 xlog_rec_header_t *head)
214{ 214{
215 ASSERT(INT_GET(head->h_magicno, ARCH_CONVERT) == XLOG_HEADER_MAGIC_NUM); 215 ASSERT(be32_to_cpu(head->h_magicno) == XLOG_HEADER_MAGIC_NUM);
216 216
217 /* 217 /*
218 * IRIX doesn't write the h_fmt field and leaves it zeroed 218 * IRIX doesn't write the h_fmt field and leaves it zeroed
219 * (XLOG_FMT_UNKNOWN). This stops us from trying to recover 219 * (XLOG_FMT_UNKNOWN). This stops us from trying to recover
220 * a dirty log created in IRIX. 220 * a dirty log created in IRIX.
221 */ 221 */
222 if (unlikely(INT_GET(head->h_fmt, ARCH_CONVERT) != XLOG_FMT)) { 222 if (unlikely(be32_to_cpu(head->h_fmt) != XLOG_FMT)) {
223 xlog_warn( 223 xlog_warn(
224 "XFS: dirty log written in incompatible format - can't recover"); 224 "XFS: dirty log written in incompatible format - can't recover");
225 xlog_header_check_dump(mp, head); 225 xlog_header_check_dump(mp, head);
@@ -245,7 +245,7 @@ xlog_header_check_mount(
245 xfs_mount_t *mp, 245 xfs_mount_t *mp,
246 xlog_rec_header_t *head) 246 xlog_rec_header_t *head)
247{ 247{
248 ASSERT(INT_GET(head->h_magicno, ARCH_CONVERT) == XLOG_HEADER_MAGIC_NUM); 248 ASSERT(be32_to_cpu(head->h_magicno) == XLOG_HEADER_MAGIC_NUM);
249 249
250 if (uuid_is_nil(&head->h_fs_uuid)) { 250 if (uuid_is_nil(&head->h_fs_uuid)) {
251 /* 251 /*
@@ -293,7 +293,7 @@ xlog_recover_iodone(
293 * Note that the algorithm can not be perfect because the disk will not 293 * Note that the algorithm can not be perfect because the disk will not
294 * necessarily be perfect. 294 * necessarily be perfect.
295 */ 295 */
296int 296STATIC int
297xlog_find_cycle_start( 297xlog_find_cycle_start(
298 xlog_t *log, 298 xlog_t *log,
299 xfs_buf_t *bp, 299 xfs_buf_t *bp,
@@ -311,7 +311,7 @@ xlog_find_cycle_start(
311 if ((error = xlog_bread(log, mid_blk, 1, bp))) 311 if ((error = xlog_bread(log, mid_blk, 1, bp)))
312 return error; 312 return error;
313 offset = xlog_align(log, mid_blk, 1, bp); 313 offset = xlog_align(log, mid_blk, 1, bp);
314 mid_cycle = GET_CYCLE(offset, ARCH_CONVERT); 314 mid_cycle = xlog_get_cycle(offset);
315 if (mid_cycle == cycle) { 315 if (mid_cycle == cycle) {
316 *last_blk = mid_blk; 316 *last_blk = mid_blk;
317 /* last_half_cycle == mid_cycle */ 317 /* last_half_cycle == mid_cycle */
@@ -371,7 +371,7 @@ xlog_find_verify_cycle(
371 371
372 buf = xlog_align(log, i, bcount, bp); 372 buf = xlog_align(log, i, bcount, bp);
373 for (j = 0; j < bcount; j++) { 373 for (j = 0; j < bcount; j++) {
374 cycle = GET_CYCLE(buf, ARCH_CONVERT); 374 cycle = xlog_get_cycle(buf);
375 if (cycle == stop_on_cycle_no) { 375 if (cycle == stop_on_cycle_no) {
376 *new_blk = i+j; 376 *new_blk = i+j;
377 goto out; 377 goto out;
@@ -447,8 +447,7 @@ xlog_find_verify_log_record(
447 447
448 head = (xlog_rec_header_t *)offset; 448 head = (xlog_rec_header_t *)offset;
449 449
450 if (XLOG_HEADER_MAGIC_NUM == 450 if (XLOG_HEADER_MAGIC_NUM == be32_to_cpu(head->h_magicno))
451 INT_GET(head->h_magicno, ARCH_CONVERT))
452 break; 451 break;
453 452
454 if (!smallmem) 453 if (!smallmem)
@@ -480,7 +479,7 @@ xlog_find_verify_log_record(
480 * record do we update last_blk. 479 * record do we update last_blk.
481 */ 480 */
482 if (XFS_SB_VERSION_HASLOGV2(&log->l_mp->m_sb)) { 481 if (XFS_SB_VERSION_HASLOGV2(&log->l_mp->m_sb)) {
483 uint h_size = INT_GET(head->h_size, ARCH_CONVERT); 482 uint h_size = be32_to_cpu(head->h_size);
484 483
485 xhdrs = h_size / XLOG_HEADER_CYCLE_SIZE; 484 xhdrs = h_size / XLOG_HEADER_CYCLE_SIZE;
486 if (h_size % XLOG_HEADER_CYCLE_SIZE) 485 if (h_size % XLOG_HEADER_CYCLE_SIZE)
@@ -489,8 +488,8 @@ xlog_find_verify_log_record(
489 xhdrs = 1; 488 xhdrs = 1;
490 } 489 }
491 490
492 if (*last_blk - i + extra_bblks 491 if (*last_blk - i + extra_bblks !=
493 != BTOBB(INT_GET(head->h_len, ARCH_CONVERT)) + xhdrs) 492 BTOBB(be32_to_cpu(head->h_len)) + xhdrs)
494 *last_blk = i; 493 *last_blk = i;
495 494
496out: 495out:
@@ -550,13 +549,13 @@ xlog_find_head(
550 if ((error = xlog_bread(log, 0, 1, bp))) 549 if ((error = xlog_bread(log, 0, 1, bp)))
551 goto bp_err; 550 goto bp_err;
552 offset = xlog_align(log, 0, 1, bp); 551 offset = xlog_align(log, 0, 1, bp);
553 first_half_cycle = GET_CYCLE(offset, ARCH_CONVERT); 552 first_half_cycle = xlog_get_cycle(offset);
554 553
555 last_blk = head_blk = log_bbnum - 1; /* get cycle # of last block */ 554 last_blk = head_blk = log_bbnum - 1; /* get cycle # of last block */
556 if ((error = xlog_bread(log, last_blk, 1, bp))) 555 if ((error = xlog_bread(log, last_blk, 1, bp)))
557 goto bp_err; 556 goto bp_err;
558 offset = xlog_align(log, last_blk, 1, bp); 557 offset = xlog_align(log, last_blk, 1, bp);
559 last_half_cycle = GET_CYCLE(offset, ARCH_CONVERT); 558 last_half_cycle = xlog_get_cycle(offset);
560 ASSERT(last_half_cycle != 0); 559 ASSERT(last_half_cycle != 0);
561 560
562 /* 561 /*
@@ -808,7 +807,7 @@ xlog_find_tail(
808 if ((error = xlog_bread(log, 0, 1, bp))) 807 if ((error = xlog_bread(log, 0, 1, bp)))
809 goto bread_err; 808 goto bread_err;
810 offset = xlog_align(log, 0, 1, bp); 809 offset = xlog_align(log, 0, 1, bp);
811 if (GET_CYCLE(offset, ARCH_CONVERT) == 0) { 810 if (xlog_get_cycle(offset) == 0) {
812 *tail_blk = 0; 811 *tail_blk = 0;
813 /* leave all other log inited values alone */ 812 /* leave all other log inited values alone */
814 goto exit; 813 goto exit;
@@ -823,8 +822,7 @@ xlog_find_tail(
823 if ((error = xlog_bread(log, i, 1, bp))) 822 if ((error = xlog_bread(log, i, 1, bp)))
824 goto bread_err; 823 goto bread_err;
825 offset = xlog_align(log, i, 1, bp); 824 offset = xlog_align(log, i, 1, bp);
826 if (XLOG_HEADER_MAGIC_NUM == 825 if (XLOG_HEADER_MAGIC_NUM == be32_to_cpu(*(__be32 *)offset)) {
827 INT_GET(*(uint *)offset, ARCH_CONVERT)) {
828 found = 1; 826 found = 1;
829 break; 827 break;
830 } 828 }
@@ -841,7 +839,7 @@ xlog_find_tail(
841 goto bread_err; 839 goto bread_err;
842 offset = xlog_align(log, i, 1, bp); 840 offset = xlog_align(log, i, 1, bp);
843 if (XLOG_HEADER_MAGIC_NUM == 841 if (XLOG_HEADER_MAGIC_NUM ==
844 INT_GET(*(uint*)offset, ARCH_CONVERT)) { 842 be32_to_cpu(*(__be32 *)offset)) {
845 found = 2; 843 found = 2;
846 break; 844 break;
847 } 845 }
@@ -855,7 +853,7 @@ xlog_find_tail(
855 853
856 /* find blk_no of tail of log */ 854 /* find blk_no of tail of log */
857 rhead = (xlog_rec_header_t *)offset; 855 rhead = (xlog_rec_header_t *)offset;
858 *tail_blk = BLOCK_LSN(INT_GET(rhead->h_tail_lsn, ARCH_CONVERT)); 856 *tail_blk = BLOCK_LSN(be64_to_cpu(rhead->h_tail_lsn));
859 857
860 /* 858 /*
861 * Reset log values according to the state of the log when we 859 * Reset log values according to the state of the log when we
@@ -869,11 +867,11 @@ xlog_find_tail(
869 */ 867 */
870 log->l_prev_block = i; 868 log->l_prev_block = i;
871 log->l_curr_block = (int)*head_blk; 869 log->l_curr_block = (int)*head_blk;
872 log->l_curr_cycle = INT_GET(rhead->h_cycle, ARCH_CONVERT); 870 log->l_curr_cycle = be32_to_cpu(rhead->h_cycle);
873 if (found == 2) 871 if (found == 2)
874 log->l_curr_cycle++; 872 log->l_curr_cycle++;
875 log->l_tail_lsn = INT_GET(rhead->h_tail_lsn, ARCH_CONVERT); 873 log->l_tail_lsn = be64_to_cpu(rhead->h_tail_lsn);
876 log->l_last_sync_lsn = INT_GET(rhead->h_lsn, ARCH_CONVERT); 874 log->l_last_sync_lsn = be64_to_cpu(rhead->h_lsn);
877 log->l_grant_reserve_cycle = log->l_curr_cycle; 875 log->l_grant_reserve_cycle = log->l_curr_cycle;
878 log->l_grant_reserve_bytes = BBTOB(log->l_curr_block); 876 log->l_grant_reserve_bytes = BBTOB(log->l_curr_block);
879 log->l_grant_write_cycle = log->l_curr_cycle; 877 log->l_grant_write_cycle = log->l_curr_cycle;
@@ -891,8 +889,8 @@ xlog_find_tail(
891 * unmount record rather than the block after it. 889 * unmount record rather than the block after it.
892 */ 890 */
893 if (XFS_SB_VERSION_HASLOGV2(&log->l_mp->m_sb)) { 891 if (XFS_SB_VERSION_HASLOGV2(&log->l_mp->m_sb)) {
894 int h_size = INT_GET(rhead->h_size, ARCH_CONVERT); 892 int h_size = be32_to_cpu(rhead->h_size);
895 int h_version = INT_GET(rhead->h_version, ARCH_CONVERT); 893 int h_version = be32_to_cpu(rhead->h_version);
896 894
897 if ((h_version & XLOG_VERSION_2) && 895 if ((h_version & XLOG_VERSION_2) &&
898 (h_size > XLOG_HEADER_CYCLE_SIZE)) { 896 (h_size > XLOG_HEADER_CYCLE_SIZE)) {
@@ -906,10 +904,10 @@ xlog_find_tail(
906 hblks = 1; 904 hblks = 1;
907 } 905 }
908 after_umount_blk = (i + hblks + (int) 906 after_umount_blk = (i + hblks + (int)
909 BTOBB(INT_GET(rhead->h_len, ARCH_CONVERT))) % log->l_logBBsize; 907 BTOBB(be32_to_cpu(rhead->h_len))) % log->l_logBBsize;
910 tail_lsn = log->l_tail_lsn; 908 tail_lsn = log->l_tail_lsn;
911 if (*head_blk == after_umount_blk && 909 if (*head_blk == after_umount_blk &&
912 INT_GET(rhead->h_num_logops, ARCH_CONVERT) == 1) { 910 be32_to_cpu(rhead->h_num_logops) == 1) {
913 umount_data_blk = (i + hblks) % log->l_logBBsize; 911 umount_data_blk = (i + hblks) % log->l_logBBsize;
914 if ((error = xlog_bread(log, umount_data_blk, 1, bp))) { 912 if ((error = xlog_bread(log, umount_data_blk, 1, bp))) {
915 goto bread_err; 913 goto bread_err;
@@ -922,10 +920,12 @@ xlog_find_tail(
922 * log records will point recovery to after the 920 * log records will point recovery to after the
923 * current unmount record. 921 * current unmount record.
924 */ 922 */
925 ASSIGN_ANY_LSN_HOST(log->l_tail_lsn, log->l_curr_cycle, 923 log->l_tail_lsn =
926 after_umount_blk); 924 xlog_assign_lsn(log->l_curr_cycle,
927 ASSIGN_ANY_LSN_HOST(log->l_last_sync_lsn, log->l_curr_cycle, 925 after_umount_blk);
928 after_umount_blk); 926 log->l_last_sync_lsn =
927 xlog_assign_lsn(log->l_curr_cycle,
928 after_umount_blk);
929 *tail_blk = after_umount_blk; 929 *tail_blk = after_umount_blk;
930 930
931 /* 931 /*
@@ -986,7 +986,7 @@ exit:
986 * -1 => use *blk_no as the first block of the log 986 * -1 => use *blk_no as the first block of the log
987 * >0 => error has occurred 987 * >0 => error has occurred
988 */ 988 */
989int 989STATIC int
990xlog_find_zeroed( 990xlog_find_zeroed(
991 xlog_t *log, 991 xlog_t *log,
992 xfs_daddr_t *blk_no) 992 xfs_daddr_t *blk_no)
@@ -1007,7 +1007,7 @@ xlog_find_zeroed(
1007 if ((error = xlog_bread(log, 0, 1, bp))) 1007 if ((error = xlog_bread(log, 0, 1, bp)))
1008 goto bp_err; 1008 goto bp_err;
1009 offset = xlog_align(log, 0, 1, bp); 1009 offset = xlog_align(log, 0, 1, bp);
1010 first_cycle = GET_CYCLE(offset, ARCH_CONVERT); 1010 first_cycle = xlog_get_cycle(offset);
1011 if (first_cycle == 0) { /* completely zeroed log */ 1011 if (first_cycle == 0) { /* completely zeroed log */
1012 *blk_no = 0; 1012 *blk_no = 0;
1013 xlog_put_bp(bp); 1013 xlog_put_bp(bp);
@@ -1018,7 +1018,7 @@ xlog_find_zeroed(
1018 if ((error = xlog_bread(log, log_bbnum-1, 1, bp))) 1018 if ((error = xlog_bread(log, log_bbnum-1, 1, bp)))
1019 goto bp_err; 1019 goto bp_err;
1020 offset = xlog_align(log, log_bbnum-1, 1, bp); 1020 offset = xlog_align(log, log_bbnum-1, 1, bp);
1021 last_cycle = GET_CYCLE(offset, ARCH_CONVERT); 1021 last_cycle = xlog_get_cycle(offset);
1022 if (last_cycle != 0) { /* log completely written to */ 1022 if (last_cycle != 0) { /* log completely written to */
1023 xlog_put_bp(bp); 1023 xlog_put_bp(bp);
1024 return 0; 1024 return 0;
@@ -1098,13 +1098,13 @@ xlog_add_record(
1098 xlog_rec_header_t *recp = (xlog_rec_header_t *)buf; 1098 xlog_rec_header_t *recp = (xlog_rec_header_t *)buf;
1099 1099
1100 memset(buf, 0, BBSIZE); 1100 memset(buf, 0, BBSIZE);
1101 INT_SET(recp->h_magicno, ARCH_CONVERT, XLOG_HEADER_MAGIC_NUM); 1101 recp->h_magicno = cpu_to_be32(XLOG_HEADER_MAGIC_NUM);
1102 INT_SET(recp->h_cycle, ARCH_CONVERT, cycle); 1102 recp->h_cycle = cpu_to_be32(cycle);
1103 INT_SET(recp->h_version, ARCH_CONVERT, 1103 recp->h_version = cpu_to_be32(
1104 XFS_SB_VERSION_HASLOGV2(&log->l_mp->m_sb) ? 2 : 1); 1104 XFS_SB_VERSION_HASLOGV2(&log->l_mp->m_sb) ? 2 : 1);
1105 ASSIGN_ANY_LSN_DISK(recp->h_lsn, cycle, block); 1105 recp->h_lsn = cpu_to_be64(xlog_assign_lsn(cycle, block));
1106 ASSIGN_ANY_LSN_DISK(recp->h_tail_lsn, tail_cycle, tail_block); 1106 recp->h_tail_lsn = cpu_to_be64(xlog_assign_lsn(tail_cycle, tail_block));
1107 INT_SET(recp->h_fmt, ARCH_CONVERT, XLOG_FMT); 1107 recp->h_fmt = cpu_to_be32(XLOG_FMT);
1108 memcpy(&recp->h_fs_uuid, &log->l_mp->m_sb.sb_uuid, sizeof(uuid_t)); 1108 memcpy(&recp->h_fs_uuid, &log->l_mp->m_sb.sb_uuid, sizeof(uuid_t));
1109} 1109}
1110 1110
@@ -2211,7 +2211,7 @@ xlog_recover_do_buffer_trans(
2211 * overlap with future reads of those inodes. 2211 * overlap with future reads of those inodes.
2212 */ 2212 */
2213 if (XFS_DINODE_MAGIC == 2213 if (XFS_DINODE_MAGIC ==
2214 INT_GET(*((__uint16_t *)(xfs_buf_offset(bp, 0))), ARCH_CONVERT) && 2214 be16_to_cpu(*((__be16 *)xfs_buf_offset(bp, 0))) &&
2215 (XFS_BUF_COUNT(bp) != MAX(log->l_mp->m_sb.sb_blocksize, 2215 (XFS_BUF_COUNT(bp) != MAX(log->l_mp->m_sb.sb_blocksize,
2216 (__uint32_t)XFS_INODE_CLUSTER_SIZE(log->l_mp)))) { 2216 (__uint32_t)XFS_INODE_CLUSTER_SIZE(log->l_mp)))) {
2217 XFS_BUF_STALE(bp); 2217 XFS_BUF_STALE(bp);
@@ -2581,8 +2581,7 @@ xlog_recover_do_dquot_trans(
2581 /* 2581 /*
2582 * This type of quotas was turned off, so ignore this record. 2582 * This type of quotas was turned off, so ignore this record.
2583 */ 2583 */
2584 type = INT_GET(recddq->d_flags, ARCH_CONVERT) & 2584 type = recddq->d_flags & (XFS_DQ_USER | XFS_DQ_PROJ | XFS_DQ_GROUP);
2585 (XFS_DQ_USER | XFS_DQ_PROJ | XFS_DQ_GROUP);
2586 ASSERT(type); 2585 ASSERT(type);
2587 if (log->l_quotaoffs_flag & type) 2586 if (log->l_quotaoffs_flag & type)
2588 return (0); 2587 return (0);
@@ -2660,7 +2659,6 @@ xlog_recover_do_efi_trans(
2660 xfs_mount_t *mp; 2659 xfs_mount_t *mp;
2661 xfs_efi_log_item_t *efip; 2660 xfs_efi_log_item_t *efip;
2662 xfs_efi_log_format_t *efi_formatp; 2661 xfs_efi_log_format_t *efi_formatp;
2663 SPLDECL(s);
2664 2662
2665 if (pass == XLOG_RECOVER_PASS1) { 2663 if (pass == XLOG_RECOVER_PASS1) {
2666 return 0; 2664 return 0;
@@ -2678,11 +2676,11 @@ xlog_recover_do_efi_trans(
2678 efip->efi_next_extent = efi_formatp->efi_nextents; 2676 efip->efi_next_extent = efi_formatp->efi_nextents;
2679 efip->efi_flags |= XFS_EFI_COMMITTED; 2677 efip->efi_flags |= XFS_EFI_COMMITTED;
2680 2678
2681 AIL_LOCK(mp,s); 2679 spin_lock(&mp->m_ail_lock);
2682 /* 2680 /*
2683 * xfs_trans_update_ail() drops the AIL lock. 2681 * xfs_trans_update_ail() drops the AIL lock.
2684 */ 2682 */
2685 xfs_trans_update_ail(mp, (xfs_log_item_t *)efip, lsn, s); 2683 xfs_trans_update_ail(mp, (xfs_log_item_t *)efip, lsn);
2686 return 0; 2684 return 0;
2687} 2685}
2688 2686
@@ -2707,7 +2705,6 @@ xlog_recover_do_efd_trans(
2707 xfs_log_item_t *lip; 2705 xfs_log_item_t *lip;
2708 int gen; 2706 int gen;
2709 __uint64_t efi_id; 2707 __uint64_t efi_id;
2710 SPLDECL(s);
2711 2708
2712 if (pass == XLOG_RECOVER_PASS1) { 2709 if (pass == XLOG_RECOVER_PASS1) {
2713 return; 2710 return;
@@ -2725,7 +2722,7 @@ xlog_recover_do_efd_trans(
2725 * in the AIL. 2722 * in the AIL.
2726 */ 2723 */
2727 mp = log->l_mp; 2724 mp = log->l_mp;
2728 AIL_LOCK(mp,s); 2725 spin_lock(&mp->m_ail_lock);
2729 lip = xfs_trans_first_ail(mp, &gen); 2726 lip = xfs_trans_first_ail(mp, &gen);
2730 while (lip != NULL) { 2727 while (lip != NULL) {
2731 if (lip->li_type == XFS_LI_EFI) { 2728 if (lip->li_type == XFS_LI_EFI) {
@@ -2735,22 +2732,14 @@ xlog_recover_do_efd_trans(
2735 * xfs_trans_delete_ail() drops the 2732 * xfs_trans_delete_ail() drops the
2736 * AIL lock. 2733 * AIL lock.
2737 */ 2734 */
2738 xfs_trans_delete_ail(mp, lip, s); 2735 xfs_trans_delete_ail(mp, lip);
2739 break; 2736 xfs_efi_item_free(efip);
2737 return;
2740 } 2738 }
2741 } 2739 }
2742 lip = xfs_trans_next_ail(mp, lip, &gen, NULL); 2740 lip = xfs_trans_next_ail(mp, lip, &gen, NULL);
2743 } 2741 }
2744 2742 spin_unlock(&mp->m_ail_lock);
2745 /*
2746 * If we found it, then free it up. If it wasn't there, it
2747 * must have been overwritten in the log. Oh well.
2748 */
2749 if (lip != NULL) {
2750 xfs_efi_item_free(efip);
2751 } else {
2752 AIL_UNLOCK(mp, s);
2753 }
2754} 2743}
2755 2744
2756/* 2745/*
@@ -2897,8 +2886,8 @@ xlog_recover_process_data(
2897 unsigned long hash; 2886 unsigned long hash;
2898 uint flags; 2887 uint flags;
2899 2888
2900 lp = dp + INT_GET(rhead->h_len, ARCH_CONVERT); 2889 lp = dp + be32_to_cpu(rhead->h_len);
2901 num_logops = INT_GET(rhead->h_num_logops, ARCH_CONVERT); 2890 num_logops = be32_to_cpu(rhead->h_num_logops);
2902 2891
2903 /* check the log format matches our own - else we can't recover */ 2892 /* check the log format matches our own - else we can't recover */
2904 if (xlog_header_check_recover(log->l_mp, rhead)) 2893 if (xlog_header_check_recover(log->l_mp, rhead))
@@ -2915,15 +2904,20 @@ xlog_recover_process_data(
2915 ASSERT(0); 2904 ASSERT(0);
2916 return (XFS_ERROR(EIO)); 2905 return (XFS_ERROR(EIO));
2917 } 2906 }
2918 tid = INT_GET(ohead->oh_tid, ARCH_CONVERT); 2907 tid = be32_to_cpu(ohead->oh_tid);
2919 hash = XLOG_RHASH(tid); 2908 hash = XLOG_RHASH(tid);
2920 trans = xlog_recover_find_tid(rhash[hash], tid); 2909 trans = xlog_recover_find_tid(rhash[hash], tid);
2921 if (trans == NULL) { /* not found; add new tid */ 2910 if (trans == NULL) { /* not found; add new tid */
2922 if (ohead->oh_flags & XLOG_START_TRANS) 2911 if (ohead->oh_flags & XLOG_START_TRANS)
2923 xlog_recover_new_tid(&rhash[hash], tid, 2912 xlog_recover_new_tid(&rhash[hash], tid,
2924 INT_GET(rhead->h_lsn, ARCH_CONVERT)); 2913 be64_to_cpu(rhead->h_lsn));
2925 } else { 2914 } else {
2926 ASSERT(dp+INT_GET(ohead->oh_len, ARCH_CONVERT) <= lp); 2915 if (dp + be32_to_cpu(ohead->oh_len) > lp) {
2916 xlog_warn(
2917 "XFS: xlog_recover_process_data: bad length");
2918 WARN_ON(1);
2919 return (XFS_ERROR(EIO));
2920 }
2927 flags = ohead->oh_flags & ~XLOG_END_TRANS; 2921 flags = ohead->oh_flags & ~XLOG_END_TRANS;
2928 if (flags & XLOG_WAS_CONT_TRANS) 2922 if (flags & XLOG_WAS_CONT_TRANS)
2929 flags &= ~XLOG_CONTINUE_TRANS; 2923 flags &= ~XLOG_CONTINUE_TRANS;
@@ -2937,8 +2931,7 @@ xlog_recover_process_data(
2937 break; 2931 break;
2938 case XLOG_WAS_CONT_TRANS: 2932 case XLOG_WAS_CONT_TRANS:
2939 error = xlog_recover_add_to_cont_trans(trans, 2933 error = xlog_recover_add_to_cont_trans(trans,
2940 dp, INT_GET(ohead->oh_len, 2934 dp, be32_to_cpu(ohead->oh_len));
2941 ARCH_CONVERT));
2942 break; 2935 break;
2943 case XLOG_START_TRANS: 2936 case XLOG_START_TRANS:
2944 xlog_warn( 2937 xlog_warn(
@@ -2949,8 +2942,7 @@ xlog_recover_process_data(
2949 case 0: 2942 case 0:
2950 case XLOG_CONTINUE_TRANS: 2943 case XLOG_CONTINUE_TRANS:
2951 error = xlog_recover_add_to_trans(trans, 2944 error = xlog_recover_add_to_trans(trans,
2952 dp, INT_GET(ohead->oh_len, 2945 dp, be32_to_cpu(ohead->oh_len));
2953 ARCH_CONVERT));
2954 break; 2946 break;
2955 default: 2947 default:
2956 xlog_warn( 2948 xlog_warn(
@@ -2962,7 +2954,7 @@ xlog_recover_process_data(
2962 if (error) 2954 if (error)
2963 return error; 2955 return error;
2964 } 2956 }
2965 dp += INT_GET(ohead->oh_len, ARCH_CONVERT); 2957 dp += be32_to_cpu(ohead->oh_len);
2966 num_logops--; 2958 num_logops--;
2967 } 2959 }
2968 return 0; 2960 return 0;
@@ -3075,10 +3067,9 @@ xlog_recover_process_efis(
3075 xfs_efi_log_item_t *efip; 3067 xfs_efi_log_item_t *efip;
3076 int gen; 3068 int gen;
3077 xfs_mount_t *mp; 3069 xfs_mount_t *mp;
3078 SPLDECL(s);
3079 3070
3080 mp = log->l_mp; 3071 mp = log->l_mp;
3081 AIL_LOCK(mp,s); 3072 spin_lock(&mp->m_ail_lock);
3082 3073
3083 lip = xfs_trans_first_ail(mp, &gen); 3074 lip = xfs_trans_first_ail(mp, &gen);
3084 while (lip != NULL) { 3075 while (lip != NULL) {
@@ -3099,12 +3090,12 @@ xlog_recover_process_efis(
3099 continue; 3090 continue;
3100 } 3091 }
3101 3092
3102 AIL_UNLOCK(mp, s); 3093 spin_unlock(&mp->m_ail_lock);
3103 xlog_recover_process_efi(mp, efip); 3094 xlog_recover_process_efi(mp, efip);
3104 AIL_LOCK(mp,s); 3095 spin_lock(&mp->m_ail_lock);
3105 lip = xfs_trans_next_ail(mp, lip, &gen, NULL); 3096 lip = xfs_trans_next_ail(mp, lip, &gen, NULL);
3106 } 3097 }
3107 AIL_UNLOCK(mp, s); 3098 spin_unlock(&mp->m_ail_lock);
3108} 3099}
3109 3100
3110/* 3101/*
@@ -3315,16 +3306,16 @@ xlog_pack_data_checksum(
3315 int size) 3306 int size)
3316{ 3307{
3317 int i; 3308 int i;
3318 uint *up; 3309 __be32 *up;
3319 uint chksum = 0; 3310 uint chksum = 0;
3320 3311
3321 up = (uint *)iclog->ic_datap; 3312 up = (__be32 *)iclog->ic_datap;
3322 /* divide length by 4 to get # words */ 3313 /* divide length by 4 to get # words */
3323 for (i = 0; i < (size >> 2); i++) { 3314 for (i = 0; i < (size >> 2); i++) {
3324 chksum ^= INT_GET(*up, ARCH_CONVERT); 3315 chksum ^= be32_to_cpu(*up);
3325 up++; 3316 up++;
3326 } 3317 }
3327 INT_SET(iclog->ic_header.h_chksum, ARCH_CONVERT, chksum); 3318 iclog->ic_header.h_chksum = cpu_to_be32(chksum);
3328} 3319}
3329#else 3320#else
3330#define xlog_pack_data_checksum(log, iclog, size) 3321#define xlog_pack_data_checksum(log, iclog, size)
@@ -3341,7 +3332,7 @@ xlog_pack_data(
3341{ 3332{
3342 int i, j, k; 3333 int i, j, k;
3343 int size = iclog->ic_offset + roundoff; 3334 int size = iclog->ic_offset + roundoff;
3344 uint cycle_lsn; 3335 __be32 cycle_lsn;
3345 xfs_caddr_t dp; 3336 xfs_caddr_t dp;
3346 xlog_in_core_2_t *xhdr; 3337 xlog_in_core_2_t *xhdr;
3347 3338
@@ -3352,8 +3343,8 @@ xlog_pack_data(
3352 dp = iclog->ic_datap; 3343 dp = iclog->ic_datap;
3353 for (i = 0; i < BTOBB(size) && 3344 for (i = 0; i < BTOBB(size) &&
3354 i < (XLOG_HEADER_CYCLE_SIZE / BBSIZE); i++) { 3345 i < (XLOG_HEADER_CYCLE_SIZE / BBSIZE); i++) {
3355 iclog->ic_header.h_cycle_data[i] = *(uint *)dp; 3346 iclog->ic_header.h_cycle_data[i] = *(__be32 *)dp;
3356 *(uint *)dp = cycle_lsn; 3347 *(__be32 *)dp = cycle_lsn;
3357 dp += BBSIZE; 3348 dp += BBSIZE;
3358 } 3349 }
3359 3350
@@ -3362,8 +3353,8 @@ xlog_pack_data(
3362 for ( ; i < BTOBB(size); i++) { 3353 for ( ; i < BTOBB(size); i++) {
3363 j = i / (XLOG_HEADER_CYCLE_SIZE / BBSIZE); 3354 j = i / (XLOG_HEADER_CYCLE_SIZE / BBSIZE);
3364 k = i % (XLOG_HEADER_CYCLE_SIZE / BBSIZE); 3355 k = i % (XLOG_HEADER_CYCLE_SIZE / BBSIZE);
3365 xhdr[j].hic_xheader.xh_cycle_data[k] = *(uint *)dp; 3356 xhdr[j].hic_xheader.xh_cycle_data[k] = *(__be32 *)dp;
3366 *(uint *)dp = cycle_lsn; 3357 *(__be32 *)dp = cycle_lsn;
3367 dp += BBSIZE; 3358 dp += BBSIZE;
3368 } 3359 }
3369 3360
@@ -3380,21 +3371,21 @@ xlog_unpack_data_checksum(
3380 xfs_caddr_t dp, 3371 xfs_caddr_t dp,
3381 xlog_t *log) 3372 xlog_t *log)
3382{ 3373{
3383 uint *up = (uint *)dp; 3374 __be32 *up = (__be32 *)dp;
3384 uint chksum = 0; 3375 uint chksum = 0;
3385 int i; 3376 int i;
3386 3377
3387 /* divide length by 4 to get # words */ 3378 /* divide length by 4 to get # words */
3388 for (i=0; i < INT_GET(rhead->h_len, ARCH_CONVERT) >> 2; i++) { 3379 for (i=0; i < be32_to_cpu(rhead->h_len) >> 2; i++) {
3389 chksum ^= INT_GET(*up, ARCH_CONVERT); 3380 chksum ^= be32_to_cpu(*up);
3390 up++; 3381 up++;
3391 } 3382 }
3392 if (chksum != INT_GET(rhead->h_chksum, ARCH_CONVERT)) { 3383 if (chksum != be32_to_cpu(rhead->h_chksum)) {
3393 if (rhead->h_chksum || 3384 if (rhead->h_chksum ||
3394 ((log->l_flags & XLOG_CHKSUM_MISMATCH) == 0)) { 3385 ((log->l_flags & XLOG_CHKSUM_MISMATCH) == 0)) {
3395 cmn_err(CE_DEBUG, 3386 cmn_err(CE_DEBUG,
3396 "XFS: LogR chksum mismatch: was (0x%x) is (0x%x)\n", 3387 "XFS: LogR chksum mismatch: was (0x%x) is (0x%x)\n",
3397 INT_GET(rhead->h_chksum, ARCH_CONVERT), chksum); 3388 be32_to_cpu(rhead->h_chksum), chksum);
3398 cmn_err(CE_DEBUG, 3389 cmn_err(CE_DEBUG,
3399"XFS: Disregard message if filesystem was created with non-DEBUG kernel"); 3390"XFS: Disregard message if filesystem was created with non-DEBUG kernel");
3400 if (XFS_SB_VERSION_HASLOGV2(&log->l_mp->m_sb)) { 3391 if (XFS_SB_VERSION_HASLOGV2(&log->l_mp->m_sb)) {
@@ -3418,18 +3409,18 @@ xlog_unpack_data(
3418 int i, j, k; 3409 int i, j, k;
3419 xlog_in_core_2_t *xhdr; 3410 xlog_in_core_2_t *xhdr;
3420 3411
3421 for (i = 0; i < BTOBB(INT_GET(rhead->h_len, ARCH_CONVERT)) && 3412 for (i = 0; i < BTOBB(be32_to_cpu(rhead->h_len)) &&
3422 i < (XLOG_HEADER_CYCLE_SIZE / BBSIZE); i++) { 3413 i < (XLOG_HEADER_CYCLE_SIZE / BBSIZE); i++) {
3423 *(uint *)dp = *(uint *)&rhead->h_cycle_data[i]; 3414 *(__be32 *)dp = *(__be32 *)&rhead->h_cycle_data[i];
3424 dp += BBSIZE; 3415 dp += BBSIZE;
3425 } 3416 }
3426 3417
3427 if (XFS_SB_VERSION_HASLOGV2(&log->l_mp->m_sb)) { 3418 if (XFS_SB_VERSION_HASLOGV2(&log->l_mp->m_sb)) {
3428 xhdr = (xlog_in_core_2_t *)rhead; 3419 xhdr = (xlog_in_core_2_t *)rhead;
3429 for ( ; i < BTOBB(INT_GET(rhead->h_len, ARCH_CONVERT)); i++) { 3420 for ( ; i < BTOBB(be32_to_cpu(rhead->h_len)); i++) {
3430 j = i / (XLOG_HEADER_CYCLE_SIZE / BBSIZE); 3421 j = i / (XLOG_HEADER_CYCLE_SIZE / BBSIZE);
3431 k = i % (XLOG_HEADER_CYCLE_SIZE / BBSIZE); 3422 k = i % (XLOG_HEADER_CYCLE_SIZE / BBSIZE);
3432 *(uint *)dp = xhdr[j].hic_xheader.xh_cycle_data[k]; 3423 *(__be32 *)dp = xhdr[j].hic_xheader.xh_cycle_data[k];
3433 dp += BBSIZE; 3424 dp += BBSIZE;
3434 } 3425 }
3435 } 3426 }
@@ -3445,24 +3436,21 @@ xlog_valid_rec_header(
3445{ 3436{
3446 int hlen; 3437 int hlen;
3447 3438
3448 if (unlikely( 3439 if (unlikely(be32_to_cpu(rhead->h_magicno) != XLOG_HEADER_MAGIC_NUM)) {
3449 (INT_GET(rhead->h_magicno, ARCH_CONVERT) !=
3450 XLOG_HEADER_MAGIC_NUM))) {
3451 XFS_ERROR_REPORT("xlog_valid_rec_header(1)", 3440 XFS_ERROR_REPORT("xlog_valid_rec_header(1)",
3452 XFS_ERRLEVEL_LOW, log->l_mp); 3441 XFS_ERRLEVEL_LOW, log->l_mp);
3453 return XFS_ERROR(EFSCORRUPTED); 3442 return XFS_ERROR(EFSCORRUPTED);
3454 } 3443 }
3455 if (unlikely( 3444 if (unlikely(
3456 (!rhead->h_version || 3445 (!rhead->h_version ||
3457 (INT_GET(rhead->h_version, ARCH_CONVERT) & 3446 (be32_to_cpu(rhead->h_version) & (~XLOG_VERSION_OKBITS))))) {
3458 (~XLOG_VERSION_OKBITS)) != 0))) {
3459 xlog_warn("XFS: %s: unrecognised log version (%d).", 3447 xlog_warn("XFS: %s: unrecognised log version (%d).",
3460 __FUNCTION__, INT_GET(rhead->h_version, ARCH_CONVERT)); 3448 __FUNCTION__, be32_to_cpu(rhead->h_version));
3461 return XFS_ERROR(EIO); 3449 return XFS_ERROR(EIO);
3462 } 3450 }
3463 3451
3464 /* LR body must have data or it wouldn't have been written */ 3452 /* LR body must have data or it wouldn't have been written */
3465 hlen = INT_GET(rhead->h_len, ARCH_CONVERT); 3453 hlen = be32_to_cpu(rhead->h_len);
3466 if (unlikely( hlen <= 0 || hlen > INT_MAX )) { 3454 if (unlikely( hlen <= 0 || hlen > INT_MAX )) {
3467 XFS_ERROR_REPORT("xlog_valid_rec_header(2)", 3455 XFS_ERROR_REPORT("xlog_valid_rec_header(2)",
3468 XFS_ERRLEVEL_LOW, log->l_mp); 3456 XFS_ERRLEVEL_LOW, log->l_mp);
@@ -3522,9 +3510,8 @@ xlog_do_recovery_pass(
3522 error = xlog_valid_rec_header(log, rhead, tail_blk); 3510 error = xlog_valid_rec_header(log, rhead, tail_blk);
3523 if (error) 3511 if (error)
3524 goto bread_err1; 3512 goto bread_err1;
3525 h_size = INT_GET(rhead->h_size, ARCH_CONVERT); 3513 h_size = be32_to_cpu(rhead->h_size);
3526 if ((INT_GET(rhead->h_version, ARCH_CONVERT) 3514 if ((be32_to_cpu(rhead->h_version) & XLOG_VERSION_2) &&
3527 & XLOG_VERSION_2) &&
3528 (h_size > XLOG_HEADER_CYCLE_SIZE)) { 3515 (h_size > XLOG_HEADER_CYCLE_SIZE)) {
3529 hblks = h_size / XLOG_HEADER_CYCLE_SIZE; 3516 hblks = h_size / XLOG_HEADER_CYCLE_SIZE;
3530 if (h_size % XLOG_HEADER_CYCLE_SIZE) 3517 if (h_size % XLOG_HEADER_CYCLE_SIZE)
@@ -3561,7 +3548,7 @@ xlog_do_recovery_pass(
3561 goto bread_err2; 3548 goto bread_err2;
3562 3549
3563 /* blocks in data section */ 3550 /* blocks in data section */
3564 bblks = (int)BTOBB(INT_GET(rhead->h_len, ARCH_CONVERT)); 3551 bblks = (int)BTOBB(be32_to_cpu(rhead->h_len));
3565 error = xlog_bread(log, blk_no + hblks, bblks, dbp); 3552 error = xlog_bread(log, blk_no + hblks, bblks, dbp);
3566 if (error) 3553 if (error)
3567 goto bread_err2; 3554 goto bread_err2;
@@ -3636,7 +3623,7 @@ xlog_do_recovery_pass(
3636 if (error) 3623 if (error)
3637 goto bread_err2; 3624 goto bread_err2;
3638 3625
3639 bblks = (int)BTOBB(INT_GET(rhead->h_len, ARCH_CONVERT)); 3626 bblks = (int)BTOBB(be32_to_cpu(rhead->h_len));
3640 blk_no += hblks; 3627 blk_no += hblks;
3641 3628
3642 /* Read in data for log record */ 3629 /* Read in data for log record */
@@ -3707,7 +3694,7 @@ xlog_do_recovery_pass(
3707 error = xlog_valid_rec_header(log, rhead, blk_no); 3694 error = xlog_valid_rec_header(log, rhead, blk_no);
3708 if (error) 3695 if (error)
3709 goto bread_err2; 3696 goto bread_err2;
3710 bblks = (int)BTOBB(INT_GET(rhead->h_len, ARCH_CONVERT)); 3697 bblks = (int)BTOBB(be32_to_cpu(rhead->h_len));
3711 if ((error = xlog_bread(log, blk_no+hblks, bblks, dbp))) 3698 if ((error = xlog_bread(log, blk_no+hblks, bblks, dbp)))
3712 goto bread_err2; 3699 goto bread_err2;
3713 offset = xlog_align(log, blk_no+hblks, bblks, dbp); 3700 offset = xlog_align(log, blk_no+hblks, bblks, dbp);