Skip to content

Commit

Permalink
Remove vn_rename and vn_remove dependency
Browse files Browse the repository at this point in the history
The only place vn_rename and vn_remove are used is when writing
out an updated pool configuration file.  By truncating the file
instead of renaming and removing it we can avoid having to implement
these interfaces entirely.  Functionally an empty cache file is
treated the same as a missing cache file.  This is particularly
advantageous because the Linux kernel has never provided a way
to reliably implement vn_rename and vn_remove.

The cachefile_004_pos.ksh test case was updated to understand
that an empty cache file is the same as a missing one.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Requires-spl: refs/pull/661/head
  • Loading branch information
behlendorf committed Oct 12, 2017
1 parent d4404c3 commit d43636d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
18 changes: 12 additions & 6 deletions module/zfs/spa_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,21 @@ spa_config_write(spa_config_dirent_t *dp, nvlist_t *nvl)
* If the nvlist is empty (NULL), then remove the old cachefile.
*/
if (nvl == NULL) {
#if defined(__linux__) && defined(_KERNEL)
if ((err = vn_open(dp->scd_path, UIO_SYSSPACE, FWRITE | FTRUNC,
0644, &vp, 0, 0)) == 0) {
(void) VOP_FSYNC(vp, FSYNC, kcred, NULL);
(void) VOP_CLOSE(vp, 0, 1, 0, kcred, NULL);
}
#else
err = vn_remove(dp->scd_path, UIO_SYSSPACE, RMFILE);
#endif
/*
* Don't report an error when the cache file is already removed
*/
if (err == ENOENT)
err = 0;

return (err);
}

Expand All @@ -179,9 +188,9 @@ spa_config_write(spa_config_dirent_t *dp, nvlist_t *nvl)
#if defined(__linux__) && defined(_KERNEL)
/*
* Write the configuration to disk. Due to the complexity involved
* in performing a rename from within the kernel the file is truncated
* and overwritten in place. In the event of an error the file is
* unlinked to make sure we always have a consistent view of the data.
* in performing a rename and remove from within the kernel the file
* is instead truncated and overwritten in place. This way we always
* always have a consistent view of the data or a zero length file.
*/
err = vn_open(dp->scd_path, UIO_SYSSPACE, oflags, 0644, &vp, 0, 0);
if (err == 0) {
Expand All @@ -191,9 +200,6 @@ spa_config_write(spa_config_dirent_t *dp, nvlist_t *nvl)
err = VOP_FSYNC(vp, FSYNC, kcred, NULL);

(void) VOP_CLOSE(vp, oflags, 1, 0, kcred, NULL);

if (err)
(void) vn_remove(dp->scd_path, UIO_SYSSPACE, RMFILE);
}
#else
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ log_must zpool set cachefile=$CPATH2 $TESTPOOL1
log_must pool_in_cache $TESTPOOL1 $CPATH2
log_must zpool set cachefile=$CPATH2 $TESTPOOL2
log_must pool_in_cache $TESTPOOL2 $CPATH2
if [[ -f $CPATH1 ]]; then
if [[ -s $CPATH1 ]]; then
log_fail "Verify set when cachefile is set on pool."
fi

log_must zpool export $TESTPOOL1
log_must zpool export $TESTPOOL2
if [[ -f $CPATH2 ]]; then
if [[ -s $CPATH2 ]]; then
log_fail "Verify export when cachefile is set on pool."
fi

Expand All @@ -117,7 +117,7 @@ log_must pool_in_cache $TESTPOOL2 $CPATH2

log_must zpool destroy $TESTPOOL1
log_must zpool destroy $TESTPOOL2
if [[ -f $CPATH2 ]]; then
if [[ -s $CPATH2 ]]; then
log_fail "Verify destroy when cachefile is set on pool."
fi

Expand Down

0 comments on commit d43636d

Please sign in to comment.