Whamcloud - gitweb
60a4aaf1d320180ee477e153352f6d3375150425
[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  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lustre/ptlrpc/recov_thread.c
37  *
38  * OST<->MDS recovery logging thread.
39  * Invariants in implementation:
40  * - we do not share logs among different OST<->MDS connections, so that
41  *   if an OST or MDS fails it need only look at log(s) relevant to itself
42  *
43  * Author: Andreas Dilger   <adilger@clusterfs.com>
44  *         Yury Umanets     <yury.umanets@sun.com>
45  *         Alexey Lyashkov  <alexey.lyashkov@sun.com>
46  */
47
48 #define DEBUG_SUBSYSTEM S_LOG
49
50 #ifndef EXPORT_SYMTAB
51 # define EXPORT_SYMTAB
52 #endif
53
54 #ifdef __KERNEL__
55 # include <libcfs/libcfs.h>
56 #else
57 # include <libcfs/list.h>
58 # include <liblustre.h>
59 #endif
60
61 #include <obd_class.h>
62 #include <obd_support.h>
63 #include <obd_class.h>
64 #include <lustre_net.h>
65 #include <lnet/types.h>
66 #include <libcfs/list.h>
67 #include <lustre_log.h>
68 #include "ptlrpc_internal.h"
69
70 static atomic_t                   llcd_count = ATOMIC_INIT(0);
71 static cfs_mem_cache_t           *llcd_cache = NULL;
72
73 #ifdef __KERNEL__
74 enum {
75         LLOG_LCM_FL_START       = 1 << 0,
76         LLOG_LCM_FL_EXIT        = 1 << 1
77 };
78
79 /** 
80  * Allocate new llcd from cache, init it and return to caller.
81  * Bumps number of objects allocated.
82  */
83 static struct llog_canceld_ctxt *llcd_alloc(void)
84 {
85         struct llog_canceld_ctxt *llcd;
86         int llcd_size;
87
88         /* 
89          * Payload of lustre_msg V2 is bigger.
90          */
91         llcd_size = CFS_PAGE_SIZE - 
92                 lustre_msg_size(LUSTRE_MSG_MAGIC_V2, 1, NULL);
93         llcd_size += offsetof(struct llog_canceld_ctxt, llcd_cookies);
94         OBD_SLAB_ALLOC(llcd, llcd_cache, CFS_ALLOC_STD, llcd_size);
95         if (!llcd)
96                 return NULL;
97
98         llcd->llcd_size = llcd_size;
99         llcd->llcd_cookiebytes = 0;
100         atomic_inc(&llcd_count);
101         return llcd;
102 }
103
104 /**
105  * Returns passed llcd to cache.
106  */
107 static void llcd_free(struct llog_canceld_ctxt *llcd)
108 {
109         LASSERT(atomic_read(&llcd_count) > 0);
110         OBD_SLAB_FREE(llcd, llcd_cache, llcd->llcd_size);
111         atomic_dec(&llcd_count);
112 }
113
114 /**
115  * Copy passed @cookies to @llcd.
116  */
117 static void llcd_copy(struct llog_canceld_ctxt *llcd, 
118                       struct llog_cookie *cookies)
119 {
120         memcpy((char *)llcd->llcd_cookies + llcd->llcd_cookiebytes, 
121               cookies, sizeof(*cookies));
122         llcd->llcd_cookiebytes += sizeof(*cookies);
123 }
124
125 /**
126  * Checks if passed cookie fits into llcd free space buffer. Returns
127  * 1 if yes and 0 otherwise.
128  */
129 static int llcd_fit(struct llog_canceld_ctxt *llcd,
130                  struct llog_cookie *cookies)
131 {
132         return (llcd->llcd_size - 
133                 llcd->llcd_cookiebytes) >= sizeof(*cookies);
134 }
135
136 static void llcd_print(struct llog_canceld_ctxt *llcd, 
137                        const char *func, int line) 
138 {
139         CDEBUG(D_RPCTRACE, "Llcd (%p) at %s:%d:\n", llcd, func, line);
140         CDEBUG(D_RPCTRACE, "  size: %d\n", llcd->llcd_size);
141         CDEBUG(D_RPCTRACE, "  ctxt: %p\n", llcd->llcd_ctxt);
142         CDEBUG(D_RPCTRACE, "  lcm : %p\n", llcd->llcd_lcm);
143         CDEBUG(D_RPCTRACE, "  cookiebytes : %d\n", llcd->llcd_cookiebytes);
144 }
145
146 /**
147  * Llcd completion function. Called uppon llcd send finish regardless
148  * sending result. Error is passed in @rc. Note, that this will be called
149  * in cleanup time when all inflight rpcs aborted.
150  */
151 static int 
152 llcd_interpret(struct ptlrpc_request *req, void *noused, int rc)
153 {
154         struct llog_canceld_ctxt *llcd = req->rq_async_args.pointer_arg[0];
155         CDEBUG(D_RPCTRACE, "Sent llcd %p (%d)\n", llcd, rc);
156         llcd_free(llcd);
157         return 0;
158 }
159  
160 /**
161  * Send @llcd to remote node. Free llcd uppon completion or error. Sending
162  * is performed in async style so this function will return asap without 
163  * blocking.
164  */
165 static int llcd_send(struct llog_canceld_ctxt *llcd)
166 {
167         char *bufs[2] = { NULL, (char *)llcd->llcd_cookies };
168         struct obd_import *import = NULL;
169         struct llog_commit_master *lcm;
170         struct ptlrpc_request *req;
171         struct llog_ctxt *ctxt;
172         int rc;
173         ENTRY;
174
175         ctxt = llcd->llcd_ctxt;
176         if (!ctxt) {
177                 CERROR("Invalid llcd with NULL ctxt found (%p)\n", 
178                        llcd);
179                 llcd_print(llcd, __FUNCTION__, __LINE__);
180                 LBUG();
181         }
182         LASSERT_SEM_LOCKED(&ctxt->loc_sem);
183
184         if (llcd->llcd_cookiebytes == 0)
185                 GOTO(exit, rc = 0);
186
187         lcm = llcd->llcd_lcm;
188         
189         /* 
190          * Check if we're in exit stage. Do not send llcd in
191          * this case. 
192          */
193         if (test_bit(LLOG_LCM_FL_EXIT, &lcm->lcm_flags))
194                 GOTO(exit, rc = -ENODEV);
195
196         CDEBUG(D_RPCTRACE, "Sending llcd %p\n", llcd);
197
198         import = llcd->llcd_ctxt->loc_imp;
199         if (!import || (import == LP_POISON) || 
200             (import->imp_client == LP_POISON)) {
201                 CERROR("Invalid import %p for llcd %p\n", 
202                        import, llcd);
203                 GOTO(exit, rc = -ENODEV);
204         }
205
206         OBD_FAIL_TIMEOUT(OBD_FAIL_PTLRPC_DELAY_RECOV, 10);
207
208         /*
209          * No need to get import here as it is already done in 
210          * llog_receptor_accept().
211          */
212         req = ptlrpc_request_alloc(import, &RQF_LOG_CANCEL);
213         if (req == NULL) {
214                 CERROR("Can't allocate request for sending llcd %p\n", 
215                        llcd);
216                 GOTO(exit, rc = -ENOMEM);
217         }
218         req_capsule_set_size(&req->rq_pill, &RMF_LOGCOOKIES,
219                              RCL_CLIENT, llcd->llcd_cookiebytes);
220
221         rc = ptlrpc_request_bufs_pack(req, LUSTRE_LOG_VERSION,
222                                       OBD_LOG_CANCEL, bufs, NULL);
223         if (rc) {
224                 ptlrpc_request_free(req);
225                 GOTO(exit, rc);
226         }
227
228         ptlrpc_at_set_req_timeout(req);
229         ptlrpc_request_set_replen(req);
230
231         /* bug 5515 */
232         req->rq_request_portal = LDLM_CANCEL_REQUEST_PORTAL;
233         req->rq_reply_portal = LDLM_CANCEL_REPLY_PORTAL;
234         req->rq_interpret_reply = llcd_interpret;
235         req->rq_async_args.pointer_arg[0] = llcd;
236         rc = ptlrpc_set_add_new_req(&lcm->lcm_pc, req);
237         if (rc)
238                 GOTO(exit, rc);
239
240         RETURN(0);
241 exit:
242         CDEBUG(D_RPCTRACE, "Refused llcd %p\n", llcd);
243         llcd_free(llcd);
244         return rc;
245 }
246
247 /**
248  * Attach @llcd to @ctxt. Establish llcd vs. ctxt reserve connection
249  * so hat they can refer each other.
250  */
251 static int
252 llcd_attach(struct llog_ctxt *ctxt, struct llog_canceld_ctxt *llcd)
253 {
254         struct llog_commit_master *lcm;
255
256         LASSERT(ctxt != NULL && llcd != NULL);
257         LASSERT_SEM_LOCKED(&ctxt->loc_sem);
258         LASSERT(ctxt->loc_llcd == NULL);
259         lcm = ctxt->loc_lcm;
260         atomic_inc(&lcm->lcm_count);
261         CDEBUG(D_RPCTRACE, "Attach llcd %p to ctxt %p (%d)\n",
262                llcd, ctxt, atomic_read(&lcm->lcm_count));
263         llcd->llcd_ctxt = llog_ctxt_get(ctxt);
264         llcd->llcd_lcm = ctxt->loc_lcm;
265         ctxt->loc_llcd = llcd;
266         return 0;
267 }
268
269 /**
270  * Opposite to llcd_attach(). Detaches llcd from its @ctxt. This makes
271  * sure that this llcd will not be found another time we try to cancel.
272  */
273 static struct llog_canceld_ctxt *llcd_detach(struct llog_ctxt *ctxt)
274 {
275         struct llog_commit_master *lcm;
276         struct llog_canceld_ctxt *llcd;
277
278         LASSERT(ctxt != NULL);
279         LASSERT_SEM_LOCKED(&ctxt->loc_sem);
280
281         llcd = ctxt->loc_llcd;
282         if (!llcd)
283                 return NULL;
284
285         lcm = ctxt->loc_lcm;
286         if (atomic_read(&lcm->lcm_count) == 0) {
287                 CERROR("Invalid detach occured %p:%p\n", ctxt, llcd);
288                 llcd_print(llcd, __FUNCTION__, __LINE__);
289                 LBUG();
290         }
291         atomic_dec(&lcm->lcm_count);
292         ctxt->loc_llcd = NULL;
293         
294         CDEBUG(D_RPCTRACE, "Detach llcd %p from ctxt %p (%d)\n", 
295                llcd, ctxt, atomic_read(&lcm->lcm_count));
296
297         llog_ctxt_put(ctxt);
298         return llcd;
299 }
300
301 /**
302  * Return @llcd cached in @ctxt. Allocate new one if required. Attach it
303  * to ctxt so that it may be used for gathering cookies and sending.
304  */
305 static struct llog_canceld_ctxt *llcd_get(struct llog_ctxt *ctxt)
306 {
307         struct llog_canceld_ctxt *llcd;
308
309         llcd = llcd_alloc();
310         if (!llcd) {
311                 CERROR("Couldn't alloc an llcd for ctxt %p\n", ctxt);
312                 return NULL;
313         }
314         llcd_attach(ctxt, llcd);
315         return llcd;
316 }
317
318 /**
319  * Deatch llcd from its @ctxt. Free llcd.
320  */
321 static void llcd_put(struct llog_ctxt *ctxt)
322 {
323         struct llog_commit_master *lcm;
324         struct llog_canceld_ctxt *llcd;
325
326         lcm = ctxt->loc_lcm;
327         llcd = llcd_detach(ctxt);
328         if (llcd)
329                 llcd_free(llcd);
330
331         if (atomic_read(&lcm->lcm_count) == 0)
332                 cfs_waitq_signal(&lcm->lcm_waitq);
333 }
334
335 /**
336  * Detach llcd from its @ctxt so that nobody will find it with try to
337  * re-use. Send llcd to remote node.
338  */
339 static int llcd_push(struct llog_ctxt *ctxt)
340 {
341         struct llog_canceld_ctxt *llcd;
342         int rc;
343
344         /*
345          * Make sure that this llcd will not be sent again as we detach 
346          * it from ctxt.
347          */
348         llcd = llcd_detach(ctxt);
349         if (!llcd) {
350                 CERROR("Invalid detached llcd found %p\n", llcd);
351                 llcd_print(llcd, __FUNCTION__, __LINE__);
352                 LBUG();
353         }
354         
355         rc = llcd_send(llcd);
356         if (rc)
357                 CERROR("Couldn't send llcd %p (%d)\n", llcd, rc);
358         return rc;
359 }
360
361 /**
362  * Start recovery thread which actually deals llcd sending. This
363  * is all ptlrpc standard thread based so there is not much of work
364  * to do.
365  */
366 int llog_recov_thread_start(struct llog_commit_master *lcm)
367 {
368         int rc;
369         ENTRY;
370
371         rc = ptlrpcd_start(lcm->lcm_name, &lcm->lcm_pc);
372         if (rc) {
373                 CERROR("Error %d while starting recovery thread %s\n", 
374                        rc, lcm->lcm_name);
375                 RETURN(rc);
376         }
377         lcm->lcm_set = lcm->lcm_pc.pc_set;
378         RETURN(rc);
379 }
380 EXPORT_SYMBOL(llog_recov_thread_start);
381
382 /**
383  * Stop recovery thread. Complement to llog_recov_thread_start().
384  */
385 void llog_recov_thread_stop(struct llog_commit_master *lcm, int force)
386 {
387         struct l_wait_info lwi = LWI_INTR(LWI_ON_SIGNAL_NOOP, NULL);
388         ENTRY;
389
390         /**
391          * Let all know that we're stopping. This will also make 
392          * llcd_send() refuse any new llcds.
393          */
394         set_bit(LLOG_LCM_FL_EXIT, &lcm->lcm_flags);
395
396         /**
397          * Stop processing thread. No new rpcs will be accepted for
398          * for processing now.
399          */
400         ptlrpcd_stop(&lcm->lcm_pc, force);
401
402         /*
403          * Wait for llcd number == 0. Note, this is infinite wait.
404          * All other parts should make sure that no lost llcd is left.
405          */
406         l_wait_event(lcm->lcm_waitq,
407                      atomic_read(&lcm->lcm_count) == 0, &lwi);
408         EXIT;
409 }
410 EXPORT_SYMBOL(llog_recov_thread_stop);
411
412 /**
413  * Initialize commit master structure and start recovery thread on it.
414  */
415 struct llog_commit_master *llog_recov_thread_init(char *name)
416 {
417         struct llog_commit_master *lcm;
418         int rc;
419         ENTRY;
420
421         OBD_ALLOC_PTR(lcm);
422         if (!lcm)
423                 RETURN(NULL);
424
425         /*
426          * Try to create threads with unique names.
427          */
428         snprintf(lcm->lcm_name, sizeof(lcm->lcm_name), 
429                  "ll_log_commit_%s", name);
430
431         strncpy(lcm->lcm_name, name, sizeof(lcm->lcm_name));
432         cfs_waitq_init(&lcm->lcm_waitq);
433         atomic_set(&lcm->lcm_count, 0);
434         rc = llog_recov_thread_start(lcm);
435         if (rc) {
436                 CERROR("Can't start commit thread, rc %d\n", rc);
437                 GOTO(out, rc);
438         }
439         RETURN(lcm);
440 out:
441         OBD_FREE_PTR(lcm);
442         return NULL;
443 }
444 EXPORT_SYMBOL(llog_recov_thread_init);
445
446 /**
447  * Finalize commit master and its recovery thread.
448  */
449 void llog_recov_thread_fini(struct llog_commit_master *lcm, int force)
450 {
451         ENTRY;
452         llog_recov_thread_stop(lcm, force);
453         OBD_FREE_PTR(lcm);
454         EXIT;
455 }
456 EXPORT_SYMBOL(llog_recov_thread_fini);
457
458 static int llog_recov_thread_replay(struct llog_ctxt *ctxt, 
459                                     void *cb, void *arg)
460 {
461         struct obd_device *obd = ctxt->loc_obd;
462         struct llog_process_cat_args *lpca;
463         int rc;
464         ENTRY;
465
466         if (obd->obd_stopping)
467                 RETURN(-ENODEV);
468
469         /*
470          * This will be balanced in llog_cat_process_thread()
471          */
472         OBD_ALLOC_PTR(lpca);
473         if (!lpca)
474                 RETURN(-ENOMEM);
475
476         lpca->lpca_cb = cb;
477         lpca->lpca_arg = arg;
478
479         /*
480          * This will be balanced in llog_cat_process_thread()
481          */
482         lpca->lpca_ctxt = llog_ctxt_get(ctxt);
483         if (!lpca->lpca_ctxt) {
484                 OBD_FREE_PTR(lpca);
485                 RETURN(-ENODEV);
486         }
487         rc = cfs_kernel_thread(llog_cat_process_thread, lpca, 
488                                CLONE_VM | CLONE_FILES);
489         if (rc < 0) {
490                 CERROR("Error starting llog_cat_process_thread(): %d\n", rc);
491                 OBD_FREE_PTR(lpca);
492                 llog_ctxt_put(ctxt);
493         } else {
494                 CDEBUG(D_HA, "Started llog_cat_process_thread(): %d\n", rc);
495                 rc = 0;
496         }
497
498         RETURN(rc);
499 }
500
501 int llog_obd_repl_connect(struct llog_ctxt *ctxt, int count, 
502                           struct llog_logid *logid, struct llog_gen *gen,
503                           struct obd_uuid *uuid)
504 {
505         int rc;
506         ENTRY;
507
508         /* 
509          * Send back cached llcd from llog before recovery if we have any.
510          * This is void is nothing cached is found there.
511          */
512         llog_sync(ctxt, NULL);
513
514         /* 
515          * Start recovery in separate thread. 
516          */
517         mutex_down(&ctxt->loc_sem);
518         ctxt->loc_gen = *gen;
519         rc = llog_recov_thread_replay(ctxt, ctxt->llog_proc_cb, logid);
520         mutex_up(&ctxt->loc_sem);
521
522         RETURN(rc);
523 }
524 EXPORT_SYMBOL(llog_obd_repl_connect);
525
526 /** 
527  * Deleted objects have a commit callback that cancels the MDS
528  * log record for the deletion. The commit callback calls this
529  * function.
530  */
531 int llog_obd_repl_cancel(struct llog_ctxt *ctxt,
532                          struct lov_stripe_md *lsm, int count,
533                          struct llog_cookie *cookies, int flags)
534 {
535         struct llog_commit_master *lcm;
536         struct llog_canceld_ctxt *llcd;
537         int rc = 0;
538         ENTRY;
539
540         LASSERT(ctxt != NULL);
541
542         mutex_down(&ctxt->loc_sem);
543         lcm = ctxt->loc_lcm;
544         
545         /*
546          * Let's check if we have all structures alive. We also check for
547          * possible shutdown. Do nothing if we're stopping.
548          */
549         if (ctxt->loc_imp == NULL) {
550                 CDEBUG(D_RPCTRACE, "No import for ctxt %p\n", ctxt);
551                 GOTO(out, rc = -ENODEV);
552         }
553
554         if (ctxt->loc_obd->obd_stopping) {
555                 CDEBUG(D_RPCTRACE, "Obd is stopping for ctxt %p\n", ctxt);
556                 GOTO(out, rc = -ENODEV);
557         }
558
559         if (test_bit(LLOG_LCM_FL_EXIT, &lcm->lcm_flags)) {
560                 CDEBUG(D_RPCTRACE, "Commit thread is stopping for ctxt %p\n", 
561                        ctxt);
562                 GOTO(out, rc = -ENODEV);
563         }
564
565         llcd = ctxt->loc_llcd;
566
567         if (count > 0 && cookies != NULL) {
568                 /*
569                  * Get new llcd from ctxt if required. 
570                  */
571                 if (!llcd) {
572                         llcd = llcd_get(ctxt);
573                         if (!llcd)
574                                 GOTO(out, rc = -ENOMEM);
575                         /*
576                          * Allocation is successful, let's check for stop
577                          * flag again to fall back as soon as possible.
578                          */
579                         if (test_bit(LLOG_LCM_FL_EXIT, &lcm->lcm_flags))
580                                 GOTO(out, rc = -ENODEV);
581                 }
582
583                 /*
584                  * Llcd does not have enough room for @cookies. Let's push 
585                  * it out and allocate new one. 
586                  */
587                 if (!llcd_fit(llcd, cookies)) {
588                         rc = llcd_push(ctxt);
589                         if (rc)
590                                 GOTO(out, rc);
591                         llcd = llcd_get(ctxt);
592                         if (!llcd)
593                                 GOTO(out, rc = -ENOMEM);
594                         /*
595                          * Allocation is successful, let's check for stop
596                          * flag again to fall back as soon as possible.
597                          */
598                         if (test_bit(LLOG_LCM_FL_EXIT, &lcm->lcm_flags))
599                                 GOTO(out, rc = -ENODEV);
600                 }
601
602                 /*
603                  * Copy cookies to @llcd, no matter old or new allocated one.
604                  */
605                 llcd_copy(llcd, cookies);
606         }
607
608         /*
609          * Let's check if we need to send copied @cookies asap. If yes - do it.
610          */
611         if (llcd && (flags & OBD_LLOG_FL_SENDNOW)) {
612                 rc = llcd_push(ctxt);
613                 if (rc)
614                         GOTO(out, rc);
615         }
616         EXIT;
617 out:
618         if (rc)
619                 llcd_put(ctxt);
620         mutex_up(&ctxt->loc_sem);
621         return rc;
622 }
623 EXPORT_SYMBOL(llog_obd_repl_cancel);
624
625 int llog_obd_repl_sync(struct llog_ctxt *ctxt, struct obd_export *exp)
626 {
627         int rc = 0;
628         ENTRY;
629
630         mutex_down(&ctxt->loc_sem);
631         if (exp && (ctxt->loc_imp == exp->exp_imp_reverse)) {
632                 CDEBUG(D_RPCTRACE, "Reverse import disconnect\n");
633                 /*
634                  * Check for llcd which might be left attached to @ctxt.
635                  * Let's kill it.
636                  */
637                 llcd_put(ctxt);
638                 mutex_up(&ctxt->loc_sem);
639         } else {
640                 mutex_up(&ctxt->loc_sem);
641                 rc = llog_cancel(ctxt, NULL, 0, NULL, OBD_LLOG_FL_SENDNOW);
642         }
643         RETURN(rc);
644 }
645 EXPORT_SYMBOL(llog_obd_repl_sync);
646
647 #else /* !__KERNEL__ */
648
649 int llog_obd_repl_cancel(struct llog_ctxt *ctxt,
650                          struct lov_stripe_md *lsm, int count,
651                          struct llog_cookie *cookies, int flags)
652 {
653         return 0;
654 }
655 #endif
656
657 /**
658  * Module init time fucntion. Initializes slab for llcd objects.
659  */
660 int llog_recov_init(void)
661 {
662         int llcd_size;
663
664         llcd_size = CFS_PAGE_SIZE - 
665                 lustre_msg_size(LUSTRE_MSG_MAGIC_V2, 1, NULL);
666         llcd_size += offsetof(struct llog_canceld_ctxt, llcd_cookies);
667         llcd_cache = cfs_mem_cache_create("llcd_cache", llcd_size, 0, 0);
668         if (!llcd_cache) {
669                 CERROR("Error allocating llcd cache\n");
670                 return -ENOMEM;
671         }
672         return 0;
673 }
674
675 /**
676  * Module fini time fucntion. Releases slab for llcd objects.
677  */
678 void llog_recov_fini(void)
679 {
680         /*
681          * Kill llcd cache when thread is stopped and we're sure no 
682          * llcd in use left.
683          */
684         if (llcd_cache) {
685                 /*
686                  * In 2.6.22 cfs_mem_cache_destroy() will not return error
687                  * for busy resources. Let's check it another way.
688                  */
689                 LASSERTF(atomic_read(&llcd_count) == 0, 
690                          "Can't destroy llcd cache! Number of "
691                          "busy llcds: %d\n", atomic_read(&llcd_count));
692                 cfs_mem_cache_destroy(llcd_cache);
693                 llcd_cache = NULL;
694         }
695 }