nbd: consistently return negative errno values
In the next patch we need to look at the return code of nbd_wr_sync.
To avoid percolating the socket_error() ugliness all around, let's
handle errors by returning negative errno values.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
diff --git a/qemu-nbd.c b/qemu-nbd.c
index 19cfb04..6c3f9b5 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -126,8 +126,7 @@
}
if (data[510] != 0x55 || data[511] != 0xaa) {
- errno = -EINVAL;
- return -1;
+ return -EINVAL;
}
for (i = 0; i < 4; i++) {
@@ -165,8 +164,7 @@
}
}
- errno = -ENOENT;
- return -1;
+ return -ENOENT;
}
static void termsig_handler(int signum)
@@ -491,9 +489,12 @@
fd_size = bs->total_sectors * 512;
- if (partition != -1 &&
- find_partition(bs, partition, &dev_offset, &fd_size)) {
- err(EXIT_FAILURE, "Could not find partition %d", partition);
+ if (partition != -1) {
+ ret = find_partition(bs, partition, &dev_offset, &fd_size);
+ if (ret < 0) {
+ errno = -ret;
+ err(EXIT_FAILURE, "Could not find partition %d", partition);
+ }
}
exp = nbd_export_new(bs, dev_offset, fd_size, nbdflags);