xfs
[Top] [All Lists]

[PATCH] xfs: Add readpage() check up for mmap file at xfs_file_mmap()

To: xfs@xxxxxxxxxxx
Subject: [PATCH] xfs: Add readpage() check up for mmap file at xfs_file_mmap()
From: Jeff Liu <jeff.liu@xxxxxxxxxx>
Date: Wed, 18 Jul 2012 22:47:28 +0800
Organization: Oracle
Reply-to: jeff.liu@xxxxxxxxxx
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.28) Gecko/20120313 Thunderbird/3.1.20
Hello,

When studying XFS code, I found xfs_file_mmap() does not check whether a 
specific file has readpage() or not.
Actually, I have no idea of which kind of file does not supply page reading 
function, but Btrfs/Ext4
as well as generic_file_mmap() all do this check at first, do we also need a 
defense here?

Thanks,
-Jeff


Signed-off-by: Jie Liu <jeff.liu@xxxxxxxxxx>

---
 fs/xfs/xfs_file.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
index 9f7ec15..92ad4a5 100644
--- a/fs/xfs/xfs_file.c
+++ b/fs/xfs/xfs_file.c
@@ -945,6 +945,11 @@ xfs_file_mmap(
        struct file     *filp,
        struct vm_area_struct *vma)
 {
+       struct address_space *mapping = file->f_mapping;
+
+       if (!mapping->a_ops->readpage)
+               return -ENOEXEC;
+
        vma->vm_ops = &xfs_file_vm_ops;
        vma->vm_flags |= VM_CAN_NONLINEAR;
 
-- 
1.7.9

<Prev in Thread] Current Thread [Next in Thread>