linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* systemtap script to controlled induce of media error
@ 2014-12-24 15:34 Anand Jain
  0 siblings, 0 replies; only message in thread
From: Anand Jain @ 2014-12-24 15:34 UTC (permalink / raw)
  To: linux-btrfs

[-- Attachment #1: Type: text/plain, Size: 467 bytes --]



  A simple script which would fake media error back the upper
  level.

  First read write files and list block numbers being read/written,
  and then specify block number on which media error has to be created.
  IO will fake fail, btrfs can be tested for these error conditions.
  You won't be able to test for data consistency.

  Works on any SCSI device no need of LVM or any IO special kernel
  module.

  attached script is still a rough cut.

Thanks, Anand

[-- Attachment #2: induce-media-err.stap --]
[-- Type: text/plain, Size: 2329 bytes --]

#! /usr/bin/env stap

global inject
global dev_block
global dev_device
global fail_read = 0

#global dev_device1 = "sde"
#global dev_device2= "sdd"
#global dev_device1 = "sdg"
#global dev_device2= "sdf"
#global dev_device1 = "sdb"
#global dev_device2= "sdc"


probe begin
{
	inject = $1
	dev_block = $2
	dev_device = @3
	#printf("BEGIN: %d %lx %s %s %s\n", inject, dev_block, dev_device, dev_device1, dev_device2);
	printf("BEGIN: %d %lx %s\n", inject, dev_block, dev_device);
}

probe kernel.function("sd_prep_fn") !,
	module("*").function("sd_prep_fn")
{
	if ($rq->rq_disk->disk_name != NULL)
        	device = kernel_string($rq->rq_disk->disk_name)
	else
		device = "none"

	#if (device == dev_device1 || device == dev_device2) {
	if (device == dev_device) {
        	if($rq->cmd_flags & 1)
			read_or_write = "w"
        	else
			read_or_write = "r"

        	printf("%s %s %lx\n", device, read_or_write, $rq->__sector)

		#if (inject && (dev_device1 == device || dev_device2 == device) && dev_block == $rq->__sector) {
		if (inject && dev_device == device && dev_block == $rq->__sector) {
			if (read_or_write == "r") {
				fail_read = 1
				printf("Trigger enabled.. ");
			} else if (read_or_write == "w" && fail_read) {
				fail_read = 0
				printf("Fix write appeared. Trigger disabled\n");
			}
		}
	}
}

probe module("*").function("scsi_decide_disposition@drivers/scsi/scsi_error.c") !,
	kernel.function("scsi_decide_disposition@drivers/scsi/scsi_error.c")
{
	if ($scmd->request->rq_disk->disk_name != NULL)
		device = kernel_string($scmd->request->rq_disk->disk_name)
	else
		device = "none"

        if($scmd->request->cmd_flags & 1)
		read_or_write = "w"
        else
		read_or_write = "r"

	block = $scmd->request->__sector

	#if ((device == dev_device1 || device == dev_device2) && fail_read && block == dev_block && read_or_write == "r")
	if (device == dev_device && fail_read && block == dev_block && read_or_write == "r")
	{
		printf("Failing the CDB .. ")
		printf("%s %s %lx\n", device, read_or_write, block)
		/* create fake status and sense data */
		$scmd->result = 0x02
		$scmd->sense_buffer[0] = 0x70
		$scmd->sense_buffer[2] = 0x03
		$scmd->sense_buffer[7] = 0x13
		$scmd->sense_buffer[12] = 0x11
		$scmd->sense_buffer[13] = 0x04
	}
}

probe end
{
	delete inject
	delete dev_block
	delete dev_device
}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2014-12-24 15:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-24 15:34 systemtap script to controlled induce of media error Anand Jain

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).