From patchwork Tue Apr 9 19:42:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 10892189 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 86F7E1805 for ; Tue, 9 Apr 2019 19:42:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 75F6928981 for ; Tue, 9 Apr 2019 19:42:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7073C2898B; Tue, 9 Apr 2019 19:42:34 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0AB712898B for ; Tue, 9 Apr 2019 19:42:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726530AbfDITmc (ORCPT ); Tue, 9 Apr 2019 15:42:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:57784 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726446AbfDITmc (ORCPT ); Tue, 9 Apr 2019 15:42:32 -0400 Received: from tleilax.poochiereds.net (cpe-71-70-156-158.nc.res.rr.com [71.70.156.158]) (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 707E12084B for ; Tue, 9 Apr 2019 19:42:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554838951; bh=/DP+pwC5sjOJBq2Txzry/xCPC005W5+TFMV6wGnY9Mw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=J2SrsKIe7JaeCqAd8TSJy94T5n0bqlchR7lCkrsVOfk2lt8B608A/cywDRxzzHcTk CMrY7PNFoCJ+WQtiCe2Y5yKaXw6snW6VS8HWjTM5obnJKNir8Kg/3Bq2ZhVq/D9mMP OlVi2KnDQHCWOan/qEVQyut6A88+dBGskuUwMU44= From: Jeff Layton To: ceph-devel@vger.kernel.org Subject: [RFC PATCH 01/11] ceph: after an MDS request, do callback and completions Date: Tue, 9 Apr 2019 15:42:19 -0400 Message-Id: <20190409194229.8247-2-jlayton@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190409194229.8247-1-jlayton@kernel.org> References: <20190409194229.8247-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 X-Virus-Scanned: ClamAV using ClamSMTP No MDS requests use r_callback today, but that will change in the future. The OSD client always does r_callback and then completes r_completion. Let's have the MDS client do the same. Signed-off-by: Jeff Layton --- fs/ceph/mds_client.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c index e09feadd2ae1..fde76aa6e916 100644 --- a/fs/ceph/mds_client.c +++ b/fs/ceph/mds_client.c @@ -2377,8 +2377,7 @@ static void complete_request(struct ceph_mds_client *mdsc, { if (req->r_callback) req->r_callback(mdsc, req); - else - complete_all(&req->r_completion); + complete_all(&req->r_completion); } /* From patchwork Tue Apr 9 19:42:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 10892193 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5A09213B5 for ; Tue, 9 Apr 2019 19:42:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 47ABD28969 for ; Tue, 9 Apr 2019 19:42:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 45C8C28985; Tue, 9 Apr 2019 19:42:36 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B348128968 for ; Tue, 9 Apr 2019 19:42:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726588AbfDITme (ORCPT ); Tue, 9 Apr 2019 15:42:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:57790 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726446AbfDITmd (ORCPT ); Tue, 9 Apr 2019 15:42:33 -0400 Received: from tleilax.poochiereds.net (cpe-71-70-156-158.nc.res.rr.com [71.70.156.158]) (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 EFB2C2084F for ; Tue, 9 Apr 2019 19:42:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554838952; bh=qVaASG4iCHLQ+EuKZMyrtOiuCU9DIAj8vKjbhTaT+Xw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=OBMaUPCxHjNljJ6LvOWVhOlKsvlYrF5tpt842zJw+b+RoxyNJsBR/tSOKUwyjXDxL TsYlyJRKuvtPHmfeAvCy2/fdYe2k7BPQYjDjDSGhxVqmxdNrHEXSu4fOySIvTLc+mG 0mTaf+1lXwwqV1xT4NAzX+wIi44rKY6xKPg/RdWM= From: Jeff Layton To: ceph-devel@vger.kernel.org Subject: [RFC PATCH 02/11] ceph: have ceph_mdsc_do_request call ceph_mdsc_submit_request Date: Tue, 9 Apr 2019 15:42:20 -0400 Message-Id: <20190409194229.8247-3-jlayton@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190409194229.8247-1-jlayton@kernel.org> References: <20190409194229.8247-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 X-Virus-Scanned: ClamAV using ClamSMTP Nothing calls ceph_mdsc_submit_request today, but ceph_mdsc_do_request just open-codes the same functionality. Have the helper return an int so we can check the r_err under the mutex, and have the caller just check the error code from the submit. Also move the acquisition of CEPH_CAP_PIN references into the same function. Signed-off-by: Jeff Layton --- fs/ceph/mds_client.c | 40 +++++++++++++++++++--------------------- fs/ceph/mds_client.h | 5 +++-- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c index fde76aa6e916..8d3d56771f09 100644 --- a/fs/ceph/mds_client.c +++ b/fs/ceph/mds_client.c @@ -2619,14 +2619,27 @@ static void kick_requests(struct ceph_mds_client *mdsc, int mds) } } -void ceph_mdsc_submit_request(struct ceph_mds_client *mdsc, +int ceph_mdsc_submit_request(struct ceph_mds_client *mdsc, struct inode *dir, struct ceph_mds_request *req) { - dout("submit_request on %p\n", req); + int err; + + /* take CAP_PIN refs for r_inode, r_parent, r_old_dentry */ + if (req->r_inode) + ceph_get_cap_refs(ceph_inode(req->r_inode), CEPH_CAP_PIN); + if (req->r_parent) + ceph_get_cap_refs(ceph_inode(req->r_parent), CEPH_CAP_PIN); + if (req->r_old_dentry_dir) + ceph_get_cap_refs(ceph_inode(req->r_old_dentry_dir), + CEPH_CAP_PIN); + + dout("submit_request on %p for inode %p\n", req, dir); mutex_lock(&mdsc->mutex); - __register_request(mdsc, req, NULL); + __register_request(mdsc, req, dir); __do_request(mdsc, req); + err = req->r_err; mutex_unlock(&mdsc->mutex); + return err; } /* @@ -2641,27 +2654,12 @@ int ceph_mdsc_do_request(struct ceph_mds_client *mdsc, dout("do_request on %p\n", req); - /* take CAP_PIN refs for r_inode, r_parent, r_old_dentry */ - if (req->r_inode) - ceph_get_cap_refs(ceph_inode(req->r_inode), CEPH_CAP_PIN); - if (req->r_parent) - ceph_get_cap_refs(ceph_inode(req->r_parent), CEPH_CAP_PIN); - if (req->r_old_dentry_dir) - ceph_get_cap_refs(ceph_inode(req->r_old_dentry_dir), - CEPH_CAP_PIN); - /* issue */ - mutex_lock(&mdsc->mutex); - __register_request(mdsc, req, dir); - __do_request(mdsc, req); - - if (req->r_err) { - err = req->r_err; + err = ceph_mdsc_submit_request(mdsc, dir, req); + if (err) goto out; - } /* wait */ - mutex_unlock(&mdsc->mutex); dout("do_request waiting\n"); if (!req->r_timeout && req->r_wait_for_completion) { err = req->r_wait_for_completion(mdsc, req); @@ -2702,8 +2700,8 @@ int ceph_mdsc_do_request(struct ceph_mds_client *mdsc, err = req->r_err; } -out: mutex_unlock(&mdsc->mutex); +out: dout("do_request %p done, result %d\n", req, err); return err; } diff --git a/fs/ceph/mds_client.h b/fs/ceph/mds_client.h index 3f0029aa8a39..98ff39fbf94a 100644 --- a/fs/ceph/mds_client.h +++ b/fs/ceph/mds_client.h @@ -465,8 +465,9 @@ extern int ceph_alloc_readdir_reply_buffer(struct ceph_mds_request *req, struct inode *dir); extern struct ceph_mds_request * ceph_mdsc_create_request(struct ceph_mds_client *mdsc, int op, int mode); -extern void ceph_mdsc_submit_request(struct ceph_mds_client *mdsc, - struct ceph_mds_request *req); +extern int ceph_mdsc_submit_request(struct ceph_mds_client *mdsc, + struct inode *dir, + struct ceph_mds_request *req); extern int ceph_mdsc_do_request(struct ceph_mds_client *mdsc, struct inode *dir, struct ceph_mds_request *req); From patchwork Tue Apr 9 19:42:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 10892211 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 269071805 for ; Tue, 9 Apr 2019 19:42:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 15F8628998 for ; Tue, 9 Apr 2019 19:42:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1474128985; Tue, 9 Apr 2019 19:42:47 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ABB1328985 for ; Tue, 9 Apr 2019 19:42:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726577AbfDITme (ORCPT ); Tue, 9 Apr 2019 15:42:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:57792 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726535AbfDITmd (ORCPT ); Tue, 9 Apr 2019 15:42:33 -0400 Received: from tleilax.poochiereds.net (cpe-71-70-156-158.nc.res.rr.com [71.70.156.158]) (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 783672077C for ; Tue, 9 Apr 2019 19:42:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554838952; bh=LS0RrZOhLQKzCryU10Xwg8l7D0/Y7S37JXN8xigKA44=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Tm++hkkJ6oSchb6O+1RQBzHca9bEpeWd/hvbF4HuEySleoH8MTmege5lRYOSZn+1g N3ti3L/g6qtooEpMo5FbzuVtjFChwqiv+l+ZbH9V6/GM2tSbc28YKHebo/pKQNaiQy k0w/k8T4svo8D57OyuTegtCmftaUatOgfPUz8qFk= From: Jeff Layton To: ceph-devel@vger.kernel.org Subject: [RFC PATCH 03/11] ceph: move wait for mds request into helper function Date: Tue, 9 Apr 2019 15:42:21 -0400 Message-Id: <20190409194229.8247-4-jlayton@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190409194229.8247-1-jlayton@kernel.org> References: <20190409194229.8247-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 X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Jeff Layton --- fs/ceph/mds_client.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c index 8d3d56771f09..9d1ac87e5897 100644 --- a/fs/ceph/mds_client.c +++ b/fs/ceph/mds_client.c @@ -2642,23 +2642,11 @@ int ceph_mdsc_submit_request(struct ceph_mds_client *mdsc, struct inode *dir, return err; } -/* - * Synchrously perform an mds request. Take care of all of the - * session setup, forwarding, retry details. - */ -int ceph_mdsc_do_request(struct ceph_mds_client *mdsc, - struct inode *dir, - struct ceph_mds_request *req) +static int ceph_mdsc_wait_request(struct ceph_mds_client *mdsc, + struct ceph_mds_request *req) { int err; - dout("do_request on %p\n", req); - - /* issue */ - err = ceph_mdsc_submit_request(mdsc, dir, req); - if (err) - goto out; - /* wait */ dout("do_request waiting\n"); if (!req->r_timeout && req->r_wait_for_completion) { @@ -2701,7 +2689,25 @@ int ceph_mdsc_do_request(struct ceph_mds_client *mdsc, } mutex_unlock(&mdsc->mutex); -out: + return err; +} + +/* + * Synchrously perform an mds request. Take care of all of the + * session setup, forwarding, retry details. + */ +int ceph_mdsc_do_request(struct ceph_mds_client *mdsc, + struct inode *dir, + struct ceph_mds_request *req) +{ + int err; + + dout("do_request on %p\n", req); + + /* issue */ + err = ceph_mdsc_submit_request(mdsc, dir, req); + if (!err) + err = ceph_mdsc_wait_request(mdsc, req); dout("do_request %p done, result %d\n", req, err); return err; } From patchwork Tue Apr 9 19:42:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 10892195 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E53841805 for ; Tue, 9 Apr 2019 19:42:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D3CA128968 for ; Tue, 9 Apr 2019 19:42:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C84AE28998; Tue, 9 Apr 2019 19:42:36 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4771F28968 for ; Tue, 9 Apr 2019 19:42:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726632AbfDITmf (ORCPT ); Tue, 9 Apr 2019 15:42:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:57802 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726565AbfDITme (ORCPT ); Tue, 9 Apr 2019 15:42:34 -0400 Received: from tleilax.poochiereds.net (cpe-71-70-156-158.nc.res.rr.com [71.70.156.158]) (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 0369C2084B for ; Tue, 9 Apr 2019 19:42:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554838953; bh=rmiFQ7S7A/GgFnFYs3NNb21R1oi0astul0Xp4tgV0wI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=YuJuncEcKCWybVmZH4ggnAL/+uxC8RAm4NWdca1vvtrFwjcbzFYYLT/JE/JB11cgd WXO1jTLxep/PspHFRMC0HTy+DaZ3Q8g7m5DMOYRWWIxPDVCmXpDbdE5eEYqOhQz/kM nwlKXdTcspQuQ8HasNus07r2B4tgN3jVbYnfKFAA= From: Jeff Layton To: ceph-devel@vger.kernel.org Subject: [RFC PATCH 04/11] ceph: hold extra reference to r_parent over life of request Date: Tue, 9 Apr 2019 15:42:22 -0400 Message-Id: <20190409194229.8247-5-jlayton@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190409194229.8247-1-jlayton@kernel.org> References: <20190409194229.8247-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 X-Virus-Scanned: ClamAV using ClamSMTP Currently, we just assume that it will stick around by virtue of the submitter's reference, but later patches will allow the syscall to return early and we can't rely on that reference at that point. Take an extra reference to the inode when setting r_parent and release it when releasing the request. Signed-off-by: Jeff Layton --- fs/ceph/dir.c | 8 ++++++++ fs/ceph/export.c | 1 + fs/ceph/file.c | 1 + fs/ceph/mds_client.c | 4 +++- 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c index a8f429882249..3eb9bc226b77 100644 --- a/fs/ceph/dir.c +++ b/fs/ceph/dir.c @@ -783,6 +783,7 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry, req->r_args.getattr.mask = cpu_to_le32(mask); req->r_parent = dir; + ihold(dir); set_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags); err = ceph_mdsc_do_request(mdsc, NULL, req); err = ceph_handle_snapdir(req, dentry, err); @@ -850,6 +851,7 @@ static int ceph_mknod(struct inode *dir, struct dentry *dentry, req->r_dentry = dget(dentry); req->r_num_caps = 2; req->r_parent = dir; + ihold(dir); set_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags); req->r_args.mknod.mode = cpu_to_le32(mode); req->r_args.mknod.rdev = cpu_to_le32(rdev); @@ -907,6 +909,7 @@ static int ceph_symlink(struct inode *dir, struct dentry *dentry, goto out; } req->r_parent = dir; + ihold(dir); set_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags); req->r_dentry = dget(dentry); req->r_num_caps = 2; @@ -963,6 +966,7 @@ static int ceph_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) req->r_dentry = dget(dentry); req->r_num_caps = 2; req->r_parent = dir; + ihold(dir); set_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags); req->r_args.mkdir.mode = cpu_to_le32(mode); req->r_dentry_drop = CEPH_CAP_FILE_SHARED | CEPH_CAP_AUTH_EXCL; @@ -1008,6 +1012,7 @@ static int ceph_link(struct dentry *old_dentry, struct inode *dir, req->r_num_caps = 2; req->r_old_dentry = dget(old_dentry); req->r_parent = dir; + ihold(dir); set_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags); req->r_dentry_drop = CEPH_CAP_FILE_SHARED; req->r_dentry_unless = CEPH_CAP_FILE_EXCL; @@ -1055,6 +1060,7 @@ static int ceph_unlink(struct inode *dir, struct dentry *dentry) req->r_dentry = dget(dentry); req->r_num_caps = 2; req->r_parent = dir; + ihold(dir); set_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags); req->r_dentry_drop = CEPH_CAP_FILE_SHARED; req->r_dentry_unless = CEPH_CAP_FILE_EXCL; @@ -1104,6 +1110,7 @@ static int ceph_rename(struct inode *old_dir, struct dentry *old_dentry, req->r_old_dentry = dget(old_dentry); req->r_old_dentry_dir = old_dir; req->r_parent = new_dir; + ihold(new_dir); set_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags); req->r_old_dentry_drop = CEPH_CAP_FILE_SHARED; req->r_old_dentry_unless = CEPH_CAP_FILE_EXCL; @@ -1586,6 +1593,7 @@ static int ceph_d_revalidate(struct dentry *dentry, unsigned int flags) req->r_dentry = dget(dentry); req->r_num_caps = 2; req->r_parent = dir; + ihold(dir); mask = CEPH_STAT_CAP_INODE | CEPH_CAP_AUTH_SHARED; if (ceph_security_xattr_wanted(dir)) diff --git a/fs/ceph/export.c b/fs/ceph/export.c index d3ef7ee429ec..e7804720549d 100644 --- a/fs/ceph/export.c +++ b/fs/ceph/export.c @@ -519,6 +519,7 @@ static int ceph_get_name(struct dentry *parent, char *name, ihold(inode); req->r_ino2 = ceph_vino(d_inode(parent)); req->r_parent = d_inode(parent); + ihold(req->r_parent); set_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags); req->r_num_caps = 2; err = ceph_mdsc_do_request(mdsc, NULL, req); diff --git a/fs/ceph/file.c b/fs/ceph/file.c index 0e505a5e09fe..f24d18f46715 100644 --- a/fs/ceph/file.c +++ b/fs/ceph/file.c @@ -478,6 +478,7 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry, req->r_args.open.mask = cpu_to_le32(mask); req->r_parent = dir; + ihold(dir); set_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags); err = ceph_mdsc_do_request(mdsc, (flags & (O_CREAT|O_TRUNC)) ? dir : NULL, diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c index 9d1ac87e5897..8c05cfe57adf 100644 --- a/fs/ceph/mds_client.c +++ b/fs/ceph/mds_client.c @@ -696,8 +696,10 @@ void ceph_mdsc_release_request(struct kref *kref) ceph_put_cap_refs(ceph_inode(req->r_inode), CEPH_CAP_PIN); iput(req->r_inode); } - if (req->r_parent) + if (req->r_parent) { ceph_put_cap_refs(ceph_inode(req->r_parent), CEPH_CAP_PIN); + iput(req->r_parent); + } iput(req->r_target_inode); if (req->r_dentry) dput(req->r_dentry); From patchwork Tue Apr 9 19:42:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 10892201 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4688C13B5 for ; Tue, 9 Apr 2019 19:42:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3579228699 for ; Tue, 9 Apr 2019 19:42:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3420828971; Tue, 9 Apr 2019 19:42: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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D875F2897D for ; Tue, 9 Apr 2019 19:42:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726688AbfDITmh (ORCPT ); Tue, 9 Apr 2019 15:42:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:57792 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726536AbfDITme (ORCPT ); Tue, 9 Apr 2019 15:42:34 -0400 Received: from tleilax.poochiereds.net (cpe-71-70-156-158.nc.res.rr.com [71.70.156.158]) (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 800472077C for ; Tue, 9 Apr 2019 19:42:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554838953; bh=N1mDEvqCt18SXkS2HLlHHPgv5Mnk4D5irXxHtZ+B5dk=; h=From:To:Subject:Date:In-Reply-To:References:From; b=xyd1L3RR1CuHHTqqRqkta04FOUPDjmkLLekDZ9eBOz9CZeP9tjjPqKtEp2gzW63QX KsHp4BMpwUScNAIYz8MWht8ekm16G2I7rW1cSNwqDCyx93MqOXUUn/gDgHLrogMJ8F I/p1dXJsfGrKMyiiLzhfYdS63SFdrCplCYA+0NOw= From: Jeff Layton To: ceph-devel@vger.kernel.org Subject: [RFC PATCH 05/11] ceph: fix comment over ceph_drop_caps_for_unlink Date: Tue, 9 Apr 2019 15:42:23 -0400 Message-Id: <20190409194229.8247-6-jlayton@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190409194229.8247-1-jlayton@kernel.org> References: <20190409194229.8247-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 X-Virus-Scanned: ClamAV using ClamSMTP It's not clear what AUTH_RDCACHE means in this context, and we're clearly just dropping LINK caps here. Signed-off-by: Jeff Layton --- fs/ceph/caps.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c index f976939f771f..90090a56899e 100644 --- a/fs/ceph/caps.c +++ b/fs/ceph/caps.c @@ -4096,7 +4096,7 @@ void ceph_put_fmode(struct ceph_inode_info *ci, int fmode) } /* - * For a soon-to-be unlinked file, drop the AUTH_RDCACHE caps. If it + * For a soon-to-be unlinked file, drop the LINK caps. If it * looks like the link count will hit 0, drop any other caps (other * than PIN) we don't specifically want (due to the file still being * open). From patchwork Tue Apr 9 19:42:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 10892197 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5E48913B5 for ; Tue, 9 Apr 2019 19:42:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4CA2B28950 for ; Tue, 9 Apr 2019 19:42:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4B0D828991; Tue, 9 Apr 2019 19:42:37 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BA0A828987 for ; Tue, 9 Apr 2019 19:42:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726656AbfDITmf (ORCPT ); Tue, 9 Apr 2019 15:42:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:57790 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726615AbfDITme (ORCPT ); Tue, 9 Apr 2019 15:42:34 -0400 Received: from tleilax.poochiereds.net (cpe-71-70-156-158.nc.res.rr.com [71.70.156.158]) (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 091C42084F for ; Tue, 9 Apr 2019 19:42:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554838954; bh=wR1kEJ7C2PXPK9sQz61e86HHBKLNOacLjXJIK6Y/KDc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=bGXJHQO7CTIvEaBFVGI6LSXx8lQNJH1Luzhw7MtcSNIyHMOsNSXgxK2OvkXFlyS5b Ij5cLN/fQB5nSmvTzb0gV8BNQJ3RKkIddtqby4WhAvNJVJ7CCRMk8yGPUu/e2dC6V0 YthnT5wT6W9dLZWJAAQ74pPp3LQqcEADUaX0oM38= From: Jeff Layton To: ceph-devel@vger.kernel.org Subject: [RFC PATCH 06/11] ceph: simplify arguments and return semantics of try_get_cap_refs Date: Tue, 9 Apr 2019 15:42:24 -0400 Message-Id: <20190409194229.8247-7-jlayton@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190409194229.8247-1-jlayton@kernel.org> References: <20190409194229.8247-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 X-Virus-Scanned: ClamAV using ClamSMTP The return of this function is rather complex. It can return 0 or 1, and in the case of a 1 return, the "err" pointer will be filled out. This necessitates a lot of copying of values. We can achieve the same effect by just returning 0, 1 or a negative error code, and drop the "err" argument from this function. Signed-off-by: Jeff Layton --- fs/ceph/caps.c | 76 ++++++++++++++++++++------------------------------ 1 file changed, 30 insertions(+), 46 deletions(-) diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c index 90090a56899e..9e0b464d374f 100644 --- a/fs/ceph/caps.c +++ b/fs/ceph/caps.c @@ -2525,9 +2525,14 @@ static void __take_cap_refs(struct ceph_inode_info *ci, int got, * to (when applicable), and check against max_size here as well. * Note that caller is responsible for ensuring max_size increases are * requested from the MDS. + * + * Returns 0 if caps were not able to be acquired (yet), a 1 if they were, + * or a negative error code. + * + * FIXME: how does a 0 return differ from -EAGAIN? */ static int try_get_cap_refs(struct ceph_inode_info *ci, int need, int want, - loff_t endoff, bool nonblock, int *got, int *err) + loff_t endoff, bool nonblock, int *got) { struct inode *inode = &ci->vfs_inode; struct ceph_mds_client *mdsc = ceph_inode_to_client(inode)->mdsc; @@ -2547,8 +2552,7 @@ static int try_get_cap_refs(struct ceph_inode_info *ci, int need, int want, if ((file_wanted & need) != need) { dout("try_get_cap_refs need %s file_wanted %s, EBADF\n", ceph_cap_string(need), ceph_cap_string(file_wanted)); - *err = -EBADF; - ret = 1; + ret = -EBADF; goto out_unlock; } @@ -2569,10 +2573,8 @@ static int try_get_cap_refs(struct ceph_inode_info *ci, int need, int want, if (endoff >= 0 && endoff > (loff_t)ci->i_max_size) { dout("get_cap_refs %p endoff %llu > maxsize %llu\n", inode, endoff, ci->i_max_size); - if (endoff > ci->i_requested_max_size) { - *err = -EAGAIN; - ret = 1; - } + if (endoff > ci->i_requested_max_size) + ret = -EAGAIN; goto out_unlock; } /* @@ -2607,8 +2609,7 @@ static int try_get_cap_refs(struct ceph_inode_info *ci, int need, int want, * task isn't in TASK_RUNNING state */ if (nonblock) { - *err = -EAGAIN; - ret = 1; + ret = -EAGAIN; goto out_unlock; } @@ -2637,8 +2638,7 @@ static int try_get_cap_refs(struct ceph_inode_info *ci, int need, int want, if (session_readonly) { dout("get_cap_refs %p needed %s but mds%d readonly\n", inode, ceph_cap_string(need), ci->i_auth_cap->mds); - *err = -EROFS; - ret = 1; + ret = -EROFS; goto out_unlock; } @@ -2647,16 +2647,14 @@ static int try_get_cap_refs(struct ceph_inode_info *ci, int need, int want, if (READ_ONCE(mdsc->fsc->mount_state) == CEPH_MOUNT_SHUTDOWN) { dout("get_cap_refs %p forced umount\n", inode); - *err = -EIO; - ret = 1; + ret = -EIO; goto out_unlock; } mds_wanted = __ceph_caps_mds_wanted(ci, false); if (need & ~(mds_wanted & need)) { dout("get_cap_refs %p caps were dropped" " (session killed?)\n", inode); - *err = -ESTALE; - ret = 1; + ret = -ESTALE; goto out_unlock; } if (!(file_wanted & ~mds_wanted)) @@ -2707,7 +2705,7 @@ static void check_max_size(struct inode *inode, loff_t endoff) int ceph_try_get_caps(struct ceph_inode_info *ci, int need, int want, bool nonblock, int *got) { - int ret, err = 0; + int ret; BUG_ON(need & ~CEPH_CAP_FILE_RD); BUG_ON(want & ~(CEPH_CAP_FILE_CACHE|CEPH_CAP_FILE_LAZYIO|CEPH_CAP_FILE_SHARED)); @@ -2715,15 +2713,8 @@ int ceph_try_get_caps(struct ceph_inode_info *ci, int need, int want, if (ret < 0) return ret; - ret = try_get_cap_refs(ci, need, want, 0, nonblock, got, &err); - if (ret) { - if (err == -EAGAIN) { - ret = 0; - } else if (err < 0) { - ret = err; - } - } - return ret; + ret = try_get_cap_refs(ci, need, want, 0, nonblock, got); + return ret == -EAGAIN ? 0 : ret; } /* @@ -2734,7 +2725,7 @@ int ceph_try_get_caps(struct ceph_inode_info *ci, int need, int want, int ceph_get_caps(struct ceph_inode_info *ci, int need, int want, loff_t endoff, int *got, struct page **pinned_page) { - int _got, ret, err = 0; + int _got, ret; ret = ceph_pool_perm_check(ci, need); if (ret < 0) @@ -2744,21 +2735,19 @@ int ceph_get_caps(struct ceph_inode_info *ci, int need, int want, if (endoff > 0) check_max_size(&ci->vfs_inode, endoff); - err = 0; _got = 0; ret = try_get_cap_refs(ci, need, want, endoff, - false, &_got, &err); - if (ret) { - if (err == -EAGAIN) - continue; - if (err < 0) - ret = err; - } else { + false, &_got); + if (ret == -EAGAIN) { + continue; + } else if (!ret) { + int err; + DEFINE_WAIT_FUNC(wait, woken_wake_function); add_wait_queue(&ci->i_cap_wq, &wait); - while (!try_get_cap_refs(ci, need, want, endoff, - true, &_got, &err)) { + while (!(err = try_get_cap_refs(ci, need, want, endoff, + true, &_got))) { if (signal_pending(current)) { ret = -ERESTARTSYS; break; @@ -2767,19 +2756,14 @@ int ceph_get_caps(struct ceph_inode_info *ci, int need, int want, } remove_wait_queue(&ci->i_cap_wq, &wait); - if (err == -EAGAIN) continue; - if (err < 0) - ret = err; } - if (ret < 0) { - if (err == -ESTALE) { - /* session was killed, try renew caps */ - ret = ceph_renew_caps(&ci->vfs_inode); - if (ret == 0) - continue; - } + if (ret == -ESTALE) { + /* session was killed, try renew caps */ + ret = ceph_renew_caps(&ci->vfs_inode); + if (ret == 0) + continue; return ret; } From patchwork Tue Apr 9 19:42:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 10892203 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 14F3717E6 for ; Tue, 9 Apr 2019 19:42:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 03A5228699 for ; Tue, 9 Apr 2019 19:42:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 021F028961; Tue, 9 Apr 2019 19:42: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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A5A8728699 for ; Tue, 9 Apr 2019 19:42:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726668AbfDITmg (ORCPT ); Tue, 9 Apr 2019 15:42:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:57792 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726446AbfDITmf (ORCPT ); Tue, 9 Apr 2019 15:42:35 -0400 Received: from tleilax.poochiereds.net (cpe-71-70-156-158.nc.res.rr.com [71.70.156.158]) (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 845012077C for ; Tue, 9 Apr 2019 19:42:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554838954; bh=Gf/ovcqZwrVYkLuPwTJbur8UJZ3nMsp+1WODO0I6esM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=fvNHzmIz1oHn/O0X+5bMMK3+knHp9VACo7eU+pkmXl3NcrxaT2aVQO3NQbHFBdcu/ 4wYmeWv3GFv2vc/AdD7ipFkYkjrmtE6vKPy39GxENSHERwgpE//nYdp3Acgn4WaVb8 lFUI+UgVNhjjroyVJPTUdyG6DLbn1zPiIeTz77Io= From: Jeff Layton To: ceph-devel@vger.kernel.org Subject: [RFC PATCH 07/11] ceph: register MDS request with dir inode from the get-go Date: Tue, 9 Apr 2019 15:42:25 -0400 Message-Id: <20190409194229.8247-8-jlayton@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190409194229.8247-1-jlayton@kernel.org> References: <20190409194229.8247-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 X-Virus-Scanned: ClamAV using ClamSMTP When the unsafe reply to a request comes in, we put it on the r_unsafe_dir inode's list. In future patches, we're going to need to wait on requests that may not have gotten an unsafe reply yet. Change __register_request to put the entry on the dir inode's list when the pointer is set in the request. Fix replay_unsafe_requests to skip entries without the CEPH_MDS_R_GOT_UNSAFE flag. The only other place that uses this list is fsync codepath, and for that we'd want to wait on all operations whether the flag is set or not. Signed-off-by: Jeff Layton --- fs/ceph/mds_client.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c index 8c05cfe57adf..6af31b1f148d 100644 --- a/fs/ceph/mds_client.c +++ b/fs/ceph/mds_client.c @@ -779,8 +779,13 @@ static void __register_request(struct ceph_mds_client *mdsc, mdsc->oldest_tid = req->r_tid; if (dir) { + struct ceph_inode_info *ci = ceph_inode(dir); + ihold(dir); req->r_unsafe_dir = dir; + spin_lock(&ci->i_unsafe_lock); + list_add_tail(&req->r_unsafe_dir_item, &ci->i_unsafe_dirops); + spin_unlock(&ci->i_unsafe_lock); } } @@ -808,8 +813,7 @@ static void __unregister_request(struct ceph_mds_client *mdsc, erase_request(&mdsc->request_tree, req); - if (req->r_unsafe_dir && - test_bit(CEPH_MDS_R_GOT_UNSAFE, &req->r_req_flags)) { + if (req->r_unsafe_dir) { struct ceph_inode_info *ci = ceph_inode(req->r_unsafe_dir); spin_lock(&ci->i_unsafe_lock); list_del_init(&req->r_unsafe_dir_item); @@ -2847,14 +2851,6 @@ static void handle_reply(struct ceph_mds_session *session, struct ceph_msg *msg) } else { set_bit(CEPH_MDS_R_GOT_UNSAFE, &req->r_req_flags); list_add_tail(&req->r_unsafe_item, &req->r_session->s_unsafe); - if (req->r_unsafe_dir) { - struct ceph_inode_info *ci = - ceph_inode(req->r_unsafe_dir); - spin_lock(&ci->i_unsafe_lock); - list_add_tail(&req->r_unsafe_dir_item, - &ci->i_unsafe_dirops); - spin_unlock(&ci->i_unsafe_lock); - } } dout("handle_reply tid %lld result %d\n", tid, result); From patchwork Tue Apr 9 19:42:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 10892209 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 400AA13B5 for ; Tue, 9 Apr 2019 19:42:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2A4FA2899E for ; Tue, 9 Apr 2019 19:42:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 262F8289A2; Tue, 9 Apr 2019 19:42:45 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C566A2899E for ; Tue, 9 Apr 2019 19:42:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726720AbfDITmn (ORCPT ); Tue, 9 Apr 2019 15:42:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:57816 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726635AbfDITmf (ORCPT ); Tue, 9 Apr 2019 15:42:35 -0400 Received: from tleilax.poochiereds.net (cpe-71-70-156-158.nc.res.rr.com [71.70.156.158]) (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 0C8392084B for ; Tue, 9 Apr 2019 19:42:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554838955; bh=eM1CZb16wJEfyuM8rSTraksR5scIG+C0mCyJkw0eSsE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=eCpmYjVF6piUMCW7odFlcBwOK6a4EZO+cPZ9ysUQnHQSxN2rI+CbWPUIAwLELPE65 CIchrgyG1mrVKn6rwgz6Gw4bBa+/8ymvV316fIoU2+Wt4Qxp9r9dtbyO1XDRdbM8Fu bYMQDZRSwruxMCyoum6vj6NzQuBzwQXtDuAkQ4i4= From: Jeff Layton To: ceph-devel@vger.kernel.org Subject: [RFC PATCH 08/11] ceph: add refcounting for Fx caps Date: Tue, 9 Apr 2019 15:42:26 -0400 Message-Id: <20190409194229.8247-9-jlayton@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190409194229.8247-1-jlayton@kernel.org> References: <20190409194229.8247-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 X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Jeff Layton --- fs/ceph/caps.c | 7 +++++++ fs/ceph/inode.c | 1 + fs/ceph/super.h | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c index 9e0b464d374f..6dc96844fdee 100644 --- a/fs/ceph/caps.c +++ b/fs/ceph/caps.c @@ -987,6 +987,8 @@ int __ceph_caps_used(struct ceph_inode_info *ci) used |= CEPH_CAP_FILE_WR; if (ci->i_wb_ref || ci->i_wrbuffer_ref) used |= CEPH_CAP_FILE_BUFFER; + if (ci->i_fx_ref) + used |= CEPH_CAP_FILE_EXCL; return used; } @@ -2502,6 +2504,8 @@ static void __take_cap_refs(struct ceph_inode_info *ci, int got, ci->i_rd_ref++; if (got & CEPH_CAP_FILE_CACHE) ci->i_rdcache_ref++; + if (got & CEPH_CAP_FILE_EXCL) + ci->i_fx_ref++; if (got & CEPH_CAP_FILE_WR) { if (ci->i_wr_ref == 0 && !ci->i_head_snapc) { BUG_ON(!snap_rwsem_locked); @@ -2865,6 +2869,9 @@ void ceph_put_cap_refs(struct ceph_inode_info *ci, int had) if (had & CEPH_CAP_FILE_CACHE) if (--ci->i_rdcache_ref == 0) last++; + if (had & CEPH_CAP_FILE_EXCL) + if (--ci->i_fx_ref == 0) + last++; if (had & CEPH_CAP_FILE_BUFFER) { if (--ci->i_wb_ref == 0) { last++; diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c index 2d61ddda9bf5..2a5b22985699 100644 --- a/fs/ceph/inode.c +++ b/fs/ceph/inode.c @@ -494,6 +494,7 @@ struct inode *ceph_alloc_inode(struct super_block *sb) ci->i_rdcache_ref = 0; ci->i_wr_ref = 0; ci->i_wb_ref = 0; + ci->i_fx_ref = 0; ci->i_wrbuffer_ref = 0; ci->i_wrbuffer_ref_head = 0; atomic_set(&ci->i_filelock_ref, 0); diff --git a/fs/ceph/super.h b/fs/ceph/super.h index a4b0da31d199..03cbb80faab1 100644 --- a/fs/ceph/super.h +++ b/fs/ceph/super.h @@ -368,7 +368,7 @@ struct ceph_inode_info { /* held references to caps */ int i_pin_ref; - int i_rd_ref, i_rdcache_ref, i_wr_ref, i_wb_ref; + int i_rd_ref, i_rdcache_ref, i_wr_ref, i_wb_ref, i_fx_ref; int i_wrbuffer_ref, i_wrbuffer_ref_head; atomic_t i_filelock_ref; atomic_t i_shared_gen; /* increment each time we get FILE_SHARED */ From patchwork Tue Apr 9 19:42:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 10892207 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 87F4F13B5 for ; Tue, 9 Apr 2019 19:42:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7729128950 for ; Tue, 9 Apr 2019 19:42:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6BA5528980; Tue, 9 Apr 2019 19:42:43 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1A37A28969 for ; Tue, 9 Apr 2019 19:42:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726712AbfDITml (ORCPT ); Tue, 9 Apr 2019 15:42:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:57818 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726615AbfDITmg (ORCPT ); Tue, 9 Apr 2019 15:42:36 -0400 Received: from tleilax.poochiereds.net (cpe-71-70-156-158.nc.res.rr.com [71.70.156.158]) (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 8A3492077C for ; Tue, 9 Apr 2019 19:42:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554838955; bh=YJOpTLsPZfqz0GBaN8f/e9Xy90XOCpjZXiXwkpONkHk=; h=From:To:Subject:Date:In-Reply-To:References:From; b=nznqVKQIcUdls7ae0G+SC0cwSRn7wDVNSZf41Wm5sQTjzBji6hnFSNHWnNhzl8Re8 2zM8wOBRGUhtdW202ca8ISjsvfogKwia8TGAzkpZDRD5padb9qAUwfnG71v4CqqHBn bYf14WgrwZTN8aaBdO2afc9Vmony1HpUyZmMFPkk= From: Jeff Layton To: ceph-devel@vger.kernel.org Subject: [RFC PATCH 09/11] ceph: add refcounting for Lx caps Date: Tue, 9 Apr 2019 15:42:27 -0400 Message-Id: <20190409194229.8247-10-jlayton@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190409194229.8247-1-jlayton@kernel.org> References: <20190409194229.8247-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 X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Jeff Layton --- fs/ceph/caps.c | 7 +++++++ fs/ceph/inode.c | 1 + fs/ceph/super.h | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c index 6dc96844fdee..d022e15c8378 100644 --- a/fs/ceph/caps.c +++ b/fs/ceph/caps.c @@ -989,6 +989,8 @@ int __ceph_caps_used(struct ceph_inode_info *ci) used |= CEPH_CAP_FILE_BUFFER; if (ci->i_fx_ref) used |= CEPH_CAP_FILE_EXCL; + if (ci->i_lx_ref) + used |= CEPH_CAP_LINK_EXCL; return used; } @@ -2506,6 +2508,8 @@ static void __take_cap_refs(struct ceph_inode_info *ci, int got, ci->i_rdcache_ref++; if (got & CEPH_CAP_FILE_EXCL) ci->i_fx_ref++; + if (got & CEPH_CAP_LINK_EXCL) + ci->i_lx_ref++; if (got & CEPH_CAP_FILE_WR) { if (ci->i_wr_ref == 0 && !ci->i_head_snapc) { BUG_ON(!snap_rwsem_locked); @@ -2872,6 +2876,9 @@ void ceph_put_cap_refs(struct ceph_inode_info *ci, int had) if (had & CEPH_CAP_FILE_EXCL) if (--ci->i_fx_ref == 0) last++; + if (had & CEPH_CAP_LINK_EXCL) + if (--ci->i_lx_ref == 0) + last++; if (had & CEPH_CAP_FILE_BUFFER) { if (--ci->i_wb_ref == 0) { last++; diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c index 2a5b22985699..a7385ce4500b 100644 --- a/fs/ceph/inode.c +++ b/fs/ceph/inode.c @@ -495,6 +495,7 @@ struct inode *ceph_alloc_inode(struct super_block *sb) ci->i_wr_ref = 0; ci->i_wb_ref = 0; ci->i_fx_ref = 0; + ci->i_lx_ref = 0; ci->i_wrbuffer_ref = 0; ci->i_wrbuffer_ref_head = 0; atomic_set(&ci->i_filelock_ref, 0); diff --git a/fs/ceph/super.h b/fs/ceph/super.h index 03cbb80faab1..3c5608f2108a 100644 --- a/fs/ceph/super.h +++ b/fs/ceph/super.h @@ -368,7 +368,7 @@ struct ceph_inode_info { /* held references to caps */ int i_pin_ref; - int i_rd_ref, i_rdcache_ref, i_wr_ref, i_wb_ref, i_fx_ref; + int i_rd_ref, i_rdcache_ref, i_wr_ref, i_wb_ref, i_fx_ref, i_lx_ref; int i_wrbuffer_ref, i_wrbuffer_ref_head; atomic_t i_filelock_ref; atomic_t i_shared_gen; /* increment each time we get FILE_SHARED */ From patchwork Tue Apr 9 19:42:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 10892205 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 810B21805 for ; Tue, 9 Apr 2019 19:42:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6EBDE2897E for ; Tue, 9 Apr 2019 19:42:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6C9DB28991; Tue, 9 Apr 2019 19:42:42 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0645228985 for ; Tue, 9 Apr 2019 19:42:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726691AbfDITmh (ORCPT ); Tue, 9 Apr 2019 15:42:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:57802 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726682AbfDITmg (ORCPT ); Tue, 9 Apr 2019 15:42:36 -0400 Received: from tleilax.poochiereds.net (cpe-71-70-156-158.nc.res.rr.com [71.70.156.158]) (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 168942084B for ; Tue, 9 Apr 2019 19:42:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554838956; bh=HiYrBc2rwV+PM00tWtPdWZgy4Th3F2MA2yljlz1nKlw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=y4kR0yjzndG6UTHR6drOgIi1G6heJedSiizRC1DvHx8QjPnWX5utvWbMjXtLZ4ttY 7iI+YKp3d5Ffv3jFdwxcjY32O5PLNOgC5udfwcXbvl1VehWnbjOgdXXXTWwama93uO VMAnyZD2QVN+11pAOu1JCTGDLMxXKPaPw3wtZnLo= From: Jeff Layton To: ceph-devel@vger.kernel.org Subject: [RFC PATCH 10/11] ceph: perform asynchronous unlink if we have sufficient caps Date: Tue, 9 Apr 2019 15:42:28 -0400 Message-Id: <20190409194229.8247-11-jlayton@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190409194229.8247-1-jlayton@kernel.org> References: <20190409194229.8247-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 X-Virus-Scanned: ClamAV using ClamSMTP When performing an unlink, if we have Fx on the parent directory and Lx on the inode of the dentry being unlinked then we don't need to wait on the reply before returning. In that situation, just fix up the dcache and link count and return immediately after issuing the call to the MDS. This does mean that we need to hold an extra reference to the inode being unlinked, and extra references to the caps to avoid races. Put those references in the r_callback routine. If the operation ends up failing, then set a writeback error on the directory inode that can be fetched later by an fsync on the dir. Signed-off-by: Jeff Layton --- fs/ceph/caps.c | 22 ++++++++++++++++++++++ fs/ceph/dir.c | 38 +++++++++++++++++++++++++++++++++++--- fs/ceph/super.h | 1 + 3 files changed, 58 insertions(+), 3 deletions(-) diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c index d022e15c8378..8fbb09c761a7 100644 --- a/fs/ceph/caps.c +++ b/fs/ceph/caps.c @@ -2682,6 +2682,28 @@ static int try_get_cap_refs(struct ceph_inode_info *ci, int need, int want, return ret; } +bool ceph_get_caps_for_unlink(struct inode *dir, struct dentry *dentry) +{ + int err, got; + struct ceph_inode_info *ci = ceph_inode(d_inode(dentry)); + + /* Ensure we have Lx on the inode being unlinked */ + err = try_get_cap_refs(ci, 0, CEPH_CAP_LINK_EXCL, 0, true, &got); + dout("Lx on %p err=%d got=%d\n", dentry, err, got); + if (err != 1 || !(got & CEPH_CAP_LINK_EXCL)) + return false; + + /* Do we have Fx on the dir ? */ + err = try_get_cap_refs(ceph_inode(dir), 0, CEPH_CAP_FILE_EXCL, 0, + true, &got); + dout("Fx on %p err=%d got=%d\n", dir, err, got); + if (err != 1 || !(got & CEPH_CAP_FILE_EXCL)) { + ceph_put_cap_refs(ci, CEPH_CAP_LINK_EXCL); + return false; + } + return true; +} + /* * Check the offset we are writing up to against our current * max_size. If necessary, tell the MDS we want to write to diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c index 3eb9bc226b77..386c9439a020 100644 --- a/fs/ceph/dir.c +++ b/fs/ceph/dir.c @@ -1029,6 +1029,18 @@ static int ceph_link(struct dentry *old_dentry, struct inode *dir, return err; } +static void ceph_async_unlink_cb(struct ceph_mds_client *mdsc, + struct ceph_mds_request *req) +{ + struct ceph_inode_info *ci = ceph_inode(req->r_old_inode); + + /* If op failed, set error on parent directory */ + mapping_set_error(req->r_parent->i_mapping, req->r_err); + ceph_put_cap_refs(ci, CEPH_CAP_LINK_EXCL); + ceph_put_cap_refs(ceph_inode(req->r_parent), CEPH_CAP_FILE_EXCL); + iput(req->r_old_inode); +} + /* * rmdir and unlink are differ only by the metadata op code */ @@ -1065,9 +1077,29 @@ static int ceph_unlink(struct inode *dir, struct dentry *dentry) req->r_dentry_drop = CEPH_CAP_FILE_SHARED; req->r_dentry_unless = CEPH_CAP_FILE_EXCL; req->r_inode_drop = ceph_drop_caps_for_unlink(inode); - err = ceph_mdsc_do_request(mdsc, dir, req); - if (!err && !req->r_reply_info.head->is_dentry) - d_delete(dentry); + + if (op == CEPH_MDS_OP_UNLINK && + ceph_get_caps_for_unlink(dir, dentry)) { + /* Keep LINK caps to ensure continuity over async call */ + req->r_inode_drop &= ~(CEPH_CAP_LINK_SHARED|CEPH_CAP_LINK_EXCL); + req->r_callback = ceph_async_unlink_cb; + req->r_old_inode = d_inode(dentry); + ihold(req->r_old_inode); + err = ceph_mdsc_submit_request(mdsc, dir, req); + if (!err) { + /* + * We have enough caps, so we assume that the unlink + * will succeed. Fix up the target inode and dcache. + */ + drop_nlink(inode); + d_delete(dentry); + } + } else { + err = ceph_mdsc_do_request(mdsc, dir, req); + if (!err && !req->r_reply_info.head->is_dentry) + d_delete(dentry); + } + ceph_mdsc_put_request(req); out: return err; diff --git a/fs/ceph/super.h b/fs/ceph/super.h index 3c5608f2108a..5c361dc1f47f 100644 --- a/fs/ceph/super.h +++ b/fs/ceph/super.h @@ -1033,6 +1033,7 @@ extern int ceph_get_caps(struct ceph_inode_info *ci, int need, int want, loff_t endoff, int *got, struct page **pinned_page); extern int ceph_try_get_caps(struct ceph_inode_info *ci, int need, int want, bool nonblock, int *got); +extern bool ceph_get_caps_for_unlink(struct inode *dir, struct dentry *dentry); /* for counting open files by mode */ extern void __ceph_get_fmode(struct ceph_inode_info *ci, int mode); From patchwork Tue Apr 9 19:42:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 10892199 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D113813B5 for ; Tue, 9 Apr 2019 19:42:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BFF4D28969 for ; Tue, 9 Apr 2019 19:42:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BE85128978; Tue, 9 Apr 2019 19:42:39 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4D4AB28998 for ; Tue, 9 Apr 2019 19:42:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726705AbfDITmi (ORCPT ); Tue, 9 Apr 2019 15:42:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:57790 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726446AbfDITmh (ORCPT ); Tue, 9 Apr 2019 15:42:37 -0400 Received: from tleilax.poochiereds.net (cpe-71-70-156-158.nc.res.rr.com [71.70.156.158]) (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 944992084F for ; Tue, 9 Apr 2019 19:42:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554838956; bh=U0BIF7rm0ylP18z8pUpgGqUGzMlkbhTPCMiYJIOSCy4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=N3Nq3Qdc08/B0gofwsQxSmC6kwlDNtmDNy5oTT1JhwI8ao28AXYJAyJuNVstVjcYT YOmSDxp+/Bzl0Jwm995au4xrYBBeVME9xBnD823Kf8hPuf4Vh3R9RFA/cAgDKqYxnY 3K08YAxQZ9xRE01OovSGvs9W9m5NbAX6s6JnwGXc= From: Jeff Layton To: ceph-devel@vger.kernel.org Subject: [RFC PATCH 11/11] ceph: wait for async dir ops to complete before doing synchronous dir ops Date: Tue, 9 Apr 2019 15:42:29 -0400 Message-Id: <20190409194229.8247-12-jlayton@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190409194229.8247-1-jlayton@kernel.org> References: <20190409194229.8247-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 X-Virus-Scanned: ClamAV using ClamSMTP Ensure that we wait on replies from any pending directory operations involving children before we allow synchronous operations involving that directory to proceed. Signed-off-by: Jeff Layton --- fs/ceph/dir.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++--- fs/ceph/file.c | 4 +++ fs/ceph/super.h | 1 + 3 files changed, 66 insertions(+), 4 deletions(-) diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c index 386c9439a020..0b8cee46e07c 100644 --- a/fs/ceph/dir.c +++ b/fs/ceph/dir.c @@ -998,11 +998,16 @@ static int ceph_link(struct dentry *old_dentry, struct inode *dir, struct ceph_mds_request *req; int err; + dout("link in dir %p old_dentry %p dentry %p\n", dir, + old_dentry, dentry); + if (ceph_snap(dir) != CEPH_NOSNAP) return -EROFS; - dout("link in dir %p old_dentry %p dentry %p\n", dir, - old_dentry, dentry); + err = ceph_async_dirop_request_wait(dir); + if (err) + return err; + req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_LINK, USE_AUTH_MDS); if (IS_ERR(req)) { d_drop(dentry); @@ -1041,6 +1046,43 @@ static void ceph_async_unlink_cb(struct ceph_mds_client *mdsc, iput(req->r_old_inode); } +int ceph_async_dirop_request_wait(struct inode *inode) +{ + struct ceph_inode_info *ci = ceph_inode(inode); + struct ceph_mds_request *req = NULL; + int ret = 0; + + /* Only applicable for directories */ + if (S_ISDIR(inode->i_mode)) + return 0; + + spin_lock(&ci->i_unsafe_lock); + if (!list_empty(&ci->i_unsafe_dirops)) { + struct ceph_mds_request *last; + last = list_last_entry(&ci->i_unsafe_dirops, + struct ceph_mds_request, + r_unsafe_dir_item); + /* + * If last request hasn't gotten a reply, then wait + * for it. + */ + if (!test_bit(CEPH_MDS_R_GOT_UNSAFE, &last->r_req_flags) && + !test_bit(CEPH_MDS_R_GOT_SAFE, &last->r_req_flags)) { + req = last; + ceph_mdsc_get_request(req); + } + } + spin_unlock(&ci->i_unsafe_lock); + + if (req) { + dout("%s %p wait on tid %llu\n", __func__, inode, + req ? req->r_tid : 0ULL); + ret = wait_for_completion_killable(&req->r_completion); + ceph_mdsc_put_request(req); + } + return ret; +} + /* * rmdir and unlink are differ only by the metadata op code */ @@ -1064,6 +1106,12 @@ static int ceph_unlink(struct inode *dir, struct dentry *dentry) CEPH_MDS_OP_RMDIR : CEPH_MDS_OP_UNLINK; } else goto out; + + /* Wait for any requests involving children to get a reply */ + err = ceph_async_dirop_request_wait(dir); + if (err) + goto out; + req = ceph_mdsc_create_request(mdsc, op, USE_AUTH_MDS); if (IS_ERR(req)) { err = PTR_ERR(req); @@ -1115,6 +1163,9 @@ static int ceph_rename(struct inode *old_dir, struct dentry *old_dentry, int op = CEPH_MDS_OP_RENAME; int err; + dout("rename dir %p dentry %p to dir %p dentry %p\n", + old_dir, old_dentry, new_dir, new_dentry); + if (flags) return -EINVAL; @@ -1131,8 +1182,14 @@ static int ceph_rename(struct inode *old_dir, struct dentry *old_dentry, (!ceph_quota_is_same_realm(old_dir, new_dir))) return -EXDEV; - dout("rename dir %p dentry %p to dir %p dentry %p\n", - old_dir, old_dentry, new_dir, new_dentry); + err = ceph_async_dirop_request_wait(old_dir); + if (err) + return err; + + err = ceph_async_dirop_request_wait(new_dir); + if (err) + return err; + req = ceph_mdsc_create_request(mdsc, op, USE_AUTH_MDS); if (IS_ERR(req)) return PTR_ERR(req); diff --git a/fs/ceph/file.c b/fs/ceph/file.c index f24d18f46715..f7e49907514e 100644 --- a/fs/ceph/file.c +++ b/fs/ceph/file.c @@ -444,6 +444,10 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry, dir, dentry, dentry, d_unhashed(dentry) ? "unhashed" : "hashed", flags, mode); + err = ceph_async_dirop_request_wait(dir); + if (err) + return err; + if (dentry->d_name.len > NAME_MAX) return -ENAMETOOLONG; diff --git a/fs/ceph/super.h b/fs/ceph/super.h index 5c361dc1f47f..e97a6ce31a4e 100644 --- a/fs/ceph/super.h +++ b/fs/ceph/super.h @@ -1070,6 +1070,7 @@ extern int ceph_handle_snapdir(struct ceph_mds_request *req, struct dentry *dentry, int err); extern struct dentry *ceph_finish_lookup(struct ceph_mds_request *req, struct dentry *dentry, int err); +extern int ceph_async_dirop_request_wait(struct inode *inode); extern void __ceph_dentry_lease_touch(struct ceph_dentry_info *di); extern void __ceph_dentry_dir_lease_touch(struct ceph_dentry_info *di);