Whamcloud - gitweb
LU-12853 ptlrpc: zero session enviroment 05/37305/2
authorAlexander Boyko <c17825@cray.com>
Mon, 14 Oct 2019 07:31:35 +0000 (03:31 -0400)
committerOleg Drokin <green@whamcloud.com>
Mon, 27 Jan 2020 23:12:41 +0000 (23:12 +0000)
handle_recovery_req() set le_ses for request processing,
and doesn't zero it after. This leads to accessing freed memory
at keys_fill() later.

The patch also adds a cleanup for xxx_env_info, makes them equal
and combines to a single function.

Lustre-change: https://review.whamcloud.com/36443
Lustre-commit: 2a620f07e23b3b044f429f049bcc5ffa96f6d844

Cray-bug-id: LUS-7676
Signed-off-by: Alexander Boyko <c17825@cray.com>
Change-Id: Ifad95c1177258b6f71effe5fa815f68c8426c516
Reviewed-by: Alexander Zarochentsev <c17826@cray.com>
Reviewed-by: Alexey Lyashkov <c17817@cray.com>
Reviewed-by: Andriy Skulysh <c17819@cray.com>
Reviewed-by: Alex Zhuravlev <bzzz@whamcloud.com>
Reviewed-by: Andrew Perepechko <c17827@cray.com>
Reviewed-by: Mike Pershin <mpershin@whamcloud.com>
Reviewed-by: Sergey Cheremencev <c17829@cray.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Reviewed-on: https://review.whamcloud.com/37305
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lustre/include/lu_object.h
lustre/ldlm/ldlm_lib.c
lustre/mdd/mdd_object.c
lustre/mdt/mdt_internal.h
lustre/mgs/mgs_internal.h
lustre/ofd/ofd_internal.h
lustre/osp/osp_internal.h
lustre/quota/lquota_internal.h
lustre/quota/qmt_internal.h
lustre/quota/qsd_internal.h

index 2be6292..c75d311 100644 (file)
@@ -1262,6 +1262,19 @@ void lu_env_fini  (struct lu_env *env);
 int  lu_env_refill(struct lu_env *env);
 int  lu_env_refill_by_tags(struct lu_env *env, __u32 ctags, __u32 stags);
 
+static inline void* lu_env_info(const struct lu_env *env,
+                               const struct lu_context_key *key)
+{
+       void *info;
+       info = lu_context_key_get(&env->le_ctx, key);
+       if (!info) {
+               if (!lu_env_refill((struct lu_env *)env))
+                       info = lu_context_key_get(&env->le_ctx, key);
+       }
+       LASSERT(info);
+       return info;
+}
+
 #ifdef HAVE_SERVER_SUPPORT
 struct lu_env *lu_env_find(void);
 int lu_env_add(struct lu_env *env);
index 97d6a95..43ea9de 100644 (file)
@@ -2180,6 +2180,8 @@ static void handle_recovery_req(struct ptlrpc_thread *thread,
         (void)handler(req);
         lu_context_exit(&thread->t_env->le_ctx);
 
+       req->rq_svc_thread->t_env->le_ses = NULL;
+
        /* don't reset timer for final stage */
        if (!exp_finished(req->rq_export)) {
                time_t to = obd_timeout;
index 2e7afc6..fd26e5f 100644 (file)
@@ -243,12 +243,7 @@ int mdd_la_get(const struct lu_env *env, struct mdd_object *obj,
 
 struct mdd_thread_info *mdd_env_info(const struct lu_env *env)
 {
-        struct mdd_thread_info *info;
-
-       lu_env_refill((struct lu_env *)env);
-        info = lu_context_key_get(&env->le_ctx, &mdd_thread_key);
-        LASSERT(info != NULL);
-        return info;
+       return lu_env_info(env, &mdd_thread_key);
 }
 
 struct lu_buf *mdd_buf_get(const struct lu_env *env, void *area, ssize_t len)
index 862f136..45c7e8a 100644 (file)
@@ -519,12 +519,7 @@ extern struct lu_context_key mdt_thread_key;
 
 static inline struct mdt_thread_info *mdt_th_info(const struct lu_env *env)
 {
-       struct mdt_thread_info *mti;
-
-       lu_env_refill((void *)env);
-       mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
-       LASSERT(mti);
-       return mti;
+       return lu_env_info(env, &mdt_thread_key);
 }
 
 struct cdt_req_progress {
index d4de273..ebb80a4 100644 (file)
@@ -316,18 +316,7 @@ extern struct lu_context_key mgs_thread_key;
 
 static inline struct mgs_thread_info *mgs_env_info(const struct lu_env *env)
 {
-       struct mgs_thread_info  *info;
-       int                     rc;
-
-       info = lu_context_key_get(&env->le_ctx, &mgs_thread_key);
-       if (info == NULL) {
-               rc = lu_env_refill((struct lu_env *)env);
-               if (rc != 0)
-                       return ERR_PTR(rc);
-               info = lu_context_key_get(&env->le_ctx, &mgs_thread_key);
-       }
-       LASSERT(info != NULL);
-       return info;
+       return lu_env_info(env, &mgs_thread_key);
 }
 
 extern const struct lu_device_operations mgs_lu_ops;
index e4733ac..224eece 100644 (file)
@@ -402,12 +402,7 @@ int ofd_intent_policy(const struct lu_env *env, struct ldlm_namespace *ns,
 
 static inline struct ofd_thread_info *ofd_info(const struct lu_env *env)
 {
-       struct ofd_thread_info *info;
-
-       lu_env_refill((void *)env);
-       info = lu_context_key_get(&env->le_ctx, &ofd_thread_key);
-       LASSERT(info);
-       return info;
+       return lu_env_info(env, &ofd_thread_key);
 }
 
 static inline struct ofd_thread_info *ofd_info_init(const struct lu_env *env,
index 64ef6e3..2c10cb9 100644 (file)
@@ -432,15 +432,7 @@ extern struct lu_context_key osp_thread_key;
 
 static inline struct osp_thread_info *osp_env_info(const struct lu_env *env)
 {
-       struct osp_thread_info *info;
-
-       info = lu_context_key_get(&env->le_ctx, &osp_thread_key);
-       if (info == NULL) {
-               lu_env_refill((struct lu_env *)env);
-               info = lu_context_key_get(&env->le_ctx, &osp_thread_key);
-       }
-       LASSERT(info);
-       return info;
+       return lu_env_info(env, &osp_thread_key);
 }
 
 struct osp_txn_info {
index 705490b..dc0ddd8 100644 (file)
@@ -334,15 +334,7 @@ extern struct lu_context_key lquota_thread_key;
 static inline
 struct lquota_thread_info *lquota_info(const struct lu_env *env)
 {
-       struct lquota_thread_info       *info;
-
-       info = lu_context_key_get(&env->le_ctx, &lquota_thread_key);
-       if (info == NULL) {
-               lu_env_refill((struct lu_env *)env);
-               info = lu_context_key_get(&env->le_ctx, &lquota_thread_key);
-       }
-       LASSERT(info);
-       return info;
+       return lu_env_info(env, &lquota_thread_key);
 }
 
 #define req_is_acq(flags)    ((flags & QUOTA_DQACQ_FL_ACQ) != 0)
index 1ac3367..4590046 100644 (file)
@@ -205,15 +205,7 @@ extern struct lu_context_key qmt_thread_key;
 static inline
 struct qmt_thread_info *qmt_info(const struct lu_env *env)
 {
-       struct qmt_thread_info  *info;
-
-       info = lu_context_key_get(&env->le_ctx, &qmt_thread_key);
-       if (info == NULL) {
-               lu_env_refill((struct lu_env *)env);
-               info = lu_context_key_get(&env->le_ctx, &qmt_thread_key);
-       }
-       LASSERT(info);
-       return info;
+       return lu_env_info(env, &qmt_thread_key);
 }
 
 /* helper routine to convert a lu_device into a qmt_device */
index a4f6734..5508e62 100644 (file)
@@ -265,15 +265,7 @@ extern struct lu_context_key qsd_thread_key;
 static inline
 struct qsd_thread_info *qsd_info(const struct lu_env *env)
 {
-       struct qsd_thread_info *info;
-
-       info = lu_context_key_get(&env->le_ctx, &qsd_thread_key);
-       if (info == NULL) {
-               lu_env_refill((struct lu_env *)env);
-               info = lu_context_key_get(&env->le_ctx, &qsd_thread_key);
-       }
-       LASSERT(info);
-       return info;
+       return lu_env_info(env, &qsd_thread_key);
 }
 
 /* helper function to check whether a given quota type is enabled */