@@ -826,6 +826,74 @@ xfs_log_mount_cancel(
826826 * deallocation must not be done until source-end.
827827 */
828828
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+
829897/*
830898 * Unmount record used to have a string "Unmount filesystem--" in the
831899 * data section where the "Un" was really a magic number (XLOG_UNMOUNT_TYPE).
@@ -842,8 +910,6 @@ xfs_log_unmount_write(xfs_mount_t *mp)
842910#ifdef DEBUG
843911 xlog_in_core_t * first_iclog ;
844912#endif
845- xlog_ticket_t * tic = NULL ;
846- xfs_lsn_t lsn ;
847913 int error ;
848914
849915 /*
@@ -870,66 +936,7 @@ xfs_log_unmount_write(xfs_mount_t *mp)
870936 } while (iclog != first_iclog );
871937#endif
872938 if (! (XLOG_FORCED_SHUTDOWN (log ))) {
873- error = xfs_log_reserve (mp , 600 , 1 , & tic , XFS_LOG , 0 );
874- if (!error ) {
875- /* the data section must be 32 bit size aligned */
876- struct {
877- uint16_t magic ;
878- uint16_t pad1 ;
879- uint32_t pad2 ; /* may as well make it 64 bits */
880- } magic = {
881- .magic = XLOG_UNMOUNT_TYPE ,
882- };
883- struct xfs_log_iovec reg = {
884- .i_addr = & magic ,
885- .i_len = sizeof (magic ),
886- .i_type = XLOG_REG_TYPE_UNMOUNT ,
887- };
888- struct xfs_log_vec vec = {
889- .lv_niovecs = 1 ,
890- .lv_iovecp = & reg ,
891- };
892-
893- /* remove inited flag, and account for space used */
894- tic -> t_flags = 0 ;
895- tic -> t_curr_res -= sizeof (magic );
896- error = xlog_write (log , & vec , tic , & lsn ,
897- NULL , XLOG_UNMOUNT_TRANS );
898- /*
899- * At this point, we're umounting anyway,
900- * so there's no point in transitioning log state
901- * to IOERROR. Just continue...
902- */
903- }
904-
905- if (error )
906- xfs_alert (mp , "%s: unmount record failed" , __func__ );
907-
908-
909- spin_lock (& log -> l_icloglock );
910- iclog = log -> l_iclog ;
911- atomic_inc (& iclog -> ic_refcnt );
912- xlog_state_want_sync (log , iclog );
913- spin_unlock (& log -> l_icloglock );
914- error = xlog_state_release_iclog (log , iclog );
915-
916- spin_lock (& log -> l_icloglock );
917- if (!(iclog -> ic_state == XLOG_STATE_ACTIVE ||
918- iclog -> ic_state == XLOG_STATE_DIRTY )) {
919- if (!XLOG_FORCED_SHUTDOWN (log )) {
920- xlog_wait (& iclog -> ic_force_wait ,
921- & log -> l_icloglock );
922- } else {
923- spin_unlock (& log -> l_icloglock );
924- }
925- } else {
926- spin_unlock (& log -> l_icloglock );
927- }
928- if (tic ) {
929- trace_xfs_log_umount_write (log , tic );
930- xlog_ungrant_log_space (log , tic );
931- xfs_log_ticket_put (tic );
932- }
939+ xfs_log_write_unmount_record (mp );
933940 } else {
934941 /*
935942 * We're already in forced_shutdown mode, couldn't
0 commit comments