linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Richard Narron <comet.berkeley@gmail.com>
To: Al Viro <viro@ZenIV.linux.org.uk>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org
Subject: Re: [git pull] first batch of ufs fixes
Date: Wed, 14 Jun 2017 13:33:29 -0700 (PDT)	[thread overview]
Message-ID: <alpine.LNX.2.21.1706141316400.2000@joy.test> (raw)
In-Reply-To: <20170614071133.GD31671@ZenIV.linux.org.uk>

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@zeniv.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@gmail.com>

  reply	other threads:[~2017-06-14 20:33 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-09 21:38 [git pull] first batch of ufs fixes Al Viro
2017-06-10 13:03 ` Richard Narron
2017-06-10 16:07   ` Al Viro
2017-06-10 18:08     ` Al Viro
2017-06-10 18:12       ` Linus Torvalds
2017-06-11 19:47       ` Richard Narron
2017-06-11 21:30         ` Al Viro
2017-06-12  6:14         ` Al Viro
2017-06-13  0:54           ` Richard Narron
2017-06-13  1:43             ` Al Viro
2017-06-13 21:56               ` Richard Narron
2017-06-14  7:11                 ` Al Viro
2017-06-14 20:33                   ` Richard Narron [this message]
2017-06-15  8:00                   ` Al Viro
2017-06-16 14:29                     ` Richard Narron
2017-06-17  2:15                       ` Al Viro
2017-06-18  1:09                         ` Al Viro
2017-06-18 20:45                           ` Richard Narron
2017-06-20  5:17                           ` [git pull] " Al Viro

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LNX.2.21.1706141316400.2000@joy.test \
    --to=comet.berkeley@gmail.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=viro@ZenIV.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).