Whamcloud - gitweb
LU-4423 libcfs: Merge linux-proc.c into module.c
[fs/lustre-release.git] / libcfs / libcfs / module.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2012, 2015, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36 #include <linux/module.h>
37 #include <linux/kernel.h>
38 #include <linux/mm.h>
39 #include <linux/string.h>
40 #include <linux/stat.h>
41 #include <linux/errno.h>
42 #include <linux/unistd.h>
43 #include <net/sock.h>
44 #include <linux/uio.h>
45 #include <linux/uaccess.h>
46
47 #include <linux/fs.h>
48 #include <linux/file.h>
49 #include <linux/list.h>
50
51 #include <linux/sysctl.h>
52 #include <linux/proc_fs.h>
53 #include <asm/div64.h>
54
55 #define DEBUG_SUBSYSTEM S_LNET
56
57 #include <libcfs/libcfs.h>
58 #include <libcfs/libcfs_crypto.h>
59 #include <lnet/lib-lnet.h>
60 #include "tracefile.h"
61
62 #ifdef CONFIG_SYSCTL
63 static struct ctl_table_header *lnet_table_header;
64 #endif
65
66 static DECLARE_RWSEM(ioctl_list_sem);
67 static LIST_HEAD(ioctl_list);
68
69 int libcfs_register_ioctl(struct libcfs_ioctl_handler *hand)
70 {
71         int rc = 0;
72
73         down_write(&ioctl_list_sem);
74         if (!list_empty(&hand->item))
75                 rc = -EBUSY;
76         else
77                 list_add_tail(&hand->item, &ioctl_list);
78         up_write(&ioctl_list_sem);
79
80         return rc;
81 }
82 EXPORT_SYMBOL(libcfs_register_ioctl);
83
84 int libcfs_deregister_ioctl(struct libcfs_ioctl_handler *hand)
85 {
86         int rc = 0;
87
88         down_write(&ioctl_list_sem);
89         if (list_empty(&hand->item))
90                 rc = -ENOENT;
91         else
92                 list_del_init(&hand->item);
93         up_write(&ioctl_list_sem);
94
95         return rc;
96 }
97 EXPORT_SYMBOL(libcfs_deregister_ioctl);
98
99 int libcfs_ioctl(unsigned long cmd, void __user *uparam)
100 {
101         struct libcfs_ioctl_data *data = NULL;
102         struct libcfs_ioctl_hdr  *hdr;
103         int                       err;
104         ENTRY;
105
106         /* 'cmd' and permissions get checked in our arch-specific caller */
107         err = libcfs_ioctl_getdata(&hdr, uparam);
108         if (err != 0) {
109                 CDEBUG_LIMIT(D_ERROR,
110                              "libcfs ioctl: data header error %d\n", err);
111                 RETURN(err);
112         }
113
114         if (hdr->ioc_version == LIBCFS_IOCTL_VERSION) {
115                 /* The libcfs_ioctl_data_adjust() function performs adjustment
116                  * operations on the libcfs_ioctl_data structure to make
117                  * it usable by the code.  This doesn't need to be called
118                  * for new data structures added. */
119                 data = container_of(hdr, struct libcfs_ioctl_data, ioc_hdr);
120                 err = libcfs_ioctl_data_adjust(data);
121                 if (err != 0)
122                         GOTO(out, err);
123         }
124
125         CDEBUG(D_IOCTL, "libcfs ioctl cmd %lu\n", cmd);
126         switch (cmd) {
127         case IOC_LIBCFS_CLEAR_DEBUG:
128                 libcfs_debug_clear_buffer();
129                 break;
130         case IOC_LIBCFS_MARK_DEBUG:
131                 if (data == NULL ||
132                     data->ioc_inlbuf1 == NULL ||
133                     data->ioc_inlbuf1[data->ioc_inllen1 - 1] != '\0')
134                         GOTO(out, err = -EINVAL);
135
136                 libcfs_debug_mark_buffer(data->ioc_inlbuf1);
137                 break;
138
139         default: {
140                 struct libcfs_ioctl_handler *hand;
141
142                 err = -EINVAL;
143                 down_read(&ioctl_list_sem);
144                 list_for_each_entry(hand, &ioctl_list, item) {
145                         err = hand->handle_ioctl(cmd, hdr);
146                         if (err == -EINVAL)
147                                 continue;
148
149                         if (err == 0) {
150                                 if (copy_to_user(uparam, hdr, hdr->ioc_len))
151                                         err = -EFAULT;
152                         }
153                         break;
154                 }
155                 up_read(&ioctl_list_sem);
156                 break; }
157         }
158 out:
159         LIBCFS_FREE(hdr, hdr->ioc_len);
160         RETURN(err);
161 }
162
163 int
164 lprocfs_call_handler(void *data, int write, loff_t *ppos,
165                      void __user *buffer, size_t *lenp,
166                      int (*handler)(void *data, int write, loff_t pos,
167                                     void __user *buffer, int len))
168 {
169         int rc = handler(data, write, *ppos, buffer, *lenp);
170
171         if (rc < 0)
172                 return rc;
173
174         if (write) {
175                 *ppos += *lenp;
176         } else {
177                 *lenp = rc;
178                 *ppos += rc;
179         }
180         return 0;
181 }
182 EXPORT_SYMBOL(lprocfs_call_handler);
183
184 static int __proc_dobitmasks(void *data, int write,
185                              loff_t pos, void __user *buffer, int nob)
186 {
187         const int     tmpstrlen = 512;
188         char         *tmpstr;
189         int           rc;
190         unsigned int *mask = data;
191         int           is_subsys = (mask == &libcfs_subsystem_debug) ? 1 : 0;
192         int           is_printk = (mask == &libcfs_printk) ? 1 : 0;
193
194         rc = cfs_trace_allocate_string_buffer(&tmpstr, tmpstrlen);
195         if (rc < 0)
196                 return rc;
197
198         if (!write) {
199                 libcfs_debug_mask2str(tmpstr, tmpstrlen, *mask, is_subsys);
200                 rc = strlen(tmpstr);
201
202                 if (pos >= rc) {
203                         rc = 0;
204                 } else {
205                         rc = cfs_trace_copyout_string(buffer, nob,
206                                                       tmpstr + pos, "\n");
207                 }
208         } else {
209                 rc = cfs_trace_copyin_string(tmpstr, tmpstrlen, buffer, nob);
210                 if (rc < 0) {
211                         kfree(tmpstr);
212                         return rc;
213                 }
214
215                 rc = libcfs_debug_str2mask(mask, tmpstr, is_subsys);
216                 /* Always print LBUG/LASSERT to console, so keep this mask */
217                 if (is_printk)
218                         *mask |= D_EMERG;
219         }
220
221         kfree(tmpstr);
222         return rc;
223 }
224
225 static int
226 proc_dobitmasks(struct ctl_table *table, int write,
227                 void __user *buffer, size_t *lenp, loff_t *ppos)
228 {
229         return lprocfs_call_handler(table->data, write, ppos, buffer, lenp,
230                                     __proc_dobitmasks);
231 }
232
233 static int min_watchdog_ratelimit;              /* disable ratelimiting */
234 static int max_watchdog_ratelimit = (24*60*60); /* limit to once per day */
235
236 static int __proc_dump_kernel(void *data, int write,
237                               loff_t pos, void __user *buffer, int nob)
238 {
239         if (!write)
240                 return 0;
241
242         return cfs_trace_dump_debug_buffer_usrstr(buffer, nob);
243 }
244
245 static int
246 proc_dump_kernel(struct ctl_table *table, int write, void __user *buffer,
247                  size_t *lenp, loff_t *ppos)
248 {
249         return lprocfs_call_handler(table->data, write, ppos, buffer, lenp,
250                                     __proc_dump_kernel);
251 }
252
253 static int __proc_daemon_file(void *data, int write,
254                               loff_t pos, void __user *buffer, int nob)
255 {
256         if (!write) {
257                 int len = strlen(cfs_tracefile);
258
259                 if (pos >= len)
260                         return 0;
261
262                 return cfs_trace_copyout_string(buffer, nob,
263                                                 cfs_tracefile + pos, "\n");
264         }
265
266         return cfs_trace_daemon_command_usrstr(buffer, nob);
267 }
268
269 static int
270 proc_daemon_file(struct ctl_table *table, int write, void __user *buffer,
271                  size_t *lenp, loff_t *ppos)
272 {
273         return lprocfs_call_handler(table->data, write, ppos, buffer, lenp,
274                                     __proc_daemon_file);
275 }
276
277 static int __proc_debug_mb(void *data, int write,
278                            loff_t pos, void __user *buffer, int nob)
279 {
280         if (!write) {
281                 char tmpstr[32];
282                 int  len = snprintf(tmpstr, sizeof(tmpstr), "%d",
283                                     cfs_trace_get_debug_mb());
284
285                 if (pos >= len)
286                         return 0;
287
288                 return cfs_trace_copyout_string(buffer, nob, tmpstr + pos,
289                                                 "\n");
290         }
291
292         return cfs_trace_set_debug_mb_usrstr(buffer, nob);
293 }
294
295 static int
296 proc_debug_mb(struct ctl_table *table, int write, void __user *buffer,
297               size_t *lenp, loff_t *ppos)
298 {
299         return lprocfs_call_handler(table->data, write, ppos, buffer, lenp,
300                                     __proc_debug_mb);
301 }
302
303 static int
304 proc_console_max_delay_cs(struct ctl_table *table, int write,
305                           void __user *buffer, size_t *lenp, loff_t *ppos)
306 {
307         int rc, max_delay_cs;
308         struct ctl_table dummy = *table;
309         cfs_duration_t d;
310
311         dummy.data = &max_delay_cs;
312         dummy.proc_handler = &proc_dointvec;
313
314         if (!write) { /* read */
315                 max_delay_cs = cfs_duration_sec(libcfs_console_max_delay * 100);
316                 rc = proc_dointvec(&dummy, write, buffer, lenp, ppos);
317                 return rc;
318         }
319
320         /* write */
321         max_delay_cs = 0;
322         rc = proc_dointvec(&dummy, write, buffer, lenp, ppos);
323         if (rc < 0)
324                 return rc;
325         if (max_delay_cs <= 0)
326                 return -EINVAL;
327
328         d = cfs_time_seconds(max_delay_cs) / 100;
329         if (d == 0 || d < libcfs_console_min_delay)
330                 return -EINVAL;
331         libcfs_console_max_delay = d;
332
333         return rc;
334 }
335
336 static int
337 proc_console_min_delay_cs(struct ctl_table *table, int write,
338                           void __user *buffer, size_t *lenp, loff_t *ppos)
339 {
340         int rc, min_delay_cs;
341         struct ctl_table dummy = *table;
342         cfs_duration_t d;
343
344         dummy.data = &min_delay_cs;
345         dummy.proc_handler = &proc_dointvec;
346
347         if (!write) { /* read */
348                 min_delay_cs = cfs_duration_sec(libcfs_console_min_delay * 100);
349                 rc = proc_dointvec(&dummy, write, buffer, lenp, ppos);
350                 return rc;
351         }
352
353         /* write */
354         min_delay_cs = 0;
355         rc = proc_dointvec(&dummy, write, buffer, lenp, ppos);
356         if (rc < 0)
357                 return rc;
358         if (min_delay_cs <= 0)
359                 return -EINVAL;
360
361         d = cfs_time_seconds(min_delay_cs) / 100;
362         if (d == 0 || d > libcfs_console_max_delay)
363                 return -EINVAL;
364         libcfs_console_min_delay = d;
365
366         return rc;
367 }
368
369 static int
370 proc_console_backoff(struct ctl_table *table, int write, void __user *buffer,
371                      size_t *lenp, loff_t *ppos)
372 {
373         int rc, backoff;
374         struct ctl_table dummy = *table;
375
376         dummy.data = &backoff;
377         dummy.proc_handler = &proc_dointvec;
378
379         if (!write) { /* read */
380                 backoff = libcfs_console_backoff;
381                 rc = proc_dointvec(&dummy, write, buffer, lenp, ppos);
382                 return rc;
383         }
384
385         /* write */
386         backoff = 0;
387         rc = proc_dointvec(&dummy, write, buffer, lenp, ppos);
388         if (rc < 0)
389                 return rc;
390
391         if (backoff <= 0)
392                 return -EINVAL;
393
394         libcfs_console_backoff = backoff;
395
396         return rc;
397 }
398
399 static int
400 libcfs_force_lbug(struct ctl_table *table, int write, void __user *buffer,
401                   size_t *lenp, loff_t *ppos)
402 {
403         if (write)
404                 LBUG();
405         return 0;
406 }
407
408 static int
409 proc_fail_loc(struct ctl_table *table, int write, void __user *buffer,
410               size_t *lenp, loff_t *ppos)
411 {
412         int rc;
413         long old_fail_loc = cfs_fail_loc;
414
415         rc = proc_doulongvec_minmax(table, write, buffer, lenp, ppos);
416         if (old_fail_loc != cfs_fail_loc)
417                 wake_up(&cfs_race_waitq);
418         return rc;
419 }
420
421 static int __proc_cpt_table(void *data, int write,
422                             loff_t pos, void __user *buffer, int nob)
423 {
424         char *buf = NULL;
425         int   len = 4096;
426         int   rc  = 0;
427
428         if (write)
429                 return -EPERM;
430
431         LASSERT(cfs_cpt_table != NULL);
432
433         while (1) {
434                 LIBCFS_ALLOC(buf, len);
435                 if (buf == NULL)
436                         return -ENOMEM;
437
438                 rc = cfs_cpt_table_print(cfs_cpt_table, buf, len);
439                 if (rc >= 0)
440                         break;
441
442                 if (rc == -EFBIG) {
443                         LIBCFS_FREE(buf, len);
444                         len <<= 1;
445                         continue;
446                 }
447                 goto out;
448         }
449
450         if (pos >= rc) {
451                 rc = 0;
452                 goto out;
453         }
454
455         rc = cfs_trace_copyout_string(buffer, nob, buf + pos, NULL);
456 out:
457         if (buf != NULL)
458                 LIBCFS_FREE(buf, len);
459         return rc;
460 }
461
462 static int
463 proc_cpt_table(struct ctl_table *table, int write, void __user *buffer,
464                size_t *lenp, loff_t *ppos)
465 {
466         return lprocfs_call_handler(table->data, write, ppos, buffer, lenp,
467                                     __proc_cpt_table);
468 }
469
470 static struct ctl_table lnet_table[] = {
471         /*
472          * NB No .strategy entries have been provided since sysctl(8) prefers
473          * to go via /proc for portability.
474          */
475         {
476                 INIT_CTL_NAME
477                 .procname       = "debug",
478                 .data           = &libcfs_debug,
479                 .maxlen         = sizeof(int),
480                 .mode           = 0644,
481                 .proc_handler   = &proc_dobitmasks,
482         },
483         {
484                 INIT_CTL_NAME
485                 .procname       = "subsystem_debug",
486                 .data           = &libcfs_subsystem_debug,
487                 .maxlen         = sizeof(int),
488                 .mode           = 0644,
489                 .proc_handler   = &proc_dobitmasks,
490         },
491         {
492                 INIT_CTL_NAME
493                 .procname       = "printk",
494                 .data           = &libcfs_printk,
495                 .maxlen         = sizeof(int),
496                 .mode           = 0644,
497                 .proc_handler   = &proc_dobitmasks,
498         },
499         {
500                 INIT_CTL_NAME
501                 .procname       = "console_ratelimit",
502                 .data           = &libcfs_console_ratelimit,
503                 .maxlen         = sizeof(int),
504                 .mode           = 0644,
505                 .proc_handler   = &proc_dointvec
506         },
507         {
508                 INIT_CTL_NAME
509                 .procname       = "console_max_delay_centisecs",
510                 .maxlen         = sizeof(int),
511                 .mode           = 0644,
512                 .proc_handler   = &proc_console_max_delay_cs
513         },
514         {
515                 INIT_CTL_NAME
516                 .procname       = "console_min_delay_centisecs",
517                 .maxlen         = sizeof(int),
518                 .mode           = 0644,
519                 .proc_handler   = &proc_console_min_delay_cs
520         },
521         {
522                 INIT_CTL_NAME
523                 .procname       = "console_backoff",
524                 .maxlen         = sizeof(int),
525                 .mode           = 0644,
526                 .proc_handler   = &proc_console_backoff
527         },
528         {
529                 INIT_CTL_NAME
530                 .procname       = "debug_path",
531                 .data           = libcfs_debug_file_path_arr,
532                 .maxlen         = sizeof(libcfs_debug_file_path_arr),
533                 .mode           = 0644,
534                 .proc_handler   = &proc_dostring,
535         },
536         {
537                 INIT_CTL_NAME
538                 .procname       = "cpu_partition_table",
539                 .maxlen         = 128,
540                 .mode           = 0444,
541                 .proc_handler   = &proc_cpt_table,
542         },
543         {
544                 INIT_CTL_NAME
545                 .procname       = "upcall",
546                 .data           = lnet_upcall,
547                 .maxlen         = sizeof(lnet_upcall),
548                 .mode           = 0644,
549                 .proc_handler   = &proc_dostring,
550         },
551         {
552                 INIT_CTL_NAME
553                 .procname       = "debug_log_upcall",
554                 .data           = lnet_debug_log_upcall,
555                 .maxlen         = sizeof(lnet_debug_log_upcall),
556                 .mode           = 0644,
557                 .proc_handler   = &proc_dostring,
558         },
559         {
560                 INIT_CTL_NAME
561                 .procname       = "lnet_memused",
562                 .data           = (int *)&libcfs_kmemory.counter,
563                 .maxlen         = sizeof(int),
564                 .mode           = 0444,
565                 .proc_handler   = &proc_dointvec,
566         },
567         {
568                 INIT_CTL_NAME
569                 .procname       = "catastrophe",
570                 .data           = &libcfs_catastrophe,
571                 .maxlen         = sizeof(int),
572                 .mode           = 0444,
573                 .proc_handler   = &proc_dointvec,
574         },
575         {
576                 INIT_CTL_NAME
577                 .procname       = "panic_on_lbug",
578                 .data           = &libcfs_panic_on_lbug,
579                 .maxlen         = sizeof(int),
580                 .mode           = 0644,
581                 .proc_handler   = &proc_dointvec,
582         },
583         {
584                 INIT_CTL_NAME
585                 .procname       = "dump_kernel",
586                 .maxlen         = 256,
587                 .mode           = 0200,
588                 .proc_handler   = &proc_dump_kernel,
589         },
590         {
591                 INIT_CTL_NAME
592                 .procname       = "daemon_file",
593                 .mode           = 0644,
594                 .maxlen         = 256,
595                 .proc_handler   = &proc_daemon_file,
596         },
597         {
598                 INIT_CTL_NAME
599                 .procname       = "debug_mb",
600                 .mode           = 0644,
601                 .proc_handler   = &proc_debug_mb,
602         },
603         {
604                 INIT_CTL_NAME
605                 .procname       = "watchdog_ratelimit",
606                 .data           = &libcfs_watchdog_ratelimit,
607                 .maxlen         = sizeof(int),
608                 .mode           = 0644,
609                 .proc_handler   = &proc_dointvec_minmax,
610                 .extra1         = &min_watchdog_ratelimit,
611                 .extra2         = &max_watchdog_ratelimit,
612         },
613         {
614                 INIT_CTL_NAME
615                 .procname       = "force_lbug",
616                 .data           = NULL,
617                 .maxlen         = 0,
618                 .mode           = 0200,
619                 .proc_handler   = &libcfs_force_lbug
620         },
621         {
622                 INIT_CTL_NAME
623                 .procname       = "fail_loc",
624                 .data           = &cfs_fail_loc,
625                 .maxlen         = sizeof(cfs_fail_loc),
626                 .mode           = 0644,
627                 .proc_handler   = &proc_fail_loc
628         },
629         {
630                 INIT_CTL_NAME
631                 .procname       = "fail_val",
632                 .data           = &cfs_fail_val,
633                 .maxlen         = sizeof(int),
634                 .mode           = 0644,
635                 .proc_handler   = &proc_dointvec
636         },
637         {
638                 INIT_CTL_NAME
639                 .procname       = "fail_err",
640                 .data           = &cfs_fail_err,
641                 .maxlen         = sizeof(cfs_fail_err),
642                 .mode           = 0644,
643                 .proc_handler   = &proc_dointvec,
644         },
645         {
646         }
647 };
648
649 #ifdef CONFIG_SYSCTL
650 static struct ctl_table top_table[] = {
651         {
652                 INIT_CTL_NAME
653                 .procname       = "lnet",
654                 .mode           = 0555,
655                 .data           = NULL,
656                 .maxlen         = 0,
657                 .child          = lnet_table,
658         },
659         { 0 }
660 };
661 #endif
662
663 static int insert_proc(void)
664 {
665 #ifdef CONFIG_SYSCTL
666         if (lnet_table_header == NULL)
667                 lnet_table_header = register_sysctl_table(top_table);
668 #endif
669         return 0;
670 }
671
672 static void remove_proc(void)
673 {
674 #ifdef CONFIG_SYSCTL
675         if (lnet_table_header != NULL)
676                 unregister_sysctl_table(lnet_table_header);
677
678         lnet_table_header = NULL;
679 #endif
680 }
681
682 static int __init libcfs_init(void)
683 {
684         int rc;
685
686         rc = libcfs_debug_init(5 * 1024 * 1024);
687         if (rc < 0) {
688                 printk(KERN_ERR "LustreError: libcfs_debug_init: %d\n", rc);
689                 return (rc);
690         }
691
692         rc = cfs_cpu_init();
693         if (rc != 0)
694                 goto cleanup_debug;
695
696         rc = misc_register(&libcfs_dev);
697         if (rc) {
698                 CERROR("misc_register: error %d\n", rc);
699                 goto cleanup_cpu;
700         }
701
702         rc = cfs_wi_startup();
703         if (rc) {
704                 CERROR("initialize workitem: error %d\n", rc);
705                 goto cleanup_deregister;
706         }
707
708         /* max to 4 threads, should be enough for rehash */
709         rc = min(cfs_cpt_weight(cfs_cpt_table, CFS_CPT_ANY), 4);
710         rc = cfs_wi_sched_create("cfs_rh", cfs_cpt_table, CFS_CPT_ANY,
711                                  rc, &cfs_sched_rehash);
712         if (rc != 0) {
713                 CERROR("Startup workitem scheduler: error: %d\n", rc);
714                 goto cleanup_deregister;
715         }
716
717         rc = cfs_crypto_register();
718         if (rc) {
719                 CERROR("cfs_crypto_regster: error %d\n", rc);
720                 goto cleanup_wi;
721         }
722
723
724         rc = insert_proc();
725         if (rc) {
726                 CERROR("insert_proc: error %d\n", rc);
727                 goto cleanup_crypto;
728         }
729
730         CDEBUG (D_OTHER, "portals setup OK\n");
731         return 0;
732 cleanup_crypto:
733         cfs_crypto_unregister();
734 cleanup_wi:
735         cfs_wi_shutdown();
736 cleanup_deregister:
737         misc_deregister(&libcfs_dev);
738 cleanup_cpu:
739         cfs_cpu_fini();
740 cleanup_debug:
741         libcfs_debug_cleanup();
742         return rc;
743 }
744
745 static void __exit libcfs_exit(void)
746 {
747         int rc;
748
749         remove_proc();
750
751         CDEBUG(D_MALLOC, "before Portals cleanup: kmem %d\n",
752                atomic_read(&libcfs_kmemory));
753
754         if (cfs_sched_rehash != NULL) {
755                 cfs_wi_sched_destroy(cfs_sched_rehash);
756                 cfs_sched_rehash = NULL;
757         }
758
759         cfs_crypto_unregister();
760         cfs_wi_shutdown();
761
762         misc_deregister(&libcfs_dev);
763
764         cfs_cpu_fini();
765
766         if (atomic_read(&libcfs_kmemory) != 0)
767                 CERROR("Portals memory leaked: %d bytes\n",
768                        atomic_read(&libcfs_kmemory));
769
770         rc = libcfs_debug_cleanup();
771         if (rc)
772                 printk(KERN_ERR "LustreError: libcfs_debug_cleanup: %d\n",
773                        rc);
774 }
775
776 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
777 MODULE_DESCRIPTION("Lustre helper library");
778 MODULE_VERSION(LIBCFS_VERSION);
779 MODULE_LICENSE("GPL");
780
781 module_init(libcfs_init);
782 module_exit(libcfs_exit);