···177177 XFS_IFORK_NEXTENTS(ip, XFS_DATA_FORK) > tip->i_df.if_ext_max)178178 return EINVAL;179179180180- /* Check root block of temp in btree form to max in target */180180+ /*181181+ * If we are in a btree format, check that the temp root block will fit182182+ * in the target and that it has enough extents to be in btree format183183+ * in the target.184184+ *185185+ * Note that we have to be careful to allow btree->extent conversions186186+ * (a common defrag case) which will occur when the temp inode is in187187+ * extent format...188188+ */181189 if (tip->i_d.di_format == XFS_DINODE_FMT_BTREE &&182182- XFS_IFORK_BOFF(ip) &&183183- tip->i_df.if_broot_bytes > XFS_IFORK_BOFF(ip))190190+ ((XFS_IFORK_BOFF(ip) &&191191+ tip->i_df.if_broot_bytes > XFS_IFORK_BOFF(ip)) ||192192+ XFS_IFORK_NEXTENTS(tip, XFS_DATA_FORK) <= ip->i_df.if_ext_max))184193 return EINVAL;185194186186- /* Check root block of target in btree form to max in temp */195195+ /* Reciprocal target->temp btree format checks */187196 if (ip->i_d.di_format == XFS_DINODE_FMT_BTREE &&188188- XFS_IFORK_BOFF(tip) &&189189- ip->i_df.if_broot_bytes > XFS_IFORK_BOFF(tip))197197+ ((XFS_IFORK_BOFF(tip) &&198198+ ip->i_df.if_broot_bytes > XFS_IFORK_BOFF(tip)) ||199199+ XFS_IFORK_NEXTENTS(ip, XFS_DATA_FORK) <= tip->i_df.if_ext_max))190200 return EINVAL;191201192202 return 0;