Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

switch ->get_link() to delayed_call, kill ->put_link()

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

Al Viro fceef393 cd3417c8

+206 -218
-2
Documentation/filesystems/Locking
··· 51 51 struct inode *, struct dentry *, unsigned int); 52 52 int (*readlink) (struct dentry *, char __user *,int); 53 53 const char *(*get_link) (struct dentry *, struct inode *, void **); 54 - void (*put_link) (struct inode *, void *); 55 54 void (*truncate) (struct inode *); 56 55 int (*permission) (struct inode *, int, unsigned int); 57 56 int (*get_acl)(struct inode *, int); ··· 83 84 rename2: yes (all) (see below) 84 85 readlink: no 85 86 get_link: no 86 - put_link: no 87 87 setattr: yes 88 88 permission: no (may not block if called in rcu-walk mode) 89 89 get_acl: no
+6
Documentation/filesystems/porting
··· 515 515 * ->get_link() gets inode as a separate argument 516 516 * ->get_link() may be called in RCU mode - in that case NULL 517 517 dentry is passed 518 + -- 519 + [mandatory] 520 + ->get_link() gets struct delayed_call *done now, and should do 521 + set_delayed_call() where it used to set *cookie. 522 + ->put_link() is gone - just give the destructor to set_delayed_call() 523 + in ->get_link().
+10 -11
Documentation/filesystems/vfs.txt
··· 350 350 int (*rename2) (struct inode *, struct dentry *, 351 351 struct inode *, struct dentry *, unsigned int); 352 352 int (*readlink) (struct dentry *, char __user *,int); 353 - const char *(*follow_link) (struct dentry *, void **); 354 - void (*put_link) (struct inode *, void *); 353 + const char *(*get_link) (struct dentry *, struct inode *, 354 + struct delayed_call *); 355 355 int (*permission) (struct inode *, int); 356 356 int (*get_acl)(struct inode *, int); 357 357 int (*setattr) (struct dentry *, struct iattr *); ··· 434 434 readlink: called by the readlink(2) system call. Only required if 435 435 you want to support reading symbolic links 436 436 437 - follow_link: called by the VFS to follow a symbolic link to the 437 + get_link: called by the VFS to follow a symbolic link to the 438 438 inode it points to. Only required if you want to support 439 439 symbolic links. This method returns the symlink body 440 440 to traverse (and possibly resets the current position with 441 441 nd_jump_link()). If the body won't go away until the inode 442 442 is gone, nothing else is needed; if it needs to be otherwise 443 - pinned, the data needed to release whatever we'd grabbed 444 - is to be stored in void * variable passed by address to 445 - follow_link() instance. 446 - 447 - put_link: called by the VFS to release resources allocated by 448 - follow_link(). The cookie stored by follow_link() is passed 449 - to this method as the last parameter; only called when 450 - cookie isn't NULL. 443 + pinned, arrange for its release by having get_link(..., ..., done) 444 + do set_delayed_call(done, destructor, argument). 445 + In that case destructor(argument) will be called once VFS is 446 + done with the body you've returned. 447 + May be called in RCU mode; that is indicated by NULL dentry 448 + argument. If request can't be handled without leaving RCU mode, 449 + have it return ERR_PTR(-ECHILD). 451 450 452 451 permission: called by the VFS to check for access rights on a POSIX-like 453 452 filesystem.
+9 -9
drivers/staging/lustre/lustre/llite/symlink.c
··· 118 118 return rc; 119 119 } 120 120 121 + static void ll_put_link(void *p) 122 + { 123 + ptlrpc_req_finished(p); 124 + } 125 + 121 126 static const char *ll_get_link(struct dentry *dentry, 122 - struct inode *inode, void **cookie) 127 + struct inode *inode, 128 + struct delayed_call *done) 123 129 { 124 130 struct ptlrpc_request *request = NULL; 125 131 int rc; ··· 143 137 } 144 138 145 139 /* symname may contain a pointer to the request message buffer, 146 - * we delay request releasing until ll_put_link then. 140 + * we delay request releasing then. 147 141 */ 148 - *cookie = request; 142 + set_delayed_call(done, ll_put_link, request); 149 143 return symname; 150 - } 151 - 152 - static void ll_put_link(struct inode *unused, void *cookie) 153 - { 154 - ptlrpc_req_finished(cookie); 155 144 } 156 145 157 146 struct inode_operations ll_fast_symlink_inode_operations = { 158 147 .readlink = generic_readlink, 159 148 .setattr = ll_setattr, 160 149 .get_link = ll_get_link, 161 - .put_link = ll_put_link, 162 150 .getattr = ll_getattr, 163 151 .permission = ll_inode_permission, 164 152 .setxattr = ll_setxattr,
+5 -4
fs/9p/vfs_inode.c
··· 1226 1226 * v9fs_vfs_get_link - follow a symlink path 1227 1227 * @dentry: dentry for symlink 1228 1228 * @inode: inode for symlink 1229 - * @cookie: place to pass the data to put_link() 1229 + * @done: delayed call for when we are done with the return value 1230 1230 */ 1231 1231 1232 1232 static const char *v9fs_vfs_get_link(struct dentry *dentry, 1233 - struct inode *inode, void **cookie) 1233 + struct inode *inode, 1234 + struct delayed_call *done) 1234 1235 { 1235 1236 struct v9fs_session_info *v9ses; 1236 1237 struct p9_fid *fid; ··· 1267 1266 1268 1267 p9stat_free(st); 1269 1268 kfree(st); 1270 - return *cookie = res; 1269 + set_delayed_call(done, kfree_link, res); 1270 + return res; 1271 1271 } 1272 1272 1273 1273 /** ··· 1462 1460 static const struct inode_operations v9fs_symlink_inode_operations = { 1463 1461 .readlink = generic_readlink, 1464 1462 .get_link = v9fs_vfs_get_link, 1465 - .put_link = kfree_put_link, 1466 1463 .getattr = v9fs_vfs_getattr, 1467 1464 .setattr = v9fs_vfs_setattr, 1468 1465 };
+5 -4
fs/9p/vfs_inode_dotl.c
··· 902 902 * v9fs_vfs_get_link_dotl - follow a symlink path 903 903 * @dentry: dentry for symlink 904 904 * @inode: inode for symlink 905 - * @cookie: place to pass the data to put_link() 905 + * @done: destructor for return value 906 906 */ 907 907 908 908 static const char * 909 909 v9fs_vfs_get_link_dotl(struct dentry *dentry, 910 - struct inode *inode, void **cookie) 910 + struct inode *inode, 911 + struct delayed_call *done) 911 912 { 912 913 struct p9_fid *fid; 913 914 char *target; ··· 925 924 retval = p9_client_readlink(fid, &target); 926 925 if (retval) 927 926 return ERR_PTR(retval); 928 - return *cookie = target; 927 + set_delayed_call(done, kfree_link, target); 928 + return target; 929 929 } 930 930 931 931 int v9fs_refresh_inode_dotl(struct p9_fid *fid, struct inode *inode) ··· 993 991 const struct inode_operations v9fs_symlink_inode_operations_dotl = { 994 992 .readlink = generic_readlink, 995 993 .get_link = v9fs_vfs_get_link_dotl, 996 - .put_link = kfree_put_link, 997 994 .getattr = v9fs_vfs_getattr_dotl, 998 995 .setattr = v9fs_vfs_setattr_dotl, 999 996 .setxattr = generic_setxattr,
-1
fs/affs/symlink.c
··· 72 72 const struct inode_operations affs_symlink_inode_operations = { 73 73 .readlink = generic_readlink, 74 74 .get_link = page_get_link, 75 - .put_link = page_put_link, 76 75 .setattr = affs_notify_change, 77 76 };
+2 -1
fs/autofs4/symlink.c
··· 13 13 #include "autofs_i.h" 14 14 15 15 static const char *autofs4_get_link(struct dentry *dentry, 16 - struct inode *inode, void **cookie) 16 + struct inode *inode, 17 + struct delayed_call *done) 17 18 { 18 19 struct autofs_sb_info *sbi; 19 20 struct autofs_info *ino;
-1
fs/btrfs/inode.c
··· 10097 10097 static const struct inode_operations btrfs_symlink_inode_operations = { 10098 10098 .readlink = generic_readlink, 10099 10099 .get_link = page_get_link, 10100 - .put_link = page_put_link, 10101 10100 .getattr = btrfs_getattr, 10102 10101 .setattr = btrfs_setattr, 10103 10102 .permission = btrfs_permission,
-1
fs/cifs/cifsfs.c
··· 901 901 const struct inode_operations cifs_symlink_inode_ops = { 902 902 .readlink = generic_readlink, 903 903 .get_link = cifs_get_link, 904 - .put_link = kfree_put_link, 905 904 .permission = cifs_permission, 906 905 /* BB add the following two eventually */ 907 906 /* revalidate: cifs_revalidate,
+2 -1
fs/cifs/cifsfs.h
··· 120 120 #endif 121 121 122 122 /* Functions related to symlinks */ 123 - extern const char *cifs_get_link(struct dentry *, struct inode *, void **); 123 + extern const char *cifs_get_link(struct dentry *, struct inode *, 124 + struct delayed_call *); 124 125 extern int cifs_symlink(struct inode *inode, struct dentry *direntry, 125 126 const char *symname); 126 127 extern int cifs_removexattr(struct dentry *, const char *);
+4 -2
fs/cifs/link.c
··· 627 627 } 628 628 629 629 const char * 630 - cifs_get_link(struct dentry *direntry, struct inode *inode, void **cookie) 630 + cifs_get_link(struct dentry *direntry, struct inode *inode, 631 + struct delayed_call *done) 631 632 { 632 633 int rc = -ENOMEM; 633 634 unsigned int xid; ··· 681 680 kfree(target_path); 682 681 return ERR_PTR(rc); 683 682 } 684 - return *cookie = target_path; 683 + set_delayed_call(done, kfree_link, target_path); 684 + return target_path; 685 685 } 686 686 687 687 int
-1
fs/coda/cnode.c
··· 19 19 static const struct inode_operations coda_symlink_inode_operations = { 20 20 .readlink = generic_readlink, 21 21 .get_link = page_get_link, 22 - .put_link = page_put_link, 23 22 .setattr = coda_setattr, 24 23 }; 25 24
+9 -8
fs/configfs/symlink.c
··· 280 280 } 281 281 282 282 static const char *configfs_get_link(struct dentry *dentry, 283 - struct inode *inode, void **cookie) 283 + struct inode *inode, 284 + struct delayed_call *done) 284 285 { 285 - char *page; 286 + char *body; 286 287 int error; 287 288 288 289 if (!dentry) 289 290 return ERR_PTR(-ECHILD); 290 291 291 - page = kzalloc(PAGE_SIZE, GFP_KERNEL); 292 - if (!page) 292 + body = kzalloc(PAGE_SIZE, GFP_KERNEL); 293 + if (!body) 293 294 return ERR_PTR(-ENOMEM); 294 295 295 - error = configfs_getlink(dentry, page); 296 + error = configfs_getlink(dentry, body); 296 297 if (!error) { 297 - return *cookie = page; 298 + set_delayed_call(done, kfree_link, body); 299 + return body; 298 300 } 299 301 300 - kfree(page); 302 + kfree(body); 301 303 return ERR_PTR(error); 302 304 } 303 305 304 306 const struct inode_operations configfs_symlink_inode_operations = { 305 307 .get_link = configfs_get_link, 306 308 .readlink = generic_readlink, 307 - .put_link = kfree_put_link, 308 309 .setattr = configfs_setattr, 309 310 }; 310 311
+4 -3
fs/ecryptfs/inode.c
··· 675 675 } 676 676 677 677 static const char *ecryptfs_get_link(struct dentry *dentry, 678 - struct inode *inode, void **cookie) 678 + struct inode *inode, 679 + struct delayed_call *done) 679 680 { 680 681 size_t len; 681 682 char *buf; ··· 690 689 fsstack_copy_attr_atime(d_inode(dentry), 691 690 d_inode(ecryptfs_dentry_to_lower(dentry))); 692 691 buf[len] = '\0'; 693 - return *cookie = buf; 692 + set_delayed_call(done, kfree_link, buf); 693 + return buf; 694 694 } 695 695 696 696 /** ··· 1104 1102 const struct inode_operations ecryptfs_symlink_iops = { 1105 1103 .readlink = generic_readlink, 1106 1104 .get_link = ecryptfs_get_link, 1107 - .put_link = kfree_put_link, 1108 1105 .permission = ecryptfs_permission, 1109 1106 .setattr = ecryptfs_setattr, 1110 1107 .getattr = ecryptfs_getattr_link,
-1
fs/ext2/symlink.c
··· 23 23 const struct inode_operations ext2_symlink_inode_operations = { 24 24 .readlink = generic_readlink, 25 25 .get_link = page_get_link, 26 - .put_link = page_put_link, 27 26 .setattr = ext2_setattr, 28 27 #ifdef CONFIG_EXT2_FS_XATTR 29 28 .setxattr = generic_setxattr,
+4 -4
fs/ext4/symlink.c
··· 24 24 25 25 #ifdef CONFIG_EXT4_FS_ENCRYPTION 26 26 static const char *ext4_encrypted_get_link(struct dentry *dentry, 27 - struct inode *inode, void **cookie) 27 + struct inode *inode, 28 + struct delayed_call *done) 28 29 { 29 30 struct page *cpage = NULL; 30 31 char *caddr, *paddr = NULL; ··· 81 80 paddr[res] = '\0'; 82 81 if (cpage) 83 82 page_cache_release(cpage); 84 - return *cookie = paddr; 83 + set_delayed_call(done, kfree_link, paddr); 84 + return paddr; 85 85 errout: 86 86 if (cpage) 87 87 page_cache_release(cpage); ··· 93 91 const struct inode_operations ext4_encrypted_symlink_inode_operations = { 94 92 .readlink = generic_readlink, 95 93 .get_link = ext4_encrypted_get_link, 96 - .put_link = kfree_put_link, 97 94 .setattr = ext4_setattr, 98 95 .setxattr = generic_setxattr, 99 96 .getxattr = generic_getxattr, ··· 104 103 const struct inode_operations ext4_symlink_inode_operations = { 105 104 .readlink = generic_readlink, 106 105 .get_link = page_get_link, 107 - .put_link = page_put_link, 108 106 .setattr = ext4_setattr, 109 107 .setxattr = generic_setxattr, 110 108 .getxattr = generic_getxattr,
+9 -7
fs/f2fs/namei.c
··· 316 316 } 317 317 318 318 static const char *f2fs_get_link(struct dentry *dentry, 319 - struct inode *inode, void **cookie) 319 + struct inode *inode, 320 + struct delayed_call *done) 320 321 { 321 - const char *link = page_get_link(dentry, inode, cookie); 322 + const char *link = page_get_link(dentry, inode, done); 322 323 if (!IS_ERR(link) && !*link) { 323 324 /* this is broken symlink case */ 324 - page_put_link(NULL, *cookie); 325 + do_delayed_call(done); 326 + clear_delayed_call(done); 325 327 link = ERR_PTR(-ENOENT); 326 328 } 327 329 return link; ··· 928 926 929 927 #ifdef CONFIG_F2FS_FS_ENCRYPTION 930 928 static const char *f2fs_encrypted_get_link(struct dentry *dentry, 931 - struct inode *inode, void **cookie) 929 + struct inode *inode, 930 + struct delayed_call *done) 932 931 { 933 932 struct page *cpage = NULL; 934 933 char *caddr, *paddr = NULL; ··· 991 988 paddr[res] = '\0'; 992 989 993 990 page_cache_release(cpage); 994 - return *cookie = paddr; 991 + set_delayed_call(done, kfree_link, paddr); 992 + return paddr; 995 993 errout: 996 994 kfree(cstr.name); 997 995 f2fs_fname_crypto_free_buffer(&pstr); ··· 1003 999 const struct inode_operations f2fs_encrypted_symlink_inode_operations = { 1004 1000 .readlink = generic_readlink, 1005 1001 .get_link = f2fs_encrypted_get_link, 1006 - .put_link = kfree_put_link, 1007 1002 .getattr = f2fs_getattr, 1008 1003 .setattr = f2fs_setattr, 1009 1004 .setxattr = generic_setxattr, ··· 1038 1035 const struct inode_operations f2fs_symlink_inode_operations = { 1039 1036 .readlink = generic_readlink, 1040 1037 .get_link = f2fs_get_link, 1041 - .put_link = page_put_link, 1042 1038 .getattr = f2fs_getattr, 1043 1039 .setattr = f2fs_setattr, 1044 1040 #ifdef CONFIG_F2FS_FS_XATTR
+3 -3
fs/fuse/dir.c
··· 1366 1366 } 1367 1367 1368 1368 static const char *fuse_get_link(struct dentry *dentry, 1369 - struct inode *inode, void **cookie) 1369 + struct inode *inode, 1370 + struct delayed_call *done) 1370 1371 { 1371 1372 struct fuse_conn *fc = get_fuse_conn(inode); 1372 1373 FUSE_ARGS(args); ··· 1393 1392 link = ERR_PTR(ret); 1394 1393 } else { 1395 1394 link[ret] = '\0'; 1396 - *cookie = link; 1395 + set_delayed_call(done, kfree_link, link); 1397 1396 } 1398 1397 fuse_invalidate_atime(inode); 1399 1398 return link; ··· 1914 1913 static const struct inode_operations fuse_symlink_inode_operations = { 1915 1914 .setattr = fuse_setattr, 1916 1915 .get_link = fuse_get_link, 1917 - .put_link = kfree_put_link, 1918 1916 .readlink = generic_readlink, 1919 1917 .getattr = fuse_getattr, 1920 1918 .setxattr = fuse_setxattr,
+4 -4
fs/gfs2/inode.c
··· 1715 1715 * gfs2_get_link - Follow a symbolic link 1716 1716 * @dentry: The dentry of the link 1717 1717 * @inode: The inode of the link 1718 - * @cookie: place to store the information for ->put_link() 1718 + * @done: destructor for return value 1719 1719 * 1720 1720 * This can handle symlinks of any size. 1721 1721 * ··· 1723 1723 */ 1724 1724 1725 1725 static const char *gfs2_get_link(struct dentry *dentry, 1726 - struct inode *inode, void **cookie) 1726 + struct inode *inode, 1727 + struct delayed_call *done) 1727 1728 { 1728 1729 struct gfs2_inode *ip = GFS2_I(inode); 1729 1730 struct gfs2_holder i_gh; ··· 1765 1764 out: 1766 1765 gfs2_glock_dq_uninit(&i_gh); 1767 1766 if (!IS_ERR(buf)) 1768 - *cookie = buf; 1767 + set_delayed_call(done, kfree_link, buf); 1769 1768 return buf; 1770 1769 } 1771 1770 ··· 2139 2138 const struct inode_operations gfs2_symlink_iops = { 2140 2139 .readlink = generic_readlink, 2141 2140 .get_link = gfs2_get_link, 2142 - .put_link = kfree_put_link, 2143 2141 .permission = gfs2_permission, 2144 2142 .setattr = gfs2_setattr, 2145 2143 .getattr = gfs2_getattr,
+6 -10
fs/hostfs/hostfs_kern.c
··· 893 893 }; 894 894 895 895 static const char *hostfs_get_link(struct dentry *dentry, 896 - struct inode *inode, void **cookie) 896 + struct inode *inode, 897 + struct delayed_call *done) 897 898 { 898 899 char *link; 899 900 if (!dentry) 900 901 return ERR_PTR(-ECHILD); 901 - link = __getname(); 902 + link = kmalloc(PATH_MAX, GFP_KERNEL); 902 903 if (link) { 903 904 char *path = dentry_name(dentry); 904 905 int err = -ENOMEM; ··· 910 909 __putname(path); 911 910 } 912 911 if (err < 0) { 913 - __putname(link); 912 + kfree(link); 914 913 return ERR_PTR(err); 915 914 } 916 915 } else { 917 916 return ERR_PTR(-ENOMEM); 918 917 } 919 918 920 - return *cookie = link; 921 - } 922 - 923 - static void hostfs_put_link(struct inode *unused, void *cookie) 924 - { 925 - __putname(cookie); 919 + set_delayed_call(done, kfree_link, link); 920 + return link; 926 921 } 927 922 928 923 static const struct inode_operations hostfs_link_iops = { 929 924 .readlink = generic_readlink, 930 925 .get_link = hostfs_get_link, 931 - .put_link = hostfs_put_link, 932 926 }; 933 927 934 928 static int hostfs_fill_sb_common(struct super_block *sb, void *d, int silent)
-1
fs/jfs/symlink.c
··· 34 34 const struct inode_operations jfs_symlink_inode_operations = { 35 35 .readlink = generic_readlink, 36 36 .get_link = page_get_link, 37 - .put_link = page_put_link, 38 37 .setattr = jfs_setattr, 39 38 .setxattr = jfs_setxattr, 40 39 .getxattr = jfs_getxattr,
+10 -9
fs/kernfs/symlink.c
··· 113 113 } 114 114 115 115 static const char *kernfs_iop_get_link(struct dentry *dentry, 116 - struct inode *inode, void **cookie) 116 + struct inode *inode, 117 + struct delayed_call *done) 117 118 { 118 - int error = -ENOMEM; 119 - char *page; 119 + char *body; 120 + int error; 120 121 121 122 if (!dentry) 122 123 return ERR_PTR(-ECHILD); 123 - page = kzalloc(PAGE_SIZE, GFP_KERNEL); 124 - if (!page) 124 + body = kzalloc(PAGE_SIZE, GFP_KERNEL); 125 + if (!body) 125 126 return ERR_PTR(-ENOMEM); 126 - error = kernfs_getlink(dentry, page); 127 + error = kernfs_getlink(dentry, body); 127 128 if (unlikely(error < 0)) { 128 - kfree(page); 129 + kfree(body); 129 130 return ERR_PTR(error); 130 131 } 131 - return *cookie = page; 132 + set_delayed_call(done, kfree_link, body); 133 + return body; 132 134 } 133 135 134 136 const struct inode_operations kernfs_symlink_iops = { ··· 140 138 .listxattr = kernfs_iop_listxattr, 141 139 .readlink = generic_readlink, 142 140 .get_link = kernfs_iop_get_link, 143 - .put_link = kfree_put_link, 144 141 .setattr = kernfs_iop_setattr, 145 142 .getattr = kernfs_iop_getattr, 146 143 .permission = kernfs_iop_permission,
+5 -4
fs/libfs.c
··· 1019 1019 } 1020 1020 EXPORT_SYMBOL(noop_fsync); 1021 1021 1022 - void kfree_put_link(struct inode *unused, void *cookie) 1022 + /* Because kfree isn't assignment-compatible with void(void*) ;-/ */ 1023 + void kfree_link(void *p) 1023 1024 { 1024 - kfree(cookie); 1025 + kfree(p); 1025 1026 } 1026 - EXPORT_SYMBOL(kfree_put_link); 1027 + EXPORT_SYMBOL(kfree_link); 1027 1028 1028 1029 /* 1029 1030 * nop .set_page_dirty method so that people can use .page_mkwrite on ··· 1088 1087 EXPORT_SYMBOL(simple_nosetlease); 1089 1088 1090 1089 const char *simple_get_link(struct dentry *dentry, struct inode *inode, 1091 - void **cookie) 1090 + struct delayed_call *done) 1092 1091 { 1093 1092 return inode->i_link; 1094 1093 }
-1
fs/minix/inode.c
··· 436 436 static const struct inode_operations minix_symlink_inode_operations = { 437 437 .readlink = generic_readlink, 438 438 .get_link = page_get_link, 439 - .put_link = page_put_link, 440 439 .getattr = minix_getattr, 441 440 }; 442 441
+26 -37
fs/namei.c
··· 505 505 int total_link_count; 506 506 struct saved { 507 507 struct path link; 508 - void *cookie; 508 + struct delayed_call done; 509 509 const char *name; 510 - struct inode *inode; 511 510 unsigned seq; 512 511 } *stack, internal[EMBEDDED_LEVELS]; 513 512 struct filename *name; 514 513 struct nameidata *saved; 514 + struct inode *link_inode; 515 515 unsigned root_seq; 516 516 int dfd; 517 517 }; ··· 592 592 int i = nd->depth; 593 593 while (i--) { 594 594 struct saved *last = nd->stack + i; 595 - struct inode *inode = last->inode; 596 - if (last->cookie && inode->i_op->put_link) { 597 - inode->i_op->put_link(inode, last->cookie); 598 - last->cookie = NULL; 599 - } 595 + do_delayed_call(&last->done); 596 + clear_delayed_call(&last->done); 600 597 } 601 598 } 602 599 ··· 855 858 static inline void put_link(struct nameidata *nd) 856 859 { 857 860 struct saved *last = nd->stack + --nd->depth; 858 - struct inode *inode = last->inode; 859 - if (last->cookie && inode->i_op->put_link) 860 - inode->i_op->put_link(inode, last->cookie); 861 + do_delayed_call(&last->done); 861 862 if (!(nd->flags & LOOKUP_RCU)) 862 863 path_put(&last->link); 863 864 } ··· 887 892 return 0; 888 893 889 894 /* Allowed if owner and follower match. */ 890 - inode = nd->stack[0].inode; 895 + inode = nd->link_inode; 891 896 if (uid_eq(current_cred()->fsuid, inode->i_uid)) 892 897 return 0; 893 898 ··· 978 983 { 979 984 struct saved *last = nd->stack + nd->depth - 1; 980 985 struct dentry *dentry = last->link.dentry; 981 - struct inode *inode = last->inode; 986 + struct inode *inode = nd->link_inode; 982 987 int error; 983 988 const char *res; 984 989 ··· 999 1004 nd->last_type = LAST_BIND; 1000 1005 res = inode->i_link; 1001 1006 if (!res) { 1007 + const char * (*get)(struct dentry *, struct inode *, 1008 + struct delayed_call *); 1009 + get = inode->i_op->get_link; 1002 1010 if (nd->flags & LOOKUP_RCU) { 1003 - res = inode->i_op->get_link(NULL, inode, 1004 - &last->cookie); 1011 + res = get(NULL, inode, &last->done); 1005 1012 if (res == ERR_PTR(-ECHILD)) { 1006 1013 if (unlikely(unlazy_walk(nd, NULL, 0))) 1007 1014 return ERR_PTR(-ECHILD); 1008 - res = inode->i_op->get_link(dentry, inode, 1009 - &last->cookie); 1015 + res = get(dentry, inode, &last->done); 1010 1016 } 1011 1017 } else { 1012 - res = inode->i_op->get_link(dentry, inode, 1013 - &last->cookie); 1018 + res = get(dentry, inode, &last->done); 1014 1019 } 1015 - if (IS_ERR_OR_NULL(res)) { 1016 - last->cookie = NULL; 1020 + if (IS_ERR_OR_NULL(res)) 1017 1021 return res; 1018 - } 1019 1022 } 1020 1023 if (*res == '/') { 1021 1024 if (nd->flags & LOOKUP_RCU) { ··· 1692 1699 1693 1700 last = nd->stack + nd->depth++; 1694 1701 last->link = *link; 1695 - last->cookie = NULL; 1696 - last->inode = inode; 1702 + clear_delayed_call(&last->done); 1703 + nd->link_inode = inode; 1697 1704 last->seq = seq; 1698 1705 return 1; 1699 1706 } ··· 4501 4508 */ 4502 4509 int generic_readlink(struct dentry *dentry, char __user *buffer, int buflen) 4503 4510 { 4504 - void *cookie; 4511 + DEFINE_DELAYED_CALL(done); 4505 4512 struct inode *inode = d_inode(dentry); 4506 4513 const char *link = inode->i_link; 4507 4514 int res; 4508 4515 4509 4516 if (!link) { 4510 - link = inode->i_op->get_link(dentry, inode, &cookie); 4517 + link = inode->i_op->get_link(dentry, inode, &done); 4511 4518 if (IS_ERR(link)) 4512 4519 return PTR_ERR(link); 4513 4520 } 4514 4521 res = readlink_copy(buffer, buflen, link); 4515 - if (inode->i_op->put_link) 4516 - inode->i_op->put_link(inode, cookie); 4522 + do_delayed_call(&done); 4517 4523 return res; 4518 4524 } 4519 4525 EXPORT_SYMBOL(generic_readlink); 4520 4526 4521 4527 /* get the link contents into pagecache */ 4522 4528 const char *page_get_link(struct dentry *dentry, struct inode *inode, 4523 - void **cookie) 4529 + struct delayed_call *callback) 4524 4530 { 4525 4531 char *kaddr; 4526 4532 struct page *page; ··· 4538 4546 if (IS_ERR(page)) 4539 4547 return (char*)page; 4540 4548 } 4541 - *cookie = page; 4549 + set_delayed_call(callback, page_put_link, page); 4542 4550 BUG_ON(mapping_gfp_mask(mapping) & __GFP_HIGHMEM); 4543 4551 kaddr = page_address(page); 4544 4552 nd_terminate_link(kaddr, inode->i_size, PAGE_SIZE - 1); ··· 4547 4555 4548 4556 EXPORT_SYMBOL(page_get_link); 4549 4557 4550 - void page_put_link(struct inode *unused, void *cookie) 4558 + void page_put_link(void *arg) 4551 4559 { 4552 - struct page *page = cookie; 4553 - page_cache_release(page); 4560 + put_page(arg); 4554 4561 } 4555 4562 EXPORT_SYMBOL(page_put_link); 4556 4563 4557 4564 int page_readlink(struct dentry *dentry, char __user *buffer, int buflen) 4558 4565 { 4559 - void *cookie = NULL; 4566 + DEFINE_DELAYED_CALL(done); 4560 4567 int res = readlink_copy(buffer, buflen, 4561 4568 page_get_link(dentry, d_inode(dentry), 4562 - &cookie)); 4563 - if (cookie) 4564 - page_put_link(NULL, cookie); 4569 + &done)); 4570 + do_delayed_call(&done); 4565 4571 return res; 4566 4572 } 4567 4573 EXPORT_SYMBOL(page_readlink); ··· 4609 4619 const struct inode_operations page_symlink_inode_operations = { 4610 4620 .readlink = generic_readlink, 4611 4621 .get_link = page_get_link, 4612 - .put_link = page_put_link, 4613 4622 }; 4614 4623 EXPORT_SYMBOL(page_symlink_inode_operations);
-1
fs/ncpfs/inode.c
··· 245 245 static const struct inode_operations ncp_symlink_inode_operations = { 246 246 .readlink = generic_readlink, 247 247 .get_link = page_get_link, 248 - .put_link = page_put_link, 249 248 .setattr = ncp_notify_change, 250 249 }; 251 250 #endif
+3 -3
fs/nfs/symlink.c
··· 43 43 } 44 44 45 45 static const char *nfs_get_link(struct dentry *dentry, 46 - struct inode *inode, void **cookie) 46 + struct inode *inode, 47 + struct delayed_call *done) 47 48 { 48 49 struct page *page; 49 50 void *err; ··· 69 68 if (IS_ERR(page)) 70 69 return ERR_CAST(page); 71 70 } 72 - *cookie = page; 71 + set_delayed_call(done, page_put_link, page); 73 72 return page_address(page); 74 73 } 75 74 ··· 79 78 const struct inode_operations nfs_symlink_inode_operations = { 80 79 .readlink = generic_readlink, 81 80 .get_link = nfs_get_link, 82 - .put_link = page_put_link, 83 81 .getattr = nfs_getattr, 84 82 .setattr = nfs_setattr, 85 83 };
-1
fs/nilfs2/namei.c
··· 570 570 const struct inode_operations nilfs_symlink_inode_operations = { 571 571 .readlink = generic_readlink, 572 572 .get_link = page_get_link, 573 - .put_link = page_put_link, 574 573 .permission = nilfs_permission, 575 574 }; 576 575
-1
fs/ocfs2/symlink.c
··· 89 89 const struct inode_operations ocfs2_symlink_inode_operations = { 90 90 .readlink = generic_readlink, 91 91 .get_link = page_get_link, 92 - .put_link = page_put_link, 93 92 .getattr = ocfs2_getattr, 94 93 .setattr = ocfs2_setattr, 95 94 .setxattr = generic_setxattr,
+3 -42
fs/overlayfs/inode.c
··· 131 131 return err; 132 132 } 133 133 134 - 135 - struct ovl_link_data { 136 - struct dentry *realdentry; 137 - void *cookie; 138 - }; 139 - 140 134 static const char *ovl_get_link(struct dentry *dentry, 141 - struct inode *inode, void **cookie) 135 + struct inode *inode, 136 + struct delayed_call *done) 142 137 { 143 138 struct dentry *realdentry; 144 139 struct inode *realinode; 145 - struct ovl_link_data *data = NULL; 146 - const char *ret; 147 140 148 141 if (!dentry) 149 142 return ERR_PTR(-ECHILD); ··· 147 154 if (WARN_ON(!realinode->i_op->get_link)) 148 155 return ERR_PTR(-EPERM); 149 156 150 - if (realinode->i_op->put_link) { 151 - data = kmalloc(sizeof(struct ovl_link_data), GFP_KERNEL); 152 - if (!data) 153 - return ERR_PTR(-ENOMEM); 154 - data->realdentry = realdentry; 155 - } 156 - 157 - ret = realinode->i_op->get_link(realdentry, realinode, cookie); 158 - if (IS_ERR_OR_NULL(ret)) { 159 - kfree(data); 160 - return ret; 161 - } 162 - 163 - if (data) 164 - data->cookie = *cookie; 165 - 166 - *cookie = data; 167 - 168 - return ret; 169 - } 170 - 171 - static void ovl_put_link(struct inode *unused, void *c) 172 - { 173 - struct inode *realinode; 174 - struct ovl_link_data *data = c; 175 - 176 - if (!data) 177 - return; 178 - 179 - realinode = data->realdentry->d_inode; 180 - realinode->i_op->put_link(realinode, data->cookie); 181 - kfree(data); 157 + return realinode->i_op->get_link(realdentry, realinode, done); 182 158 } 183 159 184 160 static int ovl_readlink(struct dentry *dentry, char __user *buf, int bufsiz) ··· 345 383 static const struct inode_operations ovl_symlink_inode_operations = { 346 384 .setattr = ovl_setattr, 347 385 .get_link = ovl_get_link, 348 - .put_link = ovl_put_link, 349 386 .readlink = ovl_readlink, 350 387 .getattr = ovl_getattr, 351 388 .setxattr = ovl_setxattr,
+5 -3
fs/proc/base.c
··· 1565 1565 } 1566 1566 1567 1567 static const char *proc_pid_get_link(struct dentry *dentry, 1568 - struct inode *inode, void **cookie) 1568 + struct inode *inode, 1569 + struct delayed_call *done) 1569 1570 { 1570 1571 struct path path; 1571 1572 int error = -EACCES; ··· 1950 1949 */ 1951 1950 static const char * 1952 1951 proc_map_files_get_link(struct dentry *dentry, 1953 - struct inode *inode, void **cookie) 1952 + struct inode *inode, 1953 + struct delayed_call *done) 1954 1954 { 1955 1955 if (!capable(CAP_SYS_ADMIN)) 1956 1956 return ERR_PTR(-EPERM); 1957 1957 1958 - return proc_pid_get_link(dentry, inode, NULL); 1958 + return proc_pid_get_link(dentry, inode, done); 1959 1959 } 1960 1960 1961 1961 /*
+8 -8
fs/proc/inode.c
··· 393 393 }; 394 394 #endif 395 395 396 + static void proc_put_link(void *p) 397 + { 398 + unuse_pde(p); 399 + } 400 + 396 401 static const char *proc_get_link(struct dentry *dentry, 397 - struct inode *inode, void **cookie) 402 + struct inode *inode, 403 + struct delayed_call *done) 398 404 { 399 405 struct proc_dir_entry *pde = PDE(inode); 400 406 if (unlikely(!use_pde(pde))) 401 407 return ERR_PTR(-EINVAL); 402 - *cookie = pde; 408 + set_delayed_call(done, proc_put_link, pde); 403 409 return pde->data; 404 - } 405 - 406 - static void proc_put_link(struct inode *unused, void *p) 407 - { 408 - unuse_pde(p); 409 410 } 410 411 411 412 const struct inode_operations proc_link_inode_operations = { 412 413 .readlink = generic_readlink, 413 414 .get_link = proc_get_link, 414 - .put_link = proc_put_link, 415 415 }; 416 416 417 417 struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
+2 -1
fs/proc/namespaces.c
··· 31 31 }; 32 32 33 33 static const char *proc_ns_get_link(struct dentry *dentry, 34 - struct inode *inode, void **cookie) 34 + struct inode *inode, 35 + struct delayed_call *done) 35 36 { 36 37 const struct proc_ns_operations *ns_ops = PROC_I(inode)->ns_ops; 37 38 struct task_struct *task;
+4 -3
fs/proc/self.c
··· 19 19 } 20 20 21 21 static const char *proc_self_get_link(struct dentry *dentry, 22 - struct inode *inode, void **cookie) 22 + struct inode *inode, 23 + struct delayed_call *done) 23 24 { 24 25 struct pid_namespace *ns = inode->i_sb->s_fs_info; 25 26 pid_t tgid = task_tgid_nr_ns(current, ns); ··· 33 32 if (unlikely(!name)) 34 33 return dentry ? ERR_PTR(-ENOMEM) : ERR_PTR(-ECHILD); 35 34 sprintf(name, "%d", tgid); 36 - return *cookie = name; 35 + set_delayed_call(done, kfree_link, name); 36 + return name; 37 37 } 38 38 39 39 static const struct inode_operations proc_self_inode_operations = { 40 40 .readlink = proc_self_readlink, 41 41 .get_link = proc_self_get_link, 42 - .put_link = kfree_put_link, 43 42 }; 44 43 45 44 static unsigned self_inum;
+4 -3
fs/proc/thread_self.c
··· 20 20 } 21 21 22 22 static const char *proc_thread_self_get_link(struct dentry *dentry, 23 - struct inode *inode, void **cookie) 23 + struct inode *inode, 24 + struct delayed_call *done) 24 25 { 25 26 struct pid_namespace *ns = inode->i_sb->s_fs_info; 26 27 pid_t tgid = task_tgid_nr_ns(current, ns); ··· 35 34 if (unlikely(!name)) 36 35 return dentry ? ERR_PTR(-ENOMEM) : ERR_PTR(-ECHILD); 37 36 sprintf(name, "%d/task/%d", tgid, pid); 38 - return *cookie = name; 37 + set_delayed_call(done, kfree_link, name); 38 + return name; 39 39 } 40 40 41 41 static const struct inode_operations proc_thread_self_inode_operations = { 42 42 .readlink = proc_thread_self_readlink, 43 43 .get_link = proc_thread_self_get_link, 44 - .put_link = kfree_put_link, 45 44 }; 46 45 47 46 static unsigned thread_self_inum;
-1
fs/reiserfs/namei.c
··· 1666 1666 const struct inode_operations reiserfs_symlink_inode_operations = { 1667 1667 .readlink = generic_readlink, 1668 1668 .get_link = page_get_link, 1669 - .put_link = page_put_link, 1670 1669 .setattr = reiserfs_setattr, 1671 1670 .setxattr = reiserfs_setxattr, 1672 1671 .getxattr = reiserfs_getxattr,
-1
fs/squashfs/symlink.c
··· 120 120 const struct inode_operations squashfs_symlink_inode_ops = { 121 121 .readlink = generic_readlink, 122 122 .get_link = page_get_link, 123 - .put_link = page_put_link, 124 123 .getxattr = generic_getxattr, 125 124 .listxattr = squashfs_listxattr 126 125 };
-1
fs/sysv/inode.c
··· 147 147 static const struct inode_operations sysv_symlink_inode_operations = { 148 148 .readlink = generic_readlink, 149 149 .get_link = page_get_link, 150 - .put_link = page_put_link, 151 150 .getattr = sysv_getattr, 152 151 }; 153 152
+3 -3
fs/xfs/xfs_iops.c
··· 417 417 xfs_vn_get_link( 418 418 struct dentry *dentry, 419 419 struct inode *inode, 420 - void **cookie) 420 + struct delayed_call *done) 421 421 { 422 422 char *link; 423 423 int error = -ENOMEM; ··· 433 433 if (unlikely(error)) 434 434 goto out_kfree; 435 435 436 - return *cookie = link; 436 + set_delayed_call(done, kfree_link, link); 437 + return link; 437 438 438 439 out_kfree: 439 440 kfree(link); ··· 1178 1177 static const struct inode_operations xfs_symlink_inode_operations = { 1179 1178 .readlink = generic_readlink, 1180 1179 .get_link = xfs_vn_get_link, 1181 - .put_link = kfree_put_link, 1182 1180 .getattr = xfs_vn_getattr, 1183 1181 .setattr = xfs_vn_setattr, 1184 1182 .setxattr = generic_setxattr,
+34
include/linux/delayed_call.h
··· 1 + #ifndef _DELAYED_CALL_H 2 + #define _DELAYED_CALL_H 3 + 4 + /* 5 + * Poor man's closures; I wish we could've done them sanely polymorphic, 6 + * but... 7 + */ 8 + 9 + struct delayed_call { 10 + void (*fn)(void *); 11 + void *arg; 12 + }; 13 + 14 + #define DEFINE_DELAYED_CALL(name) struct delayed_call name = {NULL, NULL} 15 + 16 + /* I really wish we had closures with sane typechecking... */ 17 + static inline void set_delayed_call(struct delayed_call *call, 18 + void (*fn)(void *), void *arg) 19 + { 20 + call->fn = fn; 21 + call->arg = arg; 22 + } 23 + 24 + static inline void do_delayed_call(struct delayed_call *call) 25 + { 26 + if (call->fn) 27 + call->fn(call->arg); 28 + } 29 + 30 + static inline void clear_delayed_call(struct delayed_call *call) 31 + { 32 + call->fn = NULL; 33 + } 34 + #endif
+8 -6
include/linux/fs.h
··· 31 31 #include <linux/blk_types.h> 32 32 #include <linux/workqueue.h> 33 33 #include <linux/percpu-rwsem.h> 34 + #include <linux/delayed_call.h> 34 35 35 36 #include <asm/byteorder.h> 36 37 #include <uapi/linux/fs.h> ··· 1634 1633 1635 1634 struct inode_operations { 1636 1635 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int); 1637 - const char * (*get_link) (struct dentry *, struct inode *, void **); 1636 + const char * (*get_link) (struct dentry *, struct inode *, struct delayed_call *); 1638 1637 int (*permission) (struct inode *, int); 1639 1638 struct posix_acl * (*get_acl)(struct inode *, int); 1640 1639 1641 1640 int (*readlink) (struct dentry *, char __user *,int); 1642 - void (*put_link) (struct inode *, void *); 1643 1641 1644 1642 int (*create) (struct inode *,struct dentry *, umode_t, bool); 1645 1643 int (*link) (struct dentry *,struct inode *,struct dentry *); ··· 2736 2736 2737 2737 extern int readlink_copy(char __user *, int, const char *); 2738 2738 extern int page_readlink(struct dentry *, char __user *, int); 2739 - extern const char *page_get_link(struct dentry *, struct inode *, void **); 2740 - extern void page_put_link(struct inode *, void *); 2739 + extern const char *page_get_link(struct dentry *, struct inode *, 2740 + struct delayed_call *); 2741 + extern void page_put_link(void *); 2741 2742 extern int __page_symlink(struct inode *inode, const char *symname, int len, 2742 2743 int nofs); 2743 2744 extern int page_symlink(struct inode *inode, const char *symname, int len); 2744 2745 extern const struct inode_operations page_symlink_inode_operations; 2745 - extern void kfree_put_link(struct inode *, void *); 2746 + extern void kfree_link(void *); 2746 2747 extern int generic_readlink(struct dentry *, char __user *, int); 2747 2748 extern void generic_fillattr(struct inode *, struct kstat *); 2748 2749 int vfs_getattr_nosec(struct path *path, struct kstat *stat); ··· 2754 2753 void inode_sub_bytes(struct inode *inode, loff_t bytes); 2755 2754 loff_t inode_get_bytes(struct inode *inode); 2756 2755 void inode_set_bytes(struct inode *inode, loff_t bytes); 2757 - const char *simple_get_link(struct dentry *, struct inode *, void **); 2756 + const char *simple_get_link(struct dentry *, struct inode *, 2757 + struct delayed_call *); 2758 2758 extern const struct inode_operations simple_symlink_inode_operations; 2759 2759 2760 2760 extern int iterate_dir(struct file *, struct dir_context *);
+9 -10
mm/shmem.c
··· 2496 2496 return 0; 2497 2497 } 2498 2498 2499 + static void shmem_put_link(void *arg) 2500 + { 2501 + mark_page_accessed(arg); 2502 + put_page(arg); 2503 + } 2504 + 2499 2505 static const char *shmem_get_link(struct dentry *dentry, 2500 - struct inode *inode, void **cookie) 2506 + struct inode *inode, 2507 + struct delayed_call *done) 2501 2508 { 2502 2509 struct page *page = NULL; 2503 2510 int error; ··· 2522 2515 return ERR_PTR(error); 2523 2516 unlock_page(page); 2524 2517 } 2525 - *cookie = page; 2518 + set_delayed_call(done, shmem_put_link, page); 2526 2519 return page_address(page); 2527 - } 2528 - 2529 - static void shmem_put_link(struct inode *unused, void *cookie) 2530 - { 2531 - struct page *page = cookie; 2532 - mark_page_accessed(page); 2533 - page_cache_release(page); 2534 2520 } 2535 2521 2536 2522 #ifdef CONFIG_TMPFS_XATTR ··· 2680 2680 static const struct inode_operations shmem_symlink_inode_operations = { 2681 2681 .readlink = generic_readlink, 2682 2682 .get_link = shmem_get_link, 2683 - .put_link = shmem_put_link, 2684 2683 #ifdef CONFIG_TMPFS_XATTR 2685 2684 .setxattr = shmem_setxattr, 2686 2685 .getxattr = shmem_getxattr,