summaryrefslogtreecommitdiff
path: root/systemtap/discard/test.stap
blob: 2202ba5f09ba32eaf352388270f9631836a8ce49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
function timestamp:string() {
  printf("[%012ld]\t", jiffies());
}

// Filesystem level (ext4)
probe module("ext4").function("ext4_issue_discard") {
  timestamp();
  printf("ext4_issue_discard dev=%s block_group=%u cluster=%d count=%d (=> *8 nr_sects=%d)\n", 
	 bdevname($sb->s_bdev),
	 $block_group, $cluster, $count, $count * 8);
}

// Block-Device level (disk-mapper)
probe kernel.function("blkdev_issue_discard") {
  timestamp();
  printf("blkdev_issue_discard dev=%s sector=%u nr_sects=%u\n", 
	 bdevname($bdev), $sector, $nr_sects);
}

// SCSI-Command
probe scsi.iodispatching {
  // drivers/scsi/sd.c:scsi_setup_discard_cmnd()
  if ($cmd->cmd_len >= 16 
      && $cmd->cmnd[0] == 0x93 /* WRITE_SAME_16 */
      && $cmd->cmnd[1] == 0x08 /* UNMAP */) {

    timestamp();
    printf("SCSI [WRITE_SAME_16, UNMAP, sector, count] ");

    sector = ( ($cmd->cmnd[2] << 56) +
	       ($cmd->cmnd[3] << 48) +
	       ($cmd->cmnd[4] << 40) +
	       ($cmd->cmnd[5] << 32) +
	       ($cmd->cmnd[6] << 24) +
	       ($cmd->cmnd[7] << 16) +
	       ($cmd->cmnd[8] << 8) +
	       ($cmd->cmnd[9]) );	   

    // Substract partition start position (fdisk: 22464512) + Crypto overhead (4096 sectors)
    sector = sector - 22468608;

    // Number of sectors (count)
    nr_sects = ( ($cmd->cmnd[10] << 24) +
		 ($cmd->cmnd[11] << 16) +
		 ($cmd->cmnd[12] << 8) +
		 ($cmd->cmnd[13]) );

    printf("state=%s direction=%s dev=%u:%u:%u:%u sector=%u nr_sects=%u\n",
	   device_state_str, data_direction_str, host_no, channel, lun, dev_id,
	   sector, nr_sects);
  }
}