]> git.proxmox.com Git - zfsonlinux.git/blame - spl-patches/0003-Remove-vn_rename-and-vn_remove.patch
update SPL to 0.7.7
[zfsonlinux.git] / spl-patches / 0003-Remove-vn_rename-and-vn_remove.patch
CommitLineData
edf5051c
FG
1From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2From: Brian Behlendorf <behlendorf1@llnl.gov>
3Date: Fri, 27 Oct 2017 15:49:14 -0700
4Subject: [PATCH] Remove vn_rename and vn_remove
5MIME-Version: 1.0
6Content-Type: text/plain; charset=UTF-8
7Content-Transfer-Encoding: 8bit
8
9Both vn_rename and vn_remove have been historically problematic
10to implement reliably. Rather than fixing them yet again they
11are being removed.
12
13Reviewed-by: Arkadiusz Bubala <arkadiusz.bubala@open-e.com>
14Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
15Closes #648
16Closes #661
17(cherry picked from commit 1cb26f06524bdddef24352a3d9ac90a402294f2b)
18Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
19---
20 include/sys/vnode.h | 2 -
21 module/spl/spl-vnode.c | 217 ---------------------------------------------
22 module/splat/splat-vnode.c | 96 --------------------
23 config/spl-build.m4 | 101 ---------------------
24 4 files changed, 416 deletions(-)
25
26diff --git a/include/sys/vnode.h b/include/sys/vnode.h
27index 0b857d3..ad7f8f4 100644
28--- a/include/sys/vnode.h
29+++ b/include/sys/vnode.h
30@@ -177,8 +177,6 @@ extern int vn_rdwr(uio_rw_t uio, vnode_t *vp, void *addr, ssize_t len,
31 extern int vn_close(vnode_t *vp, int flags, int x1, int x2, void *x3, void *x4);
32 extern int vn_seek(vnode_t *vp, offset_t o, offset_t *op, void *ct);
33
34-extern int vn_remove(const char *path, uio_seg_t seg, int flags);
35-extern int vn_rename(const char *path1, const char *path2, int x1);
36 extern int vn_getattr(vnode_t *vp, vattr_t *vap, int flags, void *x3, void *x4);
37 extern int vn_fsync(vnode_t *vp, int flags, void *x3, void *x4);
38 extern int vn_space(vnode_t *vp, int cmd, struct flock *bfp, int flag,
39diff --git a/module/spl/spl-vnode.c b/module/spl/spl-vnode.c
40index ca19d73..77bfb45 100644
41--- a/module/spl/spl-vnode.c
42+++ b/module/spl/spl-vnode.c
43@@ -269,223 +269,6 @@ vn_seek(vnode_t *vp, offset_t ooff, offset_t *noffp, void *ct)
44 }
45 EXPORT_SYMBOL(vn_seek);
46
47-/*
48- * spl_basename() takes a NULL-terminated string s as input containing a path.
49- * It returns a char pointer to a string and a length that describe the
50- * basename of the path. If the basename is not "." or "/", it will be an index
51- * into the string. While the string should be NULL terminated, the section
52- * referring to the basename is not. spl_basename is dual-licensed GPLv2+ and
53- * CC0. Anyone wishing to reuse it in another codebase may pick either license.
54- */
55-static void
56-spl_basename(const char *s, const char **str, int *len)
57-{
58- size_t i, end;
59-
60- ASSERT(str);
61- ASSERT(len);
62-
63- if (!s || !*s) {
64- *str = ".";
65- *len = 1;
66- return;
67- }
68-
69- i = strlen(s) - 1;
70-
71- while (i && s[i--] == '/');
72-
73- if (i == 0) {
74- *str = "/";
75- *len = 1;
76- return;
77- }
78-
79- end = i;
80-
81- for (end = i; i; i--) {
82- if (s[i] == '/') {
83- *str = &s[i+1];
84- *len = end - i + 1;
85- return;
86- }
87- }
88-
89- *str = s;
90- *len = end + 1;
91-}
92-
93-static struct dentry *
94-spl_kern_path_locked(const char *name, struct path *path)
95-{
96- struct path parent;
97- struct dentry *dentry;
98- const char *basename;
99- int len;
100- int rc;
101-
102- ASSERT(name);
103- ASSERT(path);
104-
105- spl_basename(name, &basename, &len);
106-
107- /* We do not accept "." or ".." */
108- if (len <= 2 && basename[0] == '.')
109- if (len == 1 || basename[1] == '.')
110- return (ERR_PTR(-EACCES));
111-
112- rc = kern_path(name, LOOKUP_PARENT, &parent);
113- if (rc)
114- return (ERR_PTR(rc));
115-
116- /* use I_MUTEX_PARENT because vfs_unlink needs it */
117- spl_inode_lock_nested(parent.dentry->d_inode, I_MUTEX_PARENT);
118-
119- dentry = lookup_one_len(basename, parent.dentry, len);
120- if (IS_ERR(dentry)) {
121- spl_inode_unlock(parent.dentry->d_inode);
122- path_put(&parent);
123- } else {
124- *path = parent;
125- }
126-
127- return (dentry);
128-}
129-
130-/* Based on do_unlinkat() from linux/fs/namei.c */
131-int
132-vn_remove(const char *path, uio_seg_t seg, int flags)
133-{
134- struct dentry *dentry;
135- struct path parent;
136- struct inode *inode = NULL;
137- int rc = 0;
138-
139- ASSERT(seg == UIO_SYSSPACE);
140- ASSERT(flags == RMFILE);
141-
142- dentry = spl_kern_path_locked(path, &parent);
143- rc = PTR_ERR(dentry);
144- if (!IS_ERR(dentry)) {
145- if (parent.dentry->d_name.name[parent.dentry->d_name.len]) {
146- rc = 0;
147- goto slashes;
148- }
149-
150- inode = dentry->d_inode;
151- if (inode) {
152- atomic_inc(&inode->i_count);
153- } else {
154- rc = 0;
155- goto slashes;
156- }
157-
158-#ifdef HAVE_2ARGS_VFS_UNLINK
159- rc = vfs_unlink(parent.dentry->d_inode, dentry);
160-#else
161- rc = vfs_unlink(parent.dentry->d_inode, dentry, NULL);
162-#endif /* HAVE_2ARGS_VFS_UNLINK */
163-exit1:
164- dput(dentry);
165- } else {
166- return (-rc);
167- }
168-
169- spl_inode_unlock(parent.dentry->d_inode);
170- if (inode)
171- iput(inode); /* truncate the inode here */
172-
173- path_put(&parent);
174- return (-rc);
175-
176-slashes:
177- rc = !dentry->d_inode ? -ENOENT :
178- S_ISDIR(dentry->d_inode->i_mode) ? -EISDIR : -ENOTDIR;
179- goto exit1;
180-} /* vn_remove() */
181-EXPORT_SYMBOL(vn_remove);
182-
183-/* Based on do_rename() from linux/fs/namei.c */
184-int
185-vn_rename(const char *oldname, const char *newname, int x1)
186-{
187- struct dentry *old_dir, *new_dir;
188- struct dentry *old_dentry, *new_dentry;
189- struct dentry *trap;
190- struct path old_parent, new_parent;
191- int rc = 0;
192-
193- old_dentry = spl_kern_path_locked(oldname, &old_parent);
194- if (IS_ERR(old_dentry)) {
195- rc = PTR_ERR(old_dentry);
196- goto exit;
197- }
198-
199- spl_inode_unlock(old_parent.dentry->d_inode);
200-
201- new_dentry = spl_kern_path_locked(newname, &new_parent);
202- if (IS_ERR(new_dentry)) {
203- rc = PTR_ERR(new_dentry);
204- goto exit2;
205- }
206-
207- spl_inode_unlock(new_parent.dentry->d_inode);
208-
209- rc = -EXDEV;
210- if (old_parent.mnt != new_parent.mnt)
211- goto exit3;
212-
213- old_dir = old_parent.dentry;
214- new_dir = new_parent.dentry;
215- trap = lock_rename(new_dir, old_dir);
216-
217- /* source should not be ancestor of target */
218- rc = -EINVAL;
219- if (old_dentry == trap)
220- goto exit4;
221-
222- /* target should not be an ancestor of source */
223- rc = -ENOTEMPTY;
224- if (new_dentry == trap)
225- goto exit4;
226-
227- /* source must exist */
228- rc = -ENOENT;
229- if (!old_dentry->d_inode)
230- goto exit4;
231-
232- /* unless the source is a directory trailing slashes give -ENOTDIR */
233- if (!S_ISDIR(old_dentry->d_inode->i_mode)) {
234- rc = -ENOTDIR;
235- if (old_dentry->d_name.name[old_dentry->d_name.len])
236- goto exit4;
237- if (new_dentry->d_name.name[new_dentry->d_name.len])
238- goto exit4;
239- }
240-
241-#if defined(HAVE_4ARGS_VFS_RENAME)
242- rc = vfs_rename(old_dir->d_inode, old_dentry,
243- new_dir->d_inode, new_dentry);
244-#elif defined(HAVE_5ARGS_VFS_RENAME)
245- rc = vfs_rename(old_dir->d_inode, old_dentry,
246- new_dir->d_inode, new_dentry, NULL);
247-#else
248- rc = vfs_rename(old_dir->d_inode, old_dentry,
249- new_dir->d_inode, new_dentry, NULL, 0);
250-#endif
251-exit4:
252- unlock_rename(new_dir, old_dir);
253-exit3:
254- dput(new_dentry);
255- path_put(&new_parent);
256-exit2:
257- dput(old_dentry);
258- path_put(&old_parent);
259-exit:
260- return (-rc);
261-}
262-EXPORT_SYMBOL(vn_rename);
263-
264 int
265 vn_getattr(vnode_t *vp, vattr_t *vap, int flags, void *x3, void *x4)
266 {
267diff --git a/module/splat/splat-vnode.c b/module/splat/splat-vnode.c
268index ad69cf6..9160003 100644
269--- a/module/splat/splat-vnode.c
270+++ b/module/splat/splat-vnode.c
271@@ -42,10 +42,6 @@
272 #define SPLAT_VNODE_TEST3_NAME "vn_rdwr"
273 #define SPLAT_VNODE_TEST3_DESC "Vn_rdwrt Test"
274
275-#define SPLAT_VNODE_TEST4_ID 0x0904
276-#define SPLAT_VNODE_TEST4_NAME "vn_rename"
277-#define SPLAT_VNODE_TEST4_DESC "Vn_rename Test"
278-
279 #define SPLAT_VNODE_TEST5_ID 0x0905
280 #define SPLAT_VNODE_TEST5_NAME "vn_getattr"
281 #define SPLAT_VNODE_TEST5_DESC "Vn_getattr Test"
282@@ -218,94 +214,10 @@ splat_vnode_test3(struct file *file, void *arg)
283
284 out:
285 VOP_CLOSE(vp, 0, 0, 0, 0, 0);
286- vn_remove(SPLAT_VNODE_TEST_FILE_RW, UIO_SYSSPACE, RMFILE);
287
288 return -rc;
289 } /* splat_vnode_test3() */
290
291-#if LINUX_VERSION_CODE <= KERNEL_VERSION(4,1,0)
292-static int
293-splat_vnode_test4(struct file *file, void *arg)
294-{
295- vnode_t *vp;
296- char buf1[32] = "SPL VNode Interface Test File\n";
297- char buf2[32] = "";
298- int rc;
299-
300- if ((rc = splat_vnode_unlink_all(file, arg, SPLAT_VNODE_TEST4_NAME)))
301- return rc;
302-
303- if ((rc = vn_open(SPLAT_VNODE_TEST_FILE_RW1, UIO_SYSSPACE,
304- FWRITE | FREAD | FCREAT | FEXCL, 0644, &vp, 0, 0))) {
305- splat_vprint(file, SPLAT_VNODE_TEST4_NAME,
306- "Failed to vn_open test file: %s (%d)\n",
307- SPLAT_VNODE_TEST_FILE_RW1, rc);
308- goto out;
309- }
310-
311- rc = vn_rdwr(UIO_WRITE, vp, buf1, strlen(buf1), 0,
312- UIO_SYSSPACE, 0, RLIM64_INFINITY, 0, NULL);
313- if (rc) {
314- splat_vprint(file, SPLAT_VNODE_TEST4_NAME,
315- "Failed vn_rdwr write of test file: %s (%d)\n",
316- SPLAT_VNODE_TEST_FILE_RW1, rc);
317- goto out2;
318- }
319-
320- VOP_CLOSE(vp, 0, 0, 0, 0, 0);
321-
322- rc = vn_rename(SPLAT_VNODE_TEST_FILE_RW1,SPLAT_VNODE_TEST_FILE_RW2,0);
323- if (rc) {
324- splat_vprint(file, SPLAT_VNODE_TEST4_NAME, "Failed vn_rename "
325- "%s -> %s (%d)\n",
326- SPLAT_VNODE_TEST_FILE_RW1,
327- SPLAT_VNODE_TEST_FILE_RW2, rc);
328- goto out;
329- }
330-
331- if ((rc = vn_open(SPLAT_VNODE_TEST_FILE_RW2, UIO_SYSSPACE,
332- FREAD | FEXCL, 0644, &vp, 0, 0))) {
333- splat_vprint(file, SPLAT_VNODE_TEST4_NAME,
334- "Failed to vn_open test file: %s (%d)\n",
335- SPLAT_VNODE_TEST_FILE_RW2, rc);
336- goto out;
337- }
338-
339- rc = vn_rdwr(UIO_READ, vp, buf2, strlen(buf1), 0,
340- UIO_SYSSPACE, 0, RLIM64_INFINITY, 0, NULL);
341- if (rc) {
342- splat_vprint(file, SPLAT_VNODE_TEST4_NAME,
343- "Failed vn_rdwr read of test file: %s (%d)\n",
344- SPLAT_VNODE_TEST_FILE_RW2, rc);
345- goto out2;
346- }
347-
348- if (strncmp(buf1, buf2, strlen(buf1))) {
349- rc = EINVAL;
350- splat_vprint(file, SPLAT_VNODE_TEST4_NAME,
351- "Failed strncmp data written does not match "
352- "data read\nWrote: %sRead: %s\n", buf1, buf2);
353- goto out2;
354- }
355-
356- rc = 0;
357- splat_vprint(file, SPLAT_VNODE_TEST4_NAME, "Wrote to %s: %s",
358- SPLAT_VNODE_TEST_FILE_RW1, buf1);
359- splat_vprint(file, SPLAT_VNODE_TEST4_NAME, "Read from %s: %s",
360- SPLAT_VNODE_TEST_FILE_RW2, buf2);
361- splat_vprint(file, SPLAT_VNODE_TEST4_NAME, "Successfully renamed "
362- "test file %s -> %s and verified data pattern\n",
363- SPLAT_VNODE_TEST_FILE_RW1, SPLAT_VNODE_TEST_FILE_RW2);
364-out2:
365- VOP_CLOSE(vp, 0, 0, 0, 0, 0);
366-out:
367- vn_remove(SPLAT_VNODE_TEST_FILE_RW1, UIO_SYSSPACE, RMFILE);
368- vn_remove(SPLAT_VNODE_TEST_FILE_RW2, UIO_SYSSPACE, RMFILE);
369-
370- return -rc;
371-} /* splat_vnode_test4() */
372-#endif
373-
374 static int
375 splat_vnode_test5(struct file *file, void *arg)
376 {
377@@ -387,7 +299,6 @@ splat_vnode_test6(struct file *file, void *arg)
378 "fsync'ed test file %s\n", SPLAT_VNODE_TEST_FILE_RW);
379 out:
380 VOP_CLOSE(vp, 0, 0, 0, 0, 0);
381- vn_remove(SPLAT_VNODE_TEST_FILE_RW, UIO_SYSSPACE, RMFILE);
382
383 return -rc;
384 } /* splat_vnode_test6() */
385@@ -415,10 +326,6 @@ splat_vnode_init(void)
386 SPLAT_VNODE_TEST2_ID, splat_vnode_test2);
387 splat_test_init(sub, SPLAT_VNODE_TEST3_NAME, SPLAT_VNODE_TEST3_DESC,
388 SPLAT_VNODE_TEST3_ID, splat_vnode_test3);
389-#if LINUX_VERSION_CODE <= KERNEL_VERSION(4,1,0)
390- splat_test_init(sub, SPLAT_VNODE_TEST4_NAME, SPLAT_VNODE_TEST4_DESC,
391- SPLAT_VNODE_TEST4_ID, splat_vnode_test4);
392-#endif
393 splat_test_init(sub, SPLAT_VNODE_TEST5_NAME, SPLAT_VNODE_TEST5_DESC,
394 SPLAT_VNODE_TEST5_ID, splat_vnode_test5);
395 splat_test_init(sub, SPLAT_VNODE_TEST6_NAME, SPLAT_VNODE_TEST6_DESC,
396@@ -434,9 +341,6 @@ splat_vnode_fini(splat_subsystem_t *sub)
397
398 splat_test_fini(sub, SPLAT_VNODE_TEST6_ID);
399 splat_test_fini(sub, SPLAT_VNODE_TEST5_ID);
400-#if LINUX_VERSION_CODE <= KERNEL_VERSION(4,1,0)
401- splat_test_fini(sub, SPLAT_VNODE_TEST4_ID);
402-#endif
403 splat_test_fini(sub, SPLAT_VNODE_TEST3_ID);
404 splat_test_fini(sub, SPLAT_VNODE_TEST2_ID);
405 splat_test_fini(sub, SPLAT_VNODE_TEST1_ID);
406diff --git a/config/spl-build.m4 b/config/spl-build.m4
407index 25013b5..926abd5 100644
408--- a/config/spl-build.m4
409+++ b/config/spl-build.m4
410@@ -27,8 +27,6 @@ AC_DEFUN([SPL_AC_CONFIG_KERNEL], [
411 SPL_AC_CONFIG_TRIM_UNUSED_KSYMS
412 SPL_AC_PDE_DATA
413 SPL_AC_SET_FS_PWD_WITH_CONST
414- SPL_AC_2ARGS_VFS_UNLINK
415- SPL_AC_4ARGS_VFS_RENAME
416 SPL_AC_2ARGS_VFS_FSYNC
417 SPL_AC_INODE_TRUNCATE_RANGE
418 SPL_AC_FS_STRUCT_SPINLOCK
419@@ -936,105 +934,6 @@ AC_DEFUN([SPL_AC_SET_FS_PWD_WITH_CONST],
420 EXTRA_KCFLAGS="$tmp_flags"
421 ])
422
423-dnl #
424-dnl # 3.13 API change
425-dnl # vfs_unlink() updated to take a third delegated_inode argument.
426-dnl #
427-AC_DEFUN([SPL_AC_2ARGS_VFS_UNLINK],
428- [AC_MSG_CHECKING([whether vfs_unlink() wants 2 args])
429- SPL_LINUX_TRY_COMPILE([
430- #include <linux/fs.h>
431- ],[
432- vfs_unlink((struct inode *) NULL, (struct dentry *) NULL);
433- ],[
434- AC_MSG_RESULT(yes)
435- AC_DEFINE(HAVE_2ARGS_VFS_UNLINK, 1,
436- [vfs_unlink() wants 2 args])
437- ],[
438- AC_MSG_RESULT(no)
439- dnl #
440- dnl # Linux 3.13 API change
441- dnl # Added delegated inode
442- dnl #
443- AC_MSG_CHECKING([whether vfs_unlink() wants 3 args])
444- SPL_LINUX_TRY_COMPILE([
445- #include <linux/fs.h>
446- ],[
447- vfs_unlink((struct inode *) NULL,
448- (struct dentry *) NULL,
449- (struct inode **) NULL);
450- ],[
451- AC_MSG_RESULT(yes)
452- AC_DEFINE(HAVE_3ARGS_VFS_UNLINK, 1,
453- [vfs_unlink() wants 3 args])
454- ],[
455- AC_MSG_ERROR(no)
456- ])
457-
458- ])
459-])
460-
461-dnl #
462-dnl # 3.13 and 3.15 API changes
463-dnl # Added delegated inode and flags argument.
464-dnl #
465-AC_DEFUN([SPL_AC_4ARGS_VFS_RENAME],
466- [AC_MSG_CHECKING([whether vfs_rename() wants 4 args])
467- SPL_LINUX_TRY_COMPILE([
468- #include <linux/fs.h>
469- ],[
470- vfs_rename((struct inode *) NULL, (struct dentry *) NULL,
471- (struct inode *) NULL, (struct dentry *) NULL);
472- ],[
473- AC_MSG_RESULT(yes)
474- AC_DEFINE(HAVE_4ARGS_VFS_RENAME, 1,
475- [vfs_rename() wants 4 args])
476- ],[
477- AC_MSG_RESULT(no)
478- dnl #
479- dnl # Linux 3.13 API change
480- dnl # Added delegated inode
481- dnl #
482- AC_MSG_CHECKING([whether vfs_rename() wants 5 args])
483- SPL_LINUX_TRY_COMPILE([
484- #include <linux/fs.h>
485- ],[
486- vfs_rename((struct inode *) NULL,
487- (struct dentry *) NULL,
488- (struct inode *) NULL,
489- (struct dentry *) NULL,
490- (struct inode **) NULL);
491- ],[
492- AC_MSG_RESULT(yes)
493- AC_DEFINE(HAVE_5ARGS_VFS_RENAME, 1,
494- [vfs_rename() wants 5 args])
495- ],[
496- AC_MSG_RESULT(no)
497- dnl #
498- dnl # Linux 3.15 API change
499- dnl # Added flags
500- dnl #
501- AC_MSG_CHECKING([whether vfs_rename() wants 6 args])
502- SPL_LINUX_TRY_COMPILE([
503- #include <linux/fs.h>
504- ],[
505- vfs_rename((struct inode *) NULL,
506- (struct dentry *) NULL,
507- (struct inode *) NULL,
508- (struct dentry *) NULL,
509- (struct inode **) NULL,
510- (unsigned int) 0);
511- ],[
512- AC_MSG_RESULT(yes)
513- AC_DEFINE(HAVE_6ARGS_VFS_RENAME, 1,
514- [vfs_rename() wants 6 args])
515- ],[
516- AC_MSG_ERROR(no)
517- ])
518- ])
519- ])
520-])
521-
522 dnl #
523 dnl # 2.6.36 API change,
524 dnl # The 'struct fs_struct->lock' was changed from a rwlock_t to
525--
5262.14.2
527