FreeBSD src
Go to file
Kirk McKusick 35338e6091 This change avoids a kernel deadlock on "snaplk" when using
snapshots on UFS filesystems running with journaled soft updates.
This is the first of several bugs that need to be fixed before
removing the restriction added in -r230250 to prevent the use
of snapshots on filesystems running with journaled soft updates.

The deadlock occurs when holding the snapshot lock (snaplk)
and then trying to flush an inode via ffs_update(). We become
blocked by another process trying to flush a different inode
contained in the same inode block that we need. It holds the
inode block for which we are waiting locked. When it tries to
write the inode block, it gets blocked waiting for the our
snaplk when it calls ffs_copyonwrite() to see if the inode
block needs to be copied in our snapshot.

The most obvious place that this deadlock arises is in the
ffs_copyonwrite() routine when it updates critical metadata
in a snapshot and tries to write it out before proceeding.
The fix here is to write the data and indirect block pointer
for the snapshot, but to skip the call to ffs_update() to
write the snapshot inode. To ensure that we will never have
to update a pointer in the inode itself, the ffs_snapshot()
routine that creates the snapshot has to ensure that all the
direct blocks are allocated as part of the creation of the
snapshot.

A less obvious place that this deadlock occurs is when we hold
the snaplk because we are deleting a snapshot. In the course of
doing the deletion, we need to allocate various soft update
dependency structures and allocate some journal space. If we
hit a resource limit while doing this we decrease the resources
in use by flushing out an existing dirty file to get it to give
up the soft dependency resources that it holds. The flush can
cause an ffs_update() to be done on the inode for the file that
we have selected to flush resulting in the same deadlock as
described above when the inode that we have chosen to flush
resides in the same inode block as the snapshot inode that we hold.
The fix is to defer cleaning up any time that the inode on which
we are operating is a snapshot.

Help and review by:    Jeff Roberson
Tested by:             Peter Holm
MFC (to 9 only) after: 2 weeks
2012-03-01 18:45:25 +00:00
bin Whitespace cleanup: 2012-02-25 15:21:43 +00:00
cddl Analogous to r232059, add a parameter for the ZFS file system: 2012-02-26 16:30:39 +00:00
contrib Fix a race in top non-interactive mode. Use plain sleep(3) call instead 2012-02-27 20:52:20 +00:00
crypto Polish diff against upstream. 2012-02-13 11:59:59 +00:00
etc Add backlight control to ATI-graphics PowerBooks and iBooks. 2012-02-26 13:45:25 +00:00
games o Preserve argv[0] to use it later in usage(). 2012-01-28 15:29:43 +00:00
gnu Add a WITH_CLANG_IS_CC option for src.conf(5), disabled by default, that 2012-02-29 22:58:51 +00:00
include Revert r231673 and r231682 for now, until we can run a full make 2012-02-14 21:48:46 +00:00
kerberos5 Don't support OpenLDAP during lib32 build. 2011-12-06 12:03:01 +00:00
lib Handle the case where a boolean parameter is also a node. 2012-03-01 15:09:41 +00:00
libexec Define several extra macros in bsd.sys.mk and sys/conf/kern.pre.mk, to 2012-02-28 18:30:18 +00:00
release Add isci(4) to the hardware notes. 2012-02-23 18:54:33 +00:00
rescue Disable jail support in ifconfig when either building a rescue 2012-02-14 07:14:42 +00:00
sbin remove some write-only variables. 2012-03-01 17:35:16 +00:00
secure Return NULL on error rather than ":", per the crypt(3) man page. 2012-02-22 01:23:14 +00:00
share Since r199137 namei() returns EINVAL for DELETE and RENAME operations if 2012-03-01 18:17:45 +00:00
sys This change avoids a kernel deadlock on "snaplk" when using 2012-03-01 18:45:25 +00:00
tools Add a WITH_CLANG_IS_CC option for src.conf(5), disabled by default, that 2012-02-29 22:58:51 +00:00
usr.bin Use proper "maxproc" name, not "nproc". 2012-03-01 10:21:10 +00:00
usr.sbin Grammar: tzsetup now has more than one option. 2012-02-29 14:44:42 +00:00
COPYRIGHT Happy 2012 to FreeBSD users in Samoa. 2011-12-31 04:38:04 +00:00
LOCKS Update LOCKS syntax. 2008-06-05 19:47:58 +00:00
MAINTAINERS Add isci(4) driver for amd64 and i386 targets. 2012-01-31 19:38:18 +00:00
Makefile delete-old does not have delete-old-libs dependency. 2012-02-16 14:08:14 +00:00
Makefile.inc1 Add a WITH_CLANG_IS_CC option for src.conf(5), disabled by default, that 2012-02-29 22:58:51 +00:00
Makefile.mips Retire TARGET_ABI. 2011-01-07 20:26:33 +00:00
ObsoleteFiles.inc Correct pathname for manpages after libarchive 3.0.3 update. 2012-02-28 14:35:36 +00:00
README Add the cddl/ directory. 2010-11-14 11:32:56 +00:00
UPDATING Introduce VOP_UNP_BIND(), VOP_UNP_CONNECT(), and VOP_UNP_DETACH() 2012-02-29 21:38:31 +00:00

This is the top level of the FreeBSD source directory.  This file
was last revised on:
$FreeBSD$

For copyright information, please see the file COPYRIGHT in this
directory (additional copyright information also exists for some
sources in this tree - please see the specific source directories for
more information).

The Makefile in this directory supports a number of targets for
building components (or all) of the FreeBSD source tree, the most
commonly used one being ``world'', which rebuilds and installs
everything in the FreeBSD system from the source tree except the
kernel, the kernel-modules and the contents of /etc.  The ``world''
target should only be used in cases where the source tree has not
changed from the currently running version.  See:
http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/makeworld.html
for more information, including setting make(1) variables.

The ``buildkernel'' and ``installkernel'' targets build and install
the kernel and the modules (see below).  Please see the top of
the Makefile in this directory for more information on the
standard build targets and compile-time flags.

Building a kernel is a somewhat more involved process, documentation
for which can be found at:
   http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/kernelconfig.html
And in the config(8) man page.
Note: If you want to build and install the kernel with the
``buildkernel'' and ``installkernel'' targets, you might need to build
world before.  More information is available in the handbook.

The sample kernel configuration files reside in the sys/<arch>/conf
sub-directory (assuming that you've installed the kernel sources), the
file named GENERIC being the one used to build your initial installation
kernel.  The file NOTES contains entries and documentation for all possible
devices, not just those commonly used.  It is the successor of the ancient
LINT file, but in contrast to LINT, it is not buildable as a kernel but a
pure reference and documentation file.


Source Roadmap:
---------------
bin		System/user commands.

cddl		Various commands and libraries under the Common Development
		and Distribution License.

contrib		Packages contributed by 3rd parties.

crypto		Cryptography stuff (see crypto/README).

etc		Template files for /etc.

games		Amusements.

gnu		Various commands and libraries under the GNU Public License.
		Please see gnu/COPYING* for more information.

include		System include files.

kerberos5	Kerberos5 (Heimdal) package.

lib		System libraries.

libexec		System daemons.

release		Release building Makefile & associated tools.

rescue		Build system for statically linked /rescue utilities.

sbin		System commands.

secure		Cryptographic libraries and commands.

share		Shared resources.

sys		Kernel sources.

tools		Utilities for regression testing and miscellaneous tasks.

usr.bin		User commands.

usr.sbin	System administration commands.


For information on synchronizing your source tree with one or more of
the FreeBSD Project's development branches, please see:

  http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/synching.html