Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 188699
b: refs/heads/master
c: 4af6b22
h: refs/heads/master
i:
  188697: 78b76d7
  188695: 6ebfa96
v: v3
  • Loading branch information
Yehuda Sadeh authored and Sage Weil committed Feb 11, 2010
1 parent 3ba8fc0 commit 12f9856
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 30 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 972f0d3ab1a15cb5d790dd8c53903066084b28f2
refs/heads/master: 4af6b2257ee0eb8f4bf3b1dc8acb643c0e8a887f
80 changes: 51 additions & 29 deletions trunk/fs/ceph/addr.c
Original file line number Diff line number Diff line change
Expand Up @@ -907,32 +907,20 @@ static int context_is_writeable_or_written(struct inode *inode,
* We are only allowed to write into/dirty the page if the page is
* clean, or already dirty within the same snap context.
*/
static int ceph_write_begin(struct file *file, struct address_space *mapping,
loff_t pos, unsigned len, unsigned flags,
struct page **pagep, void **fsdata)
static int ceph_update_writeable_page(struct file *file,
loff_t pos, unsigned len,
struct page *page)
{
struct inode *inode = file->f_dentry->d_inode;
struct ceph_inode_info *ci = ceph_inode(inode);
struct ceph_mds_client *mdsc = &ceph_inode_to_client(inode)->mdsc;
struct page *page;
pgoff_t index = pos >> PAGE_CACHE_SHIFT;
loff_t page_off = pos & PAGE_CACHE_MASK;
int pos_in_page = pos & ~PAGE_CACHE_MASK;
int end_in_page = pos_in_page + len;
loff_t i_size;
struct ceph_snap_context *snapc;
int r;

/* get a page*/
retry:
page = grab_cache_page_write_begin(mapping, index, 0);
if (!page)
return -ENOMEM;
*pagep = page;

dout("write_begin file %p inode %p page %p %d~%d\n", file,
inode, page, (int)pos, (int)len);

retry_locked:
/* writepages currently holds page lock, but if we change that later, */
wait_on_page_writeback(page);
Expand Down Expand Up @@ -964,7 +952,7 @@ static int ceph_write_begin(struct file *file, struct address_space *mapping,
wait_event_interruptible(ci->i_cap_wq,
context_is_writeable_or_written(inode, snapc));
ceph_put_snap_context(snapc);
goto retry;
return -EAGAIN;
}

/* yay, writeable, do it now (without dropping page lock) */
Expand Down Expand Up @@ -1021,6 +1009,35 @@ static int ceph_write_begin(struct file *file, struct address_space *mapping,
return r;
}

/*
* We are only allowed to write into/dirty the page if the page is
* clean, or already dirty within the same snap context.
*/
static int ceph_write_begin(struct file *file, struct address_space *mapping,
loff_t pos, unsigned len, unsigned flags,
struct page **pagep, void **fsdata)
{
struct inode *inode = file->f_dentry->d_inode;
struct page *page;
pgoff_t index = pos >> PAGE_CACHE_SHIFT;
int r;

do {
/* get a page*/
page = grab_cache_page_write_begin(mapping, index, 0);
if (!page)
return -ENOMEM;
*pagep = page;

dout("write_begin file %p inode %p page %p %d~%d\n", file,
inode, page, (int)pos, (int)len);

r = ceph_update_writeable_page(file, pos, len, page);
} while (r == -EAGAIN);

return r;
}

/*
* we don't do anything in here that simple_write_end doesn't do
* except adjust dirty page accounting and drop read lock on
Expand Down Expand Up @@ -1104,8 +1121,6 @@ static int ceph_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
struct ceph_mds_client *mdsc = &ceph_inode_to_client(inode)->mdsc;
loff_t off = page->index << PAGE_CACHE_SHIFT;
loff_t size, len;
struct page *locked_page = NULL;
void *fsdata = NULL;
int ret;

size = i_size_read(inode);
Expand All @@ -1116,23 +1131,30 @@ static int ceph_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)

dout("page_mkwrite %p %llu~%llu page %p idx %lu\n", inode,
off, len, page, page->index);
ret = ceph_write_begin(vma->vm_file, inode->i_mapping, off, len, 0,
&locked_page, &fsdata);
WARN_ON(page != locked_page);
if (!ret) {
/*
* doing the following, instead of calling
* ceph_write_end. Note that we keep the
* page locked
*/

lock_page(page);

ret = VM_FAULT_NOPAGE;
if ((off > size) ||
(page->mapping != inode->i_mapping))
goto out;

ret = ceph_update_writeable_page(vma->vm_file, off, len, page);
if (ret == 0) {
/* success. we'll keep the page locked. */
set_page_dirty(page);
up_read(&mdsc->snap_rwsem);
page_cache_release(page);
ret = VM_FAULT_LOCKED;
} else {
ret = VM_FAULT_SIGBUS;
if (ret == -ENOMEM)
ret = VM_FAULT_OOM;
else
ret = VM_FAULT_SIGBUS;
}
out:
dout("page_mkwrite %p %llu~%llu = %d\n", inode, off, len, ret);
if (ret != VM_FAULT_LOCKED)
unlock_page(page);
return ret;
}

Expand Down

0 comments on commit 12f9856

Please sign in to comment.