public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peng Tao <bergwolf@gmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-kernel@vger.kernel.org,
	Andriy Skulysh <Andriy_Skulysh@xyratex.com>,
	Peng Tao <bergwolf@gmail.com>,
	Andreas Dilger <andreas.dilger@intel.com>
Subject: [PATCH 04/16] staging/lustre/ptlrpc: Fix race during exp_flock_hash creation
Date: Tue, 26 Nov 2013 10:04:58 +0800	[thread overview]
Message-ID: <1385431510-18988-5-git-send-email-bergwolf@gmail.com> (raw)
In-Reply-To: <1385431510-18988-1-git-send-email-bergwolf@gmail.com>

From: Andriy Skulysh <Andriy_Skulysh@xyratex.com>

During race exp_flock_hash can be created 2 times.
It is created & assigned without any lock.

Move hash initialization from ldlm_flock_blocking_link()
to ldlm_init_export()

Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-2835
Lustre-change: http://review.whamcloud.com/5471
Signed-off-by: Andriy Skulysh <Andriy_Skulysh@xyratex.com>
Reviewed-by: Alexander Boyko <Alexander_Boyko@xyratex.com>
Reviewed-by: Vitaly Fertman <Vitaly_Fertman@xyratex.com>
Tested-by: Kyrylo Shatskyy <kyrylo_shatskyy@xyratex.com>
Reviewed-by: Keith Mannthey <keith.mannthey@intel.com>
Reviewed-by: Prakash Surya <surya1@llnl.gov>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
Signed-off-by: Peng Tao <bergwolf@gmail.com>
Signed-off-by: Andreas Dilger <andreas.dilger@intel.com>
---
 drivers/staging/lustre/lustre/ldlm/ldlm_flock.c |   28 +++++++----------------
 drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c |    8 +++++++
 2 files changed, 16 insertions(+), 20 deletions(-)

diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
index 456d5aa..c9aae13 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
@@ -95,20 +95,12 @@ ldlm_flocks_overlap(struct ldlm_lock *lock, struct ldlm_lock *new)
 		lock->l_policy_data.l_flock.start));
 }
 
-static inline int ldlm_flock_blocking_link(struct ldlm_lock *req,
-					   struct ldlm_lock *lock)
+static inline void ldlm_flock_blocking_link(struct ldlm_lock *req,
+					    struct ldlm_lock *lock)
 {
-	int rc = 0;
-
 	/* For server only */
 	if (req->l_export == NULL)
-		return 0;
-
-	if (unlikely(req->l_export->exp_flock_hash == NULL)) {
-		rc = ldlm_init_flock_export(req->l_export);
-		if (rc)
-			goto error;
-	}
+		return;
 
 	LASSERT(hlist_unhashed(&req->l_exp_flock_hash));
 
@@ -121,8 +113,6 @@ static inline int ldlm_flock_blocking_link(struct ldlm_lock *req,
 	cfs_hash_add(req->l_export->exp_flock_hash,
 		     &req->l_policy_data.l_flock.owner,
 		     &req->l_exp_flock_hash);
-error:
-	return rc;
 }
 
 static inline void ldlm_flock_blocking_unlink(struct ldlm_lock *req)
@@ -250,7 +240,6 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
 	int overlaps = 0;
 	int splitted = 0;
 	const struct ldlm_callback_suite null_cbs = { NULL };
-	int rc;
 
 	CDEBUG(D_DLMTRACE, "flags %#llx owner "LPU64" pid %u mode %u start "
 	       LPU64" end "LPU64"\n", *flags,
@@ -328,12 +317,8 @@ reprocess:
 
 			/* add lock to blocking list before deadlock
 			 * check to prevent race */
-			rc = ldlm_flock_blocking_link(req, lock);
-			if (rc) {
-				ldlm_flock_destroy(req, mode, *flags);
-				*err = rc;
-				return LDLM_ITER_STOP;
-			}
+			ldlm_flock_blocking_link(req, lock);
+
 			if (ldlm_flock_deadlock(req, lock)) {
 				ldlm_flock_blocking_unlink(req);
 				ldlm_flock_destroy(req, mode, *flags);
@@ -813,6 +798,9 @@ static cfs_hash_ops_t ldlm_export_flock_ops = {
 
 int ldlm_init_flock_export(struct obd_export *exp)
 {
+	if (strcmp(exp->exp_obd->obd_type->typ_name, LUSTRE_MDT_NAME) != 0)
+		return 0;
+
 	exp->exp_flock_hash =
 		cfs_hash_create(obd_uuid2str(&exp->exp_client_uuid),
 				HASH_EXP_LOCK_CUR_BITS,
diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c b/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c
index bbf4291..85f5e7e 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c
@@ -964,6 +964,7 @@ static cfs_hash_ops_t ldlm_export_lock_ops = {
 
 int ldlm_init_export(struct obd_export *exp)
 {
+	int rc;
 	exp->exp_lock_hash =
 		cfs_hash_create(obd_uuid2str(&exp->exp_client_uuid),
 				HASH_EXP_LOCK_CUR_BITS,
@@ -977,7 +978,14 @@ int ldlm_init_export(struct obd_export *exp)
 	if (!exp->exp_lock_hash)
 		return -ENOMEM;
 
+	rc = ldlm_init_flock_export(exp);
+	if (rc)
+		GOTO(err, rc);
+
 	return 0;
+err:
+	ldlm_destroy_export(exp);
+	return rc;
 }
 EXPORT_SYMBOL(ldlm_init_export);
 
-- 
1.7.9.5


  parent reply	other threads:[~2013-11-26  2:09 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-26  2:04 [PATCH 00/16] staging/lustre: sync with external tree, set 2 Peng Tao
2013-11-26  2:04 ` [PATCH 01/16] staging/lustre/server: use unified request handler for MGS Peng Tao
2013-11-26  2:04 ` [PATCH 02/16] staging/lustre/llog: MGC to use OSD API for backup logs Peng Tao
2013-11-26  3:14   ` Greg Kroah-Hartman
2013-11-26  3:25     ` Peng Tao
2013-11-26  3:34       ` Greg Kroah-Hartman
2013-11-26  4:05         ` Peng Tao
2013-11-26  2:04 ` [PATCH 03/16] staging/lustre/nfs: writing to new files will return ENOENT Peng Tao
2013-11-26  6:45   ` Patrick Farrell
2013-11-26 14:09     ` Peng Tao
2013-11-26  2:04 ` Peng Tao [this message]
2013-11-26  2:04 ` [PATCH 05/16] staging/lustre/mdc: prevent fall through in mdc_iocontrol() Peng Tao
2013-11-26  2:05 ` [PATCH 06/16] staging/lustre/lu: shrink lu_object by 8 bytes on x86_64 Peng Tao
2013-11-26  2:05 ` [PATCH 07/16] staging/lustre/mdt: HSM coordinator client interface Peng Tao
2013-11-26  2:05 ` [PATCH 08/16] staging/lustre/mdt: HSM coordinator agent interface Peng Tao
2013-11-26  3:30   ` Greg Kroah-Hartman
2013-11-26  4:09     ` Peng Tao
2013-11-26  2:05 ` [PATCH 09/16] staging/lustre/scrub: OI scrub on OST Peng Tao
2013-11-26  2:05 ` [PATCH 10/16] staging/lustre/scrub: control OI scrub on OST from user space Peng Tao
2013-11-26  2:05 ` [PATCH 11/16] staging/lustre/llite: don't check for O_CREAT in it_create_mode Peng Tao
2013-11-26  2:05 ` [PATCH 12/16] staging/lustre/build: clean up unused variables and dead code Peng Tao
2013-11-26  2:05 ` [PATCH 13/16] staging/lustre/build: fix compilation issue with is_compat_task Peng Tao
2013-11-26  2:05 ` [PATCH 14/16] staging/lustre/ptlrpc: Fix a crash when dereferencing NULL pointer Peng Tao
2013-11-26  2:05 ` [PATCH 15/16] staging/lustre/hsm: Add hsm_release feature Peng Tao
2013-11-26  2:05 ` [PATCH] staging/lustre/llite: extended attribute cache Peng Tao

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=1385431510-18988-5-git-send-email-bergwolf@gmail.com \
    --to=bergwolf@gmail.com \
    --cc=Andriy_Skulysh@xyratex.com \
    --cc=andreas.dilger@intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    /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: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox