xfs: take m_growlock when running growfsrt

Take the grow lock when we're expanding the realtime volume, like we do
for the other growfs calls.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>

authored by Darrick J. Wong and committed by Chandan Babu R 16e1fbdc ca6448ae

+25 -13
+25 -13
fs/xfs/xfs_rtalloc.c
··· 821 821 /* Needs to have been mounted with an rt device. */ 822 822 if (!XFS_IS_REALTIME_MOUNT(mp)) 823 823 return -EINVAL; 824 + 825 + if (!mutex_trylock(&mp->m_growlock)) 826 + return -EWOULDBLOCK; 824 827 /* 825 828 * Mount should fail if the rt bitmap/summary files don't load, but 826 829 * we'll check anyway. 827 830 */ 831 + error = -EINVAL; 828 832 if (!mp->m_rbmip || !mp->m_rsumip) 829 - return -EINVAL; 833 + goto out_unlock; 830 834 831 835 /* Shrink not supported. */ 832 836 if (in->newblocks <= sbp->sb_rblocks) 833 - return -EINVAL; 837 + goto out_unlock; 834 838 835 839 /* Can only change rt extent size when adding rt volume. */ 836 840 if (sbp->sb_rblocks > 0 && in->extsize != sbp->sb_rextsize) 837 - return -EINVAL; 841 + goto out_unlock; 838 842 839 843 /* Range check the extent size. */ 840 844 if (XFS_FSB_TO_B(mp, in->extsize) > XFS_MAX_RTEXTSIZE || 841 845 XFS_FSB_TO_B(mp, in->extsize) < XFS_MIN_RTEXTSIZE) 842 - return -EINVAL; 846 + goto out_unlock; 843 847 844 848 /* Unsupported realtime features. */ 849 + error = -EOPNOTSUPP; 845 850 if (xfs_has_rmapbt(mp) || xfs_has_reflink(mp) || xfs_has_quota(mp)) 846 - return -EOPNOTSUPP; 851 + goto out_unlock; 847 852 848 853 nrblocks = in->newblocks; 849 854 error = xfs_sb_validate_fsb_count(sbp, nrblocks); 850 855 if (error) 851 - return error; 856 + goto out_unlock; 852 857 /* 853 858 * Read in the last block of the device, make sure it exists. 854 859 */ ··· 861 856 XFS_FSB_TO_BB(mp, nrblocks - 1), 862 857 XFS_FSB_TO_BB(mp, 1), 0, &bp, NULL); 863 858 if (error) 864 - return error; 859 + goto out_unlock; 865 860 xfs_buf_relse(bp); 866 861 867 862 /* ··· 869 864 */ 870 865 nrextents = nrblocks; 871 866 do_div(nrextents, in->extsize); 872 - if (!xfs_validate_rtextents(nrextents)) 873 - return -EINVAL; 867 + if (!xfs_validate_rtextents(nrextents)) { 868 + error = -EINVAL; 869 + goto out_unlock; 870 + } 874 871 nrbmblocks = xfs_rtbitmap_blockcount(mp, nrextents); 875 872 nrextslog = xfs_compute_rextslog(nrextents); 876 873 nrsumlevels = nrextslog + 1; ··· 883 876 * the log. This prevents us from getting a log overflow, 884 877 * since we'll log basically the whole summary file at once. 885 878 */ 886 - if (nrsumblocks > (mp->m_sb.sb_logblocks >> 1)) 887 - return -EINVAL; 879 + if (nrsumblocks > (mp->m_sb.sb_logblocks >> 1)) { 880 + error = -EINVAL; 881 + goto out_unlock; 882 + } 883 + 888 884 /* 889 885 * Get the old block counts for bitmap and summary inodes. 890 886 * These can't change since other growfs callers are locked out. ··· 899 889 */ 900 890 error = xfs_growfs_rt_alloc(mp, rbmblocks, nrbmblocks, mp->m_rbmip); 901 891 if (error) 902 - return error; 892 + goto out_unlock; 903 893 error = xfs_growfs_rt_alloc(mp, rsumblocks, nrsumblocks, mp->m_rsumip); 904 894 if (error) 905 - return error; 895 + goto out_unlock; 906 896 907 897 rsum_cache = mp->m_rsum_cache; 908 898 if (nrbmblocks != sbp->sb_rbmblocks) ··· 1069 1059 } 1070 1060 } 1071 1061 1062 + out_unlock: 1063 + mutex_unlock(&mp->m_growlock); 1072 1064 return error; 1073 1065 } 1074 1066