[8921] in linux-scsi channel archive

home help back first fref pref prev next nref lref last post

scsi buffer head write capturing

daemon@ATHENA.MIT.EDU (P.Basker)
Mon May 29 04:01:17 2000

Date:	Mon, 29 May 2000 12:01:34 +0530 (IST)
From: "P.Basker" <basker_p@bbv.satyam.com>
To: linux-scsi@vger.rutgers.edu
Message-ID: <Pine.LNX.4.21.0005291200370.4028-100000@archimedes.bbv.satyam.com>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII

hello all,

I have this problem with scsi buffer cache mechanism. 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.
Here is my test code. Please enlighten me..

	TIA

		 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 = 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 = bh_ptr->b_next)
				if(req_head->cmd == WRITE)
					++counter;
			//printk(KERN_CRIT "blocknr = %ld\n",bh_ptr->b_blocknr);
		}
	}
	printk(KERN_CRIT "blocknr = %d\n",counter);
	readwrite_old();
}

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;
	spin_unlock_irqrestore(&io_request_lock,flags);
        return(0);
}
void cleanup_module(void){
	int 	flags;
	spin_lock_irqsave(&io_request_lock, flags);
	blk_dev[SCSI_DISK0_MAJOR].request_fn = readwrite_old;
	spin_unlock_irqrestore(&io_request_lock,flags);	
        printk("Cleaning Up and Leaving %d\n",counter);
}






-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@vger.rutgers.edu

home help back first fref pref prev next nref lref last post