NBDReply reply;
int ret;
int flags;
+ int reply_data_len = 0;
TRACE("Reading request.");
if (client->closing) {
client->recv_coroutine = NULL;
nbd_client_receive_next_request(client);
if (ret == -EIO) {
- goto out;
+ goto disconnect;
}
reply.handle = request.handle;
if (ret < 0) {
reply.error = -ret;
- goto error_reply;
+ goto reply;
}
if (client->closing) {
if (ret < 0) {
LOG("flush failed");
reply.error = -ret;
- goto error_reply;
+ break;
}
}
if (ret < 0) {
LOG("reading from file failed");
reply.error = -ret;
- goto error_reply;
+ break;
}
+ reply_data_len = request.len;
TRACE("Read %" PRIu32" byte(s)", request.len);
- if (nbd_co_send_reply(req, &reply, request.len) < 0)
- goto out;
+
break;
case NBD_CMD_WRITE:
TRACE("Request type is WRITE");
if (exp->nbdflags & NBD_FLAG_READ_ONLY) {
TRACE("Server is read-only, return error");
reply.error = EROFS;
- goto error_reply;
+ break;
}
TRACE("Writing to device");
if (ret < 0) {
LOG("writing to file failed");
reply.error = -ret;
- goto error_reply;
}
- if (nbd_co_send_reply(req, &reply, 0) < 0) {
- goto out;
- }
break;
-
case NBD_CMD_WRITE_ZEROES:
TRACE("Request type is WRITE_ZEROES");
if (exp->nbdflags & NBD_FLAG_READ_ONLY) {
TRACE("Server is read-only, return error");
reply.error = EROFS;
- goto error_reply;
+ break;
}
TRACE("Writing to device");
if (ret < 0) {
LOG("writing to file failed");
reply.error = -ret;
- goto error_reply;
}
- if (nbd_co_send_reply(req, &reply, 0) < 0) {
- goto out;
- }
break;
-
case NBD_CMD_DISC:
/* unreachable, thanks to special case in nbd_co_receive_request() */
abort();
LOG("flush failed");
reply.error = -ret;
}
- if (nbd_co_send_reply(req, &reply, 0) < 0) {
- goto out;
- }
+
break;
case NBD_CMD_TRIM:
TRACE("Request type is TRIM");
LOG("discard failed");
reply.error = -ret;
}
- if (nbd_co_send_reply(req, &reply, 0) < 0) {
- goto out;
- }
+
break;
default:
LOG("invalid request type (%" PRIu32 ") received", request.type);
reply.error = EINVAL;
- error_reply:
- /* We must disconnect after NBD_CMD_WRITE if we did not
- * read the payload.
- */
- if (nbd_co_send_reply(req, &reply, 0) < 0 || !req->complete) {
- goto out;
- }
- break;
+ }
+
+reply:
+ /* We must disconnect after NBD_CMD_WRITE if we did not
+ * read the payload.
+ */
+ if (nbd_co_send_reply(req, &reply, reply_data_len) < 0 || !req->complete) {
+ goto disconnect;
}
TRACE("Request/Reply complete");
nbd_client_put(client);
return;
-out:
+disconnect:
nbd_request_put(req);
client_close(client, true);
nbd_client_put(client);