Commit 18d620f0 authored by Jeff Layton's avatar Jeff Layton Committed by Ilya Dryomov

ceph: break out writeback of incompatible snap context to separate function

When dirtying a page, we have to flush incompatible contexts. Move the
search for an incompatible context into a separate function, and fix up
the caller to wait and retry if there is one.
Signed-off-by: default avatarJeff Layton <jlayton@kernel.org>
Signed-off-by: default avatarIlya Dryomov <idryomov@gmail.com>
parent 4bb926e8
...@@ -1298,75 +1298,97 @@ static int context_is_writeable_or_written(struct inode *inode, ...@@ -1298,75 +1298,97 @@ static int context_is_writeable_or_written(struct inode *inode,
return ret; return ret;
} }
/* /**
* We are only allowed to write into/dirty the page if the page is * ceph_find_incompatible - find an incompatible context and return it
* clean, or already dirty within the same snap context. * @inode: inode associated with page
* @page: page being dirtied
* *
* called with page locked. * We are only allowed to write into/dirty a page if the page is
* return success with page locked, * clean, or already dirty within the same snap context. Returns a
* or any failure (incl -EAGAIN) with page unlocked. * conflicting context if there is one, NULL if there isn't, or a
* negative error code on other errors.
*
* Must be called with page lock held.
*/ */
static int ceph_update_writeable_page(struct file *file, static struct ceph_snap_context *
loff_t pos, unsigned len, ceph_find_incompatible(struct inode *inode, struct page *page)
struct page *page)
{ {
struct inode *inode = file_inode(file);
struct ceph_fs_client *fsc = ceph_inode_to_client(inode); struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
struct ceph_inode_info *ci = ceph_inode(inode); struct ceph_inode_info *ci = ceph_inode(inode);
loff_t page_off = pos & PAGE_MASK;
int pos_in_page = pos & ~PAGE_MASK;
int end_in_page = pos_in_page + len;
loff_t i_size;
int r;
struct ceph_snap_context *snapc, *oldest;
if (READ_ONCE(fsc->mount_state) == CEPH_MOUNT_SHUTDOWN) { if (READ_ONCE(fsc->mount_state) == CEPH_MOUNT_SHUTDOWN) {
dout(" page %p forced umount\n", page); dout(" page %p forced umount\n", page);
unlock_page(page); return ERR_PTR(-EIO);
return -EIO;
} }
retry_locked: for (;;) {
/* writepages currently holds page lock, but if we change that later, */ struct ceph_snap_context *snapc, *oldest;
wait_on_page_writeback(page); wait_on_page_writeback(page);
snapc = page_snap_context(page); snapc = page_snap_context(page);
if (snapc && snapc != ci->i_head_snapc) { if (!snapc || snapc == ci->i_head_snapc)
break;
/* /*
* this page is already dirty in another (older) snap * this page is already dirty in another (older) snap
* context! is it writeable now? * context! is it writeable now?
*/ */
oldest = get_oldest_context(inode, NULL, NULL); oldest = get_oldest_context(inode, NULL, NULL);
if (snapc->seq > oldest->seq) { if (snapc->seq > oldest->seq) {
/* not writeable -- return it for the caller to deal with */
ceph_put_snap_context(oldest); ceph_put_snap_context(oldest);
dout(" page %p snapc %p not current or oldest\n", dout(" page %p snapc %p not current or oldest\n", page, snapc);
page, snapc); return ceph_get_snap_context(snapc);
/* }
* queue for writeback, and wait for snapc to ceph_put_snap_context(oldest);
* be writeable or written
/* yay, writeable, do it now (without dropping page lock) */
dout(" page %p snapc %p not current, but oldest\n", page, snapc);
if (clear_page_dirty_for_io(page)) {
int r = writepage_nounlock(page, NULL);
if (r < 0)
return ERR_PTR(r);
}
}
return NULL;
}
/*
* We are only allowed to write into/dirty the page if the page is
* clean, or already dirty within the same snap context.
*
* called with page locked.
* return success with page locked,
* or any failure (incl -EAGAIN) with page unlocked.
*/ */
snapc = ceph_get_snap_context(snapc); static int ceph_update_writeable_page(struct file *file,
loff_t pos, unsigned len,
struct page *page)
{
struct inode *inode = file_inode(file);
struct ceph_inode_info *ci = ceph_inode(inode);
struct ceph_snap_context *snapc;
loff_t page_off = pos & PAGE_MASK;
int pos_in_page = pos & ~PAGE_MASK;
int end_in_page = pos_in_page + len;
loff_t i_size;
int r;
retry_locked:
snapc = ceph_find_incompatible(inode, page);
if (snapc) {
if (IS_ERR(snapc)) {
r = PTR_ERR(snapc);
goto fail_unlock;
}
unlock_page(page); unlock_page(page);
ceph_queue_writeback(inode); ceph_queue_writeback(inode);
r = wait_event_killable(ci->i_cap_wq, r = wait_event_killable(ci->i_cap_wq,
context_is_writeable_or_written(inode, snapc)); context_is_writeable_or_written(inode, snapc));
ceph_put_snap_context(snapc); ceph_put_snap_context(snapc);
if (r == -ERESTARTSYS)
return r;
return -EAGAIN; return -EAGAIN;
} }
ceph_put_snap_context(oldest);
/* yay, writeable, do it now (without dropping page lock) */
dout(" page %p snapc %p not current, but oldest\n",
page, snapc);
if (!clear_page_dirty_for_io(page))
goto retry_locked;
r = writepage_nounlock(page, NULL);
if (r < 0)
goto fail_unlock;
goto retry_locked;
}
if (PageUptodate(page)) { if (PageUptodate(page)) {
dout(" page %p already uptodate\n", page); dout(" page %p already uptodate\n", page);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment