[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <alpine.LNX.2.21.1706141316400.2000@joy.test>
Date: Wed, 14 Jun 2017 13:33:29 -0700 (PDT)
From: Richard Narron <comet.berkeley@...il.com>
To: Al Viro <viro@...IV.linux.org.uk>
cc: Linus Torvalds <torvalds@...ux-foundation.org>,
linux-kernel@...r.kernel.org, linux-fsdevel@...r.kernel.org
Subject: Re: [git pull] first batch of ufs fixes
On Wed, 14 Jun 2017, Al Viro wrote:
...
> AFAICS, a conservative approach would be
> * reject UFS_42POSTBLFMT for 44bsd ones - it's almost certainly
> *not* one.
> * check if fs_maxbsize is equal to frag size; treat that as
> "counts are read from new location and stored both to old and new".
> 44bsd fs_maxbsize != block size => not converted, just use old locations
> for everything. UFS2 => use new locations for everything, don't bother
> with old ones. IOW, something like this (WARNING: completely untested,
> might screw your filesystem) might do.
>
> NOTE: all I have is your image *after* it had counters buggered; I don't
> know the exact sequence of operations that fucked it in your case. One
> way to trigger it is to mount/umount on OpenBSD, then mount/modify/umount
> on Linux, then mount/umount on OpenBSD, then fsck on OpenBSD. This patch
> apparently fixes that, but your reproducer might be something different.
>
> Signed-off-by: Al Viro <viro@...iv.linux.org.uk>
> ---
> diff --git a/fs/ufs/super.c b/fs/ufs/super.c
> index d9aa2627c9df..eca838a8b43e 100644
> --- a/fs/ufs/super.c
> +++ b/fs/ufs/super.c
> @@ -480,7 +480,7 @@ static void ufs_setup_cstotal(struct super_block *sb)
> usb3 = ubh_get_usb_third(uspi);
>
> if ((mtype == UFS_MOUNT_UFSTYPE_44BSD &&
> - (usb1->fs_flags & UFS_FLAGS_UPDATED)) ||
> + (usb2->fs_un.fs_u2.fs_maxbsize == usb1->fs_bsize)) ||
> mtype == UFS_MOUNT_UFSTYPE_UFS2) {
> /*we have statistic in different place, then usual*/
> uspi->cs_total.cs_ndir = fs64_to_cpu(sb, usb2->fs_un.fs_u2.cs_ndir);
> @@ -596,9 +596,7 @@ static void ufs_put_cstotal(struct super_block *sb)
> usb2 = ubh_get_usb_second(uspi);
> usb3 = ubh_get_usb_third(uspi);
>
> - if ((mtype == UFS_MOUNT_UFSTYPE_44BSD &&
> - (usb1->fs_flags & UFS_FLAGS_UPDATED)) ||
> - mtype == UFS_MOUNT_UFSTYPE_UFS2) {
> + if (mtype == UFS_MOUNT_UFSTYPE_UFS2) {
> /*we have statistic in different place, then usual*/
> usb2->fs_un.fs_u2.cs_ndir =
> cpu_to_fs64(sb, uspi->cs_total.cs_ndir);
> @@ -608,16 +606,26 @@ static void ufs_put_cstotal(struct super_block *sb)
> cpu_to_fs64(sb, uspi->cs_total.cs_nifree);
> usb3->fs_un1.fs_u2.cs_nffree =
> cpu_to_fs64(sb, uspi->cs_total.cs_nffree);
> - } else {
> - usb1->fs_cstotal.cs_ndir =
> - cpu_to_fs32(sb, uspi->cs_total.cs_ndir);
> - usb1->fs_cstotal.cs_nbfree =
> - cpu_to_fs32(sb, uspi->cs_total.cs_nbfree);
> - usb1->fs_cstotal.cs_nifree =
> - cpu_to_fs32(sb, uspi->cs_total.cs_nifree);
> - usb1->fs_cstotal.cs_nffree =
> - cpu_to_fs32(sb, uspi->cs_total.cs_nffree);
> + goto out;
> }
> +
> + if (mtype == UFS_MOUNT_UFSTYPE_44BSD &&
> + (usb2->fs_un.fs_u2.fs_maxbsize == usb1->fs_bsize)) {
> + /* store stats in both old and new places */
> + usb2->fs_un.fs_u2.cs_ndir =
> + cpu_to_fs64(sb, uspi->cs_total.cs_ndir);
> + usb2->fs_un.fs_u2.cs_nbfree =
> + cpu_to_fs64(sb, uspi->cs_total.cs_nbfree);
> + usb3->fs_un1.fs_u2.cs_nifree =
> + cpu_to_fs64(sb, uspi->cs_total.cs_nifree);
> + usb3->fs_un1.fs_u2.cs_nffree =
> + cpu_to_fs64(sb, uspi->cs_total.cs_nffree);
> + }
> + usb1->fs_cstotal.cs_ndir = cpu_to_fs32(sb, uspi->cs_total.cs_ndir);
> + usb1->fs_cstotal.cs_nbfree = cpu_to_fs32(sb, uspi->cs_total.cs_nbfree);
> + usb1->fs_cstotal.cs_nifree = cpu_to_fs32(sb, uspi->cs_total.cs_nifree);
> + usb1->fs_cstotal.cs_nffree = cpu_to_fs32(sb, uspi->cs_total.cs_nffree);
> +out:
> ubh_mark_buffer_dirty(USPI_UBH(uspi));
> ufs_print_super_stuff(sb, usb1, usb2, usb3);
> UFSD("EXIT\n");
> @@ -997,6 +1005,13 @@ static int ufs_fill_super(struct super_block *sb, void *data, int silent)
> flags |= UFS_ST_SUN;
> }
>
> + if ((flags & UFS_ST_MASK) == UFS_ST_44BSD &&
> + uspi->s_postblformat == UFS_42POSTBLFMT) {
> + if (!silent)
> + pr_err("this is not a 44bsd filesystem");
> + goto failed;
> + }
> +
> /*
> * Check ufs magic number
> */
>
Al this patch looks good to me (so far). I tested all 6 combinations of
ufs1 and ufs2 in FreeBSD 11.0, OpenBSD 6.1 and NetBSD 7.1
For each combination, I do 5 steps:
1) BSD: Make a ufs filesystem
dd if=/dev/zero to the BSD subpartition
make (newfs) a ufs (1 or 2) filesystem on the BSD subpartiton
2) Linux: Create a subdirectory and make a large file
mkdir a
dd if=/dev/zero bs=1M count=3072
3) BSD: Check a ufs filesystem
fsck -f
4) Linux: Remove the large file and the subdirectory
rm
rmdir
5) BSD; check a ufs filesystem
fsck -f
Tested-By: Richard Narron <comet.berkeley@...il.com>
Powered by blists - more mailing lists