Skip to contentSkip to conversation

nbd-client: fix hang after server closes connection

PATCH In review Stefan Hajnoczi 4 participants 7 messages Aug 21, 2017 – Aug 23, 2017 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nbd-client: fix hang after server closes connection

Commit 72b6ffc76653214b69a94a7b1643ff80df134486 ("nbd-client: Fix regression when server sends garbage") improved NBD client behavior when the connection enters a broken state.

The following still does not behave as expected:

  $ qemu-nbd -p 1234 -x drive0 -f qcow2 test.qcow2
  $ qemu-system-x86_64 -M accel=kvm -m 1G \
        -drive if=virtio,id=drive0,file=nbd://localhost:1234/drive0,format=raw
  $ pkill qemu-nbd
  (qemu) quit
  ...hang...

QEMU should be able to quit even when the connection was previously closed by the NBD server. Currently the nbd_read_reply_entry() coroutine terminates without letting in-flight requests know that the connection is dead.

This patch flags the connection as dead so in-flight requests can complete.

---
 block/nbd-client.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
block/nbd-client.c +1 -3
index 422ecb4307..5a5fe02015 100644
@@ -80,6 +80,7 @@ static coroutine_fn void nbd_read_reply_entry(void *opaque)
             error_report_err(local_err);
         }
         if (ret <= 0) {
+            s->quit = true;
             break;
         }
 
@@ -107,9 +108,6 @@ static coroutine_fn void nbd_read_reply_entry(void *opaque)
         qemu_coroutine_yield();
     }
 
-    if (ret < 0) {
-        s->quit = true;
-    }
     nbd_recv_coroutines_enter_all(s);
     s->read_reply_co = NULL;
 }
Signature · 1 line
2.13.5
#1 lore raw
Quoted 2 lines · Stefan Hajnoczi

(qemu) quit
...hang...

By the way, the same issue is present in QEMU 2.9. This is not a 2.10 regression.

Stefan

#2 lore raw
Quoted 6 lines · Stefan Hajnoczi
Quoted 2 lines · Stefan Hajnoczi

(qemu) quit
...hang...

By the way, the same issue is present in QEMU 2.9. This is not a 2.10 regression.

Most likely, though, it IS a regression introduced in 2.9 and not present in 2.8. I'll add this to my list of 2.11 NBD patches.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#3 lore raw
Quoted 10 lines · Eric Blake
Quoted 6 lines · Stefan Hajnoczi
Quoted 2 lines · Stefan Hajnoczi

(qemu) quit
...hang...

By the way, the same issue is present in QEMU 2.9. This is not a 2.10 regression.

Most likely, though, it IS a regression introduced in 2.9 and not present in 2.8. I'll add this to my list of 2.11 NBD patches.

Since it looks like we're doing -rc4 and including other NBD patches for that, I'm adding this to my 2.10 NBD queue, and will send a pull request shortly...

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#4 lore raw
Quoted 6 lines · Eric Blake
Quoted 5 lines · Eric Blake
Quoted 4 lines · Stefan Hajnoczi
Quoted 2 lines · Stefan Hajnoczi

(qemu) quit
...hang...

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

By the way, the same issue is present in QEMU 2.9. This is not a 2.10 regression.

Most likely, though, it IS a regression introduced in 2.9 and not present in 2.8. I'll add this to my list of 2.11 NBD patches.

Since it looks like we're doing -rc4 and including other NBD patches for that, I'm adding this to my 2.10 NBD queue,

On IRC, Stefan informed me that 'nbd-client: avoid spurious qio_channel_yield() re-entry' obsoletes this one.

Quoted 2 lines

and will send a pull request
shortly...

This part is still true

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
Acked-by on v1 1/1
#5 lore raw
In reply to Stefan Hajnoczi
Quoted 18 lines · Stefan Hajnoczi

Commit 72b6ffc76653214b69a94a7b1643ff80df134486 ("nbd-client: Fix regression when server sends garbage") improved NBD client behavior when the connection enters a broken state.

The following still does not behave as expected:

   $ qemu-nbd -p 1234 -x drive0 -f qcow2 test.qcow2
   $ qemu-system-x86_64 -M accel=kvm -m 1G \
         -drive if=virtio,id=drive0,file=nbd://localhost:1234/drive0,format=raw
   $ pkill qemu-nbd
   (qemu) quit
   ...hang...

QEMU should be able to quit even when the connection was previously closed by the NBD server. Currently the nbd_read_reply_entry() coroutine terminates without letting in-flight requests know that the connection is dead.

Quoted 7 lines

This patch flags the connection as dead so in-flight requests can complete.

Quoted 27 lines
---
  block/nbd-client.c | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)
block/nbd-client.c +1 -3
index 422ecb4307..5a5fe02015 100644
@@ -80,6 +80,7 @@ static coroutine_fn void nbd_read_reply_entry(void *opaque)
              error_report_err(local_err);
          }
          if (ret <= 0) {
+            s->quit = true;
              break;
          }
 
@@ -107,9 +108,6 @@ static coroutine_fn void nbd_read_reply_entry(void *opaque)
          qemu_coroutine_yield();
      }
 
-    if (ret < 0) {
-        s->quit = true;
-    }
      nbd_recv_coroutines_enter_all(s);
      s->read_reply_co = NULL;
  }
#6 lore raw
In reply to Stefan Hajnoczi
Quoted 21 lines · Stefan Hajnoczi

Commit 72b6ffc76653214b69a94a7b1643ff80df134486 ("nbd-client: Fix regression when server sends garbage") improved NBD client behavior when the connection enters a broken state.

The following still does not behave as expected:

  $ qemu-nbd -p 1234 -x drive0 -f qcow2 test.qcow2
  $ qemu-system-x86_64 -M accel=kvm -m 1G \
        -drive if=virtio,id=drive0,file=nbd://localhost:1234/drive0,format=raw
  $ pkill qemu-nbd
  (qemu) quit
  ...hang...

QEMU should be able to quit even when the connection was previously closed by the NBD server. Currently the nbd_read_reply_entry() coroutine terminates without letting in-flight requests know that the connection is dead.

This patch flags the connection as dead so in-flight requests can complete.

Quoted 7 lines
---
 block/nbd-client.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

This patch is superceded by "[PATCH] nbd-client: avoid spurious qio_channel_yield() re-entry".

Stefan