public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] loop device failing on demand (2.4)
@ 2002-08-26 12:06 Lars Marowsky-Bree
  0 siblings, 0 replies; only message in thread
From: Lars Marowsky-Bree @ 2002-08-26 12:06 UTC (permalink / raw)
  To: linux-kernel

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

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


[-- Attachment #2: loopdevice.patch --]
[-- Type: text/plain, Size: 1532 bytes --]

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

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

only message in thread, other threads:[~2002-08-26 12:02 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-08-26 12:06 [PATCH] loop device failing on demand (2.4) Lars Marowsky-Bree

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox