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