]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/3.4.83/nbd-correct-disconnect-behavior.patch
5.1-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 3.4.83 / nbd-correct-disconnect-behavior.patch
CommitLineData
1a306361
GKH
1From c378f70adbc1bbecd9e6db145019f14b2f688c7c Mon Sep 17 00:00:00 2001
2From: Paul Clements <paul.clements@steeleye.com>
3Date: Wed, 3 Jul 2013 15:09:04 -0700
4Subject: nbd: correct disconnect behavior
5
6From: Paul Clements <paul.clements@steeleye.com>
7
8commit c378f70adbc1bbecd9e6db145019f14b2f688c7c upstream.
9
10Currently, when a disconnect is requested by the user (via NBD_DISCONNECT
11ioctl) the return from NBD_DO_IT is undefined (it is usually one of
12several error codes). This means that nbd-client does not know if a
13manual disconnect was performed or whether a network error occurred.
14Because of this, nbd-client's persist mode (which tries to reconnect after
15error, but not after manual disconnect) does not always work correctly.
16
17This change fixes this by causing NBD_DO_IT to always return 0 if a user
18requests a disconnect. This means that nbd-client can correctly either
19persist the connection (if an error occurred) or disconnect (if the user
20requested it).
21
22Signed-off-by: Paul Clements <paul.clements@steeleye.com>
23Acked-by: Rob Landley <rob@landley.net>
24Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
25Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
26[xr: Backported to 3.4: adjust context]
27Signed-off-by: Rui Xiang <rui.xiang@huawei.com>
28Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
29
30---
31 drivers/block/nbd.c | 8 +++++++-
32 include/linux/nbd.h | 1 +
33 2 files changed, 8 insertions(+), 1 deletion(-)
34
35--- a/drivers/block/nbd.c
36+++ b/drivers/block/nbd.c
37@@ -590,8 +590,11 @@ static int __nbd_ioctl(struct block_devi
38 nbd_cmd(&sreq) = NBD_CMD_DISC;
39 if (!nbd->sock)
40 return -EINVAL;
41+
42+ nbd->disconnect = 1;
43+
44 nbd_send_req(nbd, &sreq);
45- return 0;
46+ return 0;
47 }
48
49 case NBD_CLEAR_SOCK: {
50@@ -620,6 +623,7 @@ static int __nbd_ioctl(struct block_devi
51 nbd->sock = SOCKET_I(inode);
52 if (max_part > 0)
53 bdev->bd_invalidated = 1;
54+ nbd->disconnect = 0; /* we're connected now */
55 return 0;
56 } else {
57 fput(file);
58@@ -691,6 +695,8 @@ static int __nbd_ioctl(struct block_devi
59 set_capacity(nbd->disk, 0);
60 if (max_part > 0)
61 ioctl_by_bdev(bdev, BLKRRPART, 0);
62+ if (nbd->disconnect) /* user requested, ignore socket errors */
63+ return 0;
64 return nbd->harderror;
65 }
66
67--- a/include/linux/nbd.h
68+++ b/include/linux/nbd.h
69@@ -68,6 +68,7 @@ struct nbd_device {
70 u64 bytesize;
71 pid_t pid; /* pid of nbd-client, if attached */
72 int xmit_timeout;
73+ int disconnect; /* a disconnect has been requested by user */
74 };
75
76 #endif