]> sourceware.org Git - systemtap.git/commitdiff
Fixed PR22287 by updating the ioblock tapset.
authorDavid Smith <dsmith@redhat.com>
Thu, 12 Oct 2017 21:47:16 +0000 (16:47 -0500)
committerDavid Smith <dsmith@redhat.com>
Thu, 12 Oct 2017 21:47:16 +0000 (16:47 -0500)
* tapset/linux/ioblock.stp (disk_get_part_start_sect): New function.
  (bio_rw_str): Handles 'struct bio' changes from kernel commit 74d46992e.
  (__bio_devname): Ditto.
  (ioblock.request): Ditto.
  (ioblock_trace.bounce): Ditto.
  (ioblock_trace.request): Ditto.
  (ioblock_trace.end): Ditto.
* tapset/linux/dev.stp (bdevname): Extract code into into disk_name() and
  just call it.
* buildrun.cxx (compile_pass): Add exportconf test for disk_get_part().
* testsuite/buildok/dev-embedded.stp: Updated.

buildrun.cxx
tapset/linux/dev.stp
tapset/linux/ioblock.stp
testsuite/buildok/dev-embedded.stp

index a72f05d9b01ea8777ae3cc06af3c218e59728aae..076204700f5ea4b74b7646f274d7a95c01aa1a9e 100644 (file)
@@ -470,6 +470,9 @@ compile_pass (systemtap_session& s)
   // used by runtime/linux/netfilter.c
   output_exportconf(s, o, "nf_register_hook", "STAPCONF_NF_REGISTER_HOOK");
 
+  // used by tapset/linux/ioblock.stp
+  output_exportconf(s, o, "disk_get_part", "STAPCONF_DISK_GET_PART");
+
   o << module_cflags << " += -include $(STAPCONF_HEADER)" << endl;
 
   for (unsigned i=0; i<s.c_macros.size(); i++)
index debb7dce1e5a7d5f60cb512806cd1327e96525ba..0232fc9b72d6c0cf309e0d3d1d127a2b483d45a1 100644 (file)
@@ -53,6 +53,17 @@ function usrdev2kerndev:long(dev:long)
     STAP_RETVALUE = new_decode_dev(STAP_ARG_dev);
 %}
 
+function disk_name:string(hd:long, partno:long)
+{
+       if (!partno)
+               return kernel_string(@cast(hd, "gendisk")->disk_name)
+       disk_name = kernel_string(@cast(hd, "gendisk")->disk_name)
+       if (isdigit(substr(disk_name, strlen(disk_name)-1, 1)))
+               return sprintf("%sp%d", disk_name, partno)
+       else
+               return sprintf("%s%d", disk_name, partno)
+}
+
 function bdevname:string(bdev:long)
 {
        bdev = & @cast(bdev, "block_device")
@@ -65,12 +76,5 @@ function bdevname:string(bdev:long)
                partno = bdev->bd_part->partno
        else
                partno = MINOR(bdev->bd_dev) - hd->first_minor;
-
-       if (!partno)
-               return kernel_string(hd->disk_name)
-       disk_name = kernel_string(hd->disk_name)
-       if (isdigit(substr(disk_name, strlen(disk_name) - 1, 1)))
-               return sprintf("%sp%d", disk_name, partno)
-       else
-               return sprintf("%s%d", disk_name, partno)
+       return disk_name(hd, partno)
 }
index e6798fc6dbfeea54a42c968dd7a4a805080bc2b0..ad3603c24d69d76a663593d14d96bc0017d914ed 100644 (file)
 #endif
 %}
 
+private function disk_get_part_start_sect:long(disk:long, partno:long)
+%{ /* pure */ /* unprivileged */
+#if defined(STAPCONF_DISK_GET_PART)
+    struct gendisk *disk = (struct gendisk *)(uintptr_t)STAP_ARG_disk;
+    int partno = (int)STAP_ARG_partno;
+    struct hd_struct *part;
+
+    STAP_RETVALUE = 0;
+    if (disk) {
+       /* Before calling disk_get_part() on 'disk', we need to make
+        * sure the memory is readable. */
+       (void)kread(&(disk->part_tbl));
+       part = disk_get_part(disk, partno);
+
+       if (part) {
+           /* Let's be doubly paranoid and make sure this memory is
+            * safe for reading. */
+           (void)kread(&(part->start_sect));
+           STAP_RETVALUE = part->start_sect;
+           disk_put_part(part);
+       }
+    }
+    CATCH_DEREF_FAULT();
+#endif
+%}
+
 /* Returns the REQ_OP_* bits for a bio structure. */
 function bio_op:long(bio:long)
 %{ /* pure */ /* unprivileged */
@@ -81,7 +107,13 @@ function bio_rw_str(rw:long)
 @__private30 function __bio_start_sect:long(bio:long)
 {
     try {
-        return @cast(bio, "bio")->bi_bdev->bd_part->start_sect
+       if (@defined(@cast(bio, "bio")->bi_dev)) {
+           return @cast(bio, "bio")->bi_bdev->bd_part->start_sect
+       }
+       else if (@defined(@cast(bio, "bio")->bi_disk)) {
+           return disk_get_part_start_sect(@cast(bio, "bio")->bi_disk,
+                                           @cast(bio, "bio")->bi_partno)
+       }
     } catch {
         return -1
     }
@@ -90,7 +122,13 @@ function bio_rw_str(rw:long)
 /* returns the block device name */
 @__private30 function __bio_devname:string(bio:long)
 {
-    return bdevname(@cast(bio, "bio")->bi_bdev)
+    if (@defined(@cast(bio, "bio")->bi_bdev)) {
+       return bdevname(@cast(bio, "bio")->bi_bdev)
+    }
+    else {
+       return disk_name(@cast(bio, "bio")->bi_disk,
+                        @cast(bio, "bio")->bi_partno)
+    }
 }
 
 global BIO_READ = 0, BIO_WRITE = 1
@@ -147,8 +185,8 @@ probe ioblock.request = kernel.function ("generic_make_request")
        hw_segments = @choose_defined($bio->bi_hw_segments, 0)
         size = @choose_defined($bio->bi_iter->bi_size, $bio->bi_size)
 
-        bdev = $bio->bi_bdev
-        bdev_contains = $bio->bi_bdev->bd_contains
+        bdev = @choose_defined($bio->bi_bdev, 0)
+        bdev_contains = @choose_defined($bio->bi_bdev->bd_contains, 0)
         p_start_sect = __bio_start_sect($bio)
 }
 
@@ -261,8 +299,8 @@ probe ioblock_trace.bounce = kernel.trace("block_bio_bounce")
         idx = @choose_defined($bio->bi_iter->bi_idx, $bio->bi_idx)
         phys_segments = $bio->bi_phys_segments
         size = @choose_defined($bio->bi_iter->bi_size, $bio->bi_size)
-        bdev_contains = $bio->bi_bdev->bd_contains
-        bdev = $bio->bi_bdev
+        bdev_contains = @choose_defined($bio->bi_bdev->bd_contains, 0)
+        bdev = @choose_defined($bio->bi_bdev, 0)
         p_start_sect = __bio_start_sect($bio)
 }
 
@@ -318,8 +356,8 @@ probe ioblock_trace.request = kernel.trace("block_bio_queue")
         idx = @choose_defined($bio->bi_iter->bi_idx, $bio->bi_idx)
         phys_segments = $bio->bi_phys_segments
         size = @choose_defined($bio->bi_iter->bi_size, $bio->bi_size)
-        bdev_contains = $bio->bi_bdev->bd_contains
-        bdev = $bio->bi_bdev
+        bdev_contains = @choose_defined($bio->bi_bdev->bd_contains, 0)
+        bdev = @choose_defined($bio->bi_bdev, 0)
         p_start_sect = __bio_start_sect($bio)
 }
 
@@ -376,7 +414,7 @@ probe ioblock_trace.end = kernel.trace("block_bio_complete")
         idx = @choose_defined($bio->bi_iter->bi_idx, $bio->bi_idx)
         phys_segments = $bio->bi_phys_segments
         size = @choose_defined($bio->bi_iter->bi_size, $bio->bi_size)
-        bdev_contains = $bio->bi_bdev->bd_contains
-        bdev = $bio->bi_bdev
+        bdev_contains = @choose_defined($bio->bi_bdev->bd_contains, 0)
+        bdev = @choose_defined($bio->bi_bdev, 0)
         p_start_sect = __bio_start_sect($bio)
 }
index 60e6a44f8ffd9a584333f41bc3ff9d3e636edb3e..413c8e417730aa3b235dd04bf7ee8f2cb85fb687 100755 (executable)
@@ -5,6 +5,7 @@ probe begin {
        print(MINOR(0))
        print(MKDEV(0, 0))
        print(usrdev2kerndev(0))
+       print(disk_name(0, 0))
        print(bdevname(0))
 }
 
This page took 0.040675 seconds and 5 git commands to generate.