From 54a8813b448cd4503c128b5ef47481be7bb018ab Mon Sep 17 00:00:00 2001 From: reidrac Date: Sat, 26 Jan 2013 13:15:59 +0000 Subject: [PATCH] Detect server disconnection after NBD_OPT_EXPORTNAME If the export is unknown to the server, it may disconnect (new-style handshake un-fixed). In that case the read call to get export size may return 0 (non error, EOF). This change fixes following error: nbd-client -N unexistent 127.0.0.1 /dev/nbd0 Negotiation: ..size = 2314498962MBError: Exported device is too big for me. Get 64-bit machine :-( Exiting. --- nbd-client.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/nbd-client.c b/nbd-client.c index d20f32c..49f75ed 100644 --- a/nbd-client.c +++ b/nbd-client.c @@ -283,8 +283,11 @@ void negotiate(int sock, u64 *rsize64, u32 *flags, char* name, uint32_t needed_f printf("."); } - if (read(sock, &size64, sizeof(size64)) < 0) + if (read(sock, &size64, sizeof(size64)) < 0) { + if (!errno) + err("Server closed connection"); err("Failed/3: %m\n"); + } size64 = ntohll(size64); #ifdef NBD_SET_SIZE_BLOCKS -- 2.34.1