Whamcloud - gitweb
LU-3273 mdt: Hold med_open_lock before walking med_open_head 72/7272/4
authorSwapnil Pimpale <spimpale@ddn.com>
Thu, 8 Aug 2013 13:42:25 +0000 (19:12 +0530)
committerOleg Drokin <oleg.drokin@intel.com>
Tue, 17 Sep 2013 10:16:22 +0000 (10:16 +0000)
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 <spimpale@ddn.com>
Change-Id: Ib879f65d41d35f266897e8961dac78e6c4f0d9ec
Reviewed-on: http://review.whamcloud.com/7272
Tested-by: Hudson
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: John L. Hammond <john.hammond@intel.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
lustre/mdt/mdt_open.c

index 03a8d64..801d6a8 100644 (file)
@@ -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
 /*
  * 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,
  */
 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);
                 * 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);
                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);
                        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;
                        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",
                }
 
                CDEBUG(D_HA, "Store old cookie "LPX64" in new mfd\n",