]>
Commit | Line | Data |
---|---|---|
1a306361 GKH |
1 | From c378f70adbc1bbecd9e6db145019f14b2f688c7c Mon Sep 17 00:00:00 2001 |
2 | From: Paul Clements <paul.clements@steeleye.com> | |
3 | Date: Wed, 3 Jul 2013 15:09:04 -0700 | |
4 | Subject: nbd: correct disconnect behavior | |
5 | ||
6 | From: Paul Clements <paul.clements@steeleye.com> | |
7 | ||
8 | commit c378f70adbc1bbecd9e6db145019f14b2f688c7c upstream. | |
9 | ||
10 | Currently, when a disconnect is requested by the user (via NBD_DISCONNECT | |
11 | ioctl) the return from NBD_DO_IT is undefined (it is usually one of | |
12 | several error codes). This means that nbd-client does not know if a | |
13 | manual disconnect was performed or whether a network error occurred. | |
14 | Because of this, nbd-client's persist mode (which tries to reconnect after | |
15 | error, but not after manual disconnect) does not always work correctly. | |
16 | ||
17 | This change fixes this by causing NBD_DO_IT to always return 0 if a user | |
18 | requests a disconnect. This means that nbd-client can correctly either | |
19 | persist the connection (if an error occurred) or disconnect (if the user | |
20 | requested it). | |
21 | ||
22 | Signed-off-by: Paul Clements <paul.clements@steeleye.com> | |
23 | Acked-by: Rob Landley <rob@landley.net> | |
24 | Signed-off-by: Andrew Morton <akpm@linux-foundation.org> | |
25 | Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> | |
26 | [xr: Backported to 3.4: adjust context] | |
27 | Signed-off-by: Rui Xiang <rui.xiang@huawei.com> | |
28 | Signed-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 |