Skip to contentSkip to conversation

don't swapon mounted devices

PATCH New Bjorn Helgaas 1 participant 1 message Feb 5, 2003

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 don't swapon mounted devices

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

mm/swapfile.c +5 -0
@@ -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);