Whamcloud - gitweb
17b0b9fb817098d282542ead7c0e3b2c35fae588
[fs/lustre-release.git] / lustre / obdclass / class_obd.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.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2011, 2015, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  * Lustre is a trademark of Sun Microsystems, Inc.
31  */
32
33 #define DEBUG_SUBSYSTEM S_CLASS
34
35 #include <linux/user_namespace.h>
36 #ifdef HAVE_UIDGID_HEADER
37 # include <linux/uidgid.h>
38 #endif
39 #include <linux/atomic.h>
40 #include <linux/list.h>
41
42 #include <obd_support.h>
43 #include <obd_class.h>
44 #include <lnet/lnetctl.h>
45 #include <lustre_debug.h>
46 #include <lustre_kernelcomm.h>
47 #include <lprocfs_status.h>
48 #include <lustre_ver.h>
49 #include <cl_object.h>
50 #ifdef HAVE_SERVER_SUPPORT
51 # include <dt_object.h>
52 # include <md_object.h>
53 #endif /* HAVE_SERVER_SUPPORT */
54 #include <uapi/linux/lustre_ioctl.h>
55 #include "llog_internal.h"
56
57 #ifdef CONFIG_PROC_FS
58 static __u64 obd_max_alloc;
59 #else
60 __u64 obd_max_alloc;
61 #endif
62
63 static DEFINE_SPINLOCK(obd_updatemax_lock);
64
65 /* The following are visible and mutable through /proc/sys/lustre/. */
66 unsigned int obd_debug_peer_on_timeout;
67 EXPORT_SYMBOL(obd_debug_peer_on_timeout);
68 unsigned int obd_dump_on_timeout;
69 EXPORT_SYMBOL(obd_dump_on_timeout);
70 unsigned int obd_dump_on_eviction;
71 EXPORT_SYMBOL(obd_dump_on_eviction);
72 unsigned long obd_max_dirty_pages;
73 EXPORT_SYMBOL(obd_max_dirty_pages);
74 atomic_long_t obd_dirty_pages;
75 EXPORT_SYMBOL(obd_dirty_pages);
76 unsigned int obd_timeout = OBD_TIMEOUT_DEFAULT;   /* seconds */
77 EXPORT_SYMBOL(obd_timeout);
78 unsigned int ldlm_timeout = LDLM_TIMEOUT_DEFAULT; /* seconds */
79 EXPORT_SYMBOL(ldlm_timeout);
80 unsigned int obd_timeout_set;
81 EXPORT_SYMBOL(obd_timeout_set);
82 unsigned int ldlm_timeout_set;
83 EXPORT_SYMBOL(ldlm_timeout_set);
84 /* bulk transfer timeout, give up after 100s by default */
85 unsigned int bulk_timeout = 100; /* seconds */
86 EXPORT_SYMBOL(bulk_timeout);
87 /* Adaptive timeout defs here instead of ptlrpc module for /proc/sys/ access */
88 unsigned int at_min = 0;
89 EXPORT_SYMBOL(at_min);
90 unsigned int at_max = 600;
91 EXPORT_SYMBOL(at_max);
92 unsigned int at_history = 600;
93 EXPORT_SYMBOL(at_history);
94 int at_early_margin = 5;
95 EXPORT_SYMBOL(at_early_margin);
96 int at_extra = 30;
97 EXPORT_SYMBOL(at_extra);
98
99 atomic_long_t obd_dirty_transit_pages;
100 EXPORT_SYMBOL(obd_dirty_transit_pages);
101
102 char obd_jobid_var[JOBSTATS_JOBID_VAR_MAX_LEN + 1] = JOBSTATS_DISABLE;
103
104 #ifdef CONFIG_PROC_FS
105 struct lprocfs_stats *obd_memory = NULL;
106 EXPORT_SYMBOL(obd_memory);
107 #endif
108
109 char obd_jobid_node[LUSTRE_JOBID_SIZE + 1];
110
111 /* Get jobid of current process by reading the environment variable
112  * stored in between the "env_start" & "env_end" of task struct.
113  *
114  * TODO:
115  * It's better to cache the jobid for later use if there is any
116  * efficient way, the cl_env code probably could be reused for this
117  * purpose.
118  *
119  * If some job scheduler doesn't store jobid in the "env_start/end",
120  * then an upcall could be issued here to get the jobid by utilizing
121  * the userspace tools/api. Then, the jobid must be cached.
122  */
123 int lustre_get_jobid(char *jobid)
124 {
125         int jobid_len = LUSTRE_JOBID_SIZE;
126         char tmp_jobid[LUSTRE_JOBID_SIZE] = { 0 };
127         int rc = 0;
128         ENTRY;
129
130         /* Jobstats isn't enabled */
131         if (strcmp(obd_jobid_var, JOBSTATS_DISABLE) == 0)
132                 GOTO(out, rc = 0);
133
134         /* Whole node dedicated to single job */
135         if (strcmp(obd_jobid_var, JOBSTATS_NODELOCAL) == 0) {
136                 memcpy(tmp_jobid, obd_jobid_node, LUSTRE_JOBID_SIZE);
137                 GOTO(out, rc = 0);
138         }
139
140         /* Use process name + fsuid as jobid */
141         if (strcmp(obd_jobid_var, JOBSTATS_PROCNAME_UID) == 0) {
142                 snprintf(tmp_jobid, LUSTRE_JOBID_SIZE, "%s.%u",
143                          current_comm(),
144                          from_kuid(&init_user_ns, current_fsuid()));
145                 GOTO(out, rc = 0);
146         }
147
148         rc = cfs_get_environ(obd_jobid_var, tmp_jobid, &jobid_len);
149         if (rc) {
150                 if (rc == -EOVERFLOW) {
151                         /* For the PBS_JOBID and LOADL_STEP_ID keys (which are
152                          * variable length strings instead of just numbers), it
153                          * might make sense to keep the unique parts for JobID,
154                          * instead of just returning an error.  That means a
155                          * larger temp buffer for cfs_get_environ(), then
156                          * truncating the string at some separator to fit into
157                          * the specified jobid_len.  Fix later if needed. */
158                         static bool printed;
159                         if (unlikely(!printed)) {
160                                 LCONSOLE_ERROR_MSG(0x16b, "%s value too large "
161                                                    "for JobID buffer (%d)\n",
162                                                    obd_jobid_var, jobid_len);
163                                 printed = true;
164                         }
165                 } else {
166                         CDEBUG((rc == -ENOENT || rc == -EINVAL ||
167                                 rc == -EDEADLK) ? D_INFO : D_ERROR,
168                                "Get jobid for (%s) failed: rc = %d\n",
169                                obd_jobid_var, rc);
170                 }
171         }
172
173 out:
174         if (rc != 0)
175                 RETURN(rc);
176
177         /* Only replace the job ID if it changed. */
178         if (strcmp(jobid, tmp_jobid) != 0)
179                 memcpy(jobid, tmp_jobid, jobid_len);
180
181         RETURN(0);
182 }
183 EXPORT_SYMBOL(lustre_get_jobid);
184
185 static int class_resolve_dev_name(__u32 len, const char *name)
186 {
187         int rc;
188         int dev;
189
190         ENTRY;
191         if (!len || !name) {
192                 CERROR("No name passed,!\n");
193                 GOTO(out, rc = -EINVAL);
194         }
195         if (name[len - 1] != 0) {
196                 CERROR("Name not nul terminated!\n");
197                 GOTO(out, rc = -EINVAL);
198         }
199
200         CDEBUG(D_IOCTL, "device name %s\n", name);
201         dev = class_name2dev(name);
202         if (dev == -1) {
203                 CDEBUG(D_IOCTL, "No device for name %s!\n", name);
204                 GOTO(out, rc = -EINVAL);
205         }
206
207         CDEBUG(D_IOCTL, "device name %s, dev %d\n", name, dev);
208         rc = dev;
209
210 out:
211         RETURN(rc);
212 }
213
214 int class_handle_ioctl(unsigned int cmd, unsigned long arg)
215 {
216         char *buf = NULL;
217         struct obd_ioctl_data *data;
218         struct libcfs_debug_ioctl_data *debug_data;
219         struct obd_device *obd = NULL;
220         int err = 0, len = 0;
221         ENTRY;
222
223         /* only for debugging */
224         if (cmd == LIBCFS_IOC_DEBUG_MASK) {
225                 debug_data = (struct libcfs_debug_ioctl_data*)arg;
226                 libcfs_subsystem_debug = debug_data->subs;
227                 libcfs_debug = debug_data->debug;
228                 return 0;
229         }
230
231         CDEBUG(D_IOCTL, "cmd = %x\n", cmd);
232         if (obd_ioctl_getdata(&buf, &len, (void __user *)arg)) {
233                 CERROR("OBD ioctl: data error\n");
234                 RETURN(-EINVAL);
235         }
236         data = (struct obd_ioctl_data *)buf;
237
238         switch (cmd) {
239         case OBD_IOC_PROCESS_CFG: {
240                 struct lustre_cfg *lcfg;
241
242                 if (!data->ioc_plen1 || !data->ioc_pbuf1) {
243                         CERROR("No config buffer passed!\n");
244                         GOTO(out, err = -EINVAL);
245                 }
246                 OBD_ALLOC(lcfg, data->ioc_plen1);
247                 if (lcfg == NULL)
248                         GOTO(out, err = -ENOMEM);
249                 err = copy_from_user(lcfg, data->ioc_pbuf1,
250                                          data->ioc_plen1);
251                 if (!err)
252                         err = lustre_cfg_sanity_check(lcfg, data->ioc_plen1);
253                 if (!err)
254                         err = class_process_config(lcfg);
255
256                 OBD_FREE(lcfg, data->ioc_plen1);
257                 GOTO(out, err);
258         }
259
260         case OBD_GET_VERSION:
261                 if (!data->ioc_inlbuf1) {
262                         CERROR("No buffer passed in ioctl\n");
263                         GOTO(out, err = -EINVAL);
264                 }
265
266                 if (strlen(LUSTRE_VERSION_STRING) + 1 > data->ioc_inllen1) {
267                         CERROR("ioctl buffer too small to hold version\n");
268                         GOTO(out, err = -EINVAL);
269                 }
270
271                 memcpy(data->ioc_bulk, LUSTRE_VERSION_STRING,
272                        strlen(LUSTRE_VERSION_STRING) + 1);
273
274                 if (copy_to_user((void __user *)arg, data, len))
275                         err = -EFAULT;
276                 GOTO(out, err);
277
278         case OBD_IOC_NAME2DEV: {
279                 /* Resolve a device name.  This does not change the
280                  * currently selected device.
281                  */
282                 int dev;
283
284                 dev = class_resolve_dev_name(data->ioc_inllen1,
285                                              data->ioc_inlbuf1);
286                 data->ioc_dev = dev;
287                 if (dev < 0)
288                         GOTO(out, err = -EINVAL);
289
290                 if (copy_to_user((void __user *)arg, data, sizeof(*data)))
291                         err = -EFAULT;
292                 GOTO(out, err);
293         }
294
295         case OBD_IOC_UUID2DEV: {
296                 /* Resolve a device uuid.  This does not change the
297                  * currently selected device.
298                  */
299                 int dev;
300                 struct obd_uuid uuid;
301
302                 if (!data->ioc_inllen1 || !data->ioc_inlbuf1) {
303                         CERROR("No UUID passed!\n");
304                         GOTO(out, err = -EINVAL);
305                 }
306                 if (data->ioc_inlbuf1[data->ioc_inllen1 - 1] != 0) {
307                         CERROR("UUID not NUL terminated!\n");
308                         GOTO(out, err = -EINVAL);
309                 }
310
311                 CDEBUG(D_IOCTL, "device name %s\n", data->ioc_inlbuf1);
312                 obd_str2uuid(&uuid, data->ioc_inlbuf1);
313                 dev = class_uuid2dev(&uuid);
314                 data->ioc_dev = dev;
315                 if (dev == -1) {
316                         CDEBUG(D_IOCTL, "No device for UUID %s!\n",
317                                data->ioc_inlbuf1);
318                         GOTO(out, err = -EINVAL);
319                 }
320
321                 CDEBUG(D_IOCTL, "device name %s, dev %d\n", data->ioc_inlbuf1,
322                        dev);
323                 if (copy_to_user((void __user *)arg, data, sizeof(*data)))
324                         err = -EFAULT;
325                 GOTO(out, err);
326         }
327
328         case OBD_IOC_GETDEVICE: {
329                 int     index = data->ioc_count;
330                 char    *status, *str;
331
332                 if (!data->ioc_inlbuf1) {
333                         CERROR("No buffer passed in ioctl\n");
334                         GOTO(out, err = -EINVAL);
335                 }
336                 if (data->ioc_inllen1 < 128) {
337                         CERROR("ioctl buffer too small to hold version\n");
338                         GOTO(out, err = -EINVAL);
339                 }
340
341                 obd = class_num2obd(index);
342                 if (!obd)
343                         GOTO(out, err = -ENOENT);
344
345                 if (obd->obd_stopping)
346                         status = "ST";
347                 else if (obd->obd_set_up)
348                         status = "UP";
349                 else if (obd->obd_attached)
350                         status = "AT";
351                 else
352                         status = "--";
353                 str = (char *)data->ioc_bulk;
354                 snprintf(str, len - sizeof(*data), "%3d %s %s %s %s %d",
355                          (int)index, status, obd->obd_type->typ_name,
356                          obd->obd_name, obd->obd_uuid.uuid,
357                          atomic_read(&obd->obd_refcount));
358
359                 if (copy_to_user((void __user *)arg, data, len))
360                         err = -EFAULT;
361
362                 GOTO(out, err);
363         }
364
365         }
366
367         if (data->ioc_dev == OBD_DEV_BY_DEVNAME) {
368                 if (data->ioc_inllen4 <= 0 || data->ioc_inlbuf4 == NULL)
369                         GOTO(out, err = -EINVAL);
370                 if (strnlen(data->ioc_inlbuf4, MAX_OBD_NAME) >= MAX_OBD_NAME)
371                         GOTO(out, err = -EINVAL);
372                 obd = class_name2obd(data->ioc_inlbuf4);
373         } else if (data->ioc_dev < class_devno_max()) {
374                 obd = class_num2obd(data->ioc_dev);
375         } else {
376                 CERROR("OBD ioctl: No device\n");
377                 GOTO(out, err = -EINVAL);
378         }
379
380         if (obd == NULL) {
381                 CERROR("OBD ioctl : No Device %d\n", data->ioc_dev);
382                 GOTO(out, err = -EINVAL);
383         }
384         LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
385
386         if (!obd->obd_set_up || obd->obd_stopping) {
387                 CERROR("OBD ioctl: device not setup %d \n", data->ioc_dev);
388                 GOTO(out, err = -EINVAL);
389         }
390
391         switch(cmd) {
392         case OBD_IOC_NO_TRANSNO: {
393                 if (!obd->obd_attached) {
394                         CERROR("Device %d not attached\n", obd->obd_minor);
395                         GOTO(out, err = -ENODEV);
396                 }
397                 CDEBUG(D_HA, "%s: disabling committed-transno notification\n",
398                        obd->obd_name);
399                 obd->obd_no_transno = 1;
400                 GOTO(out, err = 0);
401         }
402
403         default: {
404                 err = obd_iocontrol(cmd, obd->obd_self_export, len, data, NULL);
405                 if (err)
406                         GOTO(out, err);
407
408                 if (copy_to_user((void __user *)arg, data, len))
409                         err = -EFAULT;
410                 GOTO(out, err);
411         }
412         }
413
414 out:
415         OBD_FREE_LARGE(buf, len);
416         RETURN(err);
417 } /* class_handle_ioctl */
418
419 #define OBD_INIT_CHECK
420 #ifdef OBD_INIT_CHECK
421 static int obd_init_checks(void)
422 {
423         __u64 u64val, div64val;
424         char buf[64];
425         int len, ret = 0;
426
427         CDEBUG(D_INFO, "OBD_OBJECT_EOF = %#llx\n", (__u64)OBD_OBJECT_EOF);
428
429         u64val = OBD_OBJECT_EOF;
430         CDEBUG(D_INFO, "u64val OBD_OBJECT_EOF = %#llx\n", u64val);
431         if (u64val != OBD_OBJECT_EOF) {
432                 CERROR("__u64 %#llx(%d) != 0xffffffffffffffff\n",
433                        u64val, (int)sizeof(u64val));
434                 ret = -EINVAL;
435         }
436         len = snprintf(buf, sizeof(buf), "%#llx", u64val);
437         if (len != 18) {
438                 CWARN("u64 hex wrong length! strlen(%s)=%d != 18\n", buf, len);
439                 ret = -EINVAL;
440         }
441
442         div64val = OBD_OBJECT_EOF;
443         CDEBUG(D_INFO, "u64val OBD_OBJECT_EOF = %#llx\n", u64val);
444         if (u64val != OBD_OBJECT_EOF) {
445                 CERROR("__u64 %#llx(%d) != 0xffffffffffffffff\n",
446                        u64val, (int)sizeof(u64val));
447                 ret = -EOVERFLOW;
448         }
449         if (u64val >> 8 != OBD_OBJECT_EOF >> 8) {
450                 CERROR("__u64 %#llx(%d) != 0xffffffffffffffff\n",
451                        u64val, (int)sizeof(u64val));
452                 return -EOVERFLOW;
453         }
454         if (do_div(div64val, 256) != (u64val & 255)) {
455                 CERROR("do_div(%#llx,256) != %llu\n", u64val, u64val & 255);
456                 return -EOVERFLOW;
457         }
458         if (u64val >> 8 != div64val) {
459                 CERROR("do_div(%#llx,256) %llu != %llu\n",
460                        u64val, div64val, u64val >> 8);
461                 return -EOVERFLOW;
462         }
463         len = snprintf(buf, sizeof(buf), "%#llx", u64val);
464         if (len != 18) {
465                 CWARN("u64 hex wrong length! strlen(%s)=%d != 18\n", buf, len);
466                 ret = -EINVAL;
467         }
468         len = snprintf(buf, sizeof(buf), "%llu", u64val);
469         if (len != 20) {
470                 CWARN("u64 wrong length! strlen(%s)=%d != 20\n", buf, len);
471                 ret = -EINVAL;
472         }
473         len = snprintf(buf, sizeof(buf), "%lld", u64val);
474         if (len != 2) {
475                 CWARN("s64 wrong length! strlen(%s)=%d != 2\n", buf, len);
476                 ret = -EINVAL;
477         }
478         if ((u64val & ~PAGE_MASK) >= PAGE_SIZE) {
479                 CWARN("mask failed: u64val %llu >= %llu\n", u64val,
480                       (__u64)PAGE_SIZE);
481                 ret = -EINVAL;
482         }
483
484         return ret;
485 }
486 #else
487 #define obd_init_checks() do {} while(0)
488 #endif
489
490 static int __init obdclass_init(void)
491 {
492         int err;
493
494         LCONSOLE_INFO("Lustre: Build Version: "LUSTRE_VERSION_STRING"\n");
495
496         libcfs_kkuc_init();
497
498         err = obd_init_checks();
499         if (err == -EOVERFLOW)
500                 return err;
501
502 #ifdef CONFIG_PROC_FS
503         obd_memory = lprocfs_alloc_stats(OBD_STATS_NUM,
504                                          LPROCFS_STATS_FLAG_NONE |
505                                          LPROCFS_STATS_FLAG_IRQ_SAFE);
506         if (obd_memory == NULL) {
507                 CERROR("kmalloc of 'obd_memory' failed\n");
508                 return -ENOMEM;
509         }
510
511         lprocfs_counter_init(obd_memory, OBD_MEMORY_STAT,
512                              LPROCFS_CNTR_AVGMINMAX,
513                              "memused", "bytes");
514 #endif
515         err = obd_zombie_impexp_init();
516         if (err)
517                 goto cleanup_obd_memory;
518
519         err = class_handle_init();
520         if (err)
521                 goto cleanup_zombie_impexp;
522
523         err = misc_register(&obd_psdev);
524         if (err) {
525                 CERROR("cannot register %d err %d\n", OBD_DEV_MINOR, err);
526                 goto cleanup_class_handle;
527         }
528
529         /* Default the dirty page cache cap to 1/2 of system memory.
530          * For clients with less memory, a larger fraction is needed
531          * for other purposes (mostly for BGL). */
532         if (totalram_pages <= 512 << (20 - PAGE_SHIFT))
533                 obd_max_dirty_pages = totalram_pages / 4;
534         else
535                 obd_max_dirty_pages = totalram_pages / 2;
536
537         err = obd_init_caches();
538         if (err)
539                 goto cleanup_deregister;
540
541         err = class_procfs_init();
542         if (err)
543                 goto cleanup_caches;
544
545         err = lu_global_init();
546         if (err)
547                 goto cleanup_class_procfs;
548
549         err = cl_global_init();
550         if (err != 0)
551                 goto cleanup_lu_global;
552
553 #ifdef HAVE_SERVER_SUPPORT
554         err = dt_global_init();
555         if (err != 0)
556                 goto cleanup_cl_global;
557
558         err = lu_ucred_global_init();
559         if (err != 0)
560                 goto cleanup_dt_global;
561 #endif /* HAVE_SERVER_SUPPORT */
562
563         err = llog_info_init();
564         if (err)
565 #ifdef HAVE_SERVER_SUPPORT
566                 goto cleanup_lu_ucred_global;
567 #else /* !HAVE_SERVER_SUPPORT */
568                 goto cleanup_cl_global;
569 #endif /* HAVE_SERVER_SUPPORT */
570
571         err = lustre_register_fs();
572
573         /* simulate a late OOM situation now to require all
574          * alloc'ed/initialized resources to be freed */
575         if (OBD_FAIL_CHECK(OBD_FAIL_OBDCLASS_MODULE_LOAD)) {
576                 /* fake error but filesystem has been registered */
577                 lustre_unregister_fs();
578                 /* force error to ensure module will be unloaded/cleaned */
579                 err = -ENOMEM;
580         }
581
582         if (err)
583                 goto cleanup_llog_info;
584
585         return 0;
586
587 cleanup_llog_info:
588         llog_info_fini();
589
590 #ifdef HAVE_SERVER_SUPPORT
591 cleanup_lu_ucred_global:
592         lu_ucred_global_fini();
593
594 cleanup_dt_global:
595         dt_global_fini();
596 #endif /* HAVE_SERVER_SUPPORT */
597
598 cleanup_cl_global:
599         cl_global_fini();
600
601 cleanup_lu_global:
602         lu_global_fini();
603
604 cleanup_class_procfs:
605         obd_sysctl_clean();
606         class_procfs_clean();
607
608 cleanup_caches:
609         obd_cleanup_caches();
610
611 cleanup_deregister:
612         misc_deregister(&obd_psdev);
613
614 cleanup_class_handle:
615         class_handle_cleanup();
616
617 cleanup_zombie_impexp:
618         obd_zombie_impexp_stop();
619
620 cleanup_obd_memory:
621 #ifdef CONFIG_PROC_FS
622         lprocfs_free_stats(&obd_memory);
623 #endif
624
625         return err;
626 }
627
628 void obd_update_maxusage(void)
629 {
630         __u64 max;
631
632         max = obd_memory_sum();
633
634         spin_lock(&obd_updatemax_lock);
635         if (max > obd_max_alloc)
636                 obd_max_alloc = max;
637         spin_unlock(&obd_updatemax_lock);
638 }
639 EXPORT_SYMBOL(obd_update_maxusage);
640
641 #ifdef CONFIG_PROC_FS
642 __u64 obd_memory_max(void)
643 {
644         __u64 ret;
645
646         obd_update_maxusage();
647         spin_lock(&obd_updatemax_lock);
648         ret = obd_max_alloc;
649         spin_unlock(&obd_updatemax_lock);
650
651         return ret;
652 }
653 #endif /* CONFIG_PROC_FS */
654
655 static void __exit obdclass_exit(void)
656 {
657 #ifdef CONFIG_PROC_FS
658         __u64 memory_leaked;
659         __u64 memory_max;
660 #endif /* CONFIG_PROC_FS */
661         ENTRY;
662
663         lustre_unregister_fs();
664
665         misc_deregister(&obd_psdev);
666         llog_info_fini();
667 #ifdef HAVE_SERVER_SUPPORT
668         lu_ucred_global_fini();
669         dt_global_fini();
670 #endif /* HAVE_SERVER_SUPPORT */
671         cl_global_fini();
672         lu_global_fini();
673
674         obd_cleanup_caches();
675         obd_sysctl_clean();
676
677         class_procfs_clean();
678
679         class_handle_cleanup();
680         class_del_uuid(NULL); /* Delete all UUIDs. */
681         obd_zombie_impexp_stop();
682
683 #ifdef CONFIG_PROC_FS
684         memory_leaked = obd_memory_sum();
685         memory_max = obd_memory_max();
686
687         lprocfs_free_stats(&obd_memory);
688         CDEBUG((memory_leaked) ? D_ERROR : D_INFO,
689                "obd_memory max: %llu, leaked: %llu\n",
690                memory_max, memory_leaked);
691 #endif /* CONFIG_PROC_FS */
692
693         EXIT;
694 }
695
696 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
697 MODULE_DESCRIPTION("Lustre Class Driver");
698 MODULE_VERSION(LUSTRE_VERSION_STRING);
699 MODULE_LICENSE("GPL");
700
701 module_init(obdclass_init);
702 module_exit(obdclass_exit);