Whamcloud - gitweb
- debug.c was only used by obdclass, so I moved it there
[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  * Copyright (C) 2001, 2002 Cluster File Systems, Inc.
5  *
6  * This code is issued under the GNU General Public License.
7  * See the file COPYING in this distribution
8  *
9  * These are the only exported functions, they provide some generic
10  * infrastructure for managing object devices
11  *
12  * Object Devices Class Driver
13  */
14
15 #define EXPORT_SYMTAB
16 #include <linux/config.h> /* for CONFIG_PROC_FS */
17 #include <linux/module.h>
18 #include <linux/errno.h>
19 #include <linux/kernel.h>
20 #include <linux/major.h>
21 #include <linux/sched.h>
22 #include <linux/lp.h>
23 #include <linux/slab.h>
24 #include <linux/ioport.h>
25 #include <linux/fcntl.h>
26 #include <linux/delay.h>
27 #include <linux/skbuff.h>
28 #include <linux/proc_fs.h>
29 #include <linux/fs.h>
30 #include <linux/poll.h>
31 #include <linux/init.h>
32 #include <linux/list.h>
33 #include <asm/io.h>
34 #include <asm/system.h>
35 #include <asm/poll.h>
36 #include <asm/uaccess.h>
37 #include <linux/miscdevice.h>
38
39 #define DEBUG_SUBSYSTEM S_CLASS
40
41 #include <linux/obd_support.h>
42 #include <linux/obd_class.h>
43 #include <linux/lustre_debug.h>
44 #include <linux/smp_lock.h>
45
46 struct semaphore obd_conf_sem;   /* serialize configuration commands */
47 struct obd_device obd_dev[MAX_OBD_DEVICES];
48 struct list_head obd_types;
49 unsigned long obd_memory;
50
51 /* The following are visible and mutable through /proc/sys/lustre/. */
52 unsigned long obd_fail_loc;
53 unsigned long obd_timeout = 100;
54 char obd_recovery_upcall[128] = "/usr/lib/lustre/ha_assist";
55
56 extern struct obd_type *class_nm_to_type(char *nm);
57
58 /*  opening /dev/obd */
59 static int obd_class_open(struct inode * inode, struct file * file)
60 {
61         ENTRY;
62
63         file->private_data = NULL;
64         MOD_INC_USE_COUNT;
65         RETURN(0);
66 }
67
68 /*  closing /dev/obd */
69 static int obd_class_release(struct inode * inode, struct file * file)
70 {
71         ENTRY;
72
73         if (file->private_data)
74                 file->private_data = NULL;
75
76         MOD_DEC_USE_COUNT;
77         RETURN(0);
78 }
79
80
81 inline void obd_data2conn(struct lustre_handle *conn, struct obd_ioctl_data *data)
82 {
83         conn->addr = data->ioc_addr;
84         conn->cookie = data->ioc_cookie;
85 }
86
87
88 inline void obd_conn2data(struct obd_ioctl_data *data, struct lustre_handle *conn)
89 {
90         data->ioc_addr = conn->addr;
91         data->ioc_cookie = conn->cookie;
92 }
93
94
95 /* to control /dev/obd */
96 static int obd_class_ioctl (struct inode * inode, struct file * filp,
97                             unsigned int cmd, unsigned long arg)
98 {
99         char *buf = NULL;
100         int len = 0;
101         struct obd_ioctl_data *data;
102         struct obd_device *obd = filp->private_data;
103         
104         struct lustre_handle conn;
105         int rw = OBD_BRW_READ;
106         int err = 0;
107         int serialised = 0;
108         ENTRY;
109
110         switch (cmd)
111         {
112         case OBD_IOC_BRW_WRITE:
113         case OBD_IOC_BRW_READ:
114         case OBD_IOC_GETATTR:
115                 break;
116         default:
117                 down(&obd_conf_sem);
118                 serialised = 1;
119                 break;
120         }
121         
122         if (!obd && cmd != OBD_IOC_DEVICE && cmd != TCGETS &&
123             cmd != OBD_IOC_LIST &&
124             cmd != OBD_IOC_NAME2DEV && cmd != OBD_IOC_NEWDEV) {
125                 CERROR("OBD ioctl: No device\n");
126                 GOTO(out, err=-EINVAL);
127         }
128         if (obd_ioctl_getdata(&buf, &len, (void *)arg)) {
129                 CERROR("OBD ioctl: data error\n");
130                 GOTO(out, err=-EINVAL);
131         }
132         data = (struct obd_ioctl_data *)buf;
133
134         switch (cmd) {
135         case TCGETS:
136                 GOTO(out, err=-EINVAL);
137         case OBD_IOC_DEVICE: {
138                 CDEBUG(D_IOCTL, "\n");
139                 if (data->ioc_dev >= MAX_OBD_DEVICES || data->ioc_dev < 0) {
140                         CERROR("OBD ioctl: DEVICE insufficient devices\n");
141                         GOTO(out, err=-EINVAL);
142                 }
143                 CDEBUG(D_IOCTL, "device %d\n", data->ioc_dev);
144
145                 filp->private_data = &obd_dev[data->ioc_dev];
146                 GOTO(out, err=0);
147         }
148
149         case OBD_IOC_LIST: {
150                 int i;
151                 char *buf2 = data->ioc_bulk;
152                 int remains = data->ioc_inllen1;
153
154                 if (!data->ioc_inlbuf1) {
155                         CERROR("No buffer passed!\n");
156                         GOTO(out, err=-EINVAL);
157                 }
158
159
160                 for (i = 0 ; i < MAX_OBD_DEVICES ; i++) {
161                         int l;
162                         char *status;
163                         struct obd_device *obd = &obd_dev[i];
164                         if (!obd->obd_type)
165                                 continue;
166                         if (obd->obd_flags & OBD_SET_UP)
167                                 status = "UP";
168                         else if (obd->obd_flags & OBD_ATTACHED)
169                                 status = "AT";
170                         else
171                                 status = "-";
172                         l = snprintf(buf2, remains, "%2d %s %s %s %s %d\n",
173                                      i, status, obd->obd_type->typ_name,
174                                      obd->obd_name, obd->obd_uuid, obd->obd_type->typ_refcnt);
175                         buf2 +=l;
176                         remains -=l;
177                         if (remains <= 0) {
178                                 CERROR("not enough space for device listing\n");
179                                 break;
180                         }
181                 }
182
183                 err = copy_to_user((int *)arg, data, len);
184                 GOTO(out, err);
185         }
186
187
188         case OBD_IOC_NAME2DEV: {
189                 /* Resolve a device name.  This does not change the
190                  * currently selected device.
191                  */
192                 int dev;
193
194                 if (!data->ioc_inllen1 || !data->ioc_inlbuf1 ) {
195                         CERROR("No name passed,!\n");
196                         GOTO(out, err=-EINVAL);
197                 }
198                 if (data->ioc_inlbuf1[data->ioc_inllen1-1] !=0) {
199                         CERROR("Name not nul terminated!\n");
200                         GOTO(out, err=-EINVAL);
201                 }
202
203                 CDEBUG(D_IOCTL, "device name %s\n", data->ioc_inlbuf1);
204                 dev = class_name2dev(data->ioc_inlbuf1);
205                 data->ioc_dev = dev;
206                 if (dev == -1) {
207                         CDEBUG(D_IOCTL, "No device for name %s!\n",
208                                data->ioc_inlbuf1);
209                         GOTO(out, err=-EINVAL);
210                 }
211
212                 CDEBUG(D_IOCTL, "device name %s, dev %d\n", data->ioc_inlbuf1,
213                        dev);
214                 err = copy_to_user((int *)arg, data, sizeof(*data));
215                 GOTO(out, err);
216         }
217
218         case OBD_IOC_UUID2DEV: {
219                 /* Resolve a device uuid.  This does not change the
220                  * currently selected device.
221                  */
222                 int dev;
223
224                 if (!data->ioc_inllen1 || !data->ioc_inlbuf1) {
225                         CERROR("No UUID passed!\n");
226                         GOTO(out, err=-EINVAL);
227                 }
228                 if (data->ioc_inlbuf1[data->ioc_inllen1-1] !=0) {
229                         CERROR("Name not nul terminated!\n");
230                         GOTO(out, err=-EINVAL);
231                 }
232
233                 CDEBUG(D_IOCTL, "device name %s\n", data->ioc_inlbuf1);
234                 dev = class_uuid2dev(data->ioc_inlbuf1);
235                 data->ioc_dev = dev;
236                 if (dev == -1) {
237                         CDEBUG(D_IOCTL, "No device for name %s!\n",
238                                data->ioc_inlbuf1);
239                         GOTO(out, err=-EINVAL);
240                 }
241
242                 CDEBUG(D_IOCTL, "device name %s, dev %d\n", data->ioc_inlbuf1,
243                        dev);
244                 err = copy_to_user((int *)arg, data, sizeof(*data));
245                 GOTO(out, err);
246         }
247
248         case OBD_IOC_NEWDEV: {
249                 int dev = -1;
250                 int i;
251
252                 filp->private_data = NULL;
253                 for (i = 0 ; i < MAX_OBD_DEVICES ; i++) {
254                         struct obd_device *obd = &obd_dev[i];
255                         if (!obd->obd_type) {
256                                 filp->private_data = obd;
257                                 dev = i;
258                                 break;
259                         }
260                 }
261
262
263                 data->ioc_dev = dev;
264                 if (dev == -1)
265                         GOTO(out, err=-EINVAL);
266
267                 err = copy_to_user((int *)arg, data, sizeof(*data));
268                 GOTO(out, err);
269         }
270
271         case OBD_IOC_ATTACH: {
272                 struct obd_type *type;
273                 int minor;
274
275                 /* have we attached a type to this device */
276                 if (obd->obd_flags & OBD_ATTACHED || obd->obd_type) {
277                         CERROR("OBD: Device %d already typed as %s.\n",
278                                obd->obd_minor, MKSTR(obd->obd_type->typ_name));
279                         GOTO(out, err=-EBUSY);
280                 }
281
282                 if (!data->ioc_inllen1 || !data->ioc_inlbuf1) {
283                         CERROR("No type passed!\n");
284                         GOTO(out, err=-EINVAL);
285                 }
286                 if (data->ioc_inlbuf1[data->ioc_inllen1-1] !=0) {
287                         CERROR("Type not nul terminated!\n");
288                         GOTO(out, err=-EINVAL);
289                 }
290
291                 CDEBUG(D_IOCTL, "attach type %s name: %s uuid: %s\n",
292                        MKSTR(data->ioc_inlbuf1),
293                        MKSTR(data->ioc_inlbuf2), MKSTR(data->ioc_inlbuf3));
294
295                 /* find the type */
296                 type = class_nm_to_type(data->ioc_inlbuf1);
297                 if (!type) {
298                         CERROR("OBD: unknown type dev %d\n", obd->obd_minor);
299                         GOTO(out, err=-EINVAL);
300                 }
301
302                 minor = obd->obd_minor;
303                 memset(obd, 0, sizeof(*obd));
304                 obd->obd_minor = minor;
305                 obd->obd_type = type;
306                 INIT_LIST_HEAD(&obd->obd_exports);
307                 INIT_LIST_HEAD(&obd->obd_imports);
308                 spin_lock_init(&obd->obd_dev_lock);
309
310                 /* do the attach */
311                 if (OBP(obd, attach))
312                         err = OBP(obd,attach)(obd, sizeof(*data), data);
313                 if (err) {
314                         obd->obd_type = NULL;
315                 } else {
316                         obd->obd_flags |= OBD_ATTACHED;
317
318                         type->typ_refcnt++;
319                         CDEBUG(D_IOCTL, "OBD: dev %d attached type %s\n",
320                                obd->obd_minor, data->ioc_inlbuf1);
321                         if (data->ioc_inlbuf2) {
322                                 int len = strlen(data->ioc_inlbuf2) + 1;
323                                 OBD_ALLOC(obd->obd_name, len);
324                                 if (!obd->obd_name) {
325                                         CERROR("no memory\n");
326                                         LBUG();
327                                 }
328                                 memcpy(obd->obd_name, data->ioc_inlbuf2, len);
329                                 obd->obd_proc_entry =
330                                         proc_lustre_register_obd_device(obd);
331                         } else {
332                                 CERROR("WARNING: unnamed obd device\n");
333                                 obd->obd_proc_entry = NULL;
334                         }
335
336                         if (data->ioc_inlbuf3) {
337                                 int len = strlen(data->ioc_inlbuf3);
338                                 if (len >= sizeof(obd->obd_uuid)) {
339                                         CERROR("uuid must be < %d bytes long\n",
340                                                sizeof(obd->obd_uuid));
341                                         if (obd->obd_name)
342                                                 OBD_FREE(obd->obd_name,
343                                                          strlen(obd->obd_name) + 1);
344                                         GOTO(out, err=-EINVAL);
345                                 }
346                                 memcpy(obd->obd_uuid, data->ioc_inlbuf3, len);
347                         }
348                         MOD_INC_USE_COUNT;
349                 }
350
351                 GOTO(out, err);
352         }
353
354         case OBD_IOC_DETACH: {
355                 ENTRY;
356                 if (obd->obd_flags & OBD_SET_UP) {
357                         CERROR("OBD device %d still set up\n", obd->obd_minor);
358                         GOTO(out, err=-EBUSY);
359                 }
360                 if (!(obd->obd_flags & OBD_ATTACHED) ) {
361                         CERROR("OBD device %d not attached\n", obd->obd_minor);
362                         GOTO(out, err=-ENODEV);
363                 }
364 #warning FIXME: Mike, we probably need some sort of "force detach" here
365                 if (!list_empty(&obd->obd_exports) ) {
366                         CERROR("OBD device %d (%p) has exports\n",
367                                obd->obd_minor, obd);
368                         GOTO(out, err=-EBUSY);
369                 }
370
371                 if (obd->obd_name) {
372                         OBD_FREE(obd->obd_name, strlen(obd->obd_name)+1);
373                         obd->obd_name = NULL;
374                 }
375
376                 if (obd->obd_proc_entry)
377                         proc_lustre_release_obd_device(obd);
378
379                 obd->obd_flags &= ~OBD_ATTACHED;
380                 obd->obd_type->typ_refcnt--;
381                 obd->obd_type = NULL;
382                 MOD_DEC_USE_COUNT;
383                 GOTO(out, err=0);
384         }
385
386         case OBD_IOC_SETUP: {
387                 /* have we attached a type to this device? */
388                 if (!(obd->obd_flags & OBD_ATTACHED)) {
389                         CERROR("Device %d not attached\n", obd->obd_minor);
390                         GOTO(out, err=-ENODEV);
391                 }
392
393                 /* has this been done already? */
394                 if ( obd->obd_flags & OBD_SET_UP ) {
395                         CERROR("Device %d already setup (type %s)\n",
396                                obd->obd_minor, obd->obd_type->typ_name);
397                         GOTO(out, err=-EBUSY);
398                 }
399
400                 if ( OBT(obd) && OBP(obd, setup) )
401                         err = obd_setup(obd, sizeof(*data), data);
402
403                 if (!err) {
404                         obd->obd_type->typ_refcnt++;
405                         obd->obd_flags |= OBD_SET_UP;
406                 }
407
408                 GOTO(out, err);
409         }
410         case OBD_IOC_CLEANUP: {
411                 /* have we attached a type to this device? */
412                 if (!(obd->obd_flags & OBD_ATTACHED)) {
413                         CERROR("Device %d not attached\n", obd->obd_minor);
414                         GOTO(out, err=-ENODEV);
415                 }
416
417                 if ( OBT(obd) && OBP(obd, cleanup) )
418                         err = obd_cleanup(obd);
419
420                 if (!err) {
421                         obd->obd_flags &= ~OBD_SET_UP;
422                         obd->obd_type->typ_refcnt--;
423                 }
424                 GOTO(out, err);
425         }
426
427         case OBD_IOC_CONNECT: {
428                 char * cluuid = "OBD_CLASS_UUID";
429                 obd_data2conn(&conn, data);
430
431                 err = obd_connect(&conn, obd, cluuid);
432
433                 CDEBUG(D_IOCTL, "assigned export %Lx\n", conn.addr);
434                 obd_conn2data(data, &conn);
435                 if (err)
436                         GOTO(out, err);
437
438                 err = copy_to_user((int *)arg, data, sizeof(*data));
439                 GOTO(out, err);
440         }
441
442         case OBD_IOC_DISCONNECT: {
443                 obd_data2conn(&conn, data);
444                 err = obd_disconnect(&conn);
445                 GOTO(out, err);
446         }
447
448         case OBD_IOC_DEC_USE_COUNT: {
449                 MOD_DEC_USE_COUNT;
450                 GOTO(out, err=0);
451         }
452
453         case OBD_IOC_CREATE: {
454                 struct lov_stripe_md *ea;
455                 obd_data2conn(&conn, data);
456
457
458                 err = obd_create(&conn, &data->ioc_obdo1, &ea);
459                 if (err)
460                         GOTO(out, err);
461
462                 err = copy_to_user((int *)arg, data, sizeof(*data));
463                 GOTO(out, err);
464         }
465
466         case OBD_IOC_GETATTR: {
467
468                 obd_data2conn(&conn, data);
469                 err = obd_getattr(&conn, &data->ioc_obdo1, NULL);
470                 if (err)
471                         GOTO(out, err);
472
473                 err = copy_to_user((int *)arg, data, sizeof(*data));
474                 GOTO(out, err);
475         }
476
477         case OBD_IOC_SETATTR: {
478                 obd_data2conn(&conn, data);
479                 err = obd_setattr(&conn, &data->ioc_obdo1, NULL);
480                 if (err)
481                         GOTO(out, err);
482
483                 err = copy_to_user((int *)arg, data, sizeof(*data));
484                 GOTO(out, err);
485         }
486
487         case OBD_IOC_DESTROY: {
488                 //void *ea;
489                 obd_data2conn(&conn, data);
490
491                 err = obd_destroy(&conn, &data->ioc_obdo1, NULL);
492                 if (err)
493                         GOTO(out, err);
494
495                 err = copy_to_user((int *)arg, data, sizeof(*data));
496                 GOTO(out, err);
497         }
498
499         case OBD_IOC_BRW_WRITE:
500                 rw = OBD_BRW_WRITE;
501         case OBD_IOC_BRW_READ: {
502                 struct lov_stripe_md smd;
503                 struct io_cb_data *cbd = ll_init_cb();
504                 obd_count       pages = 0;
505                 struct brw_page *pga, *pgp;
506                 __u64 id = data->ioc_obdo1.o_id;
507                 int gfp_mask = (id & 1) ? GFP_HIGHUSER : GFP_KERNEL;
508                 int verify = (id != 0);
509                 unsigned long off;
510                 int j;
511
512                 if (!cbd)
513                         GOTO(out, err = -ENOMEM);
514
515                 obd_data2conn(&conn, data);
516
517                 pages = data->ioc_count / PAGE_SIZE;
518
519                 CDEBUG(D_INODE, "BRW %s with %d pages\n",
520                        rw == OBD_BRW_READ ? "read" : "write", pages);
521                 OBD_ALLOC(pga, pages * sizeof(*pga));
522                 if (!pga) {
523                         CERROR("no memory for %d BRW per-page data\n", pages);
524                         GOTO(brw_free, err = -ENOMEM);
525                 }
526
527                 memset(&smd, 0, sizeof(smd));
528                 smd.lmd_object_id = id;
529
530                 off = data->ioc_offset;
531
532                 for (j = 0, pgp = pga; j < pages; j++, off += PAGE_SIZE, pgp++){
533                         pgp->pg = alloc_pages(gfp_mask, 0);
534                         if (!pgp->pg) {
535                                 CERROR("no memory for brw pages\n");
536                                 GOTO(brw_cleanup, err = -ENOMEM);
537                         }
538                         pgp->count = PAGE_SIZE;
539                         pgp->off = off;
540                         pgp->flag = 0;
541
542                         if (verify) {
543                                 void *addr = kmap(pgp->pg);
544
545                                 if (rw == OBD_BRW_WRITE)
546                                         page_debug_setup(addr, pgp->count,
547                                                          pgp->off, id);
548                                 else
549                                         page_debug_setup(addr, pgp->count,
550                                                          0xdeadbeef00c0ffee,
551                                                          0xdeadbeef00c0ffee);
552                                 kunmap(pgp->pg);
553                         }
554                 }
555
556                 err = obd_brw(rw, &conn, &smd, j, pga, ll_sync_io_cb, cbd);
557                 if (err)
558                         CERROR("test_brw: error from obd_brw: err = %d\n", err);
559                 EXIT;
560         brw_cleanup:
561                 for (j = 0, pgp = pga; j < pages; j++, pgp++) {
562                         if (pgp->pg != NULL) {
563                                 if (verify && !err) {
564                                         void *addr = kmap(pgp->pg);
565
566                                         err = page_debug_check("test_brw",
567                                                                addr,
568                                                                PAGE_SIZE,
569                                                                pgp->off,id);
570                                         kunmap(pgp->pg);
571                                 }
572                                 __free_pages(pgp->pg, 0);
573                         }
574                 }
575         brw_free:
576                 OBD_FREE(pga, pages * sizeof(*pga));
577                 GOTO(out, err);
578         }
579         default:
580                 obd_data2conn(&conn, data);
581
582                 err = obd_iocontrol(cmd, &conn, len, data, NULL);
583                 if (err)
584                         GOTO(out, err);
585
586                 err = copy_to_user((int *)arg, data, len);
587                 GOTO(out, err);
588         }
589
590  out:
591         if (buf)
592                 OBD_FREE(buf, len);
593         if (serialised)
594                 up(&obd_conf_sem);
595         RETURN(err);
596 } /* obd_class_ioctl */
597
598
599
600 /* declare character device */
601 static struct file_operations obd_psdev_fops = {
602         ioctl: obd_class_ioctl,       /* ioctl */
603         open: obd_class_open,        /* open */
604         release: obd_class_release,     /* release */
605 };
606
607 /* modules setup */
608 #define OBD_MINOR 241
609 static struct miscdevice obd_psdev = {
610         OBD_MINOR,
611         "obd_psdev",
612         &obd_psdev_fops
613 };
614
615 void (*class_signal_connection_failure)(struct ptlrpc_connection *);
616 int (*mds_destroy_export)(struct obd_export *exp);
617 int (*ldlm_destroy_export)(struct obd_export *exp);
618
619 EXPORT_SYMBOL(obd_dev);
620 EXPORT_SYMBOL(obdo_cachep);
621 EXPORT_SYMBOL(obd_memory);
622 EXPORT_SYMBOL(obd_fail_loc);
623 EXPORT_SYMBOL(obd_timeout);
624 EXPORT_SYMBOL(obd_recovery_upcall);
625
626 EXPORT_SYMBOL(class_register_type);
627 EXPORT_SYMBOL(class_unregister_type);
628 EXPORT_SYMBOL(class_name2dev);
629 EXPORT_SYMBOL(class_uuid2dev);
630 EXPORT_SYMBOL(class_uuid2obd);
631 EXPORT_SYMBOL(class_new_export);
632 EXPORT_SYMBOL(class_destroy_export);
633 EXPORT_SYMBOL(class_connect);
634 EXPORT_SYMBOL(class_conn2export);
635 EXPORT_SYMBOL(class_conn2obd);
636 EXPORT_SYMBOL(class_conn2cliimp);
637 EXPORT_SYMBOL(class_conn2ldlmimp);
638 EXPORT_SYMBOL(class_disconnect);
639 EXPORT_SYMBOL(class_disconnect_all);
640 //EXPORT_SYMBOL(class_uuid_parse);
641 EXPORT_SYMBOL(class_uuid_unparse);
642 //EXPORT_SYMBOL(class_multi_setup);
643 //EXPORT_SYMBOL(class_multi_cleanup);
644
645 EXPORT_SYMBOL(class_signal_connection_failure);
646 EXPORT_SYMBOL(mds_destroy_export);
647 EXPORT_SYMBOL(ldlm_destroy_export);
648 EXPORT_SYMBOL(ll_sync_io_cb);
649 EXPORT_SYMBOL(ll_init_cb);
650
651 static int __init init_obdclass(void)
652 {
653         struct obd_device *obd;
654         int err;
655         int i;
656
657         printk(KERN_INFO "OBD class driver  v0.9, info@clusterfs.com\n");
658
659         sema_init(&obd_conf_sem, 1);
660         INIT_LIST_HEAD(&obd_types);
661
662         if ((err = misc_register(&obd_psdev))) {
663                 CERROR("cannot register %d err %d\n", OBD_MINOR, err);
664                 return err;
665         }
666
667         /* This struct is already zerod for us (static global) */
668         for (i = 0, obd = obd_dev; i < MAX_OBD_DEVICES; i++, obd++)
669                 obd->obd_minor = i;
670
671         err = obd_init_caches();
672         if (err)
673                 return err;
674         obd_sysctl_init();
675         return 0;
676 }
677
678 static void __exit cleanup_obdclass(void)
679 {
680         int i;
681         ENTRY;
682
683         misc_deregister(&obd_psdev);
684         for (i = 0; i < MAX_OBD_DEVICES; i++) {
685                 struct obd_device *obd = &obd_dev[i];
686                 if (obd->obd_type && (obd->obd_flags & OBD_SET_UP) &&
687                     OBT(obd) && OBP(obd, detach)) {
688                         /* XXX should this call generic detach otherwise? */
689                         OBP(obd, detach)(obd);
690                 }
691         }
692
693         obd_cleanup_caches();
694         obd_sysctl_clean();
695         CERROR("obd memory leaked: %ld bytes\n", obd_memory);
696         EXIT;
697 }
698
699 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
700 MODULE_DESCRIPTION("Lustre Class Driver v1.0");
701 MODULE_LICENSE("GPL");
702
703 module_init(init_obdclass);
704 module_exit(cleanup_obdclass);