Whamcloud - gitweb
LU-16745 mdc: md_open_data should keep ref on close_req 56/50656/3
authorLi Dongyang <dongyangli@ddn.com>
Mon, 17 Apr 2023 11:13:03 +0000 (21:13 +1000)
committerOleg Drokin <green@whamcloud.com>
Wed, 31 May 2023 19:13:22 +0000 (19:13 +0000)
md_open_data should keep a ref on mod_close_req,
otherwise the mod_close_req could be freed before
we try to access mod_close_req via md_open_data.

Change-Id: I621f7db389854326db298d99957a0bce43024b6e
Signed-off-by: Li Dongyang <dongyangli@ddn.com>
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/50656
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Lai Siyao <lai.siyao@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/include/obd.h
lustre/mdc/mdc_request.c

index 2496e69..64e1ea3 100644 (file)
@@ -1335,6 +1335,8 @@ static inline struct md_open_data *obd_mod_alloc(void)
        if (atomic_dec_and_test(&(mod)->mod_refcount)) {          \
                if ((mod)->mod_open_req)                          \
                        ptlrpc_req_finished((mod)->mod_open_req); \
+               if ((mod)->mod_close_req)                         \
+                       ptlrpc_req_finished((mod)->mod_close_req);\
                OBD_FREE_PTR(mod);                                \
        }                                                         \
 })
index f344818..6d0f23b 100644 (file)
@@ -1027,14 +1027,16 @@ static int mdc_close(struct obd_export *exp, struct md_op_data *op_data,
        }
 
 out:
-        if (mod) {
-                if (rc != 0)
-                        mod->mod_close_req = NULL;
-                /* Since now, mod is accessed through open_req only,
-                 * thus close req does not keep a reference on mod anymore. */
-                obd_mod_put(mod);
-        }
-        *request = req;
+       if (mod) {
+               if (rc != 0)
+                       mod->mod_close_req = NULL;
+               if (mod->mod_close_req)
+                       ptlrpc_request_addref(mod->mod_close_req);
+               /* Since now, mod is accessed through open_req only,
+                * thus close req does not keep a reference on mod anymore. */
+               obd_mod_put(mod);
+       }
+       *request = req;
 
        RETURN(rc < 0 ? rc : saved_rc);
 }