[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH v3 for-2.9 5/9] gluster: Prepare for SocketAddressFl
From: |
Markus Armbruster |
Subject: |
[Qemu-block] [PATCH v3 for-2.9 5/9] gluster: Prepare for SocketAddressFlat extension |
Date: |
Thu, 30 Mar 2017 19:43:13 +0200 |
qemu_gluster_glfs_init() and qemu_gluster_parse_json() rely on the
fact that SocketAddressFlatType has only two members
SOCKET_ADDRESS_FLAT_TYPE_INET and SOCKET_ADDRESS_FLAT_TYPE_UNIX.
Correct, but won't stay correct. Make them more robust.
Signed-off-by: Markus Armbruster <address@hidden>
Reviewed-by: Max Reitz <address@hidden>
Reviewed-by: Jeff Cody <address@hidden>
---
block/gluster.c | 26 ++++++++++++++++----------
1 file changed, 16 insertions(+), 10 deletions(-)
diff --git a/block/gluster.c b/block/gluster.c
index a577dae..fb0aafe 100644
--- a/block/gluster.c
+++ b/block/gluster.c
@@ -412,10 +412,12 @@ static struct glfs
*qemu_gluster_glfs_init(BlockdevOptionsGluster *gconf,
glfs_set_preopened(gconf->volume, glfs);
for (server = gconf->server; server; server = server->next) {
- if (server->value->type == SOCKET_ADDRESS_FLAT_TYPE_UNIX) {
+ switch (server->value->type) {
+ case SOCKET_ADDRESS_FLAT_TYPE_UNIX:
ret = glfs_set_volfile_server(glfs, "unix",
server->value->u.q_unix.path, 0);
- } else {
+ break;
+ case SOCKET_ADDRESS_FLAT_TYPE_INET:
if (parse_uint_full(server->value->u.inet.port, &port, 10) < 0 ||
port > 65535) {
error_setg(errp, "'%s' is not a valid port number",
@@ -426,6 +428,9 @@ static struct glfs
*qemu_gluster_glfs_init(BlockdevOptionsGluster *gconf,
ret = glfs_set_volfile_server(glfs, "tcp",
server->value->u.inet.host,
(int)port);
+ break;
+ default:
+ abort();
}
if (ret < 0) {
@@ -487,7 +492,7 @@ static int qemu_gluster_parse_json(BlockdevOptionsGluster
*gconf,
char *str = NULL;
const char *ptr;
size_t num_servers;
- int i;
+ int i, type;
/* create opts info from runtime_json_opts list */
opts = qemu_opts_create(&runtime_json_opts, NULL, 0, &error_abort);
@@ -539,16 +544,17 @@ static int qemu_gluster_parse_json(BlockdevOptionsGluster
*gconf,
if (!strcmp(ptr, "tcp")) {
ptr = "inet"; /* accept legacy "tcp" */
}
- gsconf->type = qapi_enum_parse(SocketAddressFlatType_lookup, ptr,
- SOCKET_ADDRESS_FLAT_TYPE__MAX, -1,
- &local_err);
- if (local_err) {
- error_append_hint(&local_err,
- "Parameter '%s' may be 'inet' or 'unix'\n",
- GLUSTER_OPT_TYPE);
+ type = qapi_enum_parse(SocketAddressFlatType_lookup, ptr,
+ SOCKET_ADDRESS_FLAT_TYPE__MAX, -1, NULL);
+ if (type != SOCKET_ADDRESS_FLAT_TYPE_INET
+ && type != SOCKET_ADDRESS_FLAT_TYPE_UNIX) {
+ error_setg(&local_err,
+ "Parameter '%s' may be 'inet' or 'unix'",
+ GLUSTER_OPT_TYPE);
error_append_hint(&local_err, GERR_INDEX_HINT, i);
goto out;
}
+ gsconf->type = type;
qemu_opts_del(opts);
if (gsconf->type == SOCKET_ADDRESS_FLAT_TYPE_INET) {
--
2.7.4
- [Qemu-block] [PATCH v3 for-2.9 0/9] Fixes and cleanups around SocketAddress, Markus Armbruster, 2017/03/30
- [Qemu-block] [PATCH v3 for-2.9 3/9] io vnc sockets: Clean up SocketAddressKind switches, Markus Armbruster, 2017/03/30
- [Qemu-block] [PATCH v3 for-2.9 6/9] qapi-schema: SocketAddressFlat variants 'vsock' and 'fd', Markus Armbruster, 2017/03/30
- [Qemu-block] [PATCH v3 for-2.9 5/9] gluster: Prepare for SocketAddressFlat extension,
Markus Armbruster <=
- [Qemu-block] [PATCH v3 for-2.9 2/9] char: Fix socket with "type": "vsock" address, Markus Armbruster, 2017/03/30
- [Qemu-block] [PATCH v3 for-2.9 8/9] nbd: Tidy up blockdev-add interface, Markus Armbruster, 2017/03/30
- [Qemu-block] [PATCH v3 for-2.9 1/9] nbd sockets vnc: Mark problematic address family tests TODO, Markus Armbruster, 2017/03/30
- [Qemu-block] [PATCH v3 for-2.9 9/9] sheepdog: Fix blockdev-add, Markus Armbruster, 2017/03/30
- [Qemu-block] [PATCH v3 for-2.9 4/9] block: Document -drive problematic code and bugs, Markus Armbruster, 2017/03/30