diff mbox series

[v1,1/3] libs/libnewipc: Alter get_used_queues api

Message ID 1628135323-3722-1-git-send-email-xuyang2018.jy@fujitsu.com
State Accepted
Headers show
Series [v1,1/3] libs/libnewipc: Alter get_used_queues api | expand

Commit Message

Yang Xu Aug. 5, 2021, 3:48 a.m. UTC
Rename get_used_queues as get_used_sysvipc and add a proc file argument, so we can use
GET_USED_QUEQUES() and GET_USED_SEGMENTS() to get the corresponding used sysvipc resource
total. Since no new api cases used get_used_queues(), we don't need to change anything.

Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 include/libnewipc.h           |  6 ++++--
 libs/libltpnewipc/libnewipc.c | 16 ++++++++--------
 2 files changed, 12 insertions(+), 10 deletions(-)

Comments

Li Wang Aug. 5, 2021, 1:03 p.m. UTC | #1
Hi Xu,

I have just gone through all of the discussions on this topic
and am feeling this method is not quite perfect but currently
I have no better idea.

So, I agree to apply the method and see how it performs in
real test executing.

Reviewed-by: Li Wang <liwang@redhat.com>
Yang Xu Aug. 6, 2021, 1:50 a.m. UTC | #2
Hi Li
> Hi Xu,
>
> I have just gone through all of the discussions on this topic
> and am feeling this method is not quite perfect but currently
> I have no better idea.
I guess a better idea should be using .sysvipc flag. But here, we  use 
the easiest way to slove this problem. In the future, we can add this 
feature.
>
> So, I agree to apply the method and see how it performs in
> real test executing.
Thanks. Let's listen whether have user complains about these two cases
after this fix.
>
> Reviewed-by: Li Wang <liwang@redhat.com <mailto:liwang@redhat.com>>
Thanks for your review. I have pushed this patchset.

Best Regards
Yang Xu
>
> --
> Regards,
> Li Wang
diff mbox series

Patch

diff --git a/include/libnewipc.h b/include/libnewipc.h
index 075364f85..52e054c51 100644
--- a/include/libnewipc.h
+++ b/include/libnewipc.h
@@ -49,9 +49,11 @@  key_t getipckey(const char *file, const int lineno);
 #define GETIPCKEY() \
 	getipckey(__FILE__, __LINE__)
 
-int get_used_queues(const char *file, const int lineno);
+int get_used_sysvipc(const char *file, const int lineno, const char *sysvipc_file);
 #define GET_USED_QUEUES() \
-	get_used_queues(__FILE__, __LINE__)
+	get_used_sysvipc(__FILE__, __LINE__, "/proc/sysvipc/msg")
+#define GET_USED_SEGMENTS() \
+	get_used_sysvipc(__FILE__, __LINE__, "/proc/sysvipc/shm")
 
 void *probe_free_addr(const char *file, const int lineno);
 #define PROBE_FREE_ADDR() \
diff --git a/libs/libltpnewipc/libnewipc.c b/libs/libltpnewipc/libnewipc.c
index d0974bbe0..583291ee0 100644
--- a/libs/libltpnewipc/libnewipc.c
+++ b/libs/libltpnewipc/libnewipc.c
@@ -48,25 +48,25 @@  key_t getipckey(const char *file, const int lineno)
 	return key;
 }
 
-int get_used_queues(const char *file, const int lineno)
+int get_used_sysvipc(const char *file, const int lineno, const char *sysvipc_file)
 {
 	FILE *fp;
-	int used_queues = -1;
+	int used = -1;
 	char buf[BUFSIZE];
 
-	fp = safe_fopen(file, lineno, NULL, "/proc/sysvipc/msg", "r");
+	fp = safe_fopen(file, lineno, NULL, sysvipc_file, "r");
 
 	while (fgets(buf, BUFSIZE, fp) != NULL)
-		used_queues++;
+		used++;
 
 	fclose(fp);
 
-	if (used_queues < 0) {
-		tst_brk(TBROK, "can't read /proc/sysvipc/msg to get "
-			"used message queues at %s:%d", file, lineno);
+	if (used < 0) {
+		tst_brk(TBROK, "can't read %s to get used sysvipc resource total "
+			"at %s:%d", sysvipc_file, file, lineno);
 	}
 
-	return used_queues;
+	return used;
 }
 
 void *probe_free_addr(const char *file, const int lineno)