scsi buffer head write capturing

From: P.Basker (
Date: Sat May 27 2000 - 13:43:32 EST

hello all (especially scsi people),

Im running 2.2.14-5.0smp on a dual processor i686, from the RH 6.2 distro.

        Im trying to capture the request function registered by the scsi device
driver in 'struct blk_dev'. The following code captures the function and
invokes itself before the real request function. Im also logging the
number of buffer_heads requested for writes.

        But, when I write a file like "/etc/termcap"(size 620k) on sda10
partition, I observe less number(around 221 blocks of 1k size) of blocks
being captured by my test code. The "df" command shows more number of
blocks being written on the disk partition.

My question is why is my test code not able to trap all the write IOs,
though, when I run a similar code for the IDE it shows me correct results.
SCSI gurus please enlighten me. Here is my test code.

                 Animesh Singh.

#define MODULE
#define __KERNEL__
#define __SMP__

#include <linux/module.h>
#include <linux/version.h>
#include <linux/proc_fs.h>
#include <asm/system.h>
#include <linux/sched.h>
#include <linux/string.h>
#include <linux/delay.h>
#include <linux/version.h>
#include <asm/irq.h>
#include <linux/kdev_t.h>
#include <linux/blk.h>

void (*readwrite_old)(void);
kdev_t source_kdev_t;
static int counter;
void readwrite_new(void){
        int flags;
        struct request *req_head;
        struct buffer_head *bh_ptr;

        for(req_head = blk_dev[SCSI_DISK0_MAJOR].current_request;
            req_head = req_head->next){
                if(req_head->rq_dev == source_kdev_t){
                        printk(KERN_CRIT "\n");
                        for(bh_ptr = req_head->bh;
                                bh_ptr = bh_ptr->b_next)
                                if(req_head->cmd == WRITE)
                        //printk(KERN_CRIT "blocknr = %ld\n",bh_ptr->b_blocknr);
        printk(KERN_CRIT "blocknr = %d\n",counter);

static struct scsi_device *marker;

int init_module(void){
        int flags;
        source_kdev_t = MKDEV(SCSI_DISK0_MAJOR,10);
        spin_lock_irqsave(&io_request_lock, flags);
        readwrite_old = blk_dev[SCSI_DISK0_MAJOR].request_fn;
        blk_dev[SCSI_DISK0_MAJOR].request_fn = readwrite_new;
void cleanup_module(void){
        int flags;
        spin_lock_irqsave(&io_request_lock, flags);
        blk_dev[SCSI_DISK0_MAJOR].request_fn = readwrite_old;
        printk("Cleaning Up and Leaving %d\n",counter);

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
Please read the FAQ at

This archive was generated by hypermail 2b29 : Wed May 31 2000 - 21:00:18 EST