Whamcloud - gitweb
LU-5969 obdclass: deprecate OBD_GET_VERSION ioctl
[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 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 53, 0)
261         case OBD_GET_VERSION: {
262                 static bool warned;
263
264                 if (!data->ioc_inlbuf1) {
265                         CERROR("No buffer passed in ioctl\n");
266                         GOTO(out, err = -EINVAL);
267                 }
268
269                 if (strlen(LUSTRE_VERSION_STRING) + 1 > data->ioc_inllen1) {
270                         CERROR("ioctl buffer too small to hold version\n");
271                         GOTO(out, err = -EINVAL);
272                 }
273
274                 if (!warned) {
275                         warned = true;
276                         CWARN("%s: ioctl(OBD_GET_VERSION) is deprecated, "
277                               "use llapi_get_version_string() and/or relink\n",
278                               current->comm);
279                 }
280                 memcpy(data->ioc_bulk, LUSTRE_VERSION_STRING,
281                        strlen(LUSTRE_VERSION_STRING) + 1);
282
283                 if (copy_to_user((void __user *)arg, data, len))
284                         err = -EFAULT;
285                 GOTO(out, err);
286         }
287 #endif
288         case OBD_IOC_NAME2DEV: {
289                 /* Resolve a device name.  This does not change the
290                  * currently selected device.
291                  */
292                 int dev;
293
294                 dev = class_resolve_dev_name(data->ioc_inllen1,
295                                              data->ioc_inlbuf1);
296                 data->ioc_dev = dev;
297                 if (dev < 0)
298                         GOTO(out, err = -EINVAL);
299
300                 if (copy_to_user((void __user *)arg, data, sizeof(*data)))
301                         err = -EFAULT;
302                 GOTO(out, err);
303         }
304
305         case OBD_IOC_UUID2DEV: {
306                 /* Resolve a device uuid.  This does not change the
307                  * currently selected device.
308                  */
309                 int dev;
310                 struct obd_uuid uuid;
311
312                 if (!data->ioc_inllen1 || !data->ioc_inlbuf1) {
313                         CERROR("No UUID passed!\n");
314                         GOTO(out, err = -EINVAL);
315                 }
316                 if (data->ioc_inlbuf1[data->ioc_inllen1 - 1] != 0) {
317                         CERROR("UUID not NUL terminated!\n");
318                         GOTO(out, err = -EINVAL);
319                 }
320
321                 CDEBUG(D_IOCTL, "device name %s\n", data->ioc_inlbuf1);
322                 obd_str2uuid(&uuid, data->ioc_inlbuf1);
323                 dev = class_uuid2dev(&uuid);
324                 data->ioc_dev = dev;
325                 if (dev == -1) {
326                         CDEBUG(D_IOCTL, "No device for UUID %s!\n",
327                                data->ioc_inlbuf1);
328                         GOTO(out, err = -EINVAL);
329                 }
330
331                 CDEBUG(D_IOCTL, "device name %s, dev %d\n", data->ioc_inlbuf1,
332                        dev);
333                 if (copy_to_user((void __user *)arg, data, sizeof(*data)))
334                         err = -EFAULT;
335                 GOTO(out, err);
336         }
337
338         case OBD_IOC_GETDEVICE: {
339                 int     index = data->ioc_count;
340                 char    *status, *str;
341
342                 if (!data->ioc_inlbuf1) {
343                         CERROR("No buffer passed in ioctl\n");
344                         GOTO(out, err = -EINVAL);
345                 }
346                 if (data->ioc_inllen1 < 128) {
347                         CERROR("ioctl buffer too small to hold version\n");
348                         GOTO(out, err = -EINVAL);
349                 }
350
351                 obd = class_num2obd(index);
352                 if (!obd)
353                         GOTO(out, err = -ENOENT);
354
355                 if (obd->obd_stopping)
356                         status = "ST";
357                 else if (obd->obd_set_up)
358                         status = "UP";
359                 else if (obd->obd_attached)
360                         status = "AT";
361                 else
362                         status = "--";
363                 str = (char *)data->ioc_bulk;
364                 snprintf(str, len - sizeof(*data), "%3d %s %s %s %s %d",
365                          (int)index, status, obd->obd_type->typ_name,
366                          obd->obd_name, obd->obd_uuid.uuid,
367                          atomic_read(&obd->obd_refcount));
368
369                 if (copy_to_user((void __user *)arg, data, len))
370                         err = -EFAULT;
371
372                 GOTO(out, err);
373         }
374
375         }
376
377         if (data->ioc_dev == OBD_DEV_BY_DEVNAME) {
378                 if (data->ioc_inllen4 <= 0 || data->ioc_inlbuf4 == NULL)
379                         GOTO(out, err = -EINVAL);
380                 if (strnlen(data->ioc_inlbuf4, MAX_OBD_NAME) >= MAX_OBD_NAME)
381                         GOTO(out, err = -EINVAL);
382                 obd = class_name2obd(data->ioc_inlbuf4);
383         } else if (data->ioc_dev < class_devno_max()) {
384                 obd = class_num2obd(data->ioc_dev);
385         } else {
386                 CERROR("OBD ioctl: No device\n");
387                 GOTO(out, err = -EINVAL);
388         }
389
390         if (obd == NULL) {
391                 CERROR("OBD ioctl : No Device %d\n", data->ioc_dev);
392                 GOTO(out, err = -EINVAL);
393         }
394         LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
395
396         if (!obd->obd_set_up || obd->obd_stopping) {
397                 CERROR("OBD ioctl: device not setup %d \n", data->ioc_dev);
398                 GOTO(out, err = -EINVAL);
399         }
400
401         switch(cmd) {
402         case OBD_IOC_NO_TRANSNO: {
403                 if (!obd->obd_attached) {
404                         CERROR("Device %d not attached\n", obd->obd_minor);
405                         GOTO(out, err = -ENODEV);
406                 }
407                 CDEBUG(D_HA, "%s: disabling committed-transno notification\n",
408                        obd->obd_name);
409                 obd->obd_no_transno = 1;
410                 GOTO(out, err = 0);
411         }
412
413         default: {
414                 err = obd_iocontrol(cmd, obd->obd_self_export, len, data, NULL);
415                 if (err)
416                         GOTO(out, err);
417
418                 if (copy_to_user((void __user *)arg, data, len))
419                         err = -EFAULT;
420                 GOTO(out, err);
421         }
422         }
423
424 out:
425         OBD_FREE_LARGE(buf, len);
426         RETURN(err);
427 } /* class_handle_ioctl */
428
429 #define OBD_INIT_CHECK
430 #ifdef OBD_INIT_CHECK
431 static int obd_init_checks(void)
432 {
433         __u64 u64val, div64val;
434         char buf[64];
435         int len, ret = 0;
436
437         CDEBUG(D_INFO, "OBD_OBJECT_EOF = %#llx\n", (__u64)OBD_OBJECT_EOF);
438
439         u64val = OBD_OBJECT_EOF;
440         CDEBUG(D_INFO, "u64val OBD_OBJECT_EOF = %#llx\n", u64val);
441         if (u64val != OBD_OBJECT_EOF) {
442                 CERROR("__u64 %#llx(%d) != 0xffffffffffffffff\n",
443                        u64val, (int)sizeof(u64val));
444                 ret = -EINVAL;
445         }
446         len = snprintf(buf, sizeof(buf), "%#llx", u64val);
447         if (len != 18) {
448                 CWARN("u64 hex wrong length! strlen(%s)=%d != 18\n", buf, len);
449                 ret = -EINVAL;
450         }
451
452         div64val = OBD_OBJECT_EOF;
453         CDEBUG(D_INFO, "u64val OBD_OBJECT_EOF = %#llx\n", u64val);
454         if (u64val != OBD_OBJECT_EOF) {
455                 CERROR("__u64 %#llx(%d) != 0xffffffffffffffff\n",
456                        u64val, (int)sizeof(u64val));
457                 ret = -EOVERFLOW;
458         }
459         if (u64val >> 8 != OBD_OBJECT_EOF >> 8) {
460                 CERROR("__u64 %#llx(%d) != 0xffffffffffffffff\n",
461                        u64val, (int)sizeof(u64val));
462                 return -EOVERFLOW;
463         }
464         if (do_div(div64val, 256) != (u64val & 255)) {
465                 CERROR("do_div(%#llx,256) != %llu\n", u64val, u64val & 255);
466                 return -EOVERFLOW;
467         }
468         if (u64val >> 8 != div64val) {
469                 CERROR("do_div(%#llx,256) %llu != %llu\n",
470                        u64val, div64val, u64val >> 8);
471                 return -EOVERFLOW;
472         }
473         len = snprintf(buf, sizeof(buf), "%#llx", u64val);
474         if (len != 18) {
475                 CWARN("u64 hex wrong length! strlen(%s)=%d != 18\n", buf, len);
476                 ret = -EINVAL;
477         }
478         len = snprintf(buf, sizeof(buf), "%llu", u64val);
479         if (len != 20) {
480                 CWARN("u64 wrong length! strlen(%s)=%d != 20\n", buf, len);
481                 ret = -EINVAL;
482         }
483         len = snprintf(buf, sizeof(buf), "%lld", u64val);
484         if (len != 2) {
485                 CWARN("s64 wrong length! strlen(%s)=%d != 2\n", buf, len);
486                 ret = -EINVAL;
487         }
488         if ((u64val & ~PAGE_MASK) >= PAGE_SIZE) {
489                 CWARN("mask failed: u64val %llu >= %llu\n", u64val,
490                       (__u64)PAGE_SIZE);
491                 ret = -EINVAL;
492         }
493
494         return ret;
495 }
496 #else
497 #define obd_init_checks() do {} while(0)
498 #endif
499
500 static int __init obdclass_init(void)
501 {
502         int err;
503
504         LCONSOLE_INFO("Lustre: Build Version: "LUSTRE_VERSION_STRING"\n");
505
506         libcfs_kkuc_init();
507
508         err = obd_init_checks();
509         if (err == -EOVERFLOW)
510                 return err;
511
512 #ifdef CONFIG_PROC_FS
513         obd_memory = lprocfs_alloc_stats(OBD_STATS_NUM,
514                                          LPROCFS_STATS_FLAG_NONE |
515                                          LPROCFS_STATS_FLAG_IRQ_SAFE);
516         if (obd_memory == NULL) {
517                 CERROR("kmalloc of 'obd_memory' failed\n");
518                 return -ENOMEM;
519         }
520
521         lprocfs_counter_init(obd_memory, OBD_MEMORY_STAT,
522                              LPROCFS_CNTR_AVGMINMAX,
523                              "memused", "bytes");
524 #endif
525         err = obd_zombie_impexp_init();
526         if (err)
527                 goto cleanup_obd_memory;
528
529         err = class_handle_init();
530         if (err)
531                 goto cleanup_zombie_impexp;
532
533         err = misc_register(&obd_psdev);
534         if (err) {
535                 CERROR("cannot register %d err %d\n", OBD_DEV_MINOR, err);
536                 goto cleanup_class_handle;
537         }
538
539         /* Default the dirty page cache cap to 1/2 of system memory.
540          * For clients with less memory, a larger fraction is needed
541          * for other purposes (mostly for BGL). */
542         if (totalram_pages <= 512 << (20 - PAGE_SHIFT))
543                 obd_max_dirty_pages = totalram_pages / 4;
544         else
545                 obd_max_dirty_pages = totalram_pages / 2;
546
547         err = obd_init_caches();
548         if (err)
549                 goto cleanup_deregister;
550
551         err = class_procfs_init();
552         if (err)
553                 goto cleanup_caches;
554
555         err = lu_global_init();
556         if (err)
557                 goto cleanup_class_procfs;
558
559         err = cl_global_init();
560         if (err != 0)
561                 goto cleanup_lu_global;
562
563 #ifdef HAVE_SERVER_SUPPORT
564         err = dt_global_init();
565         if (err != 0)
566                 goto cleanup_cl_global;
567
568         err = lu_ucred_global_init();
569         if (err != 0)
570                 goto cleanup_dt_global;
571 #endif /* HAVE_SERVER_SUPPORT */
572
573         err = llog_info_init();
574         if (err)
575 #ifdef HAVE_SERVER_SUPPORT
576                 goto cleanup_lu_ucred_global;
577 #else /* !HAVE_SERVER_SUPPORT */
578                 goto cleanup_cl_global;
579 #endif /* HAVE_SERVER_SUPPORT */
580
581         err = lustre_register_fs();
582
583         /* simulate a late OOM situation now to require all
584          * alloc'ed/initialized resources to be freed */
585         if (OBD_FAIL_CHECK(OBD_FAIL_OBDCLASS_MODULE_LOAD)) {
586                 /* fake error but filesystem has been registered */
587                 lustre_unregister_fs();
588                 /* force error to ensure module will be unloaded/cleaned */
589                 err = -ENOMEM;
590         }
591
592         if (err)
593                 goto cleanup_llog_info;
594
595         return 0;
596
597 cleanup_llog_info:
598         llog_info_fini();
599
600 #ifdef HAVE_SERVER_SUPPORT
601 cleanup_lu_ucred_global:
602         lu_ucred_global_fini();
603
604 cleanup_dt_global:
605         dt_global_fini();
606 #endif /* HAVE_SERVER_SUPPORT */
607
608 cleanup_cl_global:
609         cl_global_fini();
610
611 cleanup_lu_global:
612         lu_global_fini();
613
614 cleanup_class_procfs:
615         obd_sysctl_clean();
616         class_procfs_clean();
617
618 cleanup_caches:
619         obd_cleanup_caches();
620
621 cleanup_deregister:
622         misc_deregister(&obd_psdev);
623
624 cleanup_class_handle:
625         class_handle_cleanup();
626
627 cleanup_zombie_impexp:
628         obd_zombie_impexp_stop();
629
630 cleanup_obd_memory:
631 #ifdef CONFIG_PROC_FS
632         lprocfs_free_stats(&obd_memory);
633 #endif
634
635         return err;
636 }
637
638 void obd_update_maxusage(void)
639 {
640         __u64 max;
641
642         max = obd_memory_sum();
643
644         spin_lock(&obd_updatemax_lock);
645         if (max > obd_max_alloc)
646                 obd_max_alloc = max;
647         spin_unlock(&obd_updatemax_lock);
648 }
649 EXPORT_SYMBOL(obd_update_maxusage);
650
651 #ifdef CONFIG_PROC_FS
652 __u64 obd_memory_max(void)
653 {
654         __u64 ret;
655
656         obd_update_maxusage();
657         spin_lock(&obd_updatemax_lock);
658         ret = obd_max_alloc;
659         spin_unlock(&obd_updatemax_lock);
660
661         return ret;
662 }
663 #endif /* CONFIG_PROC_FS */
664
665 static void __exit obdclass_exit(void)
666 {
667 #ifdef CONFIG_PROC_FS
668         __u64 memory_leaked;
669         __u64 memory_max;
670 #endif /* CONFIG_PROC_FS */
671         ENTRY;
672
673         lustre_unregister_fs();
674
675         misc_deregister(&obd_psdev);
676         llog_info_fini();
677 #ifdef HAVE_SERVER_SUPPORT
678         lu_ucred_global_fini();
679         dt_global_fini();
680 #endif /* HAVE_SERVER_SUPPORT */
681         cl_global_fini();
682         lu_global_fini();
683
684         obd_cleanup_caches();
685         obd_sysctl_clean();
686
687         class_procfs_clean();
688
689         class_handle_cleanup();
690         class_del_uuid(NULL); /* Delete all UUIDs. */
691         obd_zombie_impexp_stop();
692
693 #ifdef CONFIG_PROC_FS
694         memory_leaked = obd_memory_sum();
695         memory_max = obd_memory_max();
696
697         lprocfs_free_stats(&obd_memory);
698         CDEBUG((memory_leaked) ? D_ERROR : D_INFO,
699                "obd_memory max: %llu, leaked: %llu\n",
700                memory_max, memory_leaked);
701 #endif /* CONFIG_PROC_FS */
702
703         EXIT;
704 }
705
706 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
707 MODULE_DESCRIPTION("Lustre Class Driver");
708 MODULE_VERSION(LUSTRE_VERSION_STRING);
709 MODULE_LICENSE("GPL");
710
711 module_init(obdclass_init);
712 module_exit(obdclass_exit);