aboutsummaryrefslogtreecommitdiff
path: root/block
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2017-04-26 09:36:41 +0200
committerMarkus Armbruster <armbru@redhat.com>2017-05-09 09:14:40 +0200
commitbd269ebc82fbaa5fe7ce5bc7c1770ac8acecd884 (patch)
tree82ef0cd9da0812afc7021d5690c14f72e8e13177 /block
parent62cf396b5d397948c5ac4d04d09596ca14f6c173 (diff)
sockets: Limit SocketAddressLegacy to external interfaces
SocketAddressLegacy is a simple union, and simple unions are awkward: they have their variant members wrapped in a "data" object on the wire, and require additional indirections in C. SocketAddress is the equivalent flat union. Convert all users of SocketAddressLegacy to SocketAddress, except for existing external interfaces. See also commit fce5d53..9445673 and 85a82e8..c5f1ae3. Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-Id: <1493192202-3184-7-git-send-email-armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> [Minor editing accident fixed, commit message and a comment tweaked] Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'block')
-rw-r--r--block/nbd.c4
-rw-r--r--block/sheepdog.c32
2 files changed, 14 insertions, 22 deletions
diff --git a/block/nbd.c b/block/nbd.c
index bbe0f99d6c..975faab2c5 100644
--- a/block/nbd.c
+++ b/block/nbd.c
@@ -306,10 +306,9 @@ NBDClientSession *nbd_get_client_session(BlockDriverState *bs)
return &s->client;
}
-static QIOChannelSocket *nbd_establish_connection(SocketAddress *saddr_flat,
+static QIOChannelSocket *nbd_establish_connection(SocketAddress *saddr,
Error **errp)
{
- SocketAddressLegacy *saddr = socket_address_crumple(saddr_flat);
QIOChannelSocket *sioc;
Error *local_err = NULL;
@@ -319,7 +318,6 @@ static QIOChannelSocket *nbd_establish_connection(SocketAddress *saddr_flat,
qio_channel_socket_connect_sync(sioc,
saddr,
&local_err);
- qapi_free_SocketAddressLegacy(saddr);
if (local_err) {
object_unref(OBJECT(sioc));
error_propagate(errp, local_err);
diff --git a/block/sheepdog.c b/block/sheepdog.c
index b8d69b31e7..a18315a1ca 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -378,7 +378,7 @@ struct BDRVSheepdogState {
uint32_t cache_flags;
bool discard_supported;
- SocketAddressLegacy *addr;
+ SocketAddress *addr;
int fd;
CoMutex lock;
@@ -530,32 +530,29 @@ static void sd_aio_setup(SheepdogAIOCB *acb, BDRVSheepdogState *s,
QLIST_INSERT_HEAD(&s->inflight_aiocb_head, acb, aiocb_siblings);
}
-static SocketAddressLegacy *sd_socket_address(const char *path,
+static SocketAddress *sd_socket_address(const char *path,
const char *host, const char *port)
{
- SocketAddressLegacy *addr = g_new0(SocketAddressLegacy, 1);
+ SocketAddress *addr = g_new0(SocketAddress, 1);
if (path) {
- addr->type = SOCKET_ADDRESS_LEGACY_KIND_UNIX;
- addr->u.q_unix.data = g_new0(UnixSocketAddress, 1);
- addr->u.q_unix.data->path = g_strdup(path);
+ addr->type = SOCKET_ADDRESS_TYPE_UNIX;
+ addr->u.q_unix.path = g_strdup(path);
} else {
- addr->type = SOCKET_ADDRESS_LEGACY_KIND_INET;
- addr->u.inet.data = g_new0(InetSocketAddress, 1);
- addr->u.inet.data->host = g_strdup(host ?: SD_DEFAULT_ADDR);
- addr->u.inet.data->port = g_strdup(port ?: stringify(SD_DEFAULT_PORT));
+ addr->type = SOCKET_ADDRESS_TYPE_INET;
+ addr->u.inet.host = g_strdup(host ?: SD_DEFAULT_ADDR);
+ addr->u.inet.port = g_strdup(port ?: stringify(SD_DEFAULT_PORT));
}
return addr;
}
-static SocketAddressLegacy *sd_server_config(QDict *options, Error **errp)
+static SocketAddress *sd_server_config(QDict *options, Error **errp)
{
QDict *server = NULL;
QObject *crumpled_server = NULL;
Visitor *iv = NULL;
- SocketAddress *saddr_flat = NULL;
- SocketAddressLegacy *saddr = NULL;
+ SocketAddress *saddr = NULL;
Error *local_err = NULL;
qdict_extract_subqdict(options, &server, "server.");
@@ -574,16 +571,13 @@ static SocketAddressLegacy *sd_server_config(QDict *options, Error **errp)
* visitor expects the former.
*/
iv = qobject_input_visitor_new(crumpled_server);
- visit_type_SocketAddress(iv, NULL, &saddr_flat, &local_err);
+ visit_type_SocketAddress(iv, NULL, &saddr, &local_err);
if (local_err) {
error_propagate(errp, local_err);
goto done;
}
- saddr = socket_address_crumple(saddr_flat);
-
done:
- qapi_free_SocketAddress(saddr_flat);
visit_free(iv);
qobject_decref(crumpled_server);
QDECREF(server);
@@ -597,7 +591,7 @@ static int connect_to_sdog(BDRVSheepdogState *s, Error **errp)
fd = socket_connect(s->addr, NULL, NULL, errp);
- if (s->addr->type == SOCKET_ADDRESS_LEGACY_KIND_INET && fd >= 0) {
+ if (s->addr->type == SOCKET_ADDRESS_TYPE_INET && fd >= 0) {
int ret = socket_set_nodelay(fd);
if (ret < 0) {
error_report("%s", strerror(errno));
@@ -2149,7 +2143,7 @@ static void sd_close(BlockDriverState *bs)
aio_set_fd_handler(bdrv_get_aio_context(bs), s->fd,
false, NULL, NULL, NULL, NULL);
closesocket(s->fd);
- qapi_free_SocketAddressLegacy(s->addr);
+ qapi_free_SocketAddress(s->addr);
}
static int64_t sd_getlength(BlockDriverState *bs)