@@ -1466,34 +1466,39 @@ static int __allocate_data_block(struct dnode_of_data *dn, int seg_type)
14661466 return 0 ;
14671467}
14681468
1469- static void f2fs_map_lock (struct f2fs_sb_info * sbi , int flag )
1469+ static void f2fs_map_lock (struct f2fs_sb_info * sbi ,
1470+ struct f2fs_lock_context * lc ,
1471+ int flag )
14701472{
14711473 f2fs_down_read (& sbi -> cp_enable_rwsem );
14721474 if (flag == F2FS_GET_BLOCK_PRE_AIO )
14731475 f2fs_down_read (& sbi -> node_change );
14741476 else
1475- f2fs_lock_op (sbi );
1477+ f2fs_lock_op (sbi , lc );
14761478}
14771479
1478- static void f2fs_map_unlock (struct f2fs_sb_info * sbi , int flag )
1480+ static void f2fs_map_unlock (struct f2fs_sb_info * sbi ,
1481+ struct f2fs_lock_context * lc ,
1482+ int flag )
14791483{
14801484 if (flag == F2FS_GET_BLOCK_PRE_AIO )
14811485 f2fs_up_read (& sbi -> node_change );
14821486 else
1483- f2fs_unlock_op (sbi );
1487+ f2fs_unlock_op (sbi , lc );
14841488 f2fs_up_read (& sbi -> cp_enable_rwsem );
14851489}
14861490
14871491int f2fs_get_block_locked (struct dnode_of_data * dn , pgoff_t index )
14881492{
14891493 struct f2fs_sb_info * sbi = F2FS_I_SB (dn -> inode );
1494+ struct f2fs_lock_context lc ;
14901495 int err = 0 ;
14911496
1492- f2fs_map_lock (sbi , F2FS_GET_BLOCK_PRE_AIO );
1497+ f2fs_map_lock (sbi , & lc , F2FS_GET_BLOCK_PRE_AIO );
14931498 if (!f2fs_lookup_read_extent_cache_block (dn -> inode , index ,
14941499 & dn -> data_blkaddr ))
14951500 err = f2fs_reserve_block (dn , index );
1496- f2fs_map_unlock (sbi , F2FS_GET_BLOCK_PRE_AIO );
1501+ f2fs_map_unlock (sbi , & lc , F2FS_GET_BLOCK_PRE_AIO );
14971502
14981503 return err ;
14991504}
@@ -1584,6 +1589,7 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, int flag)
15841589 unsigned int maxblocks = map -> m_len ;
15851590 struct dnode_of_data dn ;
15861591 struct f2fs_sb_info * sbi = F2FS_I_SB (inode );
1592+ struct f2fs_lock_context lc ;
15871593 int mode = map -> m_may_create ? ALLOC_NODE : LOOKUP_NODE ;
15881594 pgoff_t pgofs , end_offset , end ;
15891595 int err = 0 , ofs = 1 ;
@@ -1622,7 +1628,7 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, int flag)
16221628 if (map -> m_may_create ) {
16231629 if (f2fs_lfs_mode (sbi ))
16241630 f2fs_balance_fs (sbi , true);
1625- f2fs_map_lock (sbi , flag );
1631+ f2fs_map_lock (sbi , & lc , flag );
16261632 }
16271633
16281634 /* When reading holes, we need its node page */
@@ -1788,7 +1794,7 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, int flag)
17881794 f2fs_put_dnode (& dn );
17891795
17901796 if (map -> m_may_create ) {
1791- f2fs_map_unlock (sbi , flag );
1797+ f2fs_map_unlock (sbi , & lc , flag );
17921798 f2fs_balance_fs (sbi , dn .node_changed );
17931799 }
17941800 goto next_dnode ;
@@ -1835,7 +1841,7 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, int flag)
18351841 f2fs_put_dnode (& dn );
18361842unlock_out :
18371843 if (map -> m_may_create ) {
1838- f2fs_map_unlock (sbi , flag );
1844+ f2fs_map_unlock (sbi , & lc , flag );
18391845 f2fs_balance_fs (sbi , dn .node_changed );
18401846 }
18411847out :
@@ -2865,6 +2871,7 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio)
28652871 struct inode * inode = folio -> mapping -> host ;
28662872 struct dnode_of_data dn ;
28672873 struct node_info ni ;
2874+ struct f2fs_lock_context lc ;
28682875 bool ipu_force = false;
28692876 bool atomic_commit ;
28702877 int err = 0 ;
@@ -2890,7 +2897,7 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio)
28902897 }
28912898
28922899 /* Deadlock due to between page->lock and f2fs_lock_op */
2893- if (fio -> need_lock == LOCK_REQ && !f2fs_trylock_op (fio -> sbi ))
2900+ if (fio -> need_lock == LOCK_REQ && !f2fs_trylock_op (fio -> sbi , & lc ))
28942901 return - EAGAIN ;
28952902
28962903 err = f2fs_get_dnode_of_data (& dn , folio -> index , LOOKUP_NODE );
@@ -2931,7 +2938,7 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio)
29312938 folio_start_writeback (folio );
29322939 f2fs_put_dnode (& dn );
29332940 if (fio -> need_lock == LOCK_REQ )
2934- f2fs_unlock_op (fio -> sbi );
2941+ f2fs_unlock_op (fio -> sbi , & lc );
29352942 err = f2fs_inplace_write_data (fio );
29362943 if (err ) {
29372944 if (fscrypt_inode_uses_fs_layer_crypto (inode ))
@@ -2945,7 +2952,7 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio)
29452952 }
29462953
29472954 if (fio -> need_lock == LOCK_RETRY ) {
2948- if (!f2fs_trylock_op (fio -> sbi )) {
2955+ if (!f2fs_trylock_op (fio -> sbi , & lc )) {
29492956 err = - EAGAIN ;
29502957 goto out_writepage ;
29512958 }
@@ -2977,7 +2984,7 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio)
29772984 f2fs_put_dnode (& dn );
29782985out :
29792986 if (fio -> need_lock == LOCK_REQ )
2980- f2fs_unlock_op (fio -> sbi );
2987+ f2fs_unlock_op (fio -> sbi , & lc );
29812988 return err ;
29822989}
29832990
@@ -3570,6 +3577,7 @@ static int prepare_write_begin(struct f2fs_sb_info *sbi,
35703577 struct inode * inode = folio -> mapping -> host ;
35713578 pgoff_t index = folio -> index ;
35723579 struct dnode_of_data dn ;
3580+ struct f2fs_lock_context lc ;
35733581 struct folio * ifolio ;
35743582 bool locked = false;
35753583 int flag = F2FS_GET_BLOCK_PRE_AIO ;
@@ -3586,10 +3594,10 @@ static int prepare_write_begin(struct f2fs_sb_info *sbi,
35863594 if (f2fs_has_inline_data (inode )) {
35873595 if (pos + len > MAX_INLINE_DATA (inode ))
35883596 flag = F2FS_GET_BLOCK_DEFAULT ;
3589- f2fs_map_lock (sbi , flag );
3597+ f2fs_map_lock (sbi , & lc , flag );
35903598 locked = true;
35913599 } else if ((pos & PAGE_MASK ) >= i_size_read (inode )) {
3592- f2fs_map_lock (sbi , flag );
3600+ f2fs_map_lock (sbi , & lc , flag );
35933601 locked = true;
35943602 }
35953603
@@ -3633,7 +3641,7 @@ static int prepare_write_begin(struct f2fs_sb_info *sbi,
36333641 if (!err && dn .data_blkaddr != NULL_ADDR )
36343642 goto out ;
36353643 f2fs_put_dnode (& dn );
3636- f2fs_map_lock (sbi , F2FS_GET_BLOCK_PRE_AIO );
3644+ f2fs_map_lock (sbi , & lc , F2FS_GET_BLOCK_PRE_AIO );
36373645 WARN_ON (flag != F2FS_GET_BLOCK_PRE_AIO );
36383646 locked = true;
36393647 goto restart ;
@@ -3647,7 +3655,7 @@ static int prepare_write_begin(struct f2fs_sb_info *sbi,
36473655 f2fs_put_dnode (& dn );
36483656unlock_out :
36493657 if (locked )
3650- f2fs_map_unlock (sbi , flag );
3658+ f2fs_map_unlock (sbi , & lc , flag );
36513659 return err ;
36523660}
36533661
@@ -3683,10 +3691,11 @@ static int __reserve_data_block(struct inode *inode, pgoff_t index,
36833691{
36843692 struct f2fs_sb_info * sbi = F2FS_I_SB (inode );
36853693 struct dnode_of_data dn ;
3694+ struct f2fs_lock_context lc ;
36863695 struct folio * ifolio ;
36873696 int err = 0 ;
36883697
3689- f2fs_map_lock (sbi , F2FS_GET_BLOCK_PRE_AIO );
3698+ f2fs_map_lock (sbi , & lc , F2FS_GET_BLOCK_PRE_AIO );
36903699
36913700 ifolio = f2fs_get_inode_folio (sbi , inode -> i_ino );
36923701 if (IS_ERR (ifolio )) {
@@ -3704,7 +3713,7 @@ static int __reserve_data_block(struct inode *inode, pgoff_t index,
37043713 f2fs_put_dnode (& dn );
37053714
37063715unlock_out :
3707- f2fs_map_unlock (sbi , F2FS_GET_BLOCK_PRE_AIO );
3716+ f2fs_map_unlock (sbi , & lc , F2FS_GET_BLOCK_PRE_AIO );
37083717 return err ;
37093718}
37103719
0 commit comments