/* Discard length bytes from channel. Return -errno on failure and 0 on
* success*/
-static int drop_sync(QIOChannel *ioc, size_t size, Error **errp)
+static int nbd_drop(QIOChannel *ioc, size_t size, Error **errp)
{
ssize_t ret = 0;
char small[1024];
buffer = sizeof(small) >= size ? small : g_malloc(MIN(65536, size));
while (size > 0) {
ssize_t count = MIN(65536, size);
- ret = read_sync(ioc, buffer, MIN(65536, size), errp);
+ ret = nbd_read(ioc, buffer, MIN(65536, size), errp);
if (ret < 0) {
goto cleanup;
stl_be_p(&req.option, opt);
stl_be_p(&req.length, len);
- if (write_sync(ioc, &req, sizeof(req), errp) < 0) {
+ if (nbd_write(ioc, &req, sizeof(req), errp) < 0) {
error_prepend(errp, "Failed to send option request header");
return -1;
}
- if (len && write_sync(ioc, (char *) data, len, errp) < 0) {
+ if (len && nbd_write(ioc, (char *) data, len, errp) < 0) {
error_prepend(errp, "Failed to send option request data");
return -1;
}
nbd_opt_reply *reply, Error **errp)
{
QEMU_BUILD_BUG_ON(sizeof(*reply) != 20);
- if (read_sync(ioc, reply, sizeof(*reply), errp) < 0) {
+ if (nbd_read(ioc, reply, sizeof(*reply), errp) < 0) {
error_prepend(errp, "failed to read option reply");
nbd_send_opt_abort(ioc);
return -1;
goto cleanup;
}
msg = g_malloc(reply->length + 1);
- if (read_sync(ioc, msg, reply->length, errp) < 0) {
+ if (nbd_read(ioc, msg, reply->length, errp) < 0) {
error_prepend(errp, "failed to read option error message");
goto cleanup;
}
nbd_send_opt_abort(ioc);
return -1;
}
- if (read_sync(ioc, &namelen, sizeof(namelen), errp) < 0) {
+ if (nbd_read(ioc, &namelen, sizeof(namelen), errp) < 0) {
error_prepend(errp, "failed to read option name length");
nbd_send_opt_abort(ioc);
return -1;
return -1;
}
if (namelen != strlen(want)) {
- if (drop_sync(ioc, len, errp) < 0) {
+ if (nbd_drop(ioc, len, errp) < 0) {
error_prepend(errp, "failed to skip export name with wrong length");
nbd_send_opt_abort(ioc);
return -1;
}
assert(namelen < sizeof(name));
- if (read_sync(ioc, name, namelen, errp) < 0) {
+ if (nbd_read(ioc, name, namelen, errp) < 0) {
error_prepend(errp, "failed to read export name");
nbd_send_opt_abort(ioc);
return -1;
}
name[namelen] = '\0';
len -= namelen;
- if (drop_sync(ioc, len, errp) < 0) {
+ if (nbd_drop(ioc, len, errp) < 0) {
error_prepend(errp, "failed to read export description");
nbd_send_opt_abort(ioc);
return -1;
goto fail;
}
- if (read_sync(ioc, buf, 8, errp) < 0) {
+ if (nbd_read(ioc, buf, 8, errp) < 0) {
error_prepend(errp, "Failed to read data");
goto fail;
}
goto fail;
}
- if (read_sync(ioc, &magic, sizeof(magic), errp) < 0) {
+ if (nbd_read(ioc, &magic, sizeof(magic), errp) < 0) {
error_prepend(errp, "Failed to read magic");
goto fail;
}
uint16_t globalflags;
bool fixedNewStyle = false;
- if (read_sync(ioc, &globalflags, sizeof(globalflags), errp) < 0) {
+ if (nbd_read(ioc, &globalflags, sizeof(globalflags), errp) < 0) {
error_prepend(errp, "Failed to read server flags");
goto fail;
}
}
/* client requested flags */
clientflags = cpu_to_be32(clientflags);
- if (write_sync(ioc, &clientflags, sizeof(clientflags), errp) < 0) {
+ if (nbd_write(ioc, &clientflags, sizeof(clientflags), errp) < 0) {
error_prepend(errp, "Failed to send clientflags field");
goto fail;
}
}
/* Read the response */
- if (read_sync(ioc, &s, sizeof(s), errp) < 0) {
+ if (nbd_read(ioc, &s, sizeof(s), errp) < 0) {
error_prepend(errp, "Failed to read export length");
goto fail;
}
*size = be64_to_cpu(s);
- if (read_sync(ioc, flags, sizeof(*flags), errp) < 0) {
+ if (nbd_read(ioc, flags, sizeof(*flags), errp) < 0) {
error_prepend(errp, "Failed to read export flags");
goto fail;
}
goto fail;
}
- if (read_sync(ioc, &s, sizeof(s), errp) < 0) {
+ if (nbd_read(ioc, &s, sizeof(s), errp) < 0) {
error_prepend(errp, "Failed to read export length");
goto fail;
}
*size = be64_to_cpu(s);
TRACE("Size is %" PRIu64, *size);
- if (read_sync(ioc, &oldflags, sizeof(oldflags), errp) < 0) {
+ if (nbd_read(ioc, &oldflags, sizeof(oldflags), errp) < 0) {
error_prepend(errp, "Failed to read export flags");
goto fail;
}
}
TRACE("Size is %" PRIu64 ", export flags %" PRIx16, *size, *flags);
- if (zeroes && drop_sync(ioc, 124, errp) < 0) {
+ if (zeroes && nbd_drop(ioc, 124, errp) < 0) {
error_prepend(errp, "Failed to read reserved block");
goto fail;
}
stq_be_p(buf + 16, request->from);
stl_be_p(buf + 24, request->len);
- return write_sync(ioc, buf, sizeof(buf), NULL);
+ return nbd_write(ioc, buf, sizeof(buf), NULL);
}
ssize_t nbd_receive_reply(QIOChannel *ioc, NBDReply *reply, Error **errp)
uint32_t magic;
ssize_t ret;
- ret = read_sync_eof(ioc, buf, sizeof(buf), errp);
+ ret = nbd_read_eof(ioc, buf, sizeof(buf), errp);
if (ret <= 0) {
return ret;
}
#define NBD_ENOSPC 28
#define NBD_ESHUTDOWN 108
-/* read_sync_eof
+/* nbd_read_eof
* Tries to read @size bytes from @ioc. Returns number of bytes actually read.
* May return a value >= 0 and < size only on EOF, i.e. when iteratively called
- * qio_channel_readv() returns 0. So, there are no needs to call read_sync_eof
+ * qio_channel_readv() returns 0. So, there is no need to call nbd_read_eof
* iteratively.
*/
-static inline ssize_t read_sync_eof(QIOChannel *ioc, void *buffer, size_t size,
- Error **errp)
+static inline ssize_t nbd_read_eof(QIOChannel *ioc, void *buffer, size_t size,
+ Error **errp)
{
struct iovec iov = { .iov_base = buffer, .iov_len = size };
/* Sockets are kept in blocking mode in the negotiation phase. After
* our request/reply. Synchronization is done with recv_coroutine, so
* that this is coroutine-safe.
*/
- return nbd_wr_syncv(ioc, &iov, 1, size, true, errp);
+ return nbd_rwv(ioc, &iov, 1, size, true, errp);
}
-/* read_sync
+/* nbd_read
* Reads @size bytes from @ioc. Returns 0 on success.
*/
-static inline int read_sync(QIOChannel *ioc, void *buffer, size_t size,
- Error **errp)
+static inline int nbd_read(QIOChannel *ioc, void *buffer, size_t size,
+ Error **errp)
{
- ssize_t ret = read_sync_eof(ioc, buffer, size, errp);
+ ssize_t ret = nbd_read_eof(ioc, buffer, size, errp);
if (ret >= 0 && ret != size) {
ret = -EINVAL;
return ret < 0 ? ret : 0;
}
-/* write_sync
+/* nbd_write
* Writes @size bytes to @ioc. Returns 0 on success.
*/
-static inline int write_sync(QIOChannel *ioc, const void *buffer, size_t size,
- Error **errp)
+static inline int nbd_write(QIOChannel *ioc, const void *buffer, size_t size,
+ Error **errp)
{
struct iovec iov = { .iov_base = (void *) buffer, .iov_len = size };
- ssize_t ret = nbd_wr_syncv(ioc, &iov, 1, size, false, errp);
+ ssize_t ret = nbd_rwv(ioc, &iov, 1, size, false, errp);
assert(ret < 0 || ret == size);
nbd_negotiate_continue,
qemu_coroutine_self(),
NULL);
- ret = read_sync(ioc, buffer, size, NULL);
+ ret = nbd_read(ioc, buffer, size, NULL);
g_source_remove(watch);
return ret;
nbd_negotiate_continue,
qemu_coroutine_self(),
NULL);
- ret = write_sync(ioc, buffer, size, NULL);
+ ret = nbd_write(ioc, buffer, size, NULL);
g_source_remove(watch);
return ret;
}
uint32_t magic;
ssize_t ret;
- ret = read_sync(ioc, buf, sizeof(buf), NULL);
+ ret = nbd_read(ioc, buf, sizeof(buf), NULL);
if (ret < 0) {
return ret;
}
stl_be_p(buf + 4, reply->error);
stq_be_p(buf + 8, reply->handle);
- return write_sync(ioc, buf, sizeof(buf), NULL);
+ return nbd_write(ioc, buf, sizeof(buf), NULL);
}
#define MAX_NBD_REQUESTS 16
qio_channel_set_cork(client->ioc, true);
rc = nbd_send_reply(client->ioc, reply);
if (rc >= 0) {
- ret = write_sync(client->ioc, req->data, len, NULL);
+ ret = nbd_write(client->ioc, req->data, len, NULL);
if (ret < 0) {
rc = -EIO;
}
if (request->type == NBD_CMD_WRITE) {
TRACE("Reading %" PRIu32 " byte(s)", request->len);
- if (read_sync(client->ioc, req->data, request->len, NULL) < 0) {
+ if (nbd_read(client->ioc, req->data, request->len, NULL) < 0) {
LOG("reading from socket failed");
rc = -EIO;
goto out;