• D
    xfs: make forced shutdown processing atomic · da90a037
    Dave Chinner 提交于
    mainline-inclusion
    from mainline-v5.14-rc4
    commit b36d4651
    category: bugfix
    bugzilla: https://gitee.com/openeuler/kernel/issues/I4V7IK
    CVE: NA
    
    Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=b36d4651e1650082d27fa477318183c4a7210e30
    
    -------------------------------------------------
    
    The running of a forced shutdown is a bit of a mess. It does racy
    checks for XFS_MOUNT_SHUTDOWN in xfs_do_force_shutdown(), then
    does more racy checks in xfs_log_force_unmount() before finally
    setting XFS_MOUNT_SHUTDOWN and XLOG_IO_ERROR under the
    log->icloglock.
    
    Move the checking and setting of XFS_MOUNT_SHUTDOWN into
    xfs_do_force_shutdown() so we only process a shutdown once and once
    only. Serialise this with the mp->m_sb_lock spinlock so that the
    state change is atomic and won't race. Move all the mount specific
    shutdown state changes from xfs_log_force_unmount() to
    xfs_do_force_shutdown() so they are done atomically with setting
    XFS_MOUNT_SHUTDOWN.
    
    Then get rid of the racy xlog_is_shutdown() check from
    xlog_force_shutdown(), and gate the log shutdown on the
    test_and_set_bit(XLOG_IO_ERROR) test under the icloglock. This
    means that the log is shutdown once and once only, and code that
    needs to prevent races with shutdown can do so by holding the
    icloglock and checking the return value of xlog_is_shutdown().
    
    This results in a predictable shutdown execution process - we set the
    shutdown flags once and process the shutdown once rather than the
    current "as many concurrent shutdowns as can race to the flag
    setting" situation we have now.
    
    Also, now that shutdown is atomic, alway emit a stack trace when the
    error level for the filesystem is high enough. This means that we
    always get a stack trace when trying to diagnose the cause of
    shutdowns in the field, rather than just for SHUTDOWN_CORRUPT_INCORE
    cases.
    Signed-off-by: NDave Chinner <dchinner@redhat.com>
    Reviewed-by: NDarrick J. Wong <djwong@kernel.org>
    Reviewed-by: NChristoph Hellwig <hch@lst.de>
    Signed-off-by: NDarrick J. Wong <djwong@kernel.org>
    Signed-off-by: NLihong Kou <koulihong@huawei.com>
    Reviewed-by: NZhang Yi <yi.zhang@huawei.com>
    Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
    da90a037
xfs_log.c 105.5 KB