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

xfs: refactor unmount record write

Refactor the writing of the unmount record into a separate helper. No
functionality changes.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>

+82 -62
+13
fs/xfs/libxfs/xfs_log_format.h
··· 77 77 78 78 #define XLOG_UNMOUNT_TYPE 0x556e /* Un for Unmount */ 79 79 80 + /* 81 + * Log item for unmount records. 82 + * 83 + * The unmount record used to have a string "Unmount filesystem--" in the 84 + * data section where the "Un" was really a magic number (XLOG_UNMOUNT_TYPE). 85 + * We just write the magic number now; see xfs_log_unmount_write. 86 + */ 87 + struct xfs_unmount_log_format { 88 + uint16_t magic; /* XLOG_UNMOUNT_TYPE */ 89 + uint16_t pad1; 90 + uint32_t pad2; /* may as well make it 64 bits */ 91 + }; 92 + 80 93 /* Region types for iovec's i_type */ 81 94 #define XLOG_REG_TYPE_BFORMAT 1 82 95 #define XLOG_REG_TYPE_BCHUNK 2
+69 -62
fs/xfs/xfs_log.c
··· 826 826 * deallocation must not be done until source-end. 827 827 */ 828 828 829 + /* Actually write the unmount record to disk. */ 830 + static void 831 + xfs_log_write_unmount_record( 832 + struct xfs_mount *mp) 833 + { 834 + /* the data section must be 32 bit size aligned */ 835 + struct xfs_unmount_log_format magic = { 836 + .magic = XLOG_UNMOUNT_TYPE, 837 + }; 838 + struct xfs_log_iovec reg = { 839 + .i_addr = &magic, 840 + .i_len = sizeof(magic), 841 + .i_type = XLOG_REG_TYPE_UNMOUNT, 842 + }; 843 + struct xfs_log_vec vec = { 844 + .lv_niovecs = 1, 845 + .lv_iovecp = &reg, 846 + }; 847 + struct xlog *log = mp->m_log; 848 + struct xlog_in_core *iclog; 849 + struct xlog_ticket *tic = NULL; 850 + xfs_lsn_t lsn; 851 + int error; 852 + 853 + error = xfs_log_reserve(mp, 600, 1, &tic, XFS_LOG, 0); 854 + if (error) 855 + goto out_err; 856 + 857 + /* remove inited flag, and account for space used */ 858 + tic->t_flags = 0; 859 + tic->t_curr_res -= sizeof(magic); 860 + error = xlog_write(log, &vec, tic, &lsn, NULL, XLOG_UNMOUNT_TRANS); 861 + /* 862 + * At this point, we're umounting anyway, so there's no point in 863 + * transitioning log state to IOERROR. Just continue... 864 + */ 865 + out_err: 866 + if (error) 867 + xfs_alert(mp, "%s: unmount record failed", __func__); 868 + 869 + spin_lock(&log->l_icloglock); 870 + iclog = log->l_iclog; 871 + atomic_inc(&iclog->ic_refcnt); 872 + xlog_state_want_sync(log, iclog); 873 + spin_unlock(&log->l_icloglock); 874 + error = xlog_state_release_iclog(log, iclog); 875 + 876 + spin_lock(&log->l_icloglock); 877 + switch (iclog->ic_state) { 878 + default: 879 + if (!XLOG_FORCED_SHUTDOWN(log)) { 880 + xlog_wait(&iclog->ic_force_wait, &log->l_icloglock); 881 + break; 882 + } 883 + /* fall through */ 884 + case XLOG_STATE_ACTIVE: 885 + case XLOG_STATE_DIRTY: 886 + spin_unlock(&log->l_icloglock); 887 + break; 888 + } 889 + 890 + if (tic) { 891 + trace_xfs_log_umount_write(log, tic); 892 + xlog_ungrant_log_space(log, tic); 893 + xfs_log_ticket_put(tic); 894 + } 895 + } 896 + 829 897 /* 830 898 * Unmount record used to have a string "Unmount filesystem--" in the 831 899 * data section where the "Un" was really a magic number (XLOG_UNMOUNT_TYPE). ··· 910 842 #ifdef DEBUG 911 843 xlog_in_core_t *first_iclog; 912 844 #endif 913 - xlog_ticket_t *tic = NULL; 914 - xfs_lsn_t lsn; 915 845 int error; 916 846 917 847 /* ··· 936 870 } while (iclog != first_iclog); 937 871 #endif 938 872 if (! (XLOG_FORCED_SHUTDOWN(log))) { 939 - error = xfs_log_reserve(mp, 600, 1, &tic, XFS_LOG, 0); 940 - if (!error) { 941 - /* the data section must be 32 bit size aligned */ 942 - struct { 943 - uint16_t magic; 944 - uint16_t pad1; 945 - uint32_t pad2; /* may as well make it 64 bits */ 946 - } magic = { 947 - .magic = XLOG_UNMOUNT_TYPE, 948 - }; 949 - struct xfs_log_iovec reg = { 950 - .i_addr = &magic, 951 - .i_len = sizeof(magic), 952 - .i_type = XLOG_REG_TYPE_UNMOUNT, 953 - }; 954 - struct xfs_log_vec vec = { 955 - .lv_niovecs = 1, 956 - .lv_iovecp = &reg, 957 - }; 958 - 959 - /* remove inited flag, and account for space used */ 960 - tic->t_flags = 0; 961 - tic->t_curr_res -= sizeof(magic); 962 - error = xlog_write(log, &vec, tic, &lsn, 963 - NULL, XLOG_UNMOUNT_TRANS); 964 - /* 965 - * At this point, we're umounting anyway, 966 - * so there's no point in transitioning log state 967 - * to IOERROR. Just continue... 968 - */ 969 - } 970 - 971 - if (error) 972 - xfs_alert(mp, "%s: unmount record failed", __func__); 973 - 974 - 975 - spin_lock(&log->l_icloglock); 976 - iclog = log->l_iclog; 977 - atomic_inc(&iclog->ic_refcnt); 978 - xlog_state_want_sync(log, iclog); 979 - spin_unlock(&log->l_icloglock); 980 - error = xlog_state_release_iclog(log, iclog); 981 - 982 - spin_lock(&log->l_icloglock); 983 - if (!(iclog->ic_state == XLOG_STATE_ACTIVE || 984 - iclog->ic_state == XLOG_STATE_DIRTY)) { 985 - if (!XLOG_FORCED_SHUTDOWN(log)) { 986 - xlog_wait(&iclog->ic_force_wait, 987 - &log->l_icloglock); 988 - } else { 989 - spin_unlock(&log->l_icloglock); 990 - } 991 - } else { 992 - spin_unlock(&log->l_icloglock); 993 - } 994 - if (tic) { 995 - trace_xfs_log_umount_write(log, tic); 996 - xlog_ungrant_log_space(log, tic); 997 - xfs_log_ticket_put(tic); 998 - } 873 + xfs_log_write_unmount_record(mp); 999 874 } else { 1000 875 /* 1001 876 * We're already in forced_shutdown mode, couldn't