From 98f44bbe70bb803e7be2421b7cc92a1c179afb87 Mon Sep 17 00:00:00 2001 From: Max Reitz Date: Wed, 25 Feb 2015 13:08:21 -0500 Subject: nbd: Handle blk_getlength() failure Signed-off-by: Max Reitz Message-Id: <1424887718-10800-9-git-send-email-mreitz@redhat.com> Signed-off-by: Paolo Bonzini --- qemu-nbd.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'qemu-nbd.c') diff --git a/qemu-nbd.c b/qemu-nbd.c index d8daf1d3a6..0cb0e4e29a 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -717,6 +717,10 @@ int main(int argc, char **argv) bs->detect_zeroes = detect_zeroes; fd_size = blk_getlength(blk); + if (fd_size < 0) { + errx(EXIT_FAILURE, "Failed to determine the image length: %s", + strerror(-fd_size)); + } if (partition != -1) { ret = find_partition(blk, partition, &dev_offset, &fd_size); @@ -726,7 +730,11 @@ int main(int argc, char **argv) } } - exp = nbd_export_new(blk, dev_offset, fd_size, nbdflags, nbd_export_closed); + exp = nbd_export_new(blk, dev_offset, fd_size, nbdflags, nbd_export_closed, + &local_err); + if (!exp) { + errx(EXIT_FAILURE, "%s", error_get_pretty(local_err)); + } if (sockpath) { fd = unix_socket_incoming(sockpath); -- cgit v1.2.3