Skip to contentSkip to conversation

Add SAFE_ACCESS macro

PATCH Superseded Dai Shili 3 participants 27 messages Mar 14, 2022 – Mar 25, 2022 Library code

lore
Share & tools
lore

Dai Shili

author
#0 lore raw

PATCH 1/2 Add SAFE_ACCESS macro

---
 include/old/safe_macros.h |  3 +++
 include/safe_macros_fn.h  |  3 +++
 include/tst_safe_macros.h |  3 +++
 lib/safe_macros.c         | 20 ++++++++++++++++++++
 4 files changed, 29 insertions(+)
include/old/safe_macros.h +3 -0
index fb1d7a1..1d5de49 100644
@@ -20,6 +20,9 @@
 #include "old_safe_stdio.h"
 #include "old_safe_net.h"
 
+#define SAFE_ACCESS(cleanup_fn, pathname, mode)	\
+	safe_access(__FILE__, __LINE__, cleanup_fn, (pathname), (mode))
+
 #define SAFE_BASENAME(cleanup_fn, path)	\
 	safe_basename(__FILE__, __LINE__, (cleanup_fn), (path))
 
include/safe_macros_fn.h +3 -0
index 3df9528..2c8eb50 100644
@@ -24,6 +24,9 @@
 #include <unistd.h>
 #include <dirent.h>
 
+int safe_access(const char *file, const int lineno,
+		void (*cleanup_fn)(void), const char *pathname, int mode);
+
 char* safe_basename(const char *file, const int lineno,
                     void (*cleanup_fn)(void), char *path);
 
include/tst_safe_macros.h +3 -0
index 9a543e4..d8e56f5 100644
@@ -24,6 +24,9 @@
 #include "safe_macros_fn.h"
 #include "tst_cmd.h"
 
+#define SAFE_ACCESS(pathname, mode) \
+	safe_access(__FILE__, __LINE__, NULL, (pathname), (mode))
+
 #define SAFE_BASENAME(path) \
 	safe_basename(__FILE__, __LINE__, NULL, (path))
 
lib/safe_macros.c +20 -0
index a5b6bc5..006e583 100644
@@ -24,6 +24,26 @@
 #include "test.h"
 #include "safe_macros.h"
 
+int
+safe_access(const char *file, const int lineno, void (*cleanup_fn) (void),
+	   const char *pathname, int mode)
+{
+	int rval;
+
+	rval = access(pathname, mode);
+
+	if (rval == -1) {
+		tst_brkm_(file, lineno, TBROK | TERRNO, cleanup_fn,
+			"access(%s,%d) failed", pathname, mode);
+	} else if (rval) {
+		tst_brkm_(file, lineno, TBROK | TERRNO, cleanup_fn,
+			"Invalid access(%s,%d) return value %d", pathname,
+			mode, rval);
+	}
+
+	return rval;
+}
+
 char *safe_basename(const char *file, const int lineno,
 		    void (*cleanup_fn) (void), char *path)
 {
Signature · 5 lines
1.8.3.1


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

PATCH 2/2 Make use of SAFE_ACCESS

---
 testcases/kernel/mem/tunable/max_map_count.c    | 4 +---
 testcases/kernel/syscalls/fanotify/fanotify17.c | 3 +--
 testcases/kernel/syscalls/getxattr/getxattr05.c | 3 +--
 testcases/kernel/syscalls/madvise/madvise08.c   | 3 +--
 testcases/kernel/syscalls/quotactl/quotactl01.c | 6 ++----
 testcases/kernel/syscalls/quotactl/quotactl06.c | 3 +--
 testcases/kernel/syscalls/umount2/umount2_02.c  | 6 ++----
 7 files changed, 9 insertions(+), 19 deletions(-)
testcases/kernel/mem/tunable/max_map_count.c +1 -3
index a4c3dbf..caf8972 100644
@@ -58,9 +58,7 @@ static long old_overcommit = -1;
 
 static void setup(void)
 {
-	if (access(PATH_SYSVM "max_map_count", F_OK) != 0)
-		tst_brk(TBROK | TERRNO,
-			 "Can't support to test max_map_count");
+	SAFE_ACCESS(PATH_SYSVM "max_map_count", F_OK);
 
 	old_max_map_count = get_sys_tune("max_map_count");
 	old_overcommit = get_sys_tune("overcommit_memory");
testcases/kernel/syscalls/fanotify/fanotify17.c +1 -2
index 35beb53..7d74b25 100644
@@ -159,8 +159,7 @@ static void do_unshare(int map_root)
 		 * uid_map file should exist since Linux 3.8 because
 		 * it is available on Linux 3.5
 		 */
-		if (access(UID_MAP, F_OK))
-			tst_brk(TBROK, "file %s didn't exist", UID_MAP);
+		SAFE_ACCESS(UID_MAP, F_OK);
 
 		SAFE_FILE_PRINTF(UID_MAP, "%d %d %d", 0, 0, 1);
 	}
testcases/kernel/syscalls/getxattr/getxattr05.c +1 -2
index c0d339f..3e73cc5 100644
@@ -100,8 +100,7 @@ static void do_unshare(int map_root)
 		/* uid_map file should exist since Linux 3.8 because
 		 * it is available on Linux 3.5
 		 */
-		if (access(UID_MAP, F_OK))
-			tst_brk(TBROK, "file %s didn't exist", UID_MAP);
+		SAFE_ACCESS(UID_MAP, F_OK);
 
 		SAFE_FILE_PRINTF(UID_MAP, "%d %d %d", 0, 0, 1);
 	}
testcases/kernel/syscalls/madvise/madvise08.c +1 -2
index 30f3604..10549f4 100644
@@ -110,8 +110,7 @@ static int find_sequence(int pid)
 
 	snprintf(dumpname, 256, "dump-%d", pid);
 	tst_res(TINFO, "Dump file should be %s", dumpname);
-	if (access(dumpname, F_OK))
-		tst_brk(TBROK | TERRNO, "Dump file was not found.");
+	SAFE_ACCESS(dumpname, F_OK);
 
 	dfd = SAFE_OPEN(dumpname, O_RDONLY);
 
testcases/kernel/syscalls/quotactl/quotactl01.c +2 -4
index 561e503..3382d7b 100644
@@ -160,11 +160,9 @@ static void setup(void)
 	SAFE_CMD(cmd, NULL, NULL);
 	fmt_id = var->fmt_id;
 
-	if (access(USRPATH, F_OK) == -1)
-		tst_brk(TFAIL | TERRNO, "user quotafile didn't exist");
+	SAFE_ACCESS(USRPATH, F_OK);
 
-	if (access(GRPPATH, F_OK) == -1)
-		tst_brk(TFAIL | TERRNO, "group quotafile didn't exist");
+	SAFE_ACCESS(GRPPATH, F_OK);
 
 	tst_require_quota_support(tst_device->dev, fmt_id, usrpath);
 
testcases/kernel/syscalls/quotactl/quotactl06.c +1 -2
index 8771523..839c6ed 100644
@@ -186,8 +186,7 @@ static void setup(void)
 	/* vfsv0 block limit 2^42, vfsv1 block limit 2^63 - 1 */
 	set_dqmax.dqb_bsoftlimit = tst_variant ? 0x20000000000000 : 0x100000000;
 
-	if (access(USRPATH, F_OK) == -1)
-		tst_brk(TBROK | TERRNO, "user quotafile didn't exist");
+	SAFE_ACCESS(USRPATH, F_OK);
 
 	tst_require_quota_support(tst_device->dev, fmt_id, usrpath);
 
testcases/kernel/syscalls/umount2/umount2_02.c +2 -4
index 7d558fa..9dad4d5 100644
@@ -128,10 +128,8 @@ static void setup(void)
 static void test_umount2(int i)
 {
 	/* a new access removes the expired mark of the mount point */
-	if (test_cases[i].do_access) {
-		if (access(MNTPOINT, F_OK) == -1)
-			tst_brkm(TBROK | TERRNO, cleanup, "access(2) failed");
-	}
+	if (test_cases[i].do_access)
+		SAFE_ACCESS(cleanup, MNTPOINT, F_OK);
 
 	TEST(umount2_retry(MNTPOINT, test_cases[i].flag));
 
Signature · 5 lines
1.8.3.1


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

Re: [LTP] [PATCH 2/2] Make use of SAFE_ACCESS

Hi Dai

Since only umount2_02 uses old ltp api, I think we can convert it into ltp new api. Then we can just add this safe_macro to tst_safe_macro.c instead of safe_macro.c.

Best Regards
Yang Xu

Quoted 117 lines
---
  testcases/kernel/mem/tunable/max_map_count.c    | 4 +---
  testcases/kernel/syscalls/fanotify/fanotify17.c | 3 +--
  testcases/kernel/syscalls/getxattr/getxattr05.c | 3 +--
  testcases/kernel/syscalls/madvise/madvise08.c   | 3 +--
  testcases/kernel/syscalls/quotactl/quotactl01.c | 6 ++----
  testcases/kernel/syscalls/quotactl/quotactl06.c | 3 +--
  testcases/kernel/syscalls/umount2/umount2_02.c  | 6 ++----
  7 files changed, 9 insertions(+), 19 deletions(-)
testcases/kernel/mem/tunable/max_map_count.c +1 -3
index a4c3dbf..caf8972 100644
@@ -58,9 +58,7 @@ static long old_overcommit = -1;
 
  static void setup(void)
  {
-	if (access(PATH_SYSVM "max_map_count", F_OK) != 0)
-		tst_brk(TBROK | TERRNO,
-			 "Can't support to test max_map_count");
+	SAFE_ACCESS(PATH_SYSVM "max_map_count", F_OK);
 
  	old_max_map_count = get_sys_tune("max_map_count");
  	old_overcommit = get_sys_tune("overcommit_memory");
testcases/kernel/syscalls/fanotify/fanotify17.c +1 -2
index 35beb53..7d74b25 100644
@@ -159,8 +159,7 @@ static void do_unshare(int map_root)
  		 * uid_map file should exist since Linux 3.8 because
  		 * it is available on Linux 3.5
  		 */
-		if (access(UID_MAP, F_OK))
-			tst_brk(TBROK, "file %s didn't exist", UID_MAP);
+		SAFE_ACCESS(UID_MAP, F_OK);
 
  		SAFE_FILE_PRINTF(UID_MAP, "%d %d %d", 0, 0, 1);
  	}
testcases/kernel/syscalls/getxattr/getxattr05.c +1 -2
index c0d339f..3e73cc5 100644
@@ -100,8 +100,7 @@ static void do_unshare(int map_root)
  		/* uid_map file should exist since Linux 3.8 because
  		 * it is available on Linux 3.5
  		 */
-		if (access(UID_MAP, F_OK))
-			tst_brk(TBROK, "file %s didn't exist", UID_MAP);
+		SAFE_ACCESS(UID_MAP, F_OK);
 
  		SAFE_FILE_PRINTF(UID_MAP, "%d %d %d", 0, 0, 1);
  	}
testcases/kernel/syscalls/madvise/madvise08.c +1 -2
index 30f3604..10549f4 100644
@@ -110,8 +110,7 @@ static int find_sequence(int pid)
 
  	snprintf(dumpname, 256, "dump-%d", pid);
  	tst_res(TINFO, "Dump file should be %s", dumpname);
-	if (access(dumpname, F_OK))
-		tst_brk(TBROK | TERRNO, "Dump file was not found.");
+	SAFE_ACCESS(dumpname, F_OK);
 
  	dfd = SAFE_OPEN(dumpname, O_RDONLY);
 
testcases/kernel/syscalls/quotactl/quotactl01.c +2 -4
index 561e503..3382d7b 100644
@@ -160,11 +160,9 @@ static void setup(void)
  	SAFE_CMD(cmd, NULL, NULL);
  	fmt_id = var->fmt_id;
 
-	if (access(USRPATH, F_OK) == -1)
-		tst_brk(TFAIL | TERRNO, "user quotafile didn't exist");
+	SAFE_ACCESS(USRPATH, F_OK);
 
-	if (access(GRPPATH, F_OK) == -1)
-		tst_brk(TFAIL | TERRNO, "group quotafile didn't exist");
+	SAFE_ACCESS(GRPPATH, F_OK);
 
  	tst_require_quota_support(tst_device->dev, fmt_id, usrpath);
 
testcases/kernel/syscalls/quotactl/quotactl06.c +1 -2
index 8771523..839c6ed 100644
@@ -186,8 +186,7 @@ static void setup(void)
  	/* vfsv0 block limit 2^42, vfsv1 block limit 2^63 - 1 */
  	set_dqmax.dqb_bsoftlimit = tst_variant ? 0x20000000000000 : 0x100000000;
 
-	if (access(USRPATH, F_OK) == -1)
-		tst_brk(TBROK | TERRNO, "user quotafile didn't exist");
+	SAFE_ACCESS(USRPATH, F_OK);
 
  	tst_require_quota_support(tst_device->dev, fmt_id, usrpath);
 
testcases/kernel/syscalls/umount2/umount2_02.c +2 -4
index 7d558fa..9dad4d5 100644
@@ -128,10 +128,8 @@ static void setup(void)
  static void test_umount2(int i)
  {
  	/* a new access removes the expired mark of the mount point */
-	if (test_cases[i].do_access) {
-		if (access(MNTPOINT, F_OK) == -1)
-			tst_brkm(TBROK | TERRNO, cleanup, "access(2) failed");
-	}
+	if (test_cases[i].do_access)
+		SAFE_ACCESS(cleanup, MNTPOINT, F_OK);
 
  	TEST(umount2_retry(MNTPOINT, test_cases[i].flag));
 
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
author
#3 lore raw

PATCH v2 1/3 Add SAFE_ACCESS macro

---
 include/tst_safe_macros.h |  5 +++++
 lib/tst_safe_macros.c     | 19 +++++++++++++++++++
 2 files changed, 24 insertions(+)
include/tst_safe_macros.h +5 -0
index 9a543e4..81c4b08 100644
@@ -24,6 +24,11 @@
 #include "safe_macros_fn.h"
 #include "tst_cmd.h"
 
+int safe_access(const char *filename, const int lineno, const char *pathname,
+		   int mode);
+#define SAFE_ACCESS(path, mode) \
+	safe_access(__FILE__, __LINE__, (path), (mode))
+
 #define SAFE_BASENAME(path) \
 	safe_basename(__FILE__, __LINE__, NULL, (path))
 
lib/tst_safe_macros.c +19 -0
index a9f6aeb..24aad0d 100644
@@ -20,6 +20,25 @@
 #include "lapi/personality.h"
 #include "lapi/pidfd.h"
 
+int safe_access(const char *file, const int lineno,
+           const char *pathname, int mode)
+{
+        int rval;
+
+        rval = access(pathname, mode);
+
+        if (rval == -1) {
+                tst_brk_(file, lineno, TBROK | TERRNO,
+                        "access(%s,%d) failed", pathname, mode);
+        } else if (rval) {
+                tst_brk_(file, lineno, TBROK | TERRNO,
+                        "Invalid access(%s,%d) return value %d", pathname,
+                        mode, rval);
+        }
+
+        return rval;
+}
+
 int safe_setpgid(const char *file, const int lineno, pid_t pid, pid_t pgid)
 {
 	int rval;
Signature · 5 lines
1.8.3.1


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

PATCH v2 2/3 Make use of SAFE_ACCESS

---
 testcases/kernel/mem/tunable/max_map_count.c    | 4 +---
 testcases/kernel/syscalls/fanotify/fanotify17.c | 3 +--
 testcases/kernel/syscalls/getxattr/getxattr05.c | 3 +--
 testcases/kernel/syscalls/madvise/madvise08.c   | 3 +--
 testcases/kernel/syscalls/quotactl/quotactl01.c | 6 ++----
 testcases/kernel/syscalls/quotactl/quotactl06.c | 3 +--
 6 files changed, 7 insertions(+), 15 deletions(-)
testcases/kernel/mem/tunable/max_map_count.c +1 -3
index a4c3dbf..caf8972 100644
@@ -58,9 +58,7 @@ static long old_overcommit = -1;
 
 static void setup(void)
 {
-	if (access(PATH_SYSVM "max_map_count", F_OK) != 0)
-		tst_brk(TBROK | TERRNO,
-			 "Can't support to test max_map_count");
+	SAFE_ACCESS(PATH_SYSVM "max_map_count", F_OK);
 
 	old_max_map_count = get_sys_tune("max_map_count");
 	old_overcommit = get_sys_tune("overcommit_memory");
testcases/kernel/syscalls/fanotify/fanotify17.c +1 -2
index 35beb53..7d74b25 100644
@@ -159,8 +159,7 @@ static void do_unshare(int map_root)
 		 * uid_map file should exist since Linux 3.8 because
 		 * it is available on Linux 3.5
 		 */
-		if (access(UID_MAP, F_OK))
-			tst_brk(TBROK, "file %s didn't exist", UID_MAP);
+		SAFE_ACCESS(UID_MAP, F_OK);
 
 		SAFE_FILE_PRINTF(UID_MAP, "%d %d %d", 0, 0, 1);
 	}
testcases/kernel/syscalls/getxattr/getxattr05.c +1 -2
index c0d339f..3e73cc5 100644
@@ -100,8 +100,7 @@ static void do_unshare(int map_root)
 		/* uid_map file should exist since Linux 3.8 because
 		 * it is available on Linux 3.5
 		 */
-		if (access(UID_MAP, F_OK))
-			tst_brk(TBROK, "file %s didn't exist", UID_MAP);
+		SAFE_ACCESS(UID_MAP, F_OK);
 
 		SAFE_FILE_PRINTF(UID_MAP, "%d %d %d", 0, 0, 1);
 	}
testcases/kernel/syscalls/madvise/madvise08.c +1 -2
index 30f3604..10549f4 100644
@@ -110,8 +110,7 @@ static int find_sequence(int pid)
 
 	snprintf(dumpname, 256, "dump-%d", pid);
 	tst_res(TINFO, "Dump file should be %s", dumpname);
-	if (access(dumpname, F_OK))
-		tst_brk(TBROK | TERRNO, "Dump file was not found.");
+	SAFE_ACCESS(dumpname, F_OK);
 
 	dfd = SAFE_OPEN(dumpname, O_RDONLY);
 
testcases/kernel/syscalls/quotactl/quotactl01.c +2 -4
index 63f6e91..56c4f2f 100644
@@ -160,11 +160,9 @@ static void setup(void)
 	SAFE_CMD(cmd, NULL, NULL);
 	fmt_id = var->fmt_id;
 
-	if (access(USRPATH, F_OK) == -1)
-		tst_brk(TFAIL | TERRNO, "user quotafile didn't exist");
+	SAFE_ACCESS(USRPATH, F_OK);
 
-	if (access(GRPPATH, F_OK) == -1)
-		tst_brk(TFAIL | TERRNO, "group quotafile didn't exist");
+	SAFE_ACCESS(GRPPATH, F_OK);
 
 	tst_require_quota_support(tst_device->dev, fmt_id, usrpath);
 
testcases/kernel/syscalls/quotactl/quotactl06.c +1 -2
index feb4750..0ac099b 100644
@@ -186,8 +186,7 @@ static void setup(void)
 	/* vfsv0 block limit 2^42, vfsv1 block limit 2^63 - 1 */
 	set_dqmax.dqb_bsoftlimit = tst_variant ? 0x20000000000000 : 0x100000000;
 
-	if (access(USRPATH, F_OK) == -1)
-		tst_brk(TBROK | TERRNO, "user quotafile didn't exist");
+	SAFE_ACCESS(USRPATH, F_OK);
 
 	tst_require_quota_support(tst_device->dev, fmt_id, usrpath);
 
Signature · 5 lines
1.8.3.1


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

Re: [LTP] [PATCH v2 2/3] Make use of SAFE_ACCESS

Hi Dai

Looks good to me,

just some small nits:
Since quotactl01 use tst_brk(TFAIL | TERRNO), we should also mention it ie commit 706d412a quotactl06: Replace tst_brk(TFAIL) with TBROK does.

Also this patch need rebase since commit 26d117f8 ("syscalls/quotactl:
Remove tst_require_quota_support") break this source code.

Best Regards
Yang Xu

Quoted 99 lines
---
  testcases/kernel/mem/tunable/max_map_count.c    | 4 +---
  testcases/kernel/syscalls/fanotify/fanotify17.c | 3 +--
  testcases/kernel/syscalls/getxattr/getxattr05.c | 3 +--
  testcases/kernel/syscalls/madvise/madvise08.c   | 3 +--
  testcases/kernel/syscalls/quotactl/quotactl01.c | 6 ++----
  testcases/kernel/syscalls/quotactl/quotactl06.c | 3 +--
  6 files changed, 7 insertions(+), 15 deletions(-)
testcases/kernel/mem/tunable/max_map_count.c +1 -3
index a4c3dbf..caf8972 100644
@@ -58,9 +58,7 @@ static long old_overcommit = -1;
 
  static void setup(void)
  {
-	if (access(PATH_SYSVM "max_map_count", F_OK) != 0)
-		tst_brk(TBROK | TERRNO,
-			 "Can't support to test max_map_count");
+	SAFE_ACCESS(PATH_SYSVM "max_map_count", F_OK);
 
  	old_max_map_count = get_sys_tune("max_map_count");
  	old_overcommit = get_sys_tune("overcommit_memory");
testcases/kernel/syscalls/fanotify/fanotify17.c +1 -2
index 35beb53..7d74b25 100644
@@ -159,8 +159,7 @@ static void do_unshare(int map_root)
  		 * uid_map file should exist since Linux 3.8 because
  		 * it is available on Linux 3.5
  		 */
-		if (access(UID_MAP, F_OK))
-			tst_brk(TBROK, "file %s didn't exist", UID_MAP);
+		SAFE_ACCESS(UID_MAP, F_OK);
 
  		SAFE_FILE_PRINTF(UID_MAP, "%d %d %d", 0, 0, 1);
  	}
testcases/kernel/syscalls/getxattr/getxattr05.c +1 -2
index c0d339f..3e73cc5 100644
@@ -100,8 +100,7 @@ static void do_unshare(int map_root)
  		/* uid_map file should exist since Linux 3.8 because
  		 * it is available on Linux 3.5
  		 */
-		if (access(UID_MAP, F_OK))
-			tst_brk(TBROK, "file %s didn't exist", UID_MAP);
+		SAFE_ACCESS(UID_MAP, F_OK);
 
  		SAFE_FILE_PRINTF(UID_MAP, "%d %d %d", 0, 0, 1);
  	}
testcases/kernel/syscalls/madvise/madvise08.c +1 -2
index 30f3604..10549f4 100644
@@ -110,8 +110,7 @@ static int find_sequence(int pid)
 
  	snprintf(dumpname, 256, "dump-%d", pid);
  	tst_res(TINFO, "Dump file should be %s", dumpname);
-	if (access(dumpname, F_OK))
-		tst_brk(TBROK | TERRNO, "Dump file was not found.");
+	SAFE_ACCESS(dumpname, F_OK);
 
  	dfd = SAFE_OPEN(dumpname, O_RDONLY);
 
testcases/kernel/syscalls/quotactl/quotactl01.c +2 -4
index 63f6e91..56c4f2f 100644
@@ -160,11 +160,9 @@ static void setup(void)
  	SAFE_CMD(cmd, NULL, NULL);
  	fmt_id = var->fmt_id;
 
-	if (access(USRPATH, F_OK) == -1)
-		tst_brk(TFAIL | TERRNO, "user quotafile didn't exist");
+	SAFE_ACCESS(USRPATH, F_OK);
 
-	if (access(GRPPATH, F_OK) == -1)
-		tst_brk(TFAIL | TERRNO, "group quotafile didn't exist");
+	SAFE_ACCESS(GRPPATH, F_OK);
 
  	tst_require_quota_support(tst_device->dev, fmt_id, usrpath);
 
testcases/kernel/syscalls/quotactl/quotactl06.c +1 -2
index feb4750..0ac099b 100644
@@ -186,8 +186,7 @@ static void setup(void)
  	/* vfsv0 block limit 2^42, vfsv1 block limit 2^63 - 1 */
  	set_dqmax.dqb_bsoftlimit = tst_variant ? 0x20000000000000 : 0x100000000;
 
-	if (access(USRPATH, F_OK) == -1)
-		tst_brk(TBROK | TERRNO, "user quotafile didn't exist");
+	SAFE_ACCESS(USRPATH, F_OK);
 
  	tst_require_quota_support(tst_device->dev, fmt_id, usrpath);
 
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
author
#6 lore raw

PATCH v2 3/3 syscalls/umount2: Convert to new API and use SAFE_ACCESS

In reply to Dai Shili

1. use TST_EXP_FAIL and TST_EXP_PASS macro
2. use SAFE macro
3. simplify verify operations

---
 testcases/kernel/syscalls/umount2/umount2.h    |   5 +-
 testcases/kernel/syscalls/umount2/umount2_02.c | 194 +++++++------------------
 testcases/kernel/syscalls/umount2/umount2_03.c | 167 +++++----------------
 3 files changed, 94 insertions(+), 272 deletions(-)
testcases/kernel/syscalls/umount2/umount2.h +3 -2
index 65e4c24..d1e486e 100644
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2016 Cyril Hrubis <[email protected]>
  *
@@ -28,13 +29,13 @@ static inline int umount2_retry(const char *target, int flags)
 		if (ret == 0 || errno != EBUSY)
 			return ret;
 
-		tst_resm(TINFO, "umount('%s', %i) failed with EBUSY, try %2i...",
+		tst_res(TINFO, "umount('%s', %i) failed with EBUSY, try %2i...",
 			 target, flags, i);
 
 		usleep(100000);
 	}
 
-	tst_resm(TWARN, "Failed to umount('%s', %i) after 50 retries",
+	tst_res(TWARN, "Failed to umount('%s', %i) after 50 retries",
 	         target, flags);
 
 	errno = EBUSY;
testcases/kernel/syscalls/umount2/umount2_02.c +51 -143

233 lines not on this page · raw message

testcases/kernel/syscalls/umount2/umount2_03.c +40 -127

207 lines not on this page · raw message

Signature · 5 lines
1.8.3.1


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

Re: [LTP] [PATCH v2 3/3] syscalls/umount2: Convert to new API and use SAFE_ACCESS

Hi Dai

Since umount2_02 and umount2_03 is similar, can we merge them into a single case?

Best Regards
Yang Xu

Quoted 486 lines

1. use TST_EXP_FAIL and TST_EXP_PASS macro
2. use SAFE macro
3. simplify verify operations

---
  testcases/kernel/syscalls/umount2/umount2.h    |   5 +-
  testcases/kernel/syscalls/umount2/umount2_02.c | 194 +++++++------------------
  testcases/kernel/syscalls/umount2/umount2_03.c | 167 +++++----------------
  3 files changed, 94 insertions(+), 272 deletions(-)
testcases/kernel/syscalls/umount2/umount2.h +3 -2
index 65e4c24..d1e486e 100644
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
  /*
   * Copyright (c) 2016 Cyril Hrubis<[email protected]>
   *
@@ -28,13 +29,13 @@ static inline int umount2_retry(const char *target, int flags)
  		if (ret == 0 || errno != EBUSY)
  			return ret;
 
-		tst_resm(TINFO, "umount('%s', %i) failed with EBUSY, try %2i...",
+		tst_res(TINFO, "umount('%s', %i) failed with EBUSY, try %2i...",
  			 target, flags, i);
 
  		usleep(100000);
  	}
 
-	tst_resm(TWARN, "Failed to umount('%s', %i) after 50 retries",
+	tst_res(TWARN, "Failed to umount('%s', %i) after 50 retries",
  	         target, flags);
 
  	errno = EBUSY;
testcases/kernel/syscalls/umount2/umount2_02.c +51 -143
index 7d558fa..39f1608 100644
@@ -1,182 +1,90 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
  /*
- * Copyright (c) 2015 Fujitsu Ltd.
+ * Copyright (c) 2015-2022 FUJITSU LIMITED. All rights reserved
   * Author: Guangwen Feng<[email protected]>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License
- * alone with this program.
   */
 
  /*
- * DESCRIPTION
+ * [Description]
+ *
   *  Test for feature MNT_EXPIRE of umount2().
- *  "Mark the mount point as expired.If a mount point is not currently
- *   in use, then an initial call to umount2() with this flag fails with
- *   the error EAGAIN, but marks the mount point as expired. The mount
- *   point remains expired as long as it isn't accessed by any process.
- *   A second umount2() call specifying MNT_EXPIRE unmounts an expired
- *   mount point. This flag cannot be specified with either MNT_FORCE or
- *   MNT_DETACH. (fails with the error EINVAL)"
+ *
+ * - EINVAL when flag is specified with either MNT_FORCE or MNT_DETACH
+ * - EAGAIN when initial call to umount2(2) with MNT_EXPIRE
+ * - EAGAIN when umount2(2) with MNT_EXPIRE after access(2)
+ * - succeed when second call to umount2(2) with MNT_EXPIRE
   */
 
-#include<errno.h>
  #include<sys/mount.h>
-
-#include "test.h"
-#include "safe_macros.h"
  #include "lapi/mount.h"
-
+#include "tst_test.h"
  #include "umount2.h"
 
-#define DIR_MODE	(S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)
-#define MNTPOINT	"mntpoint"
-
-static void setup(void);
-static void test_umount2(int i);
-static void verify_failure(int i);
-static void verify_success(int i);
-static void cleanup(void);
-
-static const char *device;
-static const char *fs_type;
+#define MNTPOINT        "mntpoint"
 
  static int mount_flag;
 
-static struct test_case_t {
+static struct tcase {
  	int flag;
  	int exp_errno;
  	int do_access;
  	const char *desc;
-} test_cases[] = {
+} tcases[] = {
  	{MNT_EXPIRE | MNT_FORCE, EINVAL, 0,
-		"umount2(2) with MNT_EXPIRE | MNT_FORCE expected EINVAL"},
+		"umount2() with MNT_EXPIRE | MNT_FORCE expected EINVAL"},
+
  	{MNT_EXPIRE | MNT_DETACH, EINVAL, 0,
-		"umount2(2) with MNT_EXPIRE | MNT_DETACH expected EINVAL"},
+		"umount2() with MNT_EXPIRE | MNT_DETACH expected EINVAL"},
+
  	{MNT_EXPIRE, EAGAIN, 0,
-		"initial call to umount2(2) with MNT_EXPIRE expected EAGAIN"},
+		"initial call to umount2() with MNT_EXPIRE expected EAGAIN"},
+
  	{MNT_EXPIRE, EAGAIN, 1,
-		"umount2(2) with MNT_EXPIRE after access(2) expected EAGAIN"},
+		"umount2() with MNT_EXPIRE after access() expected EAGAIN"},
+
  	{MNT_EXPIRE, 0, 0,
-		"second call to umount2(2) with MNT_EXPIRE expected success"},
+		"second call to umount2() with MNT_EXPIRE expected success"},
  };
 
-char *TCID = "umount2_02";
-int TST_TOTAL = ARRAY_SIZE(test_cases);
-
-int main(int ac, char **av)
+static void test_umount2(unsigned int n)
  {
-	int lc;
-	int tc;
+	struct tcase *tc =&tcases[n];
 
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		SAFE_MOUNT(cleanup, device, MNTPOINT, fs_type, 0, NULL);
+	if (!mount_flag) {
+		SAFE_MOUNT(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, NULL);
  		mount_flag = 1;
-
-		for (tc = 0; tc<  TST_TOTAL; tc++)
-			test_umount2(tc);
-
-		if (mount_flag) {
-			if (tst_umount(MNTPOINT))
-				tst_brkm(TBROK, cleanup, "umount() failed");
-			mount_flag = 0;
-		}
  	}
 
-	cleanup();
-	tst_exit();
-}
-
-static void setup(void)
-{
-	tst_require_root();
-
-	if ((tst_kvercmp(2, 6, 8))<  0) {
-		tst_brkm(TCONF, NULL, "This test can only run on kernels "
-			 "that are 2.6.8 or higher");
-	}
-
-	tst_sig(NOFORK, DEF_HANDLER, NULL);
-
-	tst_tmpdir();
+	tst_res(TINFO, "Testing %s", tc->desc);
 
-	fs_type = tst_dev_fs_type();
-	device = tst_acquire_device(cleanup);
+	if (tc->do_access)
+		SAFE_ACCESS(MNTPOINT, F_OK);
 
-	if (!device)
-		tst_brkm(TCONF, cleanup, "Failed to obtain block device");
-
-	tst_mkfs(cleanup, device, fs_type, NULL, NULL);
-
-	SAFE_MKDIR(cleanup, MNTPOINT, DIR_MODE);
-
-	TEST_PAUSE;
-}
-
-static void test_umount2(int i)
-{
-	/* a new access removes the expired mark of the mount point */
-	if (test_cases[i].do_access) {
-		if (access(MNTPOINT, F_OK) == -1)
-			tst_brkm(TBROK | TERRNO, cleanup, "access(2) failed");
-	}
-
-	TEST(umount2_retry(MNTPOINT, test_cases[i].flag));
-
-	if (test_cases[i].exp_errno != 0)
-		verify_failure(i);
-	else
-		verify_success(i);
-}
-
-static void verify_failure(int i)
-{
-	if (TEST_RETURN == 0) {
-		tst_resm(TFAIL, "%s passed unexpectedly", test_cases[i].desc);
-		mount_flag = 0;
-		return;
-	}
-
-	if (TEST_ERRNO != test_cases[i].exp_errno) {
-		tst_resm(TFAIL | TTERRNO, "%s failed unexpectedly",
-			 test_cases[i].desc);
-		return;
-	}
-
-	tst_resm(TPASS | TTERRNO, "umount2(2) failed as expected");
-}
-
-static void verify_success(int i)
-{
-	if (TEST_RETURN != 0) {
-		tst_resm(TFAIL | TTERRNO, "%s failed unexpectedly",
-			 test_cases[i].desc);
-		return;
+	if (tc->exp_errno) {
+		TST_EXP_FAIL(umount2_retry(MNTPOINT, tc->flag), tc->exp_errno,
+			"umount2_retry(%s, %d)", MNTPOINT, tc->flag);
+		if (!TST_PASS)
+			mount_flag = 0;
+	} else {
+		TST_EXP_PASS(umount2_retry(MNTPOINT, tc->flag),
+			"umount2_retry(%s, %d)", MNTPOINT, tc->flag);
+		if (TST_PASS)
+			mount_flag = 0;
  	}
-
-	tst_resm(TPASS, "umount2(2) succeeded as expected");
-	mount_flag = 0;
  }
 
  static void cleanup(void)
  {
-	if (mount_flag&&  tst_umount(MNTPOINT))
-		tst_resm(TWARN | TERRNO, "Failed to unmount");
-
-	if (device)
-		tst_release_device(device);
-
-	tst_rmdir();
+	if (mount_flag)
+		SAFE_UMOUNT(MNTPOINT);
  }
+
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.cleanup = cleanup,
+	.needs_root = 1,
+	.needs_device = 1,
+	.format_device = 1,
+	.mntpoint = MNTPOINT,
+	.test = test_umount2,
+};
testcases/kernel/syscalls/umount2/umount2_03.c +40 -127
index a8fddf6..f44ff79 100644
@@ -1,167 +1,80 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
  /*
- * Copyright (c) 2015 Fujitsu Ltd.
+ * Copyright (c) 2015-2022 FUJITSU LIMITED. All rights reserved
   * Author: Guangwen Feng<[email protected]>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License
- * alone with this program.
   */
 
  /*
- * DESCRIPTION
+ * [Description]
+ *
   *  Test for feature UMOUNT_NOFOLLOW of umount2().
- *  "Don't dereference target if it is a symbolic link,
- *   and fails with the error EINVAL."
+ *
+ * - EINVAL when target is a symbolic link
+ * - succeed when target is a mount point
   */
 
-#include<errno.h>
  #include<sys/mount.h>
-
-#include "test.h"
-#include "safe_macros.h"
+#include "tst_test.h"
  #include "lapi/mount.h"
-
  #include "umount2.h"
 
-#define DIR_MODE	(S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)
  #define MNTPOINT	"mntpoint"
  #define SYMLINK	"symlink"
 
-static void setup(void);
-static void test_umount2(int i);
-static void verify_failure(int i);
-static void verify_success(int i);
-static void cleanup(void);
-
-static const char *device;
-static const char *fs_type;
-
  static int mount_flag;
 
  static struct test_case_t {
  	const char *mntpoint;
  	int exp_errno;
  	const char *desc;
-} test_cases[] = {
+} tcase[] = {
  	{SYMLINK, EINVAL,
  		"umount2('symlink', UMOUNT_NOFOLLOW) expected EINVAL"},
  	{MNTPOINT, 0,
  		"umount2('mntpoint', UMOUNT_NOFOLLOW) expected success"},
  };
 
-char *TCID = "umount2_03";
-int TST_TOTAL = ARRAY_SIZE(test_cases);
-
-int main(int ac, char **av)
+static void test_umount2(unsigned int n)
  {
-	int lc;
-	int tc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
+	struct test_case_t *tc =&tcase[n];
 
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		for (tc = 0; tc<  TST_TOTAL; tc++)
-			test_umount2(tc);
+	if (!mount_flag) {
+		SAFE_MOUNT(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, NULL);
+		mount_flag = 1;
  	}
 
-	cleanup();
-	tst_exit();
-}
-
-static void setup(void)
-{
-	tst_require_root();
-
-	if ((tst_kvercmp(2, 6, 34))<  0) {
-		tst_brkm(TCONF, NULL, "This test can only run on kernels "
-			 "that are 2.6.34 or higher");
-	}
-
-	tst_sig(NOFORK, DEF_HANDLER, NULL);
-
-	tst_tmpdir();
-
-	fs_type = tst_dev_fs_type();
-	device = tst_acquire_device(cleanup);
-
-	if (!device)
-		tst_brkm(TCONF, cleanup, "Failed to obtain block device");
-
-	tst_mkfs(cleanup, device, fs_type, NULL, NULL);
-
-	SAFE_MKDIR(cleanup, MNTPOINT, DIR_MODE);
-
-	SAFE_SYMLINK(cleanup, MNTPOINT, SYMLINK);
-
-	TEST_PAUSE;
-}
-
-static void test_umount2(int i)
-{
-	SAFE_MOUNT(cleanup, device, MNTPOINT, fs_type, 0, NULL);
-	mount_flag = 1;
-
-	TEST(umount2_retry(test_cases[i].mntpoint, UMOUNT_NOFOLLOW));
-
-	if (test_cases[i].exp_errno != 0)
-		verify_failure(i);
-	else
-		verify_success(i);
-
-	if (mount_flag) {
-		if (tst_umount(MNTPOINT))
-			tst_brkm(TBROK, cleanup, "umount() failed");
-		mount_flag = 0;
+	tst_res(TINFO, "Testing %s", tc->desc);
+
+	if (tc->exp_errno) {
+		TST_EXP_FAIL(umount2_retry(tc->mntpoint, UMOUNT_NOFOLLOW), tc->exp_errno,
+			"umount2_retry(%s, %d)", tc->mntpoint, UMOUNT_NOFOLLOW);
+		if (!TST_PASS)
+			mount_flag = 0;
+	} else {
+		TST_EXP_PASS(umount2_retry(tc->mntpoint, UMOUNT_NOFOLLOW),
+			"umount2_retry(%s, %d)", tc->mntpoint, UMOUNT_NOFOLLOW);
+		if (TST_PASS)
+			mount_flag = 0;
  	}
  }
 
-static void verify_failure(int i)
-{
-	if (TEST_RETURN == 0) {
-		tst_resm(TFAIL, "%s passed unexpectedly", test_cases[i].desc);
-		mount_flag = 0;
-		return;
-	}
-
-	if (TEST_ERRNO != test_cases[i].exp_errno) {
-		tst_resm(TFAIL | TTERRNO, "%s failed unexpectedly",
-			 test_cases[i].desc);
-		return;
-	}
-
-	tst_resm(TPASS | TTERRNO, "umount2(2) failed as expected");
-}
-
-static void verify_success(int i)
+static void setup(void)
  {
-	if (TEST_RETURN != 0) {
-		tst_resm(TFAIL | TTERRNO, "%s failed unexpectedly",
-			 test_cases[i].desc);
-		return;
-	}
-
-	tst_resm(TPASS, "umount2(2) succeeded as expected");
-	mount_flag = 0;
+	SAFE_SYMLINK(MNTPOINT, SYMLINK);
  }
 
  static void cleanup(void)
  {
-	if (mount_flag&&  tst_umount(MNTPOINT))
-		tst_resm(TWARN | TERRNO, "Failed to unmount");
-
-	if (device)
-		tst_release_device(device);
-
-	tst_rmdir();
+	if (mount_flag)
+		SAFE_UMOUNT(MNTPOINT);
  }
+
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcase),
+	.needs_tmpdir = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.format_device = 1,
+	.mntpoint = MNTPOINT,
+	.test = test_umount2,
+};
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#8 lore raw

Re: [LTP] [PATCH v2 3/3] syscalls/umount2: Convert to new API and use SAFE_ACCESS

Hi Dai

Sorry, it seems keep umount2_02 and umount2_03 is more clean.

Quoted 66 lines

Hi Dai

Since umount2_02 and umount2_03 is similar, can we merge them into a single case?

Best Regards
Yang Xu

Quoted 59 lines

1. use TST_EXP_FAIL and TST_EXP_PASS macro
2. use SAFE macro
3. simplify verify operations

---
   testcases/kernel/syscalls/umount2/umount2.h    |   5 +-
   testcases/kernel/syscalls/umount2/umount2_02.c | 194 +++++++------------------
   testcases/kernel/syscalls/umount2/umount2_03.c | 167 +++++----------------
   3 files changed, 94 insertions(+), 272 deletions(-)
testcases/kernel/syscalls/umount2/umount2.h +3 -2
index 65e4c24..d1e486e 100644
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
   /*
    * Copyright (c) 2016 Cyril Hrubis<[email protected]>
    *
@@ -28,13 +29,13 @@ static inline int umount2_retry(const char *target, int flags)
   		if (ret == 0 || errno != EBUSY)
   			return ret;
 
-		tst_resm(TINFO, "umount('%s', %i) failed with EBUSY, try %2i...",
+		tst_res(TINFO, "umount('%s', %i) failed with EBUSY, try %2i...",
   			 target, flags, i);
 
   		usleep(100000);
   	}
 
-	tst_resm(TWARN, "Failed to umount('%s', %i) after 50 retries",
+	tst_res(TWARN, "Failed to umount('%s', %i) after 50 retries",
   	         target, flags);
 
   	errno = EBUSY;
testcases/kernel/syscalls/umount2/umount2_02.c +2 -12
index 7d558fa..39f1608 100644
@@ -1,182 +1,90 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
   /*
- * Copyright (c) 2015 Fujitsu Ltd.
+ * Copyright (c) 2015-2022 FUJITSU LIMITED. All rights reserved
    * Author: Guangwen Feng<[email protected]>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License
- * alone with this program.
    */
 
Quoted 1 line

testcases/kernel/syscalls/umount2/umount2_02.c line 7

Quoted 1 line
testcases/kernel/syscalls/umount2/umount2_02.c +0 -0
   /*

typo, /* => /*\

Quoted 203 lines
Quoted 203 lines
testcases/kernel/syscalls/umount2/umount2_02.c +39 -131
- * DESCRIPTION
+ * [Description]
+ *
    *  Test for feature MNT_EXPIRE of umount2().
- *  "Mark the mount point as expired.If a mount point is not currently
- *   in use, then an initial call to umount2() with this flag fails with
- *   the error EAGAIN, but marks the mount point as expired. The mount
- *   point remains expired as long as it isn't accessed by any process.
- *   A second umount2() call specifying MNT_EXPIRE unmounts an expired
- *   mount point. This flag cannot be specified with either MNT_FORCE or
- *   MNT_DETACH. (fails with the error EINVAL)"
+ *
+ * - EINVAL when flag is specified with either MNT_FORCE or MNT_DETACH
+ * - EAGAIN when initial call to umount2(2) with MNT_EXPIRE
+ * - EAGAIN when umount2(2) with MNT_EXPIRE after access(2)
+ * - succeed when second call to umount2(2) with MNT_EXPIRE
    */
 
-#include<errno.h>
   #include<sys/mount.h>
-
-#include "test.h"
-#include "safe_macros.h"
   #include "lapi/mount.h"
-
+#include "tst_test.h"
   #include "umount2.h"
 
-#define DIR_MODE	(S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)
-#define MNTPOINT	"mntpoint"
-
-static void setup(void);
-static void test_umount2(int i);
-static void verify_failure(int i);
-static void verify_success(int i);
-static void cleanup(void);
-
-static const char *device;
-static const char *fs_type;
+#define MNTPOINT        "mntpoint"
 
   static int mount_flag;
 
-static struct test_case_t {
+static struct tcase {
   	int flag;
   	int exp_errno;
   	int do_access;
   	const char *desc;
-} test_cases[] = {
+} tcases[] = {
   	{MNT_EXPIRE | MNT_FORCE, EINVAL, 0,
-		"umount2(2) with MNT_EXPIRE | MNT_FORCE expected EINVAL"},
+		"umount2() with MNT_EXPIRE | MNT_FORCE expected EINVAL"},
+
   	{MNT_EXPIRE | MNT_DETACH, EINVAL, 0,
-		"umount2(2) with MNT_EXPIRE | MNT_DETACH expected EINVAL"},
+		"umount2() with MNT_EXPIRE | MNT_DETACH expected EINVAL"},
+
   	{MNT_EXPIRE, EAGAIN, 0,
-		"initial call to umount2(2) with MNT_EXPIRE expected EAGAIN"},
+		"initial call to umount2() with MNT_EXPIRE expected EAGAIN"},
+
   	{MNT_EXPIRE, EAGAIN, 1,
-		"umount2(2) with MNT_EXPIRE after access(2) expected EAGAIN"},
+		"umount2() with MNT_EXPIRE after access() expected EAGAIN"},
+
   	{MNT_EXPIRE, 0, 0,
-		"second call to umount2(2) with MNT_EXPIRE expected success"},
+		"second call to umount2() with MNT_EXPIRE expected success"},
   };
 
-char *TCID = "umount2_02";
-int TST_TOTAL = ARRAY_SIZE(test_cases);
-
-int main(int ac, char **av)
+static void test_umount2(unsigned int n)
   {
-	int lc;
-	int tc;
+	struct tcase *tc =&tcases[n];
 
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		SAFE_MOUNT(cleanup, device, MNTPOINT, fs_type, 0, NULL);
+	if (!mount_flag) {
+		SAFE_MOUNT(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, NULL);
   		mount_flag = 1;
-
-		for (tc = 0; tc<   TST_TOTAL; tc++)
-			test_umount2(tc);
-
-		if (mount_flag) {
-			if (tst_umount(MNTPOINT))
-				tst_brkm(TBROK, cleanup, "umount() failed");
-			mount_flag = 0;
-		}
   	}
 
-	cleanup();
-	tst_exit();
-}
-
-static void setup(void)
-{
-	tst_require_root();
-
-	if ((tst_kvercmp(2, 6, 8))<   0) {
-		tst_brkm(TCONF, NULL, "This test can only run on kernels "
-			 "that are 2.6.8 or higher");
-	}
-
-	tst_sig(NOFORK, DEF_HANDLER, NULL);
-
-	tst_tmpdir();
+	tst_res(TINFO, "Testing %s", tc->desc);
 
-	fs_type = tst_dev_fs_type();
-	device = tst_acquire_device(cleanup);
+	if (tc->do_access)
+		SAFE_ACCESS(MNTPOINT, F_OK);
 
-	if (!device)
-		tst_brkm(TCONF, cleanup, "Failed to obtain block device");
-
-	tst_mkfs(cleanup, device, fs_type, NULL, NULL);
-
-	SAFE_MKDIR(cleanup, MNTPOINT, DIR_MODE);
-
-	TEST_PAUSE;
-}
-
-static void test_umount2(int i)
-{
-	/* a new access removes the expired mark of the mount point */
-	if (test_cases[i].do_access) {
-		if (access(MNTPOINT, F_OK) == -1)
-			tst_brkm(TBROK | TERRNO, cleanup, "access(2) failed");
-	}
-
-	TEST(umount2_retry(MNTPOINT, test_cases[i].flag));
-
-	if (test_cases[i].exp_errno != 0)
-		verify_failure(i);
-	else
-		verify_success(i);
-}
-
-static void verify_failure(int i)
-{
-	if (TEST_RETURN == 0) {
-		tst_resm(TFAIL, "%s passed unexpectedly", test_cases[i].desc);
-		mount_flag = 0;
-		return;
-	}
-
-	if (TEST_ERRNO != test_cases[i].exp_errno) {
-		tst_resm(TFAIL | TTERRNO, "%s failed unexpectedly",
-			 test_cases[i].desc);
-		return;
-	}
-
-	tst_resm(TPASS | TTERRNO, "umount2(2) failed as expected");
-}
-
-static void verify_success(int i)
-{
-	if (TEST_RETURN != 0) {
-		tst_resm(TFAIL | TTERRNO, "%s failed unexpectedly",
-			 test_cases[i].desc);
-		return;
+	if (tc->exp_errno) {
+		TST_EXP_FAIL(umount2_retry(MNTPOINT, tc->flag), tc->exp_errno,
+			"umount2_retry(%s, %d)", MNTPOINT, tc->flag);
+		if (!TST_PASS)
+			mount_flag = 0;
+	} else {
+		TST_EXP_PASS(umount2_retry(MNTPOINT, tc->flag),
+			"umount2_retry(%s, %d)", MNTPOINT, tc->flag);
+		if (TST_PASS)
+			mount_flag = 0;
   	}
-
-	tst_resm(TPASS, "umount2(2) succeeded as expected");
-	mount_flag = 0;
   }
 
   static void cleanup(void)
   {
-	if (mount_flag&&   tst_umount(MNTPOINT))
-		tst_resm(TWARN | TERRNO, "Failed to unmount");
-
-	if (device)
-		tst_release_device(device);
-
-	tst_rmdir();
+	if (mount_flag)
+		SAFE_UMOUNT(MNTPOINT);
Quoted 8 lines

testcases/kernel/syscalls/umount2/umount2_02.c line 87

Quoted 8 lines
testcases/kernel/syscalls/umount2/umount2_02.c +7 -0
   }
+
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.cleanup = cleanup,
+	.needs_root = 1,
+	.needs_device = 1,
+	.format_device = 1,

If we specify format_device, it wil assign value for needs_device a utomatically. So we can remove redundant needs_device.

Quoted 26 lines
Quoted 26 lines
testcases/kernel/syscalls/umount2/umount2_02.c +3 -0
+	.mntpoint = MNTPOINT,
+	.test = test_umount2,
+};
testcases/kernel/syscalls/umount2/umount2_03.c +2 -12
index a8fddf6..f44ff79 100644
@@ -1,167 +1,80 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
   /*
- * Copyright (c) 2015 Fujitsu Ltd.
+ * Copyright (c) 2015-2022 FUJITSU LIMITED. All rights reserved
    * Author: Guangwen Feng<[email protected]>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License
- * alone with this program.
    */
 
Quoted 1 line

testcases/kernel/syscalls/umount2/umount2_03.c line 7

Quoted 1 line
testcases/kernel/syscalls/umount2/umount2_03.c +0 -0
   /*

Here as well.

Best Regards
Yang Xu

Quoted 189 lines
Quoted 188 lines
testcases/kernel/syscalls/umount2/umount2_03.c +38 -115
- * DESCRIPTION
+ * [Description]
+ *
    *  Test for feature UMOUNT_NOFOLLOW of umount2().
- *  "Don't dereference target if it is a symbolic link,
- *   and fails with the error EINVAL."
+ *
+ * - EINVAL when target is a symbolic link
+ * - succeed when target is a mount point
    */
 
-#include<errno.h>
   #include<sys/mount.h>
-
-#include "test.h"
-#include "safe_macros.h"
+#include "tst_test.h"
   #include "lapi/mount.h"
-
   #include "umount2.h"
 
-#define DIR_MODE	(S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)
   #define MNTPOINT	"mntpoint"
   #define SYMLINK	"symlink"
 
-static void setup(void);
-static void test_umount2(int i);
-static void verify_failure(int i);
-static void verify_success(int i);
-static void cleanup(void);
-
-static const char *device;
-static const char *fs_type;
-
   static int mount_flag;
 
   static struct test_case_t {
   	const char *mntpoint;
   	int exp_errno;
   	const char *desc;
-} test_cases[] = {
+} tcase[] = {
   	{SYMLINK, EINVAL,
   		"umount2('symlink', UMOUNT_NOFOLLOW) expected EINVAL"},
   	{MNTPOINT, 0,
   		"umount2('mntpoint', UMOUNT_NOFOLLOW) expected success"},
   };
 
-char *TCID = "umount2_03";
-int TST_TOTAL = ARRAY_SIZE(test_cases);
-
-int main(int ac, char **av)
+static void test_umount2(unsigned int n)
   {
-	int lc;
-	int tc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
+	struct test_case_t *tc =&tcase[n];
 
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		for (tc = 0; tc<   TST_TOTAL; tc++)
-			test_umount2(tc);
+	if (!mount_flag) {
+		SAFE_MOUNT(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, NULL);
+		mount_flag = 1;
   	}
 
-	cleanup();
-	tst_exit();
-}
-
-static void setup(void)
-{
-	tst_require_root();
-
-	if ((tst_kvercmp(2, 6, 34))<   0) {
-		tst_brkm(TCONF, NULL, "This test can only run on kernels "
-			 "that are 2.6.34 or higher");
-	}
-
-	tst_sig(NOFORK, DEF_HANDLER, NULL);
-
-	tst_tmpdir();
-
-	fs_type = tst_dev_fs_type();
-	device = tst_acquire_device(cleanup);
-
-	if (!device)
-		tst_brkm(TCONF, cleanup, "Failed to obtain block device");
-
-	tst_mkfs(cleanup, device, fs_type, NULL, NULL);
-
-	SAFE_MKDIR(cleanup, MNTPOINT, DIR_MODE);
-
-	SAFE_SYMLINK(cleanup, MNTPOINT, SYMLINK);
-
-	TEST_PAUSE;
-}
-
-static void test_umount2(int i)
-{
-	SAFE_MOUNT(cleanup, device, MNTPOINT, fs_type, 0, NULL);
-	mount_flag = 1;
-
-	TEST(umount2_retry(test_cases[i].mntpoint, UMOUNT_NOFOLLOW));
-
-	if (test_cases[i].exp_errno != 0)
-		verify_failure(i);
-	else
-		verify_success(i);
-
-	if (mount_flag) {
-		if (tst_umount(MNTPOINT))
-			tst_brkm(TBROK, cleanup, "umount() failed");
-		mount_flag = 0;
+	tst_res(TINFO, "Testing %s", tc->desc);
+
+	if (tc->exp_errno) {
+		TST_EXP_FAIL(umount2_retry(tc->mntpoint, UMOUNT_NOFOLLOW), tc->exp_errno,
+			"umount2_retry(%s, %d)", tc->mntpoint, UMOUNT_NOFOLLOW);
+		if (!TST_PASS)
+			mount_flag = 0;
+	} else {
+		TST_EXP_PASS(umount2_retry(tc->mntpoint, UMOUNT_NOFOLLOW),
+			"umount2_retry(%s, %d)", tc->mntpoint, UMOUNT_NOFOLLOW);
+		if (TST_PASS)
+			mount_flag = 0;
   	}
   }
 
-static void verify_failure(int i)
-{
-	if (TEST_RETURN == 0) {
-		tst_resm(TFAIL, "%s passed unexpectedly", test_cases[i].desc);
-		mount_flag = 0;
-		return;
-	}
-
-	if (TEST_ERRNO != test_cases[i].exp_errno) {
-		tst_resm(TFAIL | TTERRNO, "%s failed unexpectedly",
-			 test_cases[i].desc);
-		return;
-	}
-
-	tst_resm(TPASS | TTERRNO, "umount2(2) failed as expected");
-}
-
-static void verify_success(int i)
+static void setup(void)
   {
-	if (TEST_RETURN != 0) {
-		tst_resm(TFAIL | TTERRNO, "%s failed unexpectedly",
-			 test_cases[i].desc);
-		return;
-	}
-
-	tst_resm(TPASS, "umount2(2) succeeded as expected");
-	mount_flag = 0;
+	SAFE_SYMLINK(MNTPOINT, SYMLINK);
   }
 
   static void cleanup(void)
   {
-	if (mount_flag&&   tst_umount(MNTPOINT))
-		tst_resm(TWARN | TERRNO, "Failed to unmount");
-
-	if (device)
-		tst_release_device(device);
-
-	tst_rmdir();
+	if (mount_flag)
+		SAFE_UMOUNT(MNTPOINT);
   }
+
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcase),
+	.needs_tmpdir = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.format_device = 1,
+	.mntpoint = MNTPOINT,
+	.test = test_umount2,
+};
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
author
#9 lore raw

PATCH v3 1/3 Add SAFE_ACCESS macro

---
 include/tst_safe_macros.h |  5 +++++
 lib/tst_safe_macros.c     | 19 +++++++++++++++++++
 2 files changed, 24 insertions(+)
include/tst_safe_macros.h +5 -0
index 9a543e4..81c4b08 100644
@@ -24,6 +24,11 @@
 #include "safe_macros_fn.h"
 #include "tst_cmd.h"
 
+int safe_access(const char *filename, const int lineno, const char *pathname,
+		   int mode);
+#define SAFE_ACCESS(path, mode) \
+	safe_access(__FILE__, __LINE__, (path), (mode))
+
 #define SAFE_BASENAME(path) \
 	safe_basename(__FILE__, __LINE__, NULL, (path))
 
lib/tst_safe_macros.c +19 -0
index a9f6aeb..c4cdc87 100644
@@ -20,6 +20,25 @@
 #include "lapi/personality.h"
 #include "lapi/pidfd.h"
 
+int safe_access(const char *file, const int lineno,
+	    const char *pathname, int mode)
+{
+	int rval;
+
+	rval = access(pathname, mode);
+
+	if (rval == -1) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"access(%s,%d) failed", pathname, mode);
+	} else if (rval) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"Invalid access(%s,%d) return value %d", pathname,
+			mode, rval);
+	}
+
+	return rval;
+}
+
 int safe_setpgid(const char *file, const int lineno, pid_t pid, pid_t pgid)
 {
 	int rval;
Signature · 5 lines
1.8.3.1


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

PATCH v3 2/3 Make use of SAFE_ACCESS

1. quotactl01: Replace tst_brk(TFAIL) with TBROK
2. use SAFE_ACCESS

---
 testcases/kernel/mem/tunable/max_map_count.c    | 4 +---
 testcases/kernel/syscalls/fanotify/fanotify17.c | 3 +--
 testcases/kernel/syscalls/getxattr/getxattr05.c | 3 +--
 testcases/kernel/syscalls/madvise/madvise08.c   | 3 +--
 testcases/kernel/syscalls/quotactl/quotactl01.c | 6 ++----
 testcases/kernel/syscalls/quotactl/quotactl06.c | 3 +--
 6 files changed, 7 insertions(+), 15 deletions(-)
testcases/kernel/mem/tunable/max_map_count.c +1 -3
index a4c3dbf..caf8972 100644
@@ -58,9 +58,7 @@ static long old_overcommit = -1;
 
 static void setup(void)
 {
-	if (access(PATH_SYSVM "max_map_count", F_OK) != 0)
-		tst_brk(TBROK | TERRNO,
-			 "Can't support to test max_map_count");
+	SAFE_ACCESS(PATH_SYSVM "max_map_count", F_OK);
 
 	old_max_map_count = get_sys_tune("max_map_count");
 	old_overcommit = get_sys_tune("overcommit_memory");
testcases/kernel/syscalls/fanotify/fanotify17.c +1 -2
index 35beb53..7d74b25 100644
@@ -159,8 +159,7 @@ static void do_unshare(int map_root)
 		 * uid_map file should exist since Linux 3.8 because
 		 * it is available on Linux 3.5
 		 */
-		if (access(UID_MAP, F_OK))
-			tst_brk(TBROK, "file %s didn't exist", UID_MAP);
+		SAFE_ACCESS(UID_MAP, F_OK);
 
 		SAFE_FILE_PRINTF(UID_MAP, "%d %d %d", 0, 0, 1);
 	}
testcases/kernel/syscalls/getxattr/getxattr05.c +1 -2
index c0d339f..3e73cc5 100644
@@ -100,8 +100,7 @@ static void do_unshare(int map_root)
 		/* uid_map file should exist since Linux 3.8 because
 		 * it is available on Linux 3.5
 		 */
-		if (access(UID_MAP, F_OK))
-			tst_brk(TBROK, "file %s didn't exist", UID_MAP);
+		SAFE_ACCESS(UID_MAP, F_OK);
 
 		SAFE_FILE_PRINTF(UID_MAP, "%d %d %d", 0, 0, 1);
 	}
testcases/kernel/syscalls/madvise/madvise08.c +1 -2
index 30f3604..10549f4 100644
@@ -110,8 +110,7 @@ static int find_sequence(int pid)
 
 	snprintf(dumpname, 256, "dump-%d", pid);
 	tst_res(TINFO, "Dump file should be %s", dumpname);
-	if (access(dumpname, F_OK))
-		tst_brk(TBROK | TERRNO, "Dump file was not found.");
+	SAFE_ACCESS(dumpname, F_OK);
 
 	dfd = SAFE_OPEN(dumpname, O_RDONLY);
 
testcases/kernel/syscalls/quotactl/quotactl01.c +2 -4
index c14228e..36ec93e 100644
@@ -160,11 +160,9 @@ static void setup(void)
 	SAFE_CMD(cmd, NULL, NULL);
 	fmt_id = var->fmt_id;
 
-	if (access(USRPATH, F_OK) == -1)
-		tst_brk(TFAIL | TERRNO, "user quotafile didn't exist");
+	SAFE_ACCESS(USRPATH, F_OK);
 
-	if (access(GRPPATH, F_OK) == -1)
-		tst_brk(TFAIL | TERRNO, "group quotafile didn't exist");
+	SAFE_ACCESS(GRPPATH, F_OK);
 
 	TEST(quotactl(QCMD(Q_GETNEXTQUOTA, USRQUOTA), tst_device->dev,
 		test_id, (void *) &res_ndq));
testcases/kernel/syscalls/quotactl/quotactl06.c +1 -2
index ae8d7fa..74a098a 100644
@@ -186,8 +186,7 @@ static void setup(void)
 	/* vfsv0 block limit 2^42, vfsv1 block limit 2^63 - 1 */
 	set_dqmax.dqb_bsoftlimit = tst_variant ? 0x20000000000000 : 0x100000000;
 
-	if (access(USRPATH, F_OK) == -1)
-		tst_brk(TBROK | TERRNO, "user quotafile didn't exist");
+	SAFE_ACCESS(USRPATH, F_OK);
 
 	SAFE_MKDIR(TESTDIR1, 0666);
 
Signature · 5 lines
1.8.3.1


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

Re: [LTP] [PATCH v3 2/3] Make use of SAFE_ACCESS

In reply to Dai Shili

And also this one merged.

Kind regards,
Petr

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

PATCH v3 3/3 syscalls/umount2: Convert to new API and use SAFE_ACCESS

In reply to Dai Shili

1. use TST_EXP_FAIL and TST_EXP_PASS macro
2. use SAFE macro
3. simplify verify operations
4. merge umount2_03 to umount2_02

---
 runtest/syscalls                               |   1 -
 testcases/kernel/syscalls/umount2/.gitignore   |   1 -
 testcases/kernel/syscalls/umount2/umount2.h    |   5 +-
 testcases/kernel/syscalls/umount2/umount2_02.c | 209 ++++++++-----------------
 testcases/kernel/syscalls/umount2/umount2_03.c | 167 --------------------
 5 files changed, 71 insertions(+), 312 deletions(-)
 delete mode 100644 testcases/kernel/syscalls/umount2/umount2_03.c
runtest/syscalls +0 -1
index 6186bfc..0eea946 100644
@@ -1647,7 +1647,6 @@ umount03 umount03
 
 umount2_01 umount2_01
 umount2_02 umount2_02
-umount2_03 umount2_03
 
 userfaultfd01 userfaultfd01
 
testcases/kernel/syscalls/umount2/.gitignore +0 -1
index 1d6a0e8..e2056bf 100644
@@ -1,3 +1,2 @@
 /umount2_01
 /umount2_02
-/umount2_03
testcases/kernel/syscalls/umount2/umount2.h +3 -2
index 65e4c24..d1e486e 100644
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2016 Cyril Hrubis <[email protected]>
  *
@@ -28,13 +29,13 @@ static inline int umount2_retry(const char *target, int flags)
 		if (ret == 0 || errno != EBUSY)
 			return ret;
 
-		tst_resm(TINFO, "umount('%s', %i) failed with EBUSY, try %2i...",
+		tst_res(TINFO, "umount('%s', %i) failed with EBUSY, try %2i...",
 			 target, flags, i);
 
 		usleep(100000);
 	}
 
-	tst_resm(TWARN, "Failed to umount('%s', %i) after 50 retries",
+	tst_res(TWARN, "Failed to umount('%s', %i) after 50 retries",
 	         target, flags);
 
 	errno = EBUSY;
testcases/kernel/syscalls/umount2/umount2_02.c +68 -141

250 lines not on this page · raw message

testcases/kernel/syscalls/umount2/umount2_03.c deleted +0 -167

167 lines not on this page · raw message

Signature · 5 lines
1.8.3.1


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

Re: [LTP] [PATCH v3 3/3] syscalls/umount2: Convert to new API and use SAFE_ACCESS

Hi Dai,

testcases/kernel/syscalls/umount2/umount2.h line 4

Quoted 6 lines

+++ b/testcases/kernel/syscalls/umount2/umount2.h

testcases/kernel/syscalls/umount2/umount2.h +1 -0
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2016 Cyril Hrubis <[email protected]>
  *

nit: if you add SPDX (good to do) you're supposed to remove GPL text (i.e. remove: "This program is free software: you ...")

Can be done before merge.

Kind regards,
Petr

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

Re: [LTP] [PATCH v3 3/3] syscalls/umount2: Convert to new API and use SAFE_ACCESS

Hi Petr,

Quoted 11 lines · Petr Vorel

Hi Dai,

testcases/kernel/syscalls/umount2/umount2.h line 4

Quoted 6 lines

+++ b/testcases/kernel/syscalls/umount2/umount2.h

testcases/kernel/syscalls/umount2/umount2.h +1 -0
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
  /*
   * Copyright (c) 2016 Cyril Hrubis <[email protected]>
   *

nit: if you add SPDX (good to do) you're supposed to remove GPL text (i.e. remove: "This program is free software: you ...")

Quoted 1 line

Can be done before merge.

Got it. I will send v4.

Quoted 2 lines

Kind regards,
Petr

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

PATCH v4 1/1 syscalls/umount2: Convert to new API and use SAFE_ACCESS

In reply to Petr Vorel

1. use TST_EXP_FAIL and TST_EXP_PASS macro
2. use SAFE macro
3. simplify verify operations
4. merge umount2_03 to umount2_02

---
 runtest/syscalls                               |   1 -
 testcases/kernel/syscalls/umount2/.gitignore   |   1 -
 testcases/kernel/syscalls/umount2/umount2.h    |  18 +--
 testcases/kernel/syscalls/umount2/umount2_02.c | 210 ++++++++-----------------
 testcases/kernel/syscalls/umount2/umount2_03.c | 167 --------------------
 5 files changed, 71 insertions(+), 326 deletions(-)
 delete mode 100644 testcases/kernel/syscalls/umount2/umount2_03.c
runtest/syscalls +0 -1
index 6186bfc..0eea946 100644
@@ -1647,7 +1647,6 @@ umount03 umount03
 
 umount2_01 umount2_01
 umount2_02 umount2_02
-umount2_03 umount2_03
 
 userfaultfd01 userfaultfd01
 
testcases/kernel/syscalls/umount2/.gitignore +0 -1
index 1d6a0e8..e2056bf 100644
@@ -1,3 +1,2 @@
 /umount2_01
 /umount2_02
-/umount2_03
testcases/kernel/syscalls/umount2/umount2.h +3 -15
index 65e4c24..22df8c6 100644
@@ -1,18 +1,6 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2016 Cyril Hrubis <[email protected]>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 
 #ifndef UMOUNT2_H__
@@ -28,13 +16,13 @@ static inline int umount2_retry(const char *target, int flags)
 		if (ret == 0 || errno != EBUSY)
 			return ret;
 
-		tst_resm(TINFO, "umount('%s', %i) failed with EBUSY, try %2i...",
+		tst_res(TINFO, "umount('%s', %i) failed with EBUSY, try %2i...",
 			 target, flags, i);
 
 		usleep(100000);
 	}
 
-	tst_resm(TWARN, "Failed to umount('%s', %i) after 50 retries",
+	tst_res(TWARN, "Failed to umount('%s', %i) after 50 retries",
 	         target, flags);
 
 	errno = EBUSY;
testcases/kernel/syscalls/umount2/umount2_02.c +68 -142

250 lines not on this page · raw message

testcases/kernel/syscalls/umount2/umount2_03.c deleted +0 -167

167 lines not on this page · raw message

Signature · 5 lines
1.8.3.1


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

Re: [LTP] [PATCH v4] syscalls/umount2: Convert to new API and use SAFE_ACCESS

Hi Dai,

We're nearly there, IMHO 2 minor changes are required.

nit: you can help reviewers to list changelog from previous version (for your next patches), see:

https://patchwork.ozlabs.org/project/ltp/patch/[email protected]/
https://patchwork.ozlabs.org/project/ltp/cover/[email protected]/

Quoted 4 lines

1. use TST_EXP_FAIL and TST_EXP_PASS macro
2. use SAFE macro
3. simplify verify operations
4. merge umount2_03 to umount2_02

very nit: more important that "use SAFE macro" (that's one of the main reasons why we use new API) is to mention the reason why to merge tests.

...

Quoted 4 lines

+/*\
+ * [Description]
+ *
* Test for feature MNT_EXPIRE of umount2().

This must be:
* Test for feature MNT_EXPIRE of umount2().
extra space after '* ' leads text to be formatted as <pre> or <code>.

Quoted 7 lines

- * "Mark the mount point as expired.If a mount point is not currently

- *   in use, then an initial call to umount2() with this flag fails with
- *   the error EAGAIN, but marks the mount point as expired. The mount
- *   point remains expired as long as it isn't accessed by any process.
- *   A second umount2() call specifying MNT_EXPIRE unmounts an expired
- *   mount point. This flag cannot be specified with either MNT_FORCE or
- *   MNT_DETACH. (fails with the error EINVAL)"
Quoted 7 lines

+ *
+ * - EINVAL when flag is specified with either MNT_FORCE or MNT_DETACH
+ * - EAGAIN when initial call to umount2(2) with MNT_EXPIRE
+ * - EAGAIN when umount2(2) with MNT_EXPIRE after access(2)
+ * - succeed when second call to umount2(2) with MNT_EXPIRE
+ *
+ * Test for feature UMOUNT_NOFOLLOW of umount2().

And here as well:
* Test for feature UMOUNT_NOFOLLOW of umount2().

run make in metadata/ and then check docparse/metadata.html (or docparse/metadata.pdf).

(1st thing to change)

Quoted 5 lines

+ *
+ * - EINVAL when target is a symbolic link
+ * - succeed when target is a mount point
*/

testcases/kernel/syscalls/umount2/umount2_02.c line 26

Quoted 9 lines
testcases/kernel/syscalls/umount2/umount2_02.c +1 -5
-#include <errno.h>
 #include <sys/mount.h>
-
-#include "test.h"
-#include "safe_macros.h"
 #include "lapi/mount.h"
-
+#include "tst_test.h"
 #include "umount2.h"

umount2.h is now used only in this test. Please put the content into the test and delete the file (2nd change to do).

...

testcases/kernel/syscalls/umount2/umount2_02.c line 41

Quoted 3 lines
testcases/kernel/syscalls/umount2/umount2_02.c +3 -0
+} tcases[] = {
+	{MNTPOINT, MNT_EXPIRE | MNT_FORCE, EINVAL, 0,
+		"umount2() with MNT_EXPIRE | MNT_FORCE expected EINVAL"},

nit: I was thinking about using macro to not repeat to flag and exp_errno, (something similar to POLICY_DESC_TEXT(x, y) in testcases/kernel/syscalls/mbind/mbind01.c), but as description varies a lot it's probably better to keep it as is (unless you rephrase it).

...

Quoted 2 lines
testcases/kernel/syscalls/umount2/umount2_02.c +2 -0
+	{SYMLINK, UMOUNT_NOFOLLOW, EINVAL, 0,
+		"umount2('symlink', UMOUNT_NOFOLLOW) expected EINVAL"},

...

Quoted 3 lines
testcases/kernel/syscalls/umount2/umount2_02.c +3 -0
+	{MNTPOINT, UMOUNT_NOFOLLOW, 0, 0,
+		"umount2('mntpoint', UMOUNT_NOFOLLOW) expected success"},
+};

...

Quoted 8 lines
testcases/kernel/syscalls/umount2/umount2_02.c +3 -4
+	if (tc->do_access)
+		SAFE_ACCESS(MNTPOINT, F_OK);
 
-	if (TEST_ERRNO != test_cases[i].exp_errno) {
-		tst_resm(TFAIL | TTERRNO, "%s failed unexpectedly",
-			 test_cases[i].desc);
-		return;
+	if (tc->exp_errno) {

testcases/kernel/syscalls/umount2/umount2_02.c line 86

Quoted 10 lines
testcases/kernel/syscalls/umount2/umount2_02.c +9 -0
+		TST_EXP_FAIL(umount2_retry(tc->mntpoint, tc->flag), tc->exp_errno,
+			"umount2_retry(%s, %d)", tc->mntpoint, tc->flag);
+		if (!TST_PASS)
+			mount_flag = 0;
+	} else {
+		TST_EXP_PASS(umount2_retry(tc->mntpoint, tc->flag),
+			"umount2_retry(%s, %d)", tc->mntpoint, tc->flag);
+		if (TST_PASS)
+			mount_flag = 0;
 	}

nit: this would be more compact:

	if (tc->exp_errno)
		TST_EXP_FAIL(umount2_retry(tc->mntpoint, tc->flag), tc->exp_errno,
			"umount2_retry(%s, %d)", tc->mntpoint, tc->flag);
	else
		TST_EXP_PASS(umount2_retry(tc->mntpoint, tc->flag),
			"umount2_retry(%s, %d)", tc->mntpoint, tc->flag);

	if (!!tc->exp_errno ^ !!TST_PASS)
		mount_flag = 0;

Kind regards,
Petr

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

Re: [LTP] [PATCH v4] syscalls/umount2: Convert to new API and use SAFE_ACCESS

Hi Petr,

Thanks for review, I will send v5 later.

Quoted 113 lines · Petr Vorel

Hi Dai,

We're nearly there, IMHO 2 minor changes are required.

nit: you can help reviewers to list changelog from previous version (for your next patches), see:

https://patchwork.ozlabs.org/project/ltp/patch/[email protected]/
https://patchwork.ozlabs.org/project/ltp/cover/[email protected]/

Quoted 4 lines

1. use TST_EXP_FAIL and TST_EXP_PASS macro
2. use SAFE macro
3. simplify verify operations
4. merge umount2_03 to umount2_02

very nit: more important that "use SAFE macro" (that's one of the main reasons why we use new API) is to mention the reason why to merge tests.

...

Quoted 4 lines

+/*\
+ * [Description]
+ *
* Test for feature MNT_EXPIRE of umount2().

This must be:
* Test for feature MNT_EXPIRE of umount2().
extra space after '* ' leads text to be formatted as <pre> or <code>.

Quoted 7 lines

- * "Mark the mount point as expired.If a mount point is not currently

- *   in use, then an initial call to umount2() with this flag fails with
- *   the error EAGAIN, but marks the mount point as expired. The mount
- *   point remains expired as long as it isn't accessed by any process.
- *   A second umount2() call specifying MNT_EXPIRE unmounts an expired
- *   mount point. This flag cannot be specified with either MNT_FORCE or
- *   MNT_DETACH. (fails with the error EINVAL)"
Quoted 7 lines

+ *
+ * - EINVAL when flag is specified with either MNT_FORCE or MNT_DETACH
+ * - EAGAIN when initial call to umount2(2) with MNT_EXPIRE
+ * - EAGAIN when umount2(2) with MNT_EXPIRE after access(2)
+ * - succeed when second call to umount2(2) with MNT_EXPIRE
+ *
+ * Test for feature UMOUNT_NOFOLLOW of umount2().

And here as well:
* Test for feature UMOUNT_NOFOLLOW of umount2().

run make in metadata/ and then check docparse/metadata.html (or docparse/metadata.pdf).

(1st thing to change)

testcases/kernel/syscalls/umount2/umount2_02.c line 26

Quoted 13 lines

+ *
+ * - EINVAL when target is a symbolic link
+ * - succeed when target is a mount point
*/

testcases/kernel/syscalls/umount2/umount2_02.c +1 -5
-#include <errno.h>
  #include <sys/mount.h>
-
-#include "test.h"
-#include "safe_macros.h"
  #include "lapi/mount.h"
-
+#include "tst_test.h"
  #include "umount2.h"

umount2.h is now used only in this test. Please put the content into the test and delete the file (2nd change to do).

...

testcases/kernel/syscalls/umount2/umount2_02.c line 41

Quoted 3 lines
testcases/kernel/syscalls/umount2/umount2_02.c +3 -0
+} tcases[] = {
+	{MNTPOINT, MNT_EXPIRE | MNT_FORCE, EINVAL, 0,
+		"umount2() with MNT_EXPIRE | MNT_FORCE expected EINVAL"},

nit: I was thinking about using macro to not repeat to flag and exp_errno, (something similar to POLICY_DESC_TEXT(x, y) in testcases/kernel/syscalls/mbind/mbind01.c), but as description varies a lot it's probably better to keep it as is (unless you rephrase it).

...

Quoted 2 lines
testcases/kernel/syscalls/umount2/umount2_02.c +2 -0
+	{SYMLINK, UMOUNT_NOFOLLOW, EINVAL, 0,
+		"umount2('symlink', UMOUNT_NOFOLLOW) expected EINVAL"},

...

Quoted 3 lines
testcases/kernel/syscalls/umount2/umount2_02.c +3 -0
+	{MNTPOINT, UMOUNT_NOFOLLOW, 0, 0,
+		"umount2('mntpoint', UMOUNT_NOFOLLOW) expected success"},
+};

...

Quoted 7 lines
testcases/kernel/syscalls/umount2/umount2_02.c +3 -4
+	if (tc->do_access)
+		SAFE_ACCESS(MNTPOINT, F_OK);
-	if (TEST_ERRNO != test_cases[i].exp_errno) {
-		tst_resm(TFAIL | TTERRNO, "%s failed unexpectedly",
-			 test_cases[i].desc);
-		return;
+	if (tc->exp_errno) {

testcases/kernel/syscalls/umount2/umount2_02.c line 86

Quoted 10 lines
testcases/kernel/syscalls/umount2/umount2_02.c +9 -0
+		TST_EXP_FAIL(umount2_retry(tc->mntpoint, tc->flag), tc->exp_errno,
+			"umount2_retry(%s, %d)", tc->mntpoint, tc->flag);
+		if (!TST_PASS)
+			mount_flag = 0;
+	} else {
+		TST_EXP_PASS(umount2_retry(tc->mntpoint, tc->flag),
+			"umount2_retry(%s, %d)", tc->mntpoint, tc->flag);
+		if (TST_PASS)
+			mount_flag = 0;
  	}

nit: this would be more compact:

	if (tc->exp_errno)
		TST_EXP_FAIL(umount2_retry(tc->mntpoint, tc->flag), tc->exp_errno,
			"umount2_retry(%s, %d)", tc->mntpoint, tc->flag);
	else
		TST_EXP_PASS(umount2_retry(tc->mntpoint, tc->flag),
			"umount2_retry(%s, %d)", tc->mntpoint, tc->flag);

	if (!!tc->exp_errno ^ !!TST_PASS)
		mount_flag = 0;

Kind regards,
Petr

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

PATCH v5 1/1 syscalls/umount2: Convert to new API and use SAFE_ACCESS

In reply to Petr Vorel

1. use SAFE macro
2. use TST_EXP_FAIL and TST_EXP_PASS macro
3. simplify verify operations
4. merge umount2_03 and umount2.h to umount2_02

---
v4->v5:
- Add changelog from previous version
- Make commit message order more reasonable
- Fix description format
- Merge umount2.h into umount2_02
- Use macro to not repeat flag and exp_errno
- Make test_umount2() more compact

 runtest/syscalls                               |   1 -
 testcases/kernel/syscalls/umount2/.gitignore   |   1 -
 testcases/kernel/syscalls/umount2/umount2.h    |  44 -----
 testcases/kernel/syscalls/umount2/umount2_02.c | 212 +++++++++----------------
 testcases/kernel/syscalls/umount2/umount2_03.c | 167 -------------------
 5 files changed, 77 insertions(+), 348 deletions(-)
 delete mode 100644 testcases/kernel/syscalls/umount2/umount2.h
 delete mode 100644 testcases/kernel/syscalls/umount2/umount2_03.c
runtest/syscalls +0 -1
index 6186bfc..0eea946 100644
@@ -1647,7 +1647,6 @@ umount03 umount03
 
 umount2_01 umount2_01
 umount2_02 umount2_02
-umount2_03 umount2_03
 
 userfaultfd01 userfaultfd01
 
testcases/kernel/syscalls/umount2/.gitignore +0 -1
index 1d6a0e8..e2056bf 100644
@@ -1,3 +1,2 @@
 /umount2_01
 /umount2_02
-/umount2_03
testcases/kernel/syscalls/umount2/umount2.h deleted +0 -44

44 lines not on this page · raw message

testcases/kernel/syscalls/umount2/umount2_02.c +77 -135

259 lines not on this page · raw message

testcases/kernel/syscalls/umount2/umount2_03.c deleted +0 -167

167 lines not on this page · raw message

Signature · 5 lines
1.8.3.1


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

Re: [LTP] [PATCH v5] syscalls/umount2: Convert to new API and use SAFE_ACCESS

Hi Dai,

Quoted 2 lines

v4->v5:
- Add changelog from previous version

nit: You don't have mention in changelog that you're adding it. (note anything after --- is not in the commit message)

Quoted 5 lines

- Make commit message order more reasonable
- Fix description format
- Merge umount2.h into umount2_02
- Use macro to not repeat flag and exp_errno
- Make test_umount2() more compact

Thanks for implementing all this!

I merged it with few minor changes, added Xu's Reviewed-by: tag (he reviewed v2 and v3).

...

testcases/kernel/syscalls/umount2/umount2_02.c line 32

Quoted 4 lines

+++ b/testcases/kernel/syscalls/umount2/umount2_02.c

testcases/kernel/syscalls/umount2/umount2_02.c +3 -0
+#define FLAG_DESC(x, y) .flag = x, .exp_errno = 0, .desc = "umount2("y") with "#x" expected success"
+#define FLAG_EXP_ERRNO_DESC(x, y, z) .flag = x, .exp_errno = y, \
+				     .desc = "umount2("z") with "#x" expected "#y

I cleaned whitespace here.

...

testcases/kernel/syscalls/umount2/umount2_02.c line 43

Quoted 4 lines
testcases/kernel/syscalls/umount2/umount2_02.c +4 -0
+	const char *mntpoint;
+	int do_access;
+} tcases[] = {
+	{FLAG_EXP_ERRNO_DESC(MNT_EXPIRE | MNT_FORCE, EINVAL, ""), MNTPOINT, 0},

I removed blank lines in here.

...

Quoted 1 line

+static inline int umount2_retry(const char *target, int flags)

I removed this inline (required for *.h, but not needed here).

Kind regards,
Petr

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

Re: [LTP] [PATCH v3 3/3] syscalls/umount2: Convert to new API and use SAFE_ACCESS

In reply to Dai Shili

Hi Dai

It seems you don't fix some problems thant I comment on your v2 patch. so again

Quoted 1 line

/*

Typo /* =>/*\

So the description can be used in docparse.

ps:you can cd ltp/docparse directory, then run make command, it will generate metadata.html, then put this html file into your nginx or appache directory, then you can see this html whether works well for docparse from other host.

Quoted 218 lines

- * DESCRIPTION
+ * [Description]
+ *
* Test for feature MNT_EXPIRE of umount2().
- * "Mark the mount point as expired.If a mount point is not currently

- *   in use, then an initial call to umount2() with this flag fails with
- *   the error EAGAIN, but marks the mount point as expired. The mount
- *   point remains expired as long as it isn't accessed by any process.
- *   A second umount2() call specifying MNT_EXPIRE unmounts an expired
- *   mount point. This flag cannot be specified with either MNT_FORCE or
- *   MNT_DETACH. (fails with the error EINVAL)"

+ *
+ * - EINVAL when flag is specified with either MNT_FORCE or MNT_DETACH
+ * - EAGAIN when initial call to umount2(2) with MNT_EXPIRE
+ * - EAGAIN when umount2(2) with MNT_EXPIRE after access(2)
+ * - succeed when second call to umount2(2) with MNT_EXPIRE
+ *
+ * Test for feature UMOUNT_NOFOLLOW of umount2().
+ *
+ * - EINVAL when target is a symbolic link
+ * - succeed when target is a mount point
*/

testcases/kernel/syscalls/umount2/umount2_02.c +42 -121
-#include<errno.h>
  #include<sys/mount.h>
-
-#include "test.h"
-#include "safe_macros.h"
  #include "lapi/mount.h"
-
+#include "tst_test.h"
  #include "umount2.h"
 
-#define DIR_MODE	(S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)
-#define MNTPOINT	"mntpoint"
-
-static void setup(void);
-static void test_umount2(int i);
-static void verify_failure(int i);
-static void verify_success(int i);
-static void cleanup(void);
-
-static const char *device;
-static const char *fs_type;
+#define MNTPOINT        "mntpoint"
+#define SYMLINK	"symlink"
 
  static int mount_flag;
 
-static struct test_case_t {
+static struct tcase {
+	const char *mntpoint;
  	int flag;
  	int exp_errno;
  	int do_access;
  	const char *desc;
-} test_cases[] = {
-	{MNT_EXPIRE | MNT_FORCE, EINVAL, 0,
-		"umount2(2) with MNT_EXPIRE | MNT_FORCE expected EINVAL"},
-	{MNT_EXPIRE | MNT_DETACH, EINVAL, 0,
-		"umount2(2) with MNT_EXPIRE | MNT_DETACH expected EINVAL"},
-	{MNT_EXPIRE, EAGAIN, 0,
-		"initial call to umount2(2) with MNT_EXPIRE expected EAGAIN"},
-	{MNT_EXPIRE, EAGAIN, 1,
-		"umount2(2) with MNT_EXPIRE after access(2) expected EAGAIN"},
-	{MNT_EXPIRE, 0, 0,
-		"second call to umount2(2) with MNT_EXPIRE expected success"},
-};
+} tcases[] = {
+	{MNTPOINT, MNT_EXPIRE | MNT_FORCE, EINVAL, 0,
+		"umount2() with MNT_EXPIRE | MNT_FORCE expected EINVAL"},
 
-char *TCID = "umount2_02";
-int TST_TOTAL = ARRAY_SIZE(test_cases);
+	{MNTPOINT, MNT_EXPIRE | MNT_DETACH, EINVAL, 0,
+		"umount2() with MNT_EXPIRE | MNT_DETACH expected EINVAL"},
 
-int main(int ac, char **av)
-{
-	int lc;
-	int tc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
+	{MNTPOINT, MNT_EXPIRE, EAGAIN, 0,
+		"initial call to umount2() with MNT_EXPIRE expected EAGAIN"},
 
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
+	{MNTPOINT, MNT_EXPIRE, EAGAIN, 1,
+		"umount2() with MNT_EXPIRE after access() expected EAGAIN"},
 
-		SAFE_MOUNT(cleanup, device, MNTPOINT, fs_type, 0, NULL);
-		mount_flag = 1;
-
-		for (tc = 0; tc<  TST_TOTAL; tc++)
-			test_umount2(tc);
+	{MNTPOINT, MNT_EXPIRE, 0, 0,
+		"second call to umount2() with MNT_EXPIRE expected success"},
 
-		if (mount_flag) {
-			if (tst_umount(MNTPOINT))
-				tst_brkm(TBROK, cleanup, "umount() failed");
-			mount_flag = 0;
-		}
-	}
+	{SYMLINK, UMOUNT_NOFOLLOW, EINVAL, 0,
+		"umount2('symlink', UMOUNT_NOFOLLOW) expected EINVAL"},
 
-	cleanup();
-	tst_exit();
-}
+	{MNTPOINT, UMOUNT_NOFOLLOW, 0, 0,
+		"umount2('mntpoint', UMOUNT_NOFOLLOW) expected success"},
+};
 
-static void setup(void)
+static void test_umount2(unsigned int n)
  {
-	tst_require_root();
-
-	if ((tst_kvercmp(2, 6, 8))<  0) {
-		tst_brkm(TCONF, NULL, "This test can only run on kernels "
-			 "that are 2.6.8 or higher");
-	}
+	struct tcase *tc =&tcases[n];
 
-	tst_sig(NOFORK, DEF_HANDLER, NULL);
-
-	tst_tmpdir();
-
-	fs_type = tst_dev_fs_type();
-	device = tst_acquire_device(cleanup);
-
-	if (!device)
-		tst_brkm(TCONF, cleanup, "Failed to obtain block device");
-
-	tst_mkfs(cleanup, device, fs_type, NULL, NULL);
-
-	SAFE_MKDIR(cleanup, MNTPOINT, DIR_MODE);
-
-	TEST_PAUSE;
-}
-
-static void test_umount2(int i)
-{
-	/* a new access removes the expired mark of the mount point */
-	if (test_cases[i].do_access) {
-		if (access(MNTPOINT, F_OK) == -1)
-			tst_brkm(TBROK | TERRNO, cleanup, "access(2) failed");
+	if (!mount_flag) {
+		SAFE_MOUNT(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, NULL);
+		mount_flag = 1;
  	}
 
-	TEST(umount2_retry(MNTPOINT, test_cases[i].flag));
-
-	if (test_cases[i].exp_errno != 0)
-		verify_failure(i);
-	else
-		verify_success(i);
-}
+	tst_res(TINFO, "Testing %s", tc->desc);
 
-static void verify_failure(int i)
-{
-	if (TEST_RETURN == 0) {
-		tst_resm(TFAIL, "%s passed unexpectedly", test_cases[i].desc);
-		mount_flag = 0;
-		return;
-	}
+	if (tc->do_access)
+		SAFE_ACCESS(MNTPOINT, F_OK);
 
-	if (TEST_ERRNO != test_cases[i].exp_errno) {
-		tst_resm(TFAIL | TTERRNO, "%s failed unexpectedly",
-			 test_cases[i].desc);
-		return;
+	if (tc->exp_errno) {
+		TST_EXP_FAIL(umount2_retry(tc->mntpoint, tc->flag), tc->exp_errno,
+			"umount2_retry(%s, %d)", tc->mntpoint, tc->flag);
+		if (!TST_PASS)
+			mount_flag = 0;
+	} else {
+		TST_EXP_PASS(umount2_retry(tc->mntpoint, tc->flag),
+			"umount2_retry(%s, %d)", tc->mntpoint, tc->flag);
+		if (TST_PASS)
+			mount_flag = 0;
  	}
-
-	tst_resm(TPASS | TTERRNO, "umount2(2) failed as expected");
  }
 
-static void verify_success(int i)
+static void setup(void)
  {
-	if (TEST_RETURN != 0) {
-		tst_resm(TFAIL | TTERRNO, "%s failed unexpectedly",
-			 test_cases[i].desc);
-		return;
-	}
-
-	tst_resm(TPASS, "umount2(2) succeeded as expected");
-	mount_flag = 0;
+	SAFE_SYMLINK(MNTPOINT, SYMLINK);
  }
 
  static void cleanup(void)
  {
-	if (mount_flag&&  tst_umount(MNTPOINT))
-		tst_resm(TWARN | TERRNO, "Failed to unmount");
-
-	if (device)
-		tst_release_device(device);
-
-	tst_rmdir();
+	if (mount_flag)

testcases/kernel/syscalls/umount2/umount2_02.c line 106

Quoted 10 lines
testcases/kernel/syscalls/umount2/umount2_02.c +9 -0
+		SAFE_UMOUNT(MNTPOINT);
  }
+
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.cleanup = cleanup,
+	.setup = setup,
+	.needs_root = 1,
+	.needs_device = 1,
+	.format_device = 1,

If we specify format_device, we don't need .needs_device because format_device will enable needs_device automatically.

Best Regards
Yang Xu

Quoted 3 lines
testcases/kernel/syscalls/umount2/umount2_02.c +3 -0
+	.mntpoint = MNTPOINT,
+	.test = test_umount2,
+};
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by Reviewed-by Yang Xu on v3 1/3
#22 lore raw
In reply to Dai Shili

Hi Dai,

Also adding Xu tag from previous version (Dai you can dare to add it for next version if the patch does not change):
https://lore.kernel.org/ltp/[email protected]/
https://patchwork.ozlabs.org/project/ltp/patch/[email protected]/

Kind regards,
Petr

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

Hi Petr,

Quoted 10 lines · Petr Vorel

Hi Dai,

Also adding Xu tag from previous version (Dai you can dare to add it for next version if the patch does not change):
https://lore.kernel.org/ltp/[email protected]/
https://patchwork.ozlabs.org/project/ltp/patch/[email protected]/

Got it. I'll pay attention next time.

Quoted 2 lines

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#24 lore raw
In reply to Dai Shili

Hi Dai,

also +1 for fixing whitespace in your changes :).

Kind regards,
Petr

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