From: Wu Bo <wubo40@huawei.com> To: <jlayton@kernel.org>, <sage@redhat.com>, <idryomov@gmail.com> Cc: <ceph-devel@vger.kernel.org>, <linux-kernel@vger.kernel.org>, <liuzhiqiang26@huawei.com>, <linfeilong@huawei.com>, <wubo40@huawei.com> Subject: [PATCH V2] fs/ceph:fix double unlock in handle_cap_export() Date: Tue, 28 Apr 2020 21:13:42 +0800 [thread overview] Message-ID: <1588079622-423774-1-git-send-email-wubo40@huawei.com> (raw) if the ceph_mdsc_open_export_target_session() return fails, should add a lock to avoid twice unlocking. Because the lock will be released at the retry or out_unlock tag. -- v1 -> v2: add spin_lock(&ci->i_ceph_lock) before goto out_unlock tag. Signed-off-by: Wu Bo <wubo40@huawei.com> --- fs/ceph/caps.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c index 185db76..414c0e2 100644 --- a/fs/ceph/caps.c +++ b/fs/ceph/caps.c @@ -3731,22 +3731,25 @@ static void handle_cap_export(struct inode *inode, struct ceph_mds_caps *ex, /* open target session */ tsession = ceph_mdsc_open_export_target_session(mdsc, target); - if (!IS_ERR(tsession)) { - if (mds > target) { - mutex_lock(&session->s_mutex); - mutex_lock_nested(&tsession->s_mutex, - SINGLE_DEPTH_NESTING); - } else { - mutex_lock(&tsession->s_mutex); - mutex_lock_nested(&session->s_mutex, - SINGLE_DEPTH_NESTING); - } - new_cap = ceph_get_cap(mdsc, NULL); - } else { + if (IS_ERR(tsession)) { WARN_ON(1); tsession = NULL; target = -1; + mutex_lock(&session->s_mutex); + spin_lock(&ci->i_ceph_lock); + goto out_unlock; + } + + if (mds > target) { + mutex_lock(&session->s_mutex); + mutex_lock_nested(&tsession->s_mutex, + SINGLE_DEPTH_NESTING); + } else { + mutex_lock(&tsession->s_mutex); + mutex_lock_nested(&session->s_mutex, + SINGLE_DEPTH_NESTING); } + new_cap = ceph_get_cap(mdsc, NULL); goto retry; out_unlock: -- 1.8.3.1
WARNING: multiple messages have this Message-ID (diff)
From: Wu Bo <wubo40@huawei.com> To: jlayton@kernel.org, sage@redhat.com, idryomov@gmail.com Cc: ceph-devel@vger.kernel.org, linux-kernel@vger.kernel.org, liuzhiqiang26@huawei.com, linfeilong@huawei.com, wubo40@huawei.com Subject: [PATCH V2] fs/ceph:fix double unlock in handle_cap_export() Date: Tue, 28 Apr 2020 21:13:42 +0800 [thread overview] Message-ID: <1588079622-423774-1-git-send-email-wubo40@huawei.com> (raw) if the ceph_mdsc_open_export_target_session() return fails, should add a lock to avoid twice unlocking. Because the lock will be released at the retry or out_unlock tag. -- v1 -> v2: add spin_lock(&ci->i_ceph_lock) before goto out_unlock tag. Signed-off-by: Wu Bo <wubo40@huawei.com> --- fs/ceph/caps.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c index 185db76..414c0e2 100644 --- a/fs/ceph/caps.c +++ b/fs/ceph/caps.c @@ -3731,22 +3731,25 @@ static void handle_cap_export(struct inode *inode, struct ceph_mds_caps *ex, /* open target session */ tsession = ceph_mdsc_open_export_target_session(mdsc, target); - if (!IS_ERR(tsession)) { - if (mds > target) { - mutex_lock(&session->s_mutex); - mutex_lock_nested(&tsession->s_mutex, - SINGLE_DEPTH_NESTING); - } else { - mutex_lock(&tsession->s_mutex); - mutex_lock_nested(&session->s_mutex, - SINGLE_DEPTH_NESTING); - } - new_cap = ceph_get_cap(mdsc, NULL); - } else { + if (IS_ERR(tsession)) { WARN_ON(1); tsession = NULL; target = -1; + mutex_lock(&session->s_mutex); + spin_lock(&ci->i_ceph_lock); + goto out_unlock; + } + + if (mds > target) { + mutex_lock(&session->s_mutex); + mutex_lock_nested(&tsession->s_mutex, + SINGLE_DEPTH_NESTING); + } else { + mutex_lock(&tsession->s_mutex); + mutex_lock_nested(&session->s_mutex, + SINGLE_DEPTH_NESTING); } + new_cap = ceph_get_cap(mdsc, NULL); goto retry; out_unlock: -- 1.8.3.1
next reply other threads:[~2020-04-28 13:14 UTC|newest] Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-04-28 13:13 Wu Bo [this message] 2020-04-28 13:13 ` [PATCH V2] fs/ceph:fix double unlock in handle_cap_export() Wu Bo 2020-04-28 14:48 ` Jeff Layton 2020-04-29 0:46 ` Wu Bo 2020-04-29 0:46 ` Wu Bo 2020-04-29 15:31 ` Jeff Layton 2020-04-30 2:50 ` Yan, Zheng 2020-04-30 4:31 ` Wu Bo 2020-04-30 4:31 ` Wu Bo
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=1588079622-423774-1-git-send-email-wubo40@huawei.com \ --to=wubo40@huawei.com \ --cc=ceph-devel@vger.kernel.org \ --cc=idryomov@gmail.com \ --cc=jlayton@kernel.org \ --cc=linfeilong@huawei.com \ --cc=linux-kernel@vger.kernel.org \ --cc=liuzhiqiang26@huawei.com \ --cc=sage@redhat.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.