Whamcloud - gitweb
class_obd.c: plugged a few minor memory leaks
authoradilger <adilger>
Mon, 6 Mar 2000 03:12:37 +0000 (03:12 +0000)
committeradilger <adilger>
Mon, 6 Mar 2000 03:12:37 +0000 (03:12 +0000)
obdcontrol: added IOCTL for punch

lustre/obdclass/class_obd.c
lustre/obdclass/obdcontrol

index b826c14..51904f8 100644 (file)
@@ -59,7 +59,8 @@
 
 static int obd_init_magic;
 int obd_print_entry = 0;
 
 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;
 
 struct obd_device obd_dev[MAX_OBD_DEVICES];
 struct list_head obd_types;
 
@@ -132,10 +133,12 @@ static int getdata(int len, void **data)
 {
        void *tmp = NULL;
 
 {
        void *tmp = NULL;
 
-       if (!len) 
+       if (!len) {
+               *data = NULL;
                return 0;
                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 )
 
        OBD_ALLOC(tmp, void *, len);
        if ( !tmp )
@@ -143,7 +146,7 @@ static int getdata(int len, void **data)
        
        memset(tmp, 0, len);
        if ( copy_from_user(tmp, *data, len)) {
        
        memset(tmp, 0, len);
        if ( copy_from_user(tmp, *data, len)) {
-               OBD_FREE(tmp,len);
+               OBD_FREE(tmp, len);
                return -EFAULT;
        }
        *data = tmp;
                return -EFAULT;
        }
        *data = tmp;
@@ -239,14 +242,16 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp,
                INIT_LIST_HEAD(&obddev->obd_gen_clients);
                obddev->obd_multi_count = 0;
 
                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) ) {
                       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);
                        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;
                        MOD_INC_USE_COUNT;
                        EXIT;
                        return 0;
@@ -255,7 +260,8 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp,
                /* do the attach */
                err = OBP(obddev, attach)(obddev, input->att_datalen,
                                          input->att_data);
                /* 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;
 
                if ( err ) {
                        obddev->obd_flags &= ~OBD_ATTACHED;
@@ -345,6 +351,9 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp,
                        obddev->obd_type->typ_refcnt++;
                        CDEBUG(D_PSDEV, "Dev %d refcount now %d\n",
                               dev, obddev->obd_type->typ_refcnt);
                        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;
                        return 0;
@@ -363,6 +372,8 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp,
                        obddev->obd_flags |= OBD_SET_UP;
                        EXIT;
                }
                        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: {
                return err;
        }
        case OBD_IOC_CLEANUP: {
@@ -968,6 +979,7 @@ void cleanup_module(void)
 
        obd_cleanup_obdo_cache();
        obd_sysctl_clean();
 
        obd_cleanup_obdo_cache();
        obd_sysctl_clean();
+       CDEBUG(D_MALLOC, "CLASS mem used %ld\n", obd_memory);
        obd_init_magic = 0;
        EXIT;
 }
        obd_init_magic = 0;
        EXIT;
 }
index d070c03..0e11f78 100755 (executable)
@@ -61,6 +61,8 @@ 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);
   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
 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
@@ -232,6 +234,7 @@ my %commands =
      '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"},
      '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."},
      '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."},
@@ -1244,8 +1247,7 @@ sub Write {
        $count = 0;
     }
 
        $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;
 
     my $obdo;
     $obdo->{id} = $id;
@@ -1272,6 +1274,49 @@ sub Write {
     }
 }
 
     }
 }
 
+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;
 
 sub Preallocate {
     my $num = shift;