|
@@ -81,9 +81,10 @@
|
|
#define read_sync(fd, buffer, size) nbd_wr_sync(fd, buffer, size, true)
|
|
#define read_sync(fd, buffer, size) nbd_wr_sync(fd, buffer, size, true)
|
|
#define write_sync(fd, buffer, size) nbd_wr_sync(fd, buffer, size, false)
|
|
#define write_sync(fd, buffer, size) nbd_wr_sync(fd, buffer, size, false)
|
|
|
|
|
|
-size_t nbd_wr_sync(int fd, void *buffer, size_t size, bool do_read)
|
|
|
|
|
|
+ssize_t nbd_wr_sync(int fd, void *buffer, size_t size, bool do_read)
|
|
{
|
|
{
|
|
size_t offset = 0;
|
|
size_t offset = 0;
|
|
|
|
+ int err;
|
|
|
|
|
|
if (qemu_in_coroutine()) {
|
|
if (qemu_in_coroutine()) {
|
|
if (do_read) {
|
|
if (do_read) {
|
|
@@ -103,15 +104,15 @@ size_t nbd_wr_sync(int fd, void *buffer, size_t size, bool do_read)
|
|
}
|
|
}
|
|
|
|
|
|
if (len < 0) {
|
|
if (len < 0) {
|
|
- errno = socket_error();
|
|
|
|
|
|
+ err = socket_error();
|
|
|
|
|
|
/* recoverable error */
|
|
/* recoverable error */
|
|
- if (errno == EINTR || errno == EAGAIN) {
|
|
|
|
|
|
+ if (err == EINTR || err == EAGAIN) {
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
|
|
/* unrecoverable error */
|
|
/* unrecoverable error */
|
|
- return 0;
|
|
|
|
|
|
+ return -err;
|
|
}
|
|
}
|
|
|
|
|
|
/* eof */
|
|
/* eof */
|
|
@@ -192,6 +193,7 @@ int unix_socket_outgoing(const char *path)
|
|
static int nbd_send_negotiate(int csock, off_t size, uint32_t flags)
|
|
static int nbd_send_negotiate(int csock, off_t size, uint32_t flags)
|
|
{
|
|
{
|
|
char buf[8 + 8 + 8 + 128];
|
|
char buf[8 + 8 + 8 + 128];
|
|
|
|
+ int rc;
|
|
|
|
|
|
/* Negotiate
|
|
/* Negotiate
|
|
[ 0 .. 7] passwd ("NBDMAGIC")
|
|
[ 0 .. 7] passwd ("NBDMAGIC")
|
|
@@ -201,6 +203,8 @@ static int nbd_send_negotiate(int csock, off_t size, uint32_t flags)
|
|
[28 .. 151] reserved (0)
|
|
[28 .. 151] reserved (0)
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
+ rc = -EINVAL;
|
|
|
|
+
|
|
TRACE("Beginning negotiation.");
|
|
TRACE("Beginning negotiation.");
|
|
memcpy(buf, "NBDMAGIC", 8);
|
|
memcpy(buf, "NBDMAGIC", 8);
|
|
cpu_to_be64w((uint64_t*)(buf + 8), 0x00420281861253LL);
|
|
cpu_to_be64w((uint64_t*)(buf + 8), 0x00420281861253LL);
|
|
@@ -212,13 +216,13 @@ static int nbd_send_negotiate(int csock, off_t size, uint32_t flags)
|
|
|
|
|
|
if (write_sync(csock, buf, sizeof(buf)) != sizeof(buf)) {
|
|
if (write_sync(csock, buf, sizeof(buf)) != sizeof(buf)) {
|
|
LOG("write failed");
|
|
LOG("write failed");
|
|
- errno = EINVAL;
|
|
|
|
- return -1;
|
|
|
|
|
|
+ goto fail;
|
|
}
|
|
}
|
|
|
|
|
|
TRACE("Negotiation succeeded.");
|
|
TRACE("Negotiation succeeded.");
|
|
-
|
|
|
|
- return 0;
|
|
|
|
|
|
+ rc = 0;
|
|
|
|
+fail:
|
|
|
|
+ return rc;
|
|
}
|
|
}
|
|
|
|
|
|
int nbd_receive_negotiate(int csock, const char *name, uint32_t *flags,
|
|
int nbd_receive_negotiate(int csock, const char *name, uint32_t *flags,
|
|
@@ -227,20 +231,21 @@ int nbd_receive_negotiate(int csock, const char *name, uint32_t *flags,
|
|
char buf[256];
|
|
char buf[256];
|
|
uint64_t magic, s;
|
|
uint64_t magic, s;
|
|
uint16_t tmp;
|
|
uint16_t tmp;
|
|
|
|
+ int rc;
|
|
|
|
|
|
TRACE("Receiving negotiation.");
|
|
TRACE("Receiving negotiation.");
|
|
|
|
|
|
|
|
+ rc = -EINVAL;
|
|
|
|
+
|
|
if (read_sync(csock, buf, 8) != 8) {
|
|
if (read_sync(csock, buf, 8) != 8) {
|
|
LOG("read failed");
|
|
LOG("read failed");
|
|
- errno = EINVAL;
|
|
|
|
- return -1;
|
|
|
|
|
|
+ goto fail;
|
|
}
|
|
}
|
|
|
|
|
|
buf[8] = '\0';
|
|
buf[8] = '\0';
|
|
if (strlen(buf) == 0) {
|
|
if (strlen(buf) == 0) {
|
|
LOG("server connection closed");
|
|
LOG("server connection closed");
|
|
- errno = EINVAL;
|
|
|
|
- return -1;
|
|
|
|
|
|
+ goto fail;
|
|
}
|
|
}
|
|
|
|
|
|
TRACE("Magic is %c%c%c%c%c%c%c%c",
|
|
TRACE("Magic is %c%c%c%c%c%c%c%c",
|
|
@@ -255,14 +260,12 @@ int nbd_receive_negotiate(int csock, const char *name, uint32_t *flags,
|
|
|
|
|
|
if (memcmp(buf, "NBDMAGIC", 8) != 0) {
|
|
if (memcmp(buf, "NBDMAGIC", 8) != 0) {
|
|
LOG("Invalid magic received");
|
|
LOG("Invalid magic received");
|
|
- errno = EINVAL;
|
|
|
|
- return -1;
|
|
|
|
|
|
+ goto fail;
|
|
}
|
|
}
|
|
|
|
|
|
if (read_sync(csock, &magic, sizeof(magic)) != sizeof(magic)) {
|
|
if (read_sync(csock, &magic, sizeof(magic)) != sizeof(magic)) {
|
|
LOG("read failed");
|
|
LOG("read failed");
|
|
- errno = EINVAL;
|
|
|
|
- return -1;
|
|
|
|
|
|
+ goto fail;
|
|
}
|
|
}
|
|
magic = be64_to_cpu(magic);
|
|
magic = be64_to_cpu(magic);
|
|
TRACE("Magic is 0x%" PRIx64, magic);
|
|
TRACE("Magic is 0x%" PRIx64, magic);
|
|
@@ -275,61 +278,52 @@ int nbd_receive_negotiate(int csock, const char *name, uint32_t *flags,
|
|
TRACE("Checking magic (opts_magic)");
|
|
TRACE("Checking magic (opts_magic)");
|
|
if (magic != 0x49484156454F5054LL) {
|
|
if (magic != 0x49484156454F5054LL) {
|
|
LOG("Bad magic received");
|
|
LOG("Bad magic received");
|
|
- errno = EINVAL;
|
|
|
|
- return -1;
|
|
|
|
|
|
+ goto fail;
|
|
}
|
|
}
|
|
if (read_sync(csock, &tmp, sizeof(tmp)) != sizeof(tmp)) {
|
|
if (read_sync(csock, &tmp, sizeof(tmp)) != sizeof(tmp)) {
|
|
LOG("flags read failed");
|
|
LOG("flags read failed");
|
|
- errno = EINVAL;
|
|
|
|
- return -1;
|
|
|
|
|
|
+ goto fail;
|
|
}
|
|
}
|
|
*flags = be16_to_cpu(tmp) << 16;
|
|
*flags = be16_to_cpu(tmp) << 16;
|
|
/* reserved for future use */
|
|
/* reserved for future use */
|
|
if (write_sync(csock, &reserved, sizeof(reserved)) !=
|
|
if (write_sync(csock, &reserved, sizeof(reserved)) !=
|
|
sizeof(reserved)) {
|
|
sizeof(reserved)) {
|
|
LOG("write failed (reserved)");
|
|
LOG("write failed (reserved)");
|
|
- errno = EINVAL;
|
|
|
|
- return -1;
|
|
|
|
|
|
+ goto fail;
|
|
}
|
|
}
|
|
/* write the export name */
|
|
/* write the export name */
|
|
magic = cpu_to_be64(magic);
|
|
magic = cpu_to_be64(magic);
|
|
if (write_sync(csock, &magic, sizeof(magic)) != sizeof(magic)) {
|
|
if (write_sync(csock, &magic, sizeof(magic)) != sizeof(magic)) {
|
|
LOG("write failed (magic)");
|
|
LOG("write failed (magic)");
|
|
- errno = EINVAL;
|
|
|
|
- return -1;
|
|
|
|
|
|
+ goto fail;
|
|
}
|
|
}
|
|
opt = cpu_to_be32(NBD_OPT_EXPORT_NAME);
|
|
opt = cpu_to_be32(NBD_OPT_EXPORT_NAME);
|
|
if (write_sync(csock, &opt, sizeof(opt)) != sizeof(opt)) {
|
|
if (write_sync(csock, &opt, sizeof(opt)) != sizeof(opt)) {
|
|
LOG("write failed (opt)");
|
|
LOG("write failed (opt)");
|
|
- errno = EINVAL;
|
|
|
|
- return -1;
|
|
|
|
|
|
+ goto fail;
|
|
}
|
|
}
|
|
namesize = cpu_to_be32(strlen(name));
|
|
namesize = cpu_to_be32(strlen(name));
|
|
if (write_sync(csock, &namesize, sizeof(namesize)) !=
|
|
if (write_sync(csock, &namesize, sizeof(namesize)) !=
|
|
sizeof(namesize)) {
|
|
sizeof(namesize)) {
|
|
LOG("write failed (namesize)");
|
|
LOG("write failed (namesize)");
|
|
- errno = EINVAL;
|
|
|
|
- return -1;
|
|
|
|
|
|
+ goto fail;
|
|
}
|
|
}
|
|
if (write_sync(csock, (char*)name, strlen(name)) != strlen(name)) {
|
|
if (write_sync(csock, (char*)name, strlen(name)) != strlen(name)) {
|
|
LOG("write failed (name)");
|
|
LOG("write failed (name)");
|
|
- errno = EINVAL;
|
|
|
|
- return -1;
|
|
|
|
|
|
+ goto fail;
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
TRACE("Checking magic (cli_magic)");
|
|
TRACE("Checking magic (cli_magic)");
|
|
|
|
|
|
if (magic != 0x00420281861253LL) {
|
|
if (magic != 0x00420281861253LL) {
|
|
LOG("Bad magic received");
|
|
LOG("Bad magic received");
|
|
- errno = EINVAL;
|
|
|
|
- return -1;
|
|
|
|
|
|
+ goto fail;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
if (read_sync(csock, &s, sizeof(s)) != sizeof(s)) {
|
|
if (read_sync(csock, &s, sizeof(s)) != sizeof(s)) {
|
|
LOG("read failed");
|
|
LOG("read failed");
|
|
- errno = EINVAL;
|
|
|
|
- return -1;
|
|
|
|
|
|
+ goto fail;
|
|
}
|
|
}
|
|
*size = be64_to_cpu(s);
|
|
*size = be64_to_cpu(s);
|
|
*blocksize = 1024;
|
|
*blocksize = 1024;
|
|
@@ -338,24 +332,24 @@ int nbd_receive_negotiate(int csock, const char *name, uint32_t *flags,
|
|
if (!name) {
|
|
if (!name) {
|
|
if (read_sync(csock, flags, sizeof(*flags)) != sizeof(*flags)) {
|
|
if (read_sync(csock, flags, sizeof(*flags)) != sizeof(*flags)) {
|
|
LOG("read failed (flags)");
|
|
LOG("read failed (flags)");
|
|
- errno = EINVAL;
|
|
|
|
- return -1;
|
|
|
|
|
|
+ goto fail;
|
|
}
|
|
}
|
|
*flags = be32_to_cpup(flags);
|
|
*flags = be32_to_cpup(flags);
|
|
} else {
|
|
} else {
|
|
if (read_sync(csock, &tmp, sizeof(tmp)) != sizeof(tmp)) {
|
|
if (read_sync(csock, &tmp, sizeof(tmp)) != sizeof(tmp)) {
|
|
LOG("read failed (tmp)");
|
|
LOG("read failed (tmp)");
|
|
- errno = EINVAL;
|
|
|
|
- return -1;
|
|
|
|
|
|
+ goto fail;
|
|
}
|
|
}
|
|
*flags |= be32_to_cpu(tmp);
|
|
*flags |= be32_to_cpu(tmp);
|
|
}
|
|
}
|
|
if (read_sync(csock, &buf, 124) != 124) {
|
|
if (read_sync(csock, &buf, 124) != 124) {
|
|
LOG("read failed (buf)");
|
|
LOG("read failed (buf)");
|
|
- errno = EINVAL;
|
|
|
|
- return -1;
|
|
|
|
|
|
+ goto fail;
|
|
}
|
|
}
|
|
- return 0;
|
|
|
|
|
|
+ rc = 0;
|
|
|
|
+
|
|
|
|
+fail:
|
|
|
|
+ return rc;
|
|
}
|
|
}
|
|
|
|
|
|
#ifdef __linux__
|
|
#ifdef __linux__
|
|
@@ -366,8 +360,7 @@ int nbd_init(int fd, int csock, uint32_t flags, off_t size, size_t blocksize)
|
|
if (ioctl(fd, NBD_SET_SOCK, csock) < 0) {
|
|
if (ioctl(fd, NBD_SET_SOCK, csock) < 0) {
|
|
int serrno = errno;
|
|
int serrno = errno;
|
|
LOG("Failed to set NBD socket");
|
|
LOG("Failed to set NBD socket");
|
|
- errno = serrno;
|
|
|
|
- return -1;
|
|
|
|
|
|
+ return -serrno;
|
|
}
|
|
}
|
|
|
|
|
|
TRACE("Setting block size to %lu", (unsigned long)blocksize);
|
|
TRACE("Setting block size to %lu", (unsigned long)blocksize);
|
|
@@ -375,8 +368,7 @@ int nbd_init(int fd, int csock, uint32_t flags, off_t size, size_t blocksize)
|
|
if (ioctl(fd, NBD_SET_BLKSIZE, blocksize) < 0) {
|
|
if (ioctl(fd, NBD_SET_BLKSIZE, blocksize) < 0) {
|
|
int serrno = errno;
|
|
int serrno = errno;
|
|
LOG("Failed setting NBD block size");
|
|
LOG("Failed setting NBD block size");
|
|
- errno = serrno;
|
|
|
|
- return -1;
|
|
|
|
|
|
+ return -serrno;
|
|
}
|
|
}
|
|
|
|
|
|
TRACE("Setting size to %zd block(s)", (size_t)(size / blocksize));
|
|
TRACE("Setting size to %zd block(s)", (size_t)(size / blocksize));
|
|
@@ -384,8 +376,7 @@ int nbd_init(int fd, int csock, uint32_t flags, off_t size, size_t blocksize)
|
|
if (ioctl(fd, NBD_SET_SIZE_BLOCKS, size / blocksize) < 0) {
|
|
if (ioctl(fd, NBD_SET_SIZE_BLOCKS, size / blocksize) < 0) {
|
|
int serrno = errno;
|
|
int serrno = errno;
|
|
LOG("Failed setting size (in blocks)");
|
|
LOG("Failed setting size (in blocks)");
|
|
- errno = serrno;
|
|
|
|
- return -1;
|
|
|
|
|
|
+ return -serrno;
|
|
}
|
|
}
|
|
|
|
|
|
if (flags & NBD_FLAG_READ_ONLY) {
|
|
if (flags & NBD_FLAG_READ_ONLY) {
|
|
@@ -395,8 +386,7 @@ int nbd_init(int fd, int csock, uint32_t flags, off_t size, size_t blocksize)
|
|
if (ioctl(fd, BLKROSET, (unsigned long) &read_only) < 0) {
|
|
if (ioctl(fd, BLKROSET, (unsigned long) &read_only) < 0) {
|
|
int serrno = errno;
|
|
int serrno = errno;
|
|
LOG("Failed setting read-only attribute");
|
|
LOG("Failed setting read-only attribute");
|
|
- errno = serrno;
|
|
|
|
- return -1;
|
|
|
|
|
|
+ return -serrno;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -404,8 +394,7 @@ int nbd_init(int fd, int csock, uint32_t flags, off_t size, size_t blocksize)
|
|
&& errno != ENOTTY) {
|
|
&& errno != ENOTTY) {
|
|
int serrno = errno;
|
|
int serrno = errno;
|
|
LOG("Failed setting flags");
|
|
LOG("Failed setting flags");
|
|
- errno = serrno;
|
|
|
|
- return -1;
|
|
|
|
|
|
+ return -serrno;
|
|
}
|
|
}
|
|
|
|
|
|
TRACE("Negotiation ended");
|
|
TRACE("Negotiation ended");
|
|
@@ -452,26 +441,24 @@ int nbd_client(int fd)
|
|
#else
|
|
#else
|
|
int nbd_init(int fd, int csock, uint32_t flags, off_t size, size_t blocksize)
|
|
int nbd_init(int fd, int csock, uint32_t flags, off_t size, size_t blocksize)
|
|
{
|
|
{
|
|
- errno = ENOTSUP;
|
|
|
|
- return -1;
|
|
|
|
|
|
+ return -ENOTSUP;
|
|
}
|
|
}
|
|
|
|
|
|
int nbd_disconnect(int fd)
|
|
int nbd_disconnect(int fd)
|
|
{
|
|
{
|
|
- errno = ENOTSUP;
|
|
|
|
- return -1;
|
|
|
|
|
|
+ return -ENOTSUP;
|
|
}
|
|
}
|
|
|
|
|
|
int nbd_client(int fd)
|
|
int nbd_client(int fd)
|
|
{
|
|
{
|
|
- errno = ENOTSUP;
|
|
|
|
- return -1;
|
|
|
|
|
|
+ return -ENOTSUP;
|
|
}
|
|
}
|
|
#endif
|
|
#endif
|
|
|
|
|
|
ssize_t nbd_send_request(int csock, struct nbd_request *request)
|
|
ssize_t nbd_send_request(int csock, struct nbd_request *request)
|
|
{
|
|
{
|
|
uint8_t buf[4 + 4 + 8 + 8 + 4];
|
|
uint8_t buf[4 + 4 + 8 + 8 + 4];
|
|
|
|
+ ssize_t ret;
|
|
|
|
|
|
cpu_to_be32w((uint32_t*)buf, NBD_REQUEST_MAGIC);
|
|
cpu_to_be32w((uint32_t*)buf, NBD_REQUEST_MAGIC);
|
|
cpu_to_be32w((uint32_t*)(buf + 4), request->type);
|
|
cpu_to_be32w((uint32_t*)(buf + 4), request->type);
|
|
@@ -483,10 +470,14 @@ ssize_t nbd_send_request(int csock, struct nbd_request *request)
|
|
"{ .from = %" PRIu64", .len = %u, .handle = %" PRIu64", .type=%i}",
|
|
"{ .from = %" PRIu64", .len = %u, .handle = %" PRIu64", .type=%i}",
|
|
request->from, request->len, request->handle, request->type);
|
|
request->from, request->len, request->handle, request->type);
|
|
|
|
|
|
- if (write_sync(csock, buf, sizeof(buf)) != sizeof(buf)) {
|
|
|
|
|
|
+ ret = write_sync(csock, buf, sizeof(buf));
|
|
|
|
+ if (ret < 0) {
|
|
|
|
+ return ret;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (ret != sizeof(buf)) {
|
|
LOG("writing to socket failed");
|
|
LOG("writing to socket failed");
|
|
- errno = EINVAL;
|
|
|
|
- return -1;
|
|
|
|
|
|
+ return -EINVAL;
|
|
}
|
|
}
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
@@ -495,11 +486,16 @@ static ssize_t nbd_receive_request(int csock, struct nbd_request *request)
|
|
{
|
|
{
|
|
uint8_t buf[4 + 4 + 8 + 8 + 4];
|
|
uint8_t buf[4 + 4 + 8 + 8 + 4];
|
|
uint32_t magic;
|
|
uint32_t magic;
|
|
|
|
+ ssize_t ret;
|
|
|
|
|
|
- if (read_sync(csock, buf, sizeof(buf)) != sizeof(buf)) {
|
|
|
|
|
|
+ ret = read_sync(csock, buf, sizeof(buf));
|
|
|
|
+ if (ret < 0) {
|
|
|
|
+ return ret;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (ret != sizeof(buf)) {
|
|
LOG("read failed");
|
|
LOG("read failed");
|
|
- errno = EINVAL;
|
|
|
|
- return -1;
|
|
|
|
|
|
+ return -EINVAL;
|
|
}
|
|
}
|
|
|
|
|
|
/* Request
|
|
/* Request
|
|
@@ -522,8 +518,7 @@ static ssize_t nbd_receive_request(int csock, struct nbd_request *request)
|
|
|
|
|
|
if (magic != NBD_REQUEST_MAGIC) {
|
|
if (magic != NBD_REQUEST_MAGIC) {
|
|
LOG("invalid magic (got 0x%x)", magic);
|
|
LOG("invalid magic (got 0x%x)", magic);
|
|
- errno = EINVAL;
|
|
|
|
- return -1;
|
|
|
|
|
|
+ return -EINVAL;
|
|
}
|
|
}
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
@@ -532,11 +527,16 @@ ssize_t nbd_receive_reply(int csock, struct nbd_reply *reply)
|
|
{
|
|
{
|
|
uint8_t buf[NBD_REPLY_SIZE];
|
|
uint8_t buf[NBD_REPLY_SIZE];
|
|
uint32_t magic;
|
|
uint32_t magic;
|
|
|
|
+ ssize_t ret;
|
|
|
|
+
|
|
|
|
+ ret = read_sync(csock, buf, sizeof(buf));
|
|
|
|
+ if (ret < 0) {
|
|
|
|
+ return ret;
|
|
|
|
+ }
|
|
|
|
|
|
- if (read_sync(csock, buf, sizeof(buf)) != sizeof(buf)) {
|
|
|
|
|
|
+ if (ret != sizeof(buf)) {
|
|
LOG("read failed");
|
|
LOG("read failed");
|
|
- errno = EINVAL;
|
|
|
|
- return -1;
|
|
|
|
|
|
+ return -EINVAL;
|
|
}
|
|
}
|
|
|
|
|
|
/* Reply
|
|
/* Reply
|
|
@@ -555,8 +555,7 @@ ssize_t nbd_receive_reply(int csock, struct nbd_reply *reply)
|
|
|
|
|
|
if (magic != NBD_REPLY_MAGIC) {
|
|
if (magic != NBD_REPLY_MAGIC) {
|
|
LOG("invalid magic (got 0x%x)", magic);
|
|
LOG("invalid magic (got 0x%x)", magic);
|
|
- errno = EINVAL;
|
|
|
|
- return -1;
|
|
|
|
|
|
+ return -EINVAL;
|
|
}
|
|
}
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
@@ -564,6 +563,7 @@ ssize_t nbd_receive_reply(int csock, struct nbd_reply *reply)
|
|
static ssize_t nbd_send_reply(int csock, struct nbd_reply *reply)
|
|
static ssize_t nbd_send_reply(int csock, struct nbd_reply *reply)
|
|
{
|
|
{
|
|
uint8_t buf[4 + 4 + 8];
|
|
uint8_t buf[4 + 4 + 8];
|
|
|
|
+ ssize_t ret;
|
|
|
|
|
|
/* Reply
|
|
/* Reply
|
|
[ 0 .. 3] magic (NBD_REPLY_MAGIC)
|
|
[ 0 .. 3] magic (NBD_REPLY_MAGIC)
|
|
@@ -576,10 +576,14 @@ static ssize_t nbd_send_reply(int csock, struct nbd_reply *reply)
|
|
|
|
|
|
TRACE("Sending response to client");
|
|
TRACE("Sending response to client");
|
|
|
|
|
|
- if (write_sync(csock, buf, sizeof(buf)) != sizeof(buf)) {
|
|
|
|
|
|
+ ret = write_sync(csock, buf, sizeof(buf));
|
|
|
|
+ if (ret < 0) {
|
|
|
|
+ return ret;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (ret != sizeof(buf)) {
|
|
LOG("writing to socket failed");
|
|
LOG("writing to socket failed");
|
|
- errno = EINVAL;
|
|
|
|
- return -1;
|
|
|
|
|
|
+ return -EINVAL;
|
|
}
|
|
}
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
@@ -713,22 +717,15 @@ static ssize_t nbd_co_send_reply(NBDRequest *req, struct nbd_reply *reply,
|
|
|
|
|
|
if (!len) {
|
|
if (!len) {
|
|
rc = nbd_send_reply(csock, reply);
|
|
rc = nbd_send_reply(csock, reply);
|
|
- if (rc < 0) {
|
|
|
|
- rc = -errno;
|
|
|
|
- }
|
|
|
|
} else {
|
|
} else {
|
|
socket_set_cork(csock, 1);
|
|
socket_set_cork(csock, 1);
|
|
rc = nbd_send_reply(csock, reply);
|
|
rc = nbd_send_reply(csock, reply);
|
|
if (rc >= 0) {
|
|
if (rc >= 0) {
|
|
ret = qemu_co_send(csock, req->data, len);
|
|
ret = qemu_co_send(csock, req->data, len);
|
|
if (ret != len) {
|
|
if (ret != len) {
|
|
- errno = EIO;
|
|
|
|
- rc = -1;
|
|
|
|
|
|
+ rc = -EIO;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if (rc < 0) {
|
|
|
|
- rc = -errno;
|
|
|
|
- }
|
|
|
|
socket_set_cork(csock, 0);
|
|
socket_set_cork(csock, 0);
|
|
}
|
|
}
|
|
|
|
|