static int obd_init_magic;
int obd_print_entry = 0;
-int obd_debug_level = D_IOCTL|D_INODE|D_SUPER|D_WARNING;
+int obd_debug_level = D_IOCTL|D_INODE|D_SUPER|D_WARNING|D_MALLOC|D_CACHE;
+long obd_memory = 0;
struct obd_device obd_dev[MAX_OBD_DEVICES];
struct list_head obd_types;
{
void *tmp = NULL;
- if (!len)
+ if (!len) {
+ *data = NULL;
return 0;
+ }
- CDEBUG(D_INFO, "getdata: len %d, add %p\n", len, *data);
+ CDEBUG(D_MALLOC, "len %d, add %p\n", len, *data);
OBD_ALLOC(tmp, void *, len);
if ( !tmp )
memset(tmp, 0, len);
if ( copy_from_user(tmp, *data, len)) {
- OBD_FREE(tmp,len);
+ OBD_FREE(tmp, len);
return -EFAULT;
}
*data = tmp;
INIT_LIST_HEAD(&obddev->obd_gen_clients);
obddev->obd_multi_count = 0;
- CDEBUG(D_INFO, "Attach %d, datalen %d, type %s\n",
+ 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;
+ 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;
/* do the attach */
err = OBP(obddev, attach)(obddev, input->att_datalen,
input->att_data);
- OBD_FREE(input->att_data, input->att_datalen);
+ if (input->att_data)
+ OBD_FREE(input->att_data, input->att_datalen);
if ( err ) {
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);
+ if (setup->setup_data)
+ OBD_FREE(setup->setup_data,
+ setup->setup_datalen);
obddev->obd_flags |= OBD_SET_UP;
EXIT;
return 0;
obddev->obd_flags |= OBD_SET_UP;
EXIT;
}
+ if (setup->setup_data)
+ OBD_FREE(setup->setup_data, setup->setup_datalen);
return err;
}
case OBD_IOC_CLEANUP: {
obd_cleanup_obdo_cache();
obd_sysctl_clean();
+ CDEBUG(D_MALLOC, "CLASS mem used %ld\n", obd_memory);
obd_init_magic = 0;
EXIT;
}
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
'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."},
$count = 0;
}
- print("Writing $count bytes starting at byte $offset to object " .
- "$id...\n");
+ print("Writing $count bytes starting at byte $offset to object $id...\n");
my $obdo;
$obdo->{id} = $id;
}
}
+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 $num = shift;