Skip to contentSkip to conversation

tst_acquire_device: clear first sectors of LTP_DEV

RFC PATCH New Stanislav Kholmanskikh 2 participants 6 messages Feb 20, 2016 – Feb 24, 2016 Library code

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/2 tst_acquire_device: clear first sectors of LTP_DEV

mkfs.ext{2,3,4} on sparc64 does not clear the first two sectors of a partition. Therefore, if one creates a vfat file system on a block device and then creates an ext2 file system, this new ext2 file system will not be mountable without '-t specified':

~# dd if=/dev/zero of=/dev/vg/test
~# mkfs.vfat /dev/vg/test
~# mkfs.ext2 /dev/vg/test
~# mount /dev/vg/test /mnt
mount: you must specify the filesystem type

This situation may be reproduced with runtest/commands, where df01_vfat may be followed (if there is no mkfs.exfat, mkfs.ntfs) by mkfs01, mkfs01_ext2 and etc. If this is the case, then mkfs01_ext{2,3,4} will fail.

As we see in [1] ZAP_BOOTBLOCK is defined on all archs except SPARC. I could not find the exact reason why it's so, but tend to think that it was implemented to let ext{2,3,4} be created on the first partition of a Sun disk label. The thing is that with Sun disk labels it's absolutely fine to have the first partition starting at sector 0, which is used by the disk label itself:

~# fdisk -lu /dev/vdiska

Disk /dev/vdiska (Sun disk label): 255 heads, 63 sectors, 3916 cylinders Units = sectors of 1 * 512 bytes

      Device Flag    Start       End    Blocks   Id  System
/dev/vdiska1             0   2104515   1052257+   1  Boot
/dev/vdiska2       2104515  62910540  30403012+  83  Linux native
/dev/vdiska3             0  62910540  31455270    5  Whole disk

If mkfs.ext{2,3,4} overwrote the first two sectors, then 'mkfs.ext{2,3,4} /dev/vdiska1' would destroy the disk label.

Clearing the first 512k of LTP_DEV solves this issue. I don't expect it to make a noticeable impact on test execution time. 512k is fine to cover superblocks of all file systems supported by libblkid [2]. Just in case.

[1] http://git.kernel.org/cgit/fs/ext2/e2fsprogs.git/tree/misc/mke2fs.c
[2] https://github.com/karelzak/util-linux/tree/master/libblkid/src/superblocks

---
 lib/tst_device.c      |    5 +++++
 testcases/lib/test.sh |    3 +++
 2 files changed, 8 insertions(+), 0 deletions(-)
lib/tst_device.c +5 -0
index 260ed7b..ed6b2a1 100644
@@ -203,6 +203,11 @@ const char *tst_acquire_device(void (cleanup_fn)(void))
 			         "%s is not a block device", dev);
 		}
 
+		if (tst_fill_file(dev, 0, 1024, 512)) {
+			tst_brkm(TBROK | TERRNO, cleanup_fn,
+				 "Failed to clear the first 512k of %s", dev);
+		}
+
 		return dev;
 	}
 
testcases/lib/test.sh +3 -0
index eeaf0b6..9b652c0 100644
@@ -259,6 +259,9 @@ tst_acquire_device()
 		if [ ! -b ${LTP_DEV} ]; then
 			tst_brkm TBROK "${LTP_DEV} is not a block device"
 		fi
+
+		ROD_SILENT dd if=/dev/zero of="${LTP_DEV}" bs=1024 count=512
+
 		TST_DEVICE=${LTP_DEV}
 		TST_DEVICE_FLAG=0
 		return
Signature · 1 line
1.7.1
#1 lore raw

PATCH 2/2 mkfs01.sh: use df -P

For the same reason as it was in
commit deab0acd12a6 ("df01: use the POSIX output format").

---
 testcases/commands/mkfs/mkfs01.sh |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
testcases/commands/mkfs/mkfs01.sh +1 -1
index 6edecd7..eda9829 100755
@@ -90,7 +90,7 @@ mkfs_verify_type()
 mkfs_verify_size()
 {
 	mkfs_mount
-	local blocknum=`df -B 1k mntpoint | tail -n1 | awk '{print $2}'`
+	local blocknum=`df -P -B 1k mntpoint | tail -n1 | awk '{print $2}'`
 	tst_umount "$TST_DEVICE"
 
 	if [ $blocknum -gt "$2" ]; then
Signature · 1 line
1.7.1
#3 lore raw

RFC PATCH 1/2 tst_acquire_device: clear first sectors of LTP_DEV

In reply to Stanislav Kholmanskikh

Hi!

Quoted 17 lines

As we see in [1] ZAP_BOOTBLOCK is defined on all archs except SPARC. I could not find the exact reason why it's so, but tend to think that it was implemented to let ext{2,3,4} be created on the first partition of a Sun disk label. The thing is that with Sun disk labels it's absolutely fine to have the first partition starting at sector 0, which is used by the disk label itself:

~# fdisk -lu /dev/vdiska

Disk /dev/vdiska (Sun disk label): 255 heads, 63 sectors, 3916 cylinders Units = sectors of 1 * 512 bytes

      Device Flag    Start       End    Blocks   Id  System
/dev/vdiska1             0   2104515   1052257+   1  Boot
/dev/vdiska2       2104515  62910540  30403012+  83  Linux native
/dev/vdiska3             0  62910540  31455270    5  Whole disk
Quoted 7 lines

If mkfs.ext{2,3,4} overwrote the first two sectors, then 'mkfs.ext{2,3,4} /dev/vdiska1' would destroy the disk label.

Clearing the first 512k of LTP_DEV solves this issue. I don't expect it to make a noticeable impact on test execution time. 512k is fine to cover superblocks of all file systems supported by libblkid [2]. Just in case.

Sounds reasonable to me. I guess that we can remove the special cases for the force flag once this is applied as well.

Signature · 2 lines
Cyril Hrubis
[email protected]
#4 lore raw

RFC PATCH 1/2 tst_acquire_device: clear first sectors of LTP_DEV

Hi!

Quoted 21 lines · Cyril Hrubis

Hi!

Quoted 20 lines

As we see in [1] ZAP_BOOTBLOCK is defined on all archs except SPARC. I could not find the exact reason why it's so, but tend to think that it was implemented to let ext{2,3,4} be created on the first partition of a Sun disk label. The thing is that with Sun disk labels it's absolutely fine to have the first partition starting at sector 0, which is used by the disk label itself:

~# fdisk -lu /dev/vdiska

Disk /dev/vdiska (Sun disk label): 255 heads, 63 sectors, 3916 cylinders Units = sectors of 1 * 512 bytes

Device Flag Start End Blocks Id System

/dev/vdiska1             0   2104515   1052257+   1  Boot
/dev/vdiska2       2104515  62910540  30403012+  83  Linux native
/dev/vdiska3             0  62910540  31455270    5  Whole disk

If mkfs.ext{2,3,4} overwrote the first two sectors, then 'mkfs.ext{2,3,4} /dev/vdiska1' would destroy the disk label.

Quoted 8 lines
Quoted 4 lines

Clearing the first 512k of LTP_DEV solves this issue. I don't expect it to make a noticeable impact on test execution time. 512k is fine to cover superblocks of all file systems supported by libblkid [2]. Just in case.

Sounds reasonable to me. I guess that we can remove the special cases for the force flag once this is applied as well.

I committed the series. Thank you.

Regarding the force flag. Yes, we no longer need it now.

I tried to execute mount* test cases with ext2/ext3/xfs/btrfs file systems with the attached patch and they all passed.

So am I proceeding with a more formal patch?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mkfs_no_force_flag.patch
Type: text/x-diff
Size: 906 bytes
Desc: not available
URL: <http://lists.linux.it/pipermail/ltp/attachments/20160224/f039870e/attachment.patch>

#5 lore raw

RFC PATCH 1/2 tst_acquire_device: clear first sectors of LTP_DEV

Hi!

Quoted 6 lines

Regarding the force flag. Yes, we no longer need it now.

I tried to execute mount* test cases with ext2/ext3/xfs/btrfs file systems with the attached patch and they all passed.

So am I proceeding with a more formal patch?

Sounds good.

Signature · 2 lines
Cyril Hrubis
[email protected]