From patchwork Mon Feb 4 07:08:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Slavomir Kaslev X-Patchwork-Id: 10795015 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 061C0180E for ; Mon, 4 Feb 2019 07:09:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E63C32AFCA for ; Mon, 4 Feb 2019 07:09:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DA4062B0AD; Mon, 4 Feb 2019 07:09:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 901C72AFCA for ; Mon, 4 Feb 2019 07:09:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726185AbfBDHJF (ORCPT ); Mon, 4 Feb 2019 02:09:05 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:39796 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727419AbfBDHJF (ORCPT ); Mon, 4 Feb 2019 02:09:05 -0500 Received: by mail-wr1-f67.google.com with SMTP id t27so13167221wra.6 for ; Sun, 03 Feb 2019 23:09:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qLImzubeS5THv7aK5BIvbc3ZBS3aCBFOnbv1zJZD+d8=; b=XRerLBYb8fqZA/uHlJnV7r6pGftkI5FJ5ITyWKVzGblUjvmq3Vj63MNGtlFNbV4dYd DZkwBw1TW3g2tGzlHSDyG4H06RjAqk4oqgs9WcVVaj6cYGVJLtrItuHnscp93Wjhyxfl j68V03m/5SwICJRQafxsTLPsHfNVn36cN3flejuCiZGTtZ0J+BUAjZ2nVLVKRNLeaA7b CJSp0wXxUc06XvYIVKv5c3tCH7ZdXAnoiN4QP9HDFki/jTw3xDvvkaIXGDrGbik+4Et9 GKFr84dD09qeaJs2NTBt8WyHi9/IStDdpyJo+3JK4EeXB6LiD2vuUhMONhrIGC7c7S8o BRHw== X-Gm-Message-State: AJcUukd4TP3/PZtWImQU1YeAptP8ccpXUHqVxxgZ791zcCUPsGBgUjmE UvnYIwlzb+ioa3Sr3Abr0Mx8MXsROA== X-Google-Smtp-Source: ALg8bN51qCHl5E8YtopAW+awB1uVQtGKAk/4jisrG+bq9c7/WwwXKQaPiGKU10bhDRl4yTd4CkBCjQ== X-Received: by 2002:adf:92c7:: with SMTP id 65mr45024844wrn.228.1549264143362; Sun, 03 Feb 2019 23:09:03 -0800 (PST) Received: from localhost.localdomain ([213.145.108.55]) by smtp.gmail.com with ESMTPSA id w12sm13222378wrr.23.2019.02.03.23.09.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 03 Feb 2019 23:09:02 -0800 (PST) From: Slavomir Kaslev To: linux-trace-devel@vger.kernel.org Cc: rostedt@goodmis.org, slavomir.kaslev@gmail.com, tstoyanov@vmware.com, ykaradzhov@vmware.com Subject: [PATCH 1/8] trace-cmd: Remove unused global variable Date: Mon, 4 Feb 2019 09:08:48 +0200 Message-Id: <20190204070855.8921-2-kaslevs@vmware.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190204070855.8921-1-kaslevs@vmware.com> References: <20190204070855.8921-1-kaslevs@vmware.com> MIME-Version: 1.0 Sender: linux-trace-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP No changes in behavior intended. Signed-off-by: Slavomir Kaslev --- tracecmd/trace-msg.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/tracecmd/trace-msg.c b/tracecmd/trace-msg.c index 529ae2a..418a22d 100644 --- a/tracecmd/trace-msg.c +++ b/tracecmd/trace-msg.c @@ -130,8 +130,6 @@ struct tracecmd_msg { }; } __attribute__((packed)); -struct tracecmd_msg *errmsg; - static int msg_write(int fd, struct tracecmd_msg *msg) { int cmd = ntohl(msg->hdr.cmd); From patchwork Mon Feb 4 07:08:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Slavomir Kaslev X-Patchwork-Id: 10795017 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 57808922 for ; Mon, 4 Feb 2019 07:09:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 402242AFCA for ; Mon, 4 Feb 2019 07:09:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 342D22B0AD; Mon, 4 Feb 2019 07:09:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D44A62AFCA for ; Mon, 4 Feb 2019 07:09:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727547AbfBDHJG (ORCPT ); Mon, 4 Feb 2019 02:09:06 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:34155 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727419AbfBDHJG (ORCPT ); Mon, 4 Feb 2019 02:09:06 -0500 Received: by mail-wm1-f68.google.com with SMTP id y185so9313526wmd.1 for ; Sun, 03 Feb 2019 23:09:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DmkT+igkX9jSkAVe7Z+C6GyQ+YKiMwaPl4tcAEr2XnE=; b=MM+4wH2S09eK+xV6DSi6ytKc1KIoRa4iRy2a7HdBYfRXcf4GRKuo30wRx+Ez8JYf9e E/uKn7PoiqSYkaWn2xt079uil5juqg2Ysa+/WeugkSI9QS/mSjmedXJ58tViTtAsPcCT QKGwHbTtCSQCk+nONDqYVg2ivDTXxk9bmEI3p8GHY2Ughwq70WFaF5MiYhmzjShR5Ou6 Z6mZfujCZStHbJZhRMDT9UI/azipHNELmITjCcIXL54ebCrGuzdMS+ZhcHs00O3uvLB5 es+leJZGHf0k2TBnheefm3ydFAIr8k9mFBZAneUhTjD/5Cm3z55sbdpIp8+GWscfrk2o CuMw== X-Gm-Message-State: AHQUAuYWw+CFlFPXTooC5jnO/9jCBAZBimgENFqARbWKmMLOlSZHcyK8 R99dmwjlmTpEQyx19yjUNG5YKsMIpA== X-Google-Smtp-Source: AHgI3Ia8ui1NW2hAKNwWe+ZR4PGYiCPm6qRN9LJ2Gk+M1TG2gq12yq7svOhCJ5/GIqfd5Asp8mKmAA== X-Received: by 2002:a1c:6a0f:: with SMTP id f15mr4554432wmc.68.1549264144554; Sun, 03 Feb 2019 23:09:04 -0800 (PST) Received: from localhost.localdomain ([213.145.108.55]) by smtp.gmail.com with ESMTPSA id w12sm13222378wrr.23.2019.02.03.23.09.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 03 Feb 2019 23:09:03 -0800 (PST) From: Slavomir Kaslev To: linux-trace-devel@vger.kernel.org Cc: rostedt@goodmis.org, slavomir.kaslev@gmail.com, tstoyanov@vmware.com, ykaradzhov@vmware.com Subject: [PATCH 2/8] trace-cmd: Rename error_operation_for_server Date: Mon, 4 Feb 2019 09:08:49 +0200 Message-Id: <20190204070855.8921-3-kaslevs@vmware.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190204070855.8921-1-kaslevs@vmware.com> References: <20190204070855.8921-1-kaslevs@vmware.com> MIME-Version: 1.0 Sender: linux-trace-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP No changes in behavior intended. Signed-off-by: Slavomir Kaslev --- tracecmd/trace-msg.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/tracecmd/trace-msg.c b/tracecmd/trace-msg.c index 418a22d..ffebce7 100644 --- a/tracecmd/trace-msg.c +++ b/tracecmd/trace-msg.c @@ -345,6 +345,12 @@ void tracecmd_msg_set_done(struct tracecmd_msg_handle *msg_handle) msg_server->done = true; } +static void error_operation(struct tracecmd_msg *msg) +{ + warning("Message: cmd=%d size=%d\n", + ntohl(msg->hdr.cmd), ntohl(msg->hdr.size)); +} + /* * A return value of 0 indicates time-out */ @@ -432,15 +438,6 @@ static bool process_option(struct tracecmd_msg_handle *msg_handle, return false; } -static void error_operation_for_server(struct tracecmd_msg *msg) -{ - u32 cmd; - - cmd = ntohl(msg->hdr.cmd); - - warning("Message: cmd=%d size=%d\n", cmd, ntohl(msg->hdr.size)); -} - struct tracecmd_msg_handle * tracecmd_msg_handle_alloc(int fd, unsigned long flags) { @@ -545,7 +542,7 @@ int tracecmd_msg_initial_setting(struct tracecmd_msg_handle *msg_handle) return pagesize; error: - error_operation_for_server(&msg); + error_operation(&msg); return ret; } @@ -670,7 +667,7 @@ int tracecmd_msg_read_data(struct tracecmd_msg_handle *msg_handle, int ofd) return 0; error: - error_operation_for_server(&msg); + error_operation(&msg); msg_free(&msg); return ret; } @@ -709,7 +706,7 @@ int tracecmd_msg_collect_data(struct tracecmd_msg_handle *msg_handle, int ofd) return 0; error: - error_operation_for_server(&msg); + error_operation(&msg); msg_free(&msg); return ret; } From patchwork Mon Feb 4 07:08:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Slavomir Kaslev X-Patchwork-Id: 10795019 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D853F922 for ; Mon, 4 Feb 2019 07:09:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C486A2AFCA for ; Mon, 4 Feb 2019 07:09:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B882D2B0AD; Mon, 4 Feb 2019 07:09:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4B6D12AFCA for ; Mon, 4 Feb 2019 07:09:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727569AbfBDHJI (ORCPT ); Mon, 4 Feb 2019 02:09:08 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:38603 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727419AbfBDHJH (ORCPT ); Mon, 4 Feb 2019 02:09:07 -0500 Received: by mail-wr1-f68.google.com with SMTP id v13so13161975wrw.5 for ; Sun, 03 Feb 2019 23:09:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=oV05t1QuadAEL0lR4eYABfRWKFyq2SdBKAoisivU/Vg=; b=inzSrJaZdYtxTl8TMSacxAuy7jyVlZmQAOmeYpYxwEaFm0qdPT4EYytCdLckcbUem3 VQ09imOhv7TxhGjV7vSD2Zy3C/DvI3GaHVz6gYK5STu8sMELsgxmvINs3yPZP3q2ulWb qRhDDbJo8luyEopDshnrx1FkrITxTQ/YA80IMN1hTsZ98FBwH5r58y1v/91tO8LTWITJ ARegPEW866NNRZ1BgtmAT6UVqAZeDg19JKbqKnq61AS4zO1qw35cqyID7or868NbWf8O jS0b+gHmEJ5GmEJ/RpFpU0ECnBFpUKXmcreH+J7N7Gax0reVts4mHfaPI8DbqN0cq6xA b9mg== X-Gm-Message-State: AHQUAubTyRQjjx2di9dTupBNyALmBZkwAf2MXsTv3Xm+xHpoQcDwfJbe ISrjzhEWHsiTmm/riIirjYxOBdLcUw== X-Google-Smtp-Source: AHgI3IbBE9GFGwMwJki54tlStYze5oH8/IIfJSgVoHozmM2HHK++FHU32Cokf1CxjepHyDfd5oXwLA== X-Received: by 2002:adf:fd0a:: with SMTP id e10mr700615wrr.190.1549264145750; Sun, 03 Feb 2019 23:09:05 -0800 (PST) Received: from localhost.localdomain ([213.145.108.55]) by smtp.gmail.com with ESMTPSA id w12sm13222378wrr.23.2019.02.03.23.09.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 03 Feb 2019 23:09:05 -0800 (PST) From: Slavomir Kaslev To: linux-trace-devel@vger.kernel.org Cc: rostedt@goodmis.org, slavomir.kaslev@gmail.com, tstoyanov@vmware.com, ykaradzhov@vmware.com Subject: [PATCH 3/8] trace-cmd: Remove tracecmd_msg_handle/tracecmd_msg_server distinction Date: Mon, 4 Feb 2019 09:08:50 +0200 Message-Id: <20190204070855.8921-4-kaslevs@vmware.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190204070855.8921-1-kaslevs@vmware.com> References: <20190204070855.8921-1-kaslevs@vmware.com> MIME-Version: 1.0 Sender: linux-trace-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The difference between tracecmd_msg_handle and tracecmd_msg_server is a single bool and the tracecmd_msg_set_done/tracecmd_msg_done functions are also useful on the client side in the context of the tracing VMs over vsockets work. Signed-off-by: Slavomir Kaslev --- include/trace-cmd/trace-cmd.h | 11 ++--------- tracecmd/trace-listen.c | 2 +- tracecmd/trace-msg.c | 31 +++---------------------------- tracecmd/trace-record.c | 2 +- 4 files changed, 7 insertions(+), 39 deletions(-) diff --git a/include/trace-cmd/trace-cmd.h b/include/trace-cmd/trace-cmd.h index 86b9b53..33f352b 100644 --- a/include/trace-cmd/trace-cmd.h +++ b/include/trace-cmd/trace-cmd.h @@ -293,16 +293,8 @@ void tracecmd_disable_all_tracing(int disable_tracer); void tracecmd_disable_tracing(void); void tracecmd_enable_tracing(void); -enum tracecmd_msg_bits { - TRACECMD_MSG_BIT_CLIENT = 0, - TRACECMD_MSG_BIT_SERVER = 1, - TRACECMD_MSG_BIT_USE_TCP = 2, -}; - enum tracecmd_msg_flags { - TRACECMD_MSG_FL_CLIENT = (1 << TRACECMD_MSG_BIT_CLIENT), - TRACECMD_MSG_FL_SERVER = (1 << TRACECMD_MSG_BIT_SERVER), - TRACECMD_MSG_FL_USE_TCP = (1 << TRACECMD_MSG_BIT_USE_TCP), + TRACECMD_MSG_FL_USE_TCP = 1 << 0, }; /* for both client and server */ @@ -311,6 +303,7 @@ struct tracecmd_msg_handle { short cpu_count; short version; /* Current protocol version */ unsigned long flags; + bool done; }; struct tracecmd_msg_handle * diff --git a/tracecmd/trace-listen.c b/tracecmd/trace-listen.c index 9b50147..8bd7bad 100644 --- a/tracecmd/trace-listen.c +++ b/tracecmd/trace-listen.c @@ -748,7 +748,7 @@ static int do_connection(int cfd, struct sockaddr_storage *peer_addr, if (ret) return ret; - msg_handle = tracecmd_msg_handle_alloc(cfd, TRACECMD_MSG_FL_SERVER); + msg_handle = tracecmd_msg_handle_alloc(cfd, 0); s = getnameinfo((struct sockaddr *)peer_addr, peer_addr_len, host, NI_MAXHOST, diff --git a/tracecmd/trace-msg.c b/tracecmd/trace-msg.c index ffebce7..ef2a6d8 100644 --- a/tracecmd/trace-msg.c +++ b/tracecmd/trace-msg.c @@ -49,21 +49,6 @@ static inline void dprint(const char *fmt, ...) unsigned int page_size; -struct tracecmd_msg_server { - struct tracecmd_msg_handle handle; - int done; -}; - -static struct tracecmd_msg_server * -make_server(struct tracecmd_msg_handle *msg_handle) -{ - if (!(msg_handle->flags & TRACECMD_MSG_FL_SERVER)) { - plog("Message handle not of type server\n"); - return NULL; - } - return (struct tracecmd_msg_server *)msg_handle; -} - struct tracecmd_msg_opt { be32 size; be32 opt_cmd; @@ -333,16 +318,12 @@ static int msg_wait_to = MSG_WAIT_MSEC; bool tracecmd_msg_done(struct tracecmd_msg_handle *msg_handle) { - struct tracecmd_msg_server *msg_server = make_server(msg_handle); - - return (volatile int)msg_server->done; + return (volatile int)msg_handle->done; } void tracecmd_msg_set_done(struct tracecmd_msg_handle *msg_handle) { - struct tracecmd_msg_server *msg_server = make_server(msg_handle); - - msg_server->done = true; + msg_handle->done = true; } static void error_operation(struct tracecmd_msg *msg) @@ -442,14 +423,8 @@ struct tracecmd_msg_handle * tracecmd_msg_handle_alloc(int fd, unsigned long flags) { struct tracecmd_msg_handle *handle; - int size; - - if (flags == TRACECMD_MSG_FL_SERVER) - size = sizeof(struct tracecmd_msg_server); - else - size = sizeof(struct tracecmd_msg_handle); - handle = calloc(1, size); + handle = calloc(1, sizeof(struct tracecmd_msg_handle)); if (!handle) return NULL; diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index 3034a4b..8beefab 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -2883,7 +2883,7 @@ again: if (msg_handle) { msg_handle->fd = sfd; } else { - msg_handle = tracecmd_msg_handle_alloc(sfd, TRACECMD_MSG_FL_CLIENT); + msg_handle = tracecmd_msg_handle_alloc(sfd, 0); if (!msg_handle) die("Failed to allocate message handle"); From patchwork Mon Feb 4 07:08:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Slavomir Kaslev X-Patchwork-Id: 10795021 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B13436C2 for ; Mon, 4 Feb 2019 07:09:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9E3782AFCA for ; Mon, 4 Feb 2019 07:09:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 923EC2B0AD; Mon, 4 Feb 2019 07:09:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3DAFE2AFCA for ; Mon, 4 Feb 2019 07:09:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727419AbfBDHJJ (ORCPT ); Mon, 4 Feb 2019 02:09:09 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:43619 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727560AbfBDHJI (ORCPT ); Mon, 4 Feb 2019 02:09:08 -0500 Received: by mail-wr1-f65.google.com with SMTP id r2so1468359wrv.10 for ; Sun, 03 Feb 2019 23:09:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kI3IuMD7C5qSiSz4Zis0PplHVi2r/Ugs3P/CD04QUkg=; b=I8Zw/ZzvTxB8GYpe/nHoZ/q2dJNDki2kkbimzRQWhyMlodIhf+bvfKO4Hhi1+LfwvU IkY7bRMKiOpzc5+gTrpEuOBiyGeXHp3e2Egd1HC8HTbRyE15E57VuSmOpICDdGT4vxVc 3wYjzjU75oNRnIDUxaS17ebkBGNnLdttBD0vAkXUcFvZd6IrKrGlCMzEjw9tj2lzX4pH L0yZQi3GvVpbt10ZbB9lCWCxF8cycnmD31WIV2v4qps5QivRMRKFCEgSBFcTzByISxMA P/v+3qvze2l0qhdcq4OgT82xUQUXN+CvudnhVfpm+2xOwG+PoG4ej8Xza8edIOqsa6YB NNFQ== X-Gm-Message-State: AHQUAuZvyniDNfahhQpsrO1vZ8pDepv71qqkdR0a+MqIjRjisrjjtPcd yk/t8V3IJ2bOy59HRjYNCxiKoppjig== X-Google-Smtp-Source: AHgI3Ibqg2FuKebLp28sTMxJhYKg6AbifcxE20qO1xRr6k2tB2I0sDgJ5t7MUN4/pbqJhjQjHPsL0A== X-Received: by 2002:adf:ee06:: with SMTP id y6mr6354164wrn.60.1549264146949; Sun, 03 Feb 2019 23:09:06 -0800 (PST) Received: from localhost.localdomain ([213.145.108.55]) by smtp.gmail.com with ESMTPSA id w12sm13222378wrr.23.2019.02.03.23.09.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 03 Feb 2019 23:09:06 -0800 (PST) From: Slavomir Kaslev To: linux-trace-devel@vger.kernel.org Cc: rostedt@goodmis.org, slavomir.kaslev@gmail.com, tstoyanov@vmware.com, ykaradzhov@vmware.com Subject: [PATCH 4/8] trace-cmd: Check if connection is done when reading data in tracecmd_msg_read_data Date: Mon, 4 Feb 2019 09:08:51 +0200 Message-Id: <20190204070855.8921-5-kaslevs@vmware.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190204070855.8921-1-kaslevs@vmware.com> References: <20190204070855.8921-1-kaslevs@vmware.com> MIME-Version: 1.0 Sender: linux-trace-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Now that tracecmd_msg_done/tracecmd_msg_set_done can be used in both server and client context, check if the connection is shutting down in tracecmd_msg_read_data. Signed-off-by: Slavomir Kaslev --- tracecmd/trace-msg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tracecmd/trace-msg.c b/tracecmd/trace-msg.c index ef2a6d8..f7ce863 100644 --- a/tracecmd/trace-msg.c +++ b/tracecmd/trace-msg.c @@ -603,7 +603,7 @@ int tracecmd_msg_read_data(struct tracecmd_msg_handle *msg_handle, int ofd) ssize_t s; int ret; - for (;;) { + while (!tracecmd_msg_done(msg_handle)) { ret = tracecmd_msg_recv_wait(msg_handle->fd, &msg); if (ret < 0) { if (ret == -ETIMEDOUT) From patchwork Mon Feb 4 07:08:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Slavomir Kaslev X-Patchwork-Id: 10795023 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0DE79922 for ; Mon, 4 Feb 2019 07:09:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ED12E2AFCA for ; Mon, 4 Feb 2019 07:09:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E1A432B0AD; Mon, 4 Feb 2019 07:09:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8E59C2AFCA for ; Mon, 4 Feb 2019 07:09:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727598AbfBDHJK (ORCPT ); Mon, 4 Feb 2019 02:09:10 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:38605 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727560AbfBDHJK (ORCPT ); Mon, 4 Feb 2019 02:09:10 -0500 Received: by mail-wr1-f68.google.com with SMTP id v13so13162049wrw.5 for ; Sun, 03 Feb 2019 23:09:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vZpMB4fptM6Qsw9SK6xj0wpQBQFqPgxBtRx5xm0gHEw=; b=E0UcQG6DAbL+LQX0nAiw2CCtzTK9z2FyYbklayo3sz6vLuggTrH/eKV67Id+vKQgZj 76VKA3I2fFfrUPW3yUxoqtHN5oIhCmaCG3TQtD53MFamSb5vAvl5Ec3xGv97bBwP0DKc kMqkFtBgCb6kTHL931XycjN/pXj7S8Yt7S3twa9Hyig09SM6oBP0UhHrlkL/McTNYhU8 v++sfudoktC7UEZuqihslE2BwQqoBLf2l984OwQ9PIeLOMahVcP/qb9m9y45/Mze1FA6 kezoaq+l2HQ/Wj2ne6DgYgmLxw9IpQCmKRKNF+peGmMOxI1Vo9tgKQVGOuPIOah2xcUP plEQ== X-Gm-Message-State: AHQUAuYTDmZ5i2+8VT7BTrwWY48jwclATwwm4PWWo5/QGDBrBQN3FUW1 wTg7jMsMLSZeZ/gkQZyMtk5PoLBfHw== X-Google-Smtp-Source: AHgI3Ib2QFnxmlI/ZXqpkD4dhSux4WhT4vGjy7RXILOXwkSjWviJe29Su+RyM+42fbLwBYsvseP51Q== X-Received: by 2002:a5d:690d:: with SMTP id t13mr10621975wru.195.1549264148191; Sun, 03 Feb 2019 23:09:08 -0800 (PST) Received: from localhost.localdomain ([213.145.108.55]) by smtp.gmail.com with ESMTPSA id w12sm13222378wrr.23.2019.02.03.23.09.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 03 Feb 2019 23:09:07 -0800 (PST) From: Slavomir Kaslev To: linux-trace-devel@vger.kernel.org Cc: rostedt@goodmis.org, slavomir.kaslev@gmail.com, tstoyanov@vmware.com, ykaradzhov@vmware.com Subject: [PATCH 5/8] trace-cmd: Fix a memory leak in tracecmd_msg_send_init_data Date: Mon, 4 Feb 2019 09:08:52 +0200 Message-Id: <20190204070855.8921-6-kaslevs@vmware.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190204070855.8921-1-kaslevs@vmware.com> References: <20190204070855.8921-1-kaslevs@vmware.com> MIME-Version: 1.0 Sender: linux-trace-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Fix tracecmd_msg_send_init_data leaking memory for the messages it receives. Signed-off-by: Slavomir Kaslev --- tracecmd/trace-msg.c | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/tracecmd/trace-msg.c b/tracecmd/trace-msg.c index f7ce863..b4b58d4 100644 --- a/tracecmd/trace-msg.c +++ b/tracecmd/trace-msg.c @@ -373,8 +373,7 @@ static int tracecmd_msg_wait_for_msg(int fd, struct tracecmd_msg *msg) int tracecmd_msg_send_init_data(struct tracecmd_msg_handle *msg_handle, unsigned int **client_ports) { - struct tracecmd_msg send_msg; - struct tracecmd_msg recv_msg; + struct tracecmd_msg msg; int fd = msg_handle->fd; unsigned int *ports; int i, cpus; @@ -382,30 +381,41 @@ int tracecmd_msg_send_init_data(struct tracecmd_msg_handle *msg_handle, *client_ports = NULL; - tracecmd_msg_init(MSG_TINIT, &send_msg); - ret = make_tinit(msg_handle, &send_msg); + tracecmd_msg_init(MSG_TINIT, &msg); + ret = make_tinit(msg_handle, &msg); if (ret < 0) - return ret; + goto out; - ret = tracecmd_msg_send(fd, &send_msg); + ret = tracecmd_msg_send(fd, &msg); if (ret < 0) - return ret; + goto out; + + msg_free(&msg); - ret = tracecmd_msg_wait_for_msg(fd, &recv_msg); + ret = tracecmd_msg_wait_for_msg(fd, &msg); if (ret < 0) - return ret; + goto out; - if (ntohl(recv_msg.hdr.cmd) != MSG_RINIT) - return -EINVAL; + if (ntohl(msg.hdr.cmd) != MSG_RINIT) { + ret = -EINVAL; + goto error; + } - cpus = ntohl(recv_msg.rinit.cpus); + cpus = ntohl(msg.rinit.cpus); ports = malloc_or_die(sizeof(*ports) * cpus); for (i = 0; i < cpus; i++) - ports[i] = ntohl(recv_msg.port_array[i]); + ports[i] = ntohl(msg.port_array[i]); *client_ports = ports; + msg_free(&msg); return 0; + +error: + error_operation(&msg); +out: + msg_free(&msg); + return ret; } static bool process_option(struct tracecmd_msg_handle *msg_handle, From patchwork Mon Feb 4 07:08:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Slavomir Kaslev X-Patchwork-Id: 10795025 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 355A4922 for ; Mon, 4 Feb 2019 07:09:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 226872AFCA for ; Mon, 4 Feb 2019 07:09:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 149DC2B0AD; Mon, 4 Feb 2019 07:09:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BBD012AFCA for ; Mon, 4 Feb 2019 07:09:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727560AbfBDHJL (ORCPT ); Mon, 4 Feb 2019 02:09:11 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:41135 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727572AbfBDHJL (ORCPT ); Mon, 4 Feb 2019 02:09:11 -0500 Received: by mail-wr1-f67.google.com with SMTP id x10so13175869wrs.8 for ; Sun, 03 Feb 2019 23:09:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NIl11p0gvuQj+I42VoK+mRQ8/W38c1uvgs2uUc+4YWQ=; b=eSaCxsXYLMvgTfPe0P2CQuBQw5cT1kNZ+eTf+acJWw0KGJ1C244tESKLKyxex2eQUw 3Ywmu32qvM5J6gimM7ccqI/HVJjpgIIh9fjQfqIcx2gf4Rtc6a6w8cr5uYk22XMgbbmS ikjRGIDuwXvUCAgaGgLGVj5BlG793AVoe3ujRvdFg5TIqZNIdl3HoIe55vDWj7d1CRm5 RDhwGcFNg/xAA3KUy6cpikMKhhh0pjea0p6y5b37HxP5pwnX3XV88f4Efq22irI3tMTa ZObRNafToBBKDV2qkL6J+7QhStzPlmILe+DWN2eky+XpD6NFWf4UhMrV6CrxJpIv0prr j1Ow== X-Gm-Message-State: AHQUAuZDrRV9PETbhVRDAI8yt60HHwvy3S14NfbW0DwDdaBYzJm94VrL fXrlPFBtHZEhs9dWMhN8uYrwVws18g== X-Google-Smtp-Source: AHgI3IboyGHK1Cm73FmK2WSX5rWijrUb8OfJc829k70DSWoH2O5bKJ/n0RWYi29Wr5PnkcNMHbEPZA== X-Received: by 2002:adf:f30f:: with SMTP id i15mr553842wro.39.1549264149487; Sun, 03 Feb 2019 23:09:09 -0800 (PST) Received: from localhost.localdomain ([213.145.108.55]) by smtp.gmail.com with ESMTPSA id w12sm13222378wrr.23.2019.02.03.23.09.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 03 Feb 2019 23:09:08 -0800 (PST) From: Slavomir Kaslev To: linux-trace-devel@vger.kernel.org Cc: rostedt@goodmis.org, slavomir.kaslev@gmail.com, tstoyanov@vmware.com, ykaradzhov@vmware.com Subject: [PATCH 6/8] trace-cmd: Make tracecmd_msg_send_close return error code if any Date: Mon, 4 Feb 2019 09:08:53 +0200 Message-Id: <20190204070855.8921-7-kaslevs@vmware.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190204070855.8921-1-kaslevs@vmware.com> References: <20190204070855.8921-1-kaslevs@vmware.com> MIME-Version: 1.0 Sender: linux-trace-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Slavomir Kaslev --- include/trace-cmd/trace-cmd.h | 2 +- tracecmd/trace-msg.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/trace-cmd/trace-cmd.h b/include/trace-cmd/trace-cmd.h index 33f352b..0ab23f6 100644 --- a/include/trace-cmd/trace-cmd.h +++ b/include/trace-cmd/trace-cmd.h @@ -318,7 +318,7 @@ int tracecmd_msg_send_init_data(struct tracecmd_msg_handle *msg_handle, int tracecmd_msg_data_send(struct tracecmd_msg_handle *msg_handle, const char *buf, int size); int tracecmd_msg_finish_sending_data(struct tracecmd_msg_handle *msg_handle); -void tracecmd_msg_send_close_msg(struct tracecmd_msg_handle *msg_handle); +int tracecmd_msg_send_close_msg(struct tracecmd_msg_handle *msg_handle); /* for server */ int tracecmd_msg_initial_setting(struct tracecmd_msg_handle *msg_handle); diff --git a/tracecmd/trace-msg.c b/tracecmd/trace-msg.c index b4b58d4..c24424b 100644 --- a/tracecmd/trace-msg.c +++ b/tracecmd/trace-msg.c @@ -549,12 +549,12 @@ int tracecmd_msg_send_port_array(struct tracecmd_msg_handle *msg_handle, return 0; } -void tracecmd_msg_send_close_msg(struct tracecmd_msg_handle *msg_handle) +int tracecmd_msg_send_close_msg(struct tracecmd_msg_handle *msg_handle) { struct tracecmd_msg msg; tracecmd_msg_init(MSG_CLOSE, &msg); - tracecmd_msg_send(msg_handle->fd, &msg); + return tracecmd_msg_send(msg_handle->fd, &msg); } int tracecmd_msg_data_send(struct tracecmd_msg_handle *msg_handle, From patchwork Mon Feb 4 07:08:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Slavomir Kaslev X-Patchwork-Id: 10795027 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9B7FC6C2 for ; Mon, 4 Feb 2019 07:09:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 877EE28834 for ; Mon, 4 Feb 2019 07:09:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7B09D2B0AF; Mon, 4 Feb 2019 07:09:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 21B8228834 for ; Mon, 4 Feb 2019 07:09:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727606AbfBDHJN (ORCPT ); Mon, 4 Feb 2019 02:09:13 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:36444 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727572AbfBDHJM (ORCPT ); Mon, 4 Feb 2019 02:09:12 -0500 Received: by mail-wm1-f67.google.com with SMTP id p6so12119203wmc.1 for ; Sun, 03 Feb 2019 23:09:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2b7f1jwXJwAtQT3T08sfJGagfJT2amW4KYbbUFSEjwY=; b=K8dm12N7vIHAiM3jElow/KlR6Kmg3CXXRibLcVj/jNUbXXHqyMG+0C0CcSAz/pxy9J QQD0eKvF4k7moUmJtryk5ocdhxmZGP1W98qNg8MMM8EhmM9RcfKuyBEulVQyJ2kUb/GO IO9A9dWfTtDYERkxRDMN6MOy+/GNYfebSV4F97tDgqL9xPsPwF966VXERFOJRB4C4WVl sLJGG0L7/xd2e5VORK7FfR0WPKXNu611RlPl0w1aCOBS9EXDDR0y9bPHgwC61vc3gOZ3 i1uP9Z23sdMBLWzT4yvXDdm23GppDAJN/Gd3EvEjjD9znv5z4nz8aRNespb+2DY6IK97 ezoA== X-Gm-Message-State: AHQUAuZdwyuzXtrs+u07aeqJ5a447ttMwMF46V/+YynGi6uQZvdQs/cH m3QXAys2XI1qeIjlRY6iZAhOZx0IPA== X-Google-Smtp-Source: AHgI3IbOmF30zcYxfvnKHxX7y4hl1Y6X5E1g8TDd08IZrCmyuqitFDY4iu74upFHRvGhc/tqff1B9Q== X-Received: by 2002:a7b:c08b:: with SMTP id r11mr11485872wmh.29.1549264150719; Sun, 03 Feb 2019 23:09:10 -0800 (PST) Received: from localhost.localdomain ([213.145.108.55]) by smtp.gmail.com with ESMTPSA id w12sm13222378wrr.23.2019.02.03.23.09.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 03 Feb 2019 23:09:10 -0800 (PST) From: Slavomir Kaslev To: linux-trace-devel@vger.kernel.org Cc: rostedt@goodmis.org, slavomir.kaslev@gmail.com, tstoyanov@vmware.com, ykaradzhov@vmware.com Subject: [PATCH 7/8] trace-cmd: Add tracecmd_msg_wait_close function Date: Mon, 4 Feb 2019 09:08:54 +0200 Message-Id: <20190204070855.8921-8-kaslevs@vmware.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190204070855.8921-1-kaslevs@vmware.com> References: <20190204070855.8921-1-kaslevs@vmware.com> MIME-Version: 1.0 Sender: linux-trace-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add tracecmd_msg_wait_close function that waits for MSG_CLOSE and logs any invalid messages it receives. Also switch tracecmd_msg_collect_data to use the new function while at it. Signed-off-by: Slavomir Kaslev --- include/trace-cmd/trace-cmd.h | 1 + tracecmd/trace-msg.c | 35 +++++++++++++++-------------------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/include/trace-cmd/trace-cmd.h b/include/trace-cmd/trace-cmd.h index 0ab23f6..ca4452b 100644 --- a/include/trace-cmd/trace-cmd.h +++ b/include/trace-cmd/trace-cmd.h @@ -319,6 +319,7 @@ int tracecmd_msg_data_send(struct tracecmd_msg_handle *msg_handle, const char *buf, int size); int tracecmd_msg_finish_sending_data(struct tracecmd_msg_handle *msg_handle); int tracecmd_msg_send_close_msg(struct tracecmd_msg_handle *msg_handle); +int tracecmd_msg_wait_close(struct tracecmd_msg_handle *msg_handle); /* for server */ int tracecmd_msg_initial_setting(struct tracecmd_msg_handle *msg_handle); diff --git a/tracecmd/trace-msg.c b/tracecmd/trace-msg.c index c24424b..5079d43 100644 --- a/tracecmd/trace-msg.c +++ b/tracecmd/trace-msg.c @@ -659,39 +659,34 @@ error: int tracecmd_msg_collect_data(struct tracecmd_msg_handle *msg_handle, int ofd) { - struct tracecmd_msg msg; - u32 cmd; int ret; ret = tracecmd_msg_read_data(msg_handle, ofd); if (ret) - goto error; + return ret; + + return tracecmd_msg_wait_close(msg_handle); +} - /* check the finish message of the client */ +int tracecmd_msg_wait_close(struct tracecmd_msg_handle *msg_handle) +{ + struct tracecmd_msg msg; + int ret = -1; + + memset(&msg, 0, sizeof(msg)); while (!tracecmd_msg_done(msg_handle)) { ret = tracecmd_msg_recv(msg_handle->fd, &msg); - if (ret < 0) { - warning("reading client"); - return ret; - } - - cmd = ntohl(msg.hdr.cmd); - if (cmd == MSG_CLOSE) - /* Finish this connection */ - break; - else { - warning("Not accept the message %d", ntohl(msg.hdr.cmd)); - ret = -EINVAL; + if (ret < 0) goto error; - } + if (ntohl(msg.hdr.cmd) == MSG_CLOSE) + return 0; + + error_operation(&msg); msg_free(&msg); } - return 0; - error: - error_operation(&msg); msg_free(&msg); return ret; } From patchwork Mon Feb 4 07:08:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Slavomir Kaslev X-Patchwork-Id: 10795029 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 478516C2 for ; Mon, 4 Feb 2019 07:09:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 32CA728834 for ; Mon, 4 Feb 2019 07:09:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 24E3E2B0AF; Mon, 4 Feb 2019 07:09:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AFBF228834 for ; Mon, 4 Feb 2019 07:09:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727650AbfBDHJO (ORCPT ); Mon, 4 Feb 2019 02:09:14 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:42160 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727645AbfBDHJO (ORCPT ); Mon, 4 Feb 2019 02:09:14 -0500 Received: by mail-wr1-f65.google.com with SMTP id q18so13144406wrx.9 for ; Sun, 03 Feb 2019 23:09:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=E0egSwUuiWy2h7ku8TKcGlU2azsQVay5JvxvqsYVBx8=; b=oPFSysGAtIoC8jd3V7SdrPoHourPjAk2WOfz0/ghxUSI6Giqzi5AiU+Et3X7biECik 1pBfRPgZyvOPCSRom1sh+FuO7458/t6uAnuHKUUF3nEf0HHO+dWqw11eEhKHSRr11Qz8 zUCgIjK1XmsVL1PHw/Jg0z7ylMXH6TM/fbkJ7BgECFvZ+FasOQs+AnA1jJJFLq7dPYrT kXRXJRrmIeqFt4QTCBQo0zv7nZJEYE0aD1EdsMKESNSgWtRvSCZLKY/w1V5oUY94/Epl 94BBJJZ/i/pLyQDyW/LB5fYk6oPOPo+OnRy+aeChGCw9C8PDzCErYyjVXYpESJNFdoev rgdw== X-Gm-Message-State: AHQUAua6X3rJ4hVjkC+fGG6ERJnOKE3YRWrqd1cUFRi1YkO4pGfaZf8z DC4RDKusKjWL6PwrL56FP673ZFEtuw== X-Google-Smtp-Source: AHgI3IY7YlORHkB9EN2IUW+IzAtwozzbXnHGb/nDmLKcpTfQn6NxacN/cTpWnm6MB1UejA6WBLAmPw== X-Received: by 2002:adf:e746:: with SMTP id c6mr6146546wrn.218.1549264151976; Sun, 03 Feb 2019 23:09:11 -0800 (PST) Received: from localhost.localdomain ([213.145.108.55]) by smtp.gmail.com with ESMTPSA id w12sm13222378wrr.23.2019.02.03.23.09.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 03 Feb 2019 23:09:11 -0800 (PST) From: Slavomir Kaslev To: linux-trace-devel@vger.kernel.org Cc: rostedt@goodmis.org, slavomir.kaslev@gmail.com, tstoyanov@vmware.com, ykaradzhov@vmware.com Subject: [PATCH 8/8] trace-cmd: Acknowledge unexpected protocol messages Date: Mon, 4 Feb 2019 09:08:55 +0200 Message-Id: <20190204070855.8921-9-kaslevs@vmware.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190204070855.8921-1-kaslevs@vmware.com> References: <20190204070855.8921-1-kaslevs@vmware.com> MIME-Version: 1.0 Sender: linux-trace-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Send MSG_NOT_SUPP message back on unexpected incoming messages. This allows us to add new commands in the future and be able to detect and handle if we're talking with an older version of trace-cmd. Signed-off-by: Slavomir Kaslev --- tracecmd/trace-msg.c | 49 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/tracecmd/trace-msg.c b/tracecmd/trace-msg.c index 5079d43..51d0ac8 100644 --- a/tracecmd/trace-msg.c +++ b/tracecmd/trace-msg.c @@ -75,7 +75,8 @@ struct tracecmd_msg_header { C(TINIT, 1, sizeof(struct tracecmd_msg_tinit)), \ C(RINIT, 2, sizeof(struct tracecmd_msg_rinit)), \ C(SEND_DATA, 3, 0), \ - C(FIN_DATA, 4, 0), + C(FIN_DATA, 4, 0), \ + C(NOT_SUPP, 5, 0), #undef C #define C(a,b,c) MSG_##a = b @@ -370,6 +371,25 @@ static int tracecmd_msg_wait_for_msg(int fd, struct tracecmd_msg *msg) return 0; } +static int tracecmd_msg_send_notsupp(struct tracecmd_msg_handle *msg_handle) +{ + struct tracecmd_msg msg; + + tracecmd_msg_init(MSG_NOT_SUPP, &msg); + return tracecmd_msg_send(msg_handle->fd, &msg); +} + +static int handle_unexpected_msg(struct tracecmd_msg_handle *msg_handle, + struct tracecmd_msg *msg) +{ + /* Don't send MSG_NOT_SUPP back if we just received one */ + if (ntohl(msg->hdr.cmd) == MSG_NOT_SUPP) + return 0; + + return tracecmd_msg_send_notsupp(msg_handle); + +} + int tracecmd_msg_send_init_data(struct tracecmd_msg_handle *msg_handle, unsigned int **client_ports) { @@ -397,7 +417,7 @@ int tracecmd_msg_send_init_data(struct tracecmd_msg_handle *msg_handle, goto out; if (ntohl(msg.hdr.cmd) != MSG_RINIT) { - ret = -EINVAL; + ret = -EOPNOTSUPP; goto error; } @@ -413,6 +433,8 @@ int tracecmd_msg_send_init_data(struct tracecmd_msg_handle *msg_handle, error: error_operation(&msg); + if (ret == -EOPNOTSUPP) + handle_unexpected_msg(msg_handle, &msg); out: msg_free(&msg); return ret; @@ -461,7 +483,6 @@ int tracecmd_msg_initial_setting(struct tracecmd_msg_handle *msg_handle) int ret; int offset = 0; u32 size; - u32 cmd; ret = tracecmd_msg_recv_wait(msg_handle->fd, &msg); if (ret < 0) { @@ -470,9 +491,8 @@ int tracecmd_msg_initial_setting(struct tracecmd_msg_handle *msg_handle) return ret; } - cmd = ntohl(msg.hdr.cmd); - if (cmd != MSG_TINIT) { - ret = -EINVAL; + if (ntohl(msg.hdr.cmd) != MSG_TINIT) { + ret = -EOPNOTSUPP; goto error; } @@ -524,10 +544,14 @@ int tracecmd_msg_initial_setting(struct tracecmd_msg_handle *msg_handle) } } + msg_free(&msg); return pagesize; error: error_operation(&msg); + if (ret == -EOPNOTSUPP) + handle_unexpected_msg(msg_handle, &msg); + msg_free(&msg); return ret; } @@ -627,8 +651,12 @@ int tracecmd_msg_read_data(struct tracecmd_msg_handle *msg_handle, int ofd) if (cmd == MSG_FIN_DATA) { /* Finish receiving data */ break; - } else if (cmd != MSG_SEND_DATA) - goto error; + } else if (cmd != MSG_SEND_DATA) { + ret = handle_unexpected_msg(msg_handle, &msg); + if (ret < 0) + goto error; + goto next; + } n = ntohl(msg.hdr.size) - MSG_HDR_LEN - ntohl(msg.hdr.cmd_size); t = n; @@ -646,6 +674,7 @@ int tracecmd_msg_read_data(struct tracecmd_msg_handle *msg_handle, int ofd) s = n - t; } +next: msg_free(&msg); } @@ -683,6 +712,10 @@ int tracecmd_msg_wait_close(struct tracecmd_msg_handle *msg_handle) return 0; error_operation(&msg); + ret = handle_unexpected_msg(msg_handle, &msg); + if (ret < 0) + goto error; + msg_free(&msg); }