From 140ab2ed07039754464a35fd7abb41988ee9417a Mon Sep 17 00:00:00 2001 From: Swapnil Pimpale Date: Thu, 8 Aug 2013 19:12:25 +0530 Subject: [PATCH] LU-3273 mdt: Hold med_open_lock before walking med_open_head Fixed a bug where during replay mdt_mfd_open() calls mdt_handle2mfd() without acquiring the med_open_lock. We now take the med_open_lock before traversing med_open_head list. This bug was noticed during the analysis of LU-3233. Signed-off-by: Swapnil Pimpale Change-Id: Ib879f65d41d35f266897e8961dac78e6c4f0d9ec Reviewed-on: http://review.whamcloud.com/7272 Tested-by: Hudson Tested-by: Maloo Reviewed-by: John L. Hammond Reviewed-by: Andreas Dilger --- lustre/mdt/mdt_open.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lustre/mdt/mdt_open.c b/lustre/mdt/mdt_open.c index 03a8d64..801d6a8 100644 --- a/lustre/mdt/mdt_open.c +++ b/lustre/mdt/mdt_open.c @@ -77,7 +77,8 @@ struct mdt_file_data *mdt_mfd_new(const struct mdt_export_data *med) /* * Find the mfd pointed to by handle in global hash table. * In case of replay the handle is obsoleted - * but mfd can be found in mfd list by that handle + * but mfd can be found in mfd list by that handle. + * Callers need to be holding med_open_lock. */ struct mdt_file_data *mdt_handle2mfd(struct mdt_export_data *med, const struct lustre_handle *handle, @@ -762,13 +763,13 @@ static int mdt_mfd_open(struct mdt_thread_info *info, struct mdt_object *p, * restart replay, so there maybe some orphan * mfd here, we should remove them */ LASSERT(info->mti_rr.rr_handle != NULL); + spin_lock(&med->med_open_lock); old_mfd = mdt_handle2mfd(med, info->mti_rr.rr_handle, true); if (old_mfd != NULL) { CDEBUG(D_HA, "delete orphan mfd = %p, fid = "DFID", " "cookie = "LPX64"\n", mfd, PFID(mdt_object_fid(mfd->mfd_object)), info->mti_rr.rr_handle->cookie); - spin_lock(&med->med_open_lock); class_handle_unhash(&old_mfd->mfd_handle); cfs_list_del_init(&old_mfd->mfd_list); spin_unlock(&med->med_open_lock); @@ -779,6 +780,12 @@ static int mdt_mfd_open(struct mdt_thread_info *info, struct mdt_object *p, mdt_mfd_close(info, old_mfd); ma->ma_attr_flags &= ~MDS_RECOV_OPEN; ma->ma_valid &= ~MA_FLAGS; + } else { + spin_unlock(&med->med_open_lock); + CDEBUG(D_HA, "orphan mfd not found, fid = "DFID", " + "cookie = "LPX64"\n", + PFID(mdt_object_fid(mfd->mfd_object)), + info->mti_rr.rr_handle->cookie); } CDEBUG(D_HA, "Store old cookie "LPX64" in new mfd\n", -- 1.8.3.1