From nobody Sun Oct 5 21:10:49 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499689336175431.1804672958709; Mon, 10 Jul 2017 05:22:16 -0700 (PDT) Received: from localhost ([::1]:40508 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUXhd-0007Z8-Jl for importer@patchew.org; Mon, 10 Jul 2017 08:22:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54871) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUXan-0001wK-53 for qemu-devel@nongnu.org; Mon, 10 Jul 2017 08:15:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dUXak-0002lk-6s for qemu-devel@nongnu.org; Mon, 10 Jul 2017 08:15:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54156) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dUXab-0002gN-Ns; Mon, 10 Jul 2017 08:14:58 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B49F881127; Mon, 10 Jul 2017 12:14:56 +0000 (UTC) Received: from red.redhat.com (ovpn-121-60.rdu2.redhat.com [10.10.121.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id DCE477EBEC; Mon, 10 Jul 2017 12:14:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B49F881127 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com B49F881127 From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 10 Jul 2017 07:14:34 -0500 Message-Id: <20170710121434.5047-12-eblake@redhat.com> In-Reply-To: <20170710121434.5047-1-eblake@redhat.com> References: <20170710121434.5047-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 10 Jul 2017 12:14:56 +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] [PULL 11/11] nbd: use generic trace subsystem instead of TRACE macro 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: Paolo Bonzini , Vladimir Sementsov-Ogievskiy , "open list:Network Block Dev..." Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Let NBD use the trace mechanisms already present in qemu. Now you can use the -trace optino of qemu, or the -T/--trace option of qemu-img, qemu-io, and qemu-nbd, to select nbd traces. For qemu, the QMP commands trace-event-{get,set}-state can also toggle tracing on the fly. Example: qemu-nbd --trace 'nbd_*' # enables all nbd traces Recompilation with CFLAGS=3D-DDEBUG_NBD is no more needed, furthermore, DEBUG_NBD macro is removed from the code. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20170707152918.23086-11-vsementsov@virtuozzo.com> [eblake: minor tweaks to a couple of traces] Signed-off-by: Eric Blake --- nbd/nbd-internal.h | 19 --------------- nbd/client.c | 69 +++++++++++++++++++++++---------------------------= --- nbd/server.c | 70 +++++++++++++++++++++++++-------------------------= ---- Makefile.objs | 1 + nbd/trace-events | 56 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 120 insertions(+), 95 deletions(-) create mode 100644 nbd/trace-events diff --git a/nbd/nbd-internal.h b/nbd/nbd-internal.h index 39bfed1..cf6ecbf 100644 --- a/nbd/nbd-internal.h +++ b/nbd/nbd-internal.h @@ -31,25 +31,6 @@ #include "qemu/queue.h" #include "qemu/main-loop.h" -/* #define DEBUG_NBD */ - -#ifdef DEBUG_NBD -#define DEBUG_NBD_PRINT 1 -#else -#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) - /* This is all part of the "official" NBD API. * * The most up-to-date documentation is available at: diff --git a/nbd/client.c b/nbd/client.c index 1ae4ff8..9c52b9b 100644 --- a/nbd/client.c +++ b/nbd/client.c @@ -19,6 +19,7 @@ #include "qemu/osdep.h" #include "qapi/error.h" +#include "trace.h" #include "nbd-internal.h" static int nbd_errno_to_system_errno(int err) @@ -44,7 +45,7 @@ static int nbd_errno_to_system_errno(int err) ret =3D ESHUTDOWN; break; default: - TRACE("Squashing unexpected error %d to EINVAL", err); + trace_nbd_unknown_error(err); /* fallthrough */ case NBD_EINVAL: ret =3D EINVAL; @@ -103,7 +104,7 @@ static int nbd_send_option_request(QIOChannel *ioc, uin= t32_t opt, if (len =3D=3D -1) { req.length =3D len =3D strlen(data); } - TRACE("Sending option request %" PRIu32", len %" PRIu32, opt, len); + trace_nbd_send_option_request(opt, len); stq_be_p(&req.magic, NBD_OPTS_MAGIC); stl_be_p(&req.option, opt); @@ -153,8 +154,7 @@ static int nbd_receive_option_reply(QIOChannel *ioc, ui= nt32_t opt, be32_to_cpus(&reply->type); be32_to_cpus(&reply->length); - TRACE("Received option reply %" PRIx32", type %" PRIx32", len %" PRIu3= 2, - reply->option, reply->type, reply->length); + trace_nbd_receive_option_reply(reply->option, reply->type, reply->leng= th); if (reply->magic !=3D NBD_REP_MAGIC) { error_setg(errp, "Unexpected option reply magic"); @@ -201,8 +201,7 @@ static int nbd_handle_reply_err(QIOChannel *ioc, nbd_op= t_reply *reply, switch (reply->type) { case NBD_REP_ERR_UNSUP: - TRACE("server doesn't understand request %" PRIx32 - ", attempting fallback", reply->option); + trace_nbd_reply_err_unsup(reply->option); result =3D 0; goto cleanup; @@ -342,12 +341,11 @@ static int nbd_receive_query_exports(QIOChannel *ioc, { bool foundExport =3D false; - TRACE("Querying export list for '%s'", wantname); + trace_nbd_receive_query_exports_start(wantname); if (nbd_send_option_request(ioc, NBD_OPT_LIST, 0, NULL, errp) < 0) { return -1; } - TRACE("Reading available export names"); while (1) { int ret =3D nbd_receive_list(ioc, wantname, &foundExport, errp); @@ -362,7 +360,7 @@ static int nbd_receive_query_exports(QIOChannel *ioc, nbd_send_opt_abort(ioc); return -1; } - TRACE("Found desired export name '%s'", wantname); + trace_nbd_receive_query_exports_success(wantname); return 0; } } @@ -376,12 +374,12 @@ static QIOChannel *nbd_receive_starttls(QIOChannel *i= oc, QIOChannelTLS *tioc; struct NBDTLSHandshakeData data =3D { 0 }; - TRACE("Requesting TLS from server"); + trace_nbd_receive_starttls_request(); if (nbd_send_option_request(ioc, NBD_OPT_STARTTLS, 0, NULL, errp) < 0)= { return NULL; } - TRACE("Getting TLS reply from server"); + trace_nbd_receive_starttls_reply(); if (nbd_receive_option_reply(ioc, NBD_OPT_STARTTLS, &reply, errp) < 0)= { return NULL; } @@ -400,14 +398,14 @@ static QIOChannel *nbd_receive_starttls(QIOChannel *i= oc, return NULL; } - TRACE("TLS request approved, setting up TLS"); + trace_nbd_receive_starttls_new_client(); tioc =3D qio_channel_tls_new_client(ioc, tlscreds, hostname, errp); if (!tioc) { return NULL; } qio_channel_set_name(QIO_CHANNEL(tioc), "nbd-client-tls"); data.loop =3D g_main_loop_new(g_main_context_default(), FALSE); - TRACE("Starting TLS handshake"); + trace_nbd_receive_starttls_tls_handshake(); qio_channel_tls_handshake(tioc, nbd_tls_handshake, &data, @@ -437,8 +435,7 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char *= name, uint16_t *flags, int rc; bool zeroes =3D true; - TRACE("Receiving negotiation tlscreds=3D%p hostname=3D%s.", - tlscreds, hostname ? hostname : ""); + trace_nbd_receive_negotiate(tlscreds, hostname ? hostname : ""); rc =3D -EINVAL; @@ -462,7 +459,7 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char *= name, uint16_t *flags, } magic =3D ldq_be_p(buf); - TRACE("Magic is 0x%" PRIx64, magic); + trace_nbd_receive_negotiate_magic(magic); if (memcmp(buf, "NBDMAGIC", 8) !=3D 0) { error_setg(errp, "Invalid magic received"); @@ -474,7 +471,7 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char *= name, uint16_t *flags, goto fail; } magic =3D be64_to_cpu(magic); - TRACE("Magic is 0x%" PRIx64, magic); + trace_nbd_receive_negotiate_magic(magic); if (magic =3D=3D NBD_OPTS_MAGIC) { uint32_t clientflags =3D 0; @@ -486,7 +483,7 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char *= name, uint16_t *flags, goto fail; } globalflags =3D be16_to_cpu(globalflags); - TRACE("Global flags are %" PRIx32, globalflags); + trace_nbd_receive_negotiate_server_flags(globalflags); if (globalflags & NBD_FLAG_FIXED_NEWSTYLE) { fixedNewStyle =3D true; clientflags |=3D NBD_FLAG_C_FIXED_NEWSTYLE; @@ -514,7 +511,7 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char *= name, uint16_t *flags, } } if (!name) { - TRACE("Using default NBD export name \"\""); + trace_nbd_receive_negotiate_default_name(); name =3D ""; } if (fixedNewStyle) { @@ -579,7 +576,7 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char *= name, uint16_t *flags, goto fail; } - TRACE("Size is %" PRIu64 ", export flags %" PRIx16, *size, *flags); + trace_nbd_receive_negotiate_size_flags(*size, *flags); if (zeroes && nbd_drop(ioc, 124, errp) < 0) { error_prepend(errp, "Failed to read reserved block"); goto fail; @@ -601,7 +598,7 @@ int nbd_init(int fd, QIOChannelSocket *sioc, uint16_t f= lags, off_t size, return -E2BIG; } - TRACE("Setting NBD socket"); + trace_nbd_init_set_socket(); if (ioctl(fd, NBD_SET_SOCK, (unsigned long) sioc->fd) < 0) { int serrno =3D errno; @@ -609,7 +606,7 @@ int nbd_init(int fd, QIOChannelSocket *sioc, uint16_t f= lags, off_t size, return -serrno; } - TRACE("Setting block size to %lu", (unsigned long)BDRV_SECTOR_SIZE); + trace_nbd_init_set_block_size(BDRV_SECTOR_SIZE); if (ioctl(fd, NBD_SET_BLKSIZE, (unsigned long)BDRV_SECTOR_SIZE) < 0) { int serrno =3D errno; @@ -617,10 +614,9 @@ int nbd_init(int fd, QIOChannelSocket *sioc, uint16_t = flags, off_t size, return -serrno; } - TRACE("Setting size to %lu block(s)", sectors); + trace_nbd_init_set_size(sectors); if (size % BDRV_SECTOR_SIZE) { - TRACE("Ignoring trailing %d bytes of export", - (int) (size % BDRV_SECTOR_SIZE)); + trace_nbd_init_trailing_bytes(size % BDRV_SECTOR_SIZE); } if (ioctl(fd, NBD_SET_SIZE_BLOCKS, sectors) < 0) { @@ -632,7 +628,7 @@ int nbd_init(int fd, QIOChannelSocket *sioc, uint16_t f= lags, off_t size, if (ioctl(fd, NBD_SET_FLAGS, (unsigned long) flags) < 0) { if (errno =3D=3D ENOTTY) { int read_only =3D (flags & NBD_FLAG_READ_ONLY) !=3D 0; - TRACE("Setting readonly attribute"); + trace_nbd_init_set_readonly(); if (ioctl(fd, BLKROSET, (unsigned long) &read_only) < 0) { int serrno =3D errno; @@ -646,7 +642,7 @@ int nbd_init(int fd, QIOChannelSocket *sioc, uint16_t f= lags, off_t size, } } - TRACE("Negotiation ended"); + trace_nbd_init_finish(); return 0; } @@ -656,7 +652,7 @@ int nbd_client(int fd) int ret; int serrno; - TRACE("Doing NBD loop"); + trace_nbd_client_loop(); ret =3D ioctl(fd, NBD_DO_IT); if (ret < 0 && errno =3D=3D EPIPE) { @@ -668,12 +664,12 @@ int nbd_client(int fd) } serrno =3D errno; - TRACE("NBD loop returned %d: %s", ret, strerror(serrno)); + trace_nbd_client_loop_ret(ret, strerror(serrno)); - TRACE("Clearing NBD queue"); + trace_nbd_client_clear_queue(); ioctl(fd, NBD_CLEAR_QUE); - TRACE("Clearing NBD socket"); + trace_nbd_client_clear_socket(); ioctl(fd, NBD_CLEAR_SOCK); errno =3D serrno; @@ -710,11 +706,8 @@ ssize_t nbd_send_request(QIOChannel *ioc, NBDRequest *= request) { uint8_t buf[NBD_REQUEST_SIZE]; - TRACE("Sending request to server: " - "{ .from =3D %" PRIu64", .len =3D %" PRIu32 ", .handle =3D %" PR= Iu64 - ", .flags =3D %" PRIx16 ", .type =3D %" PRIu16 " }", - request->from, request->len, request->handle, - request->flags, request->type); + trace_nbd_send_request(request->from, request->len, request->handle, + request->flags, request->type); stl_be_p(buf, NBD_REQUEST_MAGIC); stw_be_p(buf + 4, request->flags); @@ -759,9 +752,7 @@ ssize_t nbd_receive_reply(QIOChannel *ioc, NBDReply *re= ply, Error **errp) error_setg(errp, "server shutting down"); return -EINVAL; } - TRACE("Got reply: { magic =3D 0x%" PRIx32 ", .error =3D % " PRId32 - ", handle =3D %" PRIu64" }", - magic, reply->error, reply->handle); + trace_nbd_receive_reply(magic, reply->error, reply->handle); if (magic !=3D NBD_REPLY_MAGIC) { error_setg(errp, "invalid magic (got 0x%" PRIx32 ")", magic); diff --git a/nbd/server.c b/nbd/server.c index 4bbce5f..9b0c588 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -19,6 +19,7 @@ #include "qemu/osdep.h" #include "qapi/error.h" +#include "trace.h" #include "nbd-internal.h" static int system_errno_to_nbd_errno(int err) @@ -138,8 +139,7 @@ static int nbd_negotiate_send_rep_len(QIOChannel *ioc, = uint32_t type, { uint64_t magic; - TRACE("Reply opt=3D%" PRIx32 " type=3D%" PRIx32 " len=3D%" PRIu32, - opt, type, len); + trace_nbd_negotiate_send_rep_len(opt, type, len); magic =3D cpu_to_be64(NBD_REP_MAGIC); if (nbd_write(ioc, &magic, sizeof(magic), errp) < 0) { @@ -191,7 +191,7 @@ nbd_negotiate_send_rep_err(QIOChannel *ioc, uint32_t ty= pe, va_end(va); len =3D strlen(msg); assert(len < 4096); - TRACE("sending error message \"%s\"", msg); + trace_nbd_negotiate_send_rep_err(msg); ret =3D nbd_negotiate_send_rep_len(ioc, type, opt, len, errp); if (ret < 0) { goto out; @@ -219,7 +219,7 @@ static int nbd_negotiate_send_rep_list(QIOChannel *ioc,= NBDExport *exp, const char *desc =3D exp->description ? exp->description : ""; int ret; - TRACE("Advertising export name '%s' description '%s'", name, desc); + trace_nbd_negotiate_send_rep_list(name, desc); name_len =3D strlen(name); desc_len =3D strlen(desc); len =3D name_len + desc_len + sizeof(len); @@ -283,7 +283,7 @@ static int nbd_negotiate_handle_export_name(NBDClient *= client, uint32_t length, /* Client sends: [20 .. xx] export name (length bytes) */ - TRACE("Checking length"); + trace_nbd_negotiate_handle_export_name(); if (length >=3D sizeof(name)) { error_setg(errp, "Bad length received"); return -EINVAL; @@ -294,7 +294,7 @@ static int nbd_negotiate_handle_export_name(NBDClient *= client, uint32_t length, } name[length] =3D '\0'; - TRACE("Client requested export '%s'", name); + trace_nbd_negotiate_handle_export_name_request(name); client->exp =3D nbd_export_find(name); if (!client->exp) { @@ -318,7 +318,7 @@ static QIOChannel *nbd_negotiate_handle_starttls(NBDCli= ent *client, QIOChannelTLS *tioc; struct NBDTLSHandshakeData data =3D { 0 }; - TRACE("Setting up TLS"); + trace_nbd_negotiate_handle_starttls(); ioc =3D client->ioc; if (length) { if (nbd_drop(ioc, length, errp) < 0) { @@ -344,7 +344,7 @@ static QIOChannel *nbd_negotiate_handle_starttls(NBDCli= ent *client, } qio_channel_set_name(QIO_CHANNEL(tioc), "nbd-server-tls"); - TRACE("Starting TLS handshake"); + trace_nbd_negotiate_handle_starttls_handshake(); data.loop =3D g_main_loop_new(g_main_context_default(), FALSE); qio_channel_tls_handshake(tioc, nbd_tls_handshake, @@ -396,15 +396,15 @@ static int nbd_negotiate_options(NBDClient *client, E= rror **errp) error_prepend(errp, "read failed: "); return -EIO; } - TRACE("Checking client flags"); + trace_nbd_negotiate_options_flags(); be32_to_cpus(&flags); if (flags & NBD_FLAG_C_FIXED_NEWSTYLE) { - TRACE("Client supports fixed newstyle handshake"); + trace_nbd_negotiate_options_newstyle(); fixedNewstyle =3D true; flags &=3D ~NBD_FLAG_C_FIXED_NEWSTYLE; } if (flags & NBD_FLAG_C_NO_ZEROES) { - TRACE("Client supports no zeroes at handshake end"); + trace_nbd_negotiate_options_no_zeroes(); client->no_zeroes =3D true; flags &=3D ~NBD_FLAG_C_NO_ZEROES; } @@ -422,8 +422,9 @@ static int nbd_negotiate_options(NBDClient *client, Err= or **errp) error_prepend(errp, "read failed: "); return -EINVAL; } - TRACE("Checking opts magic"); - if (magic !=3D be64_to_cpu(NBD_OPTS_MAGIC)) { + magic =3D be64_to_cpu(magic); + trace_nbd_negotiate_options_check_magic(magic); + if (magic !=3D NBD_OPTS_MAGIC) { error_setg(errp, "Bad magic received"); return -EINVAL; } @@ -441,7 +442,7 @@ static int nbd_negotiate_options(NBDClient *client, Err= or **errp) } length =3D be32_to_cpu(length); - TRACE("Checking option 0x%" PRIx32, option); + trace_nbd_negotiate_options_check_option(option); if (client->tlscreds && client->ioc =3D=3D (QIOChannel *)client->sioc) { QIOChannel *tioc; @@ -501,8 +502,8 @@ static int nbd_negotiate_options(NBDClient *client, Err= or **errp) &local_err); if (local_err !=3D NULL) { - TRACE("Reply to NBD_OPT_ABORT request failed: %s", - error_get_pretty(local_err)); + const char *error =3D error_get_pretty(local_err); + trace_nbd_opt_abort_reply_failed(error); error_free(local_err); } @@ -599,14 +600,14 @@ static coroutine_fn int nbd_negotiate(NBDClient *clie= nt, Error **errp) qio_channel_set_blocking(client->ioc, false, NULL); - TRACE("Beginning negotiation."); + trace_nbd_negotiate_begin(); memset(buf, 0, sizeof(buf)); memcpy(buf, "NBDMAGIC", 8); oldStyle =3D client->exp !=3D NULL && !client->tlscreds; if (oldStyle) { - TRACE("advertising size %" PRIu64 " and flags %x", - client->exp->size, client->exp->nbdflags | myflags); + trace_nbd_negotiate_old_style(client->exp->size, + client->exp->nbdflags | myflags); stq_be_p(buf + 8, NBD_CLIENT_MAGIC); stq_be_p(buf + 16, client->exp->size); stw_be_p(buf + 26, client->exp->nbdflags | myflags); @@ -631,8 +632,8 @@ static coroutine_fn int nbd_negotiate(NBDClient *client= , Error **errp) return ret; } - TRACE("advertising size %" PRIu64 " and flags %x", - client->exp->size, client->exp->nbdflags | myflags); + trace_nbd_negotiate_new_style_size_flags( + client->exp->size, client->exp->nbdflags | myflags); stq_be_p(buf + 18, client->exp->size); stw_be_p(buf + 26, client->exp->nbdflags | myflags); len =3D client->no_zeroes ? 10 : sizeof(buf) - 18; @@ -643,7 +644,7 @@ static coroutine_fn int nbd_negotiate(NBDClient *client= , Error **errp) } } - TRACE("Negotiation succeeded."); + trace_nbd_negotiate_success(); return 0; } @@ -676,9 +677,8 @@ static int nbd_receive_request(QIOChannel *ioc, NBDRequ= est *request, request->from =3D ldq_be_p(buf + 16); request->len =3D ldl_be_p(buf + 24); - TRACE("Got request: { magic =3D 0x%" PRIx32 ", .flags =3D %" PRIx16 - ", .type =3D %" PRIx16 ", from =3D %" PRIu64 ", len =3D %" PRIu3= 2 " }", - magic, request->flags, request->type, request->from, request->le= n); + trace_nbd_receive_request(magic, request->flags, request->type, + request->from, request->len); if (magic !=3D NBD_REQUEST_MAGIC) { error_setg(errp, "invalid magic (got 0x%" PRIx32 ")", magic); @@ -693,9 +693,7 @@ static int nbd_send_reply(QIOChannel *ioc, NBDReply *re= ply, Error **errp) reply->error =3D system_errno_to_nbd_errno(reply->error); - TRACE("Sending response to client: { .error =3D %" PRId32 - ", handle =3D %" PRIu64 " }", - reply->error, reply->handle); + trace_nbd_send_reply(reply->error, reply->handle); /* Reply [ 0 .. 3] magic (NBD_REPLY_MAGIC) @@ -792,7 +790,7 @@ static void blk_aio_attached(AioContext *ctx, void *opa= que) NBDExport *exp =3D opaque; NBDClient *client; - TRACE("Export %s: Attaching clients to AIO context %p\n", exp->name, c= tx); + trace_nbd_blk_aio_attached(exp->name, ctx); exp->ctx =3D ctx; @@ -812,7 +810,7 @@ static void blk_aio_detach(void *opaque) NBDExport *exp =3D opaque; NBDClient *client; - TRACE("Export %s: Detaching clients from AIO context %p\n", exp->name,= exp->ctx); + trace_nbd_blk_aio_detach(exp->name, exp->ctx); QTAILQ_FOREACH(client, &exp->clients, next) { qio_channel_detach_aio_context(client->ioc); @@ -1001,8 +999,7 @@ static int nbd_co_send_reply(NBDRequestData *req, NBDR= eply *reply, int len, g_assert(qemu_in_coroutine()); - TRACE("Send reply: handle =3D %" PRIu64 ", error =3D %" PRIu32 ", len = =3D %d", - reply->handle, reply->error, len); + trace_nbd_co_send_reply(reply->handle, reply->error, len); qemu_co_mutex_lock(&client->send_lock); client->send_coroutine =3D qemu_coroutine_self(); @@ -1043,8 +1040,7 @@ static int nbd_co_receive_request(NBDRequestData *req= , NBDRequest *request, return -EIO; } - TRACE("Decoding type: handle =3D %" PRIu64 ", type =3D %" PRIu16, - request->handle, request->type); + trace_nbd_co_receive_request_decode_type(request->handle, request->typ= e); if (request->type !=3D NBD_CMD_WRITE) { /* No payload, we are ready to read the next request. */ @@ -1086,8 +1082,8 @@ static int nbd_co_receive_request(NBDRequestData *req= , NBDRequest *request, } req->complete =3D true; - TRACE("Payload received: handle =3D %" PRIu64 ", len =3D %" PRIu32, - request->handle, request->len); + trace_nbd_co_receive_request_payload_received(request->handle, + request->len); } /* Sanity checks, part 2. */ @@ -1123,7 +1119,7 @@ static coroutine_fn void nbd_trip(void *opaque) int reply_data_len =3D 0; Error *local_err =3D NULL; - TRACE("Reading request."); + trace_nbd_trip(); if (client->closing) { nbd_client_put(client); return; diff --git a/Makefile.objs b/Makefile.objs index 756644c..3e24c32 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -168,6 +168,7 @@ trace-events-subdirs +=3D linux-user trace-events-subdirs +=3D qapi trace-events-subdirs +=3D accel/tcg trace-events-subdirs +=3D accel/kvm +trace-events-subdirs +=3D nbd trace-events-files =3D $(SRC_PATH)/trace-events $(trace-events-subdirs:%= =3D$(SRC_PATH)/%/trace-events) diff --git a/nbd/trace-events b/nbd/trace-events new file mode 100644 index 0000000..4b233b8 --- /dev/null +++ b/nbd/trace-events @@ -0,0 +1,56 @@ +# nbd/client.c +nbd_unknown_error(int err) "Squashing unexpected error %d to EINVAL" +nbd_send_option_request(uint32_t opt, uint32_t len) "Sending option reques= t %" PRIu32", len %" PRIu32 +nbd_receive_option_reply(uint32_t option, uint32_t type, uint32_t length) = "Received option reply %" PRIx32", type %" PRIx32", len %" PRIu32 +nbd_reply_err_unsup(uint32_t option) "server doesn't understand request %"= PRIx32 ", attempting fallback" +nbd_receive_query_exports_start(const char *wantname) "Querying export lis= t for '%s'" +nbd_receive_query_exports_success(const char *wantname) "Found desired exp= ort name '%s'" +nbd_receive_starttls_request(void) "Requesting TLS from server" +nbd_receive_starttls_reply(void) "Getting TLS reply from server" +nbd_receive_starttls_new_client(void) "TLS request approved, setting up TL= S" +nbd_receive_starttls_tls_handshake(void) "Starting TLS handshake" +nbd_receive_negotiate(void *tlscreds, const char *hostname) "Receiving neg= otiation tlscreds=3D%p hostname=3D%s" +nbd_receive_negotiate_magic(uint64_t magic) "Magic is 0x%" PRIx64 +nbd_receive_negotiate_server_flags(uint32_t globalflags) "Global flags are= %" PRIx32 +nbd_receive_negotiate_default_name(void) "Using default NBD export name \"= \"" +nbd_receive_negotiate_size_flags(uint64_t size, uint16_t flags) "Size is %= " PRIu64 ", export flags %" PRIx16 +nbd_init_set_socket(void) "Setting NBD socket" +nbd_init_set_block_size(unsigned long block_size) "Setting block size to %= lu" +nbd_init_set_size(unsigned long sectors) "Setting size to %lu block(s)" +nbd_init_trailing_bytes(int ignored_bytes) "Ignoring trailing %d bytes of = export" +nbd_init_set_readonly(void) "Setting readonly attribute" +nbd_init_finish(void) "Negotiation ended" +nbd_client_loop(void) "Doing NBD loop" +nbd_client_loop_ret(int ret, const char *error) "NBD loop returned %d: %s" +nbd_client_clear_queue(void) "Clearing NBD queue" +nbd_client_clear_socket(void) "Clearing NBD socket" +nbd_send_request(uint64_t from, uint32_t len, uint64_t handle, uint16_t fl= ags, uint16_t type) "Sending request to server: { .from =3D %" PRIu64", .le= n =3D %" PRIu32 ", .handle =3D %" PRIu64 ", .flags =3D %" PRIx16 ", .type = =3D %" PRIu16 " }" +nbd_receive_reply(uint32_t magic, int32_t error, uint64_t handle) "Got rep= ly: { magic =3D 0x%" PRIx32 ", .error =3D % " PRId32 ", handle =3D %" PRIu6= 4" }" + +# nbd/server.c +nbd_negotiate_send_rep_len(uint32_t opt, uint32_t type, uint32_t len) "Rep= ly opt=3D%" PRIx32 " type=3D%" PRIx32 " len=3D%" PRIu32 +nbd_negotiate_send_rep_err(const char *msg) "sending error message \"%s\"" +nbd_negotiate_send_rep_list(const char *name, const char *desc) "Advertisi= ng export name '%s' description '%s'" +nbd_negotiate_handle_export_name(void) "Checking length" +nbd_negotiate_handle_export_name_request(const char *name) "Client request= ed export '%s'" +nbd_negotiate_handle_starttls(void) "Setting up TLS" +nbd_negotiate_handle_starttls_handshake(void) "Starting TLS handshake" +nbd_negotiate_options_flags(void) "Checking client flags" +nbd_negotiate_options_newstyle(void) "Client supports fixed newstyle hands= hake" +nbd_negotiate_options_no_zeroes(void) "Client supports no zeroes at handsh= ake end" +nbd_negotiate_options_check_magic(uint64_t magic) "Checking opts magic 0x%= " PRIx64 +nbd_negotiate_options_check_option(uint32_t option) "Checking option 0x%" = PRIx32 +nbd_opt_abort_reply_failed(const char *error) "Reply to NBD_OPT_ABORT requ= est failed: %s" +nbd_negotiate_begin(void) "Beginning negotiation" +nbd_negotiate_old_style(uint64_t size, unsigned flags) "advertising size %= " PRIu64 " and flags %x" +nbd_negotiate_new_style_size_flags(uint64_t size, unsigned flags) "adverti= sing size %" PRIu64 " and flags %x" +nbd_negotiate_success(void) "Negotiation succeeded" +nbd_receive_request(uint32_t magic, uint16_t flags, uint16_t type, uint64_= t from, uint32_t len) "Got request: { magic =3D 0x%" PRIx32 ", .flags =3D %= " PRIx16 ", .type =3D %" PRIx16 ", from =3D %" PRIu64 ", len =3D %" PRIu32 = " }" +nbd_send_reply(int32_t error, uint64_t handle) "Sending response to client= : { .error =3D %" PRId32 ", handle =3D %" PRIu64 " }" +nbd_blk_aio_attached(const char *name, void *ctx) "Export %s: Attaching cl= ients to AIO context %p\n" +nbd_blk_aio_detach(const char *name, void *ctx) "Export %s: Detaching clie= nts from AIO context %p\n" +nbd_co_send_reply(uint64_t handle, uint32_t error, int len) "Send reply: h= andle =3D %" PRIu64 ", error =3D %" PRIu32 ", len =3D %d" +nbd_co_receive_request_decode_type(uint64_t handle, uint16_t type) "Decodi= ng type: handle =3D %" PRIu64 ", type =3D %" PRIu16 +nbd_co_receive_request_payload_received(uint64_t handle, uint32_t len) "Pa= yload received: handle =3D %" PRIu64 ", len =3D %" PRIu32 +nbd_co_receive_request_cmd_write(uint32_t len) "Reading %" PRIu32 " byte(s= )" +nbd_trip(void) "Reading request" --=20 2.9.4