@@ -587,7 +587,7 @@ static noinline int __bchfs_fallocate(struct bch_inode_info *inode, int mode,
587587 POS (inode -> v .i_ino , start_sector ),
588588 BTREE_ITER_slots |BTREE_ITER_intent );
589589
590- while (!ret && bkey_lt ( iter . pos , end_pos ) ) {
590+ while (!ret ) {
591591 s64 i_sectors_delta = 0 ;
592592 struct quota_res quota_res = { 0 };
593593 struct bkey_s_c k ;
@@ -598,6 +598,9 @@ static noinline int __bchfs_fallocate(struct bch_inode_info *inode, int mode,
598598
599599 bch2_trans_begin (trans );
600600
601+ if (bkey_ge (iter .pos , end_pos ))
602+ break ;
603+
601604 ret = bch2_subvolume_get_snapshot (trans ,
602605 inode -> ei_inum .subvol , & snapshot );
603606 if (ret )
@@ -634,12 +637,15 @@ static noinline int __bchfs_fallocate(struct bch_inode_info *inode, int mode,
634637 if (bch2_clamp_data_hole (& inode -> v ,
635638 & hole_start ,
636639 & hole_end ,
637- opts .data_replicas , true))
640+ opts .data_replicas , true)) {
638641 ret = drop_locks_do (trans ,
639642 (bch2_clamp_data_hole (& inode -> v ,
640643 & hole_start ,
641644 & hole_end ,
642645 opts .data_replicas , false), 0 ));
646+ if (ret )
647+ goto bkey_err ;
648+ }
643649 bch2_btree_iter_set_pos (& iter , POS (iter .pos .inode , hole_start ));
644650
645651 if (ret )
@@ -667,10 +673,13 @@ static noinline int __bchfs_fallocate(struct bch_inode_info *inode, int mode,
667673 bch2_i_sectors_acct (c , inode , & quota_res , i_sectors_delta );
668674
669675 if (bch2_mark_pagecache_reserved (inode , & hole_start ,
670- iter .pos .offset , true))
671- drop_locks_do (trans ,
676+ iter .pos .offset , true)) {
677+ ret = drop_locks_do (trans ,
672678 bch2_mark_pagecache_reserved (inode , & hole_start ,
673679 iter .pos .offset , false));
680+ if (ret )
681+ goto bkey_err ;
682+ }
674683bkey_err :
675684 bch2_quota_reservation_put (c , inode , & quota_res );
676685 if (bch2_err_matches (ret , BCH_ERR_transaction_restart ))
0 commit comments