Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 30 Sep 2011 23:18:51 +0300
From:      Kostik Belousov <kostikbel@gmail.com>
To:        Kirk McKusick <mckusick@mckusick.com>
Cc:        Attilio Rao <attilio@freebsd.org>, Garrett Cooper <yanegomi@gmail.com>, Xin LI <delphij@freebsd.org>, freebsd-fs@freebsd.org
Subject:   Re: Need to force sync(2) before umounting UFS1 filesystems?
Message-ID:  <20110930201851.GB1511@deviant.kiev.zoral.com.ua>
In-Reply-To: <201109301820.p8UIKSGj039445@chez.mckusick.com>
References:  <CAJ-FndBDzv6af%2BAVq9wkLbN8V3wHDk3BGPuTFaXB7j8EXsrrhA@mail.gmail.com> <201109301820.p8UIKSGj039445@chez.mckusick.com>

next in thread | previous in thread | raw e-mail | index | archive | help

--m4l0o/auqPKO2x83
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Fri, Sep 30, 2011 at 11:20:28AM -0700, Kirk McKusick wrote:
> > Date: Fri, 30 Sep 2011 15:31:56 +0200
> > Subject: Re: Need to force sync(2) before umounting UFS1 filesystems?
> > From: Attilio Rao <attilio@freebsd.org>
> > To: Kirk McKusick <mckusick@mckusick.com>
> > Cc: Konstantin Belousov <kib@freebsd.org>,
> >     Garrett Cooper <yanegomi@gmail.com>,
> >     freebsd-fs@freebsd.org, Xin LI <delphij@freebsd.org>
> >=20
> > 2011/9/30 Kirk McKusick <mckusick@mckusick.com>:
> >=20
> > > Here is my proposed fix. It does the unroll originally found in the
> > > non-FORCE case before sleeping waiting for the vfs_busy to clear.
> > > Is it acceptable to hold the mount mutex while calling VOP_UNLOCK?
> > > If not, then it needs to be released before the unlock, reacquired
> > > afterwards, and the check to see if the sleep is needed redone.
> >=20
> > I thought about this approach when sending the e-mail, but there is a
> > problem: you need to handle the MNTK_UNMOUNT flag checking and
> > subsequent setting after coveredvnode is held, otherwise at the first
> > looping you will just return EBUSY.
> >=20
> > You can avoid the unlock by passing PVFS | PDROP.
> >=20
> > Attilio
>=20
> Problem noted. I have updated the patch to clear the MNTK_UNMOUNT
> (and other flags set above it) after it returns from the sleep.
> Which means I cannot use the PDROP flag now, but it is good to
> know about it for future reference.
>=20
> Still not clear to me if it is acceptable to hold the mount mutex
> while calling VOP_UNLOCK. Should I drop the mount mutex around the
> VOP_UNLOCK(coveredvp)? Other than that possible problem, this patch
> appears to solve the EBUSY problem and avoid possible deadlocks.
I do not understand which deadlock is talked about there.
It seems thay Attilio concern was with acquiring covered vnode lock
after mounted fs is busied, but this is prohibited.

See r166167 for more detailed description of the order.

>=20
> 	Kirk McKusick
>=20
> Index: sys/kern/vfs_mount.c
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> --- sys/kern/vfs_mount.c	(revision 225884)
> +++ sys/kern/vfs_mount.c	(working copy)
> @@ -1187,6 +1187,7 @@
> =20
>  	mtx_assert(&Giant, MA_OWNED);
> =20
> +top:
>  	if ((coveredvp =3D mp->mnt_vnodecovered) !=3D NULL) {
>  		mnt_gen_r =3D mp->mnt_gen;
>  		VI_LOCK(coveredvp);
> @@ -1227,21 +1228,19 @@
>  		mp->mnt_kern_flag |=3D MNTK_UNMOUNTF;
>  	error =3D 0;
>  	if (mp->mnt_lockref) {
> -		if ((flags & MNT_FORCE) =3D=3D 0) {
> -			mp->mnt_kern_flag &=3D ~(MNTK_UNMOUNT | MNTK_NOINSMNTQ |
> -			    MNTK_UNMOUNTF);
> -			if (mp->mnt_kern_flag & MNTK_MWAIT) {
> -				mp->mnt_kern_flag &=3D ~MNTK_MWAIT;
> -				wakeup(mp);
> -			}
> -			MNT_IUNLOCK(mp);
> -			if (coveredvp)
> -				VOP_UNLOCK(coveredvp, 0);
> -			return (EBUSY);
> +		if (mp->mnt_kern_flag & MNTK_MWAIT) {
> +			mp->mnt_kern_flag &=3D ~MNTK_MWAIT;
> +			wakeup(mp);
>  		}
> +		if (coveredvp)
> +			VOP_UNLOCK(coveredvp, 0);
>  		mp->mnt_kern_flag |=3D MNTK_DRAINING;
>  		error =3D msleep(&mp->mnt_lockref, MNT_MTX(mp), PVFS,
>  		    "mount drain", 0);
> +		mp->mnt_kern_flag &=3D ~(MNTK_UNMOUNT | MNTK_NOINSMNTQ |
> +		    MNTK_UNMOUNTF);
> +		MNT_IUNLOCK(mp);
> +		goto top;
>  	}
>  	MNT_IUNLOCK(mp);
>  	KASSERT(mp->mnt_lockref =3D=3D 0,

--m4l0o/auqPKO2x83
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.18 (FreeBSD)

iEYEARECAAYFAk6GJCsACgkQC3+MBN1Mb4gjDQCghKC8OgO5SmPn3QAfwjbgBmiC
0yoAoM6YZsEQgGWARcYMPLFOWvCot3yj
=UE5c
-----END PGP SIGNATURE-----

--m4l0o/auqPKO2x83--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20110930201851.GB1511>