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