Whamcloud - gitweb
land clio.
[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(const struct lu_env *env,
153                struct ptlrpc_request *req, void *noused, int rc)
154 {
155         struct llog_canceld_ctxt *llcd = req->rq_async_args.pointer_arg[0];
156         CDEBUG(D_RPCTRACE, "Sent llcd %p (%d)\n", llcd, rc);
157         llcd_free(llcd);
158         return 0;
159 }
160
161 /**
162  * Send @llcd to remote node. Free llcd uppon completion or error. Sending
163  * is performed in async style so this function will return asap without
164  * blocking.
165  */
166 static int llcd_send(struct llog_canceld_ctxt *llcd)
167 {
168         char *bufs[2] = { NULL, (char *)llcd->llcd_cookies };
169         struct obd_import *import = NULL;
170         struct llog_commit_master *lcm;
171         struct ptlrpc_request *req;
172         struct llog_ctxt *ctxt;
173         int rc;
174         ENTRY;
175
176         ctxt = llcd->llcd_ctxt;
177         if (!ctxt) {
178                 CERROR("Invalid llcd with NULL ctxt found (%p)\n",
179                        llcd);
180                 llcd_print(llcd, __FUNCTION__, __LINE__);
181                 LBUG();
182         }
183         LASSERT_SEM_LOCKED(&ctxt->loc_sem);
184
185         if (llcd->llcd_cookiebytes == 0)
186                 GOTO(exit, rc = 0);
187
188         lcm = llcd->llcd_lcm;
189
190         /*
191          * Check if we're in exit stage. Do not send llcd in
192          * this case.
193          */
194         if (test_bit(LLOG_LCM_FL_EXIT, &lcm->lcm_flags))
195                 GOTO(exit, rc = -ENODEV);
196
197         CDEBUG(D_RPCTRACE, "Sending llcd %p\n", llcd);
198
199         import = llcd->llcd_ctxt->loc_imp;
200         if (!import || (import == LP_POISON) ||
201             (import->imp_client == LP_POISON)) {
202                 CERROR("Invalid import %p for llcd %p\n",
203                        import, llcd);
204                 GOTO(exit, rc = -ENODEV);
205         }
206
207         OBD_FAIL_TIMEOUT(OBD_FAIL_PTLRPC_DELAY_RECOV, 10);
208
209         /*
210          * No need to get import here as it is already done in
211          * llog_receptor_accept().
212          */
213         req = ptlrpc_request_alloc(import, &RQF_LOG_CANCEL);
214         if (req == NULL) {
215                 CERROR("Can't allocate request for sending llcd %p\n",
216                        llcd);
217                 GOTO(exit, rc = -ENOMEM);
218         }
219         req_capsule_set_size(&req->rq_pill, &RMF_LOGCOOKIES,
220                              RCL_CLIENT, llcd->llcd_cookiebytes);
221
222         rc = ptlrpc_request_bufs_pack(req, LUSTRE_LOG_VERSION,
223                                       OBD_LOG_CANCEL, bufs, NULL);
224         if (rc) {
225                 ptlrpc_request_free(req);
226                 GOTO(exit, rc);
227         }
228
229         ptlrpc_at_set_req_timeout(req);
230         ptlrpc_request_set_replen(req);
231
232         /* bug 5515 */
233         req->rq_request_portal = LDLM_CANCEL_REQUEST_PORTAL;
234         req->rq_reply_portal = LDLM_CANCEL_REPLY_PORTAL;
235         req->rq_interpret_reply = (ptlrpc_interpterer_t)llcd_interpret;
236         req->rq_async_args.pointer_arg[0] = llcd;
237         rc = ptlrpc_set_add_new_req(&lcm->lcm_pc, req);
238         if (rc) {
239                 ptlrpc_request_free(req);
240                 GOTO(exit, rc);
241         }
242         RETURN(0);
243 exit:
244         CDEBUG(D_RPCTRACE, "Refused llcd %p\n", llcd);
245         llcd_free(llcd);
246         return rc;
247 }
248
249 /**
250  * Attach @llcd to @ctxt. Establish llcd vs. ctxt reserve connection
251  * so hat they can refer each other.
252  */
253 static int
254 llcd_attach(struct llog_ctxt *ctxt, struct llog_canceld_ctxt *llcd)
255 {
256         struct llog_commit_master *lcm;
257
258         LASSERT(ctxt != NULL && llcd != NULL);
259         LASSERT_SEM_LOCKED(&ctxt->loc_sem);
260         LASSERT(ctxt->loc_llcd == NULL);
261         lcm = ctxt->loc_lcm;
262         atomic_inc(&lcm->lcm_count);
263         CDEBUG(D_RPCTRACE, "Attach llcd %p to ctxt %p (%d)\n",
264                llcd, ctxt, atomic_read(&lcm->lcm_count));
265         llcd->llcd_ctxt = llog_ctxt_get(ctxt);
266         llcd->llcd_lcm = ctxt->loc_lcm;
267         ctxt->loc_llcd = llcd;
268         return 0;
269 }
270
271 /**
272  * Opposite to llcd_attach(). Detaches llcd from its @ctxt. This makes
273  * sure that this llcd will not be found another time we try to cancel.
274  */
275 static struct llog_canceld_ctxt *llcd_detach(struct llog_ctxt *ctxt)
276 {
277         struct llog_commit_master *lcm;
278         struct llog_canceld_ctxt *llcd;
279
280         LASSERT(ctxt != NULL);
281         LASSERT_SEM_LOCKED(&ctxt->loc_sem);
282
283         llcd = ctxt->loc_llcd;
284         if (!llcd)
285                 return NULL;
286
287         lcm = ctxt->loc_lcm;
288         if (atomic_read(&lcm->lcm_count) == 0) {
289                 CERROR("Invalid detach occured %p:%p\n", ctxt, llcd);
290                 llcd_print(llcd, __FUNCTION__, __LINE__);
291                 LBUG();
292         }
293         atomic_dec(&lcm->lcm_count);
294         ctxt->loc_llcd = NULL;
295
296         CDEBUG(D_RPCTRACE, "Detach llcd %p from ctxt %p (%d)\n",
297                llcd, ctxt, atomic_read(&lcm->lcm_count));
298
299         llog_ctxt_put(ctxt);
300         return llcd;
301 }
302
303 /**
304  * Return @llcd cached in @ctxt. Allocate new one if required. Attach it
305  * to ctxt so that it may be used for gathering cookies and sending.
306  */
307 static struct llog_canceld_ctxt *llcd_get(struct llog_ctxt *ctxt)
308 {
309         struct llog_canceld_ctxt *llcd;
310
311         llcd = llcd_alloc();
312         if (!llcd) {
313                 CERROR("Couldn't alloc an llcd for ctxt %p\n", ctxt);
314                 return NULL;
315         }
316         llcd_attach(ctxt, llcd);
317         return llcd;
318 }
319
320 /**
321  * Deatch llcd from its @ctxt. Free llcd.
322  */
323 static void llcd_put(struct llog_ctxt *ctxt)
324 {
325         struct llog_commit_master *lcm;
326         struct llog_canceld_ctxt *llcd;
327
328         lcm = ctxt->loc_lcm;
329         llcd = llcd_detach(ctxt);
330         if (llcd)
331                 llcd_free(llcd);
332
333         if (atomic_read(&lcm->lcm_count) == 0)
334                 cfs_waitq_signal(&lcm->lcm_waitq);
335 }
336
337 /**
338  * Detach llcd from its @ctxt so that nobody will find it with try to
339  * re-use. Send llcd to remote node.
340  */
341 static int llcd_push(struct llog_ctxt *ctxt)
342 {
343         struct llog_canceld_ctxt *llcd;
344         int rc;
345
346         /*
347          * Make sure that this llcd will not be sent again as we detach
348          * it from ctxt.
349          */
350         llcd = llcd_detach(ctxt);
351         if (!llcd) {
352                 CERROR("Invalid detached llcd found %p\n", llcd);
353                 llcd_print(llcd, __FUNCTION__, __LINE__);
354                 LBUG();
355         }
356
357         rc = llcd_send(llcd);
358         if (rc)
359                 CERROR("Couldn't send llcd %p (%d)\n", llcd, rc);
360         return rc;
361 }
362
363 /**
364  * Start recovery thread which actually deals llcd sending. This
365  * is all ptlrpc standard thread based so there is not much of work
366  * to do.
367  */
368 int llog_recov_thread_start(struct llog_commit_master *lcm)
369 {
370         int rc;
371         ENTRY;
372
373         rc = ptlrpcd_start(lcm->lcm_name, &lcm->lcm_pc);
374         if (rc) {
375                 CERROR("Error %d while starting recovery thread %s\n",
376                        rc, lcm->lcm_name);
377                 RETURN(rc);
378         }
379         lcm->lcm_set = lcm->lcm_pc.pc_set;
380         RETURN(rc);
381 }
382 EXPORT_SYMBOL(llog_recov_thread_start);
383
384 /**
385  * Stop recovery thread. Complement to llog_recov_thread_start().
386  */
387 void llog_recov_thread_stop(struct llog_commit_master *lcm, int force)
388 {
389         struct l_wait_info lwi = LWI_INTR(LWI_ON_SIGNAL_NOOP, NULL);
390         ENTRY;
391
392         /**
393          * Let all know that we're stopping. This will also make
394          * llcd_send() refuse any new llcds.
395          */
396         set_bit(LLOG_LCM_FL_EXIT, &lcm->lcm_flags);
397
398         /**
399          * Stop processing thread. No new rpcs will be accepted for
400          * for processing now.
401          */
402         ptlrpcd_stop(&lcm->lcm_pc, force);
403
404         /*
405          * Wait for llcd number == 0. Note, this is infinite wait.
406          * All other parts should make sure that no lost llcd is left.
407          */
408         l_wait_event(lcm->lcm_waitq,
409                      atomic_read(&lcm->lcm_count) == 0, &lwi);
410         EXIT;
411 }
412 EXPORT_SYMBOL(llog_recov_thread_stop);
413
414 /**
415  * Initialize commit master structure and start recovery thread on it.
416  */
417 struct llog_commit_master *llog_recov_thread_init(char *name)
418 {
419         struct llog_commit_master *lcm;
420         int rc;
421         ENTRY;
422
423         OBD_ALLOC_PTR(lcm);
424         if (!lcm)
425                 RETURN(NULL);
426
427         /*
428          * Try to create threads with unique names.
429          */
430         snprintf(lcm->lcm_name, sizeof(lcm->lcm_name),
431                  "ll_log_commit_%s", name);
432
433         strncpy(lcm->lcm_name, name, sizeof(lcm->lcm_name));
434         cfs_waitq_init(&lcm->lcm_waitq);
435         atomic_set(&lcm->lcm_count, 0);
436         rc = llog_recov_thread_start(lcm);
437         if (rc) {
438                 CERROR("Can't start commit thread, rc %d\n", rc);
439                 GOTO(out, rc);
440         }
441         RETURN(lcm);
442 out:
443         OBD_FREE_PTR(lcm);
444         return NULL;
445 }
446 EXPORT_SYMBOL(llog_recov_thread_init);
447
448 /**
449  * Finalize commit master and its recovery thread.
450  */
451 void llog_recov_thread_fini(struct llog_commit_master *lcm, int force)
452 {
453         ENTRY;
454         llog_recov_thread_stop(lcm, force);
455         OBD_FREE_PTR(lcm);
456         EXIT;
457 }
458 EXPORT_SYMBOL(llog_recov_thread_fini);
459
460 static int llog_recov_thread_replay(struct llog_ctxt *ctxt,
461                                     void *cb, void *arg)
462 {
463         struct obd_device *obd = ctxt->loc_obd;
464         struct llog_process_cat_args *lpca;
465         int rc;
466         ENTRY;
467
468         if (obd->obd_stopping)
469                 RETURN(-ENODEV);
470
471         /*
472          * This will be balanced in llog_cat_process_thread()
473          */
474         OBD_ALLOC_PTR(lpca);
475         if (!lpca)
476                 RETURN(-ENOMEM);
477
478         lpca->lpca_cb = cb;
479         lpca->lpca_arg = arg;
480
481         /*
482          * This will be balanced in llog_cat_process_thread()
483          */
484         lpca->lpca_ctxt = llog_ctxt_get(ctxt);
485         if (!lpca->lpca_ctxt) {
486                 OBD_FREE_PTR(lpca);
487                 RETURN(-ENODEV);
488         }
489         rc = cfs_kernel_thread(llog_cat_process_thread, lpca,
490                                CLONE_VM | CLONE_FILES);
491         if (rc < 0) {
492                 CERROR("Error starting llog_cat_process_thread(): %d\n", rc);
493                 OBD_FREE_PTR(lpca);
494                 llog_ctxt_put(ctxt);
495         } else {
496                 CDEBUG(D_HA, "Started llog_cat_process_thread(): %d\n", rc);
497                 rc = 0;
498         }
499
500         RETURN(rc);
501 }
502
503 int llog_obd_repl_connect(struct llog_ctxt *ctxt,
504                           struct llog_logid *logid, struct llog_gen *gen,
505                           struct obd_uuid *uuid)
506 {
507         int rc;
508         ENTRY;
509
510         /*
511          * Send back cached llcd from llog before recovery if we have any.
512          * This is void is nothing cached is found there.
513          */
514         llog_sync(ctxt, NULL);
515
516         /*
517          * Start recovery in separate thread.
518          */
519         mutex_down(&ctxt->loc_sem);
520         ctxt->loc_gen = *gen;
521         rc = llog_recov_thread_replay(ctxt, ctxt->llog_proc_cb, logid);
522         mutex_up(&ctxt->loc_sem);
523
524         RETURN(rc);
525 }
526 EXPORT_SYMBOL(llog_obd_repl_connect);
527
528 /**
529  * Deleted objects have a commit callback that cancels the MDS
530  * log record for the deletion. The commit callback calls this
531  * function.
532  */
533 int llog_obd_repl_cancel(struct llog_ctxt *ctxt,
534                          struct lov_stripe_md *lsm, int count,
535                          struct llog_cookie *cookies, int flags)
536 {
537         struct llog_commit_master *lcm;
538         struct llog_canceld_ctxt *llcd;
539         int rc = 0;
540         ENTRY;
541
542         LASSERT(ctxt != NULL);
543
544         mutex_down(&ctxt->loc_sem);
545         lcm = ctxt->loc_lcm;
546
547         /*
548          * Let's check if we have all structures alive. We also check for
549          * possible shutdown. Do nothing if we're stopping.
550          */
551         if (ctxt->loc_imp == NULL) {
552                 CDEBUG(D_RPCTRACE, "No import for ctxt %p\n", ctxt);
553                 GOTO(out, rc = -ENODEV);
554         }
555
556         if (ctxt->loc_obd->obd_stopping) {
557                 CDEBUG(D_RPCTRACE, "Obd is stopping for ctxt %p\n", ctxt);
558                 GOTO(out, rc = -ENODEV);
559         }
560
561         if (test_bit(LLOG_LCM_FL_EXIT, &lcm->lcm_flags)) {
562                 CDEBUG(D_RPCTRACE, "Commit thread is stopping for ctxt %p\n",
563                        ctxt);
564                 GOTO(out, rc = -ENODEV);
565         }
566
567         llcd = ctxt->loc_llcd;
568
569         if (count > 0 && cookies != NULL) {
570                 /*
571                  * Get new llcd from ctxt if required.
572                  */
573                 if (!llcd) {
574                         llcd = llcd_get(ctxt);
575                         if (!llcd)
576                                 GOTO(out, rc = -ENOMEM);
577                         /*
578                          * Allocation is successful, let's check for stop
579                          * flag again to fall back as soon as possible.
580                          */
581                         if (test_bit(LLOG_LCM_FL_EXIT, &lcm->lcm_flags))
582                                 GOTO(out, rc = -ENODEV);
583                 }
584
585                 /*
586                  * Llcd does not have enough room for @cookies. Let's push
587                  * it out and allocate new one.
588                  */
589                 if (!llcd_fit(llcd, cookies)) {
590                         rc = llcd_push(ctxt);
591                         if (rc)
592                                 GOTO(out, rc);
593                         llcd = llcd_get(ctxt);
594                         if (!llcd)
595                                 GOTO(out, rc = -ENOMEM);
596                         /*
597                          * Allocation is successful, let's check for stop
598                          * flag again to fall back as soon as possible.
599                          */
600                         if (test_bit(LLOG_LCM_FL_EXIT, &lcm->lcm_flags))
601                                 GOTO(out, rc = -ENODEV);
602                 }
603
604                 /*
605                  * Copy cookies to @llcd, no matter old or new allocated one.
606                  */
607                 llcd_copy(llcd, cookies);
608         }
609
610         /*
611          * Let's check if we need to send copied @cookies asap. If yes - do it.
612          */
613         if (llcd && (flags & OBD_LLOG_FL_SENDNOW)) {
614                 rc = llcd_push(ctxt);
615                 if (rc)
616                         GOTO(out, rc);
617         }
618         EXIT;
619 out:
620         if (rc)
621                 llcd_put(ctxt);
622         mutex_up(&ctxt->loc_sem);
623         return rc;
624 }
625 EXPORT_SYMBOL(llog_obd_repl_cancel);
626
627 int llog_obd_repl_sync(struct llog_ctxt *ctxt, struct obd_export *exp)
628 {
629         int rc = 0;
630         ENTRY;
631
632         mutex_down(&ctxt->loc_sem);
633         if (exp && (ctxt->loc_imp == exp->exp_imp_reverse)) {
634                 CDEBUG(D_RPCTRACE, "Reverse import disconnect\n");
635                 /*
636                  * Check for llcd which might be left attached to @ctxt.
637                  * Let's kill it.
638                  */
639                 llcd_put(ctxt);
640                 mutex_up(&ctxt->loc_sem);
641         } else {
642                 mutex_up(&ctxt->loc_sem);
643                 rc = llog_cancel(ctxt, NULL, 0, NULL, OBD_LLOG_FL_SENDNOW);
644         }
645         RETURN(rc);
646 }
647 EXPORT_SYMBOL(llog_obd_repl_sync);
648
649 #else /* !__KERNEL__ */
650
651 int llog_obd_repl_cancel(struct llog_ctxt *ctxt,
652                          struct lov_stripe_md *lsm, int count,
653                          struct llog_cookie *cookies, int flags)
654 {
655         return 0;
656 }
657 #endif
658
659 /**
660  * Module init time fucntion. Initializes slab for llcd objects.
661  */
662 int llog_recov_init(void)
663 {
664         int llcd_size;
665
666         llcd_size = CFS_PAGE_SIZE -
667                 lustre_msg_size(LUSTRE_MSG_MAGIC_V2, 1, NULL);
668         llcd_size += offsetof(struct llog_canceld_ctxt, llcd_cookies);
669         llcd_cache = cfs_mem_cache_create("llcd_cache", llcd_size, 0, 0);
670         if (!llcd_cache) {
671                 CERROR("Error allocating llcd cache\n");
672                 return -ENOMEM;
673         }
674         return 0;
675 }
676
677 /**
678  * Module fini time fucntion. Releases slab for llcd objects.
679  */
680 void llog_recov_fini(void)
681 {
682         /*
683          * Kill llcd cache when thread is stopped and we're sure no
684          * llcd in use left.
685          */
686         if (llcd_cache) {
687                 /*
688                  * In 2.6.22 cfs_mem_cache_destroy() will not return error
689                  * for busy resources. Let's check it another way.
690                  */
691                 LASSERTF(atomic_read(&llcd_count) == 0,
692                          "Can't destroy llcd cache! Number of "
693                          "busy llcds: %d\n", atomic_read(&llcd_count));
694                 cfs_mem_cache_destroy(llcd_cache);
695                 llcd_cache = NULL;
696         }
697 }