Linux Test Project
 help / color / mirror / Atom feed
* Re: [LTP] aio_cancel: Fix incorrect strerror() usage
  2026-04-28 13:32 [LTP] [PATCH " Martin Doucha
@ 2026-04-28 14:44 ` linuxtestproject.agent
  0 siblings, 0 replies; 10+ messages in thread
From: linuxtestproject.agent @ 2026-04-28 14:44 UTC (permalink / raw)
  To: Martin Doucha; +Cc: ltp

Hi Martin,

--- [PATCH 1/2] ---

On 2026-04-28, Martin Doucha wrote:
> aio_cancel: Fix incorrect strerror() usage

This is fixing a real bug but both patches in this series are missing
Fixes: tags.

--- [PATCH 2/2] ---

On 2026-04-28, Martin Doucha wrote:
> aio_cancel_6-1: Rewrite test

> +	if (gret != AIO_CANCELED) {
> +		printf(TNAME " Unexpected aio_cancel() return value: %s\n",
> +			strerror(gret));

strerror() expects an errno value; AIO_CANCELED, AIO_NOTCANCELED, and
AIO_ALLDONE are not errno values (they are 0, 1, 2 on Linux, mapping to
"Success", "Operation not permitted", "No such file or directory").
Use "%d" to print the raw integer instead.

Pre-existing issues noticed in the surrounding code (not introduced
by this patch):

- 5-1.c:70, 7-1.c:56 — nanosleep() used for synchronization in a
  polling loop (sleep-based sync).

---
Note:

Our agent completed the review of the patch. The agent can sometimes
produce false positives although often its findings are genuine. If you
find issues with the review, please comment this email or ignore the
suggestions.

Regards,
LTP AI Reviewer

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

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

* [LTP] [PATCH v2 1/2] aio_cancel: Fix incorrect strerror() usage
@ 2026-04-29 14:53 Martin Doucha
  2026-04-29 14:53 ` [LTP] [PATCH v2 2/2] aio_cancel_6-1: Rewrite test Martin Doucha
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: Martin Doucha @ 2026-04-29 14:53 UTC (permalink / raw)
  To: ltp

Each call of strerror() invalidates the previous return value. Split
print calls to avoid calling strerror() twice in the argument list.

Also remove strerror() calls on aio_cancel() return value because
the function does not return errno constants directly.

Fixes: 690b37453 ("aio_cancel_5-1: Rewrite test")
Fixes: 220f579cd ("aio_cancel_7-1: Rewrite test")
Signed-off-by: Martin Doucha <mdoucha@suse.cz>
---

Changes since v1:
- Removed strerror() calls on aio_cancel() return value
- Added Fixes: tags

 .../conformance/interfaces/aio_cancel/5-1.c              | 9 +++++----
 .../conformance/interfaces/aio_cancel/7-1.c              | 9 +++++----
 2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/testcases/open_posix_testsuite/conformance/interfaces/aio_cancel/5-1.c b/testcases/open_posix_testsuite/conformance/interfaces/aio_cancel/5-1.c
index dd5b0bbfb..0220acd7c 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/aio_cancel/5-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/aio_cancel/5-1.c
@@ -95,8 +95,8 @@ int test_main(int argc PTS_ATTRIBUTE_UNUSED, char **argv PTS_ATTRIBUTE_UNUSED)
 	}
 
 	if (ret != AIO_NOTCANCELED) {
-		printf(TNAME " Unexpected aio_cancel() return value: %s\n",
-			strerror(ret));
+		printf(TNAME " Unexpected aio_cancel() return value: %d\n",
+			ret);
 		cleanup_aio(fds, aiocb, BUF_NB);
 		return PTS_FAIL;
 	}
@@ -131,8 +131,9 @@ int test_main(int argc PTS_ATTRIBUTE_UNUSED, char **argv PTS_ATTRIBUTE_UNUSED)
 		}
 
 		if (ret != exp_ret) {
-			printf(TNAME " Bad task #%d result: %s (expected %s)\n",
-				i, strerror(ret), strerror(exp_ret));
+			printf(TNAME " Bad task #%d result: %s",
+				i, strerror(ret));
+			printf(" (expected %s)\n", strerror(exp_ret));
 			cleanup_aio(fds, aiocb, BUF_NB);
 			return PTS_FAIL;
 		}
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/aio_cancel/7-1.c b/testcases/open_posix_testsuite/conformance/interfaces/aio_cancel/7-1.c
index 36ce8bb12..4bb9d8d09 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/aio_cancel/7-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/aio_cancel/7-1.c
@@ -89,8 +89,8 @@ int test_main(int argc PTS_ATTRIBUTE_UNUSED, char **argv PTS_ATTRIBUTE_UNUSED)
 	}
 
 	if (gret != AIO_NOTCANCELED) {
-		printf(TNAME " Unexpected aio_cancel() return value: %s\n",
-			strerror(gret));
+		printf(TNAME " Unexpected aio_cancel() return value: %d\n",
+			gret);
 		cleanup_aio(fds, aiocb, BUF_NB);
 		return PTS_FAIL;
 	}
@@ -118,8 +118,9 @@ int test_main(int argc PTS_ATTRIBUTE_UNUSED, char **argv PTS_ATTRIBUTE_UNUSED)
 		}
 
 		if (ret != exp_ret) {
-			printf(TNAME " Bad task #%d result: %s (expected %s)\n",
-				i, strerror(ret), strerror(exp_ret));
+			printf(TNAME " Bad task #%d result: %s",
+				i, strerror(ret));
+			printf(" (expected %s)\n", strerror(exp_ret));
 			cleanup_aio(fds, aiocb, BUF_NB);
 			return PTS_FAIL;
 		}
-- 
2.53.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

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

* [LTP] [PATCH v2 2/2] aio_cancel_6-1: Rewrite test
  2026-04-29 14:53 [LTP] [PATCH v2 1/2] aio_cancel: Fix incorrect strerror() usage Martin Doucha
@ 2026-04-29 14:53 ` Martin Doucha
  2026-05-06 12:23   ` Andrea Cervesato via ltp
  2026-05-06 16:36   ` Cyril Hrubis
  2026-04-29 15:20 ` [LTP] aio_cancel: Fix incorrect strerror() usage linuxtestproject.agent
                   ` (3 subsequent siblings)
  4 siblings, 2 replies; 10+ messages in thread
From: Martin Doucha @ 2026-04-29 14:53 UTC (permalink / raw)
  To: ltp

The test schedules multiple async writes into a file and then hopes that
at least one will block long enough that aio_cancel() will cancel it.
Use a socket pair instead of a file to force async writes to block
indefinitely, then cancel one of the blocked writes.  This fixes a race
condition where aio_cancel() could be called after the target write
has already finished. Also improve result checks to verify that
non-canceled writes are still pending.

Signed-off-by: Martin Doucha <mdoucha@suse.cz>
---

Changes since v1: Removed strerror() call on aio_cancel() return value

 .../conformance/interfaces/aio_cancel/6-1.c   | 135 +++++++-----------
 1 file changed, 48 insertions(+), 87 deletions(-)

diff --git a/testcases/open_posix_testsuite/conformance/interfaces/aio_cancel/6-1.c b/testcases/open_posix_testsuite/conformance/interfaces/aio_cancel/6-1.c
index 2e3d64742..623dcd8e5 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/aio_cancel/6-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/aio_cancel/6-1.c
@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2004, Bull SA. All rights reserved.
+ * Copyright (c) 2026 SUSE LLC
  * Created by:  Laurent.Vivier@bull.net
  * This file is licensed under the GPL license.  For the full content
  * of this license, see the COPYING file at the top level of this
@@ -14,128 +15,88 @@
  *
  * method:
  *
- *	queue a lot of aio_write() to a given fildes.
- *	try to cancel the last one submited
- *	if aio_error() is ECANCELED and aio_cancel() is AIO_CANCELED
- *	test is passed
- *	if aio_error() is ECANCELED and aio_cancel() is NOT AIO_CANCELED
- *	test is failed
- *	if there is no aio_error() with ECANCELED and
- *	aio_cancel() is AIO_CANCELED
- *	test is failed
- *	otherwise test is unresolved
+ *	queue multiple aio_write()s to a given socket
+ *	try to cancel a task which hasn't been started yet
+ *	if aio_cancel() return value is not AIO_CANCELED, the test failed
+ *	for blocked tasks, aio_error() must be:
+ *	- ECANCELED if aio_cancel() was called on it
+ *	- EINPROGRESS otherwise
+ *	if all aio_error() values match, the test passed, otherwise it failed
  *
  */
 
-#include <stdio.h>
-#include <sys/types.h>
 #include <unistd.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <string.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <aio.h>
 
 #include "posixtest.h"
-#include "tempfile.h"
+#include "aio_test.h"
 
 #define TNAME "aio_cancel/6-1.c"
 
-#define BUF_NB		128
-#define BUF_SIZE	1024
+#define WRITE_COUNT	8
+#define MAX_COMPLETE	3
+#define CANCELED_TASK	5
+
+static int fds[2];
+static struct aiocb aiocb[WRITE_COUNT];
 
 int test_main(int argc PTS_ATTRIBUTE_UNUSED, char **argv PTS_ATTRIBUTE_UNUSED)
 {
-	char tmpfname[PATH_MAX];
-	int fd;
-	struct aiocb *aiocb[BUF_NB];
 	int i;
-	int in_progress;
 	int gret;
 
 	if (sysconf(_SC_ASYNCHRONOUS_IO) < 200112L)
 		return PTS_UNSUPPORTED;
 
-	PTS_GET_TMP_FILENAME(tmpfname, "pts_aio_cancel_6_1");
-	unlink(tmpfname);
-	fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR);
-	if (fd == -1) {
-		printf(TNAME " Error at open(): %s\n", strerror(errno));
+	if (setup_aio(TNAME, fds, aiocb, WRITE_COUNT))
 		return PTS_UNRESOLVED;
-	}
-
-	unlink(tmpfname);
 
 	/* create AIO req */
-
-	for (i = 0; i < BUF_NB; i++) {
-		aiocb[i] = calloc(1, sizeof(struct aiocb));
-		if (aiocb[i] == NULL) {
-			printf(TNAME " Error at malloc(): %s\n",
-			       strerror(errno));
-			return PTS_UNRESOLVED;
-		}
-		aiocb[i]->aio_fildes = fd;
-		aiocb[i]->aio_buf = malloc(BUF_SIZE);
-		if (aiocb[i]->aio_buf == NULL) {
-			printf(TNAME " Error at malloc(): %s\n",
-			       strerror(errno));
-			return PTS_UNRESOLVED;
-		}
-		aiocb[i]->aio_nbytes = BUF_SIZE;
-		aiocb[i]->aio_offset = 0;
-		aiocb[i]->aio_sigevent.sigev_notify = SIGEV_NONE;
-
-		if (aio_write(aiocb[i]) == -1) {
+	for (i = 0; i < WRITE_COUNT; i++) {
+		if (aio_write(&aiocb[i]) == -1) {
 			printf(TNAME " loop %d: Error at aio_write(): %s\n",
-			       i, strerror(errno));
+				i, strerror(errno));
+			cleanup_aio(fds, aiocb, WRITE_COUNT);
 			return PTS_FAIL;
 		}
 	}
 
 	/* try to cancel the last one queued */
-
-	gret = aio_cancel(fd, aiocb[i - 1]);
+	gret = aio_cancel(fds[0], &aiocb[CANCELED_TASK]);
 
 	if (gret == -1) {
 		printf(TNAME " Error at aio_cancel(): %s\n", strerror(errno));
+		cleanup_aio(fds, aiocb, WRITE_COUNT);
 		return PTS_FAIL;
 	}
 
-	close(fd);
-
-	do {
-		in_progress = 0;
-		for (i = 0; i < BUF_NB; i++) {
-			int ret;
-
-			ret = (aio_error(aiocb[i]));
-
-			if (ret == -1) {
-				printf(TNAME " Error at aio_error(): %s\n",
-				       strerror(errno));
-				return PTS_FAIL;
-			} else if (ret == EINPROGRESS)
-				in_progress = 1;
-			else if (ret == ECANCELED) {
-				if (gret == AIO_CANCELED) {
-					printf("Test PASSED\n");
-					return PTS_PASS;
-				}
-
-				printf(TNAME
-				       " aio_cancel() is not AIO_CANCELED\n");
-				return PTS_FAIL;
-			}
+	if (gret != AIO_CANCELED) {
+		printf(TNAME " Unexpected aio_cancel() return value %d\n",
+			gret);
+		cleanup_aio(fds, aiocb, WRITE_COUNT);
+		return PTS_FAIL;
+	}
+
+	for (i = MAX_COMPLETE; i < WRITE_COUNT; i++) {
+		int exp_ret = (i == CANCELED_TASK) ? ECANCELED : EINPROGRESS;
+		int ret = aio_error(&aiocb[i]);
+
+		if (ret == -1) {
+			printf(TNAME " Error at aio_error(): %s\n",
+				strerror(errno));
+			cleanup_aio(fds, aiocb, WRITE_COUNT);
+			return PTS_FAIL;
 		}
-	} while (in_progress);
 
-	if (gret == AIO_CANCELED) {
-		printf(TNAME
-		       " aio_cancel() is AIO_CANCELED without ECANCELED\n");
-		return PTS_FAIL;
+		if (ret != exp_ret) {
+			printf(TNAME " Bad task #%d result %s",
+				i, strerror(ret));
+			printf(" (expected: %s)\n", strerror(exp_ret));
+			cleanup_aio(fds, aiocb, WRITE_COUNT);
+			return PTS_FAIL;
+		}
 	}
 
-	return PTS_UNRESOLVED;
+	cleanup_aio(fds, aiocb, WRITE_COUNT);
+	printf("Test PASSED\n");
+	return PTS_PASS;
 }
-- 
2.53.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

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

* Re: [LTP] aio_cancel: Fix incorrect strerror() usage
  2026-04-29 14:53 [LTP] [PATCH v2 1/2] aio_cancel: Fix incorrect strerror() usage Martin Doucha
  2026-04-29 14:53 ` [LTP] [PATCH v2 2/2] aio_cancel_6-1: Rewrite test Martin Doucha
@ 2026-04-29 15:20 ` linuxtestproject.agent
  2026-05-06 12:22 ` [LTP] [PATCH v2 1/2] " Andrea Cervesato via ltp
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: linuxtestproject.agent @ 2026-04-29 15:20 UTC (permalink / raw)
  To: Martin Doucha; +Cc: ltp

Hi Martin,

--- [PATCH 2/2] ---

On Wed, 29 Apr 2026 16:53:12 +0200, Martin Doucha wrote:
> aio_cancel_6-1: Rewrite test
>
> The test schedules multiple async writes into a file and then hopes that
> at least one will block long enough that aio_cancel() will cancel it.
> [...]
> This fixes a race condition where aio_cancel() could be called after the
> target write has already finished. [...]
>
> Signed-off-by: Martin Doucha <mdoucha@suse.cz>

The commit body says this fixes a race condition, so a Fixes: tag is
required. Patch 1/2 in this same series correctly uses Fixes: tags for
analogous rewrite-as-bugfix commits to 5-1.c and 7-1.c. Please add a
Fixes: referencing the commit that introduced the original 6-1.c.

Pre-existing issues noticed in the surrounding code (not introduced
by this patch):

- aio_cancel/5-1.c — Uses nanosleep() in a spin-wait loop for
  synchronization.

---
Note:

Our agent completed the review of the patch. The full review can be
found at: https://patchwork.ozlabs.org/project/ltp/list/?series=502088

The agent can sometimes produce false positives although often its
findings are genuine. If you find issues with the review, please
comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

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

* Re: [LTP] [PATCH v2 1/2] aio_cancel: Fix incorrect strerror() usage
  2026-04-29 14:53 [LTP] [PATCH v2 1/2] aio_cancel: Fix incorrect strerror() usage Martin Doucha
  2026-04-29 14:53 ` [LTP] [PATCH v2 2/2] aio_cancel_6-1: Rewrite test Martin Doucha
  2026-04-29 15:20 ` [LTP] aio_cancel: Fix incorrect strerror() usage linuxtestproject.agent
@ 2026-05-06 12:22 ` Andrea Cervesato via ltp
  2026-05-06 15:27 ` Cyril Hrubis
  2026-05-07  7:34 ` Andrea Cervesato via ltp
  4 siblings, 0 replies; 10+ messages in thread
From: Andrea Cervesato via ltp @ 2026-05-06 12:22 UTC (permalink / raw)
  To: Martin Doucha; +Cc: ltp

Reviewed-by: Andrea Cervesato <andrea.cervesato@suse.com>

--
Andrea Cervesato
SUSE QE Automation Engineer Linux
andrea.cervesato@suse.com

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

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

* Re: [LTP] [PATCH v2 2/2] aio_cancel_6-1: Rewrite test
  2026-04-29 14:53 ` [LTP] [PATCH v2 2/2] aio_cancel_6-1: Rewrite test Martin Doucha
@ 2026-05-06 12:23   ` Andrea Cervesato via ltp
  2026-05-06 16:36   ` Cyril Hrubis
  1 sibling, 0 replies; 10+ messages in thread
From: Andrea Cervesato via ltp @ 2026-05-06 12:23 UTC (permalink / raw)
  To: Martin Doucha; +Cc: ltp

Reviewed-by: Andrea Cervesato <andrea.cervesato@suse.com>

--
Andrea Cervesato
SUSE QE Automation Engineer Linux
andrea.cervesato@suse.com

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

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

* Re: [LTP] [PATCH v2 1/2] aio_cancel: Fix incorrect strerror() usage
  2026-04-29 14:53 [LTP] [PATCH v2 1/2] aio_cancel: Fix incorrect strerror() usage Martin Doucha
                   ` (2 preceding siblings ...)
  2026-05-06 12:22 ` [LTP] [PATCH v2 1/2] " Andrea Cervesato via ltp
@ 2026-05-06 15:27 ` Cyril Hrubis
  2026-05-07  7:34 ` Andrea Cervesato via ltp
  4 siblings, 0 replies; 10+ messages in thread
From: Cyril Hrubis @ 2026-05-06 15:27 UTC (permalink / raw)
  To: Martin Doucha; +Cc: ltp

Hi!
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

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

* Re: [LTP] [PATCH v2 2/2] aio_cancel_6-1: Rewrite test
  2026-04-29 14:53 ` [LTP] [PATCH v2 2/2] aio_cancel_6-1: Rewrite test Martin Doucha
  2026-05-06 12:23   ` Andrea Cervesato via ltp
@ 2026-05-06 16:36   ` Cyril Hrubis
  2026-05-07  7:32     ` Andrea Cervesato via ltp
  1 sibling, 1 reply; 10+ messages in thread
From: Cyril Hrubis @ 2026-05-06 16:36 UTC (permalink / raw)
  To: Martin Doucha; +Cc: ltp

Hi!
>  
>  	/* try to cancel the last one queued */
           ^
	   This comment is no longer true, right?

I guess that we should just remove it.


Otherwise:

Reviewed-by: Cyril Hrubis <chrubis@suse.cz>

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

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

* Re: [LTP] [PATCH v2 2/2] aio_cancel_6-1: Rewrite test
  2026-05-06 16:36   ` Cyril Hrubis
@ 2026-05-07  7:32     ` Andrea Cervesato via ltp
  0 siblings, 0 replies; 10+ messages in thread
From: Andrea Cervesato via ltp @ 2026-05-07  7:32 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: ltp

Hi Cyril,

> Hi!
> >  
> >  	/* try to cancel the last one queued */
>            ^
> 	   This comment is no longer true, right?
> 
> I guess that we should just remove it.
> 

I can remove it before merge.

Regards,
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
andrea.cervesato@suse.com

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

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

* Re: [LTP] [PATCH v2 1/2] aio_cancel: Fix incorrect strerror() usage
  2026-04-29 14:53 [LTP] [PATCH v2 1/2] aio_cancel: Fix incorrect strerror() usage Martin Doucha
                   ` (3 preceding siblings ...)
  2026-05-06 15:27 ` Cyril Hrubis
@ 2026-05-07  7:34 ` Andrea Cervesato via ltp
  4 siblings, 0 replies; 10+ messages in thread
From: Andrea Cervesato via ltp @ 2026-05-07  7:34 UTC (permalink / raw)
  To: Martin Doucha; +Cc: ltp

Merged, Thanks!

--
Andrea Cervesato
SUSE QE Automation Engineer Linux
andrea.cervesato@suse.com

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

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

end of thread, other threads:[~2026-05-07  7:36 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-29 14:53 [LTP] [PATCH v2 1/2] aio_cancel: Fix incorrect strerror() usage Martin Doucha
2026-04-29 14:53 ` [LTP] [PATCH v2 2/2] aio_cancel_6-1: Rewrite test Martin Doucha
2026-05-06 12:23   ` Andrea Cervesato via ltp
2026-05-06 16:36   ` Cyril Hrubis
2026-05-07  7:32     ` Andrea Cervesato via ltp
2026-04-29 15:20 ` [LTP] aio_cancel: Fix incorrect strerror() usage linuxtestproject.agent
2026-05-06 12:22 ` [LTP] [PATCH v2 1/2] " Andrea Cervesato via ltp
2026-05-06 15:27 ` Cyril Hrubis
2026-05-07  7:34 ` Andrea Cervesato via ltp
  -- strict thread matches above, loose matches on Subject: below --
2026-04-28 13:32 [LTP] [PATCH " Martin Doucha
2026-04-28 14:44 ` [LTP] " linuxtestproject.agent

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox