From patchwork Wed May 16 05:43:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 10402623 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 069B1601D2 for ; Wed, 16 May 2018 05:44:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EA04928733 for ; Wed, 16 May 2018 05:44:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DEA9028761; Wed, 16 May 2018 05:44:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B0C6028733 for ; Wed, 16 May 2018 05:44:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5FCA46B02ED; Wed, 16 May 2018 01:44:39 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 5AD216B02EE; Wed, 16 May 2018 01:44:39 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4C3656B02EF; Wed, 16 May 2018 01:44:39 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f69.google.com (mail-pl0-f69.google.com [209.85.160.69]) by kanga.kvack.org (Postfix) with ESMTP id 0C5676B02ED for ; Wed, 16 May 2018 01:44:39 -0400 (EDT) Received: by mail-pl0-f69.google.com with SMTP id f35-v6so1977218plb.10 for ; Tue, 15 May 2018 22:44:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references; bh=tR/Rpz5q3SfadcpHKfUo/lcxmZKEyFn2kGSWrLvKXOs=; b=V2PXs9xqsLhVDYR+WfvmvrvhatXYHpdYEt+oyVymg8/ck9oXvBlKSUBvaqVIBYUhbO FOYCbSZLR6RuXcKvq0C82Sa1Ciq0X8Uq36J14pcszZC5/2LzAqbVP6t4q5rrvg/TWac3 4OYIPPQ9dmbogHFVMISmZUvqgGKLvEEBxJBJ3DZSleK59pP9JDVNTiokFG05GuflNMVv px91D+OpeWT6OFOZmvLdsYroxnCogIbvh0OkUUHLCIpWX9ZXtWV+jl1KrFXELRNr4PDP lQ1dhjiP84BkywFZ6vFOJzn4iQ7zWGJ8IM6wmRmQMMUyInzYz1c0IKf1xQPgCkxMTpG+ cMcA== X-Gm-Message-State: ALKqPwdkberaJ54w39W4HeC6b2z+44QqYVVXfdSyeJEm7WHQjJFF60bF UKydWsfIVB6GUX+X9kX1rBTJseXRyOhr8HWnRqF7dCF4alt30+cThq9PRnknPLh/WNHhRKImXnA zRk0KFhho3rOqrm4zM6J6y0xHIKniaVegelsmScmz8JcCaLKDfFa87OSTNOQrixo= X-Received: by 2002:a17:902:4603:: with SMTP id o3-v6mr18227657pld.49.1526449478749; Tue, 15 May 2018 22:44:38 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpG0BuNzw2xyS5NYAoIGVm7I9IlRJCA3newcTqIaOTB8TRcm6kgHOrh/qzxys1NAdn91aoA X-Received: by 2002:a17:902:4603:: with SMTP id o3-v6mr18227616pld.49.1526449477941; Tue, 15 May 2018 22:44:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526449477; cv=none; d=google.com; s=arc-20160816; b=EN3sL0/IJTs/Cav5jhUB/aqGWYSrSYXVH//1NIIYBMXpoS26cPP0YWsDIDg6OkYH9s O6vmy6AYAc9wnR67yDUDD6zZZ2oin2PwB6lI+Mgere4bHodK3bYb4b5wY9bqEFk+F8Dv NK3SkcO/WnMLbSJR/JSB4/VSefRjKNRo973cNNnIzNTTdo+Ihewgqj0ZY8tR6R2j3fEV UYDPF/QuvOqnjsM2be9gmSxyQbBbYh1Bs2aQhRBOXE9F86f2Wb26GN11p2VB3wYjJBB1 l/fvjjJsmdt1AIh6HAKQ9G8/6IZMISSNJzz4Vbm+nCYp7/aqTxSpOYzcy6kLdRPj3MPc mfYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=tR/Rpz5q3SfadcpHKfUo/lcxmZKEyFn2kGSWrLvKXOs=; b=A/r8/6FV1b3QluShljdgqfOOfPRQMcdOdPAr8pqkU5dvg6zyNxMCrpBpWY+pkHhWga pBmf4iUIiMDpkEHzIzuMVT7ABwLwud9Xy85xyC2v5TUJAJZpIdJJl3RZ7A2DPwfaHKCO loogDQOWWkSP1ZfQqYuklmyO1gUqd/WqqNHAoLw3hAbSKMQQYxwWJO4IDO860ec5uUMS g3tZaoI11VGyXB+LUq4aRI6HjKHpxqsukWCbKTLezl9aU6inHDGYxZK71kWv2aJJil6f Nsk0JyC9YqFY3I9UfFJ3WrT7UFS8ox3uiDtIgMEaZ3GcGitoFD/U1w7Yb07/nApXWKML 0MUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=JYpFtapN; spf=pass (google.com: best guess record for domain of batv+8c5add14d4fec8f33fc9+5379+infradead.org+hch@bombadil.srs.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom=BATV+8c5add14d4fec8f33fc9+5379+infradead.org+hch@bombadil.srs.infradead.org Received: from bombadil.infradead.org (bombadil.infradead.org. [2607:7c80:54:e::133]) by mx.google.com with ESMTPS id 69-v6si1485199pgc.64.2018.05.15.22.44.37 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 15 May 2018 22:44:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of batv+8c5add14d4fec8f33fc9+5379+infradead.org+hch@bombadil.srs.infradead.org designates 2607:7c80:54:e::133 as permitted sender) client-ip=2607:7c80:54:e::133; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=JYpFtapN; spf=pass (google.com: best guess record for domain of batv+8c5add14d4fec8f33fc9+5379+infradead.org+hch@bombadil.srs.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom=BATV+8c5add14d4fec8f33fc9+5379+infradead.org+hch@bombadil.srs.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=tR/Rpz5q3SfadcpHKfUo/lcxmZKEyFn2kGSWrLvKXOs=; b=JYpFtapNEYhDbHdXeY5NW6OKI ui4Dp4vlrhvBoQ2cGPPMy26G8gE+u3Jf7lGJHEbEmnc8CYsq3Xr49MOb9GiXyfZFlt7PCyWUwqnL9 C0s7tqCwJK7wsZ2P/EMi1hoRYkgEEN7v56iiC15x3O+qGW4VElEL2ENxd+anepezW+2PBk6tOWxa4 quRHnvYT+44TBwqOwnAJZBADkU1ZqUGYYJraYL2z9IGe4ComyG39YCvVHw3odYZcZQsgiiCfWBcR8 uRBDbRfXZwnwdHuKNJ/Q5ZYEt+agqRI32CudKWUjKr3sfuXKC9bW8imBh3s13ypRIAuHEDtyJ57av z+5gR3gqw==; Received: from [93.83.86.253] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fIpEO-00082q-Lo; Wed, 16 May 2018 05:44:09 +0000 From: Christoph Hellwig To: Souptick Joarder , Matthew Wilcox Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, devel@lists.orangefs.org, ceph-devel@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-ext4@vger.kernel.org, ocfs2-devel@oss.oracle.com, linux-mtd@lists.infradead.org, dri-devel@lists.freedesktop.org, lustre-devel@lists.lustre.org, linux-arm-kernel@lists.infradead.org, linux-s390@vger.kernel.org Subject: [PATCH 05/14] ceph: untangle ceph_filemap_fault Date: Wed, 16 May 2018 07:43:39 +0200 Message-Id: <20180516054348.15950-6-hch@lst.de> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180516054348.15950-1-hch@lst.de> References: <20180516054348.15950-1-hch@lst.de> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Streamline the code to have a somewhat natural flow, and separate the errno values from the VM_FAULT_* values. Signed-off-by: Christoph Hellwig --- fs/ceph/addr.c | 100 +++++++++++++++++++++++++------------------------ 1 file changed, 51 insertions(+), 49 deletions(-) diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c index 5f7ad3d0df2e..6e80894ca073 100644 --- a/fs/ceph/addr.c +++ b/fs/ceph/addr.c @@ -1428,15 +1428,18 @@ static void ceph_restore_sigs(sigset_t *oldset) /* * vm ops */ -static int ceph_filemap_fault(struct vm_fault *vmf) +static vm_fault_t ceph_filemap_fault(struct vm_fault *vmf) { struct vm_area_struct *vma = vmf->vma; struct inode *inode = file_inode(vma->vm_file); + struct address_space *mapping = inode->i_mapping; struct ceph_inode_info *ci = ceph_inode(inode); struct ceph_file_info *fi = vma->vm_file->private_data; - struct page *pinned_page = NULL; + struct page *pinned_page = NULL, *page; loff_t off = vmf->pgoff << PAGE_SHIFT; - int want, got, ret; + int want, got, err = 0; + vm_fault_t ret = 0; + bool did_fault = false; sigset_t oldset; ceph_block_sigs(&oldset); @@ -1449,9 +1452,9 @@ static int ceph_filemap_fault(struct vm_fault *vmf) want = CEPH_CAP_FILE_CACHE; got = 0; - ret = ceph_get_caps(ci, CEPH_CAP_FILE_RD, want, -1, &got, &pinned_page); - if (ret < 0) - goto out_restore; + err = ceph_get_caps(ci, CEPH_CAP_FILE_RD, want, -1, &got, &pinned_page); + if (err < 0) + goto out_errno; dout("filemap_fault %p %llu~%zd got cap refs on %s\n", inode, off, (size_t)PAGE_SIZE, ceph_cap_string(got)); @@ -1462,8 +1465,8 @@ static int ceph_filemap_fault(struct vm_fault *vmf) ceph_add_rw_context(fi, &rw_ctx); ret = filemap_fault(vmf); ceph_del_rw_context(fi, &rw_ctx); - } else - ret = -EAGAIN; + did_fault = true; + } dout("filemap_fault %p %llu~%zd dropping cap refs on %s ret %d\n", inode, off, (size_t)PAGE_SIZE, ceph_cap_string(got), ret); @@ -1471,57 +1474,55 @@ static int ceph_filemap_fault(struct vm_fault *vmf) put_page(pinned_page); ceph_put_cap_refs(ci, got); - if (ret != -EAGAIN) + if (did_fault) goto out_restore; /* read inline data */ if (off >= PAGE_SIZE) { /* does not support inline data > PAGE_SIZE */ ret = VM_FAULT_SIGBUS; + goto out_restore; + } + + page = find_or_create_page(mapping, 0, + mapping_gfp_constraint(mapping, ~__GFP_FS)); + if (!page) { + ret = VM_FAULT_OOM; + goto out_inline; + } + + err = __ceph_do_getattr(inode, page, CEPH_STAT_CAP_INLINE_DATA, true); + if (err < 0 || off >= i_size_read(inode)) { + unlock_page(page); + put_page(page); + if (err < 0) + goto out_errno; + ret = VM_FAULT_SIGBUS; } else { - int ret1; - struct address_space *mapping = inode->i_mapping; - struct page *page = find_or_create_page(mapping, 0, - mapping_gfp_constraint(mapping, - ~__GFP_FS)); - if (!page) { - ret = VM_FAULT_OOM; - goto out_inline; - } - ret1 = __ceph_do_getattr(inode, page, - CEPH_STAT_CAP_INLINE_DATA, true); - if (ret1 < 0 || off >= i_size_read(inode)) { - unlock_page(page); - put_page(page); - if (ret1 < 0) - ret = ret1; - else - ret = VM_FAULT_SIGBUS; - goto out_inline; - } - if (ret1 < PAGE_SIZE) - zero_user_segment(page, ret1, PAGE_SIZE); + if (err < PAGE_SIZE) + zero_user_segment(page, err, PAGE_SIZE); else flush_dcache_page(page); SetPageUptodate(page); vmf->page = page; ret = VM_FAULT_MAJOR | VM_FAULT_LOCKED; -out_inline: - dout("filemap_fault %p %llu~%zd read inline data ret %d\n", - inode, off, (size_t)PAGE_SIZE, ret); } + +out_inline: + dout("filemap_fault %p %llu~%zd read inline data ret %d\n", + inode, off, (size_t)PAGE_SIZE, ret); out_restore: ceph_restore_sigs(&oldset); - if (ret < 0) - ret = (ret == -ENOMEM) ? VM_FAULT_OOM : VM_FAULT_SIGBUS; - return ret; +out_errno: + ret = (err == -ENOMEM) ? VM_FAULT_OOM : VM_FAULT_SIGBUS; + goto out_restore; } /* * Reuse write_begin here for simplicity. */ -static int ceph_page_mkwrite(struct vm_fault *vmf) +static vm_fault_t ceph_page_mkwrite(struct vm_fault *vmf) { struct vm_area_struct *vma = vmf->vma; struct inode *inode = file_inode(vma->vm_file); @@ -1532,7 +1533,8 @@ static int ceph_page_mkwrite(struct vm_fault *vmf) loff_t off = page_offset(page); loff_t size = i_size_read(inode); size_t len; - int want, got, ret; + int want, got, err = 0; + vm_fault_t ret = 0; sigset_t oldset; prealloc_cf = ceph_alloc_cap_flush(); @@ -1547,10 +1549,10 @@ static int ceph_page_mkwrite(struct vm_fault *vmf) lock_page(page); locked_page = page; } - ret = ceph_uninline_data(vma->vm_file, locked_page); + err = ceph_uninline_data(vma->vm_file, locked_page); if (locked_page) unlock_page(locked_page); - if (ret < 0) + if (err < 0) goto out_free; } @@ -1567,9 +1569,9 @@ static int ceph_page_mkwrite(struct vm_fault *vmf) want = CEPH_CAP_FILE_BUFFER; got = 0; - ret = ceph_get_caps(ci, CEPH_CAP_FILE_WR, want, off + len, + err = ceph_get_caps(ci, CEPH_CAP_FILE_WR, want, off + len, &got, NULL); - if (ret < 0) + if (err < 0) goto out_free; dout("page_mkwrite %p %llu~%zd got cap refs on %s\n", @@ -1587,13 +1589,13 @@ static int ceph_page_mkwrite(struct vm_fault *vmf) break; } - ret = ceph_update_writeable_page(vma->vm_file, off, len, page); - if (ret >= 0) { + err = ceph_update_writeable_page(vma->vm_file, off, len, page); + if (err >= 0) { /* success. we'll keep the page locked. */ set_page_dirty(page); ret = VM_FAULT_LOCKED; } - } while (ret == -EAGAIN); + } while (err == -EAGAIN); if (ret == VM_FAULT_LOCKED || ci->i_inline_version != CEPH_INLINE_NONE) { @@ -1608,13 +1610,13 @@ static int ceph_page_mkwrite(struct vm_fault *vmf) } dout("page_mkwrite %p %llu~%zd dropping cap refs on %s ret %d\n", - inode, off, len, ceph_cap_string(got), ret); + inode, off, len, ceph_cap_string(got), err); ceph_put_cap_refs(ci, got); out_free: ceph_restore_sigs(&oldset); ceph_free_cap_flush(prealloc_cf); - if (ret < 0) - ret = (ret == -ENOMEM) ? VM_FAULT_OOM : VM_FAULT_SIGBUS; + if (err < 0) + ret = (err == -ENOMEM) ? VM_FAULT_OOM : VM_FAULT_SIGBUS; return ret; }