]> git.proxmox.com Git - mirror_zfs.git/commit - module/zfs/spa_config.c
Linux 4.2 compat: vfs_rename()
authorBrian Behlendorf <behlendorf1@llnl.gov>
Tue, 28 Jul 2015 23:45:17 +0000 (16:45 -0700)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Wed, 19 Aug 2015 23:04:33 +0000 (16:04 -0700)
commitefc412b645cbb209e42983a9dcb9d3c9427c5495
treef6775cc2fa69fda598665c6f1369c958edd34538
parentff9b1d07256c57b607cc6ad3448c1fb2487305d6
Linux 4.2 compat: vfs_rename()

The spa_config_write() function relies on the classic method of
making sure updates to the /etc/zfs/zpool.cache file are atomic.
It writes out a temporary version of the file and then uses
vn_rename() to switch it in to place.  This way there can never
exist a partial version of the file, it's all or nothing.

Conceptually this is a good strategy and it makes good sense
for platforms where it's easy to do a rename within the kernel.
Unfortunately, Linux is not one of those platforms.  Even doing
basic I/O to a file system from within the kernel is strongly
discouraged.  In order to support this at all the vn_rename()
implementation ends up being complex and fragile.  So fragile
that recent Linux 4.2 changes have broken it.

While it is possible to update vn_rename() to work with the
latest kernels a better long term strategy is to stop using
vn_rename() entirely.  Then all this complex, fragile code can
be removed.  Achieving this is straight forward because
config_write() is the only consumer of vn_rename().

This patch reworks spa_config_write() to update the cache file
in place.  The file will be truncated, written out, and then
synced to disk.  If an error is encountered the file will be
unlinked leaving the system in a consistent state.

This does expose a tiny tiny tiny window where a system could
crash at exactly the wrong moment could leave a partially written
cache file.  However, this is highly unlikely because the cache
file is 1) infrequently updated, 2) only a few kilobytes in size,
and 3) written with a single vn_rdwr() call.

If this were to somehow happen it poses no risk to pool.  Simply
removing the cache file will allow the pool to be imported cleanly.
Going forward this will be even less of an issue as we intend to
disable the use of a cache file by default.

Bottom line not using vn_rename() allows us to make ZoL more
robust against upstream kernel changes.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #3653
module/zfs/spa_config.c