Whamcloud - gitweb
Numerous changes:
[fs/lustre-release.git] / lustre / obdclass / class_obd.c
index bf57215..545f66b 100644 (file)
@@ -6,8 +6,7 @@
  *
  *              This program is free software; you can redistribute it and/or
  *              modify it under the terms of the GNU General Public License
- *              as published by the Free Software Foundation; either version
- *              2 of the License, or (at your option) any later version.
+ *              version 2 as published by the Free Software Foundation.
  * 
  *              Adapted to become the Linux 2.0 Coda pseudo device
  *              Peter  Braam  <braam@maths.ox.ac.uk> 
@@ -29,7 +28,6 @@
  */
 
 #define EXPORT_SYMTAB
-
 #include <linux/config.h> /* for CONFIG_PROC_FS */
 #include <linux/module.h>
 #include <linux/errno.h>
 #include <linux/init.h>
 #include <linux/list.h>
 #include <asm/io.h>
-#include <asm/segment.h>
 #include <asm/system.h>
 #include <asm/poll.h>
 #include <asm/uaccess.h>
+#include <linux/miscdevice.h>
 
 #include <linux/obd_support.h>
 #include <linux/obd_class.h>
@@ -65,53 +63,26 @@ long obd_memory = 0;
 struct obd_device obd_dev[MAX_OBD_DEVICES];
 struct list_head obd_types;
 
-/* called when opening /dev/obdNNN */
+/*  opening /dev/obd */
 static int obd_class_open(struct inode * inode, struct file * file)
 {
-        int dev;
         ENTRY;
 
-        if (!inode)
-                return -EINVAL;
-        dev = MINOR(inode->i_rdev);
-        if (dev >= MAX_OBD_DEVICES)
-                return -ENODEV;
-        obd_dev[dev].obd_refcnt++;
-        CDEBUG(D_PSDEV, "Dev %d refcount now %d\n", dev,
-               obd_dev[dev].obd_refcnt);
-
-       obd_dev[dev].obd_proc_entry = 
-               proc_lustre_register_obd_device(&obd_dev[dev]);
-
+       file->private_data = NULL;
         MOD_INC_USE_COUNT;
         EXIT;
         return 0;
 }
 
-/* called when closing /dev/obdNNN */
+/*  closing /dev/obd */
 static int obd_class_release(struct inode * inode, struct file * file)
 {
-        int dev;
         ENTRY;
 
-        if (!inode)
-                return -EINVAL;
-        dev = MINOR(inode->i_rdev);
-        if (dev >= MAX_OBD_DEVICES)
-                return -ENODEV;
-        fsync_dev(inode->i_rdev);
-        if (obd_dev[dev].obd_refcnt <= 0)
-                printk(KERN_ALERT __FUNCTION__ ": refcount(%d) <= 0\n",
-                       obd_dev[dev].obd_refcnt);
-        obd_dev[dev].obd_refcnt--;
-
-       if (obd_dev[dev].obd_proc_entry && (obd_dev[dev].obd_refcnt==0))
-               proc_lustre_release_obd_device(&obd_dev[dev]);
-
-        CDEBUG(D_PSDEV, "Dev %d refcount now %d\n", dev,
-               obd_dev[dev].obd_refcnt);
-        MOD_DEC_USE_COUNT;
+       if (file->private_data)
+               file->private_data = NULL;
 
+        MOD_DEC_USE_COUNT;
         EXIT;
         return 0;
 }
@@ -155,337 +126,251 @@ static struct obd_type *obd_nm_to_type(char *nm)
         return type;
 }
 
-
-static int getdata(int len, void **data)
-{
-        void *tmp = NULL;
-
-        if (!len) {
-                *data = NULL;
-                return 0;
-        }
-
-        CDEBUG(D_MALLOC, "len %d, add %p\n", len, *data);
-
-        OBD_ALLOC(tmp, void *, len);
-        if ( !tmp )
-                return -ENOMEM;
-        
-        memset(tmp, 0, len);
-        if ( copy_from_user(tmp, *data, len)) {
-                OBD_FREE(tmp, len);
-                return -EFAULT;
-        }
-        *data = tmp;
-
-        return 0;
-}
-
-/* to control /dev/obdNNN */
+/* to control /dev/obd */
 static int obd_class_ioctl (struct inode * inode, struct file * filp, 
                             unsigned int cmd, unsigned long arg)
 {
-        struct obd_device *obddev;
         /* NOTE this must be larger than any of the ioctl data structs */
         char buf[1024];
-        void *tmp_buf = buf;
-        struct obd_conn conn;
-        int err, dev;
-        long int cli_id; /* connect, disconnect */
-
-        if (!inode) {
-                CDEBUG(D_IOCTL, "invalid inode\n");
-                return -EINVAL;
-        }
-
-        dev = MINOR(inode->i_rdev);
-        if (dev > MAX_OBD_DEVICES)
-                return -ENODEV;
-        obddev = &obd_dev[dev];
-        conn.oc_dev = obddev;
+       struct obd_ioctl_data *data;
+       struct obd_device *obd = filp->private_data;
+       struct obd_conn conn;
+        int err = 0;
+       ENTRY;
+
+       memset(buf, 0, sizeof(buf));
+
+       if (!obd && cmd != OBD_IOC_DEVICE && cmd != TCGETS) {
+               printk("OBD ioctl: No device\n");
+               return -EINVAL;
+       } 
+       if (obd_ioctl_getdata(buf, buf + 800, (void *)arg)) { 
+               printk("OBD ioctl: data error\n");
+               return -EINVAL;
+       }
+       data = (struct obd_ioctl_data *)buf;
 
         switch (cmd) {
         case TCGETS:
                 return -EINVAL;
+       case OBD_IOC_DEVICE: { 
+               CDEBUG(D_IOCTL, "\n");
+               if (data->ioc_dev >= MAX_OBD_DEVICES ||
+                   data->ioc_dev < 0) { 
+                       printk("OBD ioctl: DEVICE insufficient devices\n");
+                       return -EINVAL;
+               }
+               CDEBUG(D_IOCTL, "device %d\n", data->ioc_dev);
+
+               filp->private_data = &obd_dev[data->ioc_dev];
+               EXIT;
+               return 0;
+       }
+
         case OBD_IOC_ATTACH: {
                 struct obd_type *type;
-                struct oic_generic *input = tmp_buf;
-                char *nm;
 
                 ENTRY;
                 /* have we attached a type to this device */
-                if ( obddev->obd_type || 
-                     (obddev->obd_flags & OBD_ATTACHED) ){
-                       char *name;
-                       if (obddev->obd_type->typ_name) 
-                               name = obddev->obd_type->typ_name; 
-                       else 
-                               name = "";
-                        CDEBUG(D_IOCTL,
-                               "OBD Device %d already attached to type %s.\n",
-                               dev, name);
-                        EXIT;
+                if ( obd->obd_type ||  (obd->obd_flags & OBD_ATTACHED) ){
+                        printk("OBD: Device %d already typed as  %s.\n",
+                               obd->obd_minor, MKSTR(obd->obd_type->typ_name));
                         return -EBUSY;
                 }
 
-                /* get data structures */
-                err = copy_from_user(input, (void *)arg, sizeof(*input));
-                if ( err ) {
-                        EXIT;
-                        return err;
-                }
-
-                err = getdata(input->att_typelen + 1, &input->att_type);
-                if ( err ) {
-                        EXIT;
-                        return err;
-                }
+               printk("-----> attach %s %s\n",  MKSTR(data->ioc_inlbuf1), 
+                      MKSTR(data->ioc_inlbuf2));
 
                 /* find the type */
-                nm = input->att_type;
-                type = obd_nm_to_type(nm);
-
-                OBD_FREE(input->att_type, input->att_typelen + 1);
+                type = obd_nm_to_type(data->ioc_inlbuf1);
                 if ( !type ) {
-                        printk(__FUNCTION__ ": unknown obd type dev %d\n",
-                               dev);
-                        EXIT;
+                        printk("OBD: unknown type dev %d\n", obd->obd_minor);
                         return -EINVAL;
                 }
-                obddev->obd_type = type;
-                
-                /* get the attach data */
-                err = getdata(input->att_datalen, &input->att_data);
-                if ( err ) {
-                        EXIT;
-                        return err;
-                }
 
-                INIT_LIST_HEAD(&obddev->obd_gen_clients);
-                obddev->obd_multi_count = 0;
-
-                CDEBUG(D_IOCTL, "Attach %d, datalen %d, type %s\n", 
-                       dev, input->att_datalen, obddev->obd_type->typ_name);
-                /* maybe we are done */
-                if ( !OBT(obddev) || !OBP(obddev, attach) ) {
-                        obddev->obd_flags |= OBD_ATTACHED;
-                        type->typ_refcnt++;
-                        CDEBUG(D_PSDEV, "Dev %d refcount now %d\n", dev,
-                               type->typ_refcnt);
-                        if (input->att_data)
-                                OBD_FREE(input->att_data, input->att_datalen);
-                        MOD_INC_USE_COUNT;
-                        EXIT;
-                        return 0;
-                }
+                obd->obd_type = type;
+                obd->obd_multi_count = 0;
+                INIT_LIST_HEAD(&obd->obd_gen_clients);
 
                 /* do the attach */
-                err = OBP(obddev, attach)(obddev, input->att_datalen,
-                                          input->att_data);
-                if (input->att_data)
-                        OBD_FREE(input->att_data, input->att_datalen);
+                if ( OBT(obd) && OBP(obd, attach) ) {
+                       err = OBP(obd, attach)(obd, data);
+               }
 
                 if ( err ) {
-                        obddev->obd_flags &= ~OBD_ATTACHED;
-                        obddev->obd_type = NULL;
+                        obd->obd_flags &= ~OBD_ATTACHED;
+                        obd->obd_type = NULL;
                         EXIT;
                 } else {
-                        obddev->obd_flags |=  OBD_ATTACHED;
+                        obd->obd_flags |=  OBD_ATTACHED;
                         type->typ_refcnt++;
-                        CDEBUG(D_PSDEV, "Dev %d refcount now %d\n", dev,
-                               type->typ_refcnt);
+                        printk("OBD: dev %d attached type %s\n", 
+                              obd->obd_minor, data->ioc_inlbuf1);
+                       obd->obd_proc_entry = 
+                               proc_lustre_register_obd_device(obd);
                         MOD_INC_USE_COUNT;
                         EXIT;
                 }
+
                 return err;
         }
 
         case OBD_IOC_DETACH: {
-
                 ENTRY;
-                if (obddev->obd_flags & OBD_SET_UP) {
-                        EXIT;
+                if (obd->obd_flags & OBD_SET_UP) {
+                        printk("OBD device %d still set up\n", obd->obd_minor);
                         return -EBUSY;
                 }
-                if (! (obddev->obd_flags & OBD_ATTACHED) ) {
-                        CDEBUG(D_IOCTL, "Device not attached\n");
-                        EXIT;
+                if (! (obd->obd_flags & OBD_ATTACHED) ) {
+                        printk("OBD device %d not attached\n", obd->obd_minor);
                         return -ENODEV;
                 }
-                if ( !list_empty(&obddev->obd_gen_clients) ) {
-                        CDEBUG(D_IOCTL, "Device has connected clients\n");
-                        EXIT;
+                if ( !list_empty(&obd->obd_gen_clients) ) {
+                        printk("OBD device %d has connected clients\n", obd->obd_minor);
                         return -EBUSY;
                 }
 
-                CDEBUG(D_PSDEV, "Detach %d, type %s\n", dev,
-                       obddev->obd_type->typ_name);
-                obddev->obd_flags &= ~OBD_ATTACHED;
-                obddev->obd_type->typ_refcnt--;
-                CDEBUG(D_PSDEV, "Dev %d refcount now %d\n", dev,
-                       obddev->obd_type->typ_refcnt);
-                obddev->obd_type = NULL;
+               if (obd->obd_proc_entry)
+                       proc_lustre_release_obd_device(obd);
+
+                obd->obd_flags &= ~OBD_ATTACHED;
+                obd->obd_type->typ_refcnt--;
+                obd->obd_type = NULL;
                 MOD_DEC_USE_COUNT;
                 EXIT;
                 return 0;
         }
 
         case OBD_IOC_SETUP: {
-                struct ioc_setup {
-                        int setup_datalen;
-                       int setup_rdev;
-                        void *setup_data;
-                } *setup;
-
-                setup = tmp_buf;
-
-
                 ENTRY;
-                /* have we attached a type to this device */
-                if (!(obddev->obd_flags & OBD_ATTACHED)) {
-                        CDEBUG(D_IOCTL, "Device not attached\n");
-                        EXIT;
+                /* have we attached a type to this device? */
+                if (!(obd->obd_flags & OBD_ATTACHED)) {
+                        printk("Device %d not attached\n", obd->obd_minor);
                         return -ENODEV;
                 }
 
                 /* has this been done already? */
-                if ( obddev->obd_flags & OBD_SET_UP ) {
-                        CDEBUG(D_IOCTL, "Device %d already setup (type %s)\n",
-                               dev, obddev->obd_type->typ_name);
-                        EXIT;
+                if ( obd->obd_flags & OBD_SET_UP ) {
+                        printk("Device %d already setup (type %s)\n",
+                               obd->obd_minor, obd->obd_type->typ_name);
                         return -EBUSY;
                 }
 
-               /* get main structure */
-               err = copy_from_user(setup, (void *) arg, sizeof(*setup));
-               if (err) {
-                 EXIT;
-                 return err;
-               }
-
-                /* get the attach data */
-                err = getdata(setup->setup_datalen, &setup->setup_data);
-                if ( err ) {
-                        EXIT;
-                        return err;
-                }
-               obddev->obd_rdev = setup->setup_rdev;
-               obddev->obd_user_name = (char *)setup->setup_data;
-
-                /* do the setup */
-                if ( !OBT(obddev) || !OBP(obddev, setup) ) {
-                        obddev->obd_type->typ_refcnt++;
-                        CDEBUG(D_PSDEV, "Dev %d refcount now %d\n",
-                               dev, obddev->obd_type->typ_refcnt);
-                        if (setup->setup_data)
-                                OBD_FREE(setup->setup_data,
-                                         setup->setup_datalen);
-                        obddev->obd_flags |= OBD_SET_UP;
-                        EXIT;
-                        return 0;
-                }
+                if ( OBT(obd) && OBP(obd, setup) )
+                       err = OBP(obd, setup)(obd, data);
 
-                CDEBUG(D_PSDEV, "Setup %d, type %s device %x, %s, len %d\n", dev, 
-                       obddev->obd_type->typ_name, setup->setup_rdev,
-                      obddev->obd_user_name, setup->setup_datalen);
+               if (!err) { 
+                       obd->obd_type->typ_refcnt++;
+                       obd->obd_flags |= OBD_SET_UP;
+                       EXIT;
+               }
 
-                err = OBP(obddev, setup)(obddev, 0, NULL);
-                          
-                if ( err )  {
-                        obddev->obd_flags &= ~OBD_SET_UP;
-                        EXIT;
-                } else {
-                        obddev->obd_type->typ_refcnt++;
-                        CDEBUG(D_PSDEV, "Dev %d refcount now %d\n",
-                               dev, obddev->obd_type->typ_refcnt);
-                        obddev->obd_flags |= OBD_SET_UP;
-                        EXIT;
-                }
-               // OBD_FREE(setup->setup_data, setup->setup_datalen);
                 return err;
         }
         case OBD_IOC_CLEANUP: {
                 ENTRY;
                 /* has this minor been registered? */
-                if (!obddev->obd_type) {
-                        CDEBUG(D_IOCTL, "OBD Device %d has no type.\n", dev);
+                if (!obd->obd_type) {
+                        printk("OBD cleanup dev %d has no type.\n", 
+                              obd->obd_minor);
                         EXIT;
                         return -ENODEV;
                 }
 
-                if ( !obddev->obd_type->typ_refcnt ) {
-                        CDEBUG(D_IOCTL, "dev %d has refcount (%d)!\n",
-                               dev, obddev->obd_type->typ_refcnt);
-                        EXIT;
-                        return -EBUSY;
-                }
-
-                if ( (!(obddev->obd_flags & OBD_SET_UP)) ||
-                     (!(obddev->obd_flags & OBD_ATTACHED))) {
-                        CDEBUG(D_IOCTL, "device not attached or set up\n");
+                if ( (!(obd->obd_flags & OBD_SET_UP)) ||
+                     (!(obd->obd_flags & OBD_ATTACHED))) {
+                        printk("OBD cleanup device %d not attached/set up\n",
+                              obd->obd_minor);
                         EXIT;
                         return -ENODEV;
                 }
 
-                if ( !OBT(obddev) || !OBP(obddev, cleanup) )
+                if ( !OBT(obd) || !OBP(obd, cleanup) )
                         goto cleanup_out;
 
                 /* cleanup has no argument */
-                err = OBP(obddev, cleanup)(obddev);
+                err = OBP(obd, cleanup)(obd);
                 if ( err ) {
                         EXIT;
                         return err;
                 }
 
         cleanup_out: 
-                obddev->obd_flags &= ~OBD_SET_UP;
-                obddev->obd_type->typ_refcnt--;
-                CDEBUG(D_PSDEV, "Dev %d refcount now %d\n", dev,
-                       obddev->obd_type->typ_refcnt);
+                obd->obd_flags &= ~OBD_SET_UP;
+                obd->obd_type->typ_refcnt--;
                 EXIT;
                 return 0;
         }
+
         case OBD_IOC_CONNECT:
         {
-                if ( (!(obddev->obd_flags & OBD_SET_UP)) ||
-                     (!(obddev->obd_flags & OBD_ATTACHED))) {
+                if ( (!(obd->obd_flags & OBD_SET_UP)) ||
+                     (!(obd->obd_flags & OBD_ATTACHED))) {
                         CDEBUG(D_IOCTL, "Device not attached or set up\n");
                         return -ENODEV;
                 }
 
-                if ( !OBT(obddev) || !OBP(obddev, connect) )
+                if ( !OBT(obd) || !OBP(obd, connect) )
                         return -EOPNOTSUPP;
+
+               conn.oc_id = data->ioc_conn1;
+               conn.oc_dev = obd; 
                 
-                err = OBP(obddev, connect)(&conn);
+                err = OBP(obd, connect)(&conn);
+               CDEBUG(D_IOCTL, "assigned connection %d\n", conn.oc_id);
+               data->ioc_conn1 = conn.oc_id;
                 if ( err )
                         return err;
 
-                return copy_to_user((int *)arg, &conn.oc_id,
-                                    sizeof(uint32_t));
+                return copy_to_user((int *)arg, data, sizeof(*data));
         }
-        case OBD_IOC_DISCONNECT:
-                /* frees data structures */
-                /* has this minor been registered? */
-                if (!obddev->obd_type)
-                        return -ENODEV;
+        case OBD_IOC_DISCONNECT: { 
 
-                get_user(cli_id, (int *) arg);
-                conn.oc_id = cli_id;
+                if (!obd->obd_type)
+                        return -ENODEV;
 
-                if ( !OBT(obddev) || !OBP(obddev, disconnect))
+                if ( !OBT(obd) || !OBP(obd, disconnect))
                         return -EOPNOTSUPP;
                 
-                OBP(obddev, disconnect)(&conn);
+               conn.oc_id = data->ioc_conn1;
+               conn.oc_dev = obd;
+                OBP(obd, disconnect)(&conn);
                 return 0;
-               
-       case OBD_IOC_DEC_USE_COUNT:
+       }               
+
+       case OBD_IOC_DEC_USE_COUNT: { 
                MOD_DEC_USE_COUNT;
                return 0;
+       }
+
+        case OBD_IOC_CREATE: {
+                /* has this minor been registered? */
+                if ( !(obd->obd_flags & OBD_ATTACHED) ||
+                     !(obd->obd_flags & OBD_SET_UP)) {
+                        CDEBUG(D_IOCTL, "Device not attached or set up\n");
+                        return -ENODEV;
+                }
+                conn.oc_id = data->ioc_conn1;
+               conn.oc_dev = obd;
+
+                if ( !OBT(obd) || !OBP(obd, create) )
+                        return -EOPNOTSUPP;
+
+                err = OBP(obd, create)(&conn, &data->ioc_obdo1);
+                if (err) {
+                        EXIT;
+                        return err;
+                }
 
+                err = copy_to_user((int *)arg, data, sizeof(*data));
+                EXIT;
+                return err;
+        }
+#if 0
         case OBD_IOC_SYNC: {
                 struct oic_range_s *range = tmp_buf;
 
-                if (!obddev->obd_type)
+                if (!obd->obd_type)
                         return -ENODEV;
 
                 err = copy_from_user(range, (const void *)arg,  sizeof(*range));
@@ -495,14 +380,14 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp,
                         return err;
                 }
                         
-                if ( !OBT(obddev) || !OBP(obddev, sync) ) {
+                if ( !OBT(obd) || !OBP(obd, sync) ) {
                         err = -EOPNOTSUPP;
                         EXIT;
                         return err;
                 }
 
                 /* XXX sync needs to be tested/verified */
-                err = OBP(obddev, sync)(&conn, &range->obdo, range->count,
+                err = OBP(obd, sync)(&conn, &range->obdo, range->count,
                                         range->offset);
 
                 if ( err ) {
@@ -512,42 +397,12 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp,
                         
                 return put_user(err, (int *) arg);
         }
-        case OBD_IOC_CREATE: {
-                struct oic_attr_s *attr = tmp_buf;
-
-                err = copy_from_user(attr, (const void *)arg,  sizeof(*attr));
-                if (err) {
-                        EXIT;
-                        return err;
-                }
-
-                /* has this minor been registered? */
-                if ( !(obddev->obd_flags & OBD_ATTACHED) ||
-                     !(obddev->obd_flags & OBD_SET_UP)) {
-                        CDEBUG(D_IOCTL, "Device not attached or set up\n");
-                        return -ENODEV;
-                }
-                conn.oc_id = attr->conn_id;
-
-                if ( !OBT(obddev) || !OBP(obddev, create) )
-                        return -EOPNOTSUPP;
-
-                err = OBP(obddev, create)(&conn, &attr->obdo);
-                if (err) {
-                        EXIT;
-                        return err;
-                }
-
-                err = copy_to_user((int *)arg, attr, sizeof(*attr));
-                EXIT;
-                return err;
-        }
 
         case OBD_IOC_DESTROY: {
                 struct oic_attr_s *attr = tmp_buf;
                 
                 /* has this minor been registered? */
-                if (!obddev->obd_type)
+                if (!obd->obd_type)
                         return -ENODEV;
 
                 err = copy_from_user(attr, (int *)arg, sizeof(*attr));
@@ -556,11 +411,11 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp,
                         return err;
                 }
 
-                if ( !OBT(obddev) || !OBP(obddev, destroy) )
+                if ( !OBT(obd) || !OBP(obd, destroy) )
                         return -EOPNOTSUPP;
 
                 conn.oc_id = attr->conn_id;
-                err = OBP(obddev, destroy)(&conn, &attr->obdo);
+                err = OBP(obd, destroy)(&conn, &attr->obdo);
                 EXIT;
                 return err;
         }
@@ -569,18 +424,18 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp,
                 struct oic_attr_s *attr = tmp_buf;
 
                 /* has this minor been registered? */
-                if (!obddev->obd_type)
+                if (!obd->obd_type)
                         return -ENODEV;
 
                 err = copy_from_user(attr, (int *)arg, sizeof(*attr));
                 if (err)
                         return err;
 
-                if ( !OBT(obddev) || !OBP(obddev, setattr) )
+                if ( !OBT(obd) || !OBP(obd, setattr) )
                         return -EOPNOTSUPP;
                 
                 conn.oc_id = attr->conn_id;
-                err = OBP(obddev, setattr)(&conn, &attr->obdo);
+                err = OBP(obd, setattr)(&conn, &attr->obdo);
                 EXIT;
                 return err;
         }
@@ -594,7 +449,7 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp,
 
                 conn.oc_id = attr->conn_id;
                 ODEBUG(&attr->obdo);
-                err = OBP(obddev, getattr)(&conn, &attr->obdo);
+                err = OBP(obd, getattr)(&conn, &attr->obdo);
                 if ( err ) {
                         EXIT;
                         return err;
@@ -617,14 +472,14 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp,
 
                 conn.oc_id = rw_s->conn_id;
 
-                if ( !OBT(obddev) || !OBP(obddev, read) ) {
+                if ( !OBT(obd) || !OBP(obd, read) ) {
                         err = -EOPNOTSUPP;
                         EXIT;
                         return err;
                 }
 
 
-                err = OBP(obddev, read)(&conn, &rw_s->obdo, rw_s->buf, 
+                err = OBP(obd, read)(&conn, &rw_s->obdo, rw_s->buf, 
                                         &rw_s->count, rw_s->offset);
                 
                 ODEBUG(&rw_s->obdo);
@@ -651,7 +506,7 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp,
 
                 conn.oc_id = rw_s->conn_id;
 
-                if ( !OBT(obddev) || !OBP(obddev, write) ) {
+                if ( !OBT(obd) || !OBP(obd, write) ) {
                         err = -EOPNOTSUPP;
                         return err;
                 }
@@ -659,7 +514,7 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp,
                 CDEBUG(D_INFO, "WRITE: conn %d, count %Ld, offset %Ld, '%s'\n",
                        rw_s->conn_id, rw_s->count, rw_s->offset, rw_s->buf);
 
-                err = OBP(obddev, write)(&conn, &rw_s->obdo, rw_s->buf, 
+                err = OBP(obd, write)(&conn, &rw_s->obdo, rw_s->buf, 
                                          &rw_s->count, rw_s->offset);
                 ODEBUG(&rw_s->obdo);
                 if ( err ) {
@@ -676,24 +531,24 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp,
                 struct oic_prealloc_s *prealloc = tmp_buf;
 
                 /* has this minor been registered? */
-                if (!obddev->obd_type)
+                if (!obd->obd_type)
                         return -ENODEV;
 
                 err = copy_from_user(prealloc, (int *)arg, sizeof(*prealloc));
                 if (err) 
                         return -EFAULT;
 
-                if ( !(obddev->obd_flags & OBD_ATTACHED) ||
-                     !(obddev->obd_flags & OBD_SET_UP)) {
+                if ( !(obd->obd_flags & OBD_ATTACHED) ||
+                     !(obd->obd_flags & OBD_SET_UP)) {
                         CDEBUG(D_IOCTL, "Device not attached or set up\n");
                         return -ENODEV;
                 }
 
-                if ( !OBT(obddev) || !OBP(obddev, preallocate) )
+                if ( !OBT(obd) || !OBP(obd, preallocate) )
                         return -EOPNOTSUPP;
 
                 conn.oc_id = prealloc->conn_id;
-                err = OBP(obddev, preallocate)(&conn, &prealloc->alloc,
+                err = OBP(obd, preallocate)(&conn, &prealloc->alloc,
                                                prealloc->ids);
                 if ( err ) {
                         EXIT;
@@ -710,17 +565,17 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp,
                 struct statfs buf;
 
                 /* has this minor been registered? */
-                if (!obddev->obd_type)
+                if (!obd->obd_type)
                         return -ENODEV;
 
                 tmp = (void *)arg + sizeof(unsigned int);
                 get_user(conn_id, (int *) arg);
 
-                if ( !OBT(obddev) || !OBP(obddev, statfs) )
+                if ( !OBT(obd) || !OBP(obd, statfs) )
                         return -EOPNOTSUPP;
 
                 conn.oc_id = conn_id;
-                err = OBP(obddev, statfs)(&conn, &buf);
+                err = OBP(obd, statfs)(&conn, &buf);
                 if ( err ) {
                         EXIT;
                         return err;
@@ -733,8 +588,8 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp,
         case OBD_IOC_COPY: {
                 struct ioc_mv_s *mvdata = tmp_buf;
 
-                if ( (!(obddev->obd_flags & OBD_SET_UP)) ||
-                     (!(obddev->obd_flags & OBD_ATTACHED))) {
+                if ( (!(obd->obd_flags & OBD_SET_UP)) ||
+                     (!(obd->obd_flags & OBD_ATTACHED))) {
                         CDEBUG(D_IOCTL, "Device not attached or set up\n");
                         return -ENODEV;
                 }
@@ -746,17 +601,17 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp,
                         return err;
                 }
 
-                if ( !OBT(obddev) || !OBP(obddev, copy) )
+                if ( !OBT(obd) || !OBP(obd, copy) )
                         return -EOPNOTSUPP;
 
                 /* do the partition */
                 CDEBUG(D_INFO, "Copy %d, type %s dst %Ld src %Ld\n", dev, 
-                       obddev->obd_type->typ_name, mvdata->dst.o_id, 
+                       obd->obd_type->typ_name, mvdata->dst.o_id, 
                        mvdata->src.o_id);
 
                 conn.oc_id = mvdata->src_conn_id;
 
-                err = OBP(obddev, copy)(&conn, &mvdata->dst, 
+                err = OBP(obd, copy)(&conn, &mvdata->dst, 
                                         &conn, &mvdata->src, 
                                         mvdata->src.o_size, 0);
                 return err;
@@ -765,8 +620,8 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp,
         case OBD_IOC_MIGR: {
                 struct ioc_mv_s *mvdata = tmp_buf;
 
-                if ( (!(obddev->obd_flags & OBD_SET_UP)) ||
-                     (!(obddev->obd_flags & OBD_ATTACHED))) {
+                if ( (!(obd->obd_flags & OBD_SET_UP)) ||
+                     (!(obd->obd_flags & OBD_ATTACHED))) {
                         CDEBUG(D_IOCTL, "Device not attached or set up\n");
                         return -ENODEV;
                 }
@@ -779,16 +634,16 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp,
 
                 CDEBUG(D_INFO, "Migrate copying %d bytes\n", sizeof(*mvdata));
 
-                if ( !OBT(obddev) || !OBP(obddev, migrate) )
+                if ( !OBT(obd) || !OBP(obd, migrate) )
                         return -EOPNOTSUPP;
 
                 /* do the partition */
                 CDEBUG(D_INFO, "Migrate %d, type %s conn %d src %Ld dst %Ld\n",
-                       dev, obddev->obd_type->typ_name, mvdata->src_conn_id,
+                       dev, obd->obd_type->typ_name, mvdata->src_conn_id,
                        mvdata->src.o_id, mvdata->dst.o_id);
 
                 conn.oc_id = mvdata->src_conn_id;
-                err = OBP(obddev, migrate)(&conn, &mvdata->dst, &mvdata->src, 
+                err = OBP(obd, migrate)(&conn, &mvdata->dst, &mvdata->src, 
                                            mvdata->src.o_size, 0);
 
                 return err;
@@ -804,14 +659,14 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp,
 
                 conn.oc_id = rw_s->conn_id;
 
-                if ( !OBT(obddev) || !OBP(obddev, punch) ) {
+                if ( !OBT(obd) || !OBP(obd, punch) ) {
                         err = -EOPNOTSUPP;
                         return err;
                 }
 
                 CDEBUG(D_INFO, "PUNCH: conn %d, count %Ld, offset %Ld\n",
                        rw_s->conn_id, rw_s->count, rw_s->offset);
-                err = OBP(obddev, punch)(&conn, &rw_s->obdo, rw_s->count,
+                err = OBP(obd, punch)(&conn, &rw_s->obdo, rw_s->count,
                                          rw_s->offset);
                 ODEBUG(&rw_s->obdo);
                 if ( err ) {
@@ -885,6 +740,10 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp,
                 EXIT;
                 return err;
         }
+#endif 
+       default:
+               return -EINVAL;
+
         }
 } /* obd_class_ioctl */
 
@@ -956,6 +815,12 @@ static struct file_operations obd_psdev_fops = {
 
 
 /* modules setup */
+#define OBD_MINOR 241
+static struct miscdevice obd_psdev = {
+        OBD_MINOR,
+        "obd_psdev",
+        &obd_psdev_fops
+};
 
 int init_obd(void)
 {
@@ -966,10 +831,9 @@ int init_obd(void)
         
         INIT_LIST_HEAD(&obd_types);
         
-        if (register_chrdev(OBD_PSDEV_MAJOR,"obd_psdev", 
-                            &obd_psdev_fops)) {
-                printk(KERN_ERR __FUNCTION__ ": unable to get major %d\n", 
-                       OBD_PSDEV_MAJOR);
+       if ( (err = misc_register(&obd_psdev)) ) { 
+                printk(KERN_ERR __FUNCTION__ ": cannot register %d err %d\n", 
+                       OBD_MINOR, err);
                 return -EIO;
         }
 
@@ -1017,14 +881,14 @@ void cleanup_module(void)
         int i;
         ENTRY;
 
-        unregister_chrdev(OBD_PSDEV_MAJOR, "obd_psdev");
+        misc_deregister(&obd_psdev);
         for (i = 0; i < MAX_OBD_DEVICES; i++) {
-                struct obd_device *obddev = &obd_dev[i];
-                if ( obddev->obd_type && 
-                     (obddev->obd_flags & OBD_SET_UP) &&
-                     OBT(obddev) && OBP(obddev, detach) ) {
+                struct obd_device *obd = &obd_dev[i];
+                if ( obd->obd_type && 
+                     (obd->obd_flags & OBD_SET_UP) &&
+                     OBT(obd) && OBP(obd, detach) ) {
                         /* XXX should this call generic detach otherwise? */
-                        OBP(obddev, detach)(obddev);
+                        OBP(obd, detach)(obd);
                 } 
         }