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