diff mbox

[01/15] dax: export a low-level __dax_zero_page_range helper

Message ID 1462783638-4968-2-git-send-email-hch@lst.de (mailing list archive)
State New, archived
Headers show

Commit Message

Christoph Hellwig May 9, 2016, 8:47 a.m. UTC
This allows XFS to perform zeroing using the iomap infrastructure and
avoid buffer heads.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/dax.c            | 35 ++++++++++++++++++++---------------
 include/linux/dax.h |  7 +++++++
 2 files changed, 27 insertions(+), 15 deletions(-)

Comments

Verma, Vishal L May 11, 2016, 10:43 p.m. UTC | #1
T24gTW9uLCAyMDE2LTA1LTA5IGF0IDEwOjQ3ICswMjAwLCBDaHJpc3RvcGggSGVsbHdpZyB3cm90
ZToNCj4gVGhpcyBhbGxvd3MgWEZTIHRvIHBlcmZvcm0gemVyb2luZyB1c2luZyB0aGUgaW9tYXAg
aW5mcmFzdHJ1Y3R1cmUgYW5kDQo+IGF2b2lkIGJ1ZmZlciBoZWFkcy4NCj4gDQo+IFNpZ25lZC1v
ZmYtYnk6IENocmlzdG9waCBIZWxsd2lnIDxoY2hAbHN0LmRlPg0KPiAtLS0NCj4gwqBmcy9kYXgu
Y8KgwqDCoMKgwqDCoMKgwqDCoMKgwqDCoHwgMzUgKysrKysrKysrKysrKysrKysrKystLS0tLS0t
LS0tLS0tLS0NCj4gwqBpbmNsdWRlL2xpbnV4L2RheC5oIHzCoMKgNyArKysrKysrDQo+IMKgMiBm
aWxlcyBjaGFuZ2VkLCAyNyBpbnNlcnRpb25zKCspLCAxNSBkZWxldGlvbnMoLSkNCg0KVGhpcyBs
b29rcyBnb29kIHRvIG1lLg0KDQpSZXZpZXdlZC1ieTogVmlzaGFsIFZlcm1hIDx2aXNoYWwubC52
ZXJtYUBpbnRlbC5jb20+DQoNCj4gDQo+IGRpZmYgLS1naXQgYS9mcy9kYXguYyBiL2ZzL2RheC5j
DQo+IGluZGV4IDkwMzIyZWIuLjZkNWQ3NDQgMTAwNjQ0DQo+IC0tLSBhL2ZzL2Rhe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BvZmZzZXQsIHVuc2lnbmVkIGludA0KPiBsZW5ndGgpDQo+ICt7DQo+ICsJcmV0dXJu
IC1FTlhJTzsNCj4gK30NCj4gwqAjZW5kaWYNCj4gwqANCj4gwqAjaWZkZWYgQ09ORklHX1RSQU5T
UEFSRU5UX0hVR0VQQUdF
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/fs/dax.c b/fs/dax.c
index 90322eb..6d5d744 100644
--- a/fs/dax.c
+++ b/fs/dax.c
@@ -1082,6 +1082,23 @@  int dax_pfn_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
 }
 EXPORT_SYMBOL_GPL(dax_pfn_mkwrite);
 
+int __dax_zero_page_range(struct block_device *bdev, sector_t sector,
+		unsigned int offset, unsigned int length)
+{
+	struct blk_dax_ctl dax = {
+		.sector		= sector,
+		.size		= PAGE_CACHE_SIZE,
+	};
+
+	if (dax_map_atomic(bdev, &dax) < 0)
+		return PTR_ERR(dax.addr);
+	clear_pmem(dax.addr + offset, length);
+	wmb_pmem();
+	dax_unmap_atomic(bdev, &dax);
+	return 0;
+}
+EXPORT_SYMBOL_GPL(__dax_zero_page_range);
+
 /**
  * dax_zero_page_range - zero a range within a page of a DAX file
  * @inode: The file being truncated
@@ -1117,23 +1134,11 @@  int dax_zero_page_range(struct inode *inode, loff_t from, unsigned length,
 	bh.b_bdev = inode->i_sb->s_bdev;
 	bh.b_size = PAGE_CACHE_SIZE;
 	err = get_block(inode, index, &bh, 0);
-	if (err < 0)
+	if (err < 0 || !buffer_written(&bh))
 		return err;
-	if (buffer_written(&bh)) {
-		struct block_device *bdev = bh.b_bdev;
-		struct blk_dax_ctl dax = {
-			.sector = to_sector(&bh, inode),
-			.size = PAGE_CACHE_SIZE,
-		};
 
-		if (dax_map_atomic(bdev, &dax) < 0)
-			return PTR_ERR(dax.addr);
-		clear_pmem(dax.addr + offset, length);
-		wmb_pmem();
-		dax_unmap_atomic(bdev, &dax);
-	}
-
-	return 0;
+	return __dax_zero_page_range(bh.b_bdev, to_sector(&bh, inode),
+			offset, length);
 }
 EXPORT_SYMBOL_GPL(dax_zero_page_range);
 
diff --git a/include/linux/dax.h b/include/linux/dax.h
index 636dd59..8155b81 100644
--- a/include/linux/dax.h
+++ b/include/linux/dax.h
@@ -17,12 +17,19 @@  int __dax_fault(struct vm_area_struct *, struct vm_fault *, get_block_t,
 
 #ifdef CONFIG_FS_DAX
 struct page *read_dax_sector(struct block_device *bdev, sector_t n);
+int __dax_zero_page_range(struct block_device *bdev, sector_t sector,
+		unsigned int offset, unsigned int length);
 #else
 static inline struct page *read_dax_sector(struct block_device *bdev,
 		sector_t n)
 {
 	return ERR_PTR(-ENXIO);
 }
+static inline int __dax_zero_page_range(struct block_device *bdev,
+		sector_t sector, unsigned int offset, unsigned int length)
+{
+	return -ENXIO;
+}
 #endif
 
 #ifdef CONFIG_TRANSPARENT_HUGEPAGE