Whamcloud - gitweb
class/*: updated to handle module autoloading (from Steve Bruggeman)
authoradilger <adilger>
Fri, 25 Feb 2000 06:35:33 +0000 (06:35 +0000)
committeradilger <adilger>
Fri, 25 Feb 2000 06:35:33 +0000 (06:35 +0000)
lustre/obdclass/class_obd.c
lustre/obdclass/obdcontrol

index ec8beca..8a1204d 100644 (file)
@@ -34,6 +34,7 @@
 #include <linux/errno.h>
 #include <linux/kernel.h>
 #include <linux/major.h>
+#include <linux/kmod.h>   /* for request_module() */
 #include <linux/sched.h>
 #include <linux/lp.h>
 #include <linux/malloc.h>
@@ -58,7 +59,7 @@
 
 static int obd_init_magic;
 int           obd_print_entry = 1;
-int           obd_debug_level = 4095;
+int           obd_debug_level = 0;
 struct obd_device obd_dev[MAX_OBD_DEVICES];
 struct list_head obd_types;
 
@@ -177,6 +178,7 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp,
        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 */
@@ -203,7 +205,19 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp,
                }
 
                /* find the type */
-               type = obd_nm_to_type(input->att_type);
+               nm = input->att_type;
+               type = obd_nm_to_type(nm);
+#ifdef CONFIG_KMOD
+               if ( !type ) {
+                       if ( !request_module(nm) ) {
+                               CDEBUG(D_IOCTL, "Loaded module '%s'\n", nm);
+                               type = obd_nm_to_type(nm);
+                       } else {
+                               CDEBUG(D_IOCTL, "Can't load module '%s'\n", nm);
+                       }
+               }
+#endif
+
                OBD_FREE(input->att_type, input->att_typelen + 1);
                if ( !type ) {
                        printk(__FUNCTION__ ": unknown obd type dev %d\n",
@@ -737,6 +751,7 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp,
        default: {
                struct obd_type *type;
                struct oic_generic input;
+               char *nm;
                void *karg;
 
                /* get data structures */
@@ -753,7 +768,18 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp,
                }
 
                /* find the type */
-               type = obd_nm_to_type(input.att_type);
+               nm = input.att_type;
+               type = obd_nm_to_type(nm);
+#ifdef CONFIG_KMOD
+               if ( !type ) {
+                       if ( !request_module(nm) ) {
+                               CDEBUG(D_IOCTL, "Loaded module '%s'\n", nm);
+                               type = obd_nm_to_type(nm);
+                       } else {
+                               CDEBUG(D_IOCTL, "Can't load module '%s'\n", nm);
+                       }
+               }
+#endif
                OBD_FREE(input.att_type, input.att_typelen + 1);
                if ( !type ) {
                        printk(__FUNCTION__ ": unknown obd type dev %d\n", dev);
@@ -860,8 +886,6 @@ static struct file_operations obd_psdev_fops = {
        obd_class_release,     /* release */
        NULL,                  /* fsync */
        NULL,                  /* fasync */
-       NULL,                  /* check_media_change */
-       NULL,                  /* revalidate */
        NULL                   /* lock */
 };
 
index 295a7d1..d070c03 100755 (executable)
@@ -210,7 +210,7 @@ my $arg;
 my %commands =
     ('device' => {func => "Device", doc => "device <dev>: open another OBD device"},
      'create' => {func => "Create", doc => "create [<num> [<mode> [quiet]]]: create new object(s) (files, unless mode is given)"},
-     'attach' => {func => "Attach", doc => "attach { ext2_obd | snap_obd snapdev snapidx tableno | scsi_obd adapter bus tid lun }: attach this minor device to the specified driver" },
+     'attach' => {func => "Attach", doc => "attach { obdext2 | obdsnap snapdev snapidx tableno | obdscsi adapter bus tid lun }: attach this minor device to the specified driver" },
      'detach' => {func => "Detach", doc => "detach this minor device"},
      'testext2iterator' => {func => "TestExt2Iterator", doc => "test ext2 iterator function"},
      'snapset' => {func => "SnapSetTable", doc => "snapset <tableno> <file>: set the table (created with snaptable) as table #tableno" },
@@ -222,7 +222,7 @@ my %commands =
      'migrate' => {func => "Migrate", doc => "migrate <srcid> <tgtid>: migrate data from one object to another"},
      'partition' => {func => "Partition", doc => "partition <type> <adapter> <bus> <tid> <lun> <partition> <size>: create a partition"},
      'format' => {func => "Format", doc => "format <type> <adapter> <bus> <tid> <lun> <size>: format a partition"},
-     'setup' => {func => "Setup", doc => "setup [type]: link this OBD device to the underlying device (default type ext2_obd)"},
+     'setup' => {func => "Setup", doc => "setup [type]: link this OBD device to the underlying device (default type obdext2)"},
      'connect' => {func => "Connect", doc => "connect: allocates client ID for this session"},
      'disconnect' => {func => "Disconnect", doc => "disconnect [id]: frees client resources"},
      'sync' => {func => "Sync", doc => "sync: flushes buffers to disk"},
@@ -367,11 +367,11 @@ sub Attach {
     if ( ! $type ) {
        print "error: missing type\n";
 usage:
-       print "usage: attach {ext2_obd | snap_obd | scsi_obd}\n";
+       print "usage: attach {obdext2 | obdsnap | obdscsi}\n";
        return;
     }
 
-    if ($type eq "scsi_obd" ) {
+    if ($type eq "obdscsi" ) {
        my $adapter = shift;
        my $bus = shift;
        my $tid = shift;
@@ -379,14 +379,14 @@ usage:
 
        $data = pack("iiii", $adapter, $bus, $tid, $lun);
        $datalen = 4 * 4;
-    } elsif ($type eq "snap_obd" ) {
+    } elsif ($type eq "obdsnap" ) {
        my $snapdev = shift;
        my $snapidx = shift;
        my $tableno = shift;
 
        $data = pack("iii", $snapdev, $snapidx, $tableno);
        $datalen = 3 * 4;
-    } elsif ($type eq "ext2_obd") {
+    } elsif ($type eq "obdext2") {
        $data = pack("i", 4711);   # bogus data
        $datalen = 0;
     } else {
@@ -434,7 +434,7 @@ sub TestExt2Iterator {
     }
 
     my $err = 0;
-    my $type = "ext2_obd";
+    my $type = "obdext2";
  
     $data = pack("i", 4711); # bogus data
     $datalen = 4;
@@ -463,7 +463,7 @@ sub SnapDelete {
     }
 
     my $err = 0;
-    my $type = "snap_obd";
+    my $type = "obdsnap";
  
     $data = pack("i", 4711); # bogus data
     $datalen = 4;
@@ -538,7 +538,7 @@ sub SnapRestore {
 
     # ready for the ioctl
     my $err = 0;
-    my $type = "snap_obd";
+    my $type = "obdsnap";
     $data = pack("i", $currentindex); # slot of previous current snapshot 
     $datalen = 4;
 
@@ -581,7 +581,7 @@ sub FindSnapInTable {
 
 sub SnapPrint { 
     my $err = 0;
-    my $type = "snap_obd";
+    my $type = "obdsnap";
     my $snaptableno = shift;
 
     $data = pack("i", $snaptableno);
@@ -605,7 +605,7 @@ sub SnapPrint {
 
 sub SnapSetTable {
     my $err = 0;
-    my $type = "snap_obd";
+    my $type = "obdsnap";
     my $snaptableno = shift;
     my $file = shift;
     my $snapcount;