@@ -1031,6 +1031,31 @@ static void set_cluster_writeback(struct compress_ctx *cc)
10311031 }
10321032}
10331033
1034+ static void cancel_cluster_writeback (struct compress_ctx * cc ,
1035+ struct compress_io_ctx * cic , int submitted )
1036+ {
1037+ int i ;
1038+
1039+ /* Wait for submitted IOs. */
1040+ if (submitted > 1 ) {
1041+ f2fs_submit_merged_write (F2FS_I_SB (cc -> inode ), DATA );
1042+ while (atomic_read (& cic -> pending_pages ) !=
1043+ (cc -> valid_nr_cpages - submitted + 1 ))
1044+ f2fs_io_schedule_timeout (DEFAULT_IO_TIMEOUT );
1045+ }
1046+
1047+ /* Cancel writeback and stay locked. */
1048+ for (i = 0 ; i < cc -> cluster_size ; i ++ ) {
1049+ if (i < submitted ) {
1050+ inode_inc_dirty_pages (cc -> inode );
1051+ lock_page (cc -> rpages [i ]);
1052+ }
1053+ clear_page_private_gcing (cc -> rpages [i ]);
1054+ if (folio_test_writeback (page_folio (cc -> rpages [i ])))
1055+ end_page_writeback (cc -> rpages [i ]);
1056+ }
1057+ }
1058+
10341059static void set_cluster_dirty (struct compress_ctx * cc )
10351060{
10361061 int i ;
@@ -1232,7 +1257,6 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc,
12321257 .page = NULL ,
12331258 .encrypted_page = NULL ,
12341259 .compressed_page = NULL ,
1235- .submitted = 0 ,
12361260 .io_type = io_type ,
12371261 .io_wbc = wbc ,
12381262 .encrypted = fscrypt_inode_uses_fs_layer_crypto (cc -> inode ) ?
@@ -1358,7 +1382,16 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc,
13581382 fio .compressed_page = cc -> cpages [i - 1 ];
13591383
13601384 cc -> cpages [i - 1 ] = NULL ;
1385+ fio .submitted = 0 ;
13611386 f2fs_outplace_write_data (& dn , & fio );
1387+ if (unlikely (!fio .submitted )) {
1388+ cancel_cluster_writeback (cc , cic , i );
1389+
1390+ /* To call fscrypt_finalize_bounce_page */
1391+ i = cc -> valid_nr_cpages ;
1392+ * submitted = 0 ;
1393+ goto out_destroy_crypt ;
1394+ }
13621395 (* submitted )++ ;
13631396unlock_continue :
13641397 inode_dec_dirty_pages (cc -> inode );
@@ -1392,8 +1425,11 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc,
13921425out_destroy_crypt :
13931426 page_array_free (cc -> inode , cic -> rpages , cc -> cluster_size );
13941427
1395- for (-- i ; i >= 0 ; i -- )
1428+ for (-- i ; i >= 0 ; i -- ) {
1429+ if (!cc -> cpages [i ])
1430+ continue ;
13961431 fscrypt_finalize_bounce_page (& cc -> cpages [i ]);
1432+ }
13971433out_put_cic :
13981434 kmem_cache_free (cic_entry_slab , cic );
13991435out_put_dnode :
0 commit comments