All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH v3 01/16] lib/tst_mkfs: Clear first 512k of the device
@ 2017-10-11 14:41 Cyril Hrubis
  2017-10-11 14:41 ` [LTP] [PATCH v3 02/16] lib: Add interface to list supported filesystems Cyril Hrubis
                   ` (15 more replies)
  0 siblings, 16 replies; 27+ messages in thread
From: Cyril Hrubis @ 2017-10-11 14:41 UTC (permalink / raw)
  To: ltp

If we cal tst_mkfs() from a test more than once we end up with the very
same bug we already fixed by clearing the device in
tst_acquire_device(), i.e. some mkfs programs will not format it when
there is a valid FS signature there. But we have to clear the device for
the shell tests as well.

So this commit adds tst_clear_device() function that is both called from
the tst_mkfs() and from the shell tst_device helper to clear up the
first 512k of the device.

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 include/tst_device.h       | 10 ++++++++++
 lib/tst_device.c           | 19 +++++++++++--------
 lib/tst_mkfs.c             |  4 ++++
 testcases/lib/tst_device.c |  5 +++++
 4 files changed, 30 insertions(+), 8 deletions(-)

diff --git a/include/tst_device.h b/include/tst_device.h
index 897696dd9..7ac288368 100644
--- a/include/tst_device.h
+++ b/include/tst_device.h
@@ -34,4 +34,14 @@ extern struct tst_device *tst_device;
  */
 int tst_umount(const char *path);
 
+/*
+ * Clears a first few blocks of the device. This is needed when device has
+ * already been formatted with a filesystems, subset of mkfs.foo utils aborts
+ * the operation if it finds a filesystem signature there.
+ *
+ * Note that this is called from tst_mkfs() automatically, so you probably will
+ * not need to use this from the test yourself.
+ */
+int tst_clear_device(const char *dev);
+
 #endif	/* TST_DEVICE_H__ */
diff --git a/lib/tst_device.c b/lib/tst_device.c
index 67432caf6..6ad6c47f6 100644
--- a/lib/tst_device.c
+++ b/lib/tst_device.c
@@ -245,15 +245,8 @@ const char *tst_acquire_device__(unsigned int size)
 
 		ltp_dev_size = ltp_dev_size/1024/1024;
 
-		if (acq_dev_size <= ltp_dev_size) {
-			if (tst_fill_file(dev, 0, 1024, 512)) {
-				tst_resm(TWARN | TERRNO,
-					 "Failed to clear the first 512k of %s",
-					 dev);
-			}
-
+		if (acq_dev_size <= ltp_dev_size)
 			return dev;
-		}
 
 		tst_resm(TINFO, "Skipping $LTP_DEV size %"PRIu64"MB, requested size %uMB",
 				ltp_dev_size, acq_dev_size);
@@ -319,6 +312,16 @@ int tst_release_device(const char *dev)
 	return ret;
 }
 
+int tst_clear_device(const char *dev)
+{
+	if (tst_fill_file(dev, 0, 1024, 512)) {
+		tst_resm(TWARN, "Failed to clear 512k block on %s", dev);
+		return 1;
+	}
+
+	return 0;
+}
+
 int tst_umount(const char *path)
 {
 	int err, ret, i;
diff --git a/lib/tst_mkfs.c b/lib/tst_mkfs.c
index f2e40ecd6..7385a939f 100644
--- a/lib/tst_mkfs.c
+++ b/lib/tst_mkfs.c
@@ -18,6 +18,7 @@
 #include "test.h"
 #include "ltp_priv.h"
 #include "tst_mkfs.h"
+#include "tst_device.h"
 
 #define OPTS_MAX 32
 
@@ -75,6 +76,9 @@ void tst_mkfs_(const char *file, const int lineno, void (cleanup_fn)(void),
 
 	argv[pos] = NULL;
 
+	if (tst_clear_device(dev))
+		tst_brkm(TBROK, cleanup_fn, "tst_clear_device() failed");
+
 	tst_resm(TINFO, "Formatting %s with %s opts='%s' extra opts='%s'",
 	         dev, fs_type, fs_opts_str, extra_opt ? extra_opt : "");
 	ret = tst_run_cmd(cleanup_fn, argv, "/dev/null", NULL, 1);
diff --git a/testcases/lib/tst_device.c b/testcases/lib/tst_device.c
index d33cac613..9afaeb1ef 100644
--- a/testcases/lib/tst_device.c
+++ b/testcases/lib/tst_device.c
@@ -59,6 +59,11 @@ static int acquire_device(int argc, char *argv[])
 	if (!device)
 		return 1;
 
+	if (tst_clear_device(device)) {
+		tst_release_device(device);
+		return 1;
+	}
+
 	printf("%s", device);
 
 	return 0;
-- 
2.13.5


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

end of thread, other threads:[~2017-11-09 18:51 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-11 14:41 [LTP] [PATCH v3 01/16] lib/tst_mkfs: Clear first 512k of the device Cyril Hrubis
2017-10-11 14:41 ` [LTP] [PATCH v3 02/16] lib: Add interface to list supported filesystems Cyril Hrubis
2017-11-09 18:38   ` Sandeep Patil
2017-10-11 14:41 ` [LTP] [PATCH v3 03/16] SAFE_MOUNT: Handle FUSE mounts as well Cyril Hrubis
2017-10-11 14:41 ` [LTP] [PATCH v3 04/16] lib/tst_test: Add .all_filesystems flag Cyril Hrubis
2017-10-11 14:41 ` [LTP] [PATCH v3 05/16] lib/tst_fs: Add tst_fill_fs() Cyril Hrubis
2017-11-09 18:50   ` Sandeep Patil
2017-10-11 14:41 ` [LTP] [PATCH v3 06/16] syscalls/fallocate05: New test Cyril Hrubis
2017-10-11 14:41 ` [LTP] [PATCH v3 07/16] syscalls/msync04: Run test for all filesystems Cyril Hrubis
2017-10-11 14:41 ` [LTP] [PATCH v3 08/16] syscalls/fallocate04: Convert to the new library Cyril Hrubis
2017-10-11 14:41 ` [LTP] [PATCH v3 09/16] syscalls/fallocate04: Run test for all filesystems Cyril Hrubis
2017-10-11 14:41 ` [LTP] [PATCH v3 10/16] syscalls/setxattr01: Convert to the new library Cyril Hrubis
2017-10-11 14:41 ` [LTP] [PATCH v3 11/16] syscalls/setxattr01: Run test for all filesystems Cyril Hrubis
2017-10-11 14:41 ` [LTP] [PATCH v3 12/16] syscallse/setxattr02: Convert to the new library Cyril Hrubis
2017-10-11 14:41 ` [LTP] [PATCH v3 13/16] syscalls/fsync01: " Cyril Hrubis
2017-10-11 14:41 ` [LTP] [PATCH v3 14/16] syscalls/fsync01: Run test for all filesystems Cyril Hrubis
2017-10-11 14:41 ` [LTP] [PATCH v3 15/16] fs/fs_fill: Add a test to fill a FS in a few threads Cyril Hrubis
2017-11-09 10:03   ` Li Wang
2017-11-09 10:19     ` Cyril Hrubis
2017-11-09 10:43       ` Li Wang
2017-11-09 10:50         ` Cyril Hrubis
2017-11-09 10:58           ` Li Wang
2017-10-11 14:41 ` [LTP] [PATCH v3 16/16] doc: Update device flags in test-writing-guidelines Cyril Hrubis
2017-11-09 18:51   ` Sandeep Patil
2017-11-01 12:24 ` [LTP] [PATCH v3 01/16] lib/tst_mkfs: Clear first 512k of the device Cyril Hrubis
2017-11-02  9:26   ` Jan Stancek
2017-11-02 13:15     ` Cyril Hrubis

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.