Whamcloud - gitweb
LU-1194 llog: fix for not sync llcd at thread stop
[fs/lustre-release.git] / lustre / ptlrpc / recov_thread.c
index 3aac145..8076420 100644 (file)
@@ -1,6 +1,4 @@
-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
- *
+/*
  * GPL HEADER START
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
@@ -28,6 +26,8 @@
 /*
  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
+ *
+ * Copyright (c) 2011, Whamcloud, Inc.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
 
 #define DEBUG_SUBSYSTEM S_LOG
 
-#ifndef EXPORT_SYMTAB
-# define EXPORT_SYMTAB
-#endif
-
 #ifdef __KERNEL__
 # include <libcfs/libcfs.h>
 #else
@@ -76,6 +72,10 @@ enum {
         LLOG_LCM_FL_EXIT        = 1 << 1
 };
 
+struct llcd_async_args {
+        struct llog_canceld_ctxt *la_ctxt;
+};
+
 static void llcd_print(struct llog_canceld_ctxt *llcd,
                        const char *func, int line)
 {
@@ -104,7 +104,7 @@ static struct llog_canceld_ctxt *llcd_alloc(struct llog_commit_master *lcm)
          */
         size = CFS_PAGE_SIZE - lustre_msg_size(LUSTRE_MSG_MAGIC_V2, 1, NULL);
         overhead =  offsetof(struct llog_canceld_ctxt, llcd_cookies);
-        OBD_SLAB_ALLOC(llcd, llcd_cache, CFS_ALLOC_STD, size + overhead);
+       OBD_SLAB_ALLOC_GFP(llcd, llcd_cache, size + overhead, CFS_ALLOC_STD);
         if (!llcd)
                 return NULL;
 
@@ -186,9 +186,11 @@ llcd_copy(struct llog_canceld_ctxt *llcd, struct llog_cookie *cookies)
  */
 static int
 llcd_interpret(const struct lu_env *env,
-               struct ptlrpc_request *req, void *noused, int rc)
+               struct ptlrpc_request *req, void *args, int rc)
 {
-        struct llog_canceld_ctxt *llcd = req->rq_async_args.pointer_arg[0];
+        struct llcd_async_args *la = args;
+        struct llog_canceld_ctxt *llcd = la->la_ctxt;
+
         CDEBUG(D_RPCTRACE, "Sent llcd %p (%d) - killing it\n", llcd, rc);
         llcd_free(llcd);
         return 0;
@@ -204,6 +206,7 @@ static int llcd_send(struct llog_canceld_ctxt *llcd)
         char *bufs[2] = { NULL, (char *)llcd->llcd_cookies };
         struct obd_import *import = NULL;
         struct llog_commit_master *lcm;
+        struct llcd_async_args *la;
         struct ptlrpc_request *req;
         struct llog_ctxt *ctxt;
         int rc;
@@ -216,7 +219,7 @@ static int llcd_send(struct llog_canceld_ctxt *llcd)
                 llcd_print(llcd, __FUNCTION__, __LINE__);
                 LBUG();
         }
-        LASSERT_SEM_LOCKED(&ctxt->loc_sem);
+        LASSERT_MUTEX_LOCKED(&ctxt->loc_mutex);
 
         if (llcd->llcd_cookiebytes == 0)
                 GOTO(exit, rc = 0);
@@ -268,18 +271,18 @@ static int llcd_send(struct llog_canceld_ctxt *llcd)
         /* bug 5515 */
         req->rq_request_portal = LDLM_CANCEL_REQUEST_PORTAL;
         req->rq_reply_portal = LDLM_CANCEL_REPLY_PORTAL;
+
         req->rq_interpret_reply = (ptlrpc_interpterer_t)llcd_interpret;
-        req->rq_async_args.pointer_arg[0] = llcd;
+
+        CLASSERT(sizeof(*la) <= sizeof(req->rq_async_args));
+        la = ptlrpc_req_async_args(req);
+        la->la_ctxt = llcd;
 
         /* llog cancels will be replayed after reconnect so this will do twice
          * first from replay llog, second for resended rpc */
         req->rq_no_delay = req->rq_no_resend = 1;
 
-        rc = ptlrpc_set_add_new_req(&lcm->lcm_pc, req);
-        if (rc) {
-                ptlrpc_request_free(req);
-                GOTO(exit, rc);
-        }
+        ptlrpc_set_add_new_req(&lcm->lcm_pc, req);
         RETURN(0);
 exit:
         CDEBUG(D_RPCTRACE, "Refused llcd %p\n", llcd);
@@ -295,7 +298,7 @@ static int
 llcd_attach(struct llog_ctxt *ctxt, struct llog_canceld_ctxt *llcd)
 {
         LASSERT(ctxt != NULL && llcd != NULL);
-        LASSERT_SEM_LOCKED(&ctxt->loc_sem);
+        LASSERT_MUTEX_LOCKED(&ctxt->loc_mutex);
         LASSERT(ctxt->loc_llcd == NULL);
         llcd->llcd_ctxt = llog_ctxt_get(ctxt);
         ctxt->loc_llcd = llcd;
@@ -315,7 +318,7 @@ static struct llog_canceld_ctxt *llcd_detach(struct llog_ctxt *ctxt)
         struct llog_canceld_ctxt *llcd;
 
         LASSERT(ctxt != NULL);
-        LASSERT_SEM_LOCKED(&ctxt->loc_sem);
+        LASSERT_MUTEX_LOCKED(&ctxt->loc_mutex);
 
         llcd = ctxt->loc_llcd;
         if (!llcd)
@@ -394,7 +397,7 @@ int llog_recov_thread_start(struct llog_commit_master *lcm)
         int rc;
         ENTRY;
 
-        rc = ptlrpcd_start(lcm->lcm_name, &lcm->lcm_pc);
+        rc = ptlrpcd_start(-1, 1, lcm->lcm_name, &lcm->lcm_pc);
         if (rc) {
                 CERROR("Error %d while starting recovery thread %s\n",
                        rc, lcm->lcm_name);
@@ -535,8 +538,7 @@ static int llog_recov_thread_replay(struct llog_ctxt *ctxt,
                 OBD_FREE_PTR(lpca);
                 RETURN(-ENODEV);
         }
-        rc = cfs_kernel_thread(llog_cat_process_thread, lpca,
-                               CLONE_VM | CLONE_FILES);
+        rc = cfs_create_thread(llog_cat_process_thread, lpca, CFS_DAEMON_FLAGS);
         if (rc < 0) {
                 CERROR("Error starting llog_cat_process_thread(): %d\n", rc);
                 OBD_FREE_PTR(lpca);
@@ -560,15 +562,15 @@ int llog_obd_repl_connect(struct llog_ctxt *ctxt,
          * Send back cached llcd from llog before recovery if we have any.
          * This is void is nothing cached is found there.
          */
-        llog_sync(ctxt, NULL);
+       llog_sync(ctxt, NULL, 0);
 
         /*
          * Start recovery in separate thread.
          */
-        cfs_mutex_down(&ctxt->loc_sem);
+        cfs_mutex_lock(&ctxt->loc_mutex);
         ctxt->loc_gen = *gen;
         rc = llog_recov_thread_replay(ctxt, ctxt->llog_proc_cb, logid);
-        cfs_mutex_up(&ctxt->loc_sem);
+        cfs_mutex_unlock(&ctxt->loc_mutex);
 
         RETURN(rc);
 }
@@ -590,7 +592,7 @@ int llog_obd_repl_cancel(struct llog_ctxt *ctxt,
 
         LASSERT(ctxt != NULL);
 
-        cfs_mutex_down(&ctxt->loc_sem);
+        cfs_mutex_lock(&ctxt->loc_mutex);
         if (!ctxt->loc_lcm) {
                 CDEBUG(D_RPCTRACE, "No lcm for ctxt %p\n", ctxt);
                 GOTO(out, rc = -ENODEV);
@@ -602,7 +604,12 @@ int llog_obd_repl_cancel(struct llog_ctxt *ctxt,
          * Let's check if we have all structures alive. We also check for
          * possible shutdown. Do nothing if we're stopping.
          */
-        if (ctxt->loc_imp == NULL) {
+       if (ctxt->loc_flags & LLOG_CTXT_FLAG_STOP) {
+               CDEBUG(D_RPCTRACE, "Last sync was done for ctxt %p\n", ctxt);
+               GOTO(out, rc = -ENODEV);
+       }
+
+       if (ctxt->loc_imp == NULL) {
                 CDEBUG(D_RPCTRACE, "No import for ctxt %p\n", ctxt);
                 GOTO(out, rc = -ENODEV);
         }
@@ -671,12 +678,17 @@ int llog_obd_repl_cancel(struct llog_ctxt *ctxt,
 out:
         if (rc)
                 llcd_put(ctxt);
-        cfs_mutex_up(&ctxt->loc_sem);
+
+       if (flags & OBD_LLOG_FL_EXIT)
+               ctxt->loc_flags = LLOG_CTXT_FLAG_STOP;
+
+        cfs_mutex_unlock(&ctxt->loc_mutex);
         return rc;
 }
 EXPORT_SYMBOL(llog_obd_repl_cancel);
 
-int llog_obd_repl_sync(struct llog_ctxt *ctxt, struct obd_export *exp)
+int llog_obd_repl_sync(struct llog_ctxt *ctxt, struct obd_export *exp,
+                      int flags)
 {
         int rc = 0;
         ENTRY;
@@ -684,7 +696,7 @@ int llog_obd_repl_sync(struct llog_ctxt *ctxt, struct obd_export *exp)
         /*
          * Flush any remaining llcd.
          */
-        cfs_mutex_down(&ctxt->loc_sem);
+        cfs_mutex_lock(&ctxt->loc_mutex);
         if (exp && (ctxt->loc_imp == exp->exp_imp_reverse)) {
                 /*
                  * This is ost->mds connection, we can't be sure that mds
@@ -692,7 +704,11 @@ int llog_obd_repl_sync(struct llog_ctxt *ctxt, struct obd_export *exp)
                  */
                 CDEBUG(D_RPCTRACE, "Kill cached llcd\n");
                 llcd_put(ctxt);
-                cfs_mutex_up(&ctxt->loc_sem);
+
+               if (flags & OBD_LLOG_FL_EXIT)
+                       ctxt->loc_flags = LLOG_CTXT_FLAG_STOP;
+
+                cfs_mutex_unlock(&ctxt->loc_mutex);
         } else {
                 /*
                  * This is either llog_sync() from generic llog code or sync
@@ -700,8 +716,9 @@ int llog_obd_repl_sync(struct llog_ctxt *ctxt, struct obd_export *exp)
                  * llcds to the target with waiting for completion.
                  */
                 CDEBUG(D_RPCTRACE, "Sync cached llcd\n");
-                cfs_mutex_up(&ctxt->loc_sem);
-                rc = llog_cancel(ctxt, NULL, 0, NULL, OBD_LLOG_FL_SENDNOW);
+                cfs_mutex_unlock(&ctxt->loc_mutex);
+               rc = llog_cancel(ctxt, NULL, 0, NULL, OBD_LLOG_FL_SENDNOW |
+                                flags);
         }
         RETURN(rc);
 }