nbd/client.c: use errp instead of LOG
Move to modern errp scheme from just LOGging errors. Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Message-Id: <20170526110913.89098-1-vsementsov@virtuozzo.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
e44ed99d19
commit
be41c100c0
|
@ -28,6 +28,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
|
#include "qapi/error.h"
|
||||||
#include "nbd-client.h"
|
#include "nbd-client.h"
|
||||||
|
|
||||||
#define HANDLE_TO_INDEX(bs, handle) ((handle) ^ ((uint64_t)(intptr_t)bs))
|
#define HANDLE_TO_INDEX(bs, handle) ((handle) ^ ((uint64_t)(intptr_t)bs))
|
||||||
|
@ -70,10 +71,14 @@ static coroutine_fn void nbd_read_reply_entry(void *opaque)
|
||||||
NBDClientSession *s = opaque;
|
NBDClientSession *s = opaque;
|
||||||
uint64_t i;
|
uint64_t i;
|
||||||
int ret;
|
int ret;
|
||||||
|
Error *local_err = NULL;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
assert(s->reply.handle == 0);
|
assert(s->reply.handle == 0);
|
||||||
ret = nbd_receive_reply(s->ioc, &s->reply);
|
ret = nbd_receive_reply(s->ioc, &s->reply, &local_err);
|
||||||
|
if (ret < 0) {
|
||||||
|
error_report_err(local_err);
|
||||||
|
}
|
||||||
if (ret <= 0) {
|
if (ret <= 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,9 +133,10 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char *name, uint16_t *flags,
|
||||||
QCryptoTLSCreds *tlscreds, const char *hostname,
|
QCryptoTLSCreds *tlscreds, const char *hostname,
|
||||||
QIOChannel **outioc,
|
QIOChannel **outioc,
|
||||||
off_t *size, Error **errp);
|
off_t *size, Error **errp);
|
||||||
int nbd_init(int fd, QIOChannelSocket *sioc, uint16_t flags, off_t size);
|
int nbd_init(int fd, QIOChannelSocket *sioc, uint16_t flags, off_t size,
|
||||||
|
Error **errp);
|
||||||
ssize_t nbd_send_request(QIOChannel *ioc, NBDRequest *request);
|
ssize_t nbd_send_request(QIOChannel *ioc, NBDRequest *request);
|
||||||
ssize_t nbd_receive_reply(QIOChannel *ioc, NBDReply *reply);
|
ssize_t nbd_receive_reply(QIOChannel *ioc, NBDReply *reply, Error **errp);
|
||||||
int nbd_client(int fd);
|
int nbd_client(int fd);
|
||||||
int nbd_disconnect(int fd);
|
int nbd_disconnect(int fd);
|
||||||
|
|
||||||
|
|
30
nbd/client.c
30
nbd/client.c
|
@ -627,11 +627,13 @@ fail:
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
int nbd_init(int fd, QIOChannelSocket *sioc, uint16_t flags, off_t size)
|
int nbd_init(int fd, QIOChannelSocket *sioc, uint16_t flags, off_t size,
|
||||||
|
Error **errp)
|
||||||
{
|
{
|
||||||
unsigned long sectors = size / BDRV_SECTOR_SIZE;
|
unsigned long sectors = size / BDRV_SECTOR_SIZE;
|
||||||
if (size / BDRV_SECTOR_SIZE != sectors) {
|
if (size / BDRV_SECTOR_SIZE != sectors) {
|
||||||
LOG("Export size %lld too large for 32-bit kernel", (long long) size);
|
error_setg(errp, "Export size %lld too large for 32-bit kernel",
|
||||||
|
(long long) size);
|
||||||
return -E2BIG;
|
return -E2BIG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -639,7 +641,7 @@ int nbd_init(int fd, QIOChannelSocket *sioc, uint16_t flags, off_t size)
|
||||||
|
|
||||||
if (ioctl(fd, NBD_SET_SOCK, (unsigned long) sioc->fd) < 0) {
|
if (ioctl(fd, NBD_SET_SOCK, (unsigned long) sioc->fd) < 0) {
|
||||||
int serrno = errno;
|
int serrno = errno;
|
||||||
LOG("Failed to set NBD socket");
|
error_setg(errp, "Failed to set NBD socket");
|
||||||
return -serrno;
|
return -serrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -647,7 +649,7 @@ int nbd_init(int fd, QIOChannelSocket *sioc, uint16_t flags, off_t size)
|
||||||
|
|
||||||
if (ioctl(fd, NBD_SET_BLKSIZE, (unsigned long)BDRV_SECTOR_SIZE) < 0) {
|
if (ioctl(fd, NBD_SET_BLKSIZE, (unsigned long)BDRV_SECTOR_SIZE) < 0) {
|
||||||
int serrno = errno;
|
int serrno = errno;
|
||||||
LOG("Failed setting NBD block size");
|
error_setg(errp, "Failed setting NBD block size");
|
||||||
return -serrno;
|
return -serrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -659,7 +661,7 @@ int nbd_init(int fd, QIOChannelSocket *sioc, uint16_t flags, off_t size)
|
||||||
|
|
||||||
if (ioctl(fd, NBD_SET_SIZE_BLOCKS, sectors) < 0) {
|
if (ioctl(fd, NBD_SET_SIZE_BLOCKS, sectors) < 0) {
|
||||||
int serrno = errno;
|
int serrno = errno;
|
||||||
LOG("Failed setting size (in blocks)");
|
error_setg(errp, "Failed setting size (in blocks)");
|
||||||
return -serrno;
|
return -serrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -670,12 +672,12 @@ int nbd_init(int fd, QIOChannelSocket *sioc, uint16_t flags, off_t size)
|
||||||
|
|
||||||
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");
|
error_setg(errp, "Failed setting read-only attribute");
|
||||||
return -serrno;
|
return -serrno;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
int serrno = errno;
|
int serrno = errno;
|
||||||
LOG("Failed setting flags");
|
error_setg(errp, "Failed setting flags");
|
||||||
return -serrno;
|
return -serrno;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -723,8 +725,10 @@ int nbd_disconnect(int fd)
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
int nbd_init(int fd, QIOChannelSocket *ioc, uint16_t flags, off_t size)
|
int nbd_init(int fd, QIOChannelSocket *ioc, uint16_t flags, off_t size,
|
||||||
|
Error **errp)
|
||||||
{
|
{
|
||||||
|
error_setg(errp, "nbd_init is only supported on Linux");
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -758,19 +762,19 @@ ssize_t nbd_send_request(QIOChannel *ioc, NBDRequest *request)
|
||||||
return write_sync(ioc, buf, sizeof(buf), NULL);
|
return write_sync(ioc, buf, sizeof(buf), NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t nbd_receive_reply(QIOChannel *ioc, NBDReply *reply)
|
ssize_t nbd_receive_reply(QIOChannel *ioc, NBDReply *reply, Error **errp)
|
||||||
{
|
{
|
||||||
uint8_t buf[NBD_REPLY_SIZE];
|
uint8_t buf[NBD_REPLY_SIZE];
|
||||||
uint32_t magic;
|
uint32_t magic;
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
|
|
||||||
ret = read_sync_eof(ioc, buf, sizeof(buf), NULL);
|
ret = read_sync_eof(ioc, buf, sizeof(buf), errp);
|
||||||
if (ret <= 0) {
|
if (ret <= 0) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret != sizeof(buf)) {
|
if (ret != sizeof(buf)) {
|
||||||
LOG("read failed");
|
error_setg(errp, "read failed");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -788,7 +792,7 @@ ssize_t nbd_receive_reply(QIOChannel *ioc, NBDReply *reply)
|
||||||
|
|
||||||
if (reply->error == ESHUTDOWN) {
|
if (reply->error == ESHUTDOWN) {
|
||||||
/* This works even on mingw which lacks a native ESHUTDOWN */
|
/* This works even on mingw which lacks a native ESHUTDOWN */
|
||||||
LOG("server shutting down");
|
error_setg(errp, "server shutting down");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
TRACE("Got reply: { magic = 0x%" PRIx32 ", .error = % " PRId32
|
TRACE("Got reply: { magic = 0x%" PRIx32 ", .error = % " PRId32
|
||||||
|
@ -796,7 +800,7 @@ ssize_t nbd_receive_reply(QIOChannel *ioc, NBDReply *reply)
|
||||||
magic, reply->error, reply->handle);
|
magic, reply->error, reply->handle);
|
||||||
|
|
||||||
if (magic != NBD_REPLY_MAGIC) {
|
if (magic != NBD_REPLY_MAGIC) {
|
||||||
LOG("invalid magic (got 0x%" PRIx32 ")", magic);
|
error_setg(errp, "invalid magic (got 0x%" PRIx32 ")", magic);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
return sizeof(buf);
|
return sizeof(buf);
|
||||||
|
|
|
@ -288,8 +288,9 @@ static void *nbd_client_thread(void *arg)
|
||||||
goto out_socket;
|
goto out_socket;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = nbd_init(fd, sioc, nbdflags, size);
|
ret = nbd_init(fd, sioc, nbdflags, size, &local_error);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
|
error_report_err(local_error);
|
||||||
goto out_fd;
|
goto out_fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,10 +69,12 @@ read failed: Input/output error
|
||||||
|
|
||||||
=== Check disconnect 4 reply ===
|
=== Check disconnect 4 reply ===
|
||||||
|
|
||||||
|
read failed
|
||||||
read failed: Input/output error
|
read failed: Input/output error
|
||||||
|
|
||||||
=== Check disconnect 8 reply ===
|
=== Check disconnect 8 reply ===
|
||||||
|
|
||||||
|
read failed
|
||||||
read failed: Input/output error
|
read failed: Input/output error
|
||||||
|
|
||||||
=== Check disconnect before data ===
|
=== Check disconnect before data ===
|
||||||
|
|
Loading…
Reference in a new issue