Whamcloud - gitweb
timeout and assert in invalidate import.
[fs/lustre-release.git] / lustre / ptlrpc / recov_thread.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2003 Cluster File Systems, Inc.
5  *   Author: Andreas Dilger <adilger@clusterfs.com>
6  *
7  *   This file is part of the Lustre file system, http://www.lustre.org
8  *   Lustre is a trademark of Cluster File Systems, Inc.
9  *
10  *   You may have signed or agreed to another license before downloading
11  *   this software.  If so, you are bound by the terms and conditions
12  *   of that agreement, and the following does not apply to you.  See the
13  *   LICENSE file included with this distribution for more information.
14  *
15  *   If you did not agree to a different license, then this copy of Lustre
16  *   is open source software; you can redistribute it and/or modify it
17  *   under the terms of version 2 of the GNU General Public License as
18  *   published by the Free Software Foundation.
19  *
20  *   In either case, Lustre is distributed in the hope that it will be
21  *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
22  *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  *   license text for more details.
24  *
25  * OST<->MDS recovery logging thread.
26  *
27  * Invariants in implementation:
28  * - we do not share logs among different OST<->MDS connections, so that
29  *   if an OST or MDS fails it need only look at log(s) relevant to itself
30  */
31
32 #define DEBUG_SUBSYSTEM S_LOG
33
34 #ifndef EXPORT_SYMTAB
35 # define EXPORT_SYMTAB
36 #endif
37
38 #ifdef __KERNEL__
39 # include <libcfs/libcfs.h>
40 #else
41 # include <libcfs/list.h>
42 # include <liblustre.h>
43 #endif
44
45 #include <libcfs/kp30.h>
46 #include <obd_class.h>
47 #include <lustre_commit_confd.h>
48 #include <obd_support.h>
49 #include <obd_class.h>
50 #include <lustre_net.h>
51 #include <lnet/types.h>
52 #include <libcfs/list.h>
53 #include <lustre_log.h>
54 #include "ptlrpc_internal.h"
55
56 #ifdef __KERNEL__
57
58 /* Allocate new commit structs in case we do not have enough.
59  * Make the llcd size small enough that it fits into a single page when we
60  * are sending/receiving it. */
61 static int llcd_alloc(struct llog_commit_master *lcm)
62 {
63         struct llog_canceld_ctxt *llcd;
64         int llcd_size;
65
66         /* payload of lustre_msg V2 is bigger */
67         llcd_size = 4096 - lustre_msg_size(LUSTRE_MSG_MAGIC_V2, 1, NULL);
68         OBD_ALLOC(llcd,
69                   llcd_size + offsetof(struct llog_canceld_ctxt, llcd_cookies));
70         if (llcd == NULL)
71                 return -ENOMEM;
72
73         llcd->llcd_size = llcd_size;
74         llcd->llcd_lcm = lcm;
75
76         spin_lock(&lcm->lcm_llcd_lock);
77         list_add(&llcd->llcd_list, &lcm->lcm_llcd_free);
78         atomic_inc(&lcm->lcm_llcd_numfree);
79         spin_unlock(&lcm->lcm_llcd_lock);
80
81         return 0;
82 }
83
84 /* Get a free cookie struct from the list */
85 static struct llog_canceld_ctxt *llcd_grab(struct llog_commit_master *lcm)
86 {
87         struct llog_canceld_ctxt *llcd;
88
89 repeat:
90         spin_lock(&lcm->lcm_llcd_lock);
91         if (list_empty(&lcm->lcm_llcd_free)) {
92                 spin_unlock(&lcm->lcm_llcd_lock);
93                 if (llcd_alloc(lcm) < 0) {
94                         CERROR("unable to allocate log commit data!\n");
95                         return NULL;
96                 }
97                 /* check new llcd wasn't grabbed while lock dropped, b=7407 */
98                 goto repeat;
99         }
100
101         llcd = list_entry(lcm->lcm_llcd_free.next, typeof(*llcd), llcd_list);
102         list_del(&llcd->llcd_list);
103         atomic_dec(&lcm->lcm_llcd_numfree);
104         spin_unlock(&lcm->lcm_llcd_lock);
105
106         llcd->llcd_cookiebytes = 0;
107
108         return llcd;
109 }
110
111 static void llcd_put(struct llog_canceld_ctxt *llcd)
112 {
113         struct llog_commit_master *lcm = llcd->llcd_lcm;
114
115         llog_ctxt_put(llcd->llcd_ctxt);
116         if (atomic_read(&lcm->lcm_llcd_numfree) >= lcm->lcm_llcd_maxfree) {
117                 int llcd_size = llcd->llcd_size +
118                          offsetof(struct llog_canceld_ctxt, llcd_cookies);
119                 OBD_FREE(llcd, llcd_size);
120         } else {
121                 spin_lock(&lcm->lcm_llcd_lock);
122                 list_add(&llcd->llcd_list, &lcm->lcm_llcd_free);
123                 atomic_inc(&lcm->lcm_llcd_numfree);
124                 spin_unlock(&lcm->lcm_llcd_lock);
125         }
126 }
127
128 /* Send some cookies to the appropriate target */
129 static void llcd_send(struct llog_canceld_ctxt *llcd)
130 {
131         if (!(llcd->llcd_lcm->lcm_flags & LLOG_LCM_FL_EXIT)) {
132         spin_lock(&llcd->llcd_lcm->lcm_llcd_lock);
133                 list_add_tail(&llcd->llcd_list,
134                               &llcd->llcd_lcm->lcm_llcd_pending);
135         spin_unlock(&llcd->llcd_lcm->lcm_llcd_lock);
136         }
137         cfs_waitq_signal_nr(&llcd->llcd_lcm->lcm_waitq, 1);
138 }
139
140 /* deleted objects have a commit callback that cancels the MDS
141  * log record for the deletion.  The commit callback calls this
142  * function
143  */
144 int llog_obd_repl_cancel(struct llog_ctxt *ctxt,
145                          struct lov_stripe_md *lsm, int count,
146                          struct llog_cookie *cookies, int flags)
147 {
148         struct llog_canceld_ctxt *llcd;
149         int rc = 0;
150         ENTRY;
151
152         LASSERT(ctxt);
153
154         mutex_down(&ctxt->loc_sem);
155         if (ctxt->loc_imp == NULL) {
156                 CDEBUG(D_RPCTRACE, "no import for ctxt %p\n", ctxt);
157                 GOTO(out, rc = 0);
158         }
159
160         llcd = ctxt->loc_llcd;
161
162         if (count > 0 && cookies != NULL) {
163                 if (llcd == NULL) {
164                         llcd = llcd_grab(ctxt->loc_lcm);
165                         if (llcd == NULL) {
166                                 CERROR("couldn't get an llcd - dropped "LPX64
167                                        ":%x+%u\n",
168                                        cookies->lgc_lgl.lgl_oid,
169                                        cookies->lgc_lgl.lgl_ogen, 
170                                        cookies->lgc_index);
171                                 GOTO(out, rc = -ENOMEM);
172                         }
173                         llcd->llcd_ctxt = llog_ctxt_get(ctxt);
174                         ctxt->loc_llcd = llcd;
175                 }
176
177                 memcpy((char *)llcd->llcd_cookies + llcd->llcd_cookiebytes, 
178                        cookies, sizeof(*cookies));
179                 llcd->llcd_cookiebytes += sizeof(*cookies);
180         } else {
181                 if (llcd == NULL || !(flags & OBD_LLOG_FL_SENDNOW))
182                         GOTO(out, rc);
183         }
184
185         if ((llcd->llcd_size - llcd->llcd_cookiebytes) < sizeof(*cookies) ||
186             (flags & OBD_LLOG_FL_SENDNOW)) {
187                 CDEBUG(D_RPCTRACE, "send llcd %p:%p\n", llcd, llcd->llcd_ctxt);
188                 ctxt->loc_llcd = NULL;
189                 llcd_send(llcd);
190         }
191 out:
192         mutex_up(&ctxt->loc_sem);
193         return rc;
194 }
195 EXPORT_SYMBOL(llog_obd_repl_cancel);
196
197 int llog_obd_repl_sync(struct llog_ctxt *ctxt, struct obd_export *exp)
198 {
199         int rc = 0;
200         ENTRY;
201
202         if (exp && (ctxt->loc_imp == exp->exp_imp_reverse)) {
203                 CDEBUG(D_RPCTRACE,"reverse import disconnect, put llcd %p:%p\n",
204                        ctxt->loc_llcd, ctxt);
205                 mutex_down(&ctxt->loc_sem);
206                 if (ctxt->loc_llcd != NULL) {
207                         llcd_put(ctxt->loc_llcd);
208                         ctxt->loc_llcd = NULL;
209                 }
210                 ctxt->loc_imp = NULL;
211                 mutex_up(&ctxt->loc_sem);
212         } else {
213                 rc = llog_cancel(ctxt, NULL, 0, NULL, OBD_LLOG_FL_SENDNOW);
214         }
215
216         RETURN(rc);
217 }
218 EXPORT_SYMBOL(llog_obd_repl_sync);
219
220 static inline void stop_log_commit(struct llog_commit_master *lcm,
221                                    struct llog_commit_daemon *lcd,
222                                    int rc)
223 {
224         CERROR("error preparing commit: rc %d\n", rc);
225
226         spin_lock(&lcm->lcm_llcd_lock);
227         list_splice_init(&lcd->lcd_llcd_list, &lcm->lcm_llcd_resend);
228         spin_unlock(&lcm->lcm_llcd_lock);
229 }
230
231 static int log_commit_thread(void *arg)
232 {
233         struct llog_commit_master *lcm = arg;
234         struct llog_commit_daemon *lcd;
235         struct llog_canceld_ctxt *llcd, *n;
236         struct obd_import *import = NULL;
237         ENTRY;
238
239         OBD_ALLOC(lcd, sizeof(*lcd));
240         if (lcd == NULL)
241                 RETURN(-ENOMEM);
242
243         spin_lock(&lcm->lcm_thread_lock);
244         THREAD_NAME(cfs_curproc_comm(), CFS_CURPROC_COMM_MAX - 1,
245                     "ll_log_comt_%02d", atomic_read(&lcm->lcm_thread_total));
246         atomic_inc(&lcm->lcm_thread_total);
247         spin_unlock(&lcm->lcm_thread_lock);
248
249         ptlrpc_daemonize(cfs_curproc_comm()); /* thread never needs to do IO */
250
251         CFS_INIT_LIST_HEAD(&lcd->lcd_lcm_list);
252         CFS_INIT_LIST_HEAD(&lcd->lcd_llcd_list);
253         lcd->lcd_lcm = lcm;
254
255         CDEBUG(D_HA, "%s started\n", cfs_curproc_comm());
256         do {
257                 struct ptlrpc_request *request;
258                 struct list_head *sending_list;
259                 int rc = 0;
260
261                 if (import)
262                         class_import_put(import);
263                 import = NULL;
264
265                 /* If we do not have enough pages available, allocate some */
266                 while (atomic_read(&lcm->lcm_llcd_numfree) <
267                        lcm->lcm_llcd_minfree) {
268                         if (llcd_alloc(lcm) < 0)
269                                 break;
270                 }
271
272                 spin_lock(&lcm->lcm_thread_lock);
273                 atomic_inc(&lcm->lcm_thread_numidle);
274                 list_move(&lcd->lcd_lcm_list, &lcm->lcm_thread_idle);
275                 spin_unlock(&lcm->lcm_thread_lock);
276
277                 wait_event_interruptible(lcm->lcm_waitq,
278                                          !list_empty(&lcm->lcm_llcd_pending) ||
279                                          lcm->lcm_flags & LLOG_LCM_FL_EXIT);
280
281                 /* If we are the last available thread, start a new one in case
282                  * we get blocked on an RPC (nobody else will start a new one)*/
283                 spin_lock(&lcm->lcm_thread_lock);
284                 atomic_dec(&lcm->lcm_thread_numidle);
285                 list_move(&lcd->lcd_lcm_list, &lcm->lcm_thread_busy);
286                 spin_unlock(&lcm->lcm_thread_lock);
287
288                 sending_list = &lcm->lcm_llcd_pending;
289         resend:
290                 if (import)
291                         class_import_put(import);
292                 import = NULL;
293                 if (lcm->lcm_flags & LLOG_LCM_FL_EXIT) {
294                         lcm->lcm_llcd_maxfree = 0;
295                         lcm->lcm_llcd_minfree = 0;
296                         lcm->lcm_thread_max = 0;
297
298                         if (list_empty(&lcm->lcm_llcd_pending) ||
299                             lcm->lcm_flags & LLOG_LCM_FL_EXIT_FORCE)
300                                 break;
301                 }
302
303                 if (atomic_read(&lcm->lcm_thread_numidle) <= 1 &&
304                     atomic_read(&lcm->lcm_thread_total) < lcm->lcm_thread_max) {
305                         rc = llog_start_commit_thread(lcm);
306                         if (rc < 0)
307                                 CERROR("error starting thread: rc %d\n", rc);
308                 }
309
310                 /* Move all of the pending cancels from the same OST off of
311                  * the list, so we don't get multiple threads blocked and/or
312                  * doing upcalls on the same OST in case of failure. */
313                 spin_lock(&lcm->lcm_llcd_lock);
314                 if (!list_empty(sending_list)) {
315                         list_move_tail(sending_list->next,
316                                        &lcd->lcd_llcd_list);
317                         llcd = list_entry(lcd->lcd_llcd_list.next,
318                                           typeof(*llcd), llcd_list);
319                         LASSERT(llcd->llcd_lcm == lcm);
320                         import = llcd->llcd_ctxt->loc_imp;
321                         if (import)
322                                 class_import_get(import);
323                 }
324                 list_for_each_entry_safe(llcd, n, sending_list, llcd_list) {
325                         LASSERT(llcd->llcd_lcm == lcm);
326                         if (import == llcd->llcd_ctxt->loc_imp)
327                                 list_move_tail(&llcd->llcd_list,
328                                                &lcd->lcd_llcd_list);
329                 }
330                 if (sending_list != &lcm->lcm_llcd_resend) {
331                         list_for_each_entry_safe(llcd, n, &lcm->lcm_llcd_resend,
332                                                  llcd_list) {
333                                 LASSERT(llcd->llcd_lcm == lcm);
334                                 if (import == llcd->llcd_ctxt->loc_imp)
335                                         list_move_tail(&llcd->llcd_list,
336                                                        &lcd->lcd_llcd_list);
337                         }
338                 }
339                 spin_unlock(&lcm->lcm_llcd_lock);
340
341                 /* We are the only one manipulating our local list - no lock */
342                 list_for_each_entry_safe(llcd,n, &lcd->lcd_llcd_list,llcd_list){
343                         char *bufs[2] = { NULL, (char *)llcd->llcd_cookies };
344
345                         list_del(&llcd->llcd_list);
346                         if (llcd->llcd_cookiebytes == 0) {
347                                 CDEBUG(D_RPCTRACE, "put empty llcd %p:%p\n",
348                                        llcd, llcd->llcd_ctxt);
349                                 llcd_put(llcd);
350                                 continue;
351                         }
352
353                         mutex_down(&llcd->llcd_ctxt->loc_sem);
354                         if (llcd->llcd_ctxt->loc_imp == NULL) {
355                                 mutex_up(&llcd->llcd_ctxt->loc_sem);
356                                 CWARN("import will be destroyed, put "
357                                       "llcd %p:%p\n", llcd, llcd->llcd_ctxt);
358                                 llcd_put(llcd);
359                                 continue;
360                         }
361                         mutex_up(&llcd->llcd_ctxt->loc_sem);
362
363                         if (!import || (import == LP_POISON) ||
364                             (import->imp_client == LP_POISON)) {
365                                 CERROR("No import %p (llcd=%p, ctxt=%p)\n",
366                                        import, llcd, llcd->llcd_ctxt);
367                                 llcd_put(llcd);
368                                 continue;
369                         }
370
371                         OBD_FAIL_TIMEOUT(OBD_FAIL_PTLRPC_DELAY_RECOV, 10);
372
373                         request = ptlrpc_request_alloc(import, &RQF_LOG_CANCEL);
374                         if (request == NULL) {
375                                 rc = -ENOMEM;
376                                 stop_log_commit(lcm, lcd, rc);
377                                 break;
378                         }
379
380                         req_capsule_set_size(&request->rq_pill, &RMF_LOGCOOKIES,
381                                              RCL_CLIENT,llcd->llcd_cookiebytes);
382
383                         rc = ptlrpc_request_bufs_pack(request,
384                                                       LUSTRE_LOG_VERSION,
385                                                       OBD_LOG_CANCEL, bufs,
386                                                       NULL);
387                         if (rc) {
388                                 ptlrpc_request_free(request);
389                                 stop_log_commit(lcm, lcd, rc);
390                                 break;
391                         }
392
393                         /* XXX FIXME bug 249, 5515 */
394                         request->rq_request_portal = LDLM_CANCEL_REQUEST_PORTAL;
395                         request->rq_reply_portal = LDLM_CANCEL_REPLY_PORTAL;
396
397                         ptlrpc_request_set_replen(request);
398                         mutex_down(&llcd->llcd_ctxt->loc_sem);
399                         if (llcd->llcd_ctxt->loc_imp == NULL) {
400                                 mutex_up(&llcd->llcd_ctxt->loc_sem);
401                                 CWARN("import will be destroyed, put "
402                                       "llcd %p:%p\n", llcd, llcd->llcd_ctxt);
403                                 llcd_put(llcd);
404                                 ptlrpc_req_finished(request);
405                                 continue;
406                         }
407                         mutex_up(&llcd->llcd_ctxt->loc_sem);
408                         rc = ptlrpc_queue_wait(request);
409                         ptlrpc_req_finished(request);
410
411                         /* If the RPC failed, we put this and the remaining
412                          * messages onto the resend list for another time. */
413                         if (rc == 0) {
414                                 llcd_put(llcd);
415                                 continue;
416                         }
417
418                         CERROR("commit %p:%p drop %d cookies: rc %d\n",
419                                llcd, llcd->llcd_ctxt,
420                                (int)(llcd->llcd_cookiebytes /
421                                      sizeof(*llcd->llcd_cookies)), rc);
422                         llcd_put(llcd);
423                 }
424
425                 if (rc == 0) {
426                         sending_list = &lcm->lcm_llcd_resend;
427                         if (!list_empty(sending_list))
428                                 goto resend;
429                 }
430         } while(1);
431
432         if (import)
433                 class_import_put(import);
434
435         /* If we are force exiting, just drop all of the cookies. */
436         if (lcm->lcm_flags & LLOG_LCM_FL_EXIT_FORCE) {
437                 spin_lock(&lcm->lcm_llcd_lock);
438                 list_splice_init(&lcm->lcm_llcd_pending, &lcd->lcd_llcd_list);
439                 list_splice_init(&lcm->lcm_llcd_resend, &lcd->lcd_llcd_list);
440                 list_splice_init(&lcm->lcm_llcd_free, &lcd->lcd_llcd_list);
441                 spin_unlock(&lcm->lcm_llcd_lock);
442
443                 list_for_each_entry_safe(llcd, n, &lcd->lcd_llcd_list,llcd_list)
444                         llcd_put(llcd);
445         }
446
447         spin_lock(&lcm->lcm_thread_lock);
448         list_del(&lcd->lcd_lcm_list);
449         spin_unlock(&lcm->lcm_thread_lock);
450         OBD_FREE(lcd, sizeof(*lcd));
451
452         CDEBUG(D_HA, "%s exiting\n", cfs_curproc_comm());
453
454         spin_lock(&lcm->lcm_thread_lock);
455         atomic_dec(&lcm->lcm_thread_total);
456         spin_unlock(&lcm->lcm_thread_lock);
457         cfs_waitq_signal(&lcm->lcm_waitq);
458
459         return 0;
460 }
461
462 int llog_start_commit_thread(struct llog_commit_master *lcm)
463 {
464         int rc;
465         ENTRY;
466
467         if (atomic_read(&lcm->lcm_thread_total) >= lcm->lcm_thread_max)
468                 RETURN(0);
469
470         rc = cfs_kernel_thread(log_commit_thread, lcm, CLONE_VM | CLONE_FILES);
471         if (rc < 0) {
472                 CERROR("error starting thread #%d: %d\n",
473                        atomic_read(&lcm->lcm_thread_total), rc);
474                 RETURN(rc);
475         }
476
477         RETURN(0);
478 }
479 EXPORT_SYMBOL(llog_start_commit_thread);
480
481 static struct llog_process_args {
482         struct semaphore         llpa_sem;
483         struct llog_ctxt        *llpa_ctxt;
484         void                    *llpa_cb;
485         void                    *llpa_arg;
486 } llpa;
487
488 int llog_init_commit_master(struct llog_commit_master *lcm)
489 {
490         CFS_INIT_LIST_HEAD(&lcm->lcm_thread_busy);
491         CFS_INIT_LIST_HEAD(&lcm->lcm_thread_idle);
492         spin_lock_init(&lcm->lcm_thread_lock);
493         atomic_set(&lcm->lcm_thread_numidle, 0);
494         cfs_waitq_init(&lcm->lcm_waitq);
495         CFS_INIT_LIST_HEAD(&lcm->lcm_llcd_pending);
496         CFS_INIT_LIST_HEAD(&lcm->lcm_llcd_resend);
497         CFS_INIT_LIST_HEAD(&lcm->lcm_llcd_free);
498         spin_lock_init(&lcm->lcm_llcd_lock);
499         atomic_set(&lcm->lcm_llcd_numfree, 0);
500         lcm->lcm_llcd_minfree = 0;
501         lcm->lcm_thread_max = 5;
502         /* FIXME initialize semaphore for llog_process_args */
503         sema_init(&llpa.llpa_sem, 1);
504         return 0;
505 }
506 EXPORT_SYMBOL(llog_init_commit_master);
507
508 int llog_cleanup_commit_master(struct llog_commit_master *lcm,
509                                int force)
510 {
511         lcm->lcm_flags |= LLOG_LCM_FL_EXIT;
512         if (force)
513                 lcm->lcm_flags |= LLOG_LCM_FL_EXIT_FORCE;
514         cfs_waitq_signal(&lcm->lcm_waitq);
515
516         wait_event_interruptible(lcm->lcm_waitq,
517                                  atomic_read(&lcm->lcm_thread_total) == 0);
518         return 0;
519 }
520 EXPORT_SYMBOL(llog_cleanup_commit_master);
521
522 static int log_process_thread(void *args)
523 {
524         struct llog_process_args *data = args;
525         struct llog_ctxt *ctxt = data->llpa_ctxt;
526         void   *cb = data->llpa_cb;
527         struct llog_logid logid = *(struct llog_logid *)(data->llpa_arg);
528         struct llog_handle *llh = NULL;
529         int rc;
530         ENTRY;
531
532         mutex_up(&data->llpa_sem);
533         ptlrpc_daemonize("llog_process");     /* thread does IO to log files */
534
535         rc = llog_create(ctxt, &llh, &logid, NULL);
536         if (rc) {
537                 CERROR("llog_create failed %d\n", rc);
538                 GOTO(out, rc);
539         }
540         rc = llog_init_handle(llh, LLOG_F_IS_CAT, NULL);
541         if (rc) {
542                 CERROR("llog_init_handle failed %d\n", rc);
543                 GOTO(release_llh, rc);
544         }
545
546         if (cb) {
547                 rc = llog_cat_process(llh, (llog_cb_t)cb, NULL);
548                 if (rc != LLOG_PROC_BREAK)
549                         CERROR("llog_cat_process failed %d\n", rc);
550         } else {
551                 CWARN("no callback function for recovery\n");
552         }
553
554         CDEBUG(D_HA, "send llcd %p:%p forcibly after recovery\n",
555                ctxt->loc_llcd, ctxt);
556         llog_sync(ctxt, NULL);
557
558 release_llh:
559         rc = llog_cat_put(llh);
560         if (rc)
561                 CERROR("llog_cat_put failed %d\n", rc);
562 out:
563         llog_ctxt_put(ctxt);
564         RETURN(rc);
565 }
566
567 static int llog_recovery_generic(struct llog_ctxt *ctxt, void *handle,void *arg)
568 {
569         struct obd_device *obd = ctxt->loc_obd;
570         int rc;
571         ENTRY;
572
573         if (obd->obd_stopping)
574                 RETURN(-ENODEV);
575
576         mutex_down(&llpa.llpa_sem);
577         llpa.llpa_cb = handle;
578         llpa.llpa_arg = arg;
579         llpa.llpa_ctxt = llog_ctxt_get(ctxt); //llog_group_get_ctxt(ctxt->loc_olg, ctxt->loc_idx);
580         if (!llpa.llpa_ctxt) {
581                 up(&llpa.llpa_sem);
582                 RETURN(-ENODEV);
583         }
584         rc = cfs_kernel_thread(log_process_thread, &llpa, CLONE_VM | CLONE_FILES);
585         if (rc < 0)
586                 CERROR("error starting log_process_thread: %d\n", rc);
587         else {
588                 CDEBUG(D_HA, "log_process_thread: %d\n", rc);
589                 rc = 0;
590         }
591
592         RETURN(rc);
593 }
594
595 int llog_repl_connect(struct llog_ctxt *ctxt, int count,
596                       struct llog_logid *logid, struct llog_gen *gen,
597                       struct obd_uuid *uuid)
598 {
599         struct llog_canceld_ctxt *llcd;
600         int rc;
601         ENTRY;
602
603         /* send back llcd before recovery from llog */
604         if (ctxt->loc_llcd != NULL) {
605                 CWARN("llcd %p:%p not empty\n", ctxt->loc_llcd, ctxt);
606                 llog_sync(ctxt, NULL);
607         }
608
609         mutex_down(&ctxt->loc_sem);
610         ctxt->loc_gen = *gen;
611         llcd = llcd_grab(ctxt->loc_lcm);
612         if (llcd == NULL) {
613                 CERROR("couldn't get an llcd\n");
614                 mutex_up(&ctxt->loc_sem);
615                 RETURN(-ENOMEM);
616         }
617         llcd->llcd_ctxt = llog_ctxt_get(ctxt);
618         ctxt->loc_llcd = llcd;
619         mutex_up(&ctxt->loc_sem);
620
621         rc = llog_recovery_generic(ctxt, ctxt->llog_proc_cb, logid);
622         if (rc != 0)
623                 CERROR("error recovery process: %d\n", rc);
624
625         RETURN(rc);
626 }
627 EXPORT_SYMBOL(llog_repl_connect);
628
629 #else /* !__KERNEL__ */
630
631 int llog_obd_repl_cancel(struct llog_ctxt *ctxt,
632                          struct lov_stripe_md *lsm, int count,
633                          struct llog_cookie *cookies, int flags)
634 {
635         return 0;
636 }
637 #endif