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