Commit 5e3c3a7e authored by Kevin Vigor's avatar Kevin Vigor Committed by Jens Axboe

nbd: clear DISCONNECT_REQUESTED flag once disconnection occurs.

When a userspace client requests a NBD device be disconnected, the
DISCONNECT_REQUESTED flag is set. While this flag is set, the driver
will not inform userspace when a connection is closed.

Unfortunately the flag was never cleared, so once a disconnect was
requested the driver would thereafter never tell userspace about a
closed connection. Thus when connections failed due to timeout, no
attempt to reconnect was made and eventually the device would fail.

Fix by clearing the DISCONNECT_REQUESTED flag (and setting the
DISCONNECTED flag) once all connections are closed.
Reviewed-by: default avatarJosef Bacik <josef@toxicpanda.com>
Signed-off-by: default avatarKevin Vigor <kvigor@fb.com>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 2ab74cd2
...@@ -216,7 +216,15 @@ static void nbd_mark_nsock_dead(struct nbd_device *nbd, struct nbd_sock *nsock, ...@@ -216,7 +216,15 @@ static void nbd_mark_nsock_dead(struct nbd_device *nbd, struct nbd_sock *nsock,
} }
if (!nsock->dead) { if (!nsock->dead) {
kernel_sock_shutdown(nsock->sock, SHUT_RDWR); kernel_sock_shutdown(nsock->sock, SHUT_RDWR);
atomic_dec(&nbd->config->live_connections); if (atomic_dec_return(&nbd->config->live_connections) == 0) {
if (test_and_clear_bit(NBD_DISCONNECT_REQUESTED,
&nbd->config->runtime_flags)) {
set_bit(NBD_DISCONNECTED,
&nbd->config->runtime_flags);
dev_info(nbd_to_dev(nbd),
"Disconnected due to user request.\n");
}
}
} }
nsock->dead = true; nsock->dead = true;
nsock->pending = NULL; nsock->pending = NULL;
...@@ -310,7 +318,9 @@ static enum blk_eh_timer_return nbd_xmit_timeout(struct request *req, ...@@ -310,7 +318,9 @@ static enum blk_eh_timer_return nbd_xmit_timeout(struct request *req,
if (config->num_connections > 1) { if (config->num_connections > 1) {
dev_err_ratelimited(nbd_to_dev(nbd), dev_err_ratelimited(nbd_to_dev(nbd),
"Connection timed out, retrying\n"); "Connection timed out, retrying (%d/%d alive)\n",
atomic_read(&config->live_connections),
config->num_connections);
/* /*
* Hooray we have more connections, requeue this IO, the submit * Hooray we have more connections, requeue this IO, the submit
* path will put it on a real connection. * path will put it on a real connection.
...@@ -733,10 +743,9 @@ static int wait_for_reconnect(struct nbd_device *nbd) ...@@ -733,10 +743,9 @@ static int wait_for_reconnect(struct nbd_device *nbd)
return 0; return 0;
if (test_bit(NBD_DISCONNECTED, &config->runtime_flags)) if (test_bit(NBD_DISCONNECTED, &config->runtime_flags))
return 0; return 0;
wait_event_timeout(config->conn_wait, return wait_event_timeout(config->conn_wait,
atomic_read(&config->live_connections), atomic_read(&config->live_connections) > 0,
config->dead_conn_timeout); config->dead_conn_timeout) > 0;
return atomic_read(&config->live_connections);
} }
static int nbd_handle_cmd(struct nbd_cmd *cmd, int index) static int nbd_handle_cmd(struct nbd_cmd *cmd, int index)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment