Merge git://git.kernel.org/pub/scm/linux/kernel/git/sfrench/cifs-2.6
[pandora-kernel.git] / fs / ocfs2 / mmap.c
index 7898bd3..4c18f4a 100644 (file)
 #include "file.h"
 #include "inode.h"
 #include "mmap.h"
+#include "super.h"
 
-static inline int ocfs2_vm_op_block_sigs(sigset_t *blocked, sigset_t *oldset)
-{
-       /* The best way to deal with signals in the vm path is
-        * to block them upfront, rather than allowing the
-        * locking paths to return -ERESTARTSYS. */
-       sigfillset(blocked);
-
-       /* We should technically never get a bad return value
-        * from sigprocmask */
-       return sigprocmask(SIG_BLOCK, blocked, oldset);
-}
-
-static inline int ocfs2_vm_op_unblock_sigs(sigset_t *oldset)
-{
-       return sigprocmask(SIG_SETMASK, oldset, NULL);
-}
 
 static int ocfs2_fault(struct vm_area_struct *area, struct vm_fault *vmf)
 {
-       sigset_t blocked, oldset;
-       int error, ret;
+       sigset_t oldset;
+       int ret;
 
        mlog_entry("(area=%p, page offset=%lu)\n", area, vmf->pgoff);
 
-       error = ocfs2_vm_op_block_sigs(&blocked, &oldset);
-       if (error < 0) {
-               mlog_errno(error);
-               ret = VM_FAULT_SIGBUS;
-               goto out;
-       }
-
+       ocfs2_block_signals(&oldset);
        ret = filemap_fault(area, vmf);
+       ocfs2_unblock_signals(&oldset);
 
-       error = ocfs2_vm_op_unblock_sigs(&oldset);
-       if (error < 0)
-               mlog_errno(error);
-out:
        mlog_exit_ptr(vmf->page);
        return ret;
 }
@@ -98,9 +74,11 @@ static int __ocfs2_page_mkwrite(struct inode *inode, struct buffer_head *di_bh,
        /*
         * Another node might have truncated while we were waiting on
         * cluster locks.
+        * We don't check size == 0 before the shift. This is borrowed
+        * from do_generic_file_read.
         */
-       last_index = size >> PAGE_CACHE_SHIFT;
-       if (page->index > last_index) {
+       last_index = (size - 1) >> PAGE_CACHE_SHIFT;
+       if (unlikely(!size || page->index > last_index)) {
                ret = -EINVAL;
                goto out;
        }
@@ -131,7 +109,7 @@ static int __ocfs2_page_mkwrite(struct inode *inode, struct buffer_head *di_bh,
         * because the "write" would invalidate their data.
         */
        if (page->index == last_index)
-               len = size & ~PAGE_CACHE_MASK;
+               len = ((size - 1) & ~PAGE_CACHE_MASK) + 1;
 
        ret = ocfs2_write_begin_nolock(mapping, pos, len, 0, &locked_page,
                                       &fsdata, di_bh, page);
@@ -158,14 +136,10 @@ static int ocfs2_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
        struct page *page = vmf->page;
        struct inode *inode = vma->vm_file->f_path.dentry->d_inode;
        struct buffer_head *di_bh = NULL;
-       sigset_t blocked, oldset;
-       int ret, ret2;
+       sigset_t oldset;
+       int ret;
 
-       ret = ocfs2_vm_op_block_sigs(&blocked, &oldset);
-       if (ret < 0) {
-               mlog_errno(ret);
-               return ret;
-       }
+       ocfs2_block_signals(&oldset);
 
        /*
         * The cluster locks taken will block a truncate from another
@@ -193,9 +167,7 @@ static int ocfs2_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
        ocfs2_inode_unlock(inode, 1);
 
 out:
-       ret2 = ocfs2_vm_op_unblock_sigs(&oldset);
-       if (ret2 < 0)
-               mlog_errno(ret2);
+       ocfs2_unblock_signals(&oldset);
        if (ret)
                ret = VM_FAULT_SIGBUS;
        return ret;