The attached patch against 2.4.21-pre3 fixes a problem in sys_swapon.
Previous behavior:
* boot kernel with "root=/dev/sda3 init=/bin/bash" (ext3 root)
* mount -t proc proc /proc
* /sbin/swapon /dev/sda3 <--- NOTE: same as root!
* mount -n -o remount,rw /
* oops in __make_request because superblock buffer_head is
no longer mapped (via sys_swapon -> set_blocksize ->
kill_bdev-> truncate_inode_pages -> do_flushpage ->
block_flushpage -> discard_bh_page -> discard_buffer)
I think 2.5 avoids this problem by attempting to get exclusive
use of the device with bd_claim (see
http://linux.bkbits.net:8080/linux-2.5/[email protected]?nav=index.html|src/.|src/mm|related/mm/swapfile.c)
bd_claim is not in 2.4, so this seems next-best.
Bjorn
--- 1.25/mm/swapfile.c Sat Dec 28 16:18:13 2002
+++ edited/mm/swapfile.c Wed Feb 5 10:32:27 2003
@@ -915,6 +915,11 @@
struct block_device_operations *bdops;
devfs_handle_t de;
+ if (is_mounted(dev)) {
+ error = -EBUSY;
+ goto bad_swap_2;
+ }
+
p->swap_device = dev;
set_blocksize(dev, PAGE_SIZE);