From patchwork Wed Jan 16 19:18:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzvetomir Stoyanov X-Patchwork-Id: 10766845 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 61F5714E5 for ; Wed, 16 Jan 2019 19:18:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4CC2228174 for ; Wed, 16 Jan 2019 19:18:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3D88A28C1C; Wed, 16 Jan 2019 19:18:49 +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 D1FE12880F for ; Wed, 16 Jan 2019 19:18:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730683AbfAPTSs (ORCPT ); Wed, 16 Jan 2019 14:18:48 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:35303 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730803AbfAPTSs (ORCPT ); Wed, 16 Jan 2019 14:18:48 -0500 Received: by mail-wm1-f67.google.com with SMTP id t200so3278786wmt.0 for ; Wed, 16 Jan 2019 11:18:47 -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=P4md0Hbd2K8zcQqaBCspqrsk6++sm8ZHmAlUqrqlhTw=; b=gB0t7ijqmSjt2s227qYBHOZGke85mlov46+y7OGx3xn6CGxOrYxxfQvEwo2K4dMMAe AB7Z5PbDEkYYBETxDd6pZfSItnqEzSZpxPyAOQbAyoUwuIJ9T2eORk9UHXp8uMsVjr64 hC+3QwFsPFDx5/cNYrGjtgdhYkJGu6Qpc2FH6nEB3XY7hgaSDRpn/boQ2xs4J24bNz4o kbKiU46wdWeRnPpAbD8g36HtXas6M44QFYT7pVGOrPodEO3D859ZbFA8+3eAcKlkisq8 qX1DkOEISOJqwSaO1esZl8zVmnkhCR1w/lE0x5HwOX3L46QZFF4maO8+yt1i9/9KMk/X NK7w== X-Gm-Message-State: AJcUukexO6ncwrGi1PUZxWOR7d0sFcWN6ocYv6cX1UOQMB+GLLvPd9Ws VKBDoZSmn1/4rVhVVg2CdvOHzS8n X-Google-Smtp-Source: ALg8bN7+PZnHNSVaC6N9FP05JEhYSBhqR577gDy7BLTMyDIrAIPTXOPHdEgt8s9sk03qepIfA/x+yw== X-Received: by 2002:a7b:c951:: with SMTP id i17mr9238875wml.70.1547666326760; Wed, 16 Jan 2019 11:18:46 -0800 (PST) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id p6sm98393345wrx.50.2019.01.16.11.18.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 16 Jan 2019 11:18:46 -0800 (PST) From: Tzvetomir Stoyanov To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH 6/7] trace-cmd: Refactored make_instances() and tracecmd_remove_instances() Date: Wed, 16 Jan 2019 21:18:37 +0200 Message-Id: <20190116191838.32127-7-tstoyanov@vmware.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190116191838.32127-1-tstoyanov@vmware.com> References: <20190116191838.32127-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 900d0d4..4c3df3d 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -4260,49 +4260,57 @@ static void clear_func_filters(void) } } -static void make_instances(void) +static void make_one_instances(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_instances(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); } }