From owner-freebsd-fs@freebsd.org Thu Mar 10 16:29:22 2016 Return-Path: Delivered-To: freebsd-fs@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id AEC40AC9DEF for ; Thu, 10 Mar 2016 16:29:22 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 5959DA61 for ; Thu, 10 Mar 2016 16:29:22 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kostik@localhost [127.0.0.1]) by kib.kiev.ua (8.15.2/8.15.2) with ESMTPS id u2AGTHte025862 (version=TLSv1 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Thu, 10 Mar 2016 18:29:17 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua u2AGTHte025862 Received: (from kostik@localhost) by tom.home (8.15.2/8.15.2/Submit) id u2AGTGgg025861; Thu, 10 Mar 2016 18:29:16 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Thu, 10 Mar 2016 18:29:16 +0200 From: Konstantin Belousov To: Chris Torek Cc: freebsd-fs@freebsd.org Subject: Re: quotactl bug: vfs_busy never unbusy-es Message-ID: <20160310162916.GB1741@kib.kiev.ua> References: <20160310091433.GS67250@kib.kiev.ua> <201603101138.u2ABcihi048011@elf.torek.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <201603101138.u2ABcihi048011@elf.torek.net> User-Agent: Mutt/1.5.24 (2015-08-30) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on tom.home X-BeenThere: freebsd-fs@freebsd.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Filesystems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 10 Mar 2016 16:29:22 -0000 On Thu, Mar 10, 2016 at 03:38:44AM -0800, Chris Torek wrote: > That, in fact, is what I started with, before I investigated > further and found the nullfs and unionfs pattern violation. > > It's certainly worth doing as a start, though. Lets fix nullfs too. The uncomfortable issue with the interface is that it is not always possible to busy mount point after unbusy. I propose to assume that for ENOENT error the busy ref is lost (this is the only possible error from vfs_busy()). I also verified that UFS quota code does not return this error for !quotaon case. diff --git a/sys/fs/nullfs/null_vfsops.c b/sys/fs/nullfs/null_vfsops.c index 49bae28..36e44cf 100644 --- a/sys/fs/nullfs/null_vfsops.c +++ b/sys/fs/nullfs/null_vfsops.c @@ -53,6 +53,7 @@ #include #include +#include static MALLOC_DEFINE(M_NULLFSMNT, "nullfs_mount", "NULLFS mount structure"); @@ -285,13 +286,33 @@ nullfs_root(mp, flags, vpp) } static int -nullfs_quotactl(mp, cmd, uid, arg) - struct mount *mp; - int cmd; - uid_t uid; - void *arg; +nullfs_quotactl(struct mount *mp, int cmd, uid_t uid, void *arg) { - return VFS_QUOTACTL(MOUNTTONULLMOUNT(mp)->nullm_vfs, cmd, uid, arg); + struct mount *lmp; + int error, error1; + + /* + * Nullfs mp is busy, which ensures that the lower mount is + * valid. + */ + lmp = MOUNTTONULLMOUNT(mp)->nullm_vfs; + vfs_ref(mp); + vfs_ref(lmp); + vfs_unbusy(mp); + error = vfs_busy(lmp, 0); + if (error == 0) { + error = VFS_QUOTACTL(lmp, cmd, uid, arg); + if ((cmd >> SUBCMDSHIFT) != Q_QUOTAON && error != ENOENT) { + vfs_unbusy(lmp); + error1 = vfs_busy(mp, 0); + if (error1 != 0) + error = error1; + } + } + vfs_rel(mp); + vfs_rel(lmp); + return (error); + } static int diff --git a/sys/kern/vfs_default.c b/sys/kern/vfs_default.c index a7977bf..26e45f4 100644 --- a/sys/kern/vfs_default.c +++ b/sys/kern/vfs_default.c @@ -66,6 +66,8 @@ __FBSDID("$FreeBSD$"); #include #include +#include + static int vop_nolookup(struct vop_lookup_args *); static int vop_norename(struct vop_rename_args *); static int vop_nostrategy(struct vop_strategy_args *); @@ -1190,6 +1192,8 @@ vfs_stdquotactl (mp, cmds, uid, arg) void *arg; { + if ((cmds >> SUBCMDSHIFT) == Q_QUOTAON) + vfs_unbusy(mp); return (EOPNOTSUPP); } diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c index 11813fc..1ca9d97 100644 --- a/sys/kern/vfs_syscalls.c +++ b/sys/kern/vfs_syscalls.c @@ -198,7 +198,7 @@ sys_quotactl(td, uap) * Require that Q_QUOTAON handles the vfs_busy() reference on * its own, always returning with ubusied mount point. */ - if ((uap->cmd >> SUBCMDSHIFT) != Q_QUOTAON) + if ((uap->cmd >> SUBCMDSHIFT) != Q_QUOTAON && error != ENOENT) vfs_unbusy(mp); return (error); }