All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH v1 1/3] libs/libnewipc: Alter get_used_queues api
@ 2021-08-05  3:48 Yang Xu
  2021-08-05  3:48 ` [LTP] [PATCH v1 2/3] syscalls/shmget03: Create shared memory segment dynamically instead of hardcode Yang Xu
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Yang Xu @ 2021-08-05  3:48 UTC (permalink / raw)
  To: ltp

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(-)

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@%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)
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [LTP] [PATCH v1 2/3] syscalls/shmget03: Create shared memory segment dynamically instead of hardcode
  2021-08-05  3:48 [LTP] [PATCH v1 1/3] libs/libnewipc: Alter get_used_queues api Yang Xu
@ 2021-08-05  3:48 ` Yang Xu
  2021-08-05  3:48 ` [LTP] [PATCH v1 3/3] syscalls/msgget03: Create message queues " Yang Xu
  2021-08-05 13:03 ` [LTP] [PATCH v1 1/3] libs/libnewipc: Alter get_used_queues api Li Wang
  2 siblings, 0 replies; 5+ messages in thread
From: Yang Xu @ 2021-08-05  3:48 UTC (permalink / raw)
  To: ltp

Before this patch, we don't consider this situation that system has consumed shared memory
segments. So we hit the ENOSPC error unexpectedly in setup.

Use GET_USED_SEGMENTS() to get the used shared memory segments, so we can trigger the
ENOSPC error correctly(just hit the limit) even current environment has consumed some
shared memory segments.

I don't use this api in verify function since we don't support run cases in parallel and
we should assume this situation that this case is the only case to use(free or alloc) sysv
ipc resource at that time.

Fixes: #842
Fixes: 4dc493b44 ("syscalls/shmget*: Convert into new api")
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 testcases/kernel/syscalls/ipc/shmget/shmget03.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/testcases/kernel/syscalls/ipc/shmget/shmget03.c b/testcases/kernel/syscalls/ipc/shmget/shmget03.c
index efbc465e1..8b157e439 100644
--- a/testcases/kernel/syscalls/ipc/shmget/shmget03.c
+++ b/testcases/kernel/syscalls/ipc/shmget/shmget03.c
@@ -22,7 +22,7 @@
 #include "libnewipc.h"
 
 static int *queues;
-static int maxshms, queue_cnt;
+static int maxshms, queue_cnt, used_cnt;
 static key_t shmkey;
 
 static void verify_shmget(void)
@@ -36,11 +36,13 @@ static void setup(void)
 	int res, num;
 
 	shmkey = GETIPCKEY();
-
+	used_cnt = GET_USED_SEGMENTS();
+	tst_res(TINFO, "Current environment %d shared memory segments are already in use",
+		used_cnt);
 	SAFE_FILE_SCANF("/proc/sys/kernel/shmmni", "%i", &maxshms);
 
-	queues = SAFE_MALLOC(maxshms * sizeof(int));
-	for (num = 0; num < maxshms; num++) {
+	queues = SAFE_MALLOC((maxshms - used_cnt) * sizeof(int));
+	for (num = 0; num < maxshms - used_cnt; num++) {
 		res = shmget(shmkey + num, SHM_SIZE, IPC_CREAT | IPC_EXCL | SHM_RW);
 		if (res == -1)
 			tst_brk(TBROK | TERRNO, "shmget failed unexpectedly");
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [LTP] [PATCH v1 3/3] syscalls/msgget03: Create message queues dynamically instead of hardcode
  2021-08-05  3:48 [LTP] [PATCH v1 1/3] libs/libnewipc: Alter get_used_queues api Yang Xu
  2021-08-05  3:48 ` [LTP] [PATCH v1 2/3] syscalls/shmget03: Create shared memory segment dynamically instead of hardcode Yang Xu
@ 2021-08-05  3:48 ` Yang Xu
  2021-08-05 13:03 ` [LTP] [PATCH v1 1/3] libs/libnewipc: Alter get_used_queues api Li Wang
  2 siblings, 0 replies; 5+ messages in thread
From: Yang Xu @ 2021-08-05  3:48 UTC (permalink / raw)
  To: ltp

It is the same problem as shmget03. Use the same way to fix this problem
that hit the ENOSPC problem unexpectedly in setup.

Fixes: #842
Fixes: 19a07c445 ("ipc/msgget03: Make sure we get ENOSPC error after..")
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 testcases/kernel/syscalls/ipc/msgget/msgget03.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/testcases/kernel/syscalls/ipc/msgget/msgget03.c b/testcases/kernel/syscalls/ipc/msgget/msgget03.c
index ab5714cdc..711886e17 100644
--- a/testcases/kernel/syscalls/ipc/msgget/msgget03.c
+++ b/testcases/kernel/syscalls/ipc/msgget/msgget03.c
@@ -21,7 +21,7 @@
 #include "tst_safe_sysv_ipc.h"
 #include "libnewipc.h"
 
-static int maxmsgs, queue_cnt;
+static int maxmsgs, queue_cnt, used_cnt;
 static int *queues;
 static key_t msgkey;
 
@@ -37,11 +37,15 @@ static void setup(void)
 
 	msgkey = GETIPCKEY();
 
+	used_cnt = GET_USED_QUEUES();
+	tst_res(TINFO, "Current environment %d message queues are already in use",
+		used_cnt);
+
 	SAFE_FILE_SCANF("/proc/sys/kernel/msgmni", "%i", &maxmsgs);
 
-	queues = SAFE_MALLOC(maxmsgs * sizeof(int));
+	queues = SAFE_MALLOC((maxmsgs - used_cnt) * sizeof(int));
 
-	for (num = 0; num < maxmsgs; num++) {
+	for (num = 0; num < maxmsgs - used_cnt; num++) {
 		res = msgget(msgkey + num, IPC_CREAT | IPC_EXCL);
 		if (res == -1)
 			tst_brk(TBROK | TERRNO, "msgget failed unexpectedly");
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [LTP] [PATCH v1 1/3] libs/libnewipc: Alter get_used_queues api
  2021-08-05  3:48 [LTP] [PATCH v1 1/3] libs/libnewipc: Alter get_used_queues api Yang Xu
  2021-08-05  3:48 ` [LTP] [PATCH v1 2/3] syscalls/shmget03: Create shared memory segment dynamically instead of hardcode Yang Xu
  2021-08-05  3:48 ` [LTP] [PATCH v1 3/3] syscalls/msgget03: Create message queues " Yang Xu
@ 2021-08-05 13:03 ` Li Wang
  2021-08-06  1:50   ` xuyang2018.jy
  2 siblings, 1 reply; 5+ messages in thread
From: Li Wang @ 2021-08-05 13:03 UTC (permalink / raw)
  To: ltp

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>

-- 
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20210805/81f576c7/attachment.htm>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [LTP] [PATCH v1 1/3] libs/libnewipc: Alter get_used_queues api
  2021-08-05 13:03 ` [LTP] [PATCH v1 1/3] libs/libnewipc: Alter get_used_queues api Li Wang
@ 2021-08-06  1:50   ` xuyang2018.jy
  0 siblings, 0 replies; 5+ messages in thread
From: xuyang2018.jy @ 2021-08-06  1:50 UTC (permalink / raw)
  To: ltp

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-08-06  1:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-05  3:48 [LTP] [PATCH v1 1/3] libs/libnewipc: Alter get_used_queues api Yang Xu
2021-08-05  3:48 ` [LTP] [PATCH v1 2/3] syscalls/shmget03: Create shared memory segment dynamically instead of hardcode Yang Xu
2021-08-05  3:48 ` [LTP] [PATCH v1 3/3] syscalls/msgget03: Create message queues " Yang Xu
2021-08-05 13:03 ` [LTP] [PATCH v1 1/3] libs/libnewipc: Alter get_used_queues api Li Wang
2021-08-06  1:50   ` xuyang2018.jy

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.