defined(&OBD_IOC_COPY);
eval 'sub OBD_IOC_MIGR () { &_IOC(3, ord(\'f\'), 23, 4);}' unless
defined(&OBD_IOC_MIGR);
+eval 'sub OBD_IOC_PUNCH () { &_IOC(3, ord(\'f\'), 24, 4);}' unless
+ defined(&OBD_IOC_PUNCH);
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
# this may be different on other architectures
# we use 32-bit integers for all 64-bit quantities in this program
-# #define OBD_INLINESZ 64
-# #define OBD_OBDMDSZ 64
+# #define OBD_INLINESZ 60
+# #define OBD_OBDMDSZ 60
# /* Note: 64-bit types are 64-bit aligned in structure */
# struct obdo {
# obd_id o_id;
# obd_flag o_flags;
# obd_flag o_obdflags;
# obd_count o_nlink;
+# obd_count o_generation;
# obd_flag o_valid; /* hot fields in this obdo */
-# char o_inline[OBD_INLINESZ];
-# char o_obdmd[OBD_OBDMDSZ];
+# char o_inline[60];
+# char o_obdmd[60];
# struct list_head o_list;
# struct obd_ops *o_op;
# };
sub obdo_pack {
my $obdo = shift;
- pack "LL LL LL LL LL LL LL L L L L L L L L a60 a64 L L L",
+ pack "LL LL LL LL LL LL LL L L L L L L L L L a60 a60 L L L",
$obdo->{id}, 0,
$obdo->{gr}, 0,
$obdo->{atime}, 0,
$obdo->{flags},
$obdo->{obdflags},
$obdo->{nlink},
+ $obdo->{generation},
$obdo->{valid},
$obdo->{inline},
$obdo->{obdmd},
$obdo->{gid},
$obdo->{flags},
$obdo->{obdflags},
- $obdo->{nlink},
- $obdo->{valid},
+ $obdo->{nlink},
+ $obdo->{generation},
+ $obdo->{valid},
$obdo->{inline},
- $obdo->{obdmd}) = unpack "x${offset}Lx4 Lx4 Lx4 Lx4 Lx4 Lx4 Lx4 L L L L L L L L a60 a64", $buf;
+ $obdo->{obdmd}) = unpack "x${offset}Lx4 Lx4 Lx4 Lx4 Lx4 Lx4 Lx4 L L L L L L L L L a60 a60", $buf;
$obdo;
}
my %commands =
('device' => {func => "Device", doc => "device <dev>: open another OBD device"},
- 'create' => {func => "Create", doc => "create: creates a new inode"},
- 'attach' => {func => "Attach", doc => "attach { ext2_obd | snap_obd snapdev snapidx tableno | scsi_obd adapter bus tid lun }" },
- 'detach' => {func => "Detach", doc => "detach this device"},
+ 'create' => {func => "Create", doc => "create [<num> [<mode> [quiet]]]: create new object(s) (files, unless mode is given)"},
+ '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" },
'snapprint' => {func => "SnapPrint", doc => "snapprint <tableno>: output the contents of table #tableno to the syslog"},
'snaptable' => {func => "SnapShotTable", doc => "snaptable: build a snapshot table (interactive)"},
'copy' => {func => "Copy", doc => "copy <srcid> <tgtid>: copy objects"},
'migrate' => {func => "Migrate", doc => "migrate <srcid> <tgtid>: migrate data from one object to another"},
- '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 [type]: link this OBD device to the underlying device (default type ext2_obd)"},
+ '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 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"},
- 'destroy' => {func => "Destroy", doc => "destroy <inode>: destroys an inode"},
+ 'destroy' => {func => "Destroy", doc => "destroy <id>: destroys an object"},
'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]"},
- 'fsread' => {func => "Read2", doc => "read <inode> <count> [offset]"},
- 'write' => {func => "Write", doc => "write <inode> <offset> <text>"},
- 'setattr' => {func => "Setattr", doc => "setattr <inode> [mode [uid [gid [size [atime [mtime [ctime]]]]]]]"},
- 'getattr' => {func => "Getattr", doc => "getattr <inode>: displays inode object attributes"},
- 'preallocate' => {func => "Preallocate", doc => "preallocate [num]: requests preallocation of num inodes."},
+ 'read' => {func => "Read", doc => "read <id> <count> [offset]: read data from object"},
+ 'fsread' => {func => "Read2", doc => "read <id> <count> [offset]: read data from object"},
+ 'write' => {func => "Write", doc => "write <id> <offset> <text>: write data to object"},
+ 'punch' => {func => "Punch", doc => "punch <id> <start> <count>: punch a hole in object"},
+ 'setattr' => {func => "Setattr", doc => "setattr <id> [mode [uid [gid [size [atime [mtime [ctime]]]]]]]: sets object attributes"},
+ 'getattr' => {func => "Getattr", doc => "getattr <id>: displays object attributes"},
+ 'preallocate' => {func => "Preallocate", doc => "preallocate [num]: requests preallocation of num objects."},
'statfs' => {func => "Statfs", doc => "statfs: filesystem status information"},
'help' => {func => \&Help, doc => "help: this message"},
'quit' => {func => \&Quit, doc => "see \"exit\""},
sub execute_line {
my $line = shift;
- my @arg = split(' ', $line);
- my $word = shift @arg;
+ my @cmdline = split(' ', $line);
+ my $word = shift @cmdline;
my $cmd;
if ( $file ) {
}
if ($cmd eq "help" || $cmd eq "exit" || $cmd eq "quit") {
- return (&{$commands{$cmd}->{func}}(@arg));
+ return (&{$commands{$cmd}->{func}}(@cmdline));
}
# Call the function.
- return (&{$commands{$cmd}->{func}}(@arg));
+ return (&{$commands{$cmd}->{func}}(@cmdline));
}
}
-
sub Attach {
my $err = 0;
my $type = shift;
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;
$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 {
}
}
+
sub Detach {
my $err = 0;
my $data = "";
}
my $err = 0;
- my $type = "ext2_obd";
+ my $type = "obdext2";
$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 $err = 0;
- my $type = "snap_obd";
+ my $type = "obdsnap";
$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);
# 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;
sub SnapPrint {
my $err = 0;
- my $type = "snap_obd";
+ my $type = "obdsnap";
my $snaptableno = shift;
$data = pack("i", $snaptableno);
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);
sub SnapSetTable {
my $err = 0;
- my $type = "snap_obd";
+ my $type = "obdsnap";
my $snaptableno = shift;
my $file = shift;
my $snapcount;
$data = pack("ii", $snaptableno, $snapcount);
$datalen = 2 * 4;
foreach my $time (sort keys %{$table}) {
+ # XXX we should change to pack LL instead of I for times
$data .= pack("Ii", $time, $table->{$time});
$datalen += 8;
}
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);
sub Copy {
my $err = 0;
- my $srcid = shift;
- my $dstid = shift;
+ my $src_obdo;
+ my $dst_obdo;
# Note: _copy IOCTL takes parameters as dst, src.
# Copy function takes parameters as src, dst.
- my $data = pack("III", $::client_id, $dstid, $srcid);
- my $datalen = 12;
+ $src_obdo->{id} = shift;
+ $dst_obdo->{id} = shift;
+ $src_obdo->{valid} = &OBD_MD_FLALL;
+
+ # XXX need to fix copy so we can have 2 client IDs here
+ my $packed = pack("L", $::client_id) . obdo_pack($dst_obdo) . pack("L", $::client_id) . obdo_pack($src_obdo);
- my $packed = pack("ip", $datalen, $data);
my $rc = ioctl(DEV_OBD, &OBD_IOC_COPY, $packed);
if (!defined $rc) {
sub Migrate {
my $err = 0;
- my $srcid = shift;
- my $dstid = shift;
# Note: _migr IOCTL takes parameters as dst, src.
# Migrate function takes parameters as src, dst.
- my $data = pack("III", $::client_id, $dstid, $srcid);
- my $datalen = 12;
+ $src_obdo->{id} = shift;
+ $dst_obdo->{id} = shift;
+ $src_obdo->{valid} = &OBD_MD_FLALL;
+
+ # We pack a dummy connection ID here
+ my $packed = pack("L", $::client_id) . obdo_pack($dst_obdo) . pack("L", $::client_id) . obdo_pack($src_obdo);
- my $packed = pack("ip", $datalen, $data);
my $rc = ioctl(DEV_OBD, &OBD_IOC_MIGR, $packed);
if (!defined $rc) {
# XXX we need a getinfo ioctl to validate parameters
# by type here
- if ($arg && !defined($::st = stat($arg))) {
- print "$arg is not a valid device\n";
+ if ($arg && !defined($::st = stat($arg))) {
+ print "$dev is not a valid device\n";
return;
}
}
sub Create {
- my $arg = shift;
+ if (!defined($::client_id)) {
+ print "You must first ``connect''.\n";
+ return;
+ }
+
+ my $num = shift;
+ my $mode = shift;
my $quiet = shift;
my $rc;
my $prealloc = 0;
- if (defined($quiet) && $quiet ne "quiet") {
- print "syntax: create [number of objects [quiet]]\n";
+ if (!defined($num)) {
+ $num = 1;
+ }
+
+ if (!defined($mode)) {
+ $mode = 0100644; # create a file (rw-r--r--) if not specified
+ }
+
+ if (scalar($num) < 1 || defined($quiet) && $quiet ne "quiet") {
+ print "usage: create [<number of objects> [<mode> [quiet]]]\n";
return;
}
- my $packed = pack("IL", $::client_id, $prealloc);
- if (!defined($arg) || scalar($arg) < 2) {
- print "Creating 1 object...\n";
+ my $i;
+ my $id = 0; # can't currently request IDs
+
+ print "Creating " . scalar($num) . " object";
+ if (scalar($num) > 1) {
+ print "s";
+ }
+ print "\n";
+
+ for ($i = 0; $i < scalar($num); $i++) {
+ my $obdo;
+ $obdo->{id} = $id;
+ $obdo->{mode} = scalar($mode);
+ $obdo->{valid} = &OBD_MD_FLMODE;
+
+ my $packed = pack("I", $::client_id) . obdo_pack($obdo);
$rc = ioctl(DEV_OBD, &OBD_IOC_CREATE, $packed);
- if (!defined($quiet)) {
- my $obdo = obdo_unpack($packed, 4);
+ if ($rc ne "0 but true") {
+ last;
+ } elsif (!defined($quiet)) {
+ $obdo = obdo_unpack($packed, 4);
print "Created object #$obdo->{id}.\n";
}
- } else {
- my $i;
-
- print "Creating " . scalar($arg) . " objects...\n";
- for ($i = 0; $i < scalar($arg); $i++) {
- $rc = ioctl(DEV_OBD, &OBD_IOC_CREATE, $packed);
- my $ino = unpack("L", $packed);
- if ($rc ne "0 but true") {
- last;
- $packed = pack("IL", $::client_id, $prealloc);
- } elsif (!defined($quiet)) {
- $packed = pack("IL", $::client_id, $prealloc);
- print "Created object #$ino.\n";
- }
- }
}
if (!defined $rc) {
return;
}
- my $arg = shift;
+ my $id = shift;
- if (!defined($arg) || scalar($arg) < 1) {
+ if (!defined($id) || scalar($id) < 1) {
print "usage: destroy <object number>\n";
return;
}
- print "Destroying object $arg...\n";
- my $packed = pack("IL", $::client_id, $arg);
+ print "Destroying object $id...\n";
+ my $packed = pack("IL", $::client_id, $id);
my $rc = ioctl(DEV_OBD, &OBD_IOC_DESTROY, $packed);
if (!defined $rc) {
return;
}
- my $inode = shift;
+ my $id = shift;
- if (!defined($inode) || scalar($inode) < 1) {
+ if (!defined($id) || scalar($id) < 1) {
print "invalid arguments; type \"help getattr\" for a synopsis\n";
return;
}
# see Setattr
my $obdo;
- $obdo->{id} = $inode;
+ $obdo->{id} = $id;
$obdo->{valid} = &OBD_MD_FLALL;
my $packed = pack("L", $::client_id) . obdo_pack($obdo);
my $rc = ioctl(DEV_OBD, &OBD_IOC_GETATTR, $packed);
-
if (!defined $rc) {
print STDERR "ioctl failed: $!\n";
return;
}
- my $inode = shift;
+ my $id = shift;
- if (!defined($inode) || scalar($inode) < 1) {
+ if (!defined($id) || scalar($id) < 1) {
print "invalid arguments; type \"help setattr\" for a synopsis\n";
return;
}
# XXX we do not currently set all of the fields in the obdo
my $obdo;
- $obdo->{id} = $inode;
+ $obdo->{id} = $id;
$obdo->{mode} = oct(shift);
$obdo->{uid} = shift;
$obdo->{gid} = shift;
return;
}
- my $inode = shift;
+ my $id = shift;
my $count = shift;
my $offset = shift;
- if (!defined($inode) || scalar($inode) < 1 || !defined($count) ||
+ if (!defined($id) || scalar($id) < 1 || !defined($count) ||
$count < 1 || (defined($offset) && $offset < 0)) {
print "invalid arguments; type \"help read\" for a synopsis\n";
return;
}
print("Reading $count bytes starting at byte $offset from object " .
- "$inode...\n");
+ "$id...\n");
# "allocate" a large enough buffer
my $buf = sprintf("%${count}s", " ");
die "suck" if (length($buf) != $count);
+ my $obdo;
+ $obdo->{id} = $id;
+
# the perl we're using doesn't support pack type Q, and offset is 64 bits
- my $packed = pack("ILpLLL", $::client_id, $inode, $buf, $count, $offset, 0);
+ my $packed = pack("L", $::client_id) . obdo_pack($obdo) .
+ pack("p LL LL", $buf, $count, $offset);
my $rc = ioctl(DEV_OBD, &OBD_IOC_READ, $packed);
return;
}
- my $inode = shift;
+ my $id = shift;
my $count = shift;
my $offset = shift;
- if (!defined($inode) || scalar($inode) < 1 || !defined($count) ||
+ if (!defined($id) || scalar($id) < 1 || !defined($count) ||
$count < 1 || (defined($offset) && $offset < 0)) {
print "invalid arguments; type \"help read\" for a synopsis\n";
return;
}
print("Reading $count bytes starting at byte $offset from object " .
- "$inode...\n");
+ "$id...\n");
# "allocate" a large enough buffer
my $buf = sprintf("%${count}s", " ");
die "suck" if (length($buf) != $count);
+ my $obdo;
+ $obdo->{id} = $id;
+
# the perl we're using doesn't support pack type Q, and offset is 64 bits
- my $packed = pack("ILpLLL", $::client_id, $inode, $buf, $count, $offset, 0);
+ my $packed = pack("L", $::client_id) . obdo_pack($obdo) .
+ pack("p LL LL", $buf, $count, $offset);
my $rc = ioctl(DEV_OBD, &OBD_IOC_READ2, $packed);
return;
}
- my $inode = shift;
+ my $id = shift;
my $offset = shift;
my $text = join(' ', @_);
my $count = length($text);
- if (!defined($inode) || scalar($inode) < 1 || !defined($offset) ||
+ if (!defined($id) || scalar($id) < 1 || !defined($offset) ||
scalar($offset) < 0) {
print "invalid arguments; type \"help write\" for a synopsis\n";
return;
$count = 0;
}
- print("Writing $count bytes starting at byte $offset to object " .
- "$inode...\n");
+ print("Writing $count bytes starting at byte $offset to object $id...\n");
+
+ my $obdo;
+ $obdo->{id} = $id;
# the perl we're using doesn't support pack type Q
- my $packed = pack("ILpLLL", $::client_id, $inode, $text, $count, $offset, 0);
+ my $packed = pack("L", $::client_id) . obdo_pack($obdo) .
+ pack("p LL LL", $buf, $count, $offset);
+
my $rc = ioctl(DEV_OBD, &OBD_IOC_WRITE, $packed);
$retval = unpack("l", $packed);
}
}
+sub Punch {
+ if (!defined($::client_id)) {
+ print "You must first ``connect''.\n";
+ return;
+ }
+
+ my $id = shift;
+ my $start = shift;
+ my $count = shift;
+
+ if (!defined($id) || scalar($id) < 1 || !defined($start) ||
+ scalar($start) < 0 || !defined($count) || scalar($count) < 0) {
+ print "invalid arguments; type \"help punch\" for a synopsis\n";
+ return;
+ }
+
+ print("Punching $count bytes starting at byte $start in object $id...\n");
+
+ my $obdo;
+ $obdo->{id} = $id;
+
+ # the perl we're using doesn't support pack type Q
+ my $packed = pack("L", $::client_id) . obdo_pack($obdo) .
+ pack("p LL LL", $buf, $start, $count);
+
+ my $rc = ioctl(DEV_OBD, &OBD_IOC_PUNCH, $packed);
+
+ $retval = unpack("l", $packed);
+
+ if (!defined $rc) {
+ print STDERR "ioctl failed: $!\n";
+ } elsif ($rc eq "0 but true") {
+ if ($retval >= 0) {
+ print "\nPunched $retval of an attempted $count bytes.\n";
+ print "Finished (success)\n";
+ } else {
+ print "Finished (error $retval)\n";
+ }
+ } else {
+ print "ioctl returned error code $rc.\n";
+ }
+}
+
sub Preallocate {
- my $arg = shift;
+ my $num = shift;
if (!defined($::client_id)) {
print "You must first ``connect''.\n";
return;
}
- if (!defined($arg) || scalar($arg) < 1 || scalar($arg) > 32) {
- $arg = 32;
+ if (!defined($num) || scalar($num) < 1 || scalar($num) > 32) {
+ $num = 32;
}
- print "Preallocating $arg inodes...\n";
- my $packed = pack("LLx128", $::client_id, $arg);
- # client id, alloc, inodes[32]
+ print "Preallocating $num objects...\n";
+ # client id, alloc, id[32]
+ my $packed = pack("LLx128", $::client_id, $num);
my $rc = ioctl(DEV_OBD, &OBD_IOC_PREALLOCATE, $packed);
print STDERR "ioctl failed: $!\n";
} elsif ($rc eq "0 but true") {
my $alloc = unpack("x4L", $packed);
- my @inodes = unpack("x8L32", $packed);
+ my @ids = unpack("x8L32", $packed);
my $i;
- print "Got $alloc inodes: ";
- foreach $i (@inodes) {
+ print "Got $alloc objects: ";
+ foreach $i (@ids) {
print $i . " ";
}
print "\nFinished (success)\n";
}
sub Help {
- my $arg = shift;
+ my $cmd = shift;
- if ( !$arg || !$commands{$arg} ) {
+ if ( !$cmd || !$commands{$cmd} ) {
print "Comands: ", join( ' ', @jcm_cmd_list), "\n";
} else {
- print "Usage: " . $commands{$arg}->{doc} . "\n";
+ print "Usage: " . $commands{$cmd}->{doc} . "\n";
}
}