Whamcloud - gitweb
Branch HEAD
[fs/lustre-release.git] / lustre / obdclass / class_obd.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
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 #ifndef EXPORT_SYMTAB
39 # define EXPORT_SYMTAB
40 #endif
41 #ifndef __KERNEL__
42 # include <liblustre.h>
43 #else
44 # include <asm/atomic.h>
45 #endif
46
47 #include <obd_support.h>
48 #include <obd_class.h>
49 #include <lustre_debug.h>
50 #include <lprocfs_status.h>
51 #include <lustre/lustre_build_version.h>
52 #include <libcfs/list.h>
53 #include "llog_internal.h"
54
55 #ifndef __KERNEL__
56 /* liblustre workaround */
57 atomic_t libcfs_kmemory = {0};
58 #endif
59
60 struct obd_device *obd_devs[MAX_OBD_DEVICES];
61 struct list_head obd_types;
62 spinlock_t obd_dev_lock = SPIN_LOCK_UNLOCKED;
63
64 #ifndef __KERNEL__
65 __u64 obd_max_pages = 0;
66 __u64 obd_max_alloc = 0;
67 __u64 obd_alloc;
68 __u64 obd_pages;
69 #endif
70
71 /* The following are visible and mutable through /proc/sys/lustre/. */
72 unsigned int obd_debug_peer_on_timeout;
73 unsigned int obd_dump_on_timeout;
74 unsigned int obd_dump_on_eviction;
75 unsigned int obd_timeout = OBD_TIMEOUT_DEFAULT;   /* seconds */
76 unsigned int ldlm_timeout = LDLM_TIMEOUT_DEFAULT; /* seconds */
77 unsigned int obd_max_dirty_pages = 256;
78 atomic_t obd_dirty_pages;
79 atomic_t obd_dirty_transit_pages;
80
81 cfs_waitq_t obd_race_waitq;
82 int obd_race_state;
83
84 #ifdef __KERNEL__
85 unsigned long obd_print_fail_loc(void)
86 {
87         CWARN("obd_fail_loc = %lx\n", obd_fail_loc);
88         return obd_fail_loc;
89 }
90
91 /*  opening /dev/obd */
92 static int obd_class_open(unsigned long flags, void *args)
93 {
94         ENTRY;
95
96         PORTAL_MODULE_USE;
97         RETURN(0);
98 }
99
100 /*  closing /dev/obd */
101 static int obd_class_release(unsigned long flags, void *args)
102 {
103         ENTRY;
104
105         PORTAL_MODULE_UNUSE;
106         RETURN(0);
107 }
108 #endif
109
110 static inline void obd_data2conn(struct lustre_handle *conn,
111                                  struct obd_ioctl_data *data)
112 {
113         memset(conn, 0, sizeof *conn);
114         conn->cookie = data->ioc_cookie;
115 }
116
117 static inline void obd_conn2data(struct obd_ioctl_data *data,
118                                  struct lustre_handle *conn)
119 {
120         data->ioc_cookie = conn->cookie;
121 }
122
123 int class_resolve_dev_name(__u32 len, const char *name)
124 {
125         int rc;
126         int dev;
127
128         ENTRY;
129         if (!len || !name) {
130                 CERROR("No name passed,!\n");
131                 GOTO(out, rc = -EINVAL);
132         }
133         if (name[len - 1] != 0) {
134                 CERROR("Name not nul terminated!\n");
135                 GOTO(out, rc = -EINVAL);
136         }
137
138         CDEBUG(D_IOCTL, "device name %s\n", name);
139         dev = class_name2dev(name);
140         if (dev == -1) {
141                 CDEBUG(D_IOCTL, "No device for name %s!\n", name);
142                 GOTO(out, rc = -EINVAL);
143         }
144
145         CDEBUG(D_IOCTL, "device name %s, dev %d\n", name, dev);
146         rc = dev;
147
148 out:
149         RETURN(rc);
150 }
151
152 int class_handle_ioctl(unsigned int cmd, unsigned long arg)
153 {
154         char *buf = NULL;
155         struct obd_ioctl_data *data;
156         struct libcfs_debug_ioctl_data *debug_data;
157         struct obd_device *obd = NULL;
158         int err = 0, len = 0;
159         ENTRY;
160
161         /* only for debugging */
162         if (cmd == LIBCFS_IOC_DEBUG_MASK) {
163                 debug_data = (struct libcfs_debug_ioctl_data*)arg;
164                 libcfs_subsystem_debug = debug_data->subs;
165                 libcfs_debug = debug_data->debug;
166                 return 0;
167         }
168
169         CDEBUG(D_IOCTL, "cmd = %x\n", cmd);
170         if (obd_ioctl_getdata(&buf, &len, (void *)arg)) {
171                 CERROR("OBD ioctl: data error\n");
172                 GOTO(out, err = -EINVAL);
173         }
174         data = (struct obd_ioctl_data *)buf;
175
176         switch (cmd) {
177         case OBD_IOC_PROCESS_CFG: {
178                 struct lustre_cfg *lcfg;
179
180                 if (!data->ioc_plen1 || !data->ioc_pbuf1) {
181                         CERROR("No config buffer passed!\n");
182                         GOTO(out, err = -EINVAL);
183                 }
184                 OBD_ALLOC(lcfg, data->ioc_plen1);
185                 if (lcfg == NULL)
186                         GOTO(out, err = -ENOMEM);
187                 err = copy_from_user(lcfg, data->ioc_pbuf1, data->ioc_plen1);
188                 if (!err)
189                         err = lustre_cfg_sanity_check(lcfg, data->ioc_plen1);
190                 if (!err)
191                         err = class_process_config(lcfg);
192
193                 OBD_FREE(lcfg, data->ioc_plen1);
194                 GOTO(out, err);
195         }
196
197         case OBD_GET_VERSION:
198                 if (!data->ioc_inlbuf1) {
199                         CERROR("No buffer passed in ioctl\n");
200                         GOTO(out, err = -EINVAL);
201                 }
202
203                 if (strlen(BUILD_VERSION) + 1 > data->ioc_inllen1) {
204                         CERROR("ioctl buffer too small to hold version\n");
205                         GOTO(out, err = -EINVAL);
206                 }
207
208                 memcpy(data->ioc_bulk, BUILD_VERSION,
209                        strlen(BUILD_VERSION) + 1);
210
211                 err = obd_ioctl_popdata((void *)arg, data, len);
212                 if (err)
213                         err = -EFAULT;
214                 GOTO(out, err);
215
216         case OBD_IOC_NAME2DEV: {
217                 /* Resolve a device name.  This does not change the
218                  * currently selected device.
219                  */
220                 int dev;
221
222                 dev = class_resolve_dev_name(data->ioc_inllen1,
223                                              data->ioc_inlbuf1);
224                 data->ioc_dev = dev;
225                 if (dev < 0)
226                         GOTO(out, err = -EINVAL);
227
228                 err = obd_ioctl_popdata((void *)arg, data, sizeof(*data));
229                 if (err)
230                         err = -EFAULT;
231                 GOTO(out, err);
232         }
233
234         case OBD_IOC_UUID2DEV: {
235                 /* Resolve a device uuid.  This does not change the
236                  * currently selected device.
237                  */
238                 int dev;
239                 struct obd_uuid uuid;
240
241                 if (!data->ioc_inllen1 || !data->ioc_inlbuf1) {
242                         CERROR("No UUID passed!\n");
243                         GOTO(out, err = -EINVAL);
244                 }
245                 if (data->ioc_inlbuf1[data->ioc_inllen1 - 1] != 0) {
246                         CERROR("UUID not NUL terminated!\n");
247                         GOTO(out, err = -EINVAL);
248                 }
249
250                 CDEBUG(D_IOCTL, "device name %s\n", data->ioc_inlbuf1);
251                 obd_str2uuid(&uuid, data->ioc_inlbuf1);
252                 dev = class_uuid2dev(&uuid);
253                 data->ioc_dev = dev;
254                 if (dev == -1) {
255                         CDEBUG(D_IOCTL, "No device for UUID %s!\n",
256                                data->ioc_inlbuf1);
257                         GOTO(out, err = -EINVAL);
258                 }
259
260                 CDEBUG(D_IOCTL, "device name %s, dev %d\n", data->ioc_inlbuf1,
261                        dev);
262                 err = obd_ioctl_popdata((void *)arg, data, sizeof(*data));
263                 if (err)
264                         err = -EFAULT;
265                 GOTO(out, err);
266         }
267
268         case OBD_IOC_CLOSE_UUID: {
269                 CDEBUG(D_IOCTL, "closing all connections to uuid %s (NOOP)\n",
270                        data->ioc_inlbuf1);
271                 GOTO(out, err = 0);
272         }
273
274         case OBD_IOC_GETDEVICE: {
275                 int     index = data->ioc_count;
276                 char    *status, *str;
277
278                 if (!data->ioc_inlbuf1) {
279                         CERROR("No buffer passed in ioctl\n");
280                         GOTO(out, err = -EINVAL);
281                 }
282                 if (data->ioc_inllen1 < 128) {
283                         CERROR("ioctl buffer too small to hold version\n");
284                         GOTO(out, err = -EINVAL);
285                 }
286
287                 obd = class_num2obd(index);
288                 if (!obd)
289                         GOTO(out, err = -ENOENT);
290
291                 if (obd->obd_stopping)
292                         status = "ST";
293                 else if (obd->obd_set_up)
294                         status = "UP";
295                 else if (obd->obd_attached)
296                         status = "AT";
297                 else
298                         status = "--";
299                 str = (char *)data->ioc_bulk;
300                 snprintf(str, len - sizeof(*data), "%3d %s %s %s %s %d",
301                          (int)index, status, obd->obd_type->typ_name,
302                          obd->obd_name, obd->obd_uuid.uuid,
303                          atomic_read(&obd->obd_refcount));
304                 err = obd_ioctl_popdata((void *)arg, data, len);
305
306                 GOTO(out, err = 0);
307         }
308
309         }
310
311         if (data->ioc_dev == OBD_DEV_BY_DEVNAME) {
312                 if (data->ioc_inllen4 <= 0 || data->ioc_inlbuf4 == NULL)
313                         GOTO(out, err = -EINVAL);
314                 if (strnlen(data->ioc_inlbuf4, MAX_OBD_NAME) >= MAX_OBD_NAME)
315                         GOTO(out, err = -EINVAL);
316                 obd = class_name2obd(data->ioc_inlbuf4);
317         } else if (data->ioc_dev < class_devno_max()) {
318                 obd = class_num2obd(data->ioc_dev);
319         } else {
320                 CERROR("OBD ioctl: No device\n");
321                 GOTO(out, err = -EINVAL);
322         }
323
324         if (obd == NULL) {
325                 CERROR("OBD ioctl : No Device %d\n", data->ioc_dev);
326                 GOTO(out, err = -EINVAL);
327         }
328         LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
329
330         if (!obd->obd_set_up || obd->obd_stopping) {
331                 CERROR("OBD ioctl: device not setup %d \n", data->ioc_dev);
332                 GOTO(out, err = -EINVAL);
333         }
334
335         switch(cmd) {
336         case OBD_IOC_NO_TRANSNO: {
337                 if (!obd->obd_attached) {
338                         CERROR("Device %d not attached\n", obd->obd_minor);
339                         GOTO(out, err = -ENODEV);
340                 }
341                 CDEBUG(D_HA, "%s: disabling committed-transno notification\n",
342                        obd->obd_name);
343                 obd->obd_no_transno = 1;
344                 GOTO(out, err = 0);
345         }
346
347         default: {
348                 err = obd_iocontrol(cmd, obd->obd_self_export, len, data, NULL);
349                 if (err)
350                         GOTO(out, err);
351
352                 err = obd_ioctl_popdata((void *)arg, data, len);
353                 if (err)
354                         err = -EFAULT;
355                 GOTO(out, err);
356         }
357         }
358
359  out:
360         if (buf)
361                 obd_ioctl_freedata(buf, len);
362         RETURN(err);
363 } /* class_handle_ioctl */
364
365
366
367 #define OBD_MINOR 241
368 #ifdef __KERNEL__
369 /* to control /dev/obd */
370 static int obd_class_ioctl (struct cfs_psdev_file *pfile, unsigned long cmd,
371                             void *arg)
372 {
373         return class_handle_ioctl(cmd, (unsigned long)arg);
374 }
375
376 /* declare character device */
377 struct cfs_psdev_ops obd_psdev_ops = {
378         /* .p_open    = */ obd_class_open,      /* open */
379         /* .p_close   = */ obd_class_release,   /* release */
380         /* .p_read    = */ NULL,
381         /* .p_write   = */ NULL,
382         /* .p_ioctl   = */ obd_class_ioctl     /* ioctl */
383 };
384
385 extern cfs_psdev_t obd_psdev;
386 #else
387 void *obd_psdev = NULL;
388 #endif
389
390 EXPORT_SYMBOL(obd_devs);
391 EXPORT_SYMBOL(obd_print_fail_loc);
392 EXPORT_SYMBOL(obd_race_waitq);
393 EXPORT_SYMBOL(obd_race_state);
394 EXPORT_SYMBOL(obd_debug_peer_on_timeout);
395 EXPORT_SYMBOL(obd_dump_on_timeout);
396 EXPORT_SYMBOL(obd_dump_on_eviction);
397 EXPORT_SYMBOL(obd_timeout);
398 EXPORT_SYMBOL(ldlm_timeout);
399 EXPORT_SYMBOL(obd_max_dirty_pages);
400 EXPORT_SYMBOL(obd_dirty_pages);
401 EXPORT_SYMBOL(obd_dirty_transit_pages);
402 EXPORT_SYMBOL(ptlrpc_put_connection_superhack);
403
404 EXPORT_SYMBOL(proc_lustre_root);
405
406 EXPORT_SYMBOL(class_register_type);
407 EXPORT_SYMBOL(class_unregister_type);
408 EXPORT_SYMBOL(class_get_type);
409 EXPORT_SYMBOL(class_put_type);
410 EXPORT_SYMBOL(class_name2dev);
411 EXPORT_SYMBOL(class_name2obd);
412 EXPORT_SYMBOL(class_uuid2dev);
413 EXPORT_SYMBOL(class_uuid2obd);
414 EXPORT_SYMBOL(class_find_client_obd);
415 EXPORT_SYMBOL(class_devices_in_group);
416 EXPORT_SYMBOL(class_conn2export);
417 EXPORT_SYMBOL(class_exp2obd);
418 EXPORT_SYMBOL(class_conn2obd);
419 EXPORT_SYMBOL(class_exp2cliimp);
420 EXPORT_SYMBOL(class_conn2cliimp);
421 EXPORT_SYMBOL(class_disconnect);
422 EXPORT_SYMBOL(class_num2obd);
423
424 /* uuid.c */
425 EXPORT_SYMBOL(class_uuid_unparse);
426 EXPORT_SYMBOL(lustre_uuid_to_peer);
427
428 EXPORT_SYMBOL(class_handle_hash);
429 EXPORT_SYMBOL(class_handle_unhash);
430 EXPORT_SYMBOL(class_handle_hash_back);
431 EXPORT_SYMBOL(class_handle2object);
432 EXPORT_SYMBOL(class_handle_free_cb);
433
434 /* obd_config.c */
435 EXPORT_SYMBOL(class_incref);
436 EXPORT_SYMBOL(class_decref);
437 EXPORT_SYMBOL(class_get_profile);
438 EXPORT_SYMBOL(class_del_profile);
439 EXPORT_SYMBOL(class_del_profiles);
440 EXPORT_SYMBOL(class_process_config);
441 EXPORT_SYMBOL(class_process_proc_param);
442 EXPORT_SYMBOL(class_config_parse_llog);
443 EXPORT_SYMBOL(class_config_dump_llog);
444 EXPORT_SYMBOL(class_attach);
445 EXPORT_SYMBOL(class_setup);
446 EXPORT_SYMBOL(class_cleanup);
447 EXPORT_SYMBOL(class_detach);
448 EXPORT_SYMBOL(class_manual_cleanup);
449
450 /* mea.c */
451 EXPORT_SYMBOL(mea_name2idx);
452 EXPORT_SYMBOL(raw_name2idx);
453
454 #define OBD_INIT_CHECK
455 #ifdef OBD_INIT_CHECK
456 int obd_init_checks(void)
457 {
458         __u64 u64val, div64val;
459         char buf[64];
460         int len, ret = 0;
461
462         CDEBUG(D_INFO, "LPU64=%s, LPD64=%s, LPX64=%s, LPSZ=%s, LPSSZ=%s\n",
463                LPU64, LPD64, LPX64, LPSZ, LPSSZ);
464
465         CDEBUG(D_INFO, "OBD_OBJECT_EOF = "LPX64"\n", (__u64)OBD_OBJECT_EOF);
466
467         u64val = OBD_OBJECT_EOF;
468         CDEBUG(D_INFO, "u64val OBD_OBJECT_EOF = "LPX64"\n", u64val);
469         if (u64val != OBD_OBJECT_EOF) {
470                 CERROR("__u64 "LPX64"(%d) != 0xffffffffffffffff\n",
471                        u64val, (int)sizeof(u64val));
472                 ret = -EINVAL;
473         }
474         len = snprintf(buf, sizeof(buf), LPX64, u64val);
475         if (len != 18) {
476                 CWARN("LPX64 wrong length! strlen(%s)=%d != 18\n", buf, len);
477                 ret = -EINVAL;
478         }
479
480         div64val = OBD_OBJECT_EOF;
481         CDEBUG(D_INFO, "u64val OBD_OBJECT_EOF = "LPX64"\n", u64val);
482         if (u64val != OBD_OBJECT_EOF) {
483                 CERROR("__u64 "LPX64"(%d) != 0xffffffffffffffff\n",
484                        u64val, (int)sizeof(u64val));
485                 ret = -EOVERFLOW;
486         }
487         if (u64val >> 8 != OBD_OBJECT_EOF >> 8) {
488                 CERROR("__u64 "LPX64"(%d) != 0xffffffffffffffff\n",
489                        u64val, (int)sizeof(u64val));
490                 return -EOVERFLOW;
491         }
492         if (do_div(div64val, 256) != (u64val & 255)) {
493                 CERROR("do_div("LPX64",256) != "LPU64"\n", u64val, u64val &255);
494                 return -EOVERFLOW;
495         }
496         if (u64val >> 8 != div64val) {
497                 CERROR("do_div("LPX64",256) "LPU64" != "LPU64"\n",
498                        u64val, div64val, u64val >> 8);
499                 return -EOVERFLOW;
500         }
501         len = snprintf(buf, sizeof(buf), LPX64, u64val);
502         if (len != 18) {
503                 CWARN("LPX64 wrong length! strlen(%s)=%d != 18\n", buf, len);
504                 ret = -EINVAL;
505         }
506         len = snprintf(buf, sizeof(buf), LPU64, u64val);
507         if (len != 20) {
508                 CWARN("LPU64 wrong length! strlen(%s)=%d != 20\n", buf, len);
509                 ret = -EINVAL;
510         }
511         len = snprintf(buf, sizeof(buf), LPD64, u64val);
512         if (len != 2) {
513                 CWARN("LPD64 wrong length! strlen(%s)=%d != 2\n", buf, len);
514                 ret = -EINVAL;
515         }
516         if ((u64val & ~CFS_PAGE_MASK) >= CFS_PAGE_SIZE) {
517                 CWARN("mask failed: u64val "LPU64" >= "LPU64"\n", u64val,
518                       (__u64)CFS_PAGE_SIZE);
519                 ret = -EINVAL;
520         }
521
522         return ret;
523 }
524 #else
525 #define obd_init_checks() do {} while(0)
526 #endif
527
528 extern spinlock_t obd_types_lock;
529 extern int class_procfs_init(void);
530 extern int class_procfs_clean(void);
531
532 #ifdef __KERNEL__
533 static int __init init_obdclass(void)
534 #else
535 int init_obdclass(void)
536 #endif
537 {
538         int i, err;
539 #ifdef __KERNEL__
540         int lustre_register_fs(void);
541
542         for (i = CAPA_SITE_CLIENT; i < CAPA_SITE_MAX; i++)
543                 CFS_INIT_LIST_HEAD(&capa_list[i]);
544 #endif
545
546         LCONSOLE_INFO("OBD class driver, http://www.lustre.org/\n");
547         LCONSOLE_INFO("        Lustre Version: "LUSTRE_VERSION_STRING"\n");
548         LCONSOLE_INFO("        Build Version: "BUILD_VERSION"\n");
549
550         spin_lock_init(&obd_types_lock);
551         cfs_waitq_init(&obd_race_waitq);
552         obd_zombie_impexp_init();
553 #ifdef LPROCFS
554         obd_memory = lprocfs_alloc_stats(OBD_STATS_NUM,
555                                          LPROCFS_STATS_FLAG_PERCPU);
556         if (obd_memory == NULL) {
557                 CERROR("kmalloc of 'obd_memory' failed\n");
558                 RETURN(-ENOMEM);
559         }
560
561         lprocfs_counter_init(obd_memory, OBD_MEMORY_STAT,
562                              LPROCFS_CNTR_AVGMINMAX,
563                              "memused", "bytes");
564         lprocfs_counter_init(obd_memory, OBD_MEMORY_PAGES_STAT,
565                              LPROCFS_CNTR_AVGMINMAX,
566                              "pagesused", "pages");
567 #endif
568         err = obd_init_checks();
569         if (err == -EOVERFLOW)
570                 return err;
571
572         class_init_uuidlist();
573         err = class_handle_init();
574         if (err)
575                 return err;
576
577         spin_lock_init(&obd_dev_lock);
578         CFS_INIT_LIST_HEAD(&obd_types);
579
580         err = cfs_psdev_register(&obd_psdev);
581         if (err) {
582                 CERROR("cannot register %d err %d\n", OBD_MINOR, err);
583                 return err;
584         }
585
586         /* This struct is already zeroed for us (static global) */
587         for (i = 0; i < class_devno_max(); i++)
588                 obd_devs[i] = NULL;
589
590         /* Default the dirty page cache cap to 1/2 of system memory.
591          * For clients with less memory, a larger fraction is needed
592          * for other purposes (mostly for BGL). */
593         if (num_physpages <= 512 << (20 - CFS_PAGE_SHIFT))
594                 obd_max_dirty_pages = num_physpages / 4;
595         else
596                 obd_max_dirty_pages = num_physpages / 2;
597
598         err = obd_init_caches();
599         if (err)
600                 return err;
601         err = lu_global_init();
602         if (err)
603                 return err;
604 #ifdef __KERNEL__
605         err = class_procfs_init();
606         if (err)
607                 return err;
608         err = lustre_register_fs();
609 #endif
610
611         return err;
612 }
613
614 /* liblustre doesn't call cleanup_obdclass, apparently.  we carry on in this
615  * ifdef to the end of the file to cover module and versioning goo.*/
616 #ifdef __KERNEL__
617 static void cleanup_obdclass(void)
618 {
619         int i;
620         int lustre_unregister_fs(void);
621         __u64 memory_leaked, pages_leaked;
622         __u64 memory_max, pages_max;
623         ENTRY;
624
625         lustre_unregister_fs();
626
627         cfs_psdev_deregister(&obd_psdev);
628         for (i = 0; i < class_devno_max(); i++) {
629                 struct obd_device *obd = class_num2obd(i);
630                 if (obd && obd->obd_set_up &&
631                     OBT(obd) && OBP(obd, detach)) {
632                         /* XXX should this call generic detach otherwise? */
633                         LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
634                         OBP(obd, detach)(obd);
635                 }
636         }
637         lu_global_fini();
638
639         obd_cleanup_caches();
640         obd_sysctl_clean();
641
642         class_procfs_clean();
643
644         class_handle_cleanup();
645         class_exit_uuidlist();
646         obd_zombie_impexp_stop();
647
648         memory_leaked = obd_memory_sum();
649         pages_leaked = obd_pages_sum();
650
651         memory_max = obd_memory_max();
652         pages_max = obd_pages_max();
653
654         lprocfs_free_stats(&obd_memory);
655         CDEBUG((memory_leaked) ? D_ERROR : D_INFO,
656                "obd_memory max: "LPU64", leaked: "LPU64"\n",
657                memory_max, memory_leaked);
658         CDEBUG((pages_leaked) ? D_ERROR : D_INFO,
659                "obd_memory_pages max: "LPU64", leaked: "LPU64"\n",
660                pages_max, pages_leaked);
661
662         EXIT;
663 }
664
665 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
666 MODULE_DESCRIPTION("Lustre Class Driver Build Version: " BUILD_VERSION);
667 MODULE_LICENSE("GPL");
668
669 cfs_module(obdclass, LUSTRE_VERSION_STRING, init_obdclass, cleanup_obdclass);
670 #endif