From owner-freebsd-fs@FreeBSD.ORG Wed Feb 20 03:59:18 2013 Return-Path: Delivered-To: fs@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 2B80E6B7 for ; Wed, 20 Feb 2013 03:59:18 +0000 (UTC) (envelope-from jamie@FreeBSD.org) Received: from m2.gritton.org (gritton.org [199.192.164.235]) by mx1.freebsd.org (Postfix) with ESMTP id E6FDBDEA for ; Wed, 20 Feb 2013 03:59:17 +0000 (UTC) Received: from glorfindel.gritton.org (c-174-52-130-157.hsd1.ut.comcast.net [174.52.130.157]) (authenticated bits=0) by m2.gritton.org (8.14.5/8.14.5) with ESMTP id r1K3xG4Z019369 for ; Tue, 19 Feb 2013 20:59:16 -0700 (MST) (envelope-from jamie@FreeBSD.org) Message-ID: <51244A13.8030907@FreeBSD.org> Date: Tue, 19 Feb 2013 20:59:15 -0700 From: Jamie Gritton User-Agent: Mozilla/5.0 (X11; U; FreeBSD amd64; en-US; rv:1.9.2.24) Gecko/20120129 Thunderbird/3.1.16 MIME-Version: 1.0 To: fs@FreeBSD.org Subject: mount/kldload race Content-Type: multipart/mixed; boundary="------------080501010405030304090106" X-BeenThere: freebsd-fs@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Filesystems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 20 Feb 2013 03:59:18 -0000 This is a multi-part message in MIME format. --------------080501010405030304090106 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Perhaps most people don't try to mount a bunch of filesystems at the same time, at least not those that depend on kernel modules. But it turns out that's going to be a pretty common situation with jails and nullfs. And I found that when attempting such a feat will cause most of these simultaneous mounts to fail with ENODEV. It turns out that the problem is a race in vfs_byname_kld(). First it'll see if the fstype is loaded, and if it isn't then it will load the module. But if the module is loaded by a different process between those two points, the resulting EEXIST from kern_kldload() will make vfs_byname_kld() error out. The fix is pretty simple: don't treat EEXIST as an error. By going on, and rechecking for the fstype, the filesystem can be mounted while still allowing any "real" error to be caught. I'm including a small patch that will accomplish this, and I'd appreciate a quick look by anyone who's familiar with this part of things before I commit it. - Jamie --------------080501010405030304090106 Content-Type: text/plain; name="vfs_init.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="vfs_init.diff" Index: sys/kern/vfs_init.c =================================================================== --- sys/kern/vfs_init.c (revision 247000) +++ sys/kern/vfs_init.c (working copy) @@ -130,13 +130,18 @@ /* Try to load the respective module. */ *error = kern_kldload(td, fstype, &fileid); + if (*error == EEXIST) { + *error = 0; + fileid = 0; + } if (*error) return (NULL); /* Look up again to see if the VFS was loaded. */ vfsp = vfs_byname(fstype); if (vfsp == NULL) { - (void)kern_kldunload(td, fileid, LINKER_UNLOAD_FORCE); + if (fileid != 0) + (void)kern_kldunload(td, fileid, LINKER_UNLOAD_FORCE); *error = ENODEV; return (NULL); } --------------080501010405030304090106--