[PATCH 13/21] nbd: use swapdev hook to make swap deadlock free

Peter Zijlstra
2006-09-06T13:42:29Z

[-- Attachment #1: nbd_vmio.patch --]
[-- Type: text/plain, Size: 1636 bytes --]

Use sk_set_vmio() on the nbd socket.

Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Signed-off-by: Daniel Phillips <phillips@google.com>
CC: Pavel Machek <pavel@ucw.cz>
---
drivers/block/nbd.c | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)

Index: linux-2.6/drivers/block/nbd.c
===================================================================
--- linux-2.6.orig/drivers/block/nbd.c
+++ linux-2.6/drivers/block/nbd.c
@@ -135,7 +135,6 @@ static int sock_xmit(struct socket *sock
spin_unlock_irqrestore(&current->sighand->siglock, flags);

do {
- sock->sk->sk_allocation = GFP_NOIO;
iov.iov_base = buf;
iov.iov_len = size;
msg.msg_name = NULL;
@@ -525,6 +524,7 @@ static int nbd_ioctl(struct inode *inode
if (S_ISSOCK(inode->i_mode)) {
lo->file = file;
lo->sock = SOCKET_I(inode);
+ lo->sock->sk->sk_allocation = GFP_NOIO;
error = 0;
} else {
fput(file);
@@ -594,10 +594,30 @@ static int nbd_ioctl(struct inode *inode
return -EINVAL;
}

+static int nbd_swapdev(struct gendisk *disk, int enable)
+{
+ struct nbd_device *lo = disk->private_data;
+
+ if (enable) {
+ sk_adjust_memalloc(0, TX_RESERVE_PAGES);
+ if (!sk_set_vmio(lo->sock->sk))
+ printk(KERN_WARNING
+ "failed to set SOCK_VMIO on NBD socket\n");
+ } else {
+ if (!sk_clear_vmio(lo->sock->sk))
+ printk(KERN_WARNING
+ "failed to clear SOCK_VMIO on NBD socket\n");
+ sk_adjust_memalloc(0, -TX_RESERVE_PAGES);
+ }
+
+ return 0;
+}
+
static struct block_device_operations nbd_fops =
{
.owner = THIS_MODULE,
.ioctl = nbd_ioctl,
+ .swapdev = nbd_swapdev,
};

/*

--