@@ -1258,19 +1258,19 @@ static vm_fault_t dax_pmd_load_hole(struct xa_state *xas, struct vm_fault *vmf,
1258
1258
}
1259
1259
#endif /* CONFIG_FS_DAX_PMD */
1260
1260
1261
- static s64 dax_unshare_iter (struct iomap_iter * iter )
1261
+ static int dax_unshare_iter (struct iomap_iter * iter )
1262
1262
{
1263
1263
struct iomap * iomap = & iter -> iomap ;
1264
1264
const struct iomap * srcmap = iomap_iter_srcmap (iter );
1265
1265
loff_t copy_pos = iter -> pos ;
1266
1266
u64 copy_len = iomap_length (iter );
1267
1267
u32 mod ;
1268
1268
int id = 0 ;
1269
- s64 ret = 0 ;
1269
+ s64 ret ;
1270
1270
void * daddr = NULL , * saddr = NULL ;
1271
1271
1272
1272
if (!iomap_want_unshare_iter (iter ))
1273
- return iomap_length (iter );
1273
+ return iomap_iter_advance_full (iter );
1274
1274
1275
1275
/*
1276
1276
* Extend the file range to be aligned to fsblock/pagesize, because
@@ -1300,14 +1300,14 @@ static s64 dax_unshare_iter(struct iomap_iter *iter)
1300
1300
if (ret < 0 )
1301
1301
goto out_unlock ;
1302
1302
1303
- if (copy_mc_to_kernel (daddr , saddr , copy_len ) == 0 )
1304
- ret = iomap_length (iter );
1305
- else
1303
+ if (copy_mc_to_kernel (daddr , saddr , copy_len ) != 0 )
1306
1304
ret = - EIO ;
1307
1305
1308
1306
out_unlock :
1309
1307
dax_read_unlock (id );
1310
- return dax_mem2blk_err (ret );
1308
+ if (ret < 0 )
1309
+ return dax_mem2blk_err (ret );
1310
+ return iomap_iter_advance_full (iter );
1311
1311
}
1312
1312
1313
1313
int dax_file_unshare (struct inode * inode , loff_t pos , loff_t len ,
@@ -1326,7 +1326,7 @@ int dax_file_unshare(struct inode *inode, loff_t pos, loff_t len,
1326
1326
1327
1327
iter .len = min (len , size - pos );
1328
1328
while ((ret = iomap_iter (& iter , ops )) > 0 )
1329
- iter .processed = dax_unshare_iter (& iter );
1329
+ iter .status = dax_unshare_iter (& iter );
1330
1330
return ret ;
1331
1331
}
1332
1332
EXPORT_SYMBOL_GPL (dax_file_unshare );
@@ -1354,51 +1354,52 @@ static int dax_memzero(struct iomap_iter *iter, loff_t pos, size_t size)
1354
1354
return ret ;
1355
1355
}
1356
1356
1357
- static s64 dax_zero_iter (struct iomap_iter * iter , bool * did_zero )
1357
+ static int dax_zero_iter (struct iomap_iter * iter , bool * did_zero )
1358
1358
{
1359
1359
const struct iomap * iomap = & iter -> iomap ;
1360
1360
const struct iomap * srcmap = iomap_iter_srcmap (iter );
1361
- loff_t pos = iter -> pos ;
1362
1361
u64 length = iomap_length (iter );
1363
- s64 written = 0 ;
1362
+ int ret ;
1364
1363
1365
1364
/* already zeroed? we're done. */
1366
1365
if (srcmap -> type == IOMAP_HOLE || srcmap -> type == IOMAP_UNWRITTEN )
1367
- return length ;
1366
+ return iomap_iter_advance ( iter , & length ) ;
1368
1367
1369
1368
/*
1370
1369
* invalidate the pages whose sharing state is to be changed
1371
1370
* because of CoW.
1372
1371
*/
1373
1372
if (iomap -> flags & IOMAP_F_SHARED )
1374
1373
invalidate_inode_pages2_range (iter -> inode -> i_mapping ,
1375
- pos >> PAGE_SHIFT ,
1376
- ( pos + length - 1 ) >> PAGE_SHIFT );
1374
+ iter -> pos >> PAGE_SHIFT ,
1375
+ ( iter -> pos + length - 1 ) >> PAGE_SHIFT );
1377
1376
1378
1377
do {
1378
+ loff_t pos = iter -> pos ;
1379
1379
unsigned offset = offset_in_page (pos );
1380
- unsigned size = min_t (u64 , PAGE_SIZE - offset , length );
1381
1380
pgoff_t pgoff = dax_iomap_pgoff (iomap , pos );
1382
- long rc ;
1383
1381
int id ;
1384
1382
1383
+ length = min_t (u64 , PAGE_SIZE - offset , length );
1384
+
1385
1385
id = dax_read_lock ();
1386
- if (IS_ALIGNED (pos , PAGE_SIZE ) && size == PAGE_SIZE )
1387
- rc = dax_zero_page_range (iomap -> dax_dev , pgoff , 1 );
1386
+ if (IS_ALIGNED (pos , PAGE_SIZE ) && length == PAGE_SIZE )
1387
+ ret = dax_zero_page_range (iomap -> dax_dev , pgoff , 1 );
1388
1388
else
1389
- rc = dax_memzero (iter , pos , size );
1389
+ ret = dax_memzero (iter , pos , length );
1390
1390
dax_read_unlock (id );
1391
1391
1392
- if (rc < 0 )
1393
- return rc ;
1394
- pos += size ;
1395
- length -= size ;
1396
- written += size ;
1392
+ if (ret < 0 )
1393
+ return ret ;
1394
+
1395
+ ret = iomap_iter_advance (iter , & length );
1396
+ if (ret )
1397
+ return ret ;
1397
1398
} while (length > 0 );
1398
1399
1399
1400
if (did_zero )
1400
1401
* did_zero = true;
1401
- return written ;
1402
+ return ret ;
1402
1403
}
1403
1404
1404
1405
int dax_zero_range (struct inode * inode , loff_t pos , loff_t len , bool * did_zero ,
@@ -1413,7 +1414,7 @@ int dax_zero_range(struct inode *inode, loff_t pos, loff_t len, bool *did_zero,
1413
1414
int ret ;
1414
1415
1415
1416
while ((ret = iomap_iter (& iter , ops )) > 0 )
1416
- iter .processed = dax_zero_iter (& iter , did_zero );
1417
+ iter .status = dax_zero_iter (& iter , did_zero );
1417
1418
return ret ;
1418
1419
}
1419
1420
EXPORT_SYMBOL_GPL (dax_zero_range );
@@ -1431,8 +1432,7 @@ int dax_truncate_page(struct inode *inode, loff_t pos, bool *did_zero,
1431
1432
}
1432
1433
EXPORT_SYMBOL_GPL (dax_truncate_page );
1433
1434
1434
- static loff_t dax_iomap_iter (const struct iomap_iter * iomi ,
1435
- struct iov_iter * iter )
1435
+ static int dax_iomap_iter (struct iomap_iter * iomi , struct iov_iter * iter )
1436
1436
{
1437
1437
const struct iomap * iomap = & iomi -> iomap ;
1438
1438
const struct iomap * srcmap = iomap_iter_srcmap (iomi );
@@ -1451,8 +1451,10 @@ static loff_t dax_iomap_iter(const struct iomap_iter *iomi,
1451
1451
if (pos >= end )
1452
1452
return 0 ;
1453
1453
1454
- if (iomap -> type == IOMAP_HOLE || iomap -> type == IOMAP_UNWRITTEN )
1455
- return iov_iter_zero (min (length , end - pos ), iter );
1454
+ if (iomap -> type == IOMAP_HOLE || iomap -> type == IOMAP_UNWRITTEN ) {
1455
+ done = iov_iter_zero (min (length , end - pos ), iter );
1456
+ return iomap_iter_advance (iomi , & done );
1457
+ }
1456
1458
}
1457
1459
1458
1460
/*
@@ -1485,7 +1487,7 @@ static loff_t dax_iomap_iter(const struct iomap_iter *iomi,
1485
1487
}
1486
1488
1487
1489
id = dax_read_lock ();
1488
- while (pos < end ) {
1490
+ while (( pos = iomi -> pos ) < end ) {
1489
1491
unsigned offset = pos & (PAGE_SIZE - 1 );
1490
1492
const size_t size = ALIGN (length + offset , PAGE_SIZE );
1491
1493
pgoff_t pgoff = dax_iomap_pgoff (iomap , pos );
@@ -1535,18 +1537,16 @@ static loff_t dax_iomap_iter(const struct iomap_iter *iomi,
1535
1537
xfer = dax_copy_to_iter (dax_dev , pgoff , kaddr ,
1536
1538
map_len , iter );
1537
1539
1538
- pos += xfer ;
1539
- length -= xfer ;
1540
- done += xfer ;
1541
-
1542
- if (xfer == 0 )
1540
+ length = xfer ;
1541
+ ret = iomap_iter_advance (iomi , & length );
1542
+ if (!ret && xfer == 0 )
1543
1543
ret = - EFAULT ;
1544
1544
if (xfer < map_len )
1545
1545
break ;
1546
1546
}
1547
1547
dax_read_unlock (id );
1548
1548
1549
- return done ? done : ret ;
1549
+ return ret ;
1550
1550
}
1551
1551
1552
1552
/**
@@ -1586,7 +1586,7 @@ dax_iomap_rw(struct kiocb *iocb, struct iov_iter *iter,
1586
1586
iomi .flags |= IOMAP_NOWAIT ;
1587
1587
1588
1588
while ((ret = iomap_iter (& iomi , ops )) > 0 )
1589
- iomi .processed = dax_iomap_iter (& iomi , iter );
1589
+ iomi .status = dax_iomap_iter (& iomi , iter );
1590
1590
1591
1591
done = iomi .pos - iocb -> ki_pos ;
1592
1592
iocb -> ki_pos = iomi .pos ;
@@ -1757,7 +1757,7 @@ static vm_fault_t dax_iomap_pte_fault(struct vm_fault *vmf, pfn_t *pfnp,
1757
1757
1758
1758
while ((error = iomap_iter (& iter , ops )) > 0 ) {
1759
1759
if (WARN_ON_ONCE (iomap_length (& iter ) < PAGE_SIZE )) {
1760
- iter .processed = - EIO ; /* fs corruption? */
1760
+ iter .status = - EIO ; /* fs corruption? */
1761
1761
continue ;
1762
1762
}
1763
1763
@@ -1769,8 +1769,10 @@ static vm_fault_t dax_iomap_pte_fault(struct vm_fault *vmf, pfn_t *pfnp,
1769
1769
ret |= VM_FAULT_MAJOR ;
1770
1770
}
1771
1771
1772
- if (!(ret & VM_FAULT_ERROR ))
1773
- iter .processed = PAGE_SIZE ;
1772
+ if (!(ret & VM_FAULT_ERROR )) {
1773
+ u64 length = PAGE_SIZE ;
1774
+ iter .status = iomap_iter_advance (& iter , & length );
1775
+ }
1774
1776
}
1775
1777
1776
1778
if (iomap_errp )
@@ -1883,8 +1885,10 @@ static vm_fault_t dax_iomap_pmd_fault(struct vm_fault *vmf, pfn_t *pfnp,
1883
1885
continue ; /* actually breaks out of the loop */
1884
1886
1885
1887
ret = dax_fault_iter (vmf , & iter , pfnp , & xas , & entry , true);
1886
- if (ret != VM_FAULT_FALLBACK )
1887
- iter .processed = PMD_SIZE ;
1888
+ if (ret != VM_FAULT_FALLBACK ) {
1889
+ u64 length = PMD_SIZE ;
1890
+ iter .status = iomap_iter_advance (& iter , & length );
1891
+ }
1888
1892
}
1889
1893
1890
1894
unlock_entry :
@@ -1999,20 +2003,21 @@ vm_fault_t dax_finish_sync_fault(struct vm_fault *vmf, unsigned int order,
1999
2003
}
2000
2004
EXPORT_SYMBOL_GPL (dax_finish_sync_fault );
2001
2005
2002
- static loff_t dax_range_compare_iter (struct iomap_iter * it_src ,
2006
+ static int dax_range_compare_iter (struct iomap_iter * it_src ,
2003
2007
struct iomap_iter * it_dest , u64 len , bool * same )
2004
2008
{
2005
2009
const struct iomap * smap = & it_src -> iomap ;
2006
2010
const struct iomap * dmap = & it_dest -> iomap ;
2007
2011
loff_t pos1 = it_src -> pos , pos2 = it_dest -> pos ;
2012
+ u64 dest_len ;
2008
2013
void * saddr , * daddr ;
2009
2014
int id , ret ;
2010
2015
2011
2016
len = min (len , min (smap -> length , dmap -> length ));
2012
2017
2013
2018
if (smap -> type == IOMAP_HOLE && dmap -> type == IOMAP_HOLE ) {
2014
2019
* same = true;
2015
- return len ;
2020
+ goto advance ;
2016
2021
}
2017
2022
2018
2023
if (smap -> type == IOMAP_HOLE || dmap -> type == IOMAP_HOLE ) {
@@ -2035,7 +2040,13 @@ static loff_t dax_range_compare_iter(struct iomap_iter *it_src,
2035
2040
if (!* same )
2036
2041
len = 0 ;
2037
2042
dax_read_unlock (id );
2038
- return len ;
2043
+
2044
+ advance :
2045
+ dest_len = len ;
2046
+ ret = iomap_iter_advance (it_src , & len );
2047
+ if (!ret )
2048
+ ret = iomap_iter_advance (it_dest , & dest_len );
2049
+ return ret ;
2039
2050
2040
2051
out_unlock :
2041
2052
dax_read_unlock (id );
@@ -2058,15 +2069,15 @@ int dax_dedupe_file_range_compare(struct inode *src, loff_t srcoff,
2058
2069
.len = len ,
2059
2070
.flags = IOMAP_DAX ,
2060
2071
};
2061
- int ret , compared = 0 ;
2072
+ int ret , status ;
2062
2073
2063
2074
while ((ret = iomap_iter (& src_iter , ops )) > 0 &&
2064
2075
(ret = iomap_iter (& dst_iter , ops )) > 0 ) {
2065
- compared = dax_range_compare_iter (& src_iter , & dst_iter ,
2076
+ status = dax_range_compare_iter (& src_iter , & dst_iter ,
2066
2077
min (src_iter .len , dst_iter .len ), same );
2067
- if (compared < 0 )
2078
+ if (status < 0 )
2068
2079
return ret ;
2069
- src_iter .processed = dst_iter .processed = compared ;
2080
+ src_iter .status = dst_iter .status = status ;
2070
2081
}
2071
2082
return ret ;
2072
2083
}
0 commit comments