]> git.proxmox.com Git - zfsonlinux.git/blame - zfs-patches/0011-Remove-vn_rename-and-vn_remove-dependency.patch
update ZFS submodule to debian/0.7.9-2
[zfsonlinux.git] / zfs-patches / 0011-Remove-vn_rename-and-vn_remove-dependency.patch
CommitLineData
75b07eca
FG
1From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2From: Brian Behlendorf <behlendorf1@llnl.gov>
3Date: Thu, 19 Oct 2017 10:06:55 -0700
4Subject: [PATCH] Remove vn_rename and vn_remove dependency
5MIME-Version: 1.0
6Content-Type: text/plain; charset=UTF-8
7Content-Transfer-Encoding: 8bit
8
9The only place vn_rename and vn_remove are used is when writing
10out an updated pool configuration file. By truncating the file
11instead of renaming and removing it we can avoid having to implement
12these interfaces entirely. Functionally an empty cache file is
13treated the same as a missing cache file. This is particularly
14advantageous because the Linux kernel has never provided a way
15to reliably implement vn_rename and vn_remove.
16
17The cachefile_004_pos.ksh test case was updated to understand
18that an empty cache file is the same as a missing one.
19
20The zfs-import-* systemd service files were not updated to use
21ConditionFileNotEmpty in place of ConditionPathExists. This
22means that after exporting all pools and rebooting new pools
23will not the scanned for on the next boot. This small change
24should not impact normal usage since pools are not exported
25as part of a normal shutdown.
26
27Documentation was updated accordingly.
28
29Reviewed-by: George Melikov <mail@gmelikov.ru>
30Reviewed-by: Arkadiusz Bubała <arkadiusz.bubala@open-e.com>
31Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
32Closes zfsonlinux/spl#648
33Closes #6753
34(cherry picked from commit 5d62588032aa1d13d7f789cf564a0d20c77a5762)
35Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
36---
37 module/zfs/spa_config.c | 34 ++++++++++++++++++----
38 man/man8/zpool.8 | 2 +-
39 .../functional/cachefile/cachefile_004_pos.ksh | 6 ++--
40 3 files changed, 32 insertions(+), 10 deletions(-)
41
42diff --git a/module/zfs/spa_config.c b/module/zfs/spa_config.c
43index 5b792b868..fea239014 100644
44--- a/module/zfs/spa_config.c
45+++ b/module/zfs/spa_config.c
46@@ -147,6 +147,26 @@ out:
47 kobj_close_file(file);
48 }
49
50+static int
51+spa_config_remove(spa_config_dirent_t *dp)
52+{
53+#if defined(__linux__) && defined(_KERNEL)
54+ int error, flags = FWRITE | FTRUNC;
55+ uio_seg_t seg = UIO_SYSSPACE;
56+ vnode_t *vp;
57+
58+ error = vn_open(dp->scd_path, seg, flags, 0644, &vp, 0, 0);
59+ if (error == 0) {
60+ (void) VOP_FSYNC(vp, FSYNC, kcred, NULL);
61+ (void) VOP_CLOSE(vp, 0, 1, 0, kcred, NULL);
62+ }
63+
64+ return (error);
65+#else
66+ return (vn_remove(dp->scd_path, UIO_SYSSPACE, RMFILE));
67+#endif
68+}
69+
70 static int
71 spa_config_write(spa_config_dirent_t *dp, nvlist_t *nvl)
72 {
73@@ -161,7 +181,10 @@ spa_config_write(spa_config_dirent_t *dp, nvlist_t *nvl)
74 * If the nvlist is empty (NULL), then remove the old cachefile.
75 */
76 if (nvl == NULL) {
77- err = vn_remove(dp->scd_path, UIO_SYSSPACE, RMFILE);
78+ err = spa_config_remove(dp);
79+ if (err == ENOENT)
80+ err = 0;
81+
82 return (err);
83 }
84
85@@ -174,9 +197,9 @@ spa_config_write(spa_config_dirent_t *dp, nvlist_t *nvl)
86 #if defined(__linux__) && defined(_KERNEL)
87 /*
88 * Write the configuration to disk. Due to the complexity involved
89- * in performing a rename from within the kernel the file is truncated
90- * and overwritten in place. In the event of an error the file is
91- * unlinked to make sure we always have a consistent view of the data.
92+ * in performing a rename and remove from within the kernel the file
93+ * is instead truncated and overwritten in place. This way we always
94+ * have a consistent view of the data or a zero length file.
95 */
96 err = vn_open(dp->scd_path, UIO_SYSSPACE, oflags, 0644, &vp, 0, 0);
97 if (err == 0) {
98@@ -186,9 +209,8 @@ spa_config_write(spa_config_dirent_t *dp, nvlist_t *nvl)
99 err = VOP_FSYNC(vp, FSYNC, kcred, NULL);
100
101 (void) VOP_CLOSE(vp, oflags, 1, 0, kcred, NULL);
102-
103 if (err)
104- (void) vn_remove(dp->scd_path, UIO_SYSSPACE, RMFILE);
105+ (void) spa_config_remove(dp);
106 }
107 #else
108 /*
109diff --git a/man/man8/zpool.8 b/man/man8/zpool.8
110index 328ba3dce..22579101a 100644
111--- a/man/man8/zpool.8
112+++ b/man/man8/zpool.8
113@@ -655,7 +655,7 @@ Because the kernel destroys and recreates this file when pools are added and
114 removed, care should be taken when attempting to access this file.
115 When the last pool using a
116 .Sy cachefile
117-is exported or destroyed, the file is removed.
118+is exported or destroyed, the file will be empty.
119 .It Sy comment Ns = Ns Ar text
120 A text string consisting of printable ASCII characters that will be stored
121 such that it is available even if the pool becomes faulted.
122diff --git a/tests/zfs-tests/tests/functional/cachefile/cachefile_004_pos.ksh b/tests/zfs-tests/tests/functional/cachefile/cachefile_004_pos.ksh
123index ae54a9365..e0b81e166 100755
124--- a/tests/zfs-tests/tests/functional/cachefile/cachefile_004_pos.ksh
125+++ b/tests/zfs-tests/tests/functional/cachefile/cachefile_004_pos.ksh
126@@ -98,13 +98,13 @@ log_must zpool set cachefile=$CPATH2 $TESTPOOL1
127 log_must pool_in_cache $TESTPOOL1 $CPATH2
128 log_must zpool set cachefile=$CPATH2 $TESTPOOL2
129 log_must pool_in_cache $TESTPOOL2 $CPATH2
130-if [[ -f $CPATH1 ]]; then
131+if [[ -s $CPATH1 ]]; then
132 log_fail "Verify set when cachefile is set on pool."
133 fi
134
135 log_must zpool export $TESTPOOL1
136 log_must zpool export $TESTPOOL2
137-if [[ -f $CPATH2 ]]; then
138+if [[ -s $CPATH2 ]]; then
139 log_fail "Verify export when cachefile is set on pool."
140 fi
141
142@@ -117,7 +117,7 @@ log_must pool_in_cache $TESTPOOL2 $CPATH2
143
144 log_must zpool destroy $TESTPOOL1
145 log_must zpool destroy $TESTPOOL2
146-if [[ -f $CPATH2 ]]; then
147+if [[ -s $CPATH2 ]]; then
148 log_fail "Verify destroy when cachefile is set on pool."
149 fi
150
151--
1522.14.2
153