[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[qemu-xen staging-4.16] nbd/server: Don't complain on certain client disconnects



commit 932333c5f00ef5697ce4e1f81750bb4dcee958a1
Author:     Eric Blake <eblake@xxxxxxxxxx>
AuthorDate: Wed Nov 17 11:02:29 2021 -0600
Commit:     Michael Roth <michael.roth@xxxxxxx>
CommitDate: Tue Dec 14 14:51:17 2021 -0600

    nbd/server: Don't complain on certain client disconnects
    
    When a client disconnects abruptly, but did not have any pending
    requests (for example, when using nbdsh without calling h.shutdown),
    we used to output the following message:
    
    $ qemu-nbd -f raw file
    $ nbdsh -u 'nbd://localhost:10809' -c 'h.trim(1,0)'
    qemu-nbd: Disconnect client, due to: Failed to read request: Unexpected 
end-of-file before all bytes were read
    
    Then in commit f148ae7, we refactored nbd_receive_request() to use
    nbd_read_eof(); when this returns 0, we regressed into tracing
    uninitialized memory (if tracing is enabled) and reporting a
    less-specific:
    
    qemu-nbd: Disconnect client, due to: Request handling failed in 
intermediate state
    
    Note that with Unix sockets, we have yet another error message,
    unchanged by the 6.0 regression:
    
    $ qemu-nbd -k /tmp/sock -f raw file
    $ nbdsh -u 'nbd+unix:///?socket=/tmp/sock' -c 'h.trim(1,0)'
    qemu-nbd: Disconnect client, due to: Failed to send reply: Unable to write 
to socket: Broken pipe
    
    But in all cases, the error message goes away if the client performs a
    soft shutdown by using NBD_CMD_DISC, rather than a hard shutdown by
    abrupt disconnect:
    
    $ nbdsh -u 'nbd://localhost:10809' -c 'h.trim(1,0)' -c 'h.shutdown()'
    
    This patch fixes things to avoid uninitialized memory, and in general
    avoids warning about a client that does a hard shutdown when not in
    the middle of a packet.  A client that aborts mid-request, or which
    does not read the full server's reply, can still result in warnings,
    but those are indeed much more unusual situations.
    
    CC: qemu-stable@xxxxxxxxxx
    Fixes: f148ae7d36 ("nbd/server: Quiesce coroutines on context switch", 
v6.0.0)
    Signed-off-by: Eric Blake <eblake@xxxxxxxxxx>
    Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@xxxxxxxxxxxxx>
    [eblake: defer unrelated typo fixes to later patch]
    Message-Id: <20211117170230.1128262-2-eblake@xxxxxxxxxx>
    Signed-off-by: Eric Blake <eblake@xxxxxxxxxx>
    (cherry picked from commit 1644cccea5c71b02b9cf8f78b780e7069a29b189)
    Signed-off-by: Michael Roth <michael.roth@xxxxxxx>
---
 nbd/server.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/nbd/server.c b/nbd/server.c
index 3927f7789d..83aeed51c7 100644
--- a/nbd/server.c
+++ b/nbd/server.c
@@ -1413,6 +1413,9 @@ static int nbd_receive_request(NBDClient *client, 
NBDRequest *request,
     if (ret < 0) {
         return ret;
     }
+    if (ret == 0) {
+        return -EIO;
+    }
 
     /* Request
        [ 0 ..  3]   magic   (NBD_REQUEST_MAGIC)
--
generated by git-patchbot for /home/xen/git/qemu-xen.git#staging-4.16



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.