Skip to contentSkip to conversation

Fix inotify{07,08} TBROK where it should TFAIL

PATCH New Cyril Hrubis 4 participants 12 messages May 26 Library code

lore
Share & tools
lore
#0 lore raw

cover Fix inotify{07,08} TBROK where it should TFAIL

Fixes regression cause by deda021818a4 ('inotify: modernize with SAFE_ wrappers')

v2: Fix all the typos

Cyril Hrubis (2):
safe_macros: Add SAFE_READ_ANY_EAGAIN syscalls/inotify{07,08}: Fix TBROK on older kernels

 include/safe_macros_fn.h                      | 16 ++++++++++++++--
 lib/safe_macros.c                             | 10 +++++++---
 testcases/kernel/syscalls/inotify/inotify07.c |  2 +-
 testcases/kernel/syscalls/inotify/inotify08.c |  2 +-
 4 files changed, 23 insertions(+), 7 deletions(-)
Signature · 5 lines
2.53.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

PATCH v2 1/2 safe_macros: Add SAFE_READ_ANY_EAGAIN

Similarly to the safe_write() this turns the len_strict into three way switch with the new value SAFE_READ_ANY_EAGAIN=2 that turns EAGAIN into a read with a zero length.

---
 include/safe_macros_fn.h | 16 ++++++++++++++--
 lib/safe_macros.c        | 10 +++++++---
 2 files changed, 21 insertions(+), 5 deletions(-)
include/safe_macros_fn.h +14 -2
index 9a09c4922..e8dc02539 100644
@@ -36,6 +36,18 @@ enum safe_write_opts {
 	SAFE_WRITE_RETRY = 2,
 };
 
+/* supported values for safe_read() len_strict parameter */
+enum safe_read_opts {
+	/* no length strictness, short reads are ok */
+	SAFE_READ_ANY = 0,
+
+	/* strict length, short reads trigger TBROK */
+	SAFE_READ_ALL = 1,
+
+	/* converts EAGAIN to read that returns 0 */
+	SAFE_READ_ANY_EAGAIN = 2,
+};
+
 char* safe_basename(const char *file, const int lineno,
                     void (*cleanup_fn)(void), char *path);
 
@@ -80,8 +92,8 @@ int safe_pipe(const char *file, const int lineno,
               void (*cleanup_fn)(void), int fildes[2]);
 
 ssize_t safe_read(const char *file, const int lineno,
-                  void (*cleanup_fn)(void), char len_strict, int fildes,
-                  void *buf, size_t nbyte);
+                  void (*cleanup_fn)(void), enum safe_read_opts len_strict,
+                  int fildes, void *buf, size_t nbyte);
 
 int safe_setegid(const char *file, const int lineno,
                  void (*cleanup_fn)(void), gid_t egid);
lib/safe_macros.c +7 -3
index 68b8747b4..f95c5fdc5 100644
@@ -286,14 +286,18 @@ int safe_pipe(const char *file, const int lineno, void (*cleanup_fn) (void),
 	return rval;
 }
 
-ssize_t safe_read(const char *file, const int lineno, void (*cleanup_fn) (void),
-                  char len_strict, int fildes, void *buf, size_t nbyte)
+ssize_t safe_read(const char *file, const int lineno,
+                  void (*cleanup_fn) (void), enum safe_read_opts len_strict,
+                  int fildes, void *buf, size_t nbyte)
 {
 	ssize_t rval;
 
 	rval = read(fildes, buf, nbyte);
 
 	if (rval == -1) {
+		if (len_strict == SAFE_READ_ANY_EAGAIN && errno == EAGAIN)
+			return 0;
+
 		tst_brkm_(file, lineno, TBROK | TERRNO, cleanup_fn,
 			"read(%d,%p,%zu) failed, returned %zd", fildes, buf,
 			nbyte, rval);
@@ -301,7 +305,7 @@ ssize_t safe_read(const char *file, const int lineno, void (*cleanup_fn) (void),
 		tst_brkm_(file, lineno, TBROK | TERRNO, cleanup_fn,
 			"Invalid read(%d,%p,%zu) return value %zd", fildes,
 			buf, nbyte, rval);
-	} else if (len_strict && (size_t)rval != nbyte) {
+	} else if (len_strict == SAFE_READ_ALL && (size_t)rval != nbyte) {
 		tst_brkm_(file, lineno, TBROK, cleanup_fn,
 			  "Short read(%d,%p,%zu) returned only %zd",
 			  fildes, buf, nbyte, rval);
Signature · 5 lines
2.53.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v2 1/2
#3 lore raw

Re: [LTP] [PATCH v2 1/2] safe_macros: Add SAFE_READ_ANY_EAGAIN

In reply to Cyril Hrubis

Hi Cyril,

...

Quoted 1 line

+/* supported values for safe_read() len_strict parameter */

Could we have kerneldoc (ok to fix before merge).

/**
* enum safe_read_opts - supported values for safe_read() len_strict parameter */ *
* @SAFE_READ_ANY: no length strictness, short reads are ok.
* @SAFE_READ_ALL: strict length, short reads trigger :c:enum:TBROK <tst_res_flags>.
* @SAFE_READ_ANY_EAGAIN: converts EAGAIN to read that returns 0.
*/

Otherwise LGTM, thanks for spotting the error.

Kind regards,
Petr

Quoted 10 lines
include/safe_macros_fn.h +10 -0
+enum safe_read_opts {
+	/* no length strictness, short reads are ok */
+	SAFE_READ_ANY = 0,
+
+	/* strict length, short reads trigger TBROK */
+	SAFE_READ_ALL = 1,
+
+	/* converts EAGAIN to read that returns 0 */
+	SAFE_READ_ANY_EAGAIN = 2,
+};

...

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#4 lore raw

Re: [LTP] [PATCH v2 1/2] safe_macros: Add SAFE_READ_ANY_EAGAIN

Hi!

Quoted 12 lines

...

Quoted 1 line

+/* supported values for safe_read() len_strict parameter */

Could we have kerneldoc (ok to fix before merge).

/**
* enum safe_read_opts - supported values for safe_read() len_strict parameter */ *
* @SAFE_READ_ANY: no length strictness, short reads are ok.
* @SAFE_READ_ALL: strict length, short reads trigger :c:enum:TBROK <tst_res_flags>.
* @SAFE_READ_ANY_EAGAIN: converts EAGAIN to read that returns 0.
*/

Quoted 1 line

Otherwise LGTM, thanks for spotting the error.

I would avoid that for now, since we are likely going to change the API after the release. Is that okay?

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#5 lore raw

Re: [LTP] [PATCH v2 1/2] safe_macros: Add SAFE_READ_ANY_EAGAIN

Quoted 13 lines

Hi!

Quoted 11 lines

...

Quoted 1 line

+/* supported values for safe_read() len_strict parameter */

Could we have kerneldoc (ok to fix before merge).

/**
* enum safe_read_opts - supported values for safe_read() len_strict parameter */ *
* @SAFE_READ_ANY: no length strictness, short reads are ok.
* @SAFE_READ_ALL: strict length, short reads trigger :c:enum:TBROK <tst_res_flags>.
* @SAFE_READ_ANY_EAGAIN: converts EAGAIN to read that returns 0.
*/

Quoted 4 lines
Quoted 1 line

Otherwise LGTM, thanks for spotting the error.

I would avoid that for now, since we are likely going to change the API after the release. Is that okay?

Sure, I'm sorry I overlooked expected API change.

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#6 lore raw

PATCH v2 2/2 syscalls/inotify{07, 08}: Fix TBROK on older kernels

In reply to Cyril Hrubis

When kernel fails to generate events the read returns EAGAIN and since we switched to SAFE_READ() the tests now TBROK when kernel does not generate events. Fix this by passing the newly introduced SAFE_READ_ANY_EAGAIN flag to the SAFE_READ().

Fixes deda021818a4 ('inotify: modernize with SAFE_ wrappers')
---
 testcases/kernel/syscalls/inotify/inotify07.c | 2 +-
 testcases/kernel/syscalls/inotify/inotify08.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/inotify/inotify07.c +1 -1
index b4000f353..9cadbf656 100644
@@ -88,7 +88,7 @@ void verify_inotify(void)
 	strcpy(event_set[test_cnt].name, FILE_NAME);
 	test_cnt++;
 
-	int len = SAFE_READ(0, fd_notify, event_buf, EVENT_BUF_LEN);
+	int len = SAFE_READ(SAFE_READ_ANY_EAGAIN, fd_notify, event_buf, EVENT_BUF_LEN);
 
 	int i = 0, test_num = 0;
 	while (i < len) {
testcases/kernel/syscalls/inotify/inotify08.c +1 -1
index e0837cac3..23d3c5a65 100644
@@ -86,7 +86,7 @@ void verify_inotify(void)
 	SAFE_TOUCH(OVL_LOWER"/"FILE_NAME, 0644, NULL);
 	SAFE_TOUCH(OVL_UPPER"/"FILE_NAME, 0644, NULL);
 
-	int len = SAFE_READ(0, fd_notify, event_buf, EVENT_BUF_LEN);
+	int len = SAFE_READ(SAFE_READ_ANY_EAGAIN, fd_notify, event_buf, EVENT_BUF_LEN);
 
 	int i = 0, test_num = 0;
 	while (i < len) {
Signature · 5 lines
2.53.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v2 2/2
#7 lore raw

Re: [LTP] [PATCH v2 2/2] syscalls/inotify{07, 08}: Fix TBROK on older kernels

Hi,
for both patches:

Quoted 38 lines · Cyril Hrubis

When kernel fails to generate events the read returns EAGAIN and since we switched to SAFE_READ() the tests now TBROK when kernel does not generate events. Fix this by passing the newly introduced SAFE_READ_ANY_EAGAIN flag to the SAFE_READ().

Fixes deda021818a4 ('inotify: modernize with SAFE_ wrappers')
---
  testcases/kernel/syscalls/inotify/inotify07.c | 2 +-
  testcases/kernel/syscalls/inotify/inotify08.c | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/inotify/inotify07.c +1 -1
index b4000f353..9cadbf656 100644
@@ -88,7 +88,7 @@ void verify_inotify(void)
  	strcpy(event_set[test_cnt].name, FILE_NAME);
  	test_cnt++;
 
-	int len = SAFE_READ(0, fd_notify, event_buf, EVENT_BUF_LEN);
+	int len = SAFE_READ(SAFE_READ_ANY_EAGAIN, fd_notify, event_buf, EVENT_BUF_LEN);
 
  	int i = 0, test_num = 0;
  	while (i < len) {
testcases/kernel/syscalls/inotify/inotify08.c +1 -1
index e0837cac3..23d3c5a65 100644
@@ -86,7 +86,7 @@ void verify_inotify(void)
  	SAFE_TOUCH(OVL_LOWER"/"FILE_NAME, 0644, NULL);
  	SAFE_TOUCH(OVL_UPPER"/"FILE_NAME, 0644, NULL);
 
-	int len = SAFE_READ(0, fd_notify, event_buf, EVENT_BUF_LEN);
+	int len = SAFE_READ(SAFE_READ_ANY_EAGAIN, fd_notify, event_buf, EVENT_BUF_LEN);
 
  	int i = 0, test_num = 0;
  	while (i < len) {
Signature · 10 lines
Martin Doucha   [email protected]
SW Quality Engineer
SUSE LINUX, s.r.o.
CORSO IIa
Krizikova 148/34
186 00 Prague 8
Czech Republic

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v2 2/2
#8 lore raw

Re: [LTP] [PATCH v2 2/2] syscalls/inotify{07, 08}: Fix TBROK on older kernels

In reply to Cyril Hrubis

Hi Cyril,

Thanks for fixing it!

Review

Quoted 2 lines
(quoted diff) +1 -1
-	int len = SAFE_READ(0, fd_notify, event_buf, EVENT_BUF_LEN);
+	int len = SAFE_READ(SAFE_READ_ANY_EAGAIN, fd_notify, event_buf, EVENT_BUF_LEN);

Maybe later after the release we could think about about shorten this with definitions. I'm ok if you consider this as not useful.

Kind regards,
Petr

+++ include/tst_safe_macros.h
@@ -117,6 +117,15 @@ int safe_pipe2(const char *file, const int lineno, int fildes[2], int flags);
#define SAFE_READ(len_strict, fildes, buf, nbyte) \
safe_read(__FILE__, __LINE__, NULL, (len_strict), (fildes), (buf), (nbyte))

+#define SAFE_READ_ANY(fildes, buf, nbyte) \
+ SAFE_READ(SAFE_READ_ANY, fildes, buf, nbyte)
+
+#define SAFE_READ_ALL(fildes, buf, nbyte) \
+ SAFE_READ(SAFE_READ_ALL, fildes, buf, nbyte)
+
+#define SAFE_READ_ANY_EAGAIN(fildes, buf, nbyte) \
+ SAFE_READ(SAFE_READ_ANY_EAGAIN, fildes, buf, nbyte)
+
#define SAFE_SETEGID(egid) \
safe_setegid(__FILE__, __LINE__, NULL, (egid))

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#9 lore raw

Re: [LTP] [PATCH v2 2/2] syscalls/inotify{07, 08}: Fix TBROK on older kernels

Hi!

Quoted 2 lines

Maybe later after the release we could think about about shorten this with definitions. I'm ok if you consider this as not useful.

I was thinking about this, but I wanted to have minimal fix before the release. We can rethink the SAFE_WRITE and SAFE_READ API later on.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#10 lore raw

Re: [LTP] [PATCH v2 2/2] syscalls/inotify{07, 08}: Fix TBROK on older kernels

Quoted 6 lines

Hi!

Quoted 2 lines

Maybe later after the release we could think about about shorten this with definitions. I'm ok if you consider this as not useful.

I was thinking about this, but I wanted to have minimal fix before the release. We can rethink the SAFE_WRITE and SAFE_READ API later on.

Good. Sure I agree with minimal changes as these are pre-release fixes.

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#11 lore raw

Re: [LTP] [PATCH v2 2/2] syscalls/inotify{07, 08}: Fix TBROK on older kernels

Hi!

Quoted 1 line

Good. Sure I agree with minimal changes as these are pre-release fixes.

Pushed.

Signature · 5 lines
Cyril Hrubis
[email protected]

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