/* jprobebio.c
   This is a simple module to get information about block io operations.
   Will Cohen
*/

#include 
#include 
#include 
#include 
#include 

#define LOG_2_BINS 8
#define BINS (1<bi_bdev, LOG_2_BINS);

  ++count_generic_make_request;
  sectors_transferred += bio_sectors(bio);

  if( bin_bdev[b] == NULL || bin_bdev[b] == bio->bi_bdev) {
	  bin_bdev[b] = bio->bi_bdev;
	  bin_bd_dev[b] = bio->bi_bdev->bd_dev;
	  ++bin_count[b];
	  bin_sectors[b] += bio_sectors(bio);
  }
  jprobe_return();
}

static struct jprobe my_jprobe = {
	.kp.addr = (kprobe_opcode_t *) generic_make_request,
	.entry = (kprobe_opcode_t *) inst_generic_make_request
};

int init_module(void)
{
	register_jprobe(&my_jprobe);
	printk("plant jprobe at %p, handler addr %p\n",
	       my_jprobe.kp.addr, my_jprobe.entry);
	return 0;
}

void cleanup_module(void)
{
  int b;

  unregister_jprobe(&my_jprobe);
  printk("jprobe unregistered\n");

  printk("generic_make_request() called %d times for %lld sectors.\n",
	 count_generic_make_request, sectors_transferred);
  for (b=0; b<BINS; ++b)
    if (bin_bdev[b] != NULL) 
      printk("bdev 0x%p (%d,%d) %d %lld sectors.\n", bin_bdev[b],
	     MAJOR(bin_bd_dev[b]), MINOR(bin_bd_dev[b]),
	     bin_count[b], bin_sectors[b]);
}

MODULE_LICENSE("GPL");

Download this file.
Close this window