nbd: Handle blk_getlength() failure

Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-Id: <1424887718-10800-9-git-send-email-mreitz@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Max Reitz 2015-02-25 13:08:21 -05:00 committed by Paolo Bonzini
parent 892f5a5270
commit 98f44bbe70
4 changed files with 30 additions and 5 deletions

View file

@ -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);