diff options
author | Max Reitz <mreitz@redhat.com> | 2019-04-05 21:16:35 +0200 |
---|---|---|
committer | Eric Blake <eblake@redhat.com> | 2019-05-07 09:43:42 -0500 |
commit | c4e2aff81bef7310a4139707f8f880dbd2bab6b4 (patch) | |
tree | 7783b9d60074a03cfffd7f1d4738d7222681f400 /qemu-nbd.c | |
parent | 19eb2d4e736dc895f31fbd6b520e514f10cc08e0 (diff) |
qemu-nbd: Look up flag names in array
The existing code to convert flag bits into strings looks a bit strange
now, and if we ever add more flags, it will look even stranger. Prevent
that from happening by making it look up the flag names in an array.
Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-Id: <20190405191635.25740-1-mreitz@redhat.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
Diffstat (limited to 'qemu-nbd.c')
-rw-r--r-- | qemu-nbd.c | 46 |
1 files changed, 17 insertions, 29 deletions
diff --git a/qemu-nbd.c b/qemu-nbd.c index dca9e72cee..081fcf74d5 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -279,37 +279,25 @@ static int qemu_nbd_client_list(SocketAddress *saddr, QCryptoTLSCreds *tls, printf(" description: %s\n", list[i].description); } if (list[i].flags & NBD_FLAG_HAS_FLAGS) { + static const char *const flag_names[] = { + [NBD_FLAG_READ_ONLY_BIT] = "readonly", + [NBD_FLAG_SEND_FLUSH_BIT] = "flush", + [NBD_FLAG_SEND_FUA_BIT] = "fua", + [NBD_FLAG_ROTATIONAL_BIT] = "rotational", + [NBD_FLAG_SEND_TRIM_BIT] = "trim", + [NBD_FLAG_SEND_WRITE_ZEROES_BIT] = "zeroes", + [NBD_FLAG_SEND_DF_BIT] = "df", + [NBD_FLAG_CAN_MULTI_CONN_BIT] = "multi", + [NBD_FLAG_SEND_RESIZE_BIT] = "resize", + [NBD_FLAG_SEND_CACHE_BIT] = "cache", + }; + printf(" size: %" PRIu64 "\n", list[i].size); printf(" flags: 0x%x (", list[i].flags); - if (list[i].flags & NBD_FLAG_READ_ONLY) { - printf(" readonly"); - } - if (list[i].flags & NBD_FLAG_SEND_FLUSH) { - printf(" flush"); - } - if (list[i].flags & NBD_FLAG_SEND_FUA) { - printf(" fua"); - } - if (list[i].flags & NBD_FLAG_ROTATIONAL) { - printf(" rotational"); - } - if (list[i].flags & NBD_FLAG_SEND_TRIM) { - printf(" trim"); - } - if (list[i].flags & NBD_FLAG_SEND_WRITE_ZEROES) { - printf(" zeroes"); - } - if (list[i].flags & NBD_FLAG_SEND_DF) { - printf(" df"); - } - if (list[i].flags & NBD_FLAG_CAN_MULTI_CONN) { - printf(" multi"); - } - if (list[i].flags & NBD_FLAG_SEND_RESIZE) { - printf(" resize"); - } - if (list[i].flags & NBD_FLAG_SEND_CACHE) { - printf(" cache"); + for (size_t bit = 0; bit < ARRAY_SIZE(flag_names); bit++) { + if (flag_names[bit] && (list[i].flags & (1 << bit))) { + printf(" %s", flag_names[bit]); + } } printf(" )\n"); } |