nbd: Use default port if only host is specified

The URL method already takes care to apply the default port when none is
specfied. Directly specifying driver-specific options required the port
number until now. Allow leaving it out and apply the default.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
master
Kevin Wolf 2013-03-18 16:56:05 +01:00
parent c2ad1b0c46
commit bebbf7fa9c
1 changed files with 10 additions and 9 deletions

View File

@ -118,22 +118,19 @@ static int nbd_parse_uri(const char *filename, QDict *options)
} }
qdict_put(options, "path", qstring_from_str(qp->p[0].value)); qdict_put(options, "path", qstring_from_str(qp->p[0].value));
} else { } else {
/* nbd[+tcp]://host:port/export */ /* nbd[+tcp]://host[:port]/export */
char *port_str;
if (!uri->server) { if (!uri->server) {
ret = -EINVAL; ret = -EINVAL;
goto out; goto out;
} }
if (!uri->port) {
uri->port = NBD_DEFAULT_PORT;
}
port_str = g_strdup_printf("%d", uri->port);
qdict_put(options, "host", qstring_from_str(uri->server)); qdict_put(options, "host", qstring_from_str(uri->server));
if (uri->port) {
char* port_str = g_strdup_printf("%d", uri->port);
qdict_put(options, "port", qstring_from_str(port_str)); qdict_put(options, "port", qstring_from_str(port_str));
g_free(port_str); g_free(port_str);
} }
}
out: out:
if (qp) { if (qp) {
@ -223,6 +220,10 @@ static int nbd_config(BDRVNBDState *s, QDict *options)
return -EINVAL; return -EINVAL;
} }
if (!qemu_opt_get(s->socket_opts, "port")) {
qemu_opt_set_number(s->socket_opts, "port", NBD_DEFAULT_PORT);
}
s->export_name = g_strdup(qdict_get_try_str(options, "export")); s->export_name = g_strdup(qdict_get_try_str(options, "export"));
if (s->export_name) { if (s->export_name) {
qdict_del(options, "export"); qdict_del(options, "export");