[PATCH 12/21] mm: block device swap notification

From: Peter Zijlstra
Date: Wed Sep 06 2006 - 09:40:53 EST


Some block devices need to do some extra work when used as swap device.

Signed-off-by: Peter Zijlstra <a.p.zijlstra@xxxxxxxxx>
CC: James E.J. Bottomley <James.Bottomley@xxxxxxxxxxxx>
CC: Mike Christie <michaelc@xxxxxxxxxxx>
CC: Pavel Machek <pavel@xxxxxx>
---
include/linux/fs.h | 1 +
mm/swapfile.c | 7 +++++++
2 files changed, 8 insertions(+)

Index: linux-2.6/include/linux/fs.h
===================================================================
--- linux-2.6.orig/include/linux/fs.h
+++ linux-2.6/include/linux/fs.h
@@ -1017,6 +1017,7 @@ struct block_device_operations {
int (*media_changed) (struct gendisk *);
int (*revalidate_disk) (struct gendisk *);
int (*getgeo)(struct block_device *, struct hd_geometry *);
+ int (*swapdev)(struct gendisk *, int enable);
struct module *owner;
};

Index: linux-2.6/mm/swapfile.c
===================================================================
--- linux-2.6.orig/mm/swapfile.c
+++ linux-2.6/mm/swapfile.c
@@ -1273,6 +1273,8 @@ asmlinkage long sys_swapoff(const char _
inode = mapping->host;
if (S_ISBLK(inode->i_mode)) {
struct block_device *bdev = I_BDEV(inode);
+ if (bdev->bd_disk->fops->swapdev)
+ bdev->bd_disk->fops->swapdev(bdev->bd_disk, 0);
set_blocksize(bdev, p->old_block_size);
bd_release(bdev);
} else {
@@ -1481,6 +1483,11 @@ asmlinkage long sys_swapdev(const char __
if (error < 0)
goto bad_swap;
p->bdev = bdev;
+ if (bdev->bd_disk->fops->swapdev) {
+ error = bdev->bd_disk->fops->swapdev(bdev->bd_disk, 1);
+ if (error < 0)
+ goto bad_swap;
+ }
} else if (S_ISREG(inode->i_mode)) {
p->bdev = inode->i_sb->s_bdev;
mutex_lock(&inode->i_mutex);

--
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/