1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: Brian Behlendorf <behlendorf1@llnl.gov>
3 Date: Fri, 27 Oct 2017 15:49:14 -0700
4 Subject: [PATCH] Remove vn_rename and vn_remove
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
9 Both vn_rename and vn_remove have been historically problematic
10 to implement reliably. Rather than fixing them yet again they
13 Reviewed-by: Arkadiusz Bubala <arkadiusz.bubala@open-e.com>
14 Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
17 (cherry picked from commit 1cb26f06524bdddef24352a3d9ac90a402294f2b)
18 Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
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(-)
26 diff --git a/include/sys/vnode.h b/include/sys/vnode.h
27 index 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);
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,
39 diff --git a/module/spl/spl-vnode.c b/module/spl/spl-vnode.c
40 index 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)
45 EXPORT_SYMBOL(vn_seek);
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.
56 -spl_basename(const char *s, const char **str, int *len)
71 - while (i && s[i--] == '/');
81 - for (end = i; i; i--) {
93 -static struct dentry *
94 -spl_kern_path_locked(const char *name, struct path *path)
97 - struct dentry *dentry;
98 - const char *basename;
105 - spl_basename(name, &basename, &len);
107 - /* We do not accept "." or ".." */
108 - if (len <= 2 && basename[0] == '.')
109 - if (len == 1 || basename[1] == '.')
110 - return (ERR_PTR(-EACCES));
112 - rc = kern_path(name, LOOKUP_PARENT, &parent);
114 - return (ERR_PTR(rc));
116 - /* use I_MUTEX_PARENT because vfs_unlink needs it */
117 - spl_inode_lock_nested(parent.dentry->d_inode, I_MUTEX_PARENT);
119 - dentry = lookup_one_len(basename, parent.dentry, len);
120 - if (IS_ERR(dentry)) {
121 - spl_inode_unlock(parent.dentry->d_inode);
130 -/* Based on do_unlinkat() from linux/fs/namei.c */
132 -vn_remove(const char *path, uio_seg_t seg, int flags)
134 - struct dentry *dentry;
135 - struct path parent;
136 - struct inode *inode = NULL;
139 - ASSERT(seg == UIO_SYSSPACE);
140 - ASSERT(flags == RMFILE);
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]) {
150 - inode = dentry->d_inode;
152 - atomic_inc(&inode->i_count);
158 -#ifdef HAVE_2ARGS_VFS_UNLINK
159 - rc = vfs_unlink(parent.dentry->d_inode, dentry);
161 - rc = vfs_unlink(parent.dentry->d_inode, dentry, NULL);
162 -#endif /* HAVE_2ARGS_VFS_UNLINK */
169 - spl_inode_unlock(parent.dentry->d_inode);
171 - iput(inode); /* truncate the inode here */
177 - rc = !dentry->d_inode ? -ENOENT :
178 - S_ISDIR(dentry->d_inode->i_mode) ? -EISDIR : -ENOTDIR;
181 -EXPORT_SYMBOL(vn_remove);
183 -/* Based on do_rename() from linux/fs/namei.c */
185 -vn_rename(const char *oldname, const char *newname, int x1)
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;
193 - old_dentry = spl_kern_path_locked(oldname, &old_parent);
194 - if (IS_ERR(old_dentry)) {
195 - rc = PTR_ERR(old_dentry);
199 - spl_inode_unlock(old_parent.dentry->d_inode);
201 - new_dentry = spl_kern_path_locked(newname, &new_parent);
202 - if (IS_ERR(new_dentry)) {
203 - rc = PTR_ERR(new_dentry);
207 - spl_inode_unlock(new_parent.dentry->d_inode);
210 - if (old_parent.mnt != new_parent.mnt)
213 - old_dir = old_parent.dentry;
214 - new_dir = new_parent.dentry;
215 - trap = lock_rename(new_dir, old_dir);
217 - /* source should not be ancestor of target */
219 - if (old_dentry == trap)
222 - /* target should not be an ancestor of source */
224 - if (new_dentry == trap)
227 - /* source must exist */
229 - if (!old_dentry->d_inode)
232 - /* unless the source is a directory trailing slashes give -ENOTDIR */
233 - if (!S_ISDIR(old_dentry->d_inode->i_mode)) {
235 - if (old_dentry->d_name.name[old_dentry->d_name.len])
237 - if (new_dentry->d_name.name[new_dentry->d_name.len])
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);
248 - rc = vfs_rename(old_dir->d_inode, old_dentry,
249 - new_dir->d_inode, new_dentry, NULL, 0);
252 - unlock_rename(new_dir, old_dir);
255 - path_put(&new_parent);
258 - path_put(&old_parent);
262 -EXPORT_SYMBOL(vn_rename);
265 vn_getattr(vnode_t *vp, vattr_t *vap, int flags, void *x3, void *x4)
267 diff --git a/module/splat/splat-vnode.c b/module/splat/splat-vnode.c
268 index ad69cf6..9160003 100644
269 --- a/module/splat/splat-vnode.c
270 +++ b/module/splat/splat-vnode.c
272 #define SPLAT_VNODE_TEST3_NAME "vn_rdwr"
273 #define SPLAT_VNODE_TEST3_DESC "Vn_rdwrt Test"
275 -#define SPLAT_VNODE_TEST4_ID 0x0904
276 -#define SPLAT_VNODE_TEST4_NAME "vn_rename"
277 -#define SPLAT_VNODE_TEST4_DESC "Vn_rename Test"
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)
285 VOP_CLOSE(vp, 0, 0, 0, 0, 0);
286 - vn_remove(SPLAT_VNODE_TEST_FILE_RW, UIO_SYSSPACE, RMFILE);
289 } /* splat_vnode_test3() */
291 -#if LINUX_VERSION_CODE <= KERNEL_VERSION(4,1,0)
293 -splat_vnode_test4(struct file *file, void *arg)
296 - char buf1[32] = "SPL VNode Interface Test File\n";
297 - char buf2[32] = "";
300 - if ((rc = splat_vnode_unlink_all(file, arg, SPLAT_VNODE_TEST4_NAME)))
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);
311 - rc = vn_rdwr(UIO_WRITE, vp, buf1, strlen(buf1), 0,
312 - UIO_SYSSPACE, 0, RLIM64_INFINITY, 0, NULL);
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);
320 - VOP_CLOSE(vp, 0, 0, 0, 0, 0);
322 - rc = vn_rename(SPLAT_VNODE_TEST_FILE_RW1,SPLAT_VNODE_TEST_FILE_RW2,0);
324 - splat_vprint(file, SPLAT_VNODE_TEST4_NAME, "Failed vn_rename "
326 - SPLAT_VNODE_TEST_FILE_RW1,
327 - SPLAT_VNODE_TEST_FILE_RW2, rc);
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);
339 - rc = vn_rdwr(UIO_READ, vp, buf2, strlen(buf1), 0,
340 - UIO_SYSSPACE, 0, RLIM64_INFINITY, 0, NULL);
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);
348 - if (strncmp(buf1, buf2, strlen(buf1))) {
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);
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);
365 - VOP_CLOSE(vp, 0, 0, 0, 0, 0);
367 - vn_remove(SPLAT_VNODE_TEST_FILE_RW1, UIO_SYSSPACE, RMFILE);
368 - vn_remove(SPLAT_VNODE_TEST_FILE_RW2, UIO_SYSSPACE, RMFILE);
371 -} /* splat_vnode_test4() */
375 splat_vnode_test5(struct file *file, void *arg)
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);
380 VOP_CLOSE(vp, 0, 0, 0, 0, 0);
381 - vn_remove(SPLAT_VNODE_TEST_FILE_RW, UIO_SYSSPACE, RMFILE);
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);
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)
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);
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);
406 diff --git a/config/spl-build.m4 b/config/spl-build.m4
407 index 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
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"
424 -dnl # 3.13 API change
425 -dnl # vfs_unlink() updated to take a third delegated_inode argument.
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>
432 - vfs_unlink((struct inode *) NULL, (struct dentry *) NULL);
435 - AC_DEFINE(HAVE_2ARGS_VFS_UNLINK, 1,
436 - [vfs_unlink() wants 2 args])
440 - dnl # Linux 3.13 API change
441 - dnl # Added delegated inode
443 - AC_MSG_CHECKING([whether vfs_unlink() wants 3 args])
444 - SPL_LINUX_TRY_COMPILE([
445 - #include <linux/fs.h>
447 - vfs_unlink((struct inode *) NULL,
448 - (struct dentry *) NULL,
449 - (struct inode **) NULL);
452 - AC_DEFINE(HAVE_3ARGS_VFS_UNLINK, 1,
453 - [vfs_unlink() wants 3 args])
462 -dnl # 3.13 and 3.15 API changes
463 -dnl # Added delegated inode and flags argument.
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>
470 - vfs_rename((struct inode *) NULL, (struct dentry *) NULL,
471 - (struct inode *) NULL, (struct dentry *) NULL);
474 - AC_DEFINE(HAVE_4ARGS_VFS_RENAME, 1,
475 - [vfs_rename() wants 4 args])
479 - dnl # Linux 3.13 API change
480 - dnl # Added delegated inode
482 - AC_MSG_CHECKING([whether vfs_rename() wants 5 args])
483 - SPL_LINUX_TRY_COMPILE([
484 - #include <linux/fs.h>
486 - vfs_rename((struct inode *) NULL,
487 - (struct dentry *) NULL,
488 - (struct inode *) NULL,
489 - (struct dentry *) NULL,
490 - (struct inode **) NULL);
493 - AC_DEFINE(HAVE_5ARGS_VFS_RENAME, 1,
494 - [vfs_rename() wants 5 args])
498 - dnl # Linux 3.15 API change
501 - AC_MSG_CHECKING([whether vfs_rename() wants 6 args])
502 - SPL_LINUX_TRY_COMPILE([
503 - #include <linux/fs.h>
505 - vfs_rename((struct inode *) NULL,
506 - (struct dentry *) NULL,
507 - (struct inode *) NULL,
508 - (struct dentry *) NULL,
509 - (struct inode **) NULL,
513 - AC_DEFINE(HAVE_6ARGS_VFS_RENAME, 1,
514 - [vfs_rename() wants 6 args])
523 dnl # 2.6.36 API change,
524 dnl # The 'struct fs_struct->lock' was changed from a rwlock_t to