@@ -3463,13 +3463,59 @@ xfs_bmap_btalloc_accounting(
34633463 args -> len );
34643464}
34653465
3466+ static int
3467+ xfs_bmap_compute_alignments (
3468+ struct xfs_bmalloca * ap ,
3469+ struct xfs_alloc_arg * args )
3470+ {
3471+ struct xfs_mount * mp = args -> mp ;
3472+ xfs_extlen_t align = 0 ; /* minimum allocation alignment */
3473+ int stripe_align = 0 ;
3474+ int error ;
3475+
3476+ /* stripe alignment for allocation is determined by mount parameters */
3477+ if (mp -> m_swidth && (mp -> m_flags & XFS_MOUNT_SWALLOC ))
3478+ stripe_align = mp -> m_swidth ;
3479+ else if (mp -> m_dalign )
3480+ stripe_align = mp -> m_dalign ;
3481+
3482+ if (ap -> flags & XFS_BMAPI_COWFORK )
3483+ align = xfs_get_cowextsz_hint (ap -> ip );
3484+ else if (ap -> datatype & XFS_ALLOC_USERDATA )
3485+ align = xfs_get_extsz_hint (ap -> ip );
3486+ if (align ) {
3487+ error = xfs_bmap_extsize_align (mp , & ap -> got , & ap -> prev ,
3488+ align , 0 , ap -> eof , 0 , ap -> conv ,
3489+ & ap -> offset , & ap -> length );
3490+ ASSERT (!error );
3491+ ASSERT (ap -> length );
3492+ }
3493+
3494+ /* apply extent size hints if obtained earlier */
3495+ if (align ) {
3496+ args -> prod = align ;
3497+ div_u64_rem (ap -> offset , args -> prod , & args -> mod );
3498+ if (args -> mod )
3499+ args -> mod = args -> prod - args -> mod ;
3500+ } else if (mp -> m_sb .sb_blocksize >= PAGE_SIZE ) {
3501+ args -> prod = 1 ;
3502+ args -> mod = 0 ;
3503+ } else {
3504+ args -> prod = PAGE_SIZE >> mp -> m_sb .sb_blocklog ;
3505+ div_u64_rem (ap -> offset , args -> prod , & args -> mod );
3506+ if (args -> mod )
3507+ args -> mod = args -> prod - args -> mod ;
3508+ }
3509+
3510+ return stripe_align ;
3511+ }
3512+
34663513STATIC int
34673514xfs_bmap_btalloc (
34683515 struct xfs_bmalloca * ap ) /* bmap alloc argument struct */
34693516{
34703517 xfs_mount_t * mp ; /* mount point structure */
34713518 xfs_alloctype_t atype = 0 ; /* type for allocation routines */
3472- xfs_extlen_t align = 0 ; /* minimum allocation alignment */
34733519 xfs_agnumber_t fb_agno ; /* ag number of ap->firstblock */
34743520 xfs_agnumber_t ag ;
34753521 xfs_alloc_arg_t args ;
@@ -3489,25 +3535,11 @@ xfs_bmap_btalloc(
34893535
34903536 mp = ap -> ip -> i_mount ;
34913537
3492- /* stripe alignment for allocation is determined by mount parameters */
3493- stripe_align = 0 ;
3494- if (mp -> m_swidth && (mp -> m_flags & XFS_MOUNT_SWALLOC ))
3495- stripe_align = mp -> m_swidth ;
3496- else if (mp -> m_dalign )
3497- stripe_align = mp -> m_dalign ;
3498-
3499- if (ap -> flags & XFS_BMAPI_COWFORK )
3500- align = xfs_get_cowextsz_hint (ap -> ip );
3501- else if (ap -> datatype & XFS_ALLOC_USERDATA )
3502- align = xfs_get_extsz_hint (ap -> ip );
3503- if (align ) {
3504- error = xfs_bmap_extsize_align (mp , & ap -> got , & ap -> prev ,
3505- align , 0 , ap -> eof , 0 , ap -> conv ,
3506- & ap -> offset , & ap -> length );
3507- ASSERT (!error );
3508- ASSERT (ap -> length );
3509- }
3538+ memset (& args , 0 , sizeof (args ));
3539+ args .tp = ap -> tp ;
3540+ args .mp = mp ;
35103541
3542+ stripe_align = xfs_bmap_compute_alignments (ap , & args );
35113543
35123544 nullfb = ap -> tp -> t_firstblock == NULLFSBLOCK ;
35133545 fb_agno = nullfb ? NULLAGNUMBER : XFS_FSB_TO_AGNO (mp ,
@@ -3538,9 +3570,6 @@ xfs_bmap_btalloc(
35383570 * Normal allocation, done through xfs_alloc_vextent.
35393571 */
35403572 tryagain = isaligned = 0 ;
3541- memset (& args , 0 , sizeof (args ));
3542- args .tp = ap -> tp ;
3543- args .mp = mp ;
35443573 args .fsbno = ap -> blkno ;
35453574 args .oinfo = XFS_RMAP_OINFO_SKIP_UPDATE ;
35463575
@@ -3571,21 +3600,7 @@ xfs_bmap_btalloc(
35713600 args .total = ap -> total ;
35723601 args .minlen = ap -> minlen ;
35733602 }
3574- /* apply extent size hints if obtained earlier */
3575- if (align ) {
3576- args .prod = align ;
3577- div_u64_rem (ap -> offset , args .prod , & args .mod );
3578- if (args .mod )
3579- args .mod = args .prod - args .mod ;
3580- } else if (mp -> m_sb .sb_blocksize >= PAGE_SIZE ) {
3581- args .prod = 1 ;
3582- args .mod = 0 ;
3583- } else {
3584- args .prod = PAGE_SIZE >> mp -> m_sb .sb_blocklog ;
3585- div_u64_rem (ap -> offset , args .prod , & args .mod );
3586- if (args .mod )
3587- args .mod = args .prod - args .mod ;
3588- }
3603+
35893604 /*
35903605 * If we are not low on available data blocks, and the underlying
35913606 * logical volume manager is a stripe, and the file offset is zero then
0 commit comments