Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove vn_rename and vn_remove dependency #6753

Merged
merged 1 commit into from
Oct 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion man/man8/zpool.8
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ Because the kernel destroys and recreates this file when pools are added and
removed, care should be taken when attempting to access this file.
When the last pool using a
.Sy cachefile
is exported or destroyed, the file is removed.
is exported or destroyed, the file will be empty.
.It Sy comment Ns = Ns Ar text
A text string consisting of printable ASCII characters that will be stored
such that it is available even if the pool becomes faulted.
Expand Down
35 changes: 26 additions & 9 deletions module/zfs/spa_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,26 @@ spa_config_load(void)
kobj_close_file(file);
}

static int
spa_config_remove(spa_config_dirent_t *dp)
{
#if defined(__linux__) && defined(_KERNEL)
int error, flags = FWRITE | FTRUNC;
uio_seg_t seg = UIO_SYSSPACE;
vnode_t *vp;

error = vn_open(dp->scd_path, seg, flags, 0644, &vp, 0, 0);
if (error == 0) {
(void) VOP_FSYNC(vp, FSYNC, kcred, NULL);
(void) VOP_CLOSE(vp, 0, 1, 0, kcred, NULL);
}

return (error);
#else
return (vn_remove(dp->scd_path, UIO_SYSSPACE, RMFILE));
#endif
}

static int
spa_config_write(spa_config_dirent_t *dp, nvlist_t *nvl)
{
Expand All @@ -161,12 +181,10 @@ 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) {
err = vn_remove(dp->scd_path, UIO_SYSSPACE, RMFILE);
/*
* Don't report an error when the cache file is already removed
*/
err = spa_config_remove(dp);
if (err == ENOENT)
err = 0;

return (err);
}

Expand All @@ -179,9 +197,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
* 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 +209,8 @@ 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);
(void) spa_config_remove(dp);
}
#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