thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

Blame SOURCES/kvm-block-ssh-Convert-from-DPRINTF-macro-to-trace-events.patch

4ec855
From f087aa3581b13254e4de34784631f1852a9ddbec Mon Sep 17 00:00:00 2001
4ec855
From: Pino Toscano <ptoscano@redhat.com>
4ec855
Date: Mon, 8 Jul 2019 15:25:52 +0100
4ec855
Subject: [PATCH 06/39] block/ssh: Convert from DPRINTF() macro to trace events
4ec855
MIME-Version: 1.0
4ec855
Content-Type: text/plain; charset=UTF-8
4ec855
Content-Transfer-Encoding: 8bit
4ec855
4ec855
RH-Author: Pino Toscano <ptoscano@redhat.com>
4ec855
Message-id: <20190708152601.21123-2-ptoscano@redhat.com>
4ec855
Patchwork-id: 89415
4ec855
O-Subject: [RHEL-8.1.0 qemu-kvm PATCH v3 01/10] block/ssh: Convert from DPRINTF() macro to trace events
4ec855
Bugzilla: 1513367
4ec855
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
4ec855
RH-Acked-by: Max Reitz <mreitz@redhat.com>
4ec855
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
4ec855
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
4ec855
4ec855
From: Laurent Vivier <lvivier@redhat.com>
4ec855
4ec855
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
4ec855
Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
4ec855
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
4ec855
Message-id: 20181213162727.17438-2-lvivier@redhat.com
4ec855
[mreitz: Fixed type of ssh_{read,write}_return's parameter to be ssize_t
4ec855
         instead of size_t]
4ec855
Signed-off-by: Max Reitz <mreitz@redhat.com>
4ec855
(cherry picked from commit 023908a24de4f264dbcd22352e8a304424005bd4)
4ec855
Signed-off-by: Pino Toscano <ptoscano@redhat.com>
4ec855
4ec855
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
4ec855
---
4ec855
 block/ssh.c        | 46 +++++++++++++++++-----------------------------
4ec855
 block/trace-events | 17 +++++++++++++++++
4ec855
 2 files changed, 34 insertions(+), 29 deletions(-)
4ec855
4ec855
diff --git a/block/ssh.c b/block/ssh.c
4ec855
index 6a55d82..dfb3e3c 100644
4ec855
--- a/block/ssh.c
4ec855
+++ b/block/ssh.c
4ec855
@@ -41,27 +41,17 @@
4ec855
 #include "qapi/qmp/qstring.h"
4ec855
 #include "qapi/qobject-input-visitor.h"
4ec855
 #include "qapi/qobject-output-visitor.h"
4ec855
+#include "trace.h"
4ec855
 
4ec855
-/* DEBUG_SSH=1 enables the DPRINTF (debugging printf) statements in
4ec855
- * this block driver code.
4ec855
- *
4ec855
+/*
4ec855
  * TRACE_LIBSSH2=<bitmask> enables tracing in libssh2 itself.  Note
4ec855
  * that this requires that libssh2 was specially compiled with the
4ec855
  * `./configure --enable-debug' option, so most likely you will have
4ec855
  * to compile it yourself.  The meaning of <bitmask> is described
4ec855
  * here: http://www.libssh2.org/libssh2_trace.html
4ec855
  */
4ec855
-#define DEBUG_SSH     0
4ec855
 #define TRACE_LIBSSH2 0 /* or try: LIBSSH2_TRACE_SFTP */
4ec855
 
4ec855
-#define DPRINTF(fmt, ...)                           \
4ec855
-    do {                                            \
4ec855
-        if (DEBUG_SSH) {                            \
4ec855
-            fprintf(stderr, "ssh: %-15s " fmt "\n", \
4ec855
-                    __func__, ##__VA_ARGS__);       \
4ec855
-        }                                           \
4ec855
-    } while (0)
4ec855
-
4ec855
 typedef struct BDRVSSHState {
4ec855
     /* Coroutine. */
4ec855
     CoMutex lock;
4ec855
@@ -336,7 +326,7 @@ static int check_host_key_knownhosts(BDRVSSHState *s,
4ec855
     switch (r) {
4ec855
     case LIBSSH2_KNOWNHOST_CHECK_MATCH:
4ec855
         /* OK */
4ec855
-        DPRINTF("host key OK: %s", found->key);
4ec855
+        trace_ssh_check_host_key_knownhosts(found->key);
4ec855
         break;
4ec855
     case LIBSSH2_KNOWNHOST_CHECK_MISMATCH:
4ec855
         ret = -EINVAL;
4ec855
@@ -721,8 +711,7 @@ static int connect_to_ssh(BDRVSSHState *s, BlockdevOptionsSsh *opts,
4ec855
     }
4ec855
 
4ec855
     /* Open the remote file. */
4ec855
-    DPRINTF("opening file %s flags=0x%x creat_mode=0%o",
4ec855
-            opts->path, ssh_flags, creat_mode);
4ec855
+    trace_ssh_connect_to_ssh(opts->path, ssh_flags, creat_mode);
4ec855
     s->sftp_handle = libssh2_sftp_open(s->sftp, opts->path, ssh_flags,
4ec855
                                        creat_mode);
4ec855
     if (!s->sftp_handle) {
4ec855
@@ -890,7 +879,7 @@ static int coroutine_fn ssh_co_create_opts(const char *filename, QemuOpts *opts,
4ec855
     /* Get desired file size. */
4ec855
     ssh_opts->size = ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0),
4ec855
                               BDRV_SECTOR_SIZE);
4ec855
-    DPRINTF("total_size=%" PRIi64, ssh_opts->size);
4ec855
+    trace_ssh_co_create_opts(ssh_opts->size);
4ec855
 
4ec855
     uri_options = qdict_new();
4ec855
     ret = parse_uri(filename, uri_options, errp);
4ec855
@@ -946,7 +935,7 @@ static void restart_coroutine(void *opaque)
4ec855
     BDRVSSHState *s = bs->opaque;
4ec855
     AioContext *ctx = bdrv_get_aio_context(bs);
4ec855
 
4ec855
-    DPRINTF("co=%p", restart->co);
4ec855
+    trace_ssh_restart_coroutine(restart->co);
4ec855
     aio_set_fd_handler(ctx, s->sock, false, NULL, NULL, NULL, NULL);
4ec855
 
4ec855
     aio_co_wake(restart->co);
4ec855
@@ -974,13 +963,12 @@ static coroutine_fn void co_yield(BDRVSSHState *s, BlockDriverState *bs)
4ec855
         wr_handler = restart_coroutine;
4ec855
     }
4ec855
 
4ec855
-    DPRINTF("s->sock=%d rd_handler=%p wr_handler=%p", s->sock,
4ec855
-            rd_handler, wr_handler);
4ec855
+    trace_ssh_co_yield(s->sock, rd_handler, wr_handler);
4ec855
 
4ec855
     aio_set_fd_handler(bdrv_get_aio_context(bs), s->sock,
4ec855
                        false, rd_handler, wr_handler, NULL, &restart);
4ec855
     qemu_coroutine_yield();
4ec855
-    DPRINTF("s->sock=%d - back", s->sock);
4ec855
+    trace_ssh_co_yield_back(s->sock);
4ec855
 }
4ec855
 
4ec855
 /* SFTP has a function `libssh2_sftp_seek64' which seeks to a position
4ec855
@@ -1003,7 +991,7 @@ static void ssh_seek(BDRVSSHState *s, int64_t offset, int flags)
4ec855
     bool force = (flags & SSH_SEEK_FORCE) != 0;
4ec855
 
4ec855
     if (force || op_read != s->offset_op_read || offset != s->offset) {
4ec855
-        DPRINTF("seeking to offset=%" PRIi64, offset);
4ec855
+        trace_ssh_seek(offset);
4ec855
         libssh2_sftp_seek64(s->sftp_handle, offset);
4ec855
         s->offset = offset;
4ec855
         s->offset_op_read = op_read;
4ec855
@@ -1019,7 +1007,7 @@ static coroutine_fn int ssh_read(BDRVSSHState *s, BlockDriverState *bs,
4ec855
     char *buf, *end_of_vec;
4ec855
     struct iovec *i;
4ec855
 
4ec855
-    DPRINTF("offset=%" PRIi64 " size=%zu", offset, size);
4ec855
+    trace_ssh_read(offset, size);
4ec855
 
4ec855
     ssh_seek(s, offset, SSH_SEEK_READ);
4ec855
 
4ec855
@@ -1038,9 +1026,9 @@ static coroutine_fn int ssh_read(BDRVSSHState *s, BlockDriverState *bs,
4ec855
      */
4ec855
     for (got = 0; got < size; ) {
4ec855
     again:
4ec855
-        DPRINTF("sftp_read buf=%p size=%zu", buf, end_of_vec - buf);
4ec855
+        trace_ssh_read_buf(buf, end_of_vec - buf);
4ec855
         r = libssh2_sftp_read(s->sftp_handle, buf, end_of_vec - buf);
4ec855
-        DPRINTF("sftp_read returned %zd", r);
4ec855
+        trace_ssh_read_return(r);
4ec855
 
4ec855
         if (r == LIBSSH2_ERROR_EAGAIN || r == LIBSSH2_ERROR_TIMEOUT) {
4ec855
             co_yield(s, bs);
4ec855
@@ -1094,7 +1082,7 @@ static int ssh_write(BDRVSSHState *s, BlockDriverState *bs,
4ec855
     char *buf, *end_of_vec;
4ec855
     struct iovec *i;
4ec855
 
4ec855
-    DPRINTF("offset=%" PRIi64 " size=%zu", offset, size);
4ec855
+    trace_ssh_write(offset, size);
4ec855
 
4ec855
     ssh_seek(s, offset, SSH_SEEK_WRITE);
4ec855
 
4ec855
@@ -1108,9 +1096,9 @@ static int ssh_write(BDRVSSHState *s, BlockDriverState *bs,
4ec855
 
4ec855
     for (written = 0; written < size; ) {
4ec855
     again:
4ec855
-        DPRINTF("sftp_write buf=%p size=%zu", buf, end_of_vec - buf);
4ec855
+        trace_ssh_write_buf(buf, end_of_vec - buf);
4ec855
         r = libssh2_sftp_write(s->sftp_handle, buf, end_of_vec - buf);
4ec855
-        DPRINTF("sftp_write returned %zd", r);
4ec855
+        trace_ssh_write_return(r);
4ec855
 
4ec855
         if (r == LIBSSH2_ERROR_EAGAIN || r == LIBSSH2_ERROR_TIMEOUT) {
4ec855
             co_yield(s, bs);
4ec855
@@ -1185,7 +1173,7 @@ static coroutine_fn int ssh_flush(BDRVSSHState *s, BlockDriverState *bs)
4ec855
 {
4ec855
     int r;
4ec855
 
4ec855
-    DPRINTF("fsync");
4ec855
+    trace_ssh_flush();
4ec855
  again:
4ec855
     r = libssh2_sftp_fsync(s->sftp_handle);
4ec855
     if (r == LIBSSH2_ERROR_EAGAIN || r == LIBSSH2_ERROR_TIMEOUT) {
4ec855
@@ -1236,7 +1224,7 @@ static int64_t ssh_getlength(BlockDriverState *bs)
4ec855
 
4ec855
     /* Note we cannot make a libssh2 call here. */
4ec855
     length = (int64_t) s->attrs.filesize;
4ec855
-    DPRINTF("length=%" PRIi64, length);
4ec855
+    trace_ssh_getlength(length);
4ec855
 
4ec855
     return length;
4ec855
 }
4ec855
diff --git a/block/trace-events b/block/trace-events
4ec855
index c35287b..4c69548 100644
4ec855
--- a/block/trace-events
4ec855
+++ b/block/trace-events
4ec855
@@ -150,3 +150,20 @@ nvme_free_req_queue_wait(void *q) "q %p"
4ec855
 nvme_cmd_map_qiov(void *s, void *cmd, void *req, void *qiov, int entries) "s %p cmd %p req %p qiov %p entries %d"
4ec855
 nvme_cmd_map_qiov_pages(void *s, int i, uint64_t page) "s %p page[%d] 0x%"PRIx64
4ec855
 nvme_cmd_map_qiov_iov(void *s, int i, void *page, int pages) "s %p iov[%d] %p pages %d"
4ec855
+
4ec855
+# block/ssh.c
4ec855
+ssh_restart_coroutine(void *co) "co=%p"
4ec855
+ssh_flush(void) "fsync"
4ec855
+ssh_check_host_key_knownhosts(const char *key) "host key OK: %s"
4ec855
+ssh_connect_to_ssh(char *path, int flags, int mode) "opening file %s flags=0x%x creat_mode=0%o"
4ec855
+ssh_co_yield(int sock, void *rd_handler, void *wr_handler) "s->sock=%d rd_handler=%p wr_handler=%p"
4ec855
+ssh_co_yield_back(int sock) "s->sock=%d - back"
4ec855
+ssh_getlength(int64_t length) "length=%" PRIi64
4ec855
+ssh_co_create_opts(uint64_t size) "total_size=%" PRIu64
4ec855
+ssh_read(int64_t offset, size_t size) "offset=%" PRIi64 " size=%zu"
4ec855
+ssh_read_buf(void *buf, size_t size) "sftp_read buf=%p size=%zu"
4ec855
+ssh_read_return(ssize_t ret) "sftp_read returned %zd"
4ec855
+ssh_write(int64_t offset, size_t size) "offset=%" PRIi64 " size=%zu"
4ec855
+ssh_write_buf(void *buf, size_t size) "sftp_write buf=%p size=%zu"
4ec855
+ssh_write_return(ssize_t ret) "sftp_write returned %zd"
4ec855
+ssh_seek(int64_t offset) "seeking to offset=%" PRIi64
4ec855
-- 
4ec855
1.8.3.1
4ec855