[RFC 3/3] ext4: Implement willwrite for the delalloc case

From: Andy Lutomirski
Date: Mon Aug 05 2013 - 15:44:22 EST


Signed-off-by: Andy Lutomirski <luto@xxxxxxxxxxxxxx>
---
fs/ext4/ext4.h | 2 ++
fs/ext4/file.c | 1 +
fs/ext4/inode.c | 22 ++++++++++++++++++++++
3 files changed, 25 insertions(+)

diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index b577e45..be7308a 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -2103,6 +2103,8 @@ extern int ext4_block_zero_page_range(handle_t *handle,
extern int ext4_zero_partial_blocks(handle_t *handle, struct inode *inode,
loff_t lstart, loff_t lend);
extern int ext4_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf);
+extern long ext4_willwrite(struct vm_area_struct *vma,
+ unsigned long start, unsigned long end);
extern qsize_t *ext4_get_reserved_space(struct inode *inode);
extern void ext4_da_update_reserve_space(struct inode *inode,
int used, int quota_claim);
diff --git a/fs/ext4/file.c b/fs/ext4/file.c
index 6f4cc56..159226f 100644
--- a/fs/ext4/file.c
+++ b/fs/ext4/file.c
@@ -201,6 +201,7 @@ ext4_file_write(struct kiocb *iocb, const struct iovec *iov,
static const struct vm_operations_struct ext4_file_vm_ops = {
.fault = filemap_fault,
.page_mkwrite = ext4_page_mkwrite,
+ .willwrite = ext4_willwrite,
.remap_pages = generic_file_remap_pages,
};

diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index ba33c67..c49e36b 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -5101,3 +5101,25 @@ out:
sb_end_pagefault(inode->i_sb);
return ret;
}
+
+long ext4_willwrite(struct vm_area_struct *vma,
+ unsigned long start, unsigned long end)
+{
+ int ret = 0;
+ struct file *file = vma->vm_file;
+ struct inode *inode = file_inode(file);
+ int retries = 0;
+
+ /* We only support the delalloc case */
+ if (test_opt(inode->i_sb, DELALLOC) &&
+ !ext4_should_journal_data(inode) &&
+ !ext4_nonda_switch(inode->i_sb)) {
+ do {
+ ret = block_willwrite(vma, start, end,
+ ext4_da_get_block_prep);
+ } while (ret == -ENOSPC &&
+ ext4_should_retry_alloc(inode->i_sb, &retries));
+ }
+
+ return ret;
+}
--
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/