[LTP] [PATCH 1/1] tst_mkfs: Add -I option to mkfs.vfat

Petr Vorel pvorel@suse.cz
Wed Mar 31 09:58:33 CEST 2021


Hi,

instead of using -I I tried Martin Doucha's suggestion to rescan partition table
with ioctl BLKRRPART. But I get EINVAL. Not sure if O_RDONLY is a proper flag,
but I also tried to open with args used for manipulating loop (open(path,
O_CREAT|O_WRONLY|O_TRUNC, S_IRUSR|S_IWUSR)) and a same issue. Happens on recent
kernel and very old kernel 3.16.

I wonder if I have wrong flags or BLKRRPART is just not supported on loop
devices. Looking into kernel sources it's this part blkdev_reread_part():

	if (!disk_part_scan_enabled(bdev->bd_disk) || bdev_is_partition(bdev))
		return -EINVAL;
Kind regards,
Petr

diff --git lib/tst_mkfs.c lib/tst_mkfs.c
index 736324f04..06fafcd18 100644
--- lib/tst_mkfs.c
+++ lib/tst_mkfs.c
@@ -15,6 +15,10 @@
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <sys/ioctl.h>
+#include <sys/mount.h>
+#include <fcntl.h>
+
 #include "test.h"
 #include "ltp_priv.h"
 #include "tst_mkfs.h"
@@ -26,7 +30,7 @@ void tst_mkfs_(const char *file, const int lineno, void (cleanup_fn)(void),
 	       const char *dev, const char *fs_type,
 	       const char *const fs_opts[], const char *const extra_opts[])
 {
-	int i, pos = 1, ret;
+	int fd, i, pos = 1, ret;
 	char mkfs[64];
 	const char *argv[OPTS_MAX] = {mkfs};
 	char fs_opts_str[1024] = "";
@@ -93,6 +97,13 @@ void tst_mkfs_(const char *file, const int lineno, void (cleanup_fn)(void),
 			"tst_clear_device() failed");
 	}
 
+	/* force kernel to reread partition table */
+	fd = open(dev, O_RDONLY);
+	tst_resm_(file, lineno, TINFO, "dev: %s, fd: %d", dev, fd);
+	ret = ioctl(fd, BLKRRPART);
+	tst_resm_(file, lineno, TINFO, "rc: %d", ret);
+	close(fd);
+
 	tst_resm_(file, lineno, TINFO,
 		"Formatting %s with %s opts='%s' extra opts='%s'",
 		dev, fs_type, fs_opts_str, extra_opts_str);


More information about the ltp mailing list