@@ -769,23 +769,35 @@ static void readpage_bio_extend(struct readpages_iter *iter,
769
769
}
770
770
}
771
771
772
- static void bchfs_read (struct btree_trans * trans , struct btree_iter * iter ,
773
- struct bch_read_bio * rbio , u64 inum ,
772
+ static void bchfs_read (struct btree_trans * trans ,
773
+ struct bch_read_bio * rbio ,
774
+ subvol_inum inum ,
774
775
struct readpages_iter * readpages_iter )
775
776
{
776
777
struct bch_fs * c = trans -> c ;
778
+ struct btree_iter iter ;
777
779
struct bkey_buf sk ;
778
780
int flags = BCH_READ_RETRY_IF_STALE |
779
781
BCH_READ_MAY_PROMOTE ;
782
+ u32 snapshot ;
780
783
int ret = 0 ;
781
784
782
785
rbio -> c = c ;
783
786
rbio -> start_time = local_clock ();
787
+ rbio -> subvol = inum .subvol ;
784
788
785
789
bch2_bkey_buf_init (& sk );
786
790
retry :
787
791
bch2_trans_begin (trans );
792
+ iter = (struct btree_iter ) { NULL };
788
793
794
+ ret = bch2_subvolume_get_snapshot (trans , inum .subvol , & snapshot );
795
+ if (ret )
796
+ goto err ;
797
+
798
+ bch2_trans_iter_init (trans , & iter , BTREE_ID_extents ,
799
+ SPOS (inum .inum , rbio -> bio .bi_iter .bi_sector , snapshot ),
800
+ BTREE_ITER_SLOTS |BTREE_ITER_FILTER_SNAPSHOTS );
789
801
while (1 ) {
790
802
struct bkey_s_c k ;
791
803
unsigned bytes , sectors , offset_into_extent ;
@@ -800,15 +812,15 @@ static void bchfs_read(struct btree_trans *trans, struct btree_iter *iter,
800
812
break ;
801
813
}
802
814
803
- bch2_btree_iter_set_pos (iter ,
804
- POS (inum , rbio -> bio .bi_iter .bi_sector ));
815
+ bch2_btree_iter_set_pos (& iter ,
816
+ POS (inum . inum , rbio -> bio .bi_iter .bi_sector ));
805
817
806
- k = bch2_btree_iter_peek_slot (iter );
818
+ k = bch2_btree_iter_peek_slot (& iter );
807
819
ret = bkey_err (k );
808
820
if (ret )
809
821
break ;
810
822
811
- offset_into_extent = iter -> pos .offset -
823
+ offset_into_extent = iter . pos .offset -
812
824
bkey_start_offset (k .k );
813
825
sectors = k .k -> size - offset_into_extent ;
814
826
@@ -838,7 +850,7 @@ static void bchfs_read(struct btree_trans *trans, struct btree_iter *iter,
838
850
if (bkey_extent_is_allocation (k .k ))
839
851
bch2_add_page_sectors (& rbio -> bio , k );
840
852
841
- bch2_read_extent (trans , rbio , iter -> pos ,
853
+ bch2_read_extent (trans , rbio , iter . pos ,
842
854
data_btree , k , offset_into_extent , flags );
843
855
844
856
if (flags & BCH_READ_LAST_FRAGMENT )
@@ -847,12 +859,14 @@ static void bchfs_read(struct btree_trans *trans, struct btree_iter *iter,
847
859
swap (rbio -> bio .bi_iter .bi_size , bytes );
848
860
bio_advance (& rbio -> bio , bytes );
849
861
}
862
+ err :
863
+ bch2_trans_iter_exit (trans , & iter );
850
864
851
865
if (ret == - EINTR )
852
866
goto retry ;
853
867
854
868
if (ret ) {
855
- bch_err_inum_ratelimited (c , inum ,
869
+ bch_err_inum_ratelimited (c , inum . inum ,
856
870
"read error %i from btree lookup" , ret );
857
871
rbio -> bio .bi_status = BLK_STS_IOERR ;
858
872
bio_endio (& rbio -> bio );
@@ -867,7 +881,6 @@ void bch2_readahead(struct readahead_control *ractl)
867
881
struct bch_fs * c = inode -> v .i_sb -> s_fs_info ;
868
882
struct bch_io_opts opts = io_opts (c , & inode -> ei_inode );
869
883
struct btree_trans trans ;
870
- struct btree_iter iter ;
871
884
struct page * page ;
872
885
struct readpages_iter readpages_iter ;
873
886
int ret ;
@@ -876,8 +889,6 @@ void bch2_readahead(struct readahead_control *ractl)
876
889
BUG_ON (ret );
877
890
878
891
bch2_trans_init (& trans , c , 0 , 0 );
879
- bch2_trans_iter_init (& trans , & iter , BTREE_ID_extents , POS_MIN ,
880
- BTREE_ITER_SLOTS );
881
892
882
893
bch2_pagecache_add_get (& inode -> ei_pagecache_lock );
883
894
@@ -898,22 +909,20 @@ void bch2_readahead(struct readahead_control *ractl)
898
909
rbio -> bio .bi_end_io = bch2_readpages_end_io ;
899
910
BUG_ON (!bio_add_page (& rbio -> bio , page , PAGE_SIZE , 0 ));
900
911
901
- bchfs_read (& trans , & iter , rbio , inode -> v . i_ino ,
912
+ bchfs_read (& trans , rbio , inode_inum ( inode ) ,
902
913
& readpages_iter );
903
914
}
904
915
905
916
bch2_pagecache_add_put (& inode -> ei_pagecache_lock );
906
917
907
- bch2_trans_iter_exit (& trans , & iter );
908
918
bch2_trans_exit (& trans );
909
919
kfree (readpages_iter .pages );
910
920
}
911
921
912
922
static void __bchfs_readpage (struct bch_fs * c , struct bch_read_bio * rbio ,
913
- u64 inum , struct page * page )
923
+ subvol_inum inum , struct page * page )
914
924
{
915
925
struct btree_trans trans ;
916
- struct btree_iter iter ;
917
926
918
927
bch2_page_state_create (page , __GFP_NOFAIL );
919
928
@@ -923,12 +932,7 @@ static void __bchfs_readpage(struct bch_fs *c, struct bch_read_bio *rbio,
923
932
BUG_ON (!bio_add_page (& rbio -> bio , page , PAGE_SIZE , 0 ));
924
933
925
934
bch2_trans_init (& trans , c , 0 , 0 );
926
- bch2_trans_iter_init (& trans , & iter , BTREE_ID_extents , POS_MIN ,
927
- BTREE_ITER_SLOTS );
928
-
929
- bchfs_read (& trans , & iter , rbio , inum , NULL );
930
-
931
- bch2_trans_iter_exit (& trans , & iter );
935
+ bchfs_read (& trans , rbio , inum , NULL );
932
936
bch2_trans_exit (& trans );
933
937
}
934
938
@@ -951,7 +955,7 @@ static int bch2_read_single_page(struct page *page,
951
955
rbio -> bio .bi_private = & done ;
952
956
rbio -> bio .bi_end_io = bch2_read_single_page_end_io ;
953
957
954
- __bchfs_readpage (c , rbio , inode -> v . i_ino , page );
958
+ __bchfs_readpage (c , rbio , inode_inum ( inode ) , page );
955
959
wait_for_completion (& done );
956
960
957
961
ret = blk_status_to_errno (rbio -> bio .bi_status );
@@ -1096,6 +1100,7 @@ static void bch2_writepage_io_alloc(struct bch_fs *c,
1096
1100
op -> nr_replicas = nr_replicas ;
1097
1101
op -> res .nr_replicas = nr_replicas ;
1098
1102
op -> write_point = writepoint_hashed (inode -> ei_last_dirtied );
1103
+ op -> subvol = inode -> ei_subvol ;
1099
1104
op -> pos = POS (inode -> v .i_ino , sector );
1100
1105
op -> end_io = bch2_writepage_io_done ;
1101
1106
op -> wbio .bio .bi_iter .bi_sector = sector ;
@@ -1733,7 +1738,7 @@ static int bch2_direct_IO_read(struct kiocb *req, struct iov_iter *iter)
1733
1738
if (iter -> count )
1734
1739
closure_get (& dio -> cl );
1735
1740
1736
- bch2_read (c , rbio_init (bio , opts ), inode -> v . i_ino );
1741
+ bch2_read (c , rbio_init (bio , opts ), inode_inum ( inode ) );
1737
1742
}
1738
1743
1739
1744
iter -> count += shorten ;
@@ -1816,7 +1821,8 @@ static bool bch2_check_range_allocated(struct bch_fs *c, subvol_inum inum,
1816
1821
if (bkey_cmp (bkey_start_pos (k .k ), POS (inum .inum , end )) >= 0 )
1817
1822
break ;
1818
1823
1819
- if (nr_replicas > bch2_bkey_replicas (c , k ) ||
1824
+ if (k .k -> p .snapshot != snapshot ||
1825
+ nr_replicas > bch2_bkey_replicas (c , k ) ||
1820
1826
(!compressed && bch2_bkey_sectors_compressed (k ))) {
1821
1827
ret = false;
1822
1828
break ;
@@ -1944,6 +1950,7 @@ static long bch2_dio_write_loop(struct dio_write *dio)
1944
1950
op_journal_seq_set (& dio -> op , & inode -> ei_journal_seq );
1945
1951
dio -> op .write_point = writepoint_hashed ((unsigned long ) current );
1946
1952
dio -> op .nr_replicas = dio -> op .opts .data_replicas ;
1953
+ dio -> op .subvol = inode -> ei_subvol ;
1947
1954
dio -> op .pos = POS (inode -> v .i_ino , (u64 ) req -> ki_pos >> 9 );
1948
1955
1949
1956
if ((req -> ki_flags & IOCB_DSYNC ) &&
@@ -2438,7 +2445,7 @@ int bch2_truncate(struct mnt_idmap *idmap,
2438
2445
2439
2446
truncate_setsize (& inode -> v , iattr -> ia_size );
2440
2447
2441
- ret = bch2_fpunch (c , inode -> v . i_ino ,
2448
+ ret = bch2_fpunch (c , inode_inum ( inode ) ,
2442
2449
round_up (iattr -> ia_size , block_bytes (c )) >> 9 ,
2443
2450
U64_MAX , & inode -> ei_journal_seq , & i_sectors_delta );
2444
2451
i_sectors_acct (c , inode , NULL , i_sectors_delta );
@@ -2498,7 +2505,7 @@ static long bchfs_fpunch(struct bch_inode_info *inode, loff_t offset, loff_t len
2498
2505
if (discard_start < discard_end ) {
2499
2506
s64 i_sectors_delta = 0 ;
2500
2507
2501
- ret = bch2_fpunch (c , inode -> v . i_ino ,
2508
+ ret = bch2_fpunch (c , inode_inum ( inode ) ,
2502
2509
discard_start , discard_end ,
2503
2510
& inode -> ei_journal_seq ,
2504
2511
& i_sectors_delta );
@@ -2577,7 +2584,7 @@ static long bchfs_fcollapse_finsert(struct bch_inode_info *inode,
2577
2584
} else {
2578
2585
s64 i_sectors_delta = 0 ;
2579
2586
2580
- ret = bch2_fpunch (c , inode -> v . i_ino ,
2587
+ ret = bch2_fpunch (c , inode_inum ( inode ) ,
2581
2588
offset >> 9 , (offset + len ) >> 9 ,
2582
2589
& inode -> ei_journal_seq ,
2583
2590
& i_sectors_delta );
@@ -2793,7 +2800,8 @@ static int __bchfs_fallocate(struct bch_inode_info *inode, int mode,
2793
2800
reservation .v .nr_replicas = disk_res .nr_replicas ;
2794
2801
}
2795
2802
2796
- ret = bch2_extent_update (& trans , & iter , & reservation .k_i ,
2803
+ ret = bch2_extent_update (& trans , inode_inum (inode ), & iter ,
2804
+ & reservation .k_i ,
2797
2805
& disk_res , & inode -> ei_journal_seq ,
2798
2806
0 , & i_sectors_delta , true);
2799
2807
i_sectors_acct (c , inode , & quota_res , i_sectors_delta );
0 commit comments