Whamcloud - gitweb
doc/obd-howto.sgml: completed OBD tutorial section
[fs/lustre-release.git] / lustre / obdclass / obdcontrol
index e866cc6..69a863d 100755 (executable)
@@ -61,6 +61,17 @@ eval 'sub OBD_IOC_COPY () { &_IOC(3, ord(\'f\'), 22, 4);}' unless
   defined(&OBD_IOC_COPY);
 eval 'sub OBD_IOC_MIGR () { &_IOC(3, ord(\'f\'), 23, 4);}' unless
   defined(&OBD_IOC_MIGR);
+eval 'sub OBD_SNAP_SETTABLE () { &_IOC(3, ord(\'f\'), 40, 4);}' unless
+  defined(&OBD_SNAP_SETTABLE);
+eval 'sub OBD_SNAP_PRINTTABLE () { &_IOC(3, ord(\'f\'), 41, 4);}' unless
+  defined(&OBD_SNAP_PRINTTABLE);
+eval 'sub OBD_SNAP_DELETE() { &_IOC(3, ord(\'f\'), 42, 4);}' unless
+  defined(&OBD_SNAP_DELETE);
+eval 'sub OBD_SNAP_RESTORE() { &_IOC(3, ord(\'f\'), 43, 4);}' unless
+  defined(&OBD_SNAP_RESTORE);
+
+eval 'sub OBD_EXT2_RUNIT () { &_IOC(3, ord(\'f\'), 61, 4);}' unless
+  defined(&OBD_EXT2_RUNIT);
 
 eval 'sub ATTR_MODE () {1;}' unless defined(&ATTR_MODE);
 eval 'sub ATTR_UID () {2;}' unless defined(&ATTR_UID);
@@ -95,17 +106,22 @@ my %commands =
      'create' => {func => "Create", doc => "create: creates a new inode"},
      'attach' => {func => "Attach", doc => "attach type [adapter bus tid lun]"},
      'detach' => {func => "Detach", doc => "detach this device"},
-     'snapattach' => {func => "SnapAttach", doc => "snapattach snapno snapcount time1 index1 .... timek indexk"},
+     'testext2iterator' => {func => "TestExt2Iterator", doc => ""},
+     'snapattach' => {func => "SnapAttach", doc => "snapattach snapdev snapidx tableno"},
+     'snapset' => {func => "SnapSetTable", doc => "snapset tableno file" },
+     'snapprint' => {func => "SnapPrint", doc => "snapprint tableno"},
+     'snapdelete' => {func => "SnapDelete", doc => "snapdelete: delete connected snap obd"},
+     'snaprestore' => {func => "SnapRestore", doc => "snaprestore: restore connected old snap to current"},
      'snaptable' => {func => "SnapShotTable", doc => "snaptable: build a snapshot table (interactive)"},
      'copy' => {func => "Copy", doc => "copy srcid tgtid"},
      'migrate' => {func => "Migrate", doc => "migrate srcid tgtid"},
      'format' => {func => "Format", doc => "format type adapter bus tid lun size"},
      'partition' => {func => "Partition", doc => "partition type adapter bus tid lun partition size"},
-     'setup' => {func => "Setup", doc => "setup: link the ext2 partition (default /dev/loop0) to this obddev"},
+     'setup' => {func => "Setup", doc => "setup [type]: link this OBD device to the underlying device (default type ext2_obd, filesystem /dev/loop0)"},
      '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"},
-     'destroy' => {func => "Destroy", doc => "setup: destroys an inode"},
+     'destroy' => {func => "Destroy", doc => "destroy <inode>: destroys an inode"},
      'cleanup' => {func => "Cleanup", doc => "cleanup the minor obd device"},
      'dec_use_count' => {func => "Decusecount", doc => "decreases the module use count so that the module can be removed following an oops"},
      'read' => {func => "Read", doc => "read <inode> <count> [offset]"},
@@ -228,12 +244,17 @@ sub Filesystem {
     if (!defined($::st = stat($filesystem))) {
        die "Unable to stat $filesystem.\n";
     }
+    print "Filesystem now $filesystem\n";
 }
 
 # select the OBD device we talk to
 sub Device {
     my $device = shift;
 
+    if ($::client_id) {
+       print "Disconnecting active session ($::client_id)...";
+       Disconnect($::client_id);
+    }
     if (! $device ) {
        $device = "/dev/obd0";
     }
@@ -260,7 +281,7 @@ sub Attach {
        $datalen = 4 * 4;
     }
 
-    my $packed = pack("ipip", length($type), $type, $datalen, $data);
+    my $packed = pack("Lipip", $::client_id, length($type), $type, $datalen, $data);
 
     my $rc = ioctl(DEV_OBD, &OBD_IOC_ATTACH, $packed);
 
@@ -288,11 +309,131 @@ sub Detach {
 }
 
 
-sub SnapAttach {
+sub TestExt2Iterator { 
+    if (!defined($::client_id)) {
+       print "You must first ``connect''.\n";
+       return;
+    }
+
+    my $err = 0;
+    my $type = "ext2_obd";
+    $data = pack("i", 4711); # bogus data
+    $datalen = 4;
+
+    my $len = length($type);
+    my $cl = length($data);
+    my $add = pack("p", $data);
+    print "type $type (len $len), datalen $datalen ($cl)\n";
+    my $packed = pack("Lipip", $::client_id, length($type), $type, $datalen, $data);
+
+    my $rc = ioctl(DEV_OBD, &OBD_EXT2_RUNIT, $packed);
+
+    if (!defined $rc) {
+       print STDERR "ioctl failed: $!\n";
+    } elsif ($rc eq "0 but true") {
+       print "Finished (success)\n";
+    } else {
+       print "ioctl returned error code $rc.\n";
+    }
+}
+
+
+sub SnapDelete { 
+    if (!defined($::client_id)) {
+       print "You must first ``connect''.\n";
+       return;
+    }
+
     my $err = 0;
     my $type = "snap_obd";
-    my $snapdev = shift;
-    my $snapno = shift;
+    $data = pack("i", 4711); # bogus data
+    $datalen = 4;
+
+    my $len = length($type);
+    my $cl = length($data);
+    my $add = pack("p", $data);
+    print "type $type (len $len), datalen $datalen ($cl)\n";
+    my $packed = pack("Lipip", $::client_id, length($type), $type, $datalen, $data);
+
+    my $rc = ioctl(DEV_OBD, &OBD_SNAP_DELETE, $packed);
+
+    if (!defined $rc) {
+       print STDERR "ioctl failed: $!\n";
+    } elsif ($rc eq "0 but true") {
+       print "Finished (success)\n";
+    } else {
+       print "ioctl returned error code $rc.\n";
+    }
+}
+
+
+# FIXME the parameter to snaprestore SHOULD be the snapshot number of the
+#       snapshot to be restored, and this routine should handle all of the
+#       removal of intervening snapshots and changing the snaptable to have
+#       the "restored" snapshot as current and move the previous current.
+sub SnapRestore { 
+    if (!defined($::client_id)) {
+       print "You must first ``connect''.\n";
+       return;
+    }
+
+    my $err = 0;
+    my $type = "snap_obd";
+    my $prevcurrent = shift;
+    $data = pack("i", $prevcurrent); # where the previous current snapshot now lives
+    $datalen = 4;
+
+    my $len = length($type);
+    my $cl = length($data);
+    my $add = pack("p", $data);
+    print "type $type (len $len), datalen $datalen ($cl)\n";
+    my $packed = pack("Lipip", $::client_id, length($type), $type, $datalen, $data);
+
+    my $rc = ioctl(DEV_OBD, &OBD_SNAP_RESTORE, $packed);
+
+    if (!defined $rc) {
+       print STDERR "ioctl failed: $!\n";
+    } elsif ($rc eq "0 but true") {
+       print "Finished (success)\n";
+    } else {
+       print "ioctl returned error code $rc.\n";
+    }
+}
+
+
+
+sub SnapPrint { 
+    my $err = 0;
+    my $type = "snap_obd";
+    my $snaptableno = shift;
+
+    $data = pack("i", $snaptableno);
+    $datalen = 4;
+
+    my $len = length($type);
+    my $cl = length($data);
+    my $add = pack("p", $data);
+    print "type $type (len $len), datalen $datalen ($cl)\n";
+    my $packed = pack("Lipip", $::client_id, length($type), $type, $datalen, $data);
+
+    my $rc = ioctl(DEV_OBD, &OBD_SNAP_PRINTTABLE, $packed);
+
+    if (!defined $rc) {
+       print STDERR "ioctl failed: $!\n";
+    } elsif ($rc eq "0 but true") {
+       print "Finished (success)\n";
+    } else {
+       print "ioctl returned error code $rc.\n";
+    }
+}
+
+sub SnapSetTable {
+    my $err = 0;
+    my $type = "snap_obd";
+    my $snaptableno = shift;
     my $file = shift;
     my $snapcount;
     my $table = {};
@@ -312,8 +453,8 @@ sub SnapAttach {
        print "No current snapshot in table! First make one\n";
        return ;
     }
-    $data = pack("iii", $snapdev, $snapno, $snapcount);
-    $datalen = 3 * 4;
+    $data = pack("ii", $snaptableno, $snapcount);
+    $datalen = 2 * 4;
     foreach my $time (sort keys %{$table}) {
        $data .= pack("Ii", $time, $table->{$time});
        $datalen += 8;
@@ -323,7 +464,38 @@ sub SnapAttach {
     my $cl = length($data);
     my $add = pack("p", $data);
     print "type $type (len $len), datalen $datalen ($cl)\n";
-    my $packed = pack("ipip", length($type), $type, $datalen, $data);
+    my $packed = pack("Lipip", $::client_id, length($type), $type, $datalen, $data);
+
+    my $rc = ioctl(DEV_OBD, &OBD_SNAP_SETTABLE, $packed);
+
+    if (!defined $rc) {
+       print STDERR "ioctl failed: $!\n";
+    } elsif ($rc eq "0 but true") {
+       print "Finished (success)\n";
+    } else {
+       print "ioctl returned error code $rc.\n";
+    }
+}
+
+
+sub SnapAttach {
+    my $err = 0;
+    my $type = "snap_obd";
+    my $snapdev = shift;
+    my $snapidx = shift;
+    my $tableno = shift;
+    my $snapcount;
+    my $data;
+    my $datalen = 0;
+
+    $data = pack("iii", $snapdev, $snapidx, $tableno);
+    $datalen = 3 * 4;
+
+    my $len = length($type);
+    my $cl = length($data);
+    my $add = pack("p", $data);
+    print "type $type (len $len), datalen $datalen ($cl)\n";
+    my $packed = pack("Lipip", $::client_id, length($type), $type, $datalen, $data);
 
     my $rc = ioctl(DEV_OBD, &OBD_IOC_ATTACH, $packed);