mirror of https://gitee.com/openkylin/qemu.git
block/nbd: Default port in nbd_refresh_filename()
Instead of not emitting the port in nbd_refresh_filename(), just set it to the default if the user did not specify it. This makes the logic a bit simpler. Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Max Reitz <mreitz@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
442045cbce
commit
7edca33804
19
block/nbd.c
19
block/nbd.c
|
@ -444,6 +444,7 @@ static void nbd_refresh_filename(BlockDriverState *bs, QDict *options)
|
||||||
{
|
{
|
||||||
BDRVNBDState *s = bs->opaque;
|
BDRVNBDState *s = bs->opaque;
|
||||||
QDict *opts = qdict_new();
|
QDict *opts = qdict_new();
|
||||||
|
const char *port = s->port ?: stringify(NBD_DEFAULT_PORT);
|
||||||
|
|
||||||
qdict_put_obj(opts, "driver", QOBJECT(qstring_from_str("nbd")));
|
qdict_put_obj(opts, "driver", QOBJECT(qstring_from_str("nbd")));
|
||||||
|
|
||||||
|
@ -453,27 +454,19 @@ static void nbd_refresh_filename(BlockDriverState *bs, QDict *options)
|
||||||
} else if (s->path && !s->export) {
|
} else if (s->path && !s->export) {
|
||||||
snprintf(bs->exact_filename, sizeof(bs->exact_filename),
|
snprintf(bs->exact_filename, sizeof(bs->exact_filename),
|
||||||
"nbd+unix://?socket=%s", s->path);
|
"nbd+unix://?socket=%s", s->path);
|
||||||
} else if (!s->path && s->export && s->port) {
|
} else if (!s->path && s->export) {
|
||||||
snprintf(bs->exact_filename, sizeof(bs->exact_filename),
|
snprintf(bs->exact_filename, sizeof(bs->exact_filename),
|
||||||
"nbd://%s:%s/%s", s->host, s->port, s->export);
|
"nbd://%s:%s/%s", s->host, port, s->export);
|
||||||
} else if (!s->path && s->export && !s->port) {
|
} else if (!s->path && !s->export) {
|
||||||
snprintf(bs->exact_filename, sizeof(bs->exact_filename),
|
snprintf(bs->exact_filename, sizeof(bs->exact_filename),
|
||||||
"nbd://%s/%s", s->host, s->export);
|
"nbd://%s:%s", s->host, port);
|
||||||
} else if (!s->path && !s->export && s->port) {
|
|
||||||
snprintf(bs->exact_filename, sizeof(bs->exact_filename),
|
|
||||||
"nbd://%s:%s", s->host, s->port);
|
|
||||||
} else if (!s->path && !s->export && !s->port) {
|
|
||||||
snprintf(bs->exact_filename, sizeof(bs->exact_filename),
|
|
||||||
"nbd://%s", s->host);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s->path) {
|
if (s->path) {
|
||||||
qdict_put_obj(opts, "path", QOBJECT(qstring_from_str(s->path)));
|
qdict_put_obj(opts, "path", QOBJECT(qstring_from_str(s->path)));
|
||||||
} else if (s->port) {
|
|
||||||
qdict_put_obj(opts, "host", QOBJECT(qstring_from_str(s->host)));
|
|
||||||
qdict_put_obj(opts, "port", QOBJECT(qstring_from_str(s->port)));
|
|
||||||
} else {
|
} else {
|
||||||
qdict_put_obj(opts, "host", QOBJECT(qstring_from_str(s->host)));
|
qdict_put_obj(opts, "host", QOBJECT(qstring_from_str(s->host)));
|
||||||
|
qdict_put_obj(opts, "port", QOBJECT(qstring_from_str(port)));
|
||||||
}
|
}
|
||||||
if (s->export) {
|
if (s->export) {
|
||||||
qdict_put_obj(opts, "export", QOBJECT(qstring_from_str(s->export)));
|
qdict_put_obj(opts, "export", QOBJECT(qstring_from_str(s->export)));
|
||||||
|
|
Loading…
Reference in New Issue