From patchwork Wed Dec 12 19:40:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 1012219 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43FS3M3qFrz9s2P for ; Thu, 13 Dec 2018 06:45:51 +1100 (AEDT) Received: from localhost ([::1]:47686 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gXAS5-0001ri-2m for incoming@patchwork.ozlabs.org; Wed, 12 Dec 2018 14:45:49 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47368) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gXAMy-0005cT-1d for qemu-devel@nongnu.org; Wed, 12 Dec 2018 14:40:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gXAMv-0007kb-D3 for qemu-devel@nongnu.org; Wed, 12 Dec 2018 14:40:31 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44274) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gXAMp-0007bZ-RV; Wed, 12 Dec 2018 14:40:24 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1778180F98; Wed, 12 Dec 2018 19:40:16 +0000 (UTC) Received: from thinkpad.redhat.com (ovpn-204-190.brq.redhat.com [10.40.204.190]) by smtp.corp.redhat.com (Postfix) with ESMTP id 52C77608C6; Wed, 12 Dec 2018 19:40:13 +0000 (UTC) From: Laurent Vivier To: qemu-devel@nongnu.org Date: Wed, 12 Dec 2018 20:40:06 +0100 Message-Id: <20181212194009.2951-2-lvivier@redhat.com> In-Reply-To: <20181212194009.2951-1-lvivier@redhat.com> References: <20181212194009.2951-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 12 Dec 2018 19:40:16 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 1/4] block/ssh: Convert from DPRINTF() macro to trace events X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Laurent Vivier , qemu-block@nongnu.org, qemu-trivial@nongnu.org, "Richard W.M. Jones" , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Liu Yuan , Max Reitz Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Laurent Vivier Reviewed-by: Richard W.M. Jones Reviewed-by: Philippe Mathieu-Daudé --- block/ssh.c | 46 +++++++++++++++++----------------------------- block/trace-events | 17 +++++++++++++++++ 2 files changed, 34 insertions(+), 29 deletions(-) diff --git a/block/ssh.c b/block/ssh.c index 7fbc27abdf..bbc513e095 100644 --- a/block/ssh.c +++ b/block/ssh.c @@ -41,27 +41,17 @@ #include "qapi/qmp/qstring.h" #include "qapi/qobject-input-visitor.h" #include "qapi/qobject-output-visitor.h" +#include "trace.h" -/* DEBUG_SSH=1 enables the DPRINTF (debugging printf) statements in - * this block driver code. - * +/* * TRACE_LIBSSH2= enables tracing in libssh2 itself. Note * that this requires that libssh2 was specially compiled with the * `./configure --enable-debug' option, so most likely you will have * to compile it yourself. The meaning of is described * here: http://www.libssh2.org/libssh2_trace.html */ -#define DEBUG_SSH 0 #define TRACE_LIBSSH2 0 /* or try: LIBSSH2_TRACE_SFTP */ -#define DPRINTF(fmt, ...) \ - do { \ - if (DEBUG_SSH) { \ - fprintf(stderr, "ssh: %-15s " fmt "\n", \ - __func__, ##__VA_ARGS__); \ - } \ - } while (0) - typedef struct BDRVSSHState { /* Coroutine. */ CoMutex lock; @@ -336,7 +326,7 @@ static int check_host_key_knownhosts(BDRVSSHState *s, switch (r) { case LIBSSH2_KNOWNHOST_CHECK_MATCH: /* OK */ - DPRINTF("host key OK: %s", found->key); + trace_ssh_check_host_key_knownhosts(found->key); break; case LIBSSH2_KNOWNHOST_CHECK_MISMATCH: ret = -EINVAL; @@ -721,8 +711,7 @@ static int connect_to_ssh(BDRVSSHState *s, BlockdevOptionsSsh *opts, } /* Open the remote file. */ - DPRINTF("opening file %s flags=0x%x creat_mode=0%o", - opts->path, ssh_flags, creat_mode); + trace_ssh_connect_to_ssh(opts->path, ssh_flags, creat_mode); s->sftp_handle = libssh2_sftp_open(s->sftp, opts->path, ssh_flags, creat_mode); if (!s->sftp_handle) { @@ -890,7 +879,7 @@ static int coroutine_fn ssh_co_create_opts(const char *filename, QemuOpts *opts, /* Get desired file size. */ ssh_opts->size = ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0), BDRV_SECTOR_SIZE); - DPRINTF("total_size=%" PRIi64, ssh_opts->size); + trace_ssh_co_create_opts(ssh_opts->size); uri_options = qdict_new(); ret = parse_uri(filename, uri_options, errp); @@ -946,7 +935,7 @@ static void restart_coroutine(void *opaque) BDRVSSHState *s = bs->opaque; AioContext *ctx = bdrv_get_aio_context(bs); - DPRINTF("co=%p", restart->co); + trace_ssh_restart_coroutine(restart->co); aio_set_fd_handler(ctx, s->sock, false, NULL, NULL, NULL, NULL); aio_co_wake(restart->co); @@ -974,13 +963,12 @@ static coroutine_fn void co_yield(BDRVSSHState *s, BlockDriverState *bs) wr_handler = restart_coroutine; } - DPRINTF("s->sock=%d rd_handler=%p wr_handler=%p", s->sock, - rd_handler, wr_handler); + trace_ssh_co_yield(s->sock, rd_handler, wr_handler); aio_set_fd_handler(bdrv_get_aio_context(bs), s->sock, false, rd_handler, wr_handler, NULL, &restart); qemu_coroutine_yield(); - DPRINTF("s->sock=%d - back", s->sock); + trace_ssh_co_yield_back(s->sock); } /* SFTP has a function `libssh2_sftp_seek64' which seeks to a position @@ -1003,7 +991,7 @@ static void ssh_seek(BDRVSSHState *s, int64_t offset, int flags) bool force = (flags & SSH_SEEK_FORCE) != 0; if (force || op_read != s->offset_op_read || offset != s->offset) { - DPRINTF("seeking to offset=%" PRIi64, offset); + trace_ssh_seek(offset); libssh2_sftp_seek64(s->sftp_handle, offset); s->offset = offset; s->offset_op_read = op_read; @@ -1019,7 +1007,7 @@ static coroutine_fn int ssh_read(BDRVSSHState *s, BlockDriverState *bs, char *buf, *end_of_vec; struct iovec *i; - DPRINTF("offset=%" PRIi64 " size=%zu", offset, size); + trace_ssh_read(offset, size); ssh_seek(s, offset, SSH_SEEK_READ); @@ -1038,9 +1026,9 @@ static coroutine_fn int ssh_read(BDRVSSHState *s, BlockDriverState *bs, */ for (got = 0; got < size; ) { again: - DPRINTF("sftp_read buf=%p size=%zu", buf, end_of_vec - buf); + trace_ssh_read_buf(buf, end_of_vec - buf); r = libssh2_sftp_read(s->sftp_handle, buf, end_of_vec - buf); - DPRINTF("sftp_read returned %zd", r); + trace_ssh_read_return(r); if (r == LIBSSH2_ERROR_EAGAIN || r == LIBSSH2_ERROR_TIMEOUT) { co_yield(s, bs); @@ -1094,7 +1082,7 @@ static int ssh_write(BDRVSSHState *s, BlockDriverState *bs, char *buf, *end_of_vec; struct iovec *i; - DPRINTF("offset=%" PRIi64 " size=%zu", offset, size); + trace_ssh_write(offset, size); ssh_seek(s, offset, SSH_SEEK_WRITE); @@ -1108,9 +1096,9 @@ static int ssh_write(BDRVSSHState *s, BlockDriverState *bs, for (written = 0; written < size; ) { again: - DPRINTF("sftp_write buf=%p size=%zu", buf, end_of_vec - buf); + trace_ssh_write_buf(buf, end_of_vec - buf); r = libssh2_sftp_write(s->sftp_handle, buf, end_of_vec - buf); - DPRINTF("sftp_write returned %zd", r); + trace_ssh_write_return(r); if (r == LIBSSH2_ERROR_EAGAIN || r == LIBSSH2_ERROR_TIMEOUT) { co_yield(s, bs); @@ -1187,7 +1175,7 @@ static coroutine_fn int ssh_flush(BDRVSSHState *s, BlockDriverState *bs) { int r; - DPRINTF("fsync"); + trace_ssh_flush(); again: r = libssh2_sftp_fsync(s->sftp_handle); if (r == LIBSSH2_ERROR_EAGAIN || r == LIBSSH2_ERROR_TIMEOUT) { @@ -1238,7 +1226,7 @@ static int64_t ssh_getlength(BlockDriverState *bs) /* Note we cannot make a libssh2 call here. */ length = (int64_t) s->attrs.filesize; - DPRINTF("length=%" PRIi64, length); + trace_ssh_getlength(length); return length; } diff --git a/block/trace-events b/block/trace-events index 3e8c47bb24..b13b1e9706 100644 --- a/block/trace-events +++ b/block/trace-events @@ -156,3 +156,20 @@ nvme_cmd_map_qiov_iov(void *s, int i, void *page, int pages) "s %p iov[%d] %p pa # block/iscsi.c iscsi_xcopy(void *src_lun, uint64_t src_off, void *dst_lun, uint64_t dst_off, uint64_t bytes, int ret) "src_lun %p offset %"PRIu64" dst_lun %p offset %"PRIu64" bytes %"PRIu64" ret %d" + +# block/ssh.c +ssh_restart_coroutine(void *co) "co=%p" +ssh_flush(void) "fsync" +ssh_check_host_key_knownhosts(const char *key) "host key OK: %s" +ssh_connect_to_ssh(char *path, int flags, int mode) "opening file %s flags=0x%x creat_mode=0%o" +ssh_co_yield(int sock, void *rd_handler, void *wr_handler) "s->sock=%d rd_handler=%p wr_handler=%p" +ssh_co_yield_back(int sock) "s->sock=%d - back" +ssh_getlength(int64_t length) "length=%" PRIi64 +ssh_co_create_opts(uint64_t size) "total_size=%" PRIu64 +ssh_read(int64_t offset, size_t size) "offset=%" PRIi64 " size=%zu" +ssh_read_buf(void *buf, size_t size) "sftp_read buf=%p size=%zu" +ssh_read_return(size_t ret) "sftp_read returned %zd" +ssh_write(int64_t offset, size_t size) "offset=%" PRIi64 " size=%zu" +ssh_write_buf(void *buf, size_t size) "sftp_write buf=%p size=%zu" +ssh_write_return(size_t ret) "sftp_write returned %zd" +ssh_seek(uint64_t offset) "seeking to offset=%" PRIi64