@@ -679,68 +679,46 @@ static inline unsigned int max_pow_of_two_factor(const unsigned int nr)
679679}
680680
681681/*
682- * If the data device advertises atomic write support, limit the size of data
683- * device atomic writes to the greatest power-of-two factor of the AG size so
684- * that every atomic write unit aligns with the start of every AG . This is
685- * required so that the per-AG allocations for an atomic write will always be
682+ * If the underlying device advertises atomic write support, limit the size of
683+ * atomic writes to the greatest power-of-two factor of the group size so
684+ * that every atomic write unit aligns with the start of every group . This is
685+ * required so that the allocations for an atomic write will always be
686686 * aligned compatibly with the alignment requirements of the storage.
687687 *
688- * If the data device doesn't advertise atomic writes, then there are no
689- * alignment restrictions and the largest out-of-place write we can do
690- * ourselves is the number of blocks that user files can allocate from any AG .
688+ * If the device doesn't advertise atomic writes, then there are no alignment
689+ * restrictions and the largest out-of-place write we can do ourselves is the
690+ * number of blocks that user files can allocate from any group .
691691 */
692- static inline xfs_extlen_t xfs_calc_perag_awu_max (struct xfs_mount * mp )
693- {
694- if (mp -> m_ddev_targp -> bt_bdev_awu_min > 0 )
695- return max_pow_of_two_factor (mp -> m_sb .sb_agblocks );
696- return rounddown_pow_of_two (mp -> m_ag_max_usable );
697- }
698-
699- /*
700- * Reflink on the realtime device requires rtgroups, and atomic writes require
701- * reflink.
702- *
703- * If the realtime device advertises atomic write support, limit the size of
704- * data device atomic writes to the greatest power-of-two factor of the rtgroup
705- * size so that every atomic write unit aligns with the start of every rtgroup.
706- * This is required so that the per-rtgroup allocations for an atomic write
707- * will always be aligned compatibly with the alignment requirements of the
708- * storage.
709- *
710- * If the rt device doesn't advertise atomic writes, then there are no
711- * alignment restrictions and the largest out-of-place write we can do
712- * ourselves is the number of blocks that user files can allocate from any
713- * rtgroup.
714- */
715- static inline xfs_extlen_t xfs_calc_rtgroup_awu_max (struct xfs_mount * mp )
692+ static xfs_extlen_t
693+ xfs_calc_group_awu_max (
694+ struct xfs_mount * mp ,
695+ enum xfs_group_type type )
716696{
717- struct xfs_groups * rgs = & mp -> m_groups [XG_TYPE_RTG ];
697+ struct xfs_groups * g = & mp -> m_groups [type ];
698+ struct xfs_buftarg * btp = xfs_group_type_buftarg (mp , type );
718699
719- if (rgs -> blocks == 0 )
700+ if (g -> blocks == 0 )
720701 return 0 ;
721- if (mp -> m_rtdev_targp && mp -> m_rtdev_targp -> bt_bdev_awu_min > 0 )
722- return max_pow_of_two_factor (rgs -> blocks );
723- return rounddown_pow_of_two (rgs -> blocks );
702+ if (btp && btp -> bt_bdev_awu_min > 0 )
703+ return max_pow_of_two_factor (g -> blocks );
704+ return rounddown_pow_of_two (g -> blocks );
724705}
725706
726707/* Compute the maximum atomic write unit size for each section. */
727708static inline void
728709xfs_calc_atomic_write_unit_max (
729- struct xfs_mount * mp )
710+ struct xfs_mount * mp ,
711+ enum xfs_group_type type )
730712{
731- struct xfs_groups * ags = & mp -> m_groups [XG_TYPE_AG ];
732- struct xfs_groups * rgs = & mp -> m_groups [XG_TYPE_RTG ];
713+ struct xfs_groups * g = & mp -> m_groups [type ];
733714
734715 const xfs_extlen_t max_write = xfs_calc_atomic_write_max (mp );
735716 const xfs_extlen_t max_ioend = xfs_reflink_max_atomic_cow (mp );
736- const xfs_extlen_t max_agsize = xfs_calc_perag_awu_max (mp );
737- const xfs_extlen_t max_rgsize = xfs_calc_rtgroup_awu_max (mp );
738-
739- ags -> awu_max = min3 (max_write , max_ioend , max_agsize );
740- rgs -> awu_max = min3 (max_write , max_ioend , max_rgsize );
717+ const xfs_extlen_t max_gsize = xfs_calc_group_awu_max (mp , type );
741718
742- trace_xfs_calc_atomic_write_unit_max (mp , max_write , max_ioend ,
743- max_agsize , max_rgsize );
719+ g -> awu_max = min3 (max_write , max_ioend , max_gsize );
720+ trace_xfs_calc_atomic_write_unit_max (mp , type , max_write , max_ioend ,
721+ max_gsize , g -> awu_max );
744722}
745723
746724/*
@@ -758,7 +736,8 @@ xfs_set_max_atomic_write_opt(
758736 max (mp -> m_groups [XG_TYPE_AG ].blocks ,
759737 mp -> m_groups [XG_TYPE_RTG ].blocks );
760738 const xfs_extlen_t max_group_write =
761- max (xfs_calc_perag_awu_max (mp ), xfs_calc_rtgroup_awu_max (mp ));
739+ max (xfs_calc_group_awu_max (mp , XG_TYPE_AG ),
740+ xfs_calc_group_awu_max (mp , XG_TYPE_RTG ));
762741 int error ;
763742
764743 if (new_max_bytes == 0 )
@@ -814,7 +793,8 @@ xfs_set_max_atomic_write_opt(
814793 return error ;
815794 }
816795
817- xfs_calc_atomic_write_unit_max (mp );
796+ xfs_calc_atomic_write_unit_max (mp , XG_TYPE_AG );
797+ xfs_calc_atomic_write_unit_max (mp , XG_TYPE_RTG );
818798 mp -> m_awu_max_bytes = new_max_bytes ;
819799 return 0 ;
820800}
0 commit comments