diff options
Diffstat (limited to 'sys/contrib/openzfs/module/os/linux/zfs/zpl_file.c')
| -rw-r--r-- | sys/contrib/openzfs/module/os/linux/zfs/zpl_file.c | 74 | 
1 files changed, 74 insertions, 0 deletions
| diff --git a/sys/contrib/openzfs/module/os/linux/zfs/zpl_file.c b/sys/contrib/openzfs/module/os/linux/zfs/zpl_file.c index d07317b0d910..02965ac8cbee 100644 --- a/sys/contrib/openzfs/module/os/linux/zfs/zpl_file.c +++ b/sys/contrib/openzfs/module/os/linux/zfs/zpl_file.c @@ -23,6 +23,7 @@   * Copyright (c) 2011, Lawrence Livermore National Security, LLC.   * Copyright (c) 2015 by Chunwei Chen. All rights reserved.   * Copyright (c) 2025, Klara, Inc. + * Copyright (c) 2025, Rob Norris <robn@despairlabs.com>   */ @@ -478,6 +479,7 @@ zpl_putpage(struct page *pp, struct writeback_control *wbc, void *data)  	return (ret);  } +#ifdef HAVE_WRITE_CACHE_PAGES  #ifdef HAVE_WRITEPAGE_T_FOLIO  static int  zpl_putfolio(struct folio *pp, struct writeback_control *wbc, void *data) @@ -499,6 +501,78 @@ zpl_write_cache_pages(struct address_space *mapping,  #endif  	return (result);  } +#else +static inline int +zpl_write_cache_pages(struct address_space *mapping, +    struct writeback_control *wbc, void *data) +{ +	pgoff_t start = wbc->range_start >> PAGE_SHIFT; +	pgoff_t end = wbc->range_end >> PAGE_SHIFT; + +	struct folio_batch fbatch; +	folio_batch_init(&fbatch); + +	/* +	 * This atomically (-ish) tags all DIRTY pages in the range with +	 * TOWRITE, allowing users to continue dirtying or undirtying pages +	 * while we get on with writeback, without us treading on each other. +	 */ +	tag_pages_for_writeback(mapping, start, end); + +	int err = 0; +	unsigned int npages; + +	/* +	 * Grab references to the TOWRITE pages just flagged. This may not get +	 * all of them, so we do it in a loop until there are none left. +	 */ +	while ((npages = filemap_get_folios_tag(mapping, &start, end, +	    PAGECACHE_TAG_TOWRITE, &fbatch)) != 0) { + +		/* Loop over each page and write it out. */ +		struct folio *folio; +		while ((folio = folio_batch_next(&fbatch)) != NULL) { +			folio_lock(folio); + +			/* +			 * If the folio has been remapped, or is no longer +			 * dirty, then there's nothing to do. +			 */ +			if (folio->mapping != mapping || +			    !folio_test_dirty(folio)) { +				folio_unlock(folio); +				continue; +			} + +			/* +			 * If writeback is already in progress, wait for it to +			 * finish. We continue after this even if the page +			 * ends up clean; zfs_putpage() will skip it if no +			 * further work is required. +			 */ +			while (folio_test_writeback(folio)) +				folio_wait_bit(folio, PG_writeback); + +			/* +			 * Write it out and collect any error. zfs_putpage() +			 * will clear the TOWRITE and DIRTY flags, and return +			 * with the page unlocked. +			 */ +			int ferr = zpl_putpage(&folio->page, wbc, data); +			if (err == 0 && ferr != 0) +				err = ferr; + +			/* Housekeeping for the caller. */ +			wbc->nr_to_write -= folio_nr_pages(folio); +		} + +		/* Release any remaining references on the batch. */ +		folio_batch_release(&fbatch); +	} + +	return (err); +} +#endif  static int  zpl_writepages(struct address_space *mapping, struct writeback_control *wbc) | 
