1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001, 2002 Cluster File Systems, Inc.
6 * This code is issued under the GNU General Public License.
7 * See the file COPYING in this distribution
9 * These are the only exported functions, they provide some generic
10 * infrastructure for managing object devices
12 * Object Devices Class Driver
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>
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>
30 #include <linux/poll.h>
31 #include <linux/init.h>
32 #include <linux/list.h>
34 #include <asm/system.h>
36 #include <asm/uaccess.h>
37 #include <linux/miscdevice.h>
39 #define DEBUG_SUBSYSTEM S_CLASS
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 #include <linux/lprocfs.h>
47 struct semaphore obd_conf_sem; /* serialize configuration commands */
48 struct obd_device obd_dev[MAX_OBD_DEVICES];
49 struct list_head obd_types;
50 unsigned long obd_memory;
52 /* The following are visible and mutable through /proc/sys/lustre/. */
53 unsigned long obd_fail_loc;
54 unsigned long obd_timeout = 100;
55 char obd_recovery_upcall[128] = "/usr/lib/lustre/ha_assist";
57 extern struct obd_type *class_nm_to_type(char *nm);
59 * LProcFS specific data structures. These define the namespace for
60 * the various device classes. We will need to distribute these
61 * later, to individual modules (e.g. MDS, MDC etc)
67 * Common SNMP namespace
70 char *snmp_dir_nm[] = {
76 lprocfs_vars_t snmp_var_nm[]={
77 {"uuid", rd_uuid, wr_uuid},
78 {"f_blocksize",rd_blksize, wr_other},
79 {"f_blockstotal",rd_blktotal, wr_other},
80 {"f_blocksfree",rd_blkfree, wr_other},
81 {"f_kbytesfree", rd_kbfree, wr_other},
82 {"f_objects", rd_numobjects, wr_other},
83 {"f_objectsfree", rd_objfree, wr_other},
84 {"f_objectgroups", rd_objgroups, wr_other},
92 * Common OBD namespace for lprocFS (these are used very often)
95 char* obd_dir_nm_1[]= {
104 lprocfs_vars_t obd_var_nm_1[]= {
105 {"num_ops", lprocfs_ll_rd, lprocfs_ll_wr},
106 {"min_time", lprocfs_ll_rd, lprocfs_ll_wr},
107 {"max_time", lprocfs_ll_rd, lprocfs_ll_wr},
108 {"sum_time", lprocfs_ll_rd, lprocfs_ll_wr},
114 * MDC Spcific namespace for lprocFS
117 char *mdc_dir_nm_1[]= {
136 * Create the MDC groupings
138 lprocfs_group_t lprocfs_mdc_nm[]= {
140 {obd_dir_nm_1, obd_var_nm_1, e_generic},
141 {mdc_dir_nm_1, obd_var_nm_1, e_generic},
142 {snmp_dir_nm, snmp_var_nm, e_specific},
147 * MDS Device Groupings
149 char *mds_dir_nm_1[]={
152 "disconnect_callback",
172 char *mds_dir_nm_2[]={
178 lprocfs_vars_t mds_var_nm_2[]={
179 {"f_type", rd_fs_type, wr_other},
180 {"f_bsize",rd_other, wr_other},
181 {"f_blocks",rd_other, wr_other},
182 {"f_bfree",rd_other, wr_other},
183 {"f_bavail",rd_other, wr_other},
184 {"uuid",rd_string, wr_string},
190 char *mds_snmp_dir_nm_1[] = {
196 lprocfs_vars_t mds_snmp_var_nm_1[] = {
197 {"f_fstype", rd_fs_type, wr_other},
198 {"f_files",rd_other, wr_other},
199 {"f_inodesfree",rd_other, wr_other},
200 {"f_filesets",rd_other, wr_other},
204 lprocfs_group_t lprocfs_mds_nm[]={
205 {obd_dir_nm_1, obd_var_nm_1, e_generic},
206 {mds_dir_nm_1, obd_var_nm_1, e_generic},
207 /* {mds_dir_nm_2, mds_var_nm_2, e_specific}, */
208 {snmp_dir_nm, snmp_var_nm, e_specific},
209 {mds_snmp_dir_nm_1, mds_snmp_var_nm_1, e_specific},
217 char* osc_dir_nm_1[]={
231 lprocfs_group_t lprocfs_osc_nm[]={
232 {obd_dir_nm_1, obd_var_nm_1, e_generic},
233 {osc_dir_nm_1, obd_var_nm_1, e_generic},
234 {snmp_dir_nm, snmp_var_nm, e_specific},
240 * OST, LOV, OBD_FILTER namespace
241 * Note: These namespaces are exactly similar to the osc_dir_namespace
242 * Hence, I use the osc namespace as the base class and add only
243 * those attributes that are missing in osc_dir_namespace.
246 char *ost_lov_obdfilter_dir_nm_1[]={
255 char *ost_lov_obdfilter_dir_nm_2[]={
260 lprocfs_vars_t ost_lov_obdfilter_var_nm_2[]={
261 {"f_type", rd_fs_type, wr_other},
262 {"f_bsize",rd_other, wr_other},
263 {"f_blocks",rd_other, wr_other},
264 {"f_bfree",rd_other, wr_other},
265 {"f_bavail",rd_other, wr_other},
266 {"f_objects", rd_other, wr_other},
267 {"f_ofree", rd_other, wr_other},
268 {"f_objectgroups", rd_other, wr_other},
269 {"f_uuid", rd_string, wr_string},
275 char* obdfilter_snmp_dir_nm_1[] = {
279 lprocfs_vars_t obdfilter_snmp_var_nm_1[] = {
280 {"f_fstype", rd_other, wr_other},
281 {"f_inodestotal", rd_other, wr_other},
282 {"f_inodesfree", rd_other, wr_other},
287 lprocfs_group_t lprocfs_ost_nm[] = {
288 {obd_dir_nm_1, obd_var_nm_1, e_generic},
289 {osc_dir_nm_1, obd_var_nm_1, e_generic},
290 {ost_lov_obdfilter_dir_nm_1, obd_var_nm_1, e_generic},
291 /* {ost_lov_obdfilter_dir_nm_2, ost_lov_obdfilter_var_nm_2, e_specific}, */
292 {snmp_dir_nm, snmp_var_nm, e_specific},
296 char* lov_snmp_dir_nm_1[] = {
300 lprocfs_vars_t lov_snmp_var_nm_1[] = {
301 {"lov_stripesize", rd_other, wr_other},
302 {"lov_stripedepth", rd_other, wr_other},
303 {"lov_stripefactor", rd_other, wr_other},
304 {"lov_stripetype", rd_other, wr_other},
308 lprocfs_group_t lprocfs_lov_nm[] = {
309 {obd_dir_nm_1, obd_var_nm_1, e_generic},
310 {osc_dir_nm_1, obd_var_nm_1, e_generic},
311 {ost_lov_obdfilter_dir_nm_1, obd_var_nm_1, e_generic},
312 /* {ost_lov_obdfilter_dir_nm_2, ost_lov_obdfilter_var_nm_2, e_specific}, */
313 {snmp_dir_nm, snmp_var_nm, e_specific},
314 {lov_snmp_dir_nm_1, lov_snmp_var_nm_1, e_specific},
318 lprocfs_group_t lprocfs_obdf_nm[] = {
319 {obd_dir_nm_1, obd_var_nm_1, e_generic},
320 {osc_dir_nm_1, obd_var_nm_1, e_generic},
321 {ost_lov_obdfilter_dir_nm_1, obd_var_nm_1, e_generic},
322 /* {ost_lov_obdfilter_dir_nm_2, ost_lov_obdfilter_var_nm_2, e_specific}, */
323 {snmp_dir_nm, snmp_var_nm, e_specific},
324 {obdfilter_snmp_dir_nm_1, obdfilter_snmp_var_nm_1, e_specific},
330 * LDLM Device namespace
334 char* ldlm_dir_nm_1[]={
343 lprocfs_vars_t ldlm_var_nm_1[]= {
344 {"num_total", lprocfs_ll_rd, lprocfs_ll_wr},
345 {"num_zerolatency", lprocfs_ll_rd, lprocfs_ll_wr},
346 {"num_zerolatency_inflight", lprocfs_ll_rd, lprocfs_ll_wr},
347 {"num_zerolatency_done", lprocfs_ll_rd, lprocfs_ll_wr},
348 {"nonzero_mintime", lprocfs_ll_rd, lprocfs_ll_wr},
349 {"nonzero_maxtime", lprocfs_ll_rd, lprocfs_ll_wr},
350 {"nonzero_sumtime", lprocfs_ll_rd, lprocfs_ll_wr},
355 lprocfs_group_t lprocfs_ldlm_nm[]={
356 {obd_dir_nm_1, obd_var_nm_1, e_generic},
357 {ldlm_dir_nm_1, ldlm_var_nm_1, e_generic},
362 * Note: Need to add namespace for breaking out locks by device class
368 char* ptlrpc_dir_nm_1[]={
373 lprocfs_vars_t ptlrpc_var_nm_1[]={
374 {"msgs_alloc", lprocfs_ll_rd, lprocfs_ll_wr},
375 {"msgs_max", lprocfs_ll_rd, lprocfs_ll_wr},
376 {"recv_count", lprocfs_ll_rd, lprocfs_ll_wr},
377 {"recv_length", lprocfs_ll_rd, lprocfs_ll_wr},
378 {"send_count", lprocfs_ll_rd, lprocfs_ll_wr},
379 {"send_length", lprocfs_ll_rd, lprocfs_ll_wr},
380 {"portal_kmemory", lprocfs_ll_rd, lprocfs_ll_wr},
384 char* ptlrpc_dir_nm_2[] = {
389 lprocfs_vars_t ptlrpc_var_nm_2[] = {
390 {"type", rd_string, wr_string},
391 {"mtu", lprocfs_ll_rd, lprocfs_ll_wr},
392 {"rxpackets", lprocfs_ll_rd, lprocfs_ll_wr},
393 {"txpackets", lprocfs_ll_rd, lprocfs_ll_wr},
394 {"txbytes", lprocfs_ll_rd, lprocfs_ll_wr},
398 lprocfs_group_t lprocfs_ptlrpc_nm[]={
399 {obd_dir_nm_1, obd_var_nm_1, e_generic},
400 {ptlrpc_dir_nm_1, ptlrpc_var_nm_1, e_generic},
401 {ptlrpc_dir_nm_2, ptlrpc_var_nm_2, e_specific},
402 {snmp_dir_nm, snmp_var_nm, e_specific},
408 * Building the entire device namespace. This will be used during attach and
409 * detach to associate the namespace with the class of the device
412 lprocfs_obd_nm_t obd_nm[]={
413 {"mdc", lprocfs_mdc_nm, sizeof(struct lprofiler_gen)},
414 {"mds", lprocfs_mds_nm, sizeof(struct lprofiler_gen)},
415 {"osc", lprocfs_osc_nm, sizeof(struct lprofiler_gen)},
416 {"ost", lprocfs_ost_nm, sizeof(struct lprofiler_gen)},
417 {"lov", lprocfs_lov_nm, sizeof(struct lprofiler_gen)},
418 {"obdfilter", lprocfs_obdf_nm, sizeof(struct lprofiler_gen)},
419 {"obdecho", lprocfs_ost_nm, sizeof(struct lprofiler_gen)},
420 {"ldlm", lprocfs_ldlm_nm, sizeof(struct lprofiler_ldlm)},
421 {"ptlrpc", lprocfs_ptlrpc_nm, sizeof(struct lprofiler_ptlrpc)},
427 lprocfs_obd_nm_t* obd_nm=0;
431 /* opening /dev/obd */
432 static int obd_class_open(struct inode * inode, struct file * file)
436 file->private_data = NULL;
437 CDEBUG(D_IOCTL, "MOD_INC_USE for open: count = %d\n",
438 atomic_read(&(THIS_MODULE)->uc.usecount));
443 /* closing /dev/obd */
444 static int obd_class_release(struct inode * inode, struct file * file)
448 // XXX drop lsm, connections here
449 if (file->private_data)
450 file->private_data = NULL;
452 CDEBUG(D_IOCTL, "MOD_DEC_USE for close: count = %d\n",
453 atomic_read(&(THIS_MODULE)->uc.usecount) - 1);
459 inline void obd_data2conn(struct lustre_handle *conn, struct obd_ioctl_data *data)
461 conn->addr = data->ioc_addr;
462 conn->cookie = data->ioc_cookie;
466 inline void obd_conn2data(struct obd_ioctl_data *data, struct lustre_handle *conn)
468 data->ioc_addr = conn->addr;
469 data->ioc_cookie = conn->cookie;
473 /* to control /dev/obd */
474 static int obd_class_ioctl (struct inode * inode, struct file * filp,
475 unsigned int cmd, unsigned long arg)
479 struct obd_ioctl_data *data;
480 struct obd_device *obd = filp->private_data;
482 struct lustre_handle conn;
483 int rw = OBD_BRW_READ;
491 case OBD_IOC_BRW_WRITE:
492 case OBD_IOC_BRW_READ:
493 case OBD_IOC_GETATTR:
501 if (!obd && cmd != OBD_IOC_DEVICE && cmd != TCGETS &&
502 cmd != OBD_IOC_LIST &&
503 cmd != OBD_IOC_NAME2DEV && cmd != OBD_IOC_NEWDEV) {
504 CERROR("OBD ioctl: No device\n");
505 GOTO(out, err=-EINVAL);
507 if (obd_ioctl_getdata(&buf, &len, (void *)arg)) {
508 CERROR("OBD ioctl: data error\n");
509 GOTO(out, err=-EINVAL);
511 data = (struct obd_ioctl_data *)buf;
515 GOTO(out, err=-EINVAL);
516 case OBD_IOC_DEVICE: {
517 CDEBUG(D_IOCTL, "\n");
518 if (data->ioc_dev >= MAX_OBD_DEVICES || data->ioc_dev < 0) {
519 CERROR("OBD ioctl: DEVICE insufficient devices\n");
520 GOTO(out, err=-EINVAL);
522 CDEBUG(D_IOCTL, "device %d\n", data->ioc_dev);
524 filp->private_data = &obd_dev[data->ioc_dev];
530 char *buf2 = data->ioc_bulk;
531 int remains = data->ioc_inllen1;
533 if (!data->ioc_inlbuf1) {
534 CERROR("No buffer passed!\n");
535 GOTO(out, err=-EINVAL);
539 for (i = 0 ; i < MAX_OBD_DEVICES ; i++) {
542 struct obd_device *obd = &obd_dev[i];
545 if (obd->obd_flags & OBD_SET_UP)
547 else if (obd->obd_flags & OBD_ATTACHED)
551 l = snprintf(buf2, remains, "%2d %s %s %s %s %d\n",
552 i, status, obd->obd_type->typ_name,
553 obd->obd_name, obd->obd_uuid, obd->obd_type->typ_refcnt);
557 CERROR("not enough space for device listing\n");
562 err = copy_to_user((int *)arg, data, len);
567 case OBD_IOC_NAME2DEV: {
568 /* Resolve a device name. This does not change the
569 * currently selected device.
573 if (!data->ioc_inllen1 || !data->ioc_inlbuf1 ) {
574 CERROR("No name passed,!\n");
575 GOTO(out, err=-EINVAL);
577 if (data->ioc_inlbuf1[data->ioc_inllen1-1] !=0) {
578 CERROR("Name not nul terminated!\n");
579 GOTO(out, err=-EINVAL);
582 CDEBUG(D_IOCTL, "device name %s\n", data->ioc_inlbuf1);
583 dev = class_name2dev(data->ioc_inlbuf1);
586 CDEBUG(D_IOCTL, "No device for name %s!\n",
588 GOTO(out, err=-EINVAL);
591 CDEBUG(D_IOCTL, "device name %s, dev %d\n", data->ioc_inlbuf1,
593 err = copy_to_user((int *)arg, data, sizeof(*data));
597 case OBD_IOC_UUID2DEV: {
598 /* Resolve a device uuid. This does not change the
599 * currently selected device.
603 if (!data->ioc_inllen1 || !data->ioc_inlbuf1) {
604 CERROR("No UUID passed!\n");
605 GOTO(out, err=-EINVAL);
607 if (data->ioc_inlbuf1[data->ioc_inllen1-1] !=0) {
608 CERROR("Name not nul terminated!\n");
609 GOTO(out, err=-EINVAL);
612 CDEBUG(D_IOCTL, "device name %s\n", data->ioc_inlbuf1);
613 dev = class_uuid2dev(data->ioc_inlbuf1);
616 CDEBUG(D_IOCTL, "No device for name %s!\n",
618 GOTO(out, err=-EINVAL);
621 CDEBUG(D_IOCTL, "device name %s, dev %d\n", data->ioc_inlbuf1,
623 err = copy_to_user((int *)arg, data, sizeof(*data));
627 case OBD_IOC_NEWDEV: {
631 filp->private_data = NULL;
632 for (i = 0 ; i < MAX_OBD_DEVICES ; i++) {
633 struct obd_device *obd = &obd_dev[i];
634 if (!obd->obd_type) {
635 filp->private_data = obd;
644 GOTO(out, err=-EINVAL);
646 err = copy_to_user((int *)arg, data, sizeof(*data));
650 case OBD_IOC_ATTACH: {
651 struct obd_type *type;
654 /* have we attached a type to this device */
655 if (obd->obd_flags & OBD_ATTACHED || obd->obd_type) {
656 CERROR("OBD: Device %d already typed as %s.\n",
657 obd->obd_minor, MKSTR(obd->obd_type->typ_name));
658 GOTO(out, err=-EBUSY);
661 if (!data->ioc_inllen1 || !data->ioc_inlbuf1) {
662 CERROR("No type passed!\n");
663 GOTO(out, err=-EINVAL);
665 if (data->ioc_inlbuf1[data->ioc_inllen1-1] !=0) {
666 CERROR("Type not nul terminated!\n");
667 GOTO(out, err=-EINVAL);
670 CDEBUG(D_IOCTL, "attach type %s name: %s uuid: %s\n",
671 MKSTR(data->ioc_inlbuf1),
672 MKSTR(data->ioc_inlbuf2), MKSTR(data->ioc_inlbuf3));
675 type = class_nm_to_type(data->ioc_inlbuf1);
677 CERROR("OBD: unknown type dev %d\n", obd->obd_minor);
678 GOTO(out, err=-EINVAL);
681 minor = obd->obd_minor;
682 memset(obd, 0, sizeof(*obd));
683 obd->obd_minor = minor;
684 obd->obd_type = type;
685 INIT_LIST_HEAD(&obd->obd_exports);
686 INIT_LIST_HEAD(&obd->obd_imports);
687 spin_lock_init(&obd->obd_dev_lock);
690 if (OBP(obd, attach))
691 err = OBP(obd,attach)(obd, sizeof(*data), data);
693 obd->obd_type = NULL;
695 obd->obd_flags |= OBD_ATTACHED;
698 CDEBUG(D_IOCTL, "OBD: dev %d attached type %s\n",
699 obd->obd_minor, data->ioc_inlbuf1);
700 if (data->ioc_inlbuf2) {
701 int len = strlen(data->ioc_inlbuf2) + 1;
702 OBD_ALLOC(obd->obd_name, len);
703 if (!obd->obd_name) {
704 CERROR("no memory\n");
707 memcpy(obd->obd_name, data->ioc_inlbuf2, len);
708 /* obd->obd_proc_entry =
709 proc_lustre_register_obd_device(obd);
712 CERROR("WARNING: unnamed obd device\n");
713 obd->obd_proc_entry = NULL;
716 if (data->ioc_inlbuf3) {
717 int len = strlen(data->ioc_inlbuf3);
718 if (len >= sizeof(obd->obd_uuid)) {
719 CERROR("uuid must be < %d bytes long\n",
720 sizeof(obd->obd_uuid));
722 OBD_FREE(obd->obd_name,
723 strlen(obd->obd_name) + 1);
724 GOTO(out, err=-EINVAL);
726 memcpy(obd->obd_uuid, data->ioc_inlbuf3, len);
728 /* Get the LprocFS namespace for this device class */
730 l_idx = lprocfs_get_nm(data->ioc_inlbuf1, obd_nm);
732 CERROR("Non-existent device class"
733 "or proc/lustre not compiled \n");
735 lprocfs_reg_dev(obd, obd_nm[l_idx].obd_names,
736 obd_nm[l_idx].cntr_blk_sz);
739 CDEBUG(D_IOCTL, "MOD_INC_USE for attach: count = %d\n",
740 atomic_read(&(THIS_MODULE)->uc.usecount));
747 case OBD_IOC_DETACH: {
749 if (obd->obd_flags & OBD_SET_UP) {
750 CERROR("OBD device %d still set up\n", obd->obd_minor);
751 GOTO(out, err=-EBUSY);
753 if (!(obd->obd_flags & OBD_ATTACHED) ) {
754 CERROR("OBD device %d not attached\n", obd->obd_minor);
755 GOTO(out, err=-ENODEV);
757 #warning FIXME: Mike, we probably need some sort of "force detach" here
758 if (!list_empty(&obd->obd_exports) ) {
759 CERROR("OBD device %d (%p) has exports\n",
760 obd->obd_minor, obd);
761 GOTO(out, err=-EBUSY);
765 if (lprocfs_dereg_dev(obd) != LPROCFS_SUCCESS) {
766 CERROR("Could not remove /proc entry\n");
770 OBD_FREE(obd->obd_name, strlen(obd->obd_name)+1);
771 obd->obd_name = NULL;
774 if (obd->obd_proc_entry)
775 proc_lustre_release_obd_device(obd);
778 obd->obd_flags &= ~OBD_ATTACHED;
779 obd->obd_type->typ_refcnt--;
780 obd->obd_type = NULL;
781 CDEBUG(D_IOCTL, "MOD_DEC_USE for detach: count = %d\n",
782 atomic_read(&(THIS_MODULE)->uc.usecount) - 1);
787 case OBD_IOC_SETUP: {
788 /* have we attached a type to this device? */
789 if (!(obd->obd_flags & OBD_ATTACHED)) {
790 CERROR("Device %d not attached\n", obd->obd_minor);
791 GOTO(out, err=-ENODEV);
794 /* has this been done already? */
795 if ( obd->obd_flags & OBD_SET_UP ) {
796 CERROR("Device %d already setup (type %s)\n",
797 obd->obd_minor, obd->obd_type->typ_name);
798 GOTO(out, err=-EBUSY);
801 if ( OBT(obd) && OBP(obd, setup) )
802 err = obd_setup(obd, sizeof(*data), data);
805 obd->obd_type->typ_refcnt++;
806 obd->obd_flags |= OBD_SET_UP;
811 case OBD_IOC_CLEANUP: {
812 /* have we attached a type to this device? */
813 if (!(obd->obd_flags & OBD_ATTACHED)) {
814 CERROR("Device %d not attached\n", obd->obd_minor);
815 GOTO(out, err=-ENODEV);
818 if ( OBT(obd) && OBP(obd, cleanup) )
819 err = obd_cleanup(obd);
822 obd->obd_flags &= ~OBD_SET_UP;
823 obd->obd_type->typ_refcnt--;
828 case OBD_IOC_CONNECT: {
829 char * cluuid = "OBD_CLASS_UUID";
830 obd_data2conn(&conn, data);
832 err = obd_connect(&conn, obd, cluuid);
834 CDEBUG(D_IOCTL, "assigned export "LPX64"\n", conn.addr);
835 obd_conn2data(data, &conn);
839 err = copy_to_user((int *)arg, data, sizeof(*data));
840 // XXX save connection data into file handle
844 case OBD_IOC_DISCONNECT: {
845 obd_data2conn(&conn, data);
846 err = obd_disconnect(&conn);
850 case OBD_IOC_DEC_USE_COUNT: {
851 CDEBUG(D_IOCTL, "MOD_DEC_USE for force dec: count = %d\n",
852 atomic_read(&(THIS_MODULE)->uc.usecount) - 1);
857 case OBD_IOC_CREATE: {
858 struct lov_stripe_md *lsm = NULL;
859 obd_data2conn(&conn, data);
861 #warning FIXME: save lsm into file handle for other ops, release on close
862 err = obd_create(&conn, &data->ioc_obdo1, &lsm);
866 err = copy_to_user((int *)arg, data, sizeof(*data));
870 case OBD_IOC_GETATTR: {
872 obd_data2conn(&conn, data);
873 err = obd_getattr(&conn, &data->ioc_obdo1, NULL);
877 err = copy_to_user((int *)arg, data, sizeof(*data));
881 case OBD_IOC_SETATTR: {
882 obd_data2conn(&conn, data);
883 err = obd_setattr(&conn, &data->ioc_obdo1, NULL);
887 err = copy_to_user((int *)arg, data, sizeof(*data));
891 case OBD_IOC_DESTROY: {
893 obd_data2conn(&conn, data);
895 err = obd_destroy(&conn, &data->ioc_obdo1, NULL);
899 err = copy_to_user((int *)arg, data, sizeof(*data));
904 struct lov_stripe_md *lsm = NULL; // XXX fill in from create
906 obd_data2conn(&conn, data);
907 err = obd_open(&conn, &data->ioc_obdo1, lsm);
911 case OBD_IOC_CLOSE: {
912 struct lov_stripe_md *lsm = NULL; // XXX fill in from create
914 obd_data2conn(&conn, data);
915 obd_data2conn(&conn, data);
916 err = obd_close(&conn, &data->ioc_obdo1, lsm);
920 case OBD_IOC_BRW_WRITE:
922 case OBD_IOC_BRW_READ: {
923 struct lov_stripe_md tmp_lsm; // XXX fill in from create
924 struct lov_stripe_md *lsm = &tmp_lsm; // XXX fill in from create
925 struct io_cb_data *cbd = ll_init_cb();
927 struct brw_page *pga, *pgp;
928 __u64 id = data->ioc_obdo1.o_id;
929 int gfp_mask = (id & 1) ? GFP_HIGHUSER : GFP_KERNEL;
930 int verify = (id != 0);
935 GOTO(out, err = -ENOMEM);
937 obd_data2conn(&conn, data);
939 pages = data->ioc_count / PAGE_SIZE;
940 off = data->ioc_offset;
942 CDEBUG(D_INODE, "BRW %s with %d pages @ "LPX64"\n",
943 rw == OBD_BRW_READ ? "read" : "write", pages, off);
944 OBD_ALLOC(pga, pages * sizeof(*pga));
946 CERROR("no memory for %d BRW per-page data\n", pages);
947 GOTO(brw_free, err = -ENOMEM);
950 memset(lsm, 0, sizeof(*lsm)); // XXX don't do this later
951 lsm->lsm_object_id = id; // ensure id == lsm->lsm_object_id
953 for (j = 0, pgp = pga; j < pages; j++, off += PAGE_SIZE, pgp++){
954 pgp->pg = alloc_pages(gfp_mask, 0);
956 CERROR("no memory for brw pages\n");
957 GOTO(brw_cleanup, err = -ENOMEM);
959 pgp->count = PAGE_SIZE;
964 void *addr = kmap(pgp->pg);
966 if (rw == OBD_BRW_WRITE)
967 page_debug_setup(addr, pgp->count,
970 page_debug_setup(addr, pgp->count,
977 err = obd_brw(rw, &conn, lsm, j, pga, ll_sync_io_cb, cbd);
979 CERROR("test_brw: error from obd_brw: err = %d\n", err);
982 for (j = 0, pgp = pga; j < pages; j++, pgp++) {
983 if (pgp->pg != NULL) {
984 if (verify && !err) {
985 void *addr = kmap(pgp->pg);
987 err = page_debug_check("test_brw",
993 __free_pages(pgp->pg, 0);
997 OBD_FREE(pga, pages * sizeof(*pga));
1001 obd_data2conn(&conn, data);
1003 err = obd_iocontrol(cmd, &conn, len, data, NULL);
1007 err = copy_to_user((int *)arg, data, len);
1017 } /* obd_class_ioctl */
1021 /* declare character device */
1022 static struct file_operations obd_psdev_fops = {
1023 ioctl: obd_class_ioctl, /* ioctl */
1024 open: obd_class_open, /* open */
1025 release: obd_class_release, /* release */
1029 #define OBD_MINOR 241
1030 static struct miscdevice obd_psdev = {
1036 void (*class_signal_connection_failure)(struct ptlrpc_connection *);
1038 EXPORT_SYMBOL(obd_dev);
1039 EXPORT_SYMBOL(obdo_cachep);
1040 EXPORT_SYMBOL(obd_memory);
1041 EXPORT_SYMBOL(obd_fail_loc);
1042 EXPORT_SYMBOL(obd_timeout);
1043 EXPORT_SYMBOL(obd_recovery_upcall);
1045 EXPORT_SYMBOL(class_register_type);
1046 EXPORT_SYMBOL(class_unregister_type);
1047 EXPORT_SYMBOL(class_name2dev);
1048 EXPORT_SYMBOL(class_uuid2dev);
1049 EXPORT_SYMBOL(class_uuid2obd);
1050 EXPORT_SYMBOL(class_new_export);
1051 EXPORT_SYMBOL(class_destroy_export);
1052 EXPORT_SYMBOL(class_connect);
1053 EXPORT_SYMBOL(class_conn2export);
1054 EXPORT_SYMBOL(class_conn2obd);
1055 EXPORT_SYMBOL(class_conn2cliimp);
1056 EXPORT_SYMBOL(class_conn2ldlmimp);
1057 EXPORT_SYMBOL(class_disconnect);
1058 EXPORT_SYMBOL(class_disconnect_all);
1059 //EXPORT_SYMBOL(class_uuid_parse);
1060 EXPORT_SYMBOL(class_uuid_unparse);
1061 //EXPORT_SYMBOL(class_multi_setup);
1062 //EXPORT_SYMBOL(class_multi_cleanup);
1064 EXPORT_SYMBOL(class_signal_connection_failure);
1065 EXPORT_SYMBOL(ll_sync_io_cb);
1066 EXPORT_SYMBOL(ll_init_cb);
1068 static int __init init_obdclass(void)
1070 struct obd_device *obd;
1074 printk(KERN_INFO "OBD class driver v0.9, info@clusterfs.com\n");
1076 sema_init(&obd_conf_sem, 1);
1077 INIT_LIST_HEAD(&obd_types);
1079 if ((err = misc_register(&obd_psdev))) {
1080 CERROR("cannot register %d err %d\n", OBD_MINOR, err);
1084 /* This struct is already zerod for us (static global) */
1085 for (i = 0, obd = obd_dev; i < MAX_OBD_DEVICES; i++, obd++)
1088 err = obd_init_caches();
1095 static void __exit cleanup_obdclass(void)
1100 misc_deregister(&obd_psdev);
1101 for (i = 0; i < MAX_OBD_DEVICES; i++) {
1102 struct obd_device *obd = &obd_dev[i];
1103 if (obd->obd_type && (obd->obd_flags & OBD_SET_UP) &&
1104 OBT(obd) && OBP(obd, detach)) {
1105 /* XXX should this call generic detach otherwise? */
1106 OBP(obd, detach)(obd);
1110 obd_cleanup_caches();
1112 CERROR("obd memory leaked: %ld bytes\n", obd_memory);
1116 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
1117 MODULE_DESCRIPTION("Lustre Class Driver v1.0");
1118 MODULE_LICENSE("GPL");
1120 module_init(init_obdclass);
1121 module_exit(cleanup_obdclass);