* [Qemu-devel] [PATCH 2/3] nbd: Avoid bitrot in TRACE() usage
2016-04-06 3:35 [Qemu-devel] [PATCH 0/3 for-2.6] more nbd fixups Eric Blake
2016-04-06 3:35 ` [Qemu-devel] [PATCH 1/3] nbd: Return correct error for write to read-only export Eric Blake
@ 2016-04-06 3:35 ` Eric Blake
2016-04-06 3:35 ` [Qemu-devel] [PATCH 3/3] nbd: Improve debug traces on little-endian Eric Blake
2 siblings, 0 replies; 4+ messages in thread
From: Eric Blake @ 2016-04-06 3:35 UTC (permalink / raw)
To: qemu-devel; +Cc: pbonzini
The compiler is smart enough to optimize out 'if (0)', but won't
type-check our printfs if they are hidden behind #if.
Signed-off-by: Eric Blake <eblake@redhat.com>
---
nbd/nbd-internal.h | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/nbd/nbd-internal.h b/nbd/nbd-internal.h
index 127c48d..f4dce06 100644
--- a/nbd/nbd-internal.h
+++ b/nbd/nbd-internal.h
@@ -33,18 +33,21 @@
#define DEBUG_NBD
#ifdef DEBUG_NBD
-#define TRACE(msg, ...) do { \
- LOG(msg, ## __VA_ARGS__); \
-} while(0)
+#define DEBUG_NBD_PRINT 1
#else
-#define TRACE(msg, ...) \
- do { } while (0)
+#define DEBUG_NBD_PRINT 0
#endif
+#define TRACE(msg, ...) do { \
+ if (DEBUG_NBD_PRINT) { \
+ LOG(msg, ## __VA_ARGS__); \
+ } \
+} while (0)
+
#define LOG(msg, ...) do { \
fprintf(stderr, "%s:%s():L%d: " msg "\n", \
__FILE__, __FUNCTION__, __LINE__, ## __VA_ARGS__); \
-} while(0)
+} while (0)
/* This is all part of the "official" NBD API.
*
--
2.5.5
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [Qemu-devel] [PATCH 3/3] nbd: Improve debug traces on little-endian
2016-04-06 3:35 [Qemu-devel] [PATCH 0/3 for-2.6] more nbd fixups Eric Blake
2016-04-06 3:35 ` [Qemu-devel] [PATCH 1/3] nbd: Return correct error for write to read-only export Eric Blake
2016-04-06 3:35 ` [Qemu-devel] [PATCH 2/3] nbd: Avoid bitrot in TRACE() usage Eric Blake
@ 2016-04-06 3:35 ` Eric Blake
2 siblings, 0 replies; 4+ messages in thread
From: Eric Blake @ 2016-04-06 3:35 UTC (permalink / raw)
To: qemu-devel; +Cc: pbonzini
Print debug tracing messages while data is still in native
ordering, rather than after we've potentially swapped it into
network order for transmission. Also, it's nice if the server
mentions what it is replying, to correlate it to with what the
client says it is receiving.
Signed-off-by: Eric Blake <eblake@redhat.com>
---
nbd/client.c | 8 ++++----
nbd/server.c | 5 +++--
2 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/nbd/client.c b/nbd/client.c
index 6f0541d..602768e 100644
--- a/nbd/client.c
+++ b/nbd/client.c
@@ -629,16 +629,16 @@ ssize_t nbd_send_request(QIOChannel *ioc, struct nbd_request *request)
uint8_t buf[NBD_REQUEST_SIZE];
ssize_t ret;
+ TRACE("Sending request to server: "
+ "{ .from = %" PRIu64", .len = %u, .handle = %" PRIu64", .type=%i}",
+ request->from, request->len, request->handle, request->type);
+
cpu_to_be32w((uint32_t*)buf, NBD_REQUEST_MAGIC);
cpu_to_be32w((uint32_t*)(buf + 4), request->type);
cpu_to_be64w((uint64_t*)(buf + 8), request->handle);
cpu_to_be64w((uint64_t*)(buf + 16), request->from);
cpu_to_be32w((uint32_t*)(buf + 24), request->len);
- TRACE("Sending request to server: "
- "{ .from = %" PRIu64", .len = %u, .handle = %" PRIu64", .type=%i}",
- request->from, request->len, request->handle, request->type);
-
ret = write_sync(ioc, buf, sizeof(buf));
if (ret < 0) {
return ret;
diff --git a/nbd/server.c b/nbd/server.c
index 98e3957..6d9c15a 100644
--- a/nbd/server.c
+++ b/nbd/server.c
@@ -656,6 +656,9 @@ static ssize_t nbd_send_reply(QIOChannel *ioc, struct nbd_reply *reply)
reply->error = system_errno_to_nbd_errno(reply->error);
+ TRACE("Sending response to client: { .error = %d, handle = %" PRIu64 " }",
+ reply->error, reply->handle);
+
/* Reply
[ 0 .. 3] magic (NBD_REPLY_MAGIC)
[ 4 .. 7] error (0 == no error)
@@ -665,8 +668,6 @@ static ssize_t nbd_send_reply(QIOChannel *ioc, struct nbd_reply *reply)
stl_be_p(buf + 4, reply->error);
stq_be_p(buf + 8, reply->handle);
- TRACE("Sending response to client");
-
ret = write_sync(ioc, buf, sizeof(buf));
if (ret < 0) {
return ret;
--
2.5.5
^ permalink raw reply related [flat|nested] 4+ messages in thread