[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH v5 03/13] block/nbd: Default port in nbd_refresh_fil
From: |
Max Reitz |
Subject: |
[Qemu-block] [PATCH v5 03/13] block/nbd: Default port in nbd_refresh_filename() |
Date: |
Tue, 25 Oct 2016 15:11:31 +0200 |
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 <address@hidden>
Reviewed-by: Kevin Wolf <address@hidden>
Signed-off-by: Max Reitz <address@hidden>
---
block/nbd.c | 19 ++++++-------------
1 file changed, 6 insertions(+), 13 deletions(-)
diff --git a/block/nbd.c b/block/nbd.c
index eaca33c..c77a969 100644
--- a/block/nbd.c
+++ b/block/nbd.c
@@ -444,6 +444,7 @@ static void nbd_refresh_filename(BlockDriverState *bs,
QDict *options)
{
BDRVNBDState *s = bs->opaque;
QDict *opts = qdict_new();
+ const char *port = s->port ?: stringify(NBD_DEFAULT_PORT);
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) {
snprintf(bs->exact_filename, sizeof(bs->exact_filename),
"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),
- "nbd://%s:%s/%s", s->host, s->port, s->export);
- } else if (!s->path && s->export && !s->port) {
+ "nbd://%s:%s/%s", s->host, port, s->export);
+ } else if (!s->path && !s->export) {
snprintf(bs->exact_filename, sizeof(bs->exact_filename),
- "nbd://%s/%s", s->host, s->export);
- } 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);
+ "nbd://%s:%s", s->host, port);
}
if (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 {
qdict_put_obj(opts, "host", QOBJECT(qstring_from_str(s->host)));
+ qdict_put_obj(opts, "port", QOBJECT(qstring_from_str(port)));
}
if (s->export) {
qdict_put_obj(opts, "export", QOBJECT(qstring_from_str(s->export)));
--
2.10.1
- [Qemu-block] [PATCH v5 00/13] qapi: Allow blockdev-add for NBD, Max Reitz, 2016/10/25
- [Qemu-block] [PATCH v5 01/13] block/nbd: Drop trailing "." in error messages, Max Reitz, 2016/10/25
- [Qemu-block] [PATCH v5 02/13] block/nbd: Reject port parameter without host, Max Reitz, 2016/10/25
- [Qemu-block] [PATCH v5 03/13] block/nbd: Default port in nbd_refresh_filename(),
Max Reitz <=
- [Qemu-block] [PATCH v5 04/13] block/nbd: Use qdict_put(), Max Reitz, 2016/10/25
- [Qemu-block] [PATCH v5 05/13] block/nbd: Add nbd_has_filename_options_conflict(), Max Reitz, 2016/10/25
- [Qemu-block] [PATCH v5 07/13] block/nbd: Use SocketAddress options, Max Reitz, 2016/10/25
- [Qemu-block] [PATCH v5 06/13] block/nbd: Accept SocketAddress, Max Reitz, 2016/10/25
- [Qemu-block] [PATCH v5 08/13] qapi: Allow blockdev-add for NBD, Max Reitz, 2016/10/25