]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/commitdiff
Fix ztest truncated cache file
authorBrian Behlendorf <behlendorf1@llnl.gov>
Fri, 10 Jun 2016 13:45:26 +0000 (14:45 +0100)
committerKamal Mostafa <kamal@canonical.com>
Mon, 27 Jun 2016 21:34:47 +0000 (14:34 -0700)
BugLink: http://bugs.launchpad.net/bugs/1587686
Commit efc412b updated spa_config_write() for Linux 4.2 kernels to
truncate and overwrite rather than rename the cache file.  This is
the correct fix but it should have only been applied for the kernel
build.  In user space rename(2) is needed because ztest depends on
the cache file.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #4129
(cherry picked from zfs commit 151f84e2c32f690b92c424d8c55d2dfccaa76e51)
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Acked-by: Tim Gardner <tim.gardner@canonical.com>
Acked-by: Stefan Bader <stefan.bader@canonical.com>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
zfs/module/zfs/spa_config.c

index 929f18165934e22cd01a8745d2640fe42bfaee97..19432e0a024ea46788564dd6cbc4f33e6d682174 100644 (file)
@@ -174,7 +174,7 @@ spa_config_write(spa_config_dirent_t *dp, nvlist_t *nvl)
        VERIFY(nvlist_pack(nvl, &buf, &buflen, NV_ENCODE_XDR,
            KM_SLEEP) == 0);
 
-#ifdef __linux__
+#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
@@ -201,7 +201,8 @@ spa_config_write(spa_config_dirent_t *dp, nvlist_t *nvl)
         */
        (void) snprintf(temp, MAXPATHLEN, "%s.tmp", dp->scd_path);
 
-       if (vn_open(temp, UIO_SYSSPACE, oflags, 0644, &vp, CRCREAT, 0) == 0) {
+       error = vn_open(temp, UIO_SYSSPACE, oflags, 0644, &vp, CRCREAT, 0);
+       if (error == 0) {
                if (vn_rdwr(UIO_WRITE, vp, buf, buflen, 0, UIO_SYSSPACE,
                    0, RLIM64_INFINITY, kcred, NULL) == 0 &&
                    VOP_FSYNC(vp, FSYNC, kcred, NULL) == 0) {