From patchwork Fri Feb 1 13:45:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzvetomir Stoyanov X-Patchwork-Id: 10792803 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 76A6B746 for ; Fri, 1 Feb 2019 13:45:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 688BF2C68B for ; Fri, 1 Feb 2019 13:45:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5D1012F4AB; Fri, 1 Feb 2019 13:45:45 +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 065952C68B for ; Fri, 1 Feb 2019 13:45:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726737AbfBANpo (ORCPT ); Fri, 1 Feb 2019 08:45:44 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:40371 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729506AbfBANpo (ORCPT ); Fri, 1 Feb 2019 08:45:44 -0500 Received: by mail-wr1-f67.google.com with SMTP id p4so7136397wrt.7 for ; Fri, 01 Feb 2019 05:45:43 -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=bvcR0JidEW1GXqLErSuBSAUIWJxtH1uY9vOmR5nFGqE=; b=sBlfVlXFeNm6VVkPpbQbwSG9GKxR2RusP31IRR/MbK132u3atGoIwtnj3QF3iVFPh9 LgS0St9x0mDvtWyOJmztD79lK6yIix3pnbDhMb8i9e9HLiqr1dRI0mxIbIQxPo19ekDq +0mb5qv/11YPbcO0tJw80bRM14fOGQowlrtEf5DmYSGC2rZyGIbxd44GNGpcj8fEdV/R cJ/7HkfDEm7E34eObVDj2RfesebhnZJq4nmJDmfc3wH8BI3DeRpEhLg2k2H7ZkBeWI4b ueyIAjelDRcjyVT5geSJHDk9KL/VK4P2bz0NTejNkKZ5tnrcuB1I7caUGNSBnUvl8sdW LnPw== X-Gm-Message-State: AJcUukc/Q8K/nxhFKgMhYoswnHraqx5I8nicJ4Pp0THnmtkfRaqY0lVF 6XJY3lrIW/K/iYoaAv74OJ0= X-Google-Smtp-Source: ALg8bN7FqZo1HDY1hWTDR5yhTuLvw1kA71+iBrRJ15hEFguaFTsDekzrTiafxzImqwbwGhJek7bXPg== X-Received: by 2002:a5d:4b8b:: with SMTP id b11mr38775226wrt.180.1549028742846; Fri, 01 Feb 2019 05:45:42 -0800 (PST) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id v26sm1468732wrv.78.2019.02.01.05.45.41 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Feb 2019 05:45:42 -0800 (PST) From: Tzvetomir Stoyanov To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 5/6] trace-cmd: Refactored make_instances() and tracecmd_remove_instances() Date: Fri, 1 Feb 2019 15:45:34 +0200 Message-Id: <20190201134535.2979-6-tstoyanov@vmware.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190201134535.2979-1-tstoyanov@vmware.com> References: <20190201134535.2979-1-tstoyanov@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 In order to reuse the code which creates / deletes tracing instances, these two functions are refactotred. A new ones are implemented: make_one_instances() and tracecmd_remove_one_instance(). Signed-off-by: Tzvetomir Stoyanov --- tracecmd/trace-record.c | 54 +++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index 5b763ad..6d67858 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -4256,49 +4256,57 @@ static void clear_func_filters(void) } } -static void make_instances(void) +static void make_one_instance(struct buffer_instance *instance) { - struct buffer_instance *instance; struct stat st; char *path; int ret; + path = get_instance_dir(instance); + ret = stat(path, &st); + if (ret < 0) { + ret = mkdir(path, 0777); + if (ret < 0) + die("mkdir %s", path); + } else + /* Don't delete instances that already exist */ + instance->flags |= BUFFER_FL_KEEP; + tracecmd_put_tracing_file(path); + +} + +static void make_instances(void) +{ + struct buffer_instance *instance; + for_each_instance(instance) { if (instance->flags & BUFFER_FL_GUEST) continue; + make_one_instance(instance); + } +} - path = get_instance_dir(instance); - ret = stat(path, &st); - if (ret < 0) { - ret = mkdir(path, 0777); - if (ret < 0) - die("mkdir %s", path); - } else - /* Don't delete instances that already exist */ - instance->flags |= BUFFER_FL_KEEP; - tracecmd_put_tracing_file(path); +static void tracecmd_remove_one_instance(struct buffer_instance *instance) +{ + char *path; + + if (instance->tracing_on_fd > 0) { + close(instance->tracing_on_fd); + instance->tracing_on_fd = 0; } + path = get_instance_dir(instance); + tracecmd_put_tracing_file(path); } void tracecmd_remove_instances(void) { struct buffer_instance *instance; - char *path; - int ret; for_each_instance(instance) { /* Only delete what we created */ if (instance->flags & (BUFFER_FL_KEEP | BUFFER_FL_GUEST)) continue; - if (instance->tracing_on_fd > 0) { - close(instance->tracing_on_fd); - instance->tracing_on_fd = 0; - } - path = get_instance_dir(instance); - ret = rmdir(path); - if (ret < 0) - die("rmdir %s", path); - tracecmd_put_tracing_file(path); + tracecmd_remove_one_instance(instance); } }