@@ -781,6 +781,33 @@ static int __dax_invalidate_entry(struct address_space *mapping,
781
781
return ret ;
782
782
}
783
783
784
+ static int __dax_clear_dirty_range (struct address_space * mapping ,
785
+ pgoff_t start , pgoff_t end )
786
+ {
787
+ XA_STATE (xas , & mapping -> i_pages , start );
788
+ unsigned int scanned = 0 ;
789
+ void * entry ;
790
+
791
+ xas_lock_irq (& xas );
792
+ xas_for_each (& xas , entry , end ) {
793
+ entry = get_unlocked_entry (& xas , 0 );
794
+ xas_clear_mark (& xas , PAGECACHE_TAG_DIRTY );
795
+ xas_clear_mark (& xas , PAGECACHE_TAG_TOWRITE );
796
+ put_unlocked_entry (& xas , entry , WAKE_NEXT );
797
+
798
+ if (++ scanned % XA_CHECK_SCHED )
799
+ continue ;
800
+
801
+ xas_pause (& xas );
802
+ xas_unlock_irq (& xas );
803
+ cond_resched ();
804
+ xas_lock_irq (& xas );
805
+ }
806
+ xas_unlock_irq (& xas );
807
+
808
+ return 0 ;
809
+ }
810
+
784
811
/*
785
812
* Delete DAX entry at @index from @mapping. Wait for it
786
813
* to be unlocked before deleting it.
@@ -1440,6 +1467,16 @@ static loff_t dax_iomap_iter(const struct iomap_iter *iomi,
1440
1467
* written by write(2) is visible in mmap.
1441
1468
*/
1442
1469
if (iomap -> flags & IOMAP_F_NEW || cow ) {
1470
+ /*
1471
+ * Filesystem allows CoW on non-shared extents. The src extents
1472
+ * may have been mmapped with dirty mark before. To be able to
1473
+ * invalidate its dax entries, we need to clear the dirty mark
1474
+ * in advance.
1475
+ */
1476
+ if (cow )
1477
+ __dax_clear_dirty_range (iomi -> inode -> i_mapping ,
1478
+ pos >> PAGE_SHIFT ,
1479
+ (end - 1 ) >> PAGE_SHIFT );
1443
1480
invalidate_inode_pages2_range (iomi -> inode -> i_mapping ,
1444
1481
pos >> PAGE_SHIFT ,
1445
1482
(end - 1 ) >> PAGE_SHIFT );
0 commit comments