From patchwork Tue Jun 15 14:57:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 460592 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 83458C48BDF for ; Tue, 15 Jun 2021 14:57:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 56B866145D for ; Tue, 15 Jun 2021 14:57:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231140AbhFOO7i (ORCPT ); Tue, 15 Jun 2021 10:59:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:58704 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230298AbhFOO7g (ORCPT ); Tue, 15 Jun 2021 10:59:36 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 04CB761584; Tue, 15 Jun 2021 14:57:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1623769052; bh=WeGkGoFuxB/K90Y0r5W0csZbjj8cH51PuDrA08JVSY0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pYPTSUNnwcHBvRH2Q4EiPM73uqvqLRhh6+jSlgxHvXT2rUzeiwuZ+xNn0Q8dyCPUG 0dFqPd9E2CJdrxU2erqVDopZ/gjaiXPkmSi+4hwP8oGmurp895VPHfrSryzHJqO36V KrLmyzRmt/4MVQBryXJ9FYM2UT6Xrd3QqkxvcF3CuVtGwdhdlDXFnlNcY6+6V7Fxt9 pgg8aVQsHKA757Llwd3XcXpSb6NxauTOcC8nsRyuxoLopiTiONEa2rKPaHlPru6K/s SjR2bD0ZuFFDhaIkJnm9JNXob0uegpnLUlOsFcIxvwFSQHCsh1iqmlpHHNNuG5VZrb tiDH+WRbySXAw== From: Jeff Layton To: ceph-devel@vger.kernel.org Cc: pdonnell@redhat.com, ukernel@gmail.com, idryomov@gmail.com, xiubli@redhat.com Subject: [RFC PATCH 1/6] ceph: allow ceph_put_mds_session to take NULL or ERR_PTR Date: Tue, 15 Jun 2021 10:57:25 -0400 Message-Id: <20210615145730.21952-2-jlayton@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615145730.21952-1-jlayton@kernel.org> References: <20210615145730.21952-1-jlayton@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org ...to simplify some error paths. Signed-off-by: Jeff Layton Reviewed-by: Luis Henriques --- fs/ceph/dir.c | 3 +-- fs/ceph/inode.c | 6 ++---- fs/ceph/mds_client.c | 6 ++++-- fs/ceph/metric.c | 3 +-- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c index ac431246e0c9..0dc5f8357f58 100644 --- a/fs/ceph/dir.c +++ b/fs/ceph/dir.c @@ -1802,8 +1802,7 @@ static void ceph_d_release(struct dentry *dentry) dentry->d_fsdata = NULL; spin_unlock(&dentry->d_lock); - if (di->lease_session) - ceph_put_mds_session(di->lease_session); + ceph_put_mds_session(di->lease_session); kmem_cache_free(ceph_dentry_cachep, di); } diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c index df0c8a724609..6f43542b3344 100644 --- a/fs/ceph/inode.c +++ b/fs/ceph/inode.c @@ -1154,8 +1154,7 @@ static inline void update_dentry_lease(struct inode *dir, struct dentry *dentry, __update_dentry_lease(dir, dentry, lease, session, from_time, &old_lease_session); spin_unlock(&dentry->d_lock); - if (old_lease_session) - ceph_put_mds_session(old_lease_session); + ceph_put_mds_session(old_lease_session); } /* @@ -1200,8 +1199,7 @@ static void update_dentry_lease_careful(struct dentry *dentry, from_time, &old_lease_session); out_unlock: spin_unlock(&dentry->d_lock); - if (old_lease_session) - ceph_put_mds_session(old_lease_session); + ceph_put_mds_session(old_lease_session); } /* diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c index e5af591d3bd4..ec669634c649 100644 --- a/fs/ceph/mds_client.c +++ b/fs/ceph/mds_client.c @@ -664,6 +664,9 @@ struct ceph_mds_session *ceph_get_mds_session(struct ceph_mds_session *s) void ceph_put_mds_session(struct ceph_mds_session *s) { + if (IS_ERR_OR_NULL(s)) + return; + dout("mdsc put_session %p %d -> %d\n", s, refcount_read(&s->s_ref), refcount_read(&s->s_ref)-1); if (refcount_dec_and_test(&s->s_ref)) { @@ -1438,8 +1441,7 @@ static void __open_export_target_sessions(struct ceph_mds_client *mdsc, for (i = 0; i < mi->num_export_targets; i++) { ts = __open_export_target_session(mdsc, mi->export_targets[i]); - if (!IS_ERR(ts)) - ceph_put_mds_session(ts); + ceph_put_mds_session(ts); } } diff --git a/fs/ceph/metric.c b/fs/ceph/metric.c index 9577c71e645d..5ac151eb0d49 100644 --- a/fs/ceph/metric.c +++ b/fs/ceph/metric.c @@ -311,8 +311,7 @@ void ceph_metric_destroy(struct ceph_client_metric *m) cancel_delayed_work_sync(&m->delayed_work); - if (m->session) - ceph_put_mds_session(m->session); + ceph_put_mds_session(m->session); } #define METRIC_UPDATE_MIN_MAX(min, max, new) \ From patchwork Tue Jun 15 14:57:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 460591 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 745CFC48BDF for ; Tue, 15 Jun 2021 14:57:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5275461580 for ; Tue, 15 Jun 2021 14:57:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231409AbhFOO7k (ORCPT ); Tue, 15 Jun 2021 10:59:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:58728 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231346AbhFOO7j (ORCPT ); Tue, 15 Jun 2021 10:59:39 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1FCF161585; Tue, 15 Jun 2021 14:57:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1623769054; bh=xl5k40Kqo/vr+9qvaBVVZ5c0vdAds5jebNgpa78KCbg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XZY1WZYr4JPDyGS56ipyq6vquhun36ttifar+QLkzBLyYkJphpN+OkPNQAC0uZGDC OYLgnReVhBhqvV4oXEsSZmL+fwWd7zZ56lY7WpR/gbpwT4t6keNQeOUlAKKXJdUpNk lgFZQkQL+XIT3N5uIpblvf+s4et+r5/xFL8xVE9lcN7aM1RgjLTwpjcr//ZFFwB5dm jqBBB/Kp1QLHv35rUyVkbbtzYYZmp1eROSa8JQyBdLctGHQulB2+Zs/5rZUpJmFl4H /+LfHd9/G5qpXiJXkzMsKm6CJSAmVMG13T/wm7brqIAXxUekpzufVRgLw/y7Ik7hGS 50IzErlZElZeA== From: Jeff Layton To: ceph-devel@vger.kernel.org Cc: pdonnell@redhat.com, ukernel@gmail.com, idryomov@gmail.com, xiubli@redhat.com Subject: [RFC PATCH 4/6] ceph: don't take s_mutex in try_flush_caps Date: Tue, 15 Jun 2021 10:57:28 -0400 Message-Id: <20210615145730.21952-5-jlayton@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615145730.21952-1-jlayton@kernel.org> References: <20210615145730.21952-1-jlayton@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org The s_mutex doesn't protect anything in this codepath. Signed-off-by: Jeff Layton Reviewed-by: Luis Henriques --- fs/ceph/caps.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c index 825b1e463ad3..d21b1fa36875 100644 --- a/fs/ceph/caps.c +++ b/fs/ceph/caps.c @@ -2149,26 +2149,17 @@ static int try_flush_caps(struct inode *inode, u64 *ptid) { struct ceph_mds_client *mdsc = ceph_sb_to_client(inode->i_sb)->mdsc; struct ceph_inode_info *ci = ceph_inode(inode); - struct ceph_mds_session *session = NULL; int flushing = 0; u64 flush_tid = 0, oldest_flush_tid = 0; -retry: spin_lock(&ci->i_ceph_lock); retry_locked: if (ci->i_dirty_caps && ci->i_auth_cap) { struct ceph_cap *cap = ci->i_auth_cap; struct cap_msg_args arg; + struct ceph_mds_session *session = cap->session; - if (session != cap->session) { - spin_unlock(&ci->i_ceph_lock); - if (session) - mutex_unlock(&session->s_mutex); - session = cap->session; - mutex_lock(&session->s_mutex); - goto retry; - } - if (cap->session->s_state < CEPH_MDS_SESSION_OPEN) { + if (session->s_state < CEPH_MDS_SESSION_OPEN) { spin_unlock(&ci->i_ceph_lock); goto out; } @@ -2205,9 +2196,6 @@ static int try_flush_caps(struct inode *inode, u64 *ptid) spin_unlock(&ci->i_ceph_lock); } out: - if (session) - mutex_unlock(&session->s_mutex); - *ptid = flush_tid; return flushing; } From patchwork Tue Jun 15 14:57:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 460590 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EE2A6C49EA2 for ; Tue, 15 Jun 2021 14:57:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D050061580 for ; Tue, 15 Jun 2021 14:57:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231488AbhFOO7k (ORCPT ); Tue, 15 Jun 2021 10:59:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:58738 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231389AbhFOO7j (ORCPT ); Tue, 15 Jun 2021 10:59:39 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id CC83761584; Tue, 15 Jun 2021 14:57:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1623769055; bh=Jw6Ug6zgXs6K4EVcrCk30dxjE3sccLIEYRwJRtXKBhk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kOTGPxzgprVWyHHymRt3TszEwxJqco+Nd6RuNdGLD6TO8DsY3tC3jWY+LAsKrDBys B0T6N56OTFKukeMSt1JU83rA7lzrl3YMfHG8rCvxidP9NFzJ2oPp0HRdUNlxpXBz8j tAzztfK3N86Q4FN11RJA1OyoBECBVuAyJLUY7zeMMV65bU5VDZYXkQHWRqi5xUK0uQ vwB8Hq6O7yfgPRU9eNPph8WIyuI8gUod5CU1VYO5vdotG9ikuPkRl5xWTzWZRoMfAV mUjIm98UzqslnMx+pb30z17vrZjNHO/N+fDXHWf+c+Q/RD1pNDMm55ElWLBi+FwQ+B HRBIGz6bwDHIw== From: Jeff Layton To: ceph-devel@vger.kernel.org Cc: pdonnell@redhat.com, ukernel@gmail.com, idryomov@gmail.com, xiubli@redhat.com Subject: [RFC PATCH 5/6] ceph: don't take s_mutex in ceph_flush_snaps Date: Tue, 15 Jun 2021 10:57:29 -0400 Message-Id: <20210615145730.21952-6-jlayton@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615145730.21952-1-jlayton@kernel.org> References: <20210615145730.21952-1-jlayton@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org Signed-off-by: Jeff Layton Reviewed-by: Luis Henriques --- fs/ceph/caps.c | 8 +------- fs/ceph/snap.c | 4 +--- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c index d21b1fa36875..5864d5088e27 100644 --- a/fs/ceph/caps.c +++ b/fs/ceph/caps.c @@ -1531,7 +1531,7 @@ static inline int __send_flush_snap(struct inode *inode, * asynchronously back to the MDS once sync writes complete and dirty * data is written out. * - * Called under i_ceph_lock. Takes s_mutex as needed. + * Called under i_ceph_lock. */ static void __ceph_flush_snaps(struct ceph_inode_info *ci, struct ceph_mds_session *session) @@ -1653,7 +1653,6 @@ void ceph_flush_snaps(struct ceph_inode_info *ci, mds = ci->i_auth_cap->session->s_mds; if (session && session->s_mds != mds) { dout(" oops, wrong session %p mutex\n", session); - mutex_unlock(&session->s_mutex); ceph_put_mds_session(session); session = NULL; } @@ -1662,10 +1661,6 @@ void ceph_flush_snaps(struct ceph_inode_info *ci, mutex_lock(&mdsc->mutex); session = __ceph_lookup_mds_session(mdsc, mds); mutex_unlock(&mdsc->mutex); - if (session) { - dout(" inverting session/ino locks on %p\n", session); - mutex_lock(&session->s_mutex); - } goto retry; } @@ -1680,7 +1675,6 @@ void ceph_flush_snaps(struct ceph_inode_info *ci, if (psession) { *psession = session; } else if (session) { - mutex_unlock(&session->s_mutex); ceph_put_mds_session(session); } /* we flushed them all; remove this inode from the queue */ diff --git a/fs/ceph/snap.c b/fs/ceph/snap.c index f8cac2abab3f..afc7f4c32364 100644 --- a/fs/ceph/snap.c +++ b/fs/ceph/snap.c @@ -846,10 +846,8 @@ static void flush_snaps(struct ceph_mds_client *mdsc) } spin_unlock(&mdsc->snap_flush_lock); - if (session) { - mutex_unlock(&session->s_mutex); + if (session) ceph_put_mds_session(session); - } dout("flush_snaps done\n"); }