Skip to contentSkip to conversation

syscalls/flock: open test file with O_RDWR mode

PATCH New Eryu Guan 2 participants 3 messages May 17, 2017 – Jun 7, 2017

lore
Share & tools
lore

Eryu Guan

author
#0 lore raw

PATCH 1/1 syscalls/flock: open test file with O_RDWR mode

NFS requires the open mode to match the lock type, i.e. for LOCK_SH file must be opened for read, and for LOCK_EX file must be opened for write. Otherwise flock01 and flock04 fail on NFS with EBADF.

So open all test files in flock tests with O_RDWR mode that both lock type requirements can be met.

---
 testcases/kernel/syscalls/flock/flock01.c | 2 +-
 testcases/kernel/syscalls/flock/flock02.c | 2 +-
 testcases/kernel/syscalls/flock/flock03.c | 2 +-
 testcases/kernel/syscalls/flock/flock04.c | 2 +-
 testcases/kernel/syscalls/flock/flock05.c | 2 +-
 testcases/kernel/syscalls/flock/flock06.c | 2 +-
 6 files changed, 6 insertions(+), 6 deletions(-)
testcases/kernel/syscalls/flock/flock01.c +1 -1
index a7ecba1..3e17be4 100644
@@ -153,7 +153,7 @@ void setup(void)
 	sprintf(filename, "flock01.%d", getpid());
 
 	/* creating temporary file */
-	fd = creat(filename, 0644);
+	fd = open(filename, O_CREAT | O_TRUNC | O_RDWR, 0644);
 	if (fd < 0)
 		tst_brkm(TBROK, tst_rmdir, "creating a new file failed");
 }
testcases/kernel/syscalls/flock/flock02.c +1 -1
index 971160d..414df68 100644
@@ -150,7 +150,7 @@ void setup(void)
 
 	sprintf(filename, "flock02.%d", getpid());
 
-	fd = creat(filename, 0666);
+	fd = open(filename, O_CREAT | O_TRUNC | O_RDWR, 0666);
 	if (fd < 0)
 		tst_brkm(TFAIL | TERRNO, cleanup, "creat failed");
 }
testcases/kernel/syscalls/flock/flock03.c +1 -1
index e53b3b7..420f509 100644
@@ -181,7 +181,7 @@ static void setup(void)
 
 	TST_CHECKPOINT_INIT(tst_rmdir);
 
-	fd = creat(FILE_NAME, 0666);
+	fd = open(FILE_NAME, O_CREAT | O_TRUNC | O_RDWR, 0666);
 	if (fd < 0) {
 		tst_resm(TBROK, "creating a new file failed");
 		cleanup();
testcases/kernel/syscalls/flock/flock04.c +1 -1
index 5dafaa4..87f1dfb 100644
@@ -164,7 +164,7 @@ void setup(void)
 
 	sprintf(filename, "flock04.%d", getpid());
 
-	fd = creat(filename, 0666);
+	fd = open(filename, O_CREAT | O_TRUNC | O_RDWR, 0666);
 	if (fd == -1)
 		tst_brkm(TFAIL, cleanup, "creating a new file failed");
 }
testcases/kernel/syscalls/flock/flock05.c +1 -1
index d9d3d00..13ae2f6 100644
@@ -182,7 +182,7 @@ void setup(void)
 	sprintf(filename, "flock05.%d", getpid());
 
 	/* creating temporary file */
-	fd = creat(filename, 0666);
+	fd = open(filename, O_CREAT | O_TRUNC | O_RDWR, 0666);
 	if (fd == -1) {
 		tst_resm(TFAIL, "creating a new file failed");
 
testcases/kernel/syscalls/flock/flock06.c +1 -1
index d9c1d2d..a35c8cf 100644
@@ -158,7 +158,7 @@ void setup(void)
 	sprintf(filename, "flock06.%d", getpid());
 
 	/* creating temporary file */
-	fd = creat(filename, 0666);
+	fd = open(filename, O_CREAT | O_TRUNC | O_RDWR, 0666);
 	if (fd < 0)
 		tst_brkm(TBROK, tst_rmdir, "creating a new file failed");
 	close(fd);
Signature · 1 line
2.9.4
author
#1 lore raw

PATCH 1/1 syscalls/flock: open test file with O_RDWR mode

Quoted 8 lines · Eryu Guan

NFS requires the open mode to match the lock type, i.e. for LOCK_SH file must be opened for read, and for LOCK_EX file must be opened for write. Otherwise flock01 and flock04 fail on NFS with EBADF.

So open all test files in flock tests with O_RDWR mode that both lock type requirements can be met.

ping on this one.

Thanks,
Eryu

Quoted 90 lines
---
 testcases/kernel/syscalls/flock/flock01.c | 2 +-
 testcases/kernel/syscalls/flock/flock02.c | 2 +-
 testcases/kernel/syscalls/flock/flock03.c | 2 +-
 testcases/kernel/syscalls/flock/flock04.c | 2 +-
 testcases/kernel/syscalls/flock/flock05.c | 2 +-
 testcases/kernel/syscalls/flock/flock06.c | 2 +-
 6 files changed, 6 insertions(+), 6 deletions(-)
testcases/kernel/syscalls/flock/flock01.c +1 -1
index a7ecba1..3e17be4 100644
@@ -153,7 +153,7 @@ void setup(void)
 	sprintf(filename, "flock01.%d", getpid());
 
 	/* creating temporary file */
-	fd = creat(filename, 0644);
+	fd = open(filename, O_CREAT | O_TRUNC | O_RDWR, 0644);
 	if (fd < 0)
 		tst_brkm(TBROK, tst_rmdir, "creating a new file failed");
 }
testcases/kernel/syscalls/flock/flock02.c +1 -1
index 971160d..414df68 100644
@@ -150,7 +150,7 @@ void setup(void)
 
 	sprintf(filename, "flock02.%d", getpid());
 
-	fd = creat(filename, 0666);
+	fd = open(filename, O_CREAT | O_TRUNC | O_RDWR, 0666);
 	if (fd < 0)
 		tst_brkm(TFAIL | TERRNO, cleanup, "creat failed");
 }
testcases/kernel/syscalls/flock/flock03.c +1 -1
index e53b3b7..420f509 100644
@@ -181,7 +181,7 @@ static void setup(void)
 
 	TST_CHECKPOINT_INIT(tst_rmdir);
 
-	fd = creat(FILE_NAME, 0666);
+	fd = open(FILE_NAME, O_CREAT | O_TRUNC | O_RDWR, 0666);
 	if (fd < 0) {
 		tst_resm(TBROK, "creating a new file failed");
 		cleanup();
testcases/kernel/syscalls/flock/flock04.c +1 -1
index 5dafaa4..87f1dfb 100644
@@ -164,7 +164,7 @@ void setup(void)
 
 	sprintf(filename, "flock04.%d", getpid());
 
-	fd = creat(filename, 0666);
+	fd = open(filename, O_CREAT | O_TRUNC | O_RDWR, 0666);
 	if (fd == -1)
 		tst_brkm(TFAIL, cleanup, "creating a new file failed");
 }
testcases/kernel/syscalls/flock/flock05.c +1 -1
index d9d3d00..13ae2f6 100644
@@ -182,7 +182,7 @@ void setup(void)
 	sprintf(filename, "flock05.%d", getpid());
 
 	/* creating temporary file */
-	fd = creat(filename, 0666);
+	fd = open(filename, O_CREAT | O_TRUNC | O_RDWR, 0666);
 	if (fd == -1) {
 		tst_resm(TFAIL, "creating a new file failed");
 
testcases/kernel/syscalls/flock/flock06.c +1 -1
index d9c1d2d..a35c8cf 100644
@@ -158,7 +158,7 @@ void setup(void)
 	sprintf(filename, "flock06.%d", getpid());
 
 	/* creating temporary file */
-	fd = creat(filename, 0666);
+	fd = open(filename, O_CREAT | O_TRUNC | O_RDWR, 0666);
 	if (fd < 0)
 		tst_brkm(TBROK, tst_rmdir, "creating a new file failed");
 	close(fd);
Signature · 1 line
2.9.4
#2 lore raw

PATCH 1/1 syscalls/flock: open test file with O_RDWR mode

----- Original Message -----

Quoted 11 lines · Eryu Guan
Quoted 8 lines

NFS requires the open mode to match the lock type, i.e. for LOCK_SH file must be opened for read, and for LOCK_EX file must be opened for write. Otherwise flock01 and flock04 fail on NFS with EBADF.

So open all test files in flock tests with O_RDWR mode that both lock type requirements can be met.

ping on this one.

Pushed.

Thanks,
Jan