From: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org
Subject: [PATCH v4 4/8] libtracefs: Add new API to check if instance exists
Date: Tue, 17 Nov 2020 09:45:53 +0200 [thread overview]
Message-ID: <20201117074557.180602-5-tz.stoyanov@gmail.com> (raw)
In-Reply-To: <20201117074557.180602-1-tz.stoyanov@gmail.com>
A new API is implemented:
tracefs_instance_exists()
which can be used to check if ftrace instance with given name exists in
the system.
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
include/tracefs/tracefs.h | 1 +
lib/tracefs/tracefs-instance.c | 22 +++++++++++++++++++++-
utest/tracefs-utest.c | 2 ++
3 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/include/tracefs/tracefs.h b/include/tracefs/tracefs.h
index 1cf8de48..ef806d3c 100644
--- a/include/tracefs/tracefs.h
+++ b/include/tracefs/tracefs.h
@@ -33,6 +33,7 @@ int tracefs_instance_file_write(struct tracefs_instance *instance,
char *tracefs_instance_file_read(struct tracefs_instance *instance,
char *file, int *psize);
+bool tracefs_instance_exists(const char *name);
bool tracefs_file_exists(struct tracefs_instance *instance, char *name);
bool tracefs_dir_exists(struct tracefs_instance *instance, char *name);
diff --git a/lib/tracefs/tracefs-instance.c b/lib/tracefs/tracefs-instance.c
index e37d93d1..06f33c35 100644
--- a/lib/tracefs/tracefs-instance.c
+++ b/lib/tracefs/tracefs-instance.c
@@ -257,7 +257,10 @@ static bool check_file_exists(struct tracefs_instance *instance,
int ret;
path = tracefs_instance_get_dir(instance);
- snprintf(file, PATH_MAX, "%s/%s", path, name);
+ if (name)
+ snprintf(file, PATH_MAX, "%s/%s", path, name);
+ else
+ snprintf(file, PATH_MAX, "%s", path);
tracefs_put_tracing_file(path);
ret = stat(file, &st);
if (ret < 0)
@@ -266,6 +269,23 @@ static bool check_file_exists(struct tracefs_instance *instance,
return !dir == !S_ISDIR(st.st_mode);
}
+/**
+ * tracefs_instance_exists - Check an instance with given name exists
+ * @name: name of the instance
+ *
+ * Returns true if the instance exists, false otherwise
+ *
+ */
+bool tracefs_instance_exists(const char *name)
+{
+ char file[PATH_MAX];
+
+ if (!name)
+ return false;
+ snprintf(file, PATH_MAX, "instances/%s", name);
+ return check_file_exists(NULL, file, true);
+}
+
/**
* tracefs_file_exists - Check if a file with given name exists in given instance
* @instance: ftrace instance, can be NULL for the top instance
diff --git a/utest/tracefs-utest.c b/utest/tracefs-utest.c
index b5296963..2febdb88 100644
--- a/utest/tracefs-utest.c
+++ b/utest/tracefs-utest.c
@@ -197,6 +197,7 @@ static void test_instance_file(void)
CU_TEST(asprintf(&inst_dir, "%s/instances/%s", tdir, name) > 0);
CU_TEST(stat(inst_dir, &st) != 0);
+ CU_TEST(tracefs_instance_exists(name) == false);
instance = tracefs_instance_alloc(name);
CU_TEST(instance != NULL);
CU_TEST(stat(inst_dir, &st) != 0);
@@ -205,6 +206,7 @@ static void test_instance_file(void)
CU_TEST(strcmp(inst_name, name) == 0);
CU_TEST(tracefs_instance_create(instance) == 0);
+ CU_TEST(tracefs_instance_exists(name) == true);
CU_TEST(stat(inst_dir, &st) == 0);
CU_TEST(S_ISDIR(st.st_mode));
--
2.28.0
next prev parent reply other threads:[~2020-11-17 7:46 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-17 7:45 [PATCH v4 0/8] libtracefs fixes and improvements Tzvetomir Stoyanov (VMware)
2020-11-17 7:45 ` [PATCH v4 1/8] trace-cmd: Change tracefs.h include path Tzvetomir Stoyanov (VMware)
2020-11-17 7:45 ` [PATCH v4 2/8] libtracefs: Change get name API to return constant string Tzvetomir Stoyanov (VMware)
2020-11-17 7:45 ` [PATCH v4 3/8] libtracefs: Use tracefs_list_free() API Tzvetomir Stoyanov (VMware)
2020-11-17 7:45 ` Tzvetomir Stoyanov (VMware) [this message]
2020-11-17 7:45 ` [PATCH v4 5/8] libtracefs: Combine allocate and create APIs into one Tzvetomir Stoyanov (VMware)
2020-11-18 21:44 ` Steven Rostedt
2020-11-18 21:46 ` [PATCH v4.1 - 5.1/8] libtracefs: Use the permissions of the instances directory for instances Steven Rostedt
2020-11-19 15:07 ` Tzvetomir Stoyanov
2020-11-18 21:46 ` [PATCH v4.1 5.2/8] libtracefs: Combine allocate and create APIs into one Steven Rostedt
2020-11-17 7:45 ` [PATCH v4 6/8] libtracefs: Add new tracefs API tracefs_instances_walk() Tzvetomir Stoyanov (VMware)
2020-11-17 7:45 ` [PATCH v4 7/8] trace-cmd: Add new libtrasefs API to get the current trace clock Tzvetomir Stoyanov (VMware)
2020-11-17 7:45 ` [PATCH v4 8/8] libtracefs: Hide non API functions Tzvetomir Stoyanov (VMware)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201117074557.180602-5-tz.stoyanov@gmail.com \
--to=tz.stoyanov@gmail.com \
--cc=linux-trace-devel@vger.kernel.org \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).