staging: lustre: obdclass: hoist locking in lu_context_exit()
authorJohn L. Hammond <john.hammond@intel.com>
Wed, 2 May 2018 18:21:46 +0000 (14:21 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 7 May 2018 01:47:09 +0000 (18:47 -0700)
Hoist lu_keys_guard locking out of the for loop in lu_context_exit().

Signed-off-by: John L. Hammond <john.hammond@intel.com>
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-8918
Reviewed-on: https://review.whamcloud.com/24217
Reviewed-by: Dmitry Eremin <dmitry.eremin@intel.com>
Reviewed-by: Jinshan Xiong <jinshan.xiong@gmail.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
Signed-off-by: James Simmons <jsimmons@infradead.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/lustre/lustre/obdclass/lu_object.c

index 5f7ba257f5752fc67b1a72e90b415fcf8027d0fb..96f21a5dafc418c55e1d5d957419665394e71a99 100644 (file)
@@ -1721,10 +1721,11 @@ void lu_context_exit(struct lu_context *ctx)
        LINVRNT(ctx->lc_state == LCS_ENTERED);
        ctx->lc_state = LCS_LEFT;
        if (ctx->lc_tags & LCT_HAS_EXIT && ctx->lc_value) {
+               /* could race with key quiescency */
+               if (ctx->lc_tags & LCT_REMEMBER)
+                       read_lock(&lu_keys_guard);
+
                for (i = 0; i < ARRAY_SIZE(lu_keys); ++i) {
-                       /* could race with key quiescency */
-                       if (ctx->lc_tags & LCT_REMEMBER)
-                               read_lock(&lu_keys_guard);
                        if (ctx->lc_value[i]) {
                                struct lu_context_key *key;
 
@@ -1733,9 +1734,10 @@ void lu_context_exit(struct lu_context *ctx)
                                        key->lct_exit(ctx,
                                                      key, ctx->lc_value[i]);
                        }
-                       if (ctx->lc_tags & LCT_REMEMBER)
-                               read_unlock(&lu_keys_guard);
                }
+
+               if (ctx->lc_tags & LCT_REMEMBER)
+                       read_unlock(&lu_keys_guard);
        }
 }
 EXPORT_SYMBOL(lu_context_exit);