@@ -171,19 +171,16 @@ xfs_readsb(
171171 ASSERT (mp -> m_ddev_targp != NULL );
172172
173173 /*
174- * For the initial read, we must guess at the sector
175- * size based on the block device. It's enough to
176- * get the sb_sectsize out of the superblock and
177- * then reread with the proper length.
178- * We don't verify it yet, because it may not be complete.
174+ * In the first pass, use the device sector size to just read enough
175+ * of the superblock to extract the XFS sector size.
176+ *
177+ * The device sector size must be smaller than or equal to the XFS
178+ * sector size and thus we can always read the superblock. Once we know
179+ * the XFS sector size, re-read it and run the buffer verifier.
179180 */
180- sector_size = xfs_getsize_buftarg ( mp -> m_ddev_targp ) ;
181+ sector_size = mp -> m_ddev_targp -> bt_logical_sectorsize ;
181182 buf_ops = NULL ;
182183
183- /*
184- * Allocate a (locked) buffer to hold the superblock. This will be kept
185- * around at all times to optimize access to the superblock.
186- */
187184reread :
188185 error = xfs_buf_read_uncached (mp -> m_ddev_targp , XFS_SB_DADDR ,
189186 BTOBB (sector_size ), & bp , buf_ops );
@@ -247,6 +244,10 @@ xfs_readsb(
247244 /* no need to be quiet anymore, so reset the buf ops */
248245 bp -> b_ops = & xfs_sb_buf_ops ;
249246
247+ /*
248+ * Keep a pointer of the sb buffer around instead of caching it in the
249+ * buffer cache because we access it frequently.
250+ */
250251 mp -> m_sb_bp = bp ;
251252 xfs_buf_unlock (bp );
252253 return 0 ;
@@ -678,68 +679,46 @@ static inline unsigned int max_pow_of_two_factor(const unsigned int nr)
678679}
679680
680681/*
681- * If the data device advertises atomic write support, limit the size of data
682- * device atomic writes to the greatest power-of-two factor of the AG size so
683- * that every atomic write unit aligns with the start of every AG . This is
684- * 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
685686 * aligned compatibly with the alignment requirements of the storage.
686687 *
687- * If the data device doesn't advertise atomic writes, then there are no
688- * alignment restrictions and the largest out-of-place write we can do
689- * ourselves is the number of blocks that user files can allocate from any AG.
690- */
691- static inline xfs_extlen_t xfs_calc_perag_awu_max (struct xfs_mount * mp )
692- {
693- if (mp -> m_ddev_targp -> bt_bdev_awu_min > 0 )
694- return max_pow_of_two_factor (mp -> m_sb .sb_agblocks );
695- return rounddown_pow_of_two (mp -> m_ag_max_usable );
696- }
697-
698- /*
699- * Reflink on the realtime device requires rtgroups, and atomic writes require
700- * reflink.
701- *
702- * If the realtime device advertises atomic write support, limit the size of
703- * data device atomic writes to the greatest power-of-two factor of the rtgroup
704- * size so that every atomic write unit aligns with the start of every rtgroup.
705- * This is required so that the per-rtgroup allocations for an atomic write
706- * will always be aligned compatibly with the alignment requirements of the
707- * storage.
708- *
709- * If the rt device doesn't advertise atomic writes, then there are no
710- * alignment restrictions and the largest out-of-place write we can do
711- * ourselves is the number of blocks that user files can allocate from any
712- * rtgroup.
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.
713691 */
714- 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 )
715696{
716- 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 );
717699
718- if (rgs -> blocks == 0 )
700+ if (g -> blocks == 0 )
719701 return 0 ;
720- if (mp -> m_rtdev_targp && mp -> m_rtdev_targp -> bt_bdev_awu_min > 0 )
721- return max_pow_of_two_factor (rgs -> blocks );
722- return rounddown_pow_of_two (rgs -> blocks );
702+ if (btp && btp -> bt_awu_min > 0 )
703+ return max_pow_of_two_factor (g -> blocks );
704+ return rounddown_pow_of_two (g -> blocks );
723705}
724706
725707/* Compute the maximum atomic write unit size for each section. */
726708static inline void
727709xfs_calc_atomic_write_unit_max (
728- struct xfs_mount * mp )
710+ struct xfs_mount * mp ,
711+ enum xfs_group_type type )
729712{
730- struct xfs_groups * ags = & mp -> m_groups [XG_TYPE_AG ];
731- struct xfs_groups * rgs = & mp -> m_groups [XG_TYPE_RTG ];
713+ struct xfs_groups * g = & mp -> m_groups [type ];
732714
733715 const xfs_extlen_t max_write = xfs_calc_atomic_write_max (mp );
734716 const xfs_extlen_t max_ioend = xfs_reflink_max_atomic_cow (mp );
735- const xfs_extlen_t max_agsize = xfs_calc_perag_awu_max (mp );
736- const xfs_extlen_t max_rgsize = xfs_calc_rtgroup_awu_max (mp );
737-
738- ags -> awu_max = min3 (max_write , max_ioend , max_agsize );
739- rgs -> awu_max = min3 (max_write , max_ioend , max_rgsize );
717+ const xfs_extlen_t max_gsize = xfs_calc_group_awu_max (mp , type );
740718
741- trace_xfs_calc_atomic_write_unit_max (mp , max_write , max_ioend ,
742- 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 );
743722}
744723
745724/*
@@ -757,7 +736,8 @@ xfs_set_max_atomic_write_opt(
757736 max (mp -> m_groups [XG_TYPE_AG ].blocks ,
758737 mp -> m_groups [XG_TYPE_RTG ].blocks );
759738 const xfs_extlen_t max_group_write =
760- 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 ));
761741 int error ;
762742
763743 if (new_max_bytes == 0 )
@@ -813,7 +793,8 @@ xfs_set_max_atomic_write_opt(
813793 return error ;
814794 }
815795
816- 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 );
817798 mp -> m_awu_max_bytes = new_max_bytes ;
818799 return 0 ;
819800}
0 commit comments