[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

avoid creation of partitions beyond actual capacity (patch for 2.6.15)



In reply to: "Here is how to stop the new udev from accessing your
striped	 dmraid drives (Peter Jones)"

Hi folkes,

When using striped Fake-Raid's the partition table of a RAID set is
oftenly found at the fist sector on one of the underlying disks. This
confuses the kernel which creates partitions for every disk carrying a
partition table. It's very likely such a partition starts at an offset
beyond the end of a single device that belongs to the striped set. The
result is a partition like /dev/sdXY which starts at an offset beyound the
maximum capacity of the device. If any (user-)code accesses the device the
kernel will output scary block IO errors. Udev will acces the device, so
the errors will occur everytime you boot.

People on this list are proposing to prevent udev, hal et altera to access
the device. This can be done by removing udev rules, like the way Peter
Jones describes. I solved the underlying problem on my setup by a kernel
patch. I never felt any need to share the code, until now: The code seems
to be interesting for more people.

My approach just prevents the kernel to create invalid partitions:
partitions beyond the end of a device won't be created (the offset is set
to zero and rest of the existing code path won't create the partition).
In fact the patch adds a check in the partition detection code. Not
creating partitions with an offset >= capacity won't hurt any other code.
Not using the patch won't hurt either, but I found it annoying to see
Block IO errors in my syslogger just because of a tiny kernel bug.

You can download / review the patch here:
http://tienstra4.flatnet.tudelft.nl/~gerte/linux-2.6.15-dont-create-incorrect-partitions.txt

A copy of the patch has been attached to this e-mail.

Feel free to alter or include in any distribution,
Gerte
diff -Nur linux-2.6.15/fs/partitions/check.c linux-2.6.15-check/fs/partitions/check.c
--- linux-2.6.15/fs/partitions/check.c	2006-01-03 04:21:10.000000000 +0100
+++ linux-2.6.15-check/fs/partitions/check.c	2006-02-08 21:20:03.000000000 +0100
@@ -175,8 +175,19 @@
 		memset(&state->parts, 0, sizeof(state->parts));
 		res = check_part[i++](state, bdev);
 	}
-	if (res > 0)
+	if (res > 0) {
+		sector_t from, cap;
+		for(i = 1; i < state->limit; i++) {
+			from = state->parts[i].from;
+			cap = get_capacity(hd);
+			if(state->parts[i].size + from > cap) {
+				printk(KERN_WARNING " %s: partition %s%d beyond device capacity\n",
+						hd->disk_name, hd->disk_name, i);
+				state->parts[i].size = cap - (from < cap ? from : cap);
+			}
+		}
 		return state;
+	}
 	if (!res)
 		printk(" unknown partition table\n");
 	else if (warn_no_part)

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]