@@ -733,28 +733,27 @@ static int __iomap_write_begin(const struct iomap_iter *iter, size_t len,
733
733
return 0 ;
734
734
}
735
735
736
- static struct folio * __iomap_get_folio (struct iomap_iter * iter , size_t len )
736
+ static struct folio * __iomap_get_folio (struct iomap_iter * iter ,
737
+ const struct iomap_write_ops * write_ops , size_t len )
737
738
{
738
- const struct iomap_folio_ops * folio_ops = iter -> iomap .folio_ops ;
739
739
loff_t pos = iter -> pos ;
740
740
741
741
if (!mapping_large_folio_support (iter -> inode -> i_mapping ))
742
742
len = min_t (size_t , len , PAGE_SIZE - offset_in_page (pos ));
743
743
744
- if (folio_ops && folio_ops -> get_folio )
745
- return folio_ops -> get_folio (iter , pos , len );
746
- else
747
- return iomap_get_folio (iter , pos , len );
744
+ if (write_ops && write_ops -> get_folio )
745
+ return write_ops -> get_folio (iter , pos , len );
746
+ return iomap_get_folio (iter , pos , len );
748
747
}
749
748
750
- static void __iomap_put_folio (struct iomap_iter * iter , size_t ret ,
749
+ static void __iomap_put_folio (struct iomap_iter * iter ,
750
+ const struct iomap_write_ops * write_ops , size_t ret ,
751
751
struct folio * folio )
752
752
{
753
- const struct iomap_folio_ops * folio_ops = iter -> iomap .folio_ops ;
754
753
loff_t pos = iter -> pos ;
755
754
756
- if (folio_ops && folio_ops -> put_folio ) {
757
- folio_ops -> put_folio (iter -> inode , pos , ret , folio );
755
+ if (write_ops && write_ops -> put_folio ) {
756
+ write_ops -> put_folio (iter -> inode , pos , ret , folio );
758
757
} else {
759
758
folio_unlock (folio );
760
759
folio_put (folio );
@@ -791,10 +790,10 @@ static int iomap_write_begin_inline(const struct iomap_iter *iter,
791
790
* offset, and length. Callers can optionally pass a max length *plen,
792
791
* otherwise init to zero.
793
792
*/
794
- static int iomap_write_begin (struct iomap_iter * iter , struct folio * * foliop ,
793
+ static int iomap_write_begin (struct iomap_iter * iter ,
794
+ const struct iomap_write_ops * write_ops , struct folio * * foliop ,
795
795
size_t * poffset , u64 * plen )
796
796
{
797
- const struct iomap_folio_ops * folio_ops = iter -> iomap .folio_ops ;
798
797
const struct iomap * srcmap = iomap_iter_srcmap (iter );
799
798
loff_t pos = iter -> pos ;
800
799
u64 len = min_t (u64 , SIZE_MAX , iomap_length (iter ));
@@ -809,7 +808,7 @@ static int iomap_write_begin(struct iomap_iter *iter, struct folio **foliop,
809
808
if (fatal_signal_pending (current ))
810
809
return - EINTR ;
811
810
812
- folio = __iomap_get_folio (iter , len );
811
+ folio = __iomap_get_folio (iter , write_ops , len );
813
812
if (IS_ERR (folio ))
814
813
return PTR_ERR (folio );
815
814
@@ -823,8 +822,8 @@ static int iomap_write_begin(struct iomap_iter *iter, struct folio **foliop,
823
822
* could do the wrong thing here (zero a page range incorrectly or fail
824
823
* to zero) and corrupt data.
825
824
*/
826
- if (folio_ops && folio_ops -> iomap_valid ) {
827
- bool iomap_valid = folio_ops -> iomap_valid (iter -> inode ,
825
+ if (write_ops && write_ops -> iomap_valid ) {
826
+ bool iomap_valid = write_ops -> iomap_valid (iter -> inode ,
828
827
& iter -> iomap );
829
828
if (!iomap_valid ) {
830
829
iter -> iomap .flags |= IOMAP_F_STALE ;
@@ -850,8 +849,7 @@ static int iomap_write_begin(struct iomap_iter *iter, struct folio **foliop,
850
849
return 0 ;
851
850
852
851
out_unlock :
853
- __iomap_put_folio (iter , 0 , folio );
854
-
852
+ __iomap_put_folio (iter , write_ops , 0 , folio );
855
853
return status ;
856
854
}
857
855
@@ -923,7 +921,8 @@ static bool iomap_write_end(struct iomap_iter *iter, size_t len, size_t copied,
923
921
return __iomap_write_end (iter -> inode , pos , len , copied , folio );
924
922
}
925
923
926
- static int iomap_write_iter (struct iomap_iter * iter , struct iov_iter * i )
924
+ static int iomap_write_iter (struct iomap_iter * iter , struct iov_iter * i ,
925
+ const struct iomap_write_ops * write_ops )
927
926
{
928
927
ssize_t total_written = 0 ;
929
928
int status = 0 ;
@@ -967,7 +966,8 @@ static int iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i)
967
966
break ;
968
967
}
969
968
970
- status = iomap_write_begin (iter , & folio , & offset , & bytes );
969
+ status = iomap_write_begin (iter , write_ops , & folio , & offset ,
970
+ & bytes );
971
971
if (unlikely (status )) {
972
972
iomap_write_failed (iter -> inode , iter -> pos , bytes );
973
973
break ;
@@ -996,7 +996,7 @@ static int iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i)
996
996
i_size_write (iter -> inode , pos + written );
997
997
iter -> iomap .flags |= IOMAP_F_SIZE_CHANGED ;
998
998
}
999
- __iomap_put_folio (iter , written , folio );
999
+ __iomap_put_folio (iter , write_ops , written , folio );
1000
1000
1001
1001
if (old_size < pos )
1002
1002
pagecache_isize_extended (iter -> inode , old_size , pos );
@@ -1029,7 +1029,8 @@ static int iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i)
1029
1029
1030
1030
ssize_t
1031
1031
iomap_file_buffered_write (struct kiocb * iocb , struct iov_iter * i ,
1032
- const struct iomap_ops * ops , void * private )
1032
+ const struct iomap_ops * ops ,
1033
+ const struct iomap_write_ops * write_ops , void * private )
1033
1034
{
1034
1035
struct iomap_iter iter = {
1035
1036
.inode = iocb -> ki_filp -> f_mapping -> host ,
@@ -1046,7 +1047,7 @@ iomap_file_buffered_write(struct kiocb *iocb, struct iov_iter *i,
1046
1047
iter .flags |= IOMAP_DONTCACHE ;
1047
1048
1048
1049
while ((ret = iomap_iter (& iter , ops )) > 0 )
1049
- iter .status = iomap_write_iter (& iter , i );
1050
+ iter .status = iomap_write_iter (& iter , i , write_ops );
1050
1051
1051
1052
if (unlikely (iter .pos == iocb -> ki_pos ))
1052
1053
return ret ;
@@ -1280,7 +1281,8 @@ void iomap_write_delalloc_release(struct inode *inode, loff_t start_byte,
1280
1281
}
1281
1282
EXPORT_SYMBOL_GPL (iomap_write_delalloc_release );
1282
1283
1283
- static int iomap_unshare_iter (struct iomap_iter * iter )
1284
+ static int iomap_unshare_iter (struct iomap_iter * iter ,
1285
+ const struct iomap_write_ops * write_ops )
1284
1286
{
1285
1287
struct iomap * iomap = & iter -> iomap ;
1286
1288
u64 bytes = iomap_length (iter );
@@ -1295,14 +1297,15 @@ static int iomap_unshare_iter(struct iomap_iter *iter)
1295
1297
bool ret ;
1296
1298
1297
1299
bytes = min_t (u64 , SIZE_MAX , bytes );
1298
- status = iomap_write_begin (iter , & folio , & offset , & bytes );
1300
+ status = iomap_write_begin (iter , write_ops , & folio , & offset ,
1301
+ & bytes );
1299
1302
if (unlikely (status ))
1300
1303
return status ;
1301
1304
if (iomap -> flags & IOMAP_F_STALE )
1302
1305
break ;
1303
1306
1304
1307
ret = iomap_write_end (iter , bytes , bytes , folio );
1305
- __iomap_put_folio (iter , bytes , folio );
1308
+ __iomap_put_folio (iter , write_ops , bytes , folio );
1306
1309
if (WARN_ON_ONCE (!ret ))
1307
1310
return - EIO ;
1308
1311
@@ -1320,7 +1323,8 @@ static int iomap_unshare_iter(struct iomap_iter *iter)
1320
1323
1321
1324
int
1322
1325
iomap_file_unshare (struct inode * inode , loff_t pos , loff_t len ,
1323
- const struct iomap_ops * ops )
1326
+ const struct iomap_ops * ops ,
1327
+ const struct iomap_write_ops * write_ops )
1324
1328
{
1325
1329
struct iomap_iter iter = {
1326
1330
.inode = inode ,
@@ -1335,7 +1339,7 @@ iomap_file_unshare(struct inode *inode, loff_t pos, loff_t len,
1335
1339
1336
1340
iter .len = min (len , size - pos );
1337
1341
while ((ret = iomap_iter (& iter , ops )) > 0 )
1338
- iter .status = iomap_unshare_iter (& iter );
1342
+ iter .status = iomap_unshare_iter (& iter , write_ops );
1339
1343
return ret ;
1340
1344
}
1341
1345
EXPORT_SYMBOL_GPL (iomap_file_unshare );
@@ -1354,7 +1358,8 @@ static inline int iomap_zero_iter_flush_and_stale(struct iomap_iter *i)
1354
1358
return filemap_write_and_wait_range (mapping , i -> pos , end );
1355
1359
}
1356
1360
1357
- static int iomap_zero_iter (struct iomap_iter * iter , bool * did_zero )
1361
+ static int iomap_zero_iter (struct iomap_iter * iter , bool * did_zero ,
1362
+ const struct iomap_write_ops * write_ops )
1358
1363
{
1359
1364
u64 bytes = iomap_length (iter );
1360
1365
int status ;
@@ -1365,7 +1370,8 @@ static int iomap_zero_iter(struct iomap_iter *iter, bool *did_zero)
1365
1370
bool ret ;
1366
1371
1367
1372
bytes = min_t (u64 , SIZE_MAX , bytes );
1368
- status = iomap_write_begin (iter , & folio , & offset , & bytes );
1373
+ status = iomap_write_begin (iter , write_ops , & folio , & offset ,
1374
+ & bytes );
1369
1375
if (status )
1370
1376
return status ;
1371
1377
if (iter -> iomap .flags & IOMAP_F_STALE )
@@ -1378,7 +1384,7 @@ static int iomap_zero_iter(struct iomap_iter *iter, bool *did_zero)
1378
1384
folio_mark_accessed (folio );
1379
1385
1380
1386
ret = iomap_write_end (iter , bytes , bytes , folio );
1381
- __iomap_put_folio (iter , bytes , folio );
1387
+ __iomap_put_folio (iter , write_ops , bytes , folio );
1382
1388
if (WARN_ON_ONCE (!ret ))
1383
1389
return - EIO ;
1384
1390
@@ -1394,7 +1400,8 @@ static int iomap_zero_iter(struct iomap_iter *iter, bool *did_zero)
1394
1400
1395
1401
int
1396
1402
iomap_zero_range (struct inode * inode , loff_t pos , loff_t len , bool * did_zero ,
1397
- const struct iomap_ops * ops , void * private )
1403
+ const struct iomap_ops * ops ,
1404
+ const struct iomap_write_ops * write_ops , void * private )
1398
1405
{
1399
1406
struct iomap_iter iter = {
1400
1407
.inode = inode ,
@@ -1424,7 +1431,8 @@ iomap_zero_range(struct inode *inode, loff_t pos, loff_t len, bool *did_zero,
1424
1431
filemap_range_needs_writeback (mapping , pos , pos + plen - 1 )) {
1425
1432
iter .len = plen ;
1426
1433
while ((ret = iomap_iter (& iter , ops )) > 0 )
1427
- iter .status = iomap_zero_iter (& iter , did_zero );
1434
+ iter .status = iomap_zero_iter (& iter , did_zero ,
1435
+ write_ops );
1428
1436
1429
1437
iter .len = len - (iter .pos - pos );
1430
1438
if (ret || !iter .len )
@@ -1455,15 +1463,16 @@ iomap_zero_range(struct inode *inode, loff_t pos, loff_t len, bool *did_zero,
1455
1463
continue ;
1456
1464
}
1457
1465
1458
- iter .status = iomap_zero_iter (& iter , did_zero );
1466
+ iter .status = iomap_zero_iter (& iter , did_zero , write_ops );
1459
1467
}
1460
1468
return ret ;
1461
1469
}
1462
1470
EXPORT_SYMBOL_GPL (iomap_zero_range );
1463
1471
1464
1472
int
1465
1473
iomap_truncate_page (struct inode * inode , loff_t pos , bool * did_zero ,
1466
- const struct iomap_ops * ops , void * private )
1474
+ const struct iomap_ops * ops ,
1475
+ const struct iomap_write_ops * write_ops , void * private )
1467
1476
{
1468
1477
unsigned int blocksize = i_blocksize (inode );
1469
1478
unsigned int off = pos & (blocksize - 1 );
@@ -1472,7 +1481,7 @@ iomap_truncate_page(struct inode *inode, loff_t pos, bool *did_zero,
1472
1481
if (!off )
1473
1482
return 0 ;
1474
1483
return iomap_zero_range (inode , pos , blocksize - off , did_zero , ops ,
1475
- private );
1484
+ write_ops , private );
1476
1485
}
1477
1486
EXPORT_SYMBOL_GPL (iomap_truncate_page );
1478
1487
0 commit comments