From patchwork Wed Jul 22 10:55:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 11678201 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C474813A4 for ; Wed, 22 Jul 2020 10:55:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AB87C207DD for ; Wed, 22 Jul 2020 10:55:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595415318; bh=17j7GzhWRoYXK1PIiQe5xTNGrVBOSRwhYGmwIK1/OpM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=tzADmYh8DyyrcFuvnjgST5zrPd/64RexFQSLCjKOn3cCW1QVrHYJeEeylTcyjM8Mp zJnk5KOlQNgDWejCw7LOemGuyhKARNjCPC86k9mdr/wpROSfgLGlNVjSV3zLJWJ4K4 mybegPXy07EDOTcs7l6IImzI+Zon9c+5e5EXH9bM= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728238AbgGVKzS (ORCPT ); Wed, 22 Jul 2020 06:55:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:53584 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728171AbgGVKzR (ORCPT ); Wed, 22 Jul 2020 06:55:17 -0400 Received: from tleilax.com (68-20-15-154.lightspeed.rlghnc.sbcglobal.net [68.20.15.154]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 57964206F5; Wed, 22 Jul 2020 10:55:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595415316; bh=17j7GzhWRoYXK1PIiQe5xTNGrVBOSRwhYGmwIK1/OpM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=peeEP1UGLszwQLDS0YQmI1BPfOnlOOOjsvOmc8YKNZyf15/xqtnuKPTKuvLIDAhEi Tiqc8bt51NyKNQ5pKDuUfrwBXqYUDBK37vSudybL/6ertAoqTAIrruAP6SvmpOxbv2 bLF03vn43NFJ4ZcWvUzb6J7O4kFrgDZrAy5oLuv0= From: Jeff Layton To: ceph-devel@vger.kernel.org Cc: dhowells@redhat.com, dwysocha@redhat.com, smfrench@gmail.com Subject: [RFC PATCH 05/11] ceph: fold ceph_update_writeable_page into ceph_write_begin Date: Wed, 22 Jul 2020 06:55:05 -0400 Message-Id: <20200722105511.11187-6-jlayton@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200722105511.11187-1-jlayton@kernel.org> References: <20200722105511.11187-1-jlayton@kernel.org> MIME-Version: 1.0 Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org ...and reorganize the loop for better clarity. Signed-off-by: Jeff Layton --- fs/ceph/addr.c | 141 ++++++++++++++++++++++--------------------------- 1 file changed, 62 insertions(+), 79 deletions(-) diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c index 42fb38a112b8..b43431c0c95c 100644 --- a/fs/ceph/addr.c +++ b/fs/ceph/addr.c @@ -1253,6 +1253,8 @@ static int context_is_writeable_or_written(struct inode *inode, * @inode: inode associated with page * @page: page being dirtied * + * We are only allowed to write into/dirty the page if the page is + * clean, or already dirty within the same snap context. * Returns NULL on success, negative error code on error, and a snapc ref that should be * waited on otherwise. */ @@ -1309,104 +1311,85 @@ ceph_find_incompatible(struct inode *inode, struct page *page) /* * 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. */ -static int ceph_update_writeable_page(struct file *file, - loff_t pos, unsigned len, - struct page *page) +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_inode(file); struct ceph_inode_info *ci = ceph_inode(inode); struct ceph_snap_context *snapc; + struct page *page = NULL; + pgoff_t index = pos >> PAGE_SHIFT; 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; +refind: + /* get a page */ + page = grab_cache_page_write_begin(mapping, index, 0); + if (!page) + return -ENOMEM; -retry_locked: - snapc = ceph_find_incompatible(inode, page); - if (snapc) { - if (IS_ERR(snapc)) { - r = PTR_ERR(snapc); - goto fail_unlock; + dout("write_begin file %p inode %p page %p %d~%d\n", file, + inode, page, (int)pos, (int)len); + + for (;;) { + snapc = ceph_find_incompatible(inode, page); + if (snapc) { + if (IS_ERR(snapc)) { + r = PTR_ERR(snapc); + break; + } + unlock_page(page); + ceph_queue_writeback(inode); + r = wait_event_killable(ci->i_cap_wq, + context_is_writeable_or_written(inode, snapc)); + ceph_put_snap_context(snapc); + put_page(page); + goto refind; } - unlock_page(page); - ceph_queue_writeback(inode); - r = wait_event_killable(ci->i_cap_wq, - context_is_writeable_or_written(inode, snapc)); - ceph_put_snap_context(snapc); - return -EAGAIN; - } - if (PageUptodate(page)) { - dout(" page %p already uptodate\n", page); - return 0; - } + if (PageUptodate(page)) { + dout(" page %p already uptodate\n", page); + break; + } - /* full page? */ - if (pos_in_page == 0 && len == PAGE_SIZE) - return 0; + /* full page? */ + if (pos_in_page == 0 && len == PAGE_SIZE) + break; - /* past end of file? */ - i_size = i_size_read(inode); - - if (page_off >= i_size || - (pos_in_page == 0 && (pos+len) >= i_size && - end_in_page - pos_in_page != PAGE_SIZE)) { - dout(" zeroing %p 0 - %d and %d - %d\n", - page, pos_in_page, end_in_page, (int)PAGE_SIZE); - zero_user_segments(page, - 0, pos_in_page, - end_in_page, PAGE_SIZE); - return 0; - } + /* past end of file? */ + i_size = i_size_read(inode); + if (page_off >= i_size || + (pos_in_page == 0 && (pos+len) >= i_size && + end_in_page - pos_in_page != PAGE_SIZE)) { + dout(" zeroing %p 0 - %d and %d - %d\n", + page, pos_in_page, end_in_page, (int)PAGE_SIZE); + zero_user_segments(page, + 0, pos_in_page, + end_in_page, PAGE_SIZE); + break; + } - /* we need to read it. */ - r = ceph_do_readpage(file, page); - if (r < 0) { - if (r == -EINPROGRESS) - return -EAGAIN; - goto fail_unlock; + /* we need to read it. */ + r = ceph_do_readpage(file, page); + if (r) { + if (r == -EINPROGRESS) + continue; + break; + } } - goto retry_locked; -fail_unlock: - unlock_page(page); - 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_inode(file); - struct page *page; - pgoff_t index = pos >> PAGE_SHIFT; - int r; - - do { - /* get a page */ - page = grab_cache_page_write_begin(mapping, index, 0); - if (!page) - return -ENOMEM; - - 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); - if (r < 0) + if (r < 0) { + if (page) { + unlock_page(page); put_page(page); - else - *pagep = page; - } while (r == -EAGAIN); - + } + } else { + *pagep = page; + } return r; }