qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 18/19] nbd/client: refactor TRACE of NBD_MAGIC


From: Vladimir Sementsov-Ogievskiy
Subject: Re: [Qemu-devel] [PATCH 18/19] nbd/client: refactor TRACE of NBD_MAGIC
Date: Tue, 6 Jun 2017 12:01:46 +0300
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.1

05.06.2017 18:06, Eric Blake wrote:
On 05/30/2017 09:30 AM, Vladimir Sementsov-Ogievskiy wrote:
Signed-off-by: Vladimir Sementsov-Ogievskiy <address@hidden>
---
  nbd/client.c | 26 +++++++++++++++++---------
  1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/nbd/client.c b/nbd/client.c
index 3d15596120..52f7981c9c 100644
--- a/nbd/client.c
+++ b/nbd/client.c
@@ -426,6 +426,21 @@ static QIOChannel *nbd_receive_starttls(QIOChannel *ioc,
      return QIO_CHANNEL(tioc);
  }
+static const char *nbd_magic_to_string(char *out, const char *in,
+                                       size_t count)
+{
+    size_t i;
+
+    for (i = 0; i < count; ++i) {
+        if (in[i] == '\0') {
+            out[i] = '\0';
+            break;
+        }
+        out[i] = qemu_isprint(in[i]) ? in[i] : '.';
+    }
+
+    return out;
+}
Do we really need this?

-    TRACE("Magic is %c%c%c%c%c%c%c%c",
-          qemu_isprint(buf[0]) ? buf[0] : '.',
-          qemu_isprint(buf[1]) ? buf[1] : '.',
-          qemu_isprint(buf[2]) ? buf[2] : '.',
-          qemu_isprint(buf[3]) ? buf[3] : '.',
-          qemu_isprint(buf[4]) ? buf[4] : '.',
-          qemu_isprint(buf[5]) ? buf[5] : '.',
-          qemu_isprint(buf[6]) ? buf[6] : '.',
-          qemu_isprint(buf[7]) ? buf[7] : '.');
+    TRACE("Magic is %s", nbd_magic_to_string(print_buf, buf, 9));
Would it be any simpler to just print the received magic as a 64-bit
number in hex, instead of trying to string-ize it?  Either the client
sends the right magic (the usual case), so we don't need to waste time
string-izing it, or the client is bogus and sent us garbage (where
printing a hex value is just as efficient as string-izing things to see
what the garbage actually was).

agree.



--
Best regards,
Vladimir




reply via email to

[Prev in Thread] Current Thread [Next in Thread]