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