1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Object Devices Class Driver
6 * Copyright (C) 2001-2003 Cluster File Systems, Inc.
8 * This file is part of Lustre, http://www.lustre.org.
10 * Lustre is free software; you can redistribute it and/or
11 * modify it under the terms of version 2 of the GNU General Public
12 * License as published by the Free Software Foundation.
14 * Lustre is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with Lustre; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 * These are the only exported functions, they provide some generic
24 * infrastructure for managing object devices
27 #define DEBUG_SUBSYSTEM S_CLASS
30 #include <linux/config.h> /* for CONFIG_PROC_FS */
31 #include <linux/module.h>
32 #include <linux/errno.h>
33 #include <linux/kernel.h>
34 #include <linux/major.h>
35 #include <linux/sched.h>
37 #include <linux/slab.h>
38 #include <linux/ioport.h>
39 #include <linux/fcntl.h>
40 #include <linux/delay.h>
41 #include <linux/skbuff.h>
42 #include <linux/proc_fs.h>
44 #include <linux/poll.h>
45 #include <linux/init.h>
46 #include <linux/list.h>
47 #include <linux/highmem.h>
49 #include <asm/ioctls.h>
50 #include <asm/system.h>
52 #include <asm/uaccess.h>
53 #include <linux/miscdevice.h>
54 #include <linux/smp_lock.h>
57 # include <liblustre.h>
61 #include <linux/obd_support.h>
62 #include <linux/obd_class.h>
63 #include <linux/lustre_debug.h>
64 #include <linux/lprocfs_status.h>
65 #include <portals/lib-types.h> /* for PTL_MD_MAX_IOV */
66 #include <linux/lustre_build_version.h>
68 struct semaphore obd_conf_sem; /* serialize configuration commands */
69 struct obd_device obd_dev[MAX_OBD_DEVICES];
70 struct list_head obd_types;
74 /* Root for /proc/lustre */
75 struct proc_dir_entry *proc_lustre_root = NULL;
76 int obd_proc_read_version(char *page, char **start, off_t off, int count, int *eof, void *data);
77 struct lprocfs_vars lprocfs_version[] = {{"version", obd_proc_read_version, NULL, NULL },{NULL,NULL,NULL,NULL}};
80 /* The following are visible and mutable through /proc/sys/lustre/. */
81 unsigned long obd_fail_loc;
82 unsigned long obd_timeout = 100;
83 unsigned long obd_bulk_timeout = 1;
84 char obd_lustre_upcall[128] = "/usr/lib/lustre/lustre_upcall";
85 unsigned long obd_sync_filter; /* = 0, don't sync by default */
88 /* opening /dev/obd */
89 static int obd_class_open(struct inode * inode, struct file * file)
91 struct obd_class_user_state *ocus;
94 OBD_ALLOC(ocus, sizeof(*ocus));
98 INIT_LIST_HEAD(&ocus->ocus_conns);
99 file->private_data = ocus;
105 /* closing /dev/obd */
106 static int obd_class_release(struct inode * inode, struct file * file)
108 struct obd_class_user_state *ocus = file->private_data;
109 struct obd_class_user_conn *c;
112 while (!list_empty (&ocus->ocus_conns)) {
113 c = list_entry (ocus->ocus_conns.next,
114 struct obd_class_user_conn, ocuc_chain);
115 list_del (&c->ocuc_chain);
117 CDEBUG (D_IOCTL, "Auto-disconnect %p\n", &c->ocuc_conn);
119 down (&obd_conf_sem);
120 obd_disconnect (&c->ocuc_conn, 0);
123 OBD_FREE (c, sizeof (*c));
126 OBD_FREE (ocus, sizeof (*ocus));
134 obd_class_add_user_conn (struct obd_class_user_state *ocus,
135 struct lustre_handle *conn)
137 struct obd_class_user_conn *c;
139 /* NB holding obd_conf_sem */
141 OBD_ALLOC (c, sizeof (*c));
145 c->ocuc_conn = *conn;
146 list_add (&c->ocuc_chain, &ocus->ocus_conns);
151 obd_class_remove_user_conn (struct obd_class_user_state *ocus,
152 struct lustre_handle *conn)
155 struct obd_class_user_conn *c;
157 /* NB holding obd_conf_sem or last reference */
159 list_for_each (e, &ocus->ocus_conns) {
160 c = list_entry (e, struct obd_class_user_conn, ocuc_chain);
161 if (conn->cookie == c->ocuc_conn.cookie) {
162 list_del (&c->ocuc_chain);
163 OBD_FREE (c, sizeof (*c));
169 static inline void obd_data2conn(struct lustre_handle *conn,
170 struct obd_ioctl_data *data)
172 memset(conn, 0, sizeof *conn);
173 conn->cookie = data->ioc_cookie;
176 static inline void obd_conn2data(struct obd_ioctl_data *data,
177 struct lustre_handle *conn)
179 data->ioc_cookie = conn->cookie;
182 static void dump_exports(struct obd_device *obd)
184 struct list_head *tmp, *n;
186 list_for_each_safe(tmp, n, &obd->obd_exports) {
187 struct obd_export *exp = list_entry(tmp, struct obd_export,
189 CDEBUG(D_ERROR, "%s: %p %s %d %d %p\n",
190 obd->obd_name, exp, exp->exp_client_uuid.uuid,
191 atomic_read(&exp->exp_refcount),
192 exp->exp_failed, exp->exp_outstanding_reply );
196 int class_handle_ioctl(struct obd_class_user_state *ocus, unsigned int cmd,
200 struct obd_ioctl_data *data;
201 struct portals_debug_ioctl_data *debug_data;
202 struct obd_device *obd = ocus->ocus_current_obd;
203 struct lustre_handle conn;
204 int err = 0, len = 0, serialised = 0;
207 if ((cmd & 0xffffff00) == ((int)'T') << 8) /* ignore all tty ioctls */
208 RETURN(err = -ENOTTY);
210 /* only for debugging */
211 if (cmd == PTL_IOC_DEBUG_MASK) {
212 debug_data = (struct portals_debug_ioctl_data*)arg;
213 portal_subsystem_debug = debug_data->subs;
214 portal_debug = debug_data->debug;
219 case OBD_IOC_BRW_WRITE:
220 case OBD_IOC_BRW_READ:
221 case OBD_IOC_GETATTR:
222 case ECHO_IOC_ENQUEUE:
223 case ECHO_IOC_CANCEL:
231 CDEBUG(D_IOCTL, "cmd = %x, obd = %p\n", cmd, obd);
232 if (!obd && cmd != OBD_IOC_DEVICE &&
233 cmd != OBD_IOC_LIST && cmd != OBD_GET_VERSION &&
234 cmd != OBD_IOC_NAME2DEV && cmd != OBD_IOC_UUID2DEV &&
235 cmd != OBD_IOC_NEWDEV && cmd != OBD_IOC_ADD_UUID &&
236 cmd != OBD_IOC_DEL_UUID && cmd != OBD_IOC_CLOSE_UUID) {
237 CERROR("OBD ioctl: No device\n");
238 GOTO(out, err = -EINVAL);
240 if (obd_ioctl_getdata(&buf, &len, (void *)arg)) {
241 CERROR("OBD ioctl: data error\n");
242 GOTO(out, err = -EINVAL);
244 data = (struct obd_ioctl_data *)buf;
247 case OBD_IOC_DEVICE: {
248 CDEBUG(D_IOCTL, "\n");
249 if (data->ioc_dev >= MAX_OBD_DEVICES || data->ioc_dev < 0) {
250 CERROR("OBD ioctl: DEVICE invalid device %d\n",
252 GOTO(out, err = -EINVAL);
254 CDEBUG(D_IOCTL, "device %d\n", data->ioc_dev);
256 ocus->ocus_current_obd = &obd_dev[data->ioc_dev];
262 char *buf2 = data->ioc_bulk;
263 int remains = data->ioc_inllen1;
265 if (!data->ioc_inlbuf1) {
266 CERROR("No buffer passed!\n");
267 GOTO(out, err = -EINVAL);
271 for (i = 0 ; i < MAX_OBD_DEVICES ; i++) {
274 struct obd_device *obd = &obd_dev[i];
278 if (obd->obd_stopping)
280 else if (obd->obd_set_up)
282 else if (obd->obd_attached)
286 l = snprintf(buf2, remains, "%2d %s %s %s %s %d\n",
287 i, status, obd->obd_type->typ_name,
288 obd->obd_name, obd->obd_uuid.uuid,
289 obd->obd_type->typ_refcnt);
293 CERROR("not enough space for device listing\n");
298 err = copy_to_user((void *)arg, data, len);
304 case OBD_GET_VERSION:
305 if (!data->ioc_inlbuf1) {
306 CERROR("No buffer passed in ioctl\n");
307 GOTO(out, err = -EINVAL);
310 if (strlen(BUILD_VERSION) + 1 > data->ioc_inllen1) {
311 CERROR("ioctl buffer too small to hold version\n");
312 GOTO(out, err = -EINVAL);
315 memcpy(data->ioc_bulk, BUILD_VERSION,
316 strlen(BUILD_VERSION) + 1);
318 err = copy_to_user((void *)arg, data, len);
323 case OBD_IOC_NAME2DEV: {
324 /* Resolve a device name. This does not change the
325 * currently selected device.
329 if (!data->ioc_inllen1 || !data->ioc_inlbuf1 ) {
330 CERROR("No name passed,!\n");
331 GOTO(out, err = -EINVAL);
333 if (data->ioc_inlbuf1[data->ioc_inllen1 - 1] != 0) {
334 CERROR("Name not nul terminated!\n");
335 GOTO(out, err = -EINVAL);
338 CDEBUG(D_IOCTL, "device name %s\n", data->ioc_inlbuf1);
339 dev = class_name2dev(data->ioc_inlbuf1);
342 CDEBUG(D_IOCTL, "No device for name %s!\n",
344 GOTO(out, err = -EINVAL);
347 CDEBUG(D_IOCTL, "device name %s, dev %d\n", data->ioc_inlbuf1,
349 err = copy_to_user((void *)arg, data, sizeof(*data));
355 case OBD_IOC_UUID2DEV: {
356 /* Resolve a device uuid. This does not change the
357 * currently selected device.
360 struct obd_uuid uuid;
362 if (!data->ioc_inllen1 || !data->ioc_inlbuf1) {
363 CERROR("No UUID passed!\n");
364 GOTO(out, err = -EINVAL);
366 if (data->ioc_inlbuf1[data->ioc_inllen1 - 1] != 0) {
367 CERROR("UUID not NUL terminated!\n");
368 GOTO(out, err = -EINVAL);
371 CDEBUG(D_IOCTL, "device name %s\n", data->ioc_inlbuf1);
372 obd_str2uuid(&uuid, data->ioc_inlbuf1);
373 dev = class_uuid2dev(&uuid);
376 CDEBUG(D_IOCTL, "No device for UUID %s!\n",
378 GOTO(out, err = -EINVAL);
381 CDEBUG(D_IOCTL, "device name %s, dev %d\n", data->ioc_inlbuf1,
383 err = copy_to_user((void *)arg, data, sizeof(*data));
391 case OBD_IOC_NEWDEV: {
395 ocus->ocus_current_obd = NULL;
396 for (i = 0 ; i < MAX_OBD_DEVICES ; i++) {
397 struct obd_device *obd = &obd_dev[i];
398 if (!obd->obd_type) {
399 ocus->ocus_current_obd = obd;
408 GOTO(out, err = -EINVAL);
410 err = copy_to_user((void *)arg, data, sizeof(*data));
416 case OBD_IOC_ATTACH: {
417 struct obd_type *type;
420 /* have we attached a type to this device */
421 if (obd->obd_attached|| obd->obd_type) {
422 CERROR("OBD: Device %d already typed as %s.\n",
423 obd->obd_minor, MKSTR(obd->obd_type->typ_name));
424 GOTO(out, err = -EBUSY);
427 if (!data->ioc_inllen1 || !data->ioc_inlbuf1) {
428 CERROR("No type passed!\n");
429 GOTO(out, err = -EINVAL);
431 if (data->ioc_inlbuf1[data->ioc_inllen1 - 1] != 0) {
432 CERROR("Type not nul terminated!\n");
433 GOTO(out, err = -EINVAL);
435 if (!data->ioc_inllen2 || !data->ioc_inlbuf2) {
436 CERROR("No name passed!\n");
437 GOTO(out, err = -EINVAL);
439 if (data->ioc_inlbuf2[data->ioc_inllen2 - 1] != 0) {
440 CERROR("Name not nul terminated!\n");
441 GOTO(out, err = -EINVAL);
443 if (!data->ioc_inllen3 || !data->ioc_inlbuf3) {
444 CERROR("No UUID passed!\n");
445 GOTO(out, err = -EINVAL);
447 if (data->ioc_inlbuf3[data->ioc_inllen3 - 1] != 0) {
448 CERROR("UUID not nul terminated!\n");
449 GOTO(out, err = -EINVAL);
452 CDEBUG(D_IOCTL, "attach type %s name: %s uuid: %s\n",
453 MKSTR(data->ioc_inlbuf1),
454 MKSTR(data->ioc_inlbuf2), MKSTR(data->ioc_inlbuf3));
457 type = class_get_type(data->ioc_inlbuf1);
459 CERROR("OBD: unknown type dev %d\n", obd->obd_minor);
460 GOTO(out, err = -EINVAL);
463 minor = obd->obd_minor;
464 memset(obd, 0, sizeof(*obd));
465 obd->obd_minor = minor;
466 obd->obd_type = type;
467 INIT_LIST_HEAD(&obd->obd_exports);
468 INIT_LIST_HEAD(&obd->obd_imports);
469 spin_lock_init(&obd->obd_dev_lock);
470 init_waitqueue_head(&obd->obd_refcount_waitq);
472 /* XXX belong ins setup not attach */
474 spin_lock_init(&obd->obd_processing_task_lock);
475 init_waitqueue_head(&obd->obd_next_transno_waitq);
476 INIT_LIST_HEAD(&obd->obd_recovery_queue);
477 INIT_LIST_HEAD(&obd->obd_delayed_reply_queue);
479 init_waitqueue_head(&obd->obd_commit_waitq);
481 len = strlen(data->ioc_inlbuf2) + 1;
482 OBD_ALLOC(obd->obd_name, len);
483 if (!obd->obd_name) {
484 class_put_type(obd->obd_type);
485 obd->obd_type = NULL;
486 GOTO(out, err = -ENOMEM);
488 memcpy(obd->obd_name, data->ioc_inlbuf2, len);
490 len = strlen(data->ioc_inlbuf3);
491 if (len >= sizeof(obd->obd_uuid)) {
492 CERROR("uuid must be < "LPSZ" bytes long\n",
493 sizeof(obd->obd_uuid));
495 OBD_FREE(obd->obd_name,
496 strlen(obd->obd_name) + 1);
497 class_put_type(obd->obd_type);
498 obd->obd_type = NULL;
499 GOTO(out, err = -EINVAL);
501 memcpy(obd->obd_uuid.uuid, data->ioc_inlbuf3, len);
504 if (OBP(obd, attach))
505 err = OBP(obd,attach)(obd, sizeof(*data), data);
507 if(data->ioc_inlbuf2)
508 OBD_FREE(obd->obd_name,
509 strlen(obd->obd_name) + 1);
510 class_put_type(obd->obd_type);
511 obd->obd_type = NULL;
513 obd->obd_attached = 1;
516 CDEBUG(D_IOCTL, "OBD: dev %d attached type %s\n",
517 obd->obd_minor, data->ioc_inlbuf1);
523 case OBD_IOC_DETACH: {
525 if (obd->obd_set_up) {
526 CERROR("OBD device %d still set up\n", obd->obd_minor);
527 GOTO(out, err = -EBUSY);
529 if (!obd->obd_attached) {
530 CERROR("OBD device %d not attached\n", obd->obd_minor);
531 GOTO(out, err = -ENODEV);
533 if (OBP(obd, detach))
534 err = OBP(obd,detach)(obd);
537 OBD_FREE(obd->obd_name, strlen(obd->obd_name)+1);
538 obd->obd_name = NULL;
541 obd->obd_attached = 0;
542 obd->obd_type->typ_refcnt--;
543 class_put_type(obd->obd_type);
544 obd->obd_type = NULL;
548 case OBD_IOC_SETUP: {
549 /* have we attached a type to this device? */
550 if (!obd->obd_attached) {
551 CERROR("Device %d not attached\n", obd->obd_minor);
552 GOTO(out, err = -ENODEV);
555 /* has this been done already? */
556 if (obd->obd_set_up) {
557 CERROR("Device %d already setup (type %s)\n",
558 obd->obd_minor, obd->obd_type->typ_name);
559 GOTO(out, err = -EBUSY);
562 atomic_set(&obd->obd_refcount, 0);
564 if ( OBT(obd) && OBP(obd, setup) )
565 err = obd_setup(obd, sizeof(*data), data);
568 obd->obd_type->typ_refcnt++;
570 atomic_inc(&obd->obd_refcount);
575 case OBD_IOC_CLEANUP: {
576 int force = 0, failover = 0;
579 if (!obd->obd_set_up) {
580 CERROR("Device %d not setup\n", obd->obd_minor);
581 GOTO(out, err = -ENODEV);
584 if (data->ioc_inlbuf1) {
585 for (flag = data->ioc_inlbuf1; *flag != 0; flag++)
594 CERROR("unrecognised flag '%c'\n",
599 if (atomic_read(&obd->obd_refcount) == 1 || force) {
600 /* this will stop new connections, and need to
601 do it before class_disconnect_exports() */
602 obd->obd_stopping = 1;
605 if (atomic_read(&obd->obd_refcount) > 1) {
606 struct l_wait_info lwi = LWI_TIMEOUT_INTR(60 * HZ, NULL,
611 CERROR("OBD device %d (%p) has refcount %d\n",
613 atomic_read(&obd->obd_refcount));
615 GOTO(out, err = -EBUSY);
617 class_disconnect_exports(obd, failover);
619 "%s: waiting for obd refs to go away: %d\n",
620 obd->obd_name, atomic_read(&obd->obd_refcount));
622 rc = l_wait_event(obd->obd_refcount_waitq,
623 atomic_read(&obd->obd_refcount) < 2, &lwi);
625 LASSERT(atomic_read(&obd->obd_refcount) == 1);
627 CERROR("wait cancelled cleaning anyway. "
629 atomic_read(&obd->obd_refcount));
632 CDEBUG(D_IOCTL, "%s: awake, now finishing cleanup\n",
636 if (OBT(obd) && OBP(obd, cleanup))
637 err = obd_cleanup(obd, force, failover);
640 obd->obd_set_up = obd->obd_stopping = 0;
641 obd->obd_type->typ_refcnt--;
642 atomic_dec(&obd->obd_refcount);
643 /* XXX this should be an LASSERT */
644 if (atomic_read(&obd->obd_refcount) > 0)
645 CERROR("%s still has refcount %d after "
646 "cleanup.\n", obd->obd_name,
647 atomic_read(&obd->obd_refcount));
653 case OBD_IOC_CONNECT: {
654 struct obd_uuid cluuid = { "OBD_CLASS_UUID" };
655 obd_data2conn(&conn, data);
657 err = obd_connect(&conn, obd, &cluuid);
659 CDEBUG(D_IOCTL, "assigned export "LPX64"\n", conn.cookie);
660 obd_conn2data(data, &conn);
664 err = obd_class_add_user_conn (ocus, &conn);
666 obd_disconnect (&conn, 0);
670 err = copy_to_user((void *)arg, data, sizeof(*data));
672 obd_class_remove_user_conn (ocus, &conn);
673 obd_disconnect (&conn, 0);
674 GOTO (out, err = -EFAULT);
679 case OBD_IOC_DISCONNECT: {
680 obd_data2conn(&conn, data);
681 obd_class_remove_user_conn (ocus, &conn);
682 err = obd_disconnect(&conn, 0);
686 case OBD_IOC_NO_TRANSNO: {
687 if (!obd->obd_attached) {
688 CERROR("Device %d not attached\n", obd->obd_minor);
689 GOTO(out, err = -ENODEV);
692 "disabling committed-transno notifications on %d\n",
694 obd->obd_no_transno = 1;
698 case OBD_IOC_CLOSE_UUID: {
699 struct lustre_peer peer;
700 CDEBUG(D_IOCTL, "closing all connections to uuid %s\n",
702 lustre_uuid_to_peer(data->ioc_inlbuf1, &peer);
705 case OBD_IOC_ADD_UUID: {
706 CDEBUG(D_IOCTL, "adding mapping from uuid %s to nid "LPX64
707 ", nal %d\n", data->ioc_inlbuf1, data->ioc_nid,
710 err = class_add_uuid(data->ioc_inlbuf1, data->ioc_nid,
714 case OBD_IOC_DEL_UUID: {
715 CDEBUG(D_IOCTL, "removing mappings for uuid %s\n",
716 data->ioc_inlbuf1 == NULL ? "<all uuids>" :
719 err = class_del_uuid(data->ioc_inlbuf1);
723 // obd_data2conn(&conn, data);
724 struct obd_class_user_conn *oconn = list_entry(ocus->ocus_conns.next, struct obd_class_user_conn, ocuc_chain);
725 err = obd_iocontrol(cmd, &oconn->ocuc_conn, len, data, NULL);
729 err = copy_to_user((void *)arg, data, len);
738 obd_ioctl_freedata(buf, len);
742 } /* class_handle_ioctl */
746 #define OBD_MINOR 241
748 /* to control /dev/obd */
749 static int obd_class_ioctl(struct inode *inode, struct file *filp,
750 unsigned int cmd, unsigned long arg)
752 return class_handle_ioctl(filp->private_data, cmd, arg);
755 /* declare character device */
756 static struct file_operations obd_psdev_fops = {
757 ioctl: obd_class_ioctl, /* ioctl */
758 open: obd_class_open, /* open */
759 release: obd_class_release, /* release */
763 static struct miscdevice obd_psdev = {
769 void *obd_psdev = NULL;
772 EXPORT_SYMBOL(obd_dev);
773 EXPORT_SYMBOL(obdo_cachep);
774 EXPORT_SYMBOL(obd_memory);
775 EXPORT_SYMBOL(obd_memmax);
776 EXPORT_SYMBOL(obd_fail_loc);
777 EXPORT_SYMBOL(obd_timeout);
778 EXPORT_SYMBOL(obd_lustre_upcall);
779 EXPORT_SYMBOL(obd_sync_filter);
780 EXPORT_SYMBOL(ptlrpc_put_connection_superhack);
781 EXPORT_SYMBOL(ptlrpc_abort_inflight_superhack);
782 EXPORT_SYMBOL(proc_lustre_root);
784 EXPORT_SYMBOL(lctl_fake_uuid);
786 EXPORT_SYMBOL(class_register_type);
787 EXPORT_SYMBOL(class_unregister_type);
788 EXPORT_SYMBOL(class_get_type);
789 EXPORT_SYMBOL(class_put_type);
790 EXPORT_SYMBOL(class_name2dev);
791 EXPORT_SYMBOL(class_uuid2dev);
792 EXPORT_SYMBOL(class_uuid2obd);
793 EXPORT_SYMBOL(class_export_get);
794 EXPORT_SYMBOL(class_export_put);
795 EXPORT_SYMBOL(class_new_export);
796 EXPORT_SYMBOL(class_unlink_export);
797 EXPORT_SYMBOL(class_import_get);
798 EXPORT_SYMBOL(class_import_put);
799 EXPORT_SYMBOL(class_new_import);
800 EXPORT_SYMBOL(class_destroy_import);
801 EXPORT_SYMBOL(class_connect);
802 EXPORT_SYMBOL(class_conn2export);
803 EXPORT_SYMBOL(class_conn2obd);
804 EXPORT_SYMBOL(class_conn2cliimp);
805 EXPORT_SYMBOL(class_conn2ldlmimp);
806 EXPORT_SYMBOL(class_disconnect);
807 EXPORT_SYMBOL(class_disconnect_exports);
808 EXPORT_SYMBOL(lustre_uuid_to_peer);
811 EXPORT_SYMBOL(class_uuid_unparse);
812 EXPORT_SYMBOL(client_tgtuuid2obd);
814 EXPORT_SYMBOL(class_handle_hash);
815 EXPORT_SYMBOL(class_handle_unhash);
816 EXPORT_SYMBOL(class_handle2object);
819 static int __init init_obdclass(void)
821 int init_obdclass(void)
824 struct obd_device *obd;
828 printk(KERN_INFO "OBD class driver Build Version: " BUILD_VERSION
829 ", info@clusterfs.com\n");
831 class_init_uuidlist();
834 sema_init(&obd_conf_sem, 1);
835 INIT_LIST_HEAD(&obd_types);
837 if ((err = misc_register(&obd_psdev))) {
838 CERROR("cannot register %d err %d\n", OBD_MINOR, err);
842 /* This struct is already zerod for us (static global) */
843 for (i = 0, obd = obd_dev; i < MAX_OBD_DEVICES; i++, obd++)
846 err = obd_init_caches();
855 proc_lustre_root = proc_mkdir("lustre", proc_root_fs);
856 if (!proc_lustre_root)
857 printk(KERN_ERR "error registering /proc/fs/lustre\n");
858 proc_version = lprocfs_add_vars(proc_lustre_root,lprocfs_version,NULL);
860 proc_lustre_root = NULL;
867 int obd_proc_read_version(char *page, char **start, off_t off, int count, int *eof, void *data) {
869 return snprintf(page, count, "%s\n", BUILD_VERSION);
872 int obd_proc_read_version(char *page, char **start, off_t off, int count, int *eof, void *data) { return 0; }
876 static void __exit cleanup_obdclass(void)
878 static void cleanup_obdclass(void)
884 misc_deregister(&obd_psdev);
885 for (i = 0; i < MAX_OBD_DEVICES; i++) {
886 struct obd_device *obd = &obd_dev[i];
887 if (obd->obd_type && obd->obd_set_up &&
888 OBT(obd) && OBP(obd, detach)) {
889 /* XXX should this call generic detach otherwise? */
890 OBP(obd, detach)(obd);
894 obd_cleanup_caches();
898 if (proc_lustre_root) {
899 lprocfs_remove(proc_lustre_root);
900 proc_lustre_root = NULL;
903 class_handle_cleanup();
904 class_exit_uuidlist();
906 CERROR("obd mem max: %d leaked: %d\n", obd_memmax,
907 atomic_read(&obd_memory));
911 /* Check that we're building against the appropriate version of the Lustre
914 #include <linux/lustre_version.h>
915 #define LUSTRE_MIN_VERSION 18
916 #define LUSTRE_MAX_VERSION 19
917 #if (LUSTRE_KERNEL_VERSION < LUSTRE_MIN_VERSION)
918 # error Cannot continue: Your Lustre kernel patch is older than the sources
919 #elif (LUSTRE_KERNEL_VERSION > LUSTRE_MAX_VERSION)
920 # error Cannot continue: Your Lustre sources are older than the kernel patch
923 # warning "Lib Lustre - no versioning information"
927 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
928 MODULE_DESCRIPTION("Lustre Class Driver Build Version: " BUILD_VERSION);
929 MODULE_LICENSE("GPL");
931 module_init(init_obdclass);
932 module_exit(cleanup_obdclass);