Skip to contentSkip to conversation

open: remove O_DIRECTORY case (move to fstat test)

PATCH Superseded Jinseok Kim 3 participants 4 messages Jun 4 – Jun 15

v8 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

PATCH v8 1/2 open: remove O_DIRECTORY case (move to fstat test)

The O_DIRECTORY test case was mostly verifying fstat() behavior on an existing directory rather than testing any specific open() behavior.

Following review suggestion, remove it from open01.c. A separate fstat test will be added in a follow-up patch to cover file type checks (S_ISDIR, etc.) more comprehensively.

---
 testcases/kernel/syscalls/open/open01.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)
testcases/kernel/syscalls/open/open01.c +1 -12
index 1cefb4790..1413ccdec 100644
@@ -6,15 +6,12 @@
  */
 
 /*\
- * Basic :manpage:`open(2)` test, checking sticky/directory bit.
+ * Basic :manpage:`open(2)` test, checking sticky bit.
  *
  * 1. Open a new file with O_CREAT, fstat.st_mode should not have the
  *    01000 (S_ISVTX) bit on. In Linux, the save text bit is *NOT* cleared.
- * 2. Open a new directory with O_DIRECTORY, fstat.st_mode should have the
- *    040000 (S_IFDIR) bit on.
  */
 
-#define _GNU_SOURCE		/* for O_DIRECTORY */
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -22,7 +19,6 @@
 #include "tst_test.h"
 
 #define TEST_FILE	"testfile"
-#define TEST_DIR	"testdir"
 
 static int fd;
 
@@ -34,7 +30,6 @@ static struct tcase {
 	char *desc;
 } tcases[] = {
 	{TEST_FILE, O_RDWR | O_CREAT, 01444, S_ISVTX, "sticky bit"},
-	{TEST_DIR, O_DIRECTORY, 0, S_IFDIR, "directory bit"}
 };
 
 static void verify_open(unsigned int n)
@@ -60,11 +55,6 @@ static void verify_open(unsigned int n)
 		SAFE_UNLINK(tc->filename);
 }
 
-static void setup(void)
-{
-	SAFE_MKDIR(TEST_DIR, 0755);
-}
-
 static void cleanup(void)
 {
 	if (fd > 0)
@@ -74,7 +64,6 @@ static void cleanup(void)
 static struct tst_test test = {
 	.tcnt = ARRAY_SIZE(tcases),
 	.needs_tmpdir = 1,
-	.setup = setup,
 	.cleanup = cleanup,
 	.test = verify_open,
 };

--
2.43.0

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

PATCH v8 2/2 fstat: add test for multiple file types using fstat

Following review feedback, create a dedicated fstat test that verifies S_ISREG(), S_ISDIR(), S_ISFIFO(), S_ISCHR(), S_ISBLK() on different file types.

---
Changes in v8:
- Link to the man page
- Remove desc from tcase and TST_EXP_EXPR
- Link to v7: https://lore.kernel.org/ltp/[email protected]

---
 runtest/syscalls                           |   2 +
 testcases/kernel/syscalls/fstat/.gitignore |   2 +
 testcases/kernel/syscalls/fstat/fstat04.c  | 103 +++++++++++++++++++++
 3 files changed, 107 insertions(+)
 create mode 100644 testcases/kernel/syscalls/fstat/fstat04.c
runtest/syscalls +2 -0
index f790e8f84..d420df905 100644
@@ -436,6 +436,8 @@ fstat02 fstat02
 fstat02_64 fstat02_64
 fstat03 fstat03
 fstat03_64 fstat03_64
+fstat04 fstat04
+fstat04_64 fstat04_64
 
 #fstatat64/newfstatat test cases
 fstatat01 fstatat01
testcases/kernel/syscalls/fstat/.gitignore +2 -0
index 9b1089438..a1f538f7e 100644
@@ -2,3 +2,5 @@
 /fstat02_64
 /fstat03
 /fstat03_64
+/fstat04
+/fstat04_64
testcases/kernel/syscalls/fstat/fstat04.c new file +103 -0

103 lines not on this page · raw message

--
2.43.0

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

Re: [LTP] [PATCH v8 2/2] fstat: add test for multiple file types using fstat

Hi Jinseok,

testcases/kernel/syscalls/fstat/fstat04.c line 37

Quoted 1 line
testcases/kernel/syscalls/fstat/fstat04.c new file +1 -0
+	int flags = O_RDONLY | O_NONBLOCK;

consider using O_PATH instead of O_RDONLY | O_NONBLOCK for device nodes. fstat() works correctly on O_PATH file descriptors and returns the right st_mode, without needing the underlying driver to be present. Please use it in the SAFE_OPEN().

testcases/kernel/syscalls/fstat/fstat04.c line 42

Quoted 5 lines
testcases/kernel/syscalls/fstat/fstat04.c new file +5 -0
+
+	if (tc->exp_type == S_IFDIR)
+		flags |= O_DIRECTORY;
+
+	int fd = SAFE_OPEN(tc->path, flags);

The test does not gate on CONFIG_BLK_DEV_LOOP via .needs_kconfigs, so SAFE_OPEN will TBROK on systems without loop support.

Regards,
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw
In reply to Jinseok Kim

Hi Jinseok,

Quoted 1 line · Jinseok Kim

open: remove O_DIRECTORY case (move to fstat test)

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

Review

Quoted 6 lines
(quoted diff) +5 -0
+/*\
+ * Verify that :manpage:`fstat(2)` correctly identifies various
+ * file types.
+ */
 
+	.needs_root = 1,

Ground Rule 4 requires that the reason for needing root is documented in the test's doc comment. The test calls SAFE_MKNOD() to create block and character device nodes, which requires CAP_MKNOD. Please add a note in the /*\ ... */ block, e.g.:

"Requires root to create block and character device nodes with mknod(2)."

Review

Quoted 6 lines
(quoted diff) +6 -0
+	int flags = O_RDONLY | O_NONBLOCK;
+
+	if (tc->exp_type == S_IFDIR)
+		flags |= O_DIRECTORY;
+
+	int fd = SAFE_OPEN(tc->path, flags);

For the block device case (BLK_DEV, makedev(7, 3) = loop3) this will attempt to open the underlying block device via its driver. If the loop module is not loaded -- which can happen in containers or minimal environments -- SAFE_OPEN aborts with TBROK rather than skipping cleanly.

The test only needs the fd to call fstat(), not to perform I/O. Using O_PATH avoids instantiating the driver entirely and is more appropriate for a test focused on fstat() metadata. With O_PATH the branching on S_IFDIR also becomes unnecessary since directories can be opened without O_DIRECTORY through an O_PATH descriptor:

  int fd = SAFE_OPEN(tc->path, O_PATH | O_NOFOLLOW);

O_PATH + fstat() has been supported since Linux 3.6.

Verdict: Needs revision

---
Note:

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

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