lkml.org 
[lkml]   [2002]   [Aug]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH] loop device failing on demand (2.4)
The attached small patch allows to "fail" a loop device on demand. Any further
request to the loop device will simply fail.

Even though it of course doesn't simulate the failures one might see in the
field, it is kind of handy for automated tests, for example for multipath I/O.

Done by Jens Axboe. The reason why I am sending it: I need it most and he is
on vacation.


Sincerely,
Lars Marowsky-Brée <lmb@suse.de>

--
Immortality is an adequate definition of high availability for me.
--- Gregory F. Pfister

diff -ur /opt/kernel/linux-2.4.20-pre1/drivers/block/loop.c linux/drivers/block/loop.c
--- /opt/kernel/linux-2.4.20-pre1/drivers/block/loop.c 2002-08-03 02:39:43.000000000 +0200
+++ linux/drivers/block/loop.c 2002-08-09 09:59:42.000000000 +0200
@@ -473,6 +473,11 @@
atomic_inc(&lo->lo_pending);
spin_unlock_irq(&lo->lo_lock);

+ if (lo->lo_flags & LO_FLAGS_FAIL) {
+ printk("%s: failing %s\n", kdevname(rbh->b_rdev), rw == WRITE ? "write" : "read");
+ goto err;
+ }
+
if (rw == WRITE) {
if (lo->lo_flags & LO_FLAGS_READ_ONLY)
goto err;
@@ -877,6 +880,14 @@
case LOOP_GET_STATUS:
err = loop_get_status(lo, (struct loop_info *) arg);
break;
+ case LOOP_SET_FAIL:
+ lo->lo_flags |= LO_FLAGS_FAIL;
+ err = 0;
+ break;
+ case LOOP_CLEAR_FAIL:
+ lo->lo_flags &= ~LO_FLAGS_FAIL;
+ err = 0;
+ break;
case BLKGETSIZE:
if (lo->lo_state != Lo_bound) {
err = -ENXIO;
diff -ur /opt/kernel/linux-2.4.20-pre1/include/linux/loop.h linux/include/linux/loop.h
--- /opt/kernel/linux-2.4.20-pre1/include/linux/loop.h 2001-09-17 22:16:30.000000000 +0200
+++ linux/include/linux/loop.h 2002-08-08 12:01:56.000000000 +0200
@@ -78,6 +78,7 @@
#define LO_FLAGS_DO_BMAP 1
#define LO_FLAGS_READ_ONLY 2
#define LO_FLAGS_BH_REMAP 4
+#define LO_FLAGS_FAIL 8

/*
* Note that this structure gets the wrong offsets when directly used
@@ -151,5 +152,7 @@
#define LOOP_CLR_FD 0x4C01
#define LOOP_SET_STATUS 0x4C02
#define LOOP_GET_STATUS 0x4C03
+#define LOOP_SET_FAIL 0x4c04
+#define LOOP_CLEAR_FAIL 0x4c05

#endif
\
 
 \ /
  Last update: 2005-03-22 13:28    [W:0.042 / U:0.096 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site