Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 43757
b: refs/heads/master
c: c17bb49
h: refs/heads/master
i:
  43755: 0ca8a41
v: v3
  • Loading branch information
Akinobu Mita authored and Linus Torvalds committed Dec 8, 2006
1 parent 0d39ce1 commit 59e7157
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 933e312e73f8fc39652bd4d216a5393cc3a014b9
refs/heads/master: c17bb4951752d3e0f49cd1ea9d2e868422f9e0d6
31 changes: 31 additions & 0 deletions trunk/block/genhd.c
Original file line number Diff line number Diff line change
Expand Up @@ -417,13 +417,44 @@ static struct disk_attribute disk_attr_stat = {
.show = disk_stats_read
};

#ifdef CONFIG_FAIL_MAKE_REQUEST

static ssize_t disk_fail_store(struct gendisk * disk,
const char *buf, size_t count)
{
int i;

if (count > 0 && sscanf(buf, "%d", &i) > 0) {
if (i == 0)
disk->flags &= ~GENHD_FL_FAIL;
else
disk->flags |= GENHD_FL_FAIL;
}

return count;
}
static ssize_t disk_fail_read(struct gendisk * disk, char *page)
{
return sprintf(page, "%d\n", disk->flags & GENHD_FL_FAIL ? 1 : 0);
}
static struct disk_attribute disk_attr_fail = {
.attr = {.name = "make-it-fail", .mode = S_IRUGO | S_IWUSR },
.store = disk_fail_store,
.show = disk_fail_read
};

#endif

static struct attribute * default_attrs[] = {
&disk_attr_uevent.attr,
&disk_attr_dev.attr,
&disk_attr_range.attr,
&disk_attr_removable.attr,
&disk_attr_size.attr,
&disk_attr_stat.attr,
#ifdef CONFIG_FAIL_MAKE_REQUEST
&disk_attr_fail.attr,
#endif
NULL,
};

Expand Down
40 changes: 40 additions & 0 deletions trunk/block/ll_rw_blk.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <linux/interrupt.h>
#include <linux/cpu.h>
#include <linux/blktrace_api.h>
#include <linux/fault-inject.h>

/*
* for max sense size
Expand Down Expand Up @@ -3056,6 +3057,42 @@ static void handle_bad_sector(struct bio *bio)
set_bit(BIO_EOF, &bio->bi_flags);
}

#ifdef CONFIG_FAIL_MAKE_REQUEST

static DECLARE_FAULT_ATTR(fail_make_request);

static int __init setup_fail_make_request(char *str)
{
return setup_fault_attr(&fail_make_request, str);
}
__setup("fail_make_request=", setup_fail_make_request);

static int should_fail_request(struct bio *bio)
{
if ((bio->bi_bdev->bd_disk->flags & GENHD_FL_FAIL) ||
(bio->bi_bdev->bd_part && bio->bi_bdev->bd_part->make_it_fail))
return should_fail(&fail_make_request, bio->bi_size);

return 0;
}

static int __init fail_make_request_debugfs(void)
{
return init_fault_attr_dentries(&fail_make_request,
"fail_make_request");
}

late_initcall(fail_make_request_debugfs);

#else /* CONFIG_FAIL_MAKE_REQUEST */

static inline int should_fail_request(struct bio *bio)
{
return 0;
}

#endif /* CONFIG_FAIL_MAKE_REQUEST */

/**
* generic_make_request: hand a buffer to its device driver for I/O
* @bio: The bio describing the location in memory and on the device.
Expand Down Expand Up @@ -3141,6 +3178,9 @@ void generic_make_request(struct bio *bio)
if (unlikely(test_bit(QUEUE_FLAG_DEAD, &q->queue_flags)))
goto end_io;

if (should_fail_request(bio))
goto end_io;

/*
* If this device has partitions, remap block n
* of partition p to block n+start(p) of the disk.
Expand Down
27 changes: 27 additions & 0 deletions trunk/fs/partitions/check.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,39 @@ static struct part_attribute part_attr_stat = {
.show = part_stat_read
};

#ifdef CONFIG_FAIL_MAKE_REQUEST

static ssize_t part_fail_store(struct hd_struct * p,
const char *buf, size_t count)
{
int i;

if (count > 0 && sscanf(buf, "%d", &i) > 0)
p->make_it_fail = (i == 0) ? 0 : 1;

return count;
}
static ssize_t part_fail_read(struct hd_struct * p, char *page)
{
return sprintf(page, "%d\n", p->make_it_fail);
}
static struct part_attribute part_attr_fail = {
.attr = {.name = "make-it-fail", .mode = S_IRUGO | S_IWUSR },
.store = part_fail_store,
.show = part_fail_read
};

#endif

static struct attribute * default_attrs[] = {
&part_attr_uevent.attr,
&part_attr_dev.attr,
&part_attr_start.attr,
&part_attr_size.attr,
&part_attr_stat.attr,
#ifdef CONFIG_FAIL_MAKE_REQUEST
&part_attr_fail.attr,
#endif
NULL,
};

Expand Down
4 changes: 4 additions & 0 deletions trunk/include/linux/genhd.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,17 @@ struct hd_struct {
struct kobject *holder_dir;
unsigned ios[2], sectors[2]; /* READs and WRITEs */
int policy, partno;
#ifdef CONFIG_FAIL_MAKE_REQUEST
int make_it_fail;
#endif
};

#define GENHD_FL_REMOVABLE 1
#define GENHD_FL_DRIVERFS 2
#define GENHD_FL_CD 8
#define GENHD_FL_UP 16
#define GENHD_FL_SUPPRESS_PARTITION_INFO 32
#define GENHD_FL_FAIL 64

struct disk_stats {
unsigned long sectors[2]; /* READs and WRITEs */
Expand Down
7 changes: 7 additions & 0 deletions trunk/lib/Kconfig.debug
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,13 @@ config FAIL_PAGE_ALLOC
help
This option provides fault-injection capabilitiy for alloc_pages().

config FAIL_MAKE_REQUEST
bool "Fault-injection capabilitiy for disk IO"
depends on DEBUG_KERNEL
select FAULT_INJECTION
help
This option provides fault-injection capabilitiy to disk IO.

config FAULT_INJECTION_DEBUG_FS
bool "Debugfs entries for fault-injection capabilities"
depends on FAULT_INJECTION && SYSFS
Expand Down

0 comments on commit 59e7157

Please sign in to comment.