Skip to contentSkip to conversation

nbd: allow multiple disconnects to be sent

PATCH In review [email protected] 3 participants 6 messages Jul 21, 2017 – Jul 25, 2017 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

PATCH 1/3 nbd: allow multiple disconnects to be sent

From: Josef Bacik <[email protected]>

There's no reason to limit ourselves to one disconnect message per socket. Sometimes networks do strange things, might as well let sysadmins hit the panic button as much as they want.

---
 drivers/block/nbd.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/block/nbd.c +2 -3
index 87a0a29..f91e7ac 100644
@@ -991,9 +991,8 @@ static int nbd_disconnect(struct nbd_device *nbd)
 	struct nbd_config *config = nbd->config;
 
 	dev_info(disk_to_dev(nbd->disk), "NBD_DISCONNECT\n");
-	if (!test_and_set_bit(NBD_DISCONNECT_REQUESTED,
-			      &config->runtime_flags))
-		send_disconnects(nbd);
+	set_bit(NBD_DISCONNECT_REQUESTED, &config->runtime_flags);
+	send_disconnects(nbd);
 	return 0;
 }
 
Signature · 1 line
2.7.4
author maintainer
#1 lore raw

PATCH 2/3 nbd: take tx_lock before disconnecting

From: Josef Bacik <[email protected]>

We need to take the tx_lock so we don't interleave our disconnect request between real data going down the wire.

---
 drivers/block/nbd.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/block/nbd.c +4 -0
index f91e7ac..6aefe9f 100644
@@ -978,11 +978,15 @@ static void send_disconnects(struct nbd_device *nbd)
 	int i, ret;
 
 	for (i = 0; i < config->num_connections; i++) {
+		struct nbd_sock *nsock = config->socks[i];
+
 		iov_iter_kvec(&from, WRITE | ITER_KVEC, &iov, 1, sizeof(request));
+		mutex_lock(&nsock->tx_lock);
 		ret = sock_xmit(nbd, i, 1, &from, 0, NULL);
 		if (ret <= 0)
 			dev_err(disk_to_dev(nbd->disk),
 				"Send disconnect failed %d\n", ret);
+		mutex_unlock(&nsock->tx_lock);
 	}
 }
 
Signature · 1 line
2.7.4
author maintainer
#2 lore raw

PATCH 3/3 nbd: only set sndtimeo if we have a timeout set

In reply to [email protected]

From: Josef Bacik <[email protected]>

A user reported that he was getting immediate disconnects with my sndtimeo patch applied. This is because by default the OSS nbd client doesn't set a timeout, so we end up setting the sndtimeo to 0, which of course means we have send errors a lot. Instead only set our sndtimeo if the user specified a timeout, otherwise we'll just wait forever like we did previously.

Fixes dc88e34d69d8 ("nbd: set sk->sk_sndtimeo for our sockets")
---
 drivers/block/nbd.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/block/nbd.c +5 -2
index 6aefe9f..64b19b1 100644
@@ -908,7 +908,8 @@ static int nbd_reconnect_socket(struct nbd_device *nbd, unsigned long arg)
 			continue;
 		}
 		sk_set_memalloc(sock->sk);
-		sock->sk->sk_sndtimeo = nbd->tag_set.timeout;
+		if (nbd->tag_set.timeout)
+			sock->sk->sk_sndtimeo = nbd->tag_set.timeout;
 		atomic_inc(&config->recv_threads);
 		refcount_inc(&nbd->config_refs);
 		old = nsock->sock;
@@ -1077,7 +1078,9 @@ static int nbd_start_device(struct nbd_device *nbd)
 			return -ENOMEM;
 		}
 		sk_set_memalloc(config->socks[i]->sock->sk);
-		config->socks[i]->sock->sk->sk_sndtimeo = nbd->tag_set.timeout;
+		if (nbd->tag_set.timeout)
+			config->socks[i]->sock->sk->sk_sndtimeo =
+				nbd->tag_set.timeout;
 		atomic_inc(&config->recv_threads);
 		refcount_inc(&nbd->config_refs);
 		INIT_WORK(&args->work, recv_work);
Signature · 1 line
2.7.4
maintainer
#3 lore raw
In reply to [email protected]
Quoted 5 lines · On 07/21/2017 08:48 AM, [email protected] wrote:

From: Josef Bacik <[email protected]>

There's no reason to limit ourselves to one disconnect message per socket. Sometimes networks do strange things, might as well let sysadmins hit the panic button as much as they want.

Applied 1-3 for 4.13, thanks Josef.

Signature · 1 line
Jens Axboe
#4 lore raw
In reply to [email protected]
Quoted 5 lines · On Fri, Jul 21, 2017 at 10:48:13AM -0400, [email protected] wrote:

From: Josef Bacik <[email protected]>

There's no reason to limit ourselves to one disconnect message per socket. Sometimes networks do strange things, might as well let sysadmins hit the panic button as much as they want.

The protocol spec is pretty clear that any requests sent after the disconnect request was sent out are not guaranteed to be processed anymore.

Doesn't this allow more requests to be sent out? Or is the NBD_DISCONNECT_REQUESTED flag enough to make that impossible?

Signature · 4 lines
Could you people please use IRC like normal people?!?

  -- Amaya Rodrigo Sastre, trying to quiet down the buzz in the DebConf 2008
     Hacklab

A message that is not in the archive (sent off-list or not yet received): 20170724232429.GA7376@destiny

#6 lore raw
Quoted 12 lines · Josef Bacik
Quoted 11 lines · Wouter Verhelst
Quoted 5 lines · On Fri, Jul 21, 2017 at 10:48:13AM -0400, [email protected] wrote:

From: Josef Bacik <[email protected]>

There's no reason to limit ourselves to one disconnect message per socket. Sometimes networks do strange things, might as well let sysadmins hit the panic button as much as they want.

The protocol spec is pretty clear that any requests sent after the disconnect request was sent out are not guaranteed to be processed anymore.

Quoted 6 lines
Quoted 3 lines

Doesn't this allow more requests to be sent out? Or is the NBD_DISCONNECT_REQUESTED flag enough to make that impossible?

This just allows users to call the disconnect ioctl/netlink thing multiple times and have it send the DISCONNECT command if they want.

Right.

Quoted 1 line

We've had problems with our in-hosue nbd server missing messages,

That's pretty bad...

Quoted 4 lines

and it's just a pain to have to unstuck it because the server messed up. It's just for the rare case the server is being weird, not because we expect/guarantee that subsequent disconnect commands will be processed. Thanks,

Okay, makes sense. Just thought I'd ask :-)

Signature · 4 lines
Could you people please use IRC like normal people?!?

  -- Amaya Rodrigo Sastre, trying to quiet down the buzz in the DebConf 2008
     Hacklab