123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- #include <linux/fs.h>
- #include <linux/types.h>
- #include <linux/highmem.h>
- #include <linux/pagemap.h>
- #include <linux/uio.h>
- #include <linux/signal.h>
- #include <linux/rbtree.h>
- #include <cluster/masklog.h>
- #include "ocfs2.h"
- #include "aops.h"
- #include "dlmglue.h"
- #include "file.h"
- #include "inode.h"
- #include "mmap.h"
- #include "super.h"
- #include "ocfs2_trace.h"
- static int ocfs2_fault(struct vm_area_struct *area, struct vm_fault *vmf)
- {
- sigset_t oldset;
- int ret;
- ocfs2_block_signals(&oldset);
- ret = filemap_fault(area, vmf);
- ocfs2_unblock_signals(&oldset);
- trace_ocfs2_fault(OCFS2_I(area->vm_file->f_mapping->host)->ip_blkno,
- area, vmf->page, vmf->pgoff);
- return ret;
- }
- static int __ocfs2_page_mkwrite(struct file *file, struct buffer_head *di_bh,
- struct page *page)
- {
- int ret = VM_FAULT_NOPAGE;
- struct inode *inode = file_inode(file);
- struct address_space *mapping = inode->i_mapping;
- loff_t pos = page_offset(page);
- unsigned int len = PAGE_SIZE;
- pgoff_t last_index;
- struct page *locked_page = NULL;
- void *fsdata;
- loff_t size = i_size_read(inode);
- last_index = (size - 1) >> PAGE_SHIFT;
-
- if ((page->mapping != inode->i_mapping) ||
- (!PageUptodate(page)) ||
- (page_offset(page) >= size))
- goto out;
-
- if (page->index == last_index)
- len = ((size - 1) & ~PAGE_MASK) + 1;
- ret = ocfs2_write_begin_nolock(mapping, pos, len, OCFS2_WRITE_MMAP,
- &locked_page, &fsdata, di_bh, page);
- if (ret) {
- if (ret != -ENOSPC)
- mlog_errno(ret);
- if (ret == -ENOMEM)
- ret = VM_FAULT_OOM;
- else
- ret = VM_FAULT_SIGBUS;
- goto out;
- }
- if (!locked_page) {
- ret = VM_FAULT_NOPAGE;
- goto out;
- }
- ret = ocfs2_write_end_nolock(mapping, pos, len, len, locked_page,
- fsdata);
- BUG_ON(ret != len);
- ret = VM_FAULT_LOCKED;
- out:
- return ret;
- }
- static int ocfs2_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
- {
- struct page *page = vmf->page;
- struct inode *inode = file_inode(vma->vm_file);
- struct buffer_head *di_bh = NULL;
- sigset_t oldset;
- int ret;
- sb_start_pagefault(inode->i_sb);
- ocfs2_block_signals(&oldset);
-
- ret = ocfs2_inode_lock(inode, &di_bh, 1);
- if (ret < 0) {
- mlog_errno(ret);
- if (ret == -ENOMEM)
- ret = VM_FAULT_OOM;
- else
- ret = VM_FAULT_SIGBUS;
- goto out;
- }
-
- down_write(&OCFS2_I(inode)->ip_alloc_sem);
- ret = __ocfs2_page_mkwrite(vma->vm_file, di_bh, page);
- up_write(&OCFS2_I(inode)->ip_alloc_sem);
- brelse(di_bh);
- ocfs2_inode_unlock(inode, 1);
- out:
- ocfs2_unblock_signals(&oldset);
- sb_end_pagefault(inode->i_sb);
- return ret;
- }
- static const struct vm_operations_struct ocfs2_file_vm_ops = {
- .fault = ocfs2_fault,
- .page_mkwrite = ocfs2_page_mkwrite,
- };
- int ocfs2_mmap(struct file *file, struct vm_area_struct *vma)
- {
- int ret = 0, lock_level = 0;
- ret = ocfs2_inode_lock_atime(file_inode(file),
- file->f_path.mnt, &lock_level);
- if (ret < 0) {
- mlog_errno(ret);
- goto out;
- }
- ocfs2_inode_unlock(file_inode(file), lock_level);
- out:
- vma->vm_ops = &ocfs2_file_vm_ops;
- return 0;
- }
|