Whamcloud - gitweb
- ext2_obd.c --- fix the bugs in read/write for Linux 2.4.3
[fs/lustre-release.git] / lustre / obdclass / class_obd.c
index 0ee1298..d29ed08 100644 (file)
@@ -23,6 +23,7 @@
  *              Copyright (c) 1999 Stelias Computing, Inc.
  *                (authors {pschwan,braam}@stelias.com)
  *              Copyright (C) 1999 Seagate Technology, Inc.
+ *              Copyright (C) 2001 Cluster File Systems, Inc.
  *
  * 
  */
@@ -37,7 +38,7 @@
 #include <linux/kmod.h>   /* for request_module() */
 #include <linux/sched.h>
 #include <linux/lp.h>
-#include <linux/malloc.h>
+#include <linux/slab.h>
 #include <linux/ioport.h>
 #include <linux/fcntl.h>
 #include <linux/delay.h>
@@ -115,8 +116,11 @@ static int obd_class_release(struct inode * inode, struct file * file)
         return 0;
 }
 
-/* support function */
-static struct obd_type *obd_nm_to_type(char *nm) 
+/* 
+ * support functions: we could use inter-module communication, but this 
+ * is more portable to other OS's
+ */
+static struct obd_type *obd_search_type(char *nm)
 {
         struct list_head *tmp;
         struct obd_type *type;
@@ -131,7 +135,24 @@ static struct obd_type *obd_nm_to_type(char *nm)
                         return type;
                 }
         }
-        return NULL;
+       return NULL;
+}
+
+static struct obd_type *obd_nm_to_type(char *nm) 
+{
+        struct obd_type *type = obd_search_type(nm);
+
+#ifdef CONFIG_KMOD
+       if ( !type ) {
+               if ( !request_module(nm) ) {
+                       CDEBUG(D_PSDEV, "Loaded module '%s'\n", nm);
+                       type = obd_search_type(nm);
+               } else {
+                       CDEBUG(D_PSDEV, "Can't load module '%s'\n", nm);
+               }
+       }
+#endif
+        return type;
 }
 
 
@@ -162,19 +183,29 @@ static int getdata(int len, void **data)
 
 
 static int obd_devicename_from_path(obd_devicename* whoami, 
-                                   char* user_string) 
+                                   uint32_t klen,
+                                   char* kname, char *user_path)
 {
-  struct nameidata nd;
-  int err;
-
-  err = user_path_walk(user_string, &nd);
-  if (!err) { 
-    whoami->dentry = nd.dentry;
-    path_release(&nd);
-  }
-  return err;
+       int err;
+       struct nameidata nd;
+       whoami->len = klen;
+       whoami->name = kname;
+
+#if (LINUX_VERSION_CODE <=  0x20403)
+
+       err = user_path_walk(user_path, &nd);
+       if (!err) {
+               CDEBUG(D_INFO, "found dentry for %s\n", kname);
+               whoami->dentry = nd.dentry;
+               path_release(&nd);
+       }
+       return err;
+#endif 
+       return 0;
 }
 
+
+
 /* to control /dev/obdNNN */
 static int obd_class_ioctl (struct inode * inode, struct file * filp, 
                             unsigned int cmd, unsigned long arg)
@@ -233,16 +264,6 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp,
                 /* find the type */
                 nm = input->att_type;
                 type = obd_nm_to_type(nm);
-#ifdef CONFIG_KMOD
-                if ( !type ) {
-                        if ( !request_module(nm) ) {
-                                CDEBUG(D_PSDEV, "Loaded module '%s'\n", nm);
-                                type = obd_nm_to_type(nm);
-                        } else {
-                                CDEBUG(D_PSDEV, "Can't load module '%s'\n", nm);
-                        }
-                }
-#endif
 
                 OBD_FREE(input->att_type, input->att_typelen + 1);
                 if ( !type ) {
@@ -332,8 +353,9 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp,
         case OBD_IOC_SETUP: {
                 struct ioc_setup {
                         int setup_datalen;
-                        char *setup_data;
+                        void *setup_data;
                 } *setup;
+               char *user_path;
 
                 setup = tmp_buf;
 
@@ -362,9 +384,19 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp,
                  EXIT;
                  return err;
                }
-               
+               user_path = setup->setup_data;
+
+                /* get the attach data */
+                err = getdata(setup->setup_datalen, &setup->setup_data);
+                if ( err ) {
+                        EXIT;
+                        return err;
+                }
+
                err = obd_devicename_from_path(&(obddev->obd_fsname),
-                                               (char*) setup->setup_data);
+                                              setup->setup_datalen,
+                                              (char*) setup->setup_data, 
+                                              user_path);
                if (err) {
                  memset(&(obddev->obd_fsname), 0, sizeof(obd_devicename));
                  EXIT;