@@ -110,6 +110,13 @@ xfs_da_state_free(xfs_da_state_t *state)
110
110
kmem_cache_free (xfs_da_state_zone , state );
111
111
}
112
112
113
+ static inline int xfs_dabuf_nfsb (struct xfs_mount * mp , int whichfork )
114
+ {
115
+ if (whichfork == XFS_DATA_FORK )
116
+ return mp -> m_dir_geo -> fsbcount ;
117
+ return mp -> m_attr_geo -> fsbcount ;
118
+ }
119
+
113
120
void
114
121
xfs_da3_node_hdr_from_disk (
115
122
struct xfs_mount * mp ,
@@ -2539,7 +2546,7 @@ xfs_dabuf_map(
2539
2546
int * nmaps )
2540
2547
{
2541
2548
struct xfs_mount * mp = dp -> i_mount ;
2542
- int nfsb ;
2549
+ int nfsb = xfs_dabuf_nfsb ( mp , whichfork ) ;
2543
2550
int error = 0 ;
2544
2551
struct xfs_bmbt_irec irec ;
2545
2552
struct xfs_bmbt_irec * irecs = & irec ;
@@ -2548,35 +2555,13 @@ xfs_dabuf_map(
2548
2555
ASSERT (map && * map );
2549
2556
ASSERT (* nmaps == 1 );
2550
2557
2551
- if (whichfork == XFS_DATA_FORK )
2552
- nfsb = mp -> m_dir_geo -> fsbcount ;
2553
- else
2554
- nfsb = mp -> m_attr_geo -> fsbcount ;
2555
-
2556
- /*
2557
- * Caller doesn't have a mapping. -2 means don't complain
2558
- * if we land in a hole.
2559
- */
2560
- if (mappedbno == -1 || mappedbno == -2 ) {
2561
- /*
2562
- * Optimize the one-block case.
2563
- */
2564
- if (nfsb != 1 )
2565
- irecs = kmem_zalloc (sizeof (irec ) * nfsb ,
2566
- KM_NOFS );
2567
-
2568
- nirecs = nfsb ;
2569
- error = xfs_bmapi_read (dp , (xfs_fileoff_t )bno , nfsb , irecs ,
2570
- & nirecs , xfs_bmapi_aflag (whichfork ));
2571
- if (error )
2572
- goto out ;
2573
- } else {
2574
- irecs -> br_startblock = XFS_DADDR_TO_FSB (mp , mappedbno );
2575
- irecs -> br_startoff = (xfs_fileoff_t )bno ;
2576
- irecs -> br_blockcount = nfsb ;
2577
- irecs -> br_state = 0 ;
2578
- nirecs = 1 ;
2579
- }
2558
+ if (nfsb != 1 )
2559
+ irecs = kmem_zalloc (sizeof (irec ) * nfsb , KM_NOFS );
2560
+ nirecs = nfsb ;
2561
+ error = xfs_bmapi_read (dp , (xfs_fileoff_t )bno , nfsb , irecs ,
2562
+ & nirecs , xfs_bmapi_aflag (whichfork ));
2563
+ if (error )
2564
+ goto out ;
2580
2565
2581
2566
if (!xfs_da_map_covers_blocks (nirecs , irecs , bno , nfsb )) {
2582
2567
/* Caller ok with no mapping. */
@@ -2616,37 +2601,42 @@ xfs_dabuf_map(
2616
2601
*/
2617
2602
int
2618
2603
xfs_da_get_buf (
2619
- struct xfs_trans * trans ,
2604
+ struct xfs_trans * tp ,
2620
2605
struct xfs_inode * dp ,
2621
2606
xfs_dablk_t bno ,
2622
2607
xfs_daddr_t mappedbno ,
2623
2608
struct xfs_buf * * bpp ,
2624
2609
int whichfork )
2625
2610
{
2611
+ struct xfs_mount * mp = dp -> i_mount ;
2626
2612
struct xfs_buf * bp ;
2627
- struct xfs_buf_map map ;
2628
- struct xfs_buf_map * mapp ;
2629
- int nmap ;
2613
+ struct xfs_buf_map map , * mapp = & map ;
2614
+ int nmap = 1 ;
2630
2615
int error ;
2631
2616
2632
2617
* bpp = NULL ;
2633
- mapp = & map ;
2634
- nmap = 1 ;
2635
- error = xfs_dabuf_map (dp , bno , mappedbno , whichfork ,
2636
- & mapp , & nmap );
2618
+
2619
+ if (mappedbno >= 0 ) {
2620
+ bp = xfs_trans_get_buf (tp , mp -> m_ddev_targp , mappedbno ,
2621
+ XFS_FSB_TO_BB (mp ,
2622
+ xfs_dabuf_nfsb (mp , whichfork )), 0 );
2623
+ goto done ;
2624
+ }
2625
+
2626
+ error = xfs_dabuf_map (dp , bno , mappedbno , whichfork , & mapp , & nmap );
2637
2627
if (error ) {
2638
2628
/* mapping a hole is not an error, but we don't continue */
2639
2629
if (error == -1 )
2640
2630
error = 0 ;
2641
2631
goto out_free ;
2642
2632
}
2643
2633
2644
- bp = xfs_trans_get_buf_map (trans , dp -> i_mount -> m_ddev_targp ,
2645
- mapp , nmap , 0 );
2634
+ bp = xfs_trans_get_buf_map (tp , mp -> m_ddev_targp , mapp , nmap , 0 );
2635
+ done :
2646
2636
error = bp ? bp -> b_error : - EIO ;
2647
2637
if (error ) {
2648
2638
if (bp )
2649
- xfs_trans_brelse (trans , bp );
2639
+ xfs_trans_brelse (tp , bp );
2650
2640
goto out_free ;
2651
2641
}
2652
2642
@@ -2664,35 +2654,41 @@ xfs_da_get_buf(
2664
2654
*/
2665
2655
int
2666
2656
xfs_da_read_buf (
2667
- struct xfs_trans * trans ,
2657
+ struct xfs_trans * tp ,
2668
2658
struct xfs_inode * dp ,
2669
2659
xfs_dablk_t bno ,
2670
2660
xfs_daddr_t mappedbno ,
2671
2661
struct xfs_buf * * bpp ,
2672
2662
int whichfork ,
2673
2663
const struct xfs_buf_ops * ops )
2674
2664
{
2665
+ struct xfs_mount * mp = dp -> i_mount ;
2675
2666
struct xfs_buf * bp ;
2676
- struct xfs_buf_map map ;
2677
- struct xfs_buf_map * mapp ;
2678
- int nmap ;
2667
+ struct xfs_buf_map map , * mapp = & map ;
2668
+ int nmap = 1 ;
2679
2669
int error ;
2680
2670
2681
2671
* bpp = NULL ;
2682
- mapp = & map ;
2683
- nmap = 1 ;
2684
- error = xfs_dabuf_map (dp , bno , mappedbno , whichfork ,
2685
- & mapp , & nmap );
2672
+
2673
+ if (mappedbno >= 0 ) {
2674
+ error = xfs_trans_read_buf (mp , tp , mp -> m_ddev_targp ,
2675
+ mappedbno , XFS_FSB_TO_BB (mp ,
2676
+ xfs_dabuf_nfsb (mp , whichfork )),
2677
+ 0 , & bp , ops );
2678
+ goto done ;
2679
+ }
2680
+
2681
+ error = xfs_dabuf_map (dp , bno , mappedbno , whichfork , & mapp , & nmap );
2686
2682
if (error ) {
2687
2683
/* mapping a hole is not an error, but we don't continue */
2688
2684
if (error == -1 )
2689
2685
error = 0 ;
2690
2686
goto out_free ;
2691
2687
}
2692
2688
2693
- error = xfs_trans_read_buf_map (dp -> i_mount , trans ,
2694
- dp -> i_mount -> m_ddev_targp ,
2695
- mapp , nmap , 0 , & bp , ops );
2689
+ error = xfs_trans_read_buf_map (mp , tp , mp -> m_ddev_targp , mapp , nmap , 0 ,
2690
+ & bp , ops );
2691
+ done :
2696
2692
if (error )
2697
2693
goto out_free ;
2698
2694
@@ -2724,6 +2720,9 @@ xfs_da_reada_buf(
2724
2720
int nmap ;
2725
2721
int error ;
2726
2722
2723
+ if (mappedbno >= 0 )
2724
+ return - EINVAL ;
2725
+
2727
2726
mapp = & map ;
2728
2727
nmap = 1 ;
2729
2728
error = xfs_dabuf_map (dp , bno , mappedbno , whichfork ,
0 commit comments