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

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'nfs-for-5.13-1' of git://git.linux-nfs.org/projects/trondmy/linux-nfs

Pull NFS client updates from Trond Myklebust:
"Highlights include:

Stable fixes:

- Add validation of the UDP retrans parameter to prevent shift
out-of-bounds

- Don't discard pNFS layout segments that are marked for return

Bugfixes:

- Fix a NULL dereference crash in xprt_complete_bc_request() when the
NFSv4.1 server misbehaves.

- Fix the handling of NFS READDIR cookie verifiers

- Sundry fixes to ensure attribute revalidation works correctly when
the server does not return post-op attributes.

- nfs4_bitmask_adjust() must not change the server global bitmasks

- Fix major timeout handling in the RPC code.

- NFSv4.2 fallocate() fixes.

- Fix the NFSv4.2 SEEK_HOLE/SEEK_DATA end-of-file handling

- Copy offload attribute revalidation fixes

- Fix an incorrect filehandle size check in the pNFS flexfiles driver

- Fix several RDMA transport setup/teardown races

- Fix several RDMA queue wrapping issues

- Fix a misplaced memory read barrier in sunrpc's call_decode()

Features:

- Micro optimisation of the TCP transmission queue using TCP_CORK

- statx() performance improvements by further splitting up the
tracking of invalid cached file metadata.

- Support the NFSv4.2 'change_attr_type' attribute and use it to
optimise handling of change attribute updates"

* tag 'nfs-for-5.13-1' of git://git.linux-nfs.org/projects/trondmy/linux-nfs: (85 commits)
xprtrdma: Fix a NULL dereference in frwr_unmap_sync()
sunrpc: Fix misplaced barrier in call_decode
NFSv4.2: Remove ifdef CONFIG_NFSD from NFSv4.2 client SSC code.
xprtrdma: Move fr_mr field to struct rpcrdma_mr
xprtrdma: Move the Work Request union to struct rpcrdma_mr
xprtrdma: Move fr_linv_done field to struct rpcrdma_mr
xprtrdma: Move cqe to struct rpcrdma_mr
xprtrdma: Move fr_cid to struct rpcrdma_mr
xprtrdma: Remove the RPC/RDMA QP event handler
xprtrdma: Don't display r_xprt memory addresses in tracepoints
xprtrdma: Add an rpcrdma_mr_completion_class
xprtrdma: Add tracepoints showing FastReg WRs and remote invalidation
xprtrdma: Avoid Send Queue wrapping
xprtrdma: Do not wake RPC consumer on a failed LocalInv
xprtrdma: Do not recycle MR after FastReg/LocalInv flushes
xprtrdma: Clarify use of barrier in frwr_wc_localinv_done()
xprtrdma: Rename frwr_release_mr()
xprtrdma: rpcrdma_mr_pop() already does list_del_init()
xprtrdma: Delete rpcrdma_recv_buffer_put()
xprtrdma: Fix cwnd update ordering
...

+1120 -723
+2 -2
fs/Kconfig
··· 338 338 default y 339 339 340 340 config NFS_V4_2_SSC_HELPER 341 - tristate 342 - default y if NFS_V4=y || NFS_FS=y 341 + bool 342 + default y if NFS_V4_2 343 343 344 344 source "net/sunrpc/Kconfig" 345 345 source "fs/ceph/Kconfig"
+9 -8
fs/nfs/callback_proc.c
··· 137 137 list_for_each_entry_rcu(lo, &server->layouts, plh_layouts) { 138 138 if (!pnfs_layout_is_valid(lo)) 139 139 continue; 140 - if (stateid != NULL && 141 - !nfs4_stateid_match_other(stateid, &lo->plh_stateid)) 140 + if (!nfs4_stateid_match_other(stateid, &lo->plh_stateid)) 142 141 continue; 143 - if (!nfs_sb_active(server->super)) 144 - continue; 145 - inode = igrab(lo->plh_inode); 142 + if (nfs_sb_active(server->super)) 143 + inode = igrab(lo->plh_inode); 144 + else 145 + inode = ERR_PTR(-EAGAIN); 146 146 rcu_read_unlock(); 147 147 if (inode) 148 148 return inode; ··· 176 176 continue; 177 177 if (nfsi->layout != lo) 178 178 continue; 179 - if (!nfs_sb_active(server->super)) 180 - continue; 181 - inode = igrab(lo->plh_inode); 179 + if (nfs_sb_active(server->super)) 180 + inode = igrab(lo->plh_inode); 181 + else 182 + inode = ERR_PTR(-EAGAIN); 182 183 rcu_read_unlock(); 183 184 if (inode) 184 185 return inode;
+15 -5
fs/nfs/client.c
··· 476 476 to->to_maxval = to->to_initval; 477 477 to->to_exponential = 0; 478 478 break; 479 - #ifndef CONFIG_NFS_DISABLE_UDP_SUPPORT 480 479 case XPRT_TRANSPORT_UDP: 481 480 if (retrans == NFS_UNSPEC_RETRANS) 482 481 to->to_retries = NFS_DEF_UDP_RETRANS; ··· 486 487 to->to_maxval = NFS_MAX_UDP_TIMEOUT; 487 488 to->to_exponential = 1; 488 489 break; 489 - #endif 490 490 default: 491 491 BUG(); 492 492 } ··· 696 698 /* Initialise the client representation from the mount data */ 697 699 server->flags = ctx->flags; 698 700 server->options = ctx->options; 699 - server->caps |= NFS_CAP_HARDLINKS|NFS_CAP_SYMLINKS|NFS_CAP_FILEID| 700 - NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER|NFS_CAP_OWNER_GROUP| 701 - NFS_CAP_ATIME|NFS_CAP_CTIME|NFS_CAP_MTIME; 701 + server->caps |= NFS_CAP_HARDLINKS | NFS_CAP_SYMLINKS; 702 + 703 + switch (clp->rpc_ops->version) { 704 + case 2: 705 + server->fattr_valid = NFS_ATTR_FATTR_V2; 706 + break; 707 + case 3: 708 + server->fattr_valid = NFS_ATTR_FATTR_V3; 709 + break; 710 + default: 711 + server->fattr_valid = NFS_ATTR_FATTR_V4; 712 + } 702 713 703 714 if (ctx->rsize) 704 715 server->rsize = nfs_block_size(ctx->rsize, NULL); ··· 801 794 server->maxfilesize = fsinfo->maxfilesize; 802 795 803 796 server->time_delta = fsinfo->time_delta; 797 + server->change_attr_type = fsinfo->change_attr_type; 804 798 805 799 server->clone_blksize = fsinfo->clone_blksize; 806 800 /* We're airborne Set socket buffersize */ ··· 942 934 kfree(server); 943 935 return NULL; 944 936 } 937 + 938 + server->change_attr_type = NFS4_CHANGE_TYPE_IS_UNDEFINED; 945 939 946 940 ida_init(&server->openowner_id); 947 941 ida_init(&server->lockowner_id);
+20 -9
fs/nfs/delegation.c
··· 114 114 return ret; 115 115 } 116 116 /** 117 - * nfs_have_delegation - check if inode has a delegation, mark it 117 + * nfs4_have_delegation - check if inode has a delegation, mark it 118 118 * NFS_DELEGATION_REFERENCED if there is one. 119 119 * @inode: inode to check 120 120 * @flags: delegation types to check for ··· 481 481 if (freeme == NULL) 482 482 goto out; 483 483 add_new: 484 + /* 485 + * If we didn't revalidate the change attribute before setting 486 + * the delegation, then pre-emptively ask for a full attribute 487 + * cache revalidation. 488 + */ 489 + spin_lock(&inode->i_lock); 490 + if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_CHANGE) 491 + nfs_set_cache_invalid(inode, 492 + NFS_INO_INVALID_ATIME | NFS_INO_INVALID_CTIME | 493 + NFS_INO_INVALID_MTIME | NFS_INO_INVALID_SIZE | 494 + NFS_INO_INVALID_BLOCKS | NFS_INO_INVALID_NLINK | 495 + NFS_INO_INVALID_OTHER | NFS_INO_INVALID_DATA | 496 + NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL | 497 + NFS_INO_INVALID_XATTR); 498 + spin_unlock(&inode->i_lock); 499 + 484 500 list_add_tail_rcu(&delegation->super_list, &server->delegations); 485 501 rcu_assign_pointer(nfsi->delegation, delegation); 486 502 delegation = NULL; ··· 504 488 atomic_long_inc(&nfs_active_delegations); 505 489 506 490 trace_nfs4_set_delegation(inode, type); 507 - 508 - spin_lock(&inode->i_lock); 509 - if (NFS_I(inode)->cache_validity & (NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ATIME)) 510 - NFS_I(inode)->cache_validity |= NFS_INO_REVAL_FORCED; 511 - spin_unlock(&inode->i_lock); 512 491 out: 513 492 spin_unlock(&clp->cl_lock); 514 493 if (delegation != NULL) ··· 685 674 } 686 675 687 676 /** 688 - * nfs_inode_return_delegation - synchronously return a delegation 677 + * nfs4_inode_return_delegation - synchronously return a delegation 689 678 * @inode: inode to process 690 679 * 691 680 * This routine will always flush any dirty data to disk on the ··· 708 697 } 709 698 710 699 /** 711 - * nfs_inode_return_delegation_on_close - asynchronously return a delegation 700 + * nfs4_inode_return_delegation_on_close - asynchronously return a delegation 712 701 * @inode: inode to process 713 702 * 714 703 * This routine is called on file close in order to determine if the ··· 822 811 } 823 812 824 813 /** 825 - * nfs_super_return_all_delegations - return delegations for one superblock 814 + * nfs_server_return_all_delegations - return delegations for one superblock 826 815 * @server: pointer to nfs_server to process 827 816 * 828 817 */
+1 -2
fs/nfs/delegation.h
··· 84 84 85 85 static inline int nfs_have_delegated_attributes(struct inode *inode) 86 86 { 87 - return NFS_PROTO(inode)->have_delegation(inode, FMODE_READ) && 88 - !(NFS_I(inode)->cache_validity & NFS_INO_REVAL_FORCED); 87 + return NFS_PROTO(inode)->have_delegation(inode, FMODE_READ); 89 88 } 90 89 91 90 #endif
+19 -10
fs/nfs/dir.c
··· 866 866 break; 867 867 } 868 868 869 + verf_arg = verf_res; 870 + 869 871 status = nfs_readdir_page_filler(desc, entry, pages, pglen, 870 872 arrays, narrays); 871 873 } while (!status && nfs_readdir_page_needs_filling(page)); ··· 929 927 } 930 928 return res; 931 929 } 932 - memcpy(nfsi->cookieverf, verf, sizeof(nfsi->cookieverf)); 930 + /* 931 + * Set the cookie verifier if the page cache was empty 932 + */ 933 + if (desc->page_index == 0) 934 + memcpy(nfsi->cookieverf, verf, 935 + sizeof(nfsi->cookieverf)); 933 936 } 934 937 res = nfs_readdir_search_array(desc); 935 938 if (res == 0) { ··· 981 974 /* 982 975 * Once we've found the start of the dirent within a page: fill 'er up... 983 976 */ 984 - static void nfs_do_filldir(struct nfs_readdir_descriptor *desc) 977 + static void nfs_do_filldir(struct nfs_readdir_descriptor *desc, 978 + const __be32 *verf) 985 979 { 986 980 struct file *file = desc->file; 987 - struct nfs_inode *nfsi = NFS_I(file_inode(file)); 988 981 struct nfs_cache_array *array; 989 982 unsigned int i = 0; 990 983 ··· 998 991 desc->eof = true; 999 992 break; 1000 993 } 1001 - memcpy(desc->verf, nfsi->cookieverf, sizeof(desc->verf)); 994 + memcpy(desc->verf, verf, sizeof(desc->verf)); 1002 995 if (i < (array->size-1)) 1003 996 desc->dir_cookie = array->array[i+1].cookie; 1004 997 else ··· 1055 1048 1056 1049 for (i = 0; !desc->eof && i < sz && arrays[i]; i++) { 1057 1050 desc->page = arrays[i]; 1058 - nfs_do_filldir(desc); 1051 + nfs_do_filldir(desc, verf); 1059 1052 } 1060 1053 desc->page = NULL; 1061 1054 ··· 1076 1069 { 1077 1070 struct dentry *dentry = file_dentry(file); 1078 1071 struct inode *inode = d_inode(dentry); 1072 + struct nfs_inode *nfsi = NFS_I(inode); 1079 1073 struct nfs_open_dir_context *dir_ctx = file->private_data; 1080 1074 struct nfs_readdir_descriptor *desc; 1081 1075 int res; ··· 1130 1122 break; 1131 1123 } 1132 1124 if (res == -ETOOSMALL && desc->plus) { 1133 - clear_bit(NFS_INO_ADVISE_RDPLUS, &NFS_I(inode)->flags); 1125 + clear_bit(NFS_INO_ADVISE_RDPLUS, &nfsi->flags); 1134 1126 nfs_zap_caches(inode); 1135 1127 desc->page_index = 0; 1136 1128 desc->plus = false; ··· 1140 1132 if (res < 0) 1141 1133 break; 1142 1134 1143 - nfs_do_filldir(desc); 1135 + nfs_do_filldir(desc, nfsi->cookieverf); 1144 1136 nfs_readdir_page_unlock_and_put_cached(desc); 1145 1137 } while (!desc->eof); 1146 1138 ··· 1711 1703 NFS_I(inode)->attr_gencount = nfs_inc_attr_generation_counter(); 1712 1704 nfs_set_cache_invalid( 1713 1705 inode, NFS_INO_INVALID_CHANGE | NFS_INO_INVALID_CTIME | 1714 - NFS_INO_INVALID_OTHER | NFS_INO_REVAL_FORCED); 1706 + NFS_INO_INVALID_NLINK); 1715 1707 spin_unlock(&inode->i_lock); 1716 1708 } 1717 1709 ··· 2948 2940 2949 2941 if (S_ISDIR(inode->i_mode)) 2950 2942 return 0; 2951 - if (nfs_check_cache_invalid(inode, NFS_INO_INVALID_OTHER)) { 2943 + if (nfs_check_cache_invalid(inode, NFS_INO_INVALID_MODE)) { 2952 2944 if (mask & MAY_NOT_BLOCK) 2953 2945 return -ECHILD; 2954 2946 ret = __nfs_revalidate_inode(server, inode); ··· 3006 2998 if (mask & MAY_NOT_BLOCK) 3007 2999 return -ECHILD; 3008 3000 3009 - res = nfs_revalidate_inode(NFS_SERVER(inode), inode); 3001 + res = nfs_revalidate_inode(inode, NFS_INO_INVALID_MODE | 3002 + NFS_INO_INVALID_OTHER); 3010 3003 if (res == 0) 3011 3004 res = generic_permission(&init_user_ns, inode, mask); 3012 3005 goto out;
+2 -13
fs/nfs/export.c
··· 169 169 170 170 static u64 nfs_fetch_iversion(struct inode *inode) 171 171 { 172 - struct nfs_server *server = NFS_SERVER(inode); 173 - 174 - /* Is this the right call?: */ 175 - nfs_revalidate_inode(server, inode); 176 - /* 177 - * Also, note we're ignoring any returned error. That seems to be 178 - * the practice for cache consistency information elsewhere in 179 - * the server, but I'm not sure why. 180 - */ 181 - if (server->nfs_client->rpc_ops->version >= 4) 182 - return inode_peek_iversion_raw(inode); 183 - else 184 - return time_to_chattr(&inode->i_ctime); 172 + nfs_revalidate_inode(inode, NFS_INO_INVALID_CHANGE); 173 + return inode_peek_iversion_raw(inode); 185 174 } 186 175 187 176 const struct export_operations nfs_export_ops = {
+1 -1
fs/nfs/file.c
··· 105 105 106 106 if (filp->f_flags & O_DIRECT) 107 107 goto force_reval; 108 - if (nfs_check_cache_invalid(inode, NFS_INO_REVAL_PAGECACHE)) 108 + if (nfs_check_cache_invalid(inode, NFS_INO_INVALID_SIZE)) 109 109 goto force_reval; 110 110 return 0; 111 111 force_reval:
+1 -1
fs/nfs/flexfilelayout/flexfilelayout.c
··· 106 106 if (unlikely(!p)) 107 107 return -ENOBUFS; 108 108 fh->size = be32_to_cpup(p++); 109 - if (fh->size > sizeof(struct nfs_fh)) { 109 + if (fh->size > NFS_MAXFHSIZE) { 110 110 printk(KERN_ERR "NFS flexfiles: Too big fh received %d\n", 111 111 fh->size); 112 112 return -EOVERFLOW;
+47 -19
fs/nfs/fs_context.c
··· 283 283 return 0; 284 284 } 285 285 286 + #ifdef CONFIG_NFS_DISABLE_UDP_SUPPORT 287 + static bool nfs_server_transport_udp_invalid(const struct nfs_fs_context *ctx) 288 + { 289 + return true; 290 + } 291 + #else 292 + static bool nfs_server_transport_udp_invalid(const struct nfs_fs_context *ctx) 293 + { 294 + if (ctx->version == 4) 295 + return true; 296 + return false; 297 + } 298 + #endif 299 + 286 300 /* 287 301 * Sanity check the NFS transport protocol. 288 - * 289 302 */ 290 - static void nfs_validate_transport_protocol(struct nfs_fs_context *ctx) 303 + static int nfs_validate_transport_protocol(struct fs_context *fc, 304 + struct nfs_fs_context *ctx) 291 305 { 292 306 switch (ctx->nfs_server.protocol) { 293 307 case XPRT_TRANSPORT_UDP: 308 + if (nfs_server_transport_udp_invalid(ctx)) 309 + goto out_invalid_transport_udp; 310 + break; 294 311 case XPRT_TRANSPORT_TCP: 295 312 case XPRT_TRANSPORT_RDMA: 296 313 break; 297 314 default: 298 315 ctx->nfs_server.protocol = XPRT_TRANSPORT_TCP; 299 316 } 317 + return 0; 318 + out_invalid_transport_udp: 319 + return nfs_invalf(fc, "NFS: Unsupported transport protocol udp"); 300 320 } 301 321 302 322 /* ··· 325 305 */ 326 306 static void nfs_set_mount_transport_protocol(struct nfs_fs_context *ctx) 327 307 { 328 - nfs_validate_transport_protocol(ctx); 329 - 330 308 if (ctx->mount_server.protocol == XPRT_TRANSPORT_UDP || 331 309 ctx->mount_server.protocol == XPRT_TRANSPORT_TCP) 332 310 return; ··· 950 932 struct nfs_fh *mntfh = ctx->mntfh; 951 933 struct sockaddr *sap = (struct sockaddr *)&ctx->nfs_server.address; 952 934 int extra_flags = NFS_MOUNT_LEGACY_INTERFACE; 935 + int ret; 953 936 954 937 if (data == NULL) 955 938 goto out_no_data; ··· 994 975 if (mntfh->size < sizeof(mntfh->data)) 995 976 memset(mntfh->data + mntfh->size, 0, 996 977 sizeof(mntfh->data) - mntfh->size); 978 + 979 + /* 980 + * for proto == XPRT_TRANSPORT_UDP, which is what uses 981 + * to_exponential, implying shift: limit the shift value 982 + * to BITS_PER_LONG (majortimeo is unsigned long) 983 + */ 984 + if (!(data->flags & NFS_MOUNT_TCP)) /* this will be UDP */ 985 + if (data->retrans >= 64) /* shift value is too large */ 986 + goto out_invalid_data; 997 987 998 988 /* 999 989 * Translate to nfs_fs_context, which nfs_fill_super ··· 1076 1048 goto generic; 1077 1049 } 1078 1050 1051 + ret = nfs_validate_transport_protocol(fc, ctx); 1052 + if (ret) 1053 + return ret; 1054 + 1079 1055 ctx->skip_reconfig_option_check = true; 1080 1056 return 0; 1081 1057 ··· 1108 1076 1109 1077 out_invalid_fh: 1110 1078 return nfs_invalf(fc, "NFS: invalid root filehandle"); 1079 + 1080 + out_invalid_data: 1081 + return nfs_invalf(fc, "NFS: invalid binary mount data"); 1111 1082 } 1112 1083 1113 1084 #if IS_ENABLED(CONFIG_NFS_V4) ··· 1181 1146 { 1182 1147 struct nfs_fs_context *ctx = nfs_fc2context(fc); 1183 1148 struct sockaddr *sap = (struct sockaddr *)&ctx->nfs_server.address; 1149 + int ret; 1184 1150 char *c; 1185 1151 1186 1152 if (!data) { ··· 1254 1218 ctx->acdirmin = data->acdirmin; 1255 1219 ctx->acdirmax = data->acdirmax; 1256 1220 ctx->nfs_server.protocol = data->proto; 1257 - nfs_validate_transport_protocol(ctx); 1258 - if (ctx->nfs_server.protocol == XPRT_TRANSPORT_UDP) 1259 - goto out_invalid_transport_udp; 1221 + ret = nfs_validate_transport_protocol(fc, ctx); 1222 + if (ret) 1223 + return ret; 1260 1224 done: 1261 1225 ctx->skip_reconfig_option_check = true; 1262 1226 return 0; ··· 1267 1231 1268 1232 out_no_address: 1269 1233 return nfs_invalf(fc, "NFS4: mount program didn't pass remote address"); 1270 - 1271 - out_invalid_transport_udp: 1272 - return nfs_invalf(fc, "NFS: Unsupported transport protocol udp"); 1273 1234 } 1274 1235 #endif 1275 1236 ··· 1331 1298 if (!nfs_verify_server_address(sap)) 1332 1299 goto out_no_address; 1333 1300 1301 + ret = nfs_validate_transport_protocol(fc, ctx); 1302 + if (ret) 1303 + return ret; 1304 + 1334 1305 if (ctx->version == 4) { 1335 1306 if (IS_ENABLED(CONFIG_NFS_V4)) { 1336 1307 if (ctx->nfs_server.protocol == XPRT_TRANSPORT_RDMA) ··· 1343 1306 port = NFS_PORT; 1344 1307 max_namelen = NFS4_MAXNAMLEN; 1345 1308 max_pathlen = NFS4_MAXPATHLEN; 1346 - nfs_validate_transport_protocol(ctx); 1347 - if (ctx->nfs_server.protocol == XPRT_TRANSPORT_UDP) 1348 - goto out_invalid_transport_udp; 1349 1309 ctx->flags &= ~(NFS_MOUNT_NONLM | NFS_MOUNT_NOACL | 1350 1310 NFS_MOUNT_VER3 | NFS_MOUNT_LOCAL_FLOCK | 1351 1311 NFS_MOUNT_LOCAL_FCNTL); ··· 1351 1317 } 1352 1318 } else { 1353 1319 nfs_set_mount_transport_protocol(ctx); 1354 - #ifdef CONFIG_NFS_DISABLE_UDP_SUPPORT 1355 - if (ctx->nfs_server.protocol == XPRT_TRANSPORT_UDP) 1356 - goto out_invalid_transport_udp; 1357 - #endif 1358 1320 if (ctx->nfs_server.protocol == XPRT_TRANSPORT_RDMA) 1359 1321 port = NFS_RDMA_PORT; 1360 1322 } ··· 1384 1354 out_v4_not_compiled: 1385 1355 nfs_errorf(fc, "NFS: NFSv4 is not compiled into kernel"); 1386 1356 return -EPROTONOSUPPORT; 1387 - out_invalid_transport_udp: 1388 - return nfs_invalf(fc, "NFS: Unsupported transport protocol udp"); 1389 1357 out_no_address: 1390 1358 return nfs_invalf(fc, "NFS: mount program didn't pass remote address"); 1391 1359 out_mountproto_mismatch:
+275 -153
fs/nfs/inode.c
··· 164 164 return !time_in_range_open(jiffies, nfsi->read_cache_jiffies, nfsi->read_cache_jiffies + nfsi->attrtimeo); 165 165 } 166 166 167 - static bool nfs_check_cache_invalid_delegated(struct inode *inode, unsigned long flags) 167 + static bool nfs_check_cache_flags_invalid(struct inode *inode, 168 + unsigned long flags) 168 169 { 169 170 unsigned long cache_validity = READ_ONCE(NFS_I(inode)->cache_validity); 170 171 171 - /* Special case for the pagecache or access cache */ 172 - if (flags == NFS_INO_REVAL_PAGECACHE && 173 - !(cache_validity & NFS_INO_REVAL_FORCED)) 174 - return false; 175 172 return (cache_validity & flags) != 0; 176 - } 177 - 178 - static bool nfs_check_cache_invalid_not_delegated(struct inode *inode, unsigned long flags) 179 - { 180 - unsigned long cache_validity = READ_ONCE(NFS_I(inode)->cache_validity); 181 - 182 - if ((cache_validity & flags) != 0) 183 - return true; 184 - if (nfs_attribute_timeout(inode)) 185 - return true; 186 - return false; 187 173 } 188 174 189 175 bool nfs_check_cache_invalid(struct inode *inode, unsigned long flags) 190 176 { 191 - if (NFS_PROTO(inode)->have_delegation(inode, FMODE_READ)) 192 - return nfs_check_cache_invalid_delegated(inode, flags); 193 - 194 - return nfs_check_cache_invalid_not_delegated(inode, flags); 177 + if (nfs_check_cache_flags_invalid(inode, flags)) 178 + return true; 179 + return nfs_attribute_cache_expired(inode); 195 180 } 196 181 EXPORT_SYMBOL_GPL(nfs_check_cache_invalid); 197 182 ··· 199 214 200 215 if (have_delegation) { 201 216 if (!(flags & NFS_INO_REVAL_FORCED)) 202 - flags &= ~NFS_INO_INVALID_OTHER; 203 - flags &= ~(NFS_INO_INVALID_CHANGE 204 - | NFS_INO_INVALID_SIZE 205 - | NFS_INO_REVAL_PAGECACHE 206 - | NFS_INO_INVALID_XATTR); 207 - } 217 + flags &= ~(NFS_INO_INVALID_MODE | 218 + NFS_INO_INVALID_OTHER | 219 + NFS_INO_INVALID_XATTR); 220 + flags &= ~(NFS_INO_INVALID_CHANGE | NFS_INO_INVALID_SIZE); 221 + } else if (flags & NFS_INO_REVAL_PAGECACHE) 222 + flags |= NFS_INO_INVALID_CHANGE | NFS_INO_INVALID_SIZE; 208 223 209 224 if (!nfs_has_xattr_cache(nfsi)) 210 225 flags &= ~NFS_INO_INVALID_XATTR; 211 - if (inode->i_mapping->nrpages == 0) 212 - flags &= ~(NFS_INO_INVALID_DATA|NFS_INO_DATA_INVAL_DEFER); 213 - nfsi->cache_validity |= flags; 214 226 if (flags & NFS_INO_INVALID_DATA) 215 227 nfs_fscache_invalidate(inode); 228 + if (inode->i_mapping->nrpages == 0) 229 + flags &= ~(NFS_INO_INVALID_DATA|NFS_INO_DATA_INVAL_DEFER); 230 + flags &= ~(NFS_INO_REVAL_PAGECACHE | NFS_INO_REVAL_FORCED); 231 + nfsi->cache_validity |= flags; 216 232 } 217 233 EXPORT_SYMBOL_GPL(nfs_set_cache_invalid); 218 234 ··· 438 452 .fattr = fattr 439 453 }; 440 454 struct inode *inode = ERR_PTR(-ENOENT); 455 + u64 fattr_supported = NFS_SB(sb)->fattr_valid; 441 456 unsigned long hash; 442 457 443 458 nfs_attr_check_mountpoint(sb, fattr); ··· 471 484 inode->i_mode = fattr->mode; 472 485 nfsi->cache_validity = 0; 473 486 if ((fattr->valid & NFS_ATTR_FATTR_MODE) == 0 474 - && nfs_server_capable(inode, NFS_CAP_MODE)) 475 - nfs_set_cache_invalid(inode, NFS_INO_INVALID_OTHER); 487 + && (fattr_supported & NFS_ATTR_FATTR_MODE)) 488 + nfs_set_cache_invalid(inode, NFS_INO_INVALID_MODE); 476 489 /* Why so? Because we want revalidate for devices/FIFOs, and 477 490 * that's precisely what we have in nfs_file_inode_operations. 478 491 */ ··· 517 530 nfsi->attr_gencount = fattr->gencount; 518 531 if (fattr->valid & NFS_ATTR_FATTR_ATIME) 519 532 inode->i_atime = fattr->atime; 520 - else if (nfs_server_capable(inode, NFS_CAP_ATIME)) 533 + else if (fattr_supported & NFS_ATTR_FATTR_ATIME) 521 534 nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATIME); 522 535 if (fattr->valid & NFS_ATTR_FATTR_MTIME) 523 536 inode->i_mtime = fattr->mtime; 524 - else if (nfs_server_capable(inode, NFS_CAP_MTIME)) 537 + else if (fattr_supported & NFS_ATTR_FATTR_MTIME) 525 538 nfs_set_cache_invalid(inode, NFS_INO_INVALID_MTIME); 526 539 if (fattr->valid & NFS_ATTR_FATTR_CTIME) 527 540 inode->i_ctime = fattr->ctime; 528 - else if (nfs_server_capable(inode, NFS_CAP_CTIME)) 541 + else if (fattr_supported & NFS_ATTR_FATTR_CTIME) 529 542 nfs_set_cache_invalid(inode, NFS_INO_INVALID_CTIME); 530 543 if (fattr->valid & NFS_ATTR_FATTR_CHANGE) 531 544 inode_set_iversion_raw(inode, fattr->change_attr); ··· 537 550 nfs_set_cache_invalid(inode, NFS_INO_INVALID_SIZE); 538 551 if (fattr->valid & NFS_ATTR_FATTR_NLINK) 539 552 set_nlink(inode, fattr->nlink); 540 - else if (nfs_server_capable(inode, NFS_CAP_NLINK)) 541 - nfs_set_cache_invalid(inode, NFS_INO_INVALID_OTHER); 553 + else if (fattr_supported & NFS_ATTR_FATTR_NLINK) 554 + nfs_set_cache_invalid(inode, NFS_INO_INVALID_NLINK); 542 555 if (fattr->valid & NFS_ATTR_FATTR_OWNER) 543 556 inode->i_uid = fattr->uid; 544 - else if (nfs_server_capable(inode, NFS_CAP_OWNER)) 557 + else if (fattr_supported & NFS_ATTR_FATTR_OWNER) 545 558 nfs_set_cache_invalid(inode, NFS_INO_INVALID_OTHER); 546 559 if (fattr->valid & NFS_ATTR_FATTR_GROUP) 547 560 inode->i_gid = fattr->gid; 548 - else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP)) 561 + else if (fattr_supported & NFS_ATTR_FATTR_GROUP) 549 562 nfs_set_cache_invalid(inode, NFS_INO_INVALID_OTHER); 550 563 if (nfs_server_capable(inode, NFS_CAP_XATTR)) 551 564 nfs_set_cache_invalid(inode, NFS_INO_INVALID_XATTR); 552 565 if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED) 553 566 inode->i_blocks = fattr->du.nfs2.blocks; 567 + else if (fattr_supported & NFS_ATTR_FATTR_BLOCKS_USED && 568 + fattr->size != 0) 569 + nfs_set_cache_invalid(inode, NFS_INO_INVALID_BLOCKS); 554 570 if (fattr->valid & NFS_ATTR_FATTR_SPACE_USED) { 555 571 /* 556 572 * report the blocks in 512byte units 557 573 */ 558 574 inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used); 559 - } 560 - 561 - if (nfsi->cache_validity != 0) 562 - nfsi->cache_validity |= NFS_INO_REVAL_FORCED; 575 + } else if (fattr_supported & NFS_ATTR_FATTR_SPACE_USED && 576 + fattr->size != 0) 577 + nfs_set_cache_invalid(inode, NFS_INO_INVALID_BLOCKS); 563 578 564 579 nfs_setsecurity(inode, fattr, label); 565 580 ··· 623 634 } 624 635 625 636 /* Optimization: if the end result is no change, don't RPC */ 626 - attr->ia_valid &= NFS_VALID_ATTRS; 627 - if ((attr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0) 637 + if (((attr->ia_valid & NFS_VALID_ATTRS) & ~(ATTR_FILE|ATTR_OPEN)) == 0) 628 638 return 0; 629 639 630 640 trace_nfs_setattr_enter(inode); ··· 698 710 spin_lock(&inode->i_lock); 699 711 NFS_I(inode)->attr_gencount = fattr->gencount; 700 712 if ((attr->ia_valid & ATTR_SIZE) != 0) { 701 - nfs_set_cache_invalid(inode, NFS_INO_INVALID_MTIME); 713 + nfs_set_cache_invalid(inode, NFS_INO_INVALID_MTIME | 714 + NFS_INO_INVALID_BLOCKS); 702 715 nfs_inc_stats(inode, NFSIOS_SETATTRTRUNC); 703 716 nfs_vmtruncate(inode, attr->ia_size); 704 717 } 705 718 if ((attr->ia_valid & (ATTR_MODE|ATTR_UID|ATTR_GID)) != 0) { 706 719 NFS_I(inode)->cache_validity &= ~NFS_INO_INVALID_CTIME; 720 + if ((attr->ia_valid & ATTR_KILL_SUID) != 0 && 721 + inode->i_mode & S_ISUID) 722 + inode->i_mode &= ~S_ISUID; 723 + if ((attr->ia_valid & ATTR_KILL_SGID) != 0 && 724 + (inode->i_mode & (S_ISGID | S_IXGRP)) == 725 + (S_ISGID | S_IXGRP)) 726 + inode->i_mode &= ~S_ISGID; 707 727 if ((attr->ia_valid & ATTR_MODE) != 0) { 708 728 int mode = attr->ia_mode & S_IALLUGO; 709 729 mode |= inode->i_mode & ~S_IALLUGO; ··· 789 793 dput(parent); 790 794 } 791 795 792 - static bool nfs_need_revalidate_inode(struct inode *inode) 796 + static u32 nfs_get_valid_attrmask(struct inode *inode) 793 797 { 794 - if (NFS_I(inode)->cache_validity & 795 - (NFS_INO_INVALID_ATTR|NFS_INO_INVALID_LABEL)) 796 - return true; 797 - if (nfs_attribute_cache_expired(inode)) 798 - return true; 799 - return false; 798 + unsigned long cache_validity = READ_ONCE(NFS_I(inode)->cache_validity); 799 + u32 reply_mask = STATX_INO | STATX_TYPE; 800 + 801 + if (!(cache_validity & NFS_INO_INVALID_ATIME)) 802 + reply_mask |= STATX_ATIME; 803 + if (!(cache_validity & NFS_INO_INVALID_CTIME)) 804 + reply_mask |= STATX_CTIME; 805 + if (!(cache_validity & NFS_INO_INVALID_MTIME)) 806 + reply_mask |= STATX_MTIME; 807 + if (!(cache_validity & NFS_INO_INVALID_SIZE)) 808 + reply_mask |= STATX_SIZE; 809 + if (!(cache_validity & NFS_INO_INVALID_NLINK)) 810 + reply_mask |= STATX_NLINK; 811 + if (!(cache_validity & NFS_INO_INVALID_MODE)) 812 + reply_mask |= STATX_MODE; 813 + if (!(cache_validity & NFS_INO_INVALID_OTHER)) 814 + reply_mask |= STATX_UID | STATX_GID; 815 + if (!(cache_validity & NFS_INO_INVALID_BLOCKS)) 816 + reply_mask |= STATX_BLOCKS; 817 + return reply_mask; 800 818 } 801 819 802 820 int nfs_getattr(struct user_namespace *mnt_userns, const struct path *path, ··· 825 815 826 816 trace_nfs_getattr_enter(inode); 827 817 818 + request_mask &= STATX_TYPE | STATX_MODE | STATX_NLINK | STATX_UID | 819 + STATX_GID | STATX_ATIME | STATX_MTIME | STATX_CTIME | 820 + STATX_INO | STATX_SIZE | STATX_BLOCKS; 821 + 828 822 if ((query_flags & AT_STATX_DONT_SYNC) && !force_sync) { 829 823 nfs_readdirplus_parent_cache_hit(path->dentry); 830 - goto out_no_update; 824 + goto out_no_revalidate; 831 825 } 832 826 833 827 /* Flush out writes to the server in order to update c/mtime. */ ··· 864 850 /* Check whether the cached attributes are stale */ 865 851 do_update |= force_sync || nfs_attribute_cache_expired(inode); 866 852 cache_validity = READ_ONCE(NFS_I(inode)->cache_validity); 867 - do_update |= cache_validity & 868 - (NFS_INO_INVALID_ATTR|NFS_INO_INVALID_LABEL); 853 + do_update |= cache_validity & NFS_INO_INVALID_CHANGE; 869 854 if (request_mask & STATX_ATIME) 870 855 do_update |= cache_validity & NFS_INO_INVALID_ATIME; 871 - if (request_mask & (STATX_CTIME|STATX_MTIME)) 872 - do_update |= cache_validity & NFS_INO_REVAL_PAGECACHE; 856 + if (request_mask & STATX_CTIME) 857 + do_update |= cache_validity & NFS_INO_INVALID_CTIME; 858 + if (request_mask & STATX_MTIME) 859 + do_update |= cache_validity & NFS_INO_INVALID_MTIME; 860 + if (request_mask & STATX_SIZE) 861 + do_update |= cache_validity & NFS_INO_INVALID_SIZE; 862 + if (request_mask & STATX_NLINK) 863 + do_update |= cache_validity & NFS_INO_INVALID_NLINK; 864 + if (request_mask & STATX_MODE) 865 + do_update |= cache_validity & NFS_INO_INVALID_MODE; 866 + if (request_mask & (STATX_UID | STATX_GID)) 867 + do_update |= cache_validity & NFS_INO_INVALID_OTHER; 873 868 if (request_mask & STATX_BLOCKS) 874 869 do_update |= cache_validity & NFS_INO_INVALID_BLOCKS; 870 + 875 871 if (do_update) { 876 872 /* Update the attribute cache */ 877 873 if (!(server->flags & NFS_MOUNT_NOAC)) ··· 895 871 nfs_readdirplus_parent_cache_hit(path->dentry); 896 872 out_no_revalidate: 897 873 /* Only return attributes that were revalidated. */ 898 - stat->result_mask &= request_mask; 899 - out_no_update: 874 + stat->result_mask = nfs_get_valid_attrmask(inode) | request_mask; 875 + 900 876 generic_fillattr(&init_user_ns, inode, stat); 901 877 stat->ino = nfs_compat_user_ino64(NFS_FILEID(inode)); 902 878 if (S_ISDIR(inode->i_mode)) ··· 987 963 { 988 964 struct nfs_inode *nfsi; 989 965 struct inode *inode; 990 - struct nfs_server *server; 991 966 992 967 if (!(ctx->mode & FMODE_WRITE)) 993 968 return; ··· 1002 979 return; 1003 980 if (!list_empty(&nfsi->open_files)) 1004 981 return; 1005 - server = NFS_SERVER(inode); 1006 - if (server->flags & NFS_MOUNT_NOCTO) 982 + if (NFS_SERVER(inode)->flags & NFS_MOUNT_NOCTO) 1007 983 return; 1008 - nfs_revalidate_inode(server, inode); 984 + nfs_revalidate_inode(inode, 985 + NFS_INO_INVALID_CHANGE | NFS_INO_INVALID_SIZE); 1009 986 } 1010 987 EXPORT_SYMBOL_GPL(nfs_close_context); 1011 988 ··· 1260 1237 1261 1238 /** 1262 1239 * nfs_revalidate_inode - Revalidate the inode attributes 1263 - * @server: pointer to nfs_server struct 1264 1240 * @inode: pointer to inode struct 1241 + * @flags: cache flags to check 1265 1242 * 1266 1243 * Updates inode attribute information by retrieving the data from the server. 1267 1244 */ 1268 - int nfs_revalidate_inode(struct nfs_server *server, struct inode *inode) 1245 + int nfs_revalidate_inode(struct inode *inode, unsigned long flags) 1269 1246 { 1270 - if (!nfs_need_revalidate_inode(inode)) 1247 + if (!nfs_check_cache_invalid(inode, flags)) 1271 1248 return NFS_STALE(inode) ? -ESTALE : 0; 1272 - return __nfs_revalidate_inode(server, inode); 1249 + return __nfs_revalidate_inode(NFS_SERVER(inode), inode); 1273 1250 } 1274 1251 EXPORT_SYMBOL_GPL(nfs_revalidate_inode); 1275 1252 ··· 1355 1332 1356 1333 bool nfs_mapping_need_revalidate_inode(struct inode *inode) 1357 1334 { 1358 - return nfs_check_cache_invalid(inode, NFS_INO_REVAL_PAGECACHE) || 1335 + return nfs_check_cache_invalid(inode, NFS_INO_INVALID_CHANGE) || 1359 1336 NFS_STALE(inode); 1360 1337 } 1361 1338 ··· 1491 1468 if (!nfs_file_has_buffered_writers(nfsi)) { 1492 1469 /* Verify a few of the more important attributes */ 1493 1470 if ((fattr->valid & NFS_ATTR_FATTR_CHANGE) != 0 && !inode_eq_iversion_raw(inode, fattr->change_attr)) 1494 - invalid |= NFS_INO_INVALID_CHANGE 1495 - | NFS_INO_REVAL_PAGECACHE; 1471 + invalid |= NFS_INO_INVALID_CHANGE; 1496 1472 1497 1473 ts = inode->i_mtime; 1498 1474 if ((fattr->valid & NFS_ATTR_FATTR_MTIME) && !timespec64_equal(&ts, &fattr->mtime)) ··· 1505 1483 cur_size = i_size_read(inode); 1506 1484 new_isize = nfs_size_to_loff_t(fattr->size); 1507 1485 if (cur_size != new_isize) 1508 - invalid |= NFS_INO_INVALID_SIZE 1509 - | NFS_INO_REVAL_PAGECACHE; 1486 + invalid |= NFS_INO_INVALID_SIZE; 1510 1487 } 1511 1488 } 1512 1489 1513 1490 /* Have any file permissions changed? */ 1514 1491 if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO)) 1515 - invalid |= NFS_INO_INVALID_ACCESS 1516 - | NFS_INO_INVALID_ACL 1517 - | NFS_INO_INVALID_OTHER; 1492 + invalid |= NFS_INO_INVALID_MODE; 1518 1493 if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, fattr->uid)) 1519 - invalid |= NFS_INO_INVALID_ACCESS 1520 - | NFS_INO_INVALID_ACL 1521 - | NFS_INO_INVALID_OTHER; 1494 + invalid |= NFS_INO_INVALID_OTHER; 1522 1495 if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, fattr->gid)) 1523 - invalid |= NFS_INO_INVALID_ACCESS 1524 - | NFS_INO_INVALID_ACL 1525 - | NFS_INO_INVALID_OTHER; 1496 + invalid |= NFS_INO_INVALID_OTHER; 1526 1497 1527 1498 /* Has the link count changed? */ 1528 1499 if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink) 1529 - invalid |= NFS_INO_INVALID_OTHER; 1500 + invalid |= NFS_INO_INVALID_NLINK; 1530 1501 1531 1502 ts = inode->i_atime; 1532 1503 if ((fattr->valid & NFS_ATTR_FATTR_ATIME) && !timespec64_equal(&ts, &fattr->atime)) ··· 1657 1642 #endif 1658 1643 1659 1644 /** 1660 - * nfs_inode_attrs_need_update - check if the inode attributes need updating 1661 - * @inode: pointer to inode 1645 + * nfs_inode_attrs_cmp_generic - compare attributes 1662 1646 * @fattr: attributes 1647 + * @inode: pointer to inode 1648 + * 1649 + * Attempt to divine whether or not an RPC call reply carrying stale 1650 + * attributes got scheduled after another call carrying updated ones. 1651 + * Note also the check for wraparound of 'attr_gencount' 1652 + * 1653 + * The function returns '1' if it thinks the attributes in @fattr are 1654 + * more recent than the ones cached in @inode. Otherwise it returns 1655 + * the value '0'. 1656 + */ 1657 + static int nfs_inode_attrs_cmp_generic(const struct nfs_fattr *fattr, 1658 + const struct inode *inode) 1659 + { 1660 + unsigned long attr_gencount = NFS_I(inode)->attr_gencount; 1661 + 1662 + return (long)(fattr->gencount - attr_gencount) > 0 || 1663 + (long)(attr_gencount - nfs_read_attr_generation_counter()) > 0; 1664 + } 1665 + 1666 + /** 1667 + * nfs_inode_attrs_cmp_monotonic - compare attributes 1668 + * @fattr: attributes 1669 + * @inode: pointer to inode 1663 1670 * 1664 1671 * Attempt to divine whether or not an RPC call reply carrying stale 1665 1672 * attributes got scheduled after another call carrying updated ones. 1666 1673 * 1667 - * To do so, the function first assumes that a more recent ctime means 1668 - * that the attributes in fattr are newer, however it also attempt to 1669 - * catch the case where ctime either didn't change, or went backwards 1670 - * (if someone reset the clock on the server) by looking at whether 1671 - * or not this RPC call was started after the inode was last updated. 1672 - * Note also the check for wraparound of 'attr_gencount' 1673 - * 1674 - * The function returns 'true' if it thinks the attributes in 'fattr' are 1675 - * more recent than the ones cached in the inode. 1676 - * 1674 + * We assume that the server observes monotonic semantics for 1675 + * the change attribute, so a larger value means that the attributes in 1676 + * @fattr are more recent, in which case the function returns the 1677 + * value '1'. 1678 + * A return value of '0' indicates no measurable change 1679 + * A return value of '-1' means that the attributes in @inode are 1680 + * more recent. 1677 1681 */ 1678 - static int nfs_inode_attrs_need_update(const struct inode *inode, const struct nfs_fattr *fattr) 1682 + static int nfs_inode_attrs_cmp_monotonic(const struct nfs_fattr *fattr, 1683 + const struct inode *inode) 1679 1684 { 1680 - const struct nfs_inode *nfsi = NFS_I(inode); 1681 - 1682 - return ((long)fattr->gencount - (long)nfsi->attr_gencount) > 0 || 1683 - ((long)nfsi->attr_gencount - (long)nfs_read_attr_generation_counter() > 0); 1685 + s64 diff = fattr->change_attr - inode_peek_iversion_raw(inode); 1686 + if (diff > 0) 1687 + return 1; 1688 + return diff == 0 ? 0 : -1; 1684 1689 } 1685 1690 1686 - static int nfs_refresh_inode_locked(struct inode *inode, struct nfs_fattr *fattr) 1691 + /** 1692 + * nfs_inode_attrs_cmp_strict_monotonic - compare attributes 1693 + * @fattr: attributes 1694 + * @inode: pointer to inode 1695 + * 1696 + * Attempt to divine whether or not an RPC call reply carrying stale 1697 + * attributes got scheduled after another call carrying updated ones. 1698 + * 1699 + * We assume that the server observes strictly monotonic semantics for 1700 + * the change attribute, so a larger value means that the attributes in 1701 + * @fattr are more recent, in which case the function returns the 1702 + * value '1'. 1703 + * A return value of '-1' means that the attributes in @inode are 1704 + * more recent or unchanged. 1705 + */ 1706 + static int nfs_inode_attrs_cmp_strict_monotonic(const struct nfs_fattr *fattr, 1707 + const struct inode *inode) 1687 1708 { 1688 - int ret; 1709 + return nfs_inode_attrs_cmp_monotonic(fattr, inode) > 0 ? 1 : -1; 1710 + } 1711 + 1712 + /** 1713 + * nfs_inode_attrs_cmp - compare attributes 1714 + * @fattr: attributes 1715 + * @inode: pointer to inode 1716 + * 1717 + * This function returns '1' if it thinks the attributes in @fattr are 1718 + * more recent than the ones cached in @inode. It returns '-1' if 1719 + * the attributes in @inode are more recent than the ones in @fattr, 1720 + * and it returns 0 if not sure. 1721 + */ 1722 + static int nfs_inode_attrs_cmp(const struct nfs_fattr *fattr, 1723 + const struct inode *inode) 1724 + { 1725 + if (nfs_inode_attrs_cmp_generic(fattr, inode) > 0) 1726 + return 1; 1727 + switch (NFS_SERVER(inode)->change_attr_type) { 1728 + case NFS4_CHANGE_TYPE_IS_UNDEFINED: 1729 + break; 1730 + case NFS4_CHANGE_TYPE_IS_TIME_METADATA: 1731 + if (!(fattr->valid & NFS_ATTR_FATTR_CHANGE)) 1732 + break; 1733 + return nfs_inode_attrs_cmp_monotonic(fattr, inode); 1734 + default: 1735 + if (!(fattr->valid & NFS_ATTR_FATTR_CHANGE)) 1736 + break; 1737 + return nfs_inode_attrs_cmp_strict_monotonic(fattr, inode); 1738 + } 1739 + return 0; 1740 + } 1741 + 1742 + /** 1743 + * nfs_inode_finish_partial_attr_update - complete a previous inode update 1744 + * @fattr: attributes 1745 + * @inode: pointer to inode 1746 + * 1747 + * Returns '1' if the last attribute update left the inode cached 1748 + * attributes in a partially unrevalidated state, and @fattr 1749 + * matches the change attribute of that partial update. 1750 + * Otherwise returns '0'. 1751 + */ 1752 + static int nfs_inode_finish_partial_attr_update(const struct nfs_fattr *fattr, 1753 + const struct inode *inode) 1754 + { 1755 + const unsigned long check_valid = 1756 + NFS_INO_INVALID_ATIME | NFS_INO_INVALID_CTIME | 1757 + NFS_INO_INVALID_MTIME | NFS_INO_INVALID_SIZE | 1758 + NFS_INO_INVALID_BLOCKS | NFS_INO_INVALID_OTHER | 1759 + NFS_INO_INVALID_NLINK; 1760 + unsigned long cache_validity = NFS_I(inode)->cache_validity; 1761 + 1762 + if (!(cache_validity & NFS_INO_INVALID_CHANGE) && 1763 + (cache_validity & check_valid) != 0 && 1764 + (fattr->valid & NFS_ATTR_FATTR_CHANGE) != 0 && 1765 + nfs_inode_attrs_cmp_monotonic(fattr, inode) == 0) 1766 + return 1; 1767 + return 0; 1768 + } 1769 + 1770 + static int nfs_refresh_inode_locked(struct inode *inode, 1771 + struct nfs_fattr *fattr) 1772 + { 1773 + int attr_cmp = nfs_inode_attrs_cmp(fattr, inode); 1774 + int ret = 0; 1689 1775 1690 1776 trace_nfs_refresh_inode_enter(inode); 1691 1777 1692 - if (nfs_inode_attrs_need_update(inode, fattr)) 1778 + if (attr_cmp > 0 || nfs_inode_finish_partial_attr_update(fattr, inode)) 1693 1779 ret = nfs_update_inode(inode, fattr); 1694 - else 1780 + else if (attr_cmp == 0) 1695 1781 ret = nfs_check_inode_attributes(inode, fattr); 1696 1782 1697 1783 trace_nfs_refresh_inode_exit(inode, ret); ··· 1877 1761 */ 1878 1762 int nfs_post_op_update_inode_force_wcc_locked(struct inode *inode, struct nfs_fattr *fattr) 1879 1763 { 1764 + int attr_cmp = nfs_inode_attrs_cmp(fattr, inode); 1880 1765 int status; 1881 1766 1882 1767 /* Don't do a WCC update if these attributes are already stale */ 1883 - if ((fattr->valid & NFS_ATTR_FATTR) == 0 || 1884 - !nfs_inode_attrs_need_update(inode, fattr)) { 1768 + if (attr_cmp < 0) 1769 + return 0; 1770 + if ((fattr->valid & NFS_ATTR_FATTR) == 0 || !attr_cmp) { 1885 1771 fattr->valid &= ~(NFS_ATTR_FATTR_PRECHANGE 1886 1772 | NFS_ATTR_FATTR_PRESIZE 1887 1773 | NFS_ATTR_FATTR_PREMTIME ··· 1957 1839 */ 1958 1840 static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr) 1959 1841 { 1960 - struct nfs_server *server; 1842 + struct nfs_server *server = NFS_SERVER(inode); 1961 1843 struct nfs_inode *nfsi = NFS_I(inode); 1962 1844 loff_t cur_isize, new_isize; 1845 + u64 fattr_supported = server->fattr_valid; 1963 1846 unsigned long invalid = 0; 1964 1847 unsigned long now = jiffies; 1965 1848 unsigned long save_cache_validity; ··· 2004 1885 goto out_err; 2005 1886 } 2006 1887 2007 - server = NFS_SERVER(inode); 2008 1888 /* Update the fsid? */ 2009 1889 if (S_ISDIR(inode->i_mode) && (fattr->valid & NFS_ATTR_FATTR_FSID) && 2010 1890 !nfs_fsid_equal(&server->fsid, &fattr->fsid) && ··· 2022 1904 nfsi->cache_validity &= ~(NFS_INO_INVALID_ATTR 2023 1905 | NFS_INO_INVALID_ATIME 2024 1906 | NFS_INO_REVAL_FORCED 2025 - | NFS_INO_REVAL_PAGECACHE 2026 1907 | NFS_INO_INVALID_BLOCKS); 2027 1908 2028 1909 /* Do atomic weak cache consistency updates */ 2029 1910 nfs_wcc_update_inode(inode, fattr); 2030 1911 2031 1912 if (pnfs_layoutcommit_outstanding(inode)) { 2032 - nfsi->cache_validity |= save_cache_validity & NFS_INO_INVALID_ATTR; 1913 + nfsi->cache_validity |= 1914 + save_cache_validity & 1915 + (NFS_INO_INVALID_CHANGE | NFS_INO_INVALID_CTIME | 1916 + NFS_INO_INVALID_MTIME | NFS_INO_INVALID_SIZE | 1917 + NFS_INO_INVALID_BLOCKS); 2033 1918 cache_revalidated = false; 2034 1919 } 2035 1920 ··· 2049 1928 save_cache_validity |= NFS_INO_INVALID_CTIME 2050 1929 | NFS_INO_INVALID_MTIME 2051 1930 | NFS_INO_INVALID_SIZE 1931 + | NFS_INO_INVALID_BLOCKS 1932 + | NFS_INO_INVALID_NLINK 1933 + | NFS_INO_INVALID_MODE 2052 1934 | NFS_INO_INVALID_OTHER; 2053 1935 if (S_ISDIR(inode->i_mode)) 2054 1936 nfs_force_lookup_revalidate(inode); ··· 2064 1940 attr_changed = true; 2065 1941 } 2066 1942 } else { 2067 - nfsi->cache_validity |= save_cache_validity & 2068 - (NFS_INO_INVALID_CHANGE 2069 - | NFS_INO_REVAL_PAGECACHE 2070 - | NFS_INO_REVAL_FORCED); 1943 + nfsi->cache_validity |= 1944 + save_cache_validity & NFS_INO_INVALID_CHANGE; 2071 1945 cache_revalidated = false; 2072 1946 } 2073 1947 2074 1948 if (fattr->valid & NFS_ATTR_FATTR_MTIME) { 2075 1949 inode->i_mtime = fattr->mtime; 2076 - } else if (server->caps & NFS_CAP_MTIME) { 2077 - nfsi->cache_validity |= save_cache_validity & 2078 - (NFS_INO_INVALID_MTIME 2079 - | NFS_INO_REVAL_FORCED); 1950 + } else if (fattr_supported & NFS_ATTR_FATTR_MTIME) { 1951 + nfsi->cache_validity |= 1952 + save_cache_validity & NFS_INO_INVALID_MTIME; 2080 1953 cache_revalidated = false; 2081 1954 } 2082 1955 2083 1956 if (fattr->valid & NFS_ATTR_FATTR_CTIME) { 2084 1957 inode->i_ctime = fattr->ctime; 2085 - } else if (server->caps & NFS_CAP_CTIME) { 2086 - nfsi->cache_validity |= save_cache_validity & 2087 - (NFS_INO_INVALID_CTIME 2088 - | NFS_INO_REVAL_FORCED); 1958 + } else if (fattr_supported & NFS_ATTR_FATTR_CTIME) { 1959 + nfsi->cache_validity |= 1960 + save_cache_validity & NFS_INO_INVALID_CTIME; 2089 1961 cache_revalidated = false; 2090 1962 } 2091 1963 ··· 2105 1985 (long long)cur_isize, 2106 1986 (long long)new_isize); 2107 1987 } 1988 + if (new_isize == 0 && 1989 + !(fattr->valid & (NFS_ATTR_FATTR_SPACE_USED | 1990 + NFS_ATTR_FATTR_BLOCKS_USED))) { 1991 + fattr->du.nfs3.used = 0; 1992 + fattr->valid |= NFS_ATTR_FATTR_SPACE_USED; 1993 + } 2108 1994 } else { 2109 - nfsi->cache_validity |= save_cache_validity & 2110 - (NFS_INO_INVALID_SIZE 2111 - | NFS_INO_REVAL_PAGECACHE 2112 - | NFS_INO_REVAL_FORCED); 1995 + nfsi->cache_validity |= 1996 + save_cache_validity & NFS_INO_INVALID_SIZE; 2113 1997 cache_revalidated = false; 2114 1998 } 2115 1999 2116 - 2117 2000 if (fattr->valid & NFS_ATTR_FATTR_ATIME) 2118 2001 inode->i_atime = fattr->atime; 2119 - else if (server->caps & NFS_CAP_ATIME) { 2120 - nfsi->cache_validity |= save_cache_validity & 2121 - (NFS_INO_INVALID_ATIME 2122 - | NFS_INO_REVAL_FORCED); 2002 + else if (fattr_supported & NFS_ATTR_FATTR_ATIME) { 2003 + nfsi->cache_validity |= 2004 + save_cache_validity & NFS_INO_INVALID_ATIME; 2123 2005 cache_revalidated = false; 2124 2006 } 2125 2007 ··· 2134 2012 | NFS_INO_INVALID_ACL; 2135 2013 attr_changed = true; 2136 2014 } 2137 - } else if (server->caps & NFS_CAP_MODE) { 2138 - nfsi->cache_validity |= save_cache_validity & 2139 - (NFS_INO_INVALID_OTHER 2140 - | NFS_INO_REVAL_FORCED); 2015 + } else if (fattr_supported & NFS_ATTR_FATTR_MODE) { 2016 + nfsi->cache_validity |= 2017 + save_cache_validity & NFS_INO_INVALID_MODE; 2141 2018 cache_revalidated = false; 2142 2019 } 2143 2020 ··· 2147 2026 inode->i_uid = fattr->uid; 2148 2027 attr_changed = true; 2149 2028 } 2150 - } else if (server->caps & NFS_CAP_OWNER) { 2151 - nfsi->cache_validity |= save_cache_validity & 2152 - (NFS_INO_INVALID_OTHER 2153 - | NFS_INO_REVAL_FORCED); 2029 + } else if (fattr_supported & NFS_ATTR_FATTR_OWNER) { 2030 + nfsi->cache_validity |= 2031 + save_cache_validity & NFS_INO_INVALID_OTHER; 2154 2032 cache_revalidated = false; 2155 2033 } 2156 2034 ··· 2160 2040 inode->i_gid = fattr->gid; 2161 2041 attr_changed = true; 2162 2042 } 2163 - } else if (server->caps & NFS_CAP_OWNER_GROUP) { 2164 - nfsi->cache_validity |= save_cache_validity & 2165 - (NFS_INO_INVALID_OTHER 2166 - | NFS_INO_REVAL_FORCED); 2043 + } else if (fattr_supported & NFS_ATTR_FATTR_GROUP) { 2044 + nfsi->cache_validity |= 2045 + save_cache_validity & NFS_INO_INVALID_OTHER; 2167 2046 cache_revalidated = false; 2168 2047 } 2169 2048 ··· 2173 2054 set_nlink(inode, fattr->nlink); 2174 2055 attr_changed = true; 2175 2056 } 2176 - } else if (server->caps & NFS_CAP_NLINK) { 2177 - nfsi->cache_validity |= save_cache_validity & 2178 - (NFS_INO_INVALID_OTHER 2179 - | NFS_INO_REVAL_FORCED); 2057 + } else if (fattr_supported & NFS_ATTR_FATTR_NLINK) { 2058 + nfsi->cache_validity |= 2059 + save_cache_validity & NFS_INO_INVALID_NLINK; 2180 2060 cache_revalidated = false; 2181 2061 } 2182 2062 ··· 2184 2066 * report the blocks in 512byte units 2185 2067 */ 2186 2068 inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used); 2187 - } else if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED) 2069 + } else if (fattr_supported & NFS_ATTR_FATTR_SPACE_USED) { 2070 + nfsi->cache_validity |= 2071 + save_cache_validity & NFS_INO_INVALID_BLOCKS; 2072 + cache_revalidated = false; 2073 + } 2074 + 2075 + if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED) { 2188 2076 inode->i_blocks = fattr->du.nfs2.blocks; 2189 - else { 2190 - nfsi->cache_validity |= save_cache_validity & 2191 - (NFS_INO_INVALID_BLOCKS 2192 - | NFS_INO_REVAL_FORCED); 2077 + } else if (fattr_supported & NFS_ATTR_FATTR_BLOCKS_USED) { 2078 + nfsi->cache_validity |= 2079 + save_cache_validity & NFS_INO_INVALID_BLOCKS; 2193 2080 cache_revalidated = false; 2194 2081 } 2195 2082 2196 2083 /* Update attrtimeo value if we're out of the unstable period */ 2197 2084 if (attr_changed) { 2198 - invalid &= ~NFS_INO_INVALID_ATTR; 2199 2085 nfs_inc_stats(inode, NFSIOS_ATTRINVALIDATE); 2200 2086 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode); 2201 2087 nfsi->attrtimeo_timestamp = now; ··· 2216 2094 nfsi->attrtimeo_timestamp = now; 2217 2095 } 2218 2096 /* Set the barrier to be more recent than this fattr */ 2219 - if ((long)fattr->gencount - (long)nfsi->attr_gencount > 0) 2097 + if ((long)(fattr->gencount - nfsi->attr_gencount) > 0) 2220 2098 nfsi->attr_gencount = fattr->gencount; 2221 2099 } 2222 2100
+1 -1
fs/nfs/internal.h
··· 181 181 struct net *net; 182 182 }; 183 183 184 - extern int nfs_mount(struct nfs_mount_request *info); 184 + extern int nfs_mount(struct nfs_mount_request *info, int timeo, int retrans); 185 185 extern void nfs_umount(const struct nfs_mount_request *info); 186 186 187 187 /* client.c */
+1 -1
fs/nfs/io.c
··· 104 104 } 105 105 106 106 /** 107 - * nfs_end_io_direct - declare the file is being used for direct i/o 107 + * nfs_start_io_direct - declare the file is being used for direct i/o 108 108 * @inode: file inode 109 109 * 110 110 * Declare that a direct I/O operation is about to start, and ensure
+9 -5
fs/nfs/mount_clnt.c
··· 136 136 /** 137 137 * nfs_mount - Obtain an NFS file handle for the given host and path 138 138 * @info: pointer to mount request arguments 139 + * @timeo: deciseconds the mount waits for a response before it retries 140 + * @retrans: number of times the mount retries a request 139 141 * 140 - * Uses default timeout parameters specified by underlying transport. On 141 - * successful return, the auth_flavs list and auth_flav_len will be populated 142 - * with the list from the server or a faked-up list if the server didn't 143 - * provide one. 142 + * Uses timeout parameters specified by caller. On successful return, the 143 + * auth_flavs list and auth_flav_len will be populated with the list from the 144 + * server or a faked-up list if the server didn't provide one. 144 145 */ 145 - int nfs_mount(struct nfs_mount_request *info) 146 + int nfs_mount(struct nfs_mount_request *info, int timeo, int retrans) 146 147 { 148 + struct rpc_timeout mnt_timeout; 147 149 struct mountres result = { 148 150 .fh = info->fh, 149 151 .auth_count = info->auth_flav_len, ··· 160 158 .protocol = info->protocol, 161 159 .address = info->sap, 162 160 .addrsize = info->salen, 161 + .timeout = &mnt_timeout, 163 162 .servername = info->hostname, 164 163 .program = &mnt_program, 165 164 .version = info->version, ··· 180 177 if (info->noresvport) 181 178 args.flags |= RPC_CLNT_CREATE_NONPRIVPORT; 182 179 180 + nfs_init_timeout_values(&mnt_timeout, info->protocol, timeo, retrans); 183 181 mnt_clnt = rpc_create(&args); 184 182 if (IS_ERR(mnt_clnt)) 185 183 goto out_clnt_err;
+1 -1
fs/nfs/nfs3acl.c
··· 65 65 if (!nfs_server_capable(inode, NFS_CAP_ACLS)) 66 66 return ERR_PTR(-EOPNOTSUPP); 67 67 68 - status = nfs_revalidate_inode(server, inode); 68 + status = nfs_revalidate_inode(inode, NFS_INO_INVALID_CHANGE); 69 69 if (status < 0) 70 70 return ERR_PTR(status); 71 71
+3 -2
fs/nfs/nfs3xdr.c
··· 433 433 if (unlikely(!p)) 434 434 return -EIO; 435 435 length = be32_to_cpup(p++); 436 - if (unlikely(length > NFS3_FHSIZE)) 436 + if (unlikely(length > NFS3_FHSIZE || length == 0)) 437 437 goto out_toobig; 438 438 p = xdr_inline_decode(xdr, length); 439 439 if (unlikely(!p)) ··· 442 442 memcpy(fh->data, p, length); 443 443 return 0; 444 444 out_toobig: 445 - dprintk("NFS: file handle size (%u) too big\n", length); 445 + trace_nfs_xdr_bad_filehandle(xdr, NFSERR_BADHANDLE); 446 446 return -E2BIG; 447 447 } 448 448 ··· 2227 2227 2228 2228 /* ignore properties */ 2229 2229 result->lease_time = 0; 2230 + result->change_attr_type = NFS4_CHANGE_TYPE_IS_TIME_METADATA; 2230 2231 return 0; 2231 2232 } 2232 2233
+53 -24
fs/nfs/nfs42proc.c
··· 46 46 { 47 47 struct inode *inode = file_inode(filep); 48 48 struct nfs_server *server = NFS_SERVER(inode); 49 + u32 bitmask[3]; 49 50 struct nfs42_falloc_args args = { 50 51 .falloc_fh = NFS_FH(inode), 51 52 .falloc_offset = offset, 52 53 .falloc_length = len, 53 - .falloc_bitmask = nfs4_fattr_bitmap, 54 + .falloc_bitmask = bitmask, 54 55 }; 55 56 struct nfs42_falloc_res res = { 56 57 .falloc_server = server, ··· 69 68 return status; 70 69 } 71 70 71 + memcpy(bitmask, server->cache_consistency_bitmask, sizeof(bitmask)); 72 + if (server->attr_bitmask[1] & FATTR4_WORD1_SPACE_USED) 73 + bitmask[1] |= FATTR4_WORD1_SPACE_USED; 74 + 72 75 res.falloc_fattr = nfs_alloc_fattr(); 73 76 if (!res.falloc_fattr) 74 77 return -ENOMEM; ··· 80 75 status = nfs4_call_sync(server->client, server, msg, 81 76 &args.seq_args, &res.seq_res, 0); 82 77 if (status == 0) 83 - status = nfs_post_op_update_inode(inode, res.falloc_fattr); 78 + status = nfs_post_op_update_inode_force_wcc(inode, 79 + res.falloc_fattr); 84 80 85 81 kfree(res.falloc_fattr); 86 82 return status; ··· 90 84 static int nfs42_proc_fallocate(struct rpc_message *msg, struct file *filep, 91 85 loff_t offset, loff_t len) 92 86 { 93 - struct nfs_server *server = NFS_SERVER(file_inode(filep)); 87 + struct inode *inode = file_inode(filep); 88 + struct nfs_server *server = NFS_SERVER(inode); 94 89 struct nfs4_exception exception = { }; 95 90 struct nfs_lock_context *lock; 96 91 int err; ··· 100 93 if (IS_ERR(lock)) 101 94 return PTR_ERR(lock); 102 95 103 - exception.inode = file_inode(filep); 96 + exception.inode = inode; 104 97 exception.state = lock->open_context->state; 98 + 99 + err = nfs_sync_inode(inode); 100 + if (err) 101 + goto out; 105 102 106 103 do { 107 104 err = _nfs42_proc_fallocate(msg, filep, lock, offset, len); ··· 115 104 } 116 105 err = nfs4_handle_exception(server, err, &exception); 117 106 } while (exception.retry); 118 - 107 + out: 119 108 nfs_put_lock_context(lock); 120 109 return err; 121 110 } ··· 153 142 return -EOPNOTSUPP; 154 143 155 144 inode_lock(inode); 156 - err = nfs_sync_inode(inode); 157 - if (err) 158 - goto out_unlock; 159 145 160 146 err = nfs42_proc_fallocate(&msg, filep, offset, len); 161 147 if (err == 0) 162 148 truncate_pagecache_range(inode, offset, (offset + len) -1); 163 149 if (err == -EOPNOTSUPP) 164 150 NFS_SERVER(inode)->caps &= ~NFS_CAP_DEALLOCATE; 165 - out_unlock: 151 + 166 152 inode_unlock(inode); 167 153 return err; 168 154 } ··· 269 261 return status; 270 262 } 271 263 264 + /** 265 + * nfs42_copy_dest_done - perform inode cache updates after clone/copy offload 266 + * @inode: pointer to destination inode 267 + * @pos: destination offset 268 + * @len: copy length 269 + * 270 + * Punch a hole in the inode page cache, so that the NFS client will 271 + * know to retrieve new data. 272 + * Update the file size if necessary, and then mark the inode as having 273 + * invalid cached values for change attribute, ctime, mtime and space used. 274 + */ 275 + static void nfs42_copy_dest_done(struct inode *inode, loff_t pos, loff_t len) 276 + { 277 + loff_t newsize = pos + len; 278 + loff_t end = newsize - 1; 279 + 280 + truncate_pagecache_range(inode, pos, end); 281 + spin_lock(&inode->i_lock); 282 + if (newsize > i_size_read(inode)) 283 + i_size_write(inode, newsize); 284 + nfs_set_cache_invalid(inode, NFS_INO_INVALID_CHANGE | 285 + NFS_INO_INVALID_CTIME | 286 + NFS_INO_INVALID_MTIME | 287 + NFS_INO_INVALID_BLOCKS); 288 + spin_unlock(&inode->i_lock); 289 + } 290 + 272 291 static ssize_t _nfs42_proc_copy(struct file *src, 273 292 struct nfs_lock_context *src_lock, 274 293 struct file *dst, ··· 389 354 goto out; 390 355 } 391 356 392 - truncate_pagecache_range(dst_inode, pos_dst, 393 - pos_dst + res->write_res.count); 394 - spin_lock(&dst_inode->i_lock); 395 - nfs_set_cache_invalid( 396 - dst_inode, NFS_INO_REVAL_PAGECACHE | NFS_INO_REVAL_FORCED | 397 - NFS_INO_INVALID_SIZE | NFS_INO_INVALID_ATTR | 398 - NFS_INO_INVALID_DATA); 399 - spin_unlock(&dst_inode->i_lock); 400 - spin_lock(&src_inode->i_lock); 401 - nfs_set_cache_invalid(src_inode, NFS_INO_REVAL_PAGECACHE | 402 - NFS_INO_REVAL_FORCED | 403 - NFS_INO_INVALID_ATIME); 404 - spin_unlock(&src_inode->i_lock); 357 + nfs42_copy_dest_done(dst_inode, pos_dst, res->write_res.count); 358 + nfs_invalidate_atime(src_inode); 405 359 status = res->write_res.count; 406 360 out: 407 361 if (args->sync) ··· 683 659 if (status) 684 660 return status; 685 661 686 - return vfs_setpos(filep, res.sr_offset, inode->i_sb->s_maxbytes); 662 + if (whence == SEEK_DATA && res.sr_eof) 663 + return -NFS4ERR_NXIO; 664 + else 665 + return vfs_setpos(filep, res.sr_offset, inode->i_sb->s_maxbytes); 687 666 } 688 667 689 668 loff_t nfs42_proc_llseek(struct file *filep, loff_t offset, int whence) ··· 1071 1044 1072 1045 status = nfs4_call_sync(server->client, server, msg, 1073 1046 &args.seq_args, &res.seq_res, 0); 1074 - if (status == 0) 1047 + if (status == 0) { 1048 + nfs42_copy_dest_done(dst_inode, dst_offset, count); 1075 1049 status = nfs_post_op_update_inode(dst_inode, res.dst_fattr); 1050 + } 1076 1051 1077 1052 kfree(res.dst_fattr); 1078 1053 return status;
+1 -1
fs/nfs/nfs42xattr.c
··· 168 168 * make it easier to copy the value after an RPC, even if 169 169 * the value will not be passed up to application (e.g. 170 170 * for a 'query' getxattr with NULL buffer). 171 - * @len: Length of the value. Can be 0 for zero-length attribues. 171 + * @len: Length of the value. Can be 0 for zero-length attributes. 172 172 * @value and @pages will be NULL if @len is 0. 173 173 */ 174 174 static struct nfs4_xattr_entry *
-4
fs/nfs/nfs4file.c
··· 420 420 */ 421 421 void nfs42_ssc_register_ops(void) 422 422 { 423 - #ifdef CONFIG_NFSD_V4 424 423 nfs42_ssc_register(&nfs4_ssc_clnt_ops_tbl); 425 - #endif 426 424 } 427 425 428 426 /** ··· 431 433 */ 432 434 void nfs42_ssc_unregister_ops(void) 433 435 { 434 - #ifdef CONFIG_NFSD_V4 435 436 nfs42_ssc_unregister(&nfs4_ssc_clnt_ops_tbl); 436 - #endif 437 437 } 438 438 #endif /* CONFIG_NFS_V4_2 */ 439 439
+148 -116
fs/nfs/nfs4proc.c
··· 108 108 static int nfs41_free_stateid(struct nfs_server *, const nfs4_stateid *, 109 109 const struct cred *, bool); 110 110 #endif 111 - static void nfs4_bitmask_adjust(__u32 *bitmask, struct inode *inode, 112 - struct nfs_server *server, 113 - struct nfs4_label *label); 111 + static void nfs4_bitmask_set(__u32 bitmask[NFS4_BITMASK_SZ], 112 + const __u32 *src, struct inode *inode, 113 + struct nfs_server *server, 114 + struct nfs4_label *label); 114 115 115 116 #ifdef CONFIG_NFS_V4_SECURITY_LABEL 116 117 static inline struct nfs4_label * ··· 264 263 | FATTR4_WORD1_FS_LAYOUT_TYPES, 265 264 FATTR4_WORD2_LAYOUT_BLKSIZE 266 265 | FATTR4_WORD2_CLONE_BLKSIZE 266 + | FATTR4_WORD2_CHANGE_ATTR_TYPE 267 267 | FATTR4_WORD2_XATTR_SUPPORT 268 268 }; 269 269 ··· 285 283 }; 286 284 287 285 static void nfs4_bitmap_copy_adjust(__u32 *dst, const __u32 *src, 288 - struct inode *inode) 286 + struct inode *inode, unsigned long flags) 289 287 { 290 288 unsigned long cache_validity; 291 289 ··· 293 291 if (!inode || !nfs4_have_delegation(inode, FMODE_READ)) 294 292 return; 295 293 296 - cache_validity = READ_ONCE(NFS_I(inode)->cache_validity); 297 - if (!(cache_validity & NFS_INO_REVAL_FORCED)) 298 - cache_validity &= ~(NFS_INO_INVALID_CHANGE 299 - | NFS_INO_INVALID_SIZE); 294 + cache_validity = READ_ONCE(NFS_I(inode)->cache_validity) | flags; 300 295 296 + /* Remove the attributes over which we have full control */ 297 + dst[1] &= ~FATTR4_WORD1_RAWDEV; 301 298 if (!(cache_validity & NFS_INO_INVALID_SIZE)) 302 299 dst[0] &= ~FATTR4_WORD0_SIZE; 303 300 304 301 if (!(cache_validity & NFS_INO_INVALID_CHANGE)) 305 302 dst[0] &= ~FATTR4_WORD0_CHANGE; 306 - } 307 303 308 - static void nfs4_bitmap_copy_adjust_setattr(__u32 *dst, 309 - const __u32 *src, struct inode *inode) 310 - { 311 - nfs4_bitmap_copy_adjust(dst, src, inode); 304 + if (!(cache_validity & NFS_INO_INVALID_MODE)) 305 + dst[1] &= ~FATTR4_WORD1_MODE; 306 + if (!(cache_validity & NFS_INO_INVALID_OTHER)) 307 + dst[1] &= ~(FATTR4_WORD1_OWNER | FATTR4_WORD1_OWNER_GROUP); 312 308 } 313 309 314 310 static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, ··· 1169 1169 static void 1170 1170 nfs4_inc_nlink_locked(struct inode *inode) 1171 1171 { 1172 - nfs_set_cache_invalid(inode, NFS_INO_INVALID_OTHER); 1172 + nfs_set_cache_invalid(inode, NFS_INO_INVALID_CHANGE | 1173 + NFS_INO_INVALID_CTIME | 1174 + NFS_INO_INVALID_NLINK); 1173 1175 inc_nlink(inode); 1176 + } 1177 + 1178 + static void 1179 + nfs4_inc_nlink(struct inode *inode) 1180 + { 1181 + spin_lock(&inode->i_lock); 1182 + nfs4_inc_nlink_locked(inode); 1183 + spin_unlock(&inode->i_lock); 1174 1184 } 1175 1185 1176 1186 static void 1177 1187 nfs4_dec_nlink_locked(struct inode *inode) 1178 1188 { 1179 - nfs_set_cache_invalid(inode, NFS_INO_INVALID_OTHER); 1189 + nfs_set_cache_invalid(inode, NFS_INO_INVALID_CHANGE | 1190 + NFS_INO_INVALID_CTIME | 1191 + NFS_INO_INVALID_NLINK); 1180 1192 drop_nlink(inode); 1181 1193 } 1182 1194 ··· 1198 1186 unsigned long timestamp, unsigned long cache_validity) 1199 1187 { 1200 1188 struct nfs_inode *nfsi = NFS_I(inode); 1189 + u64 change_attr = inode_peek_iversion_raw(inode); 1201 1190 1202 1191 cache_validity |= NFS_INO_INVALID_CTIME | NFS_INO_INVALID_MTIME; 1203 1192 1204 - if (cinfo->atomic && cinfo->before == inode_peek_iversion_raw(inode)) { 1205 - nfsi->cache_validity &= ~NFS_INO_REVAL_PAGECACHE; 1193 + switch (NFS_SERVER(inode)->change_attr_type) { 1194 + case NFS4_CHANGE_TYPE_IS_UNDEFINED: 1195 + break; 1196 + case NFS4_CHANGE_TYPE_IS_TIME_METADATA: 1197 + if ((s64)(change_attr - cinfo->after) > 0) 1198 + goto out; 1199 + break; 1200 + default: 1201 + if ((s64)(change_attr - cinfo->after) >= 0) 1202 + goto out; 1203 + } 1204 + 1205 + if (cinfo->atomic && cinfo->before == change_attr) { 1206 1206 nfsi->attrtimeo_timestamp = jiffies; 1207 1207 } else { 1208 1208 if (S_ISDIR(inode->i_mode)) { ··· 1226 1202 cache_validity |= NFS_INO_REVAL_PAGECACHE; 1227 1203 } 1228 1204 1229 - if (cinfo->before != inode_peek_iversion_raw(inode)) 1205 + if (cinfo->before != change_attr) 1230 1206 cache_validity |= NFS_INO_INVALID_ACCESS | 1231 1207 NFS_INO_INVALID_ACL | 1232 1208 NFS_INO_INVALID_XATTR; ··· 1234 1210 inode_set_iversion_raw(inode, cinfo->after); 1235 1211 nfsi->read_cache_jiffies = timestamp; 1236 1212 nfsi->attr_gencount = nfs_inc_attr_generation_counter(); 1237 - nfs_set_cache_invalid(inode, cache_validity); 1238 1213 nfsi->cache_validity &= ~NFS_INO_INVALID_CHANGE; 1214 + out: 1215 + nfs_set_cache_invalid(inode, cache_validity); 1239 1216 } 1240 1217 1241 1218 void ··· 3369 3344 .inode = inode, 3370 3345 .stateid = &arg.stateid, 3371 3346 }; 3347 + unsigned long adjust_flags = NFS_INO_INVALID_CHANGE; 3372 3348 int err; 3373 3349 3350 + if (sattr->ia_valid & (ATTR_MODE | ATTR_KILL_SUID | ATTR_KILL_SGID)) 3351 + adjust_flags |= NFS_INO_INVALID_MODE; 3352 + if (sattr->ia_valid & (ATTR_UID | ATTR_GID)) 3353 + adjust_flags |= NFS_INO_INVALID_OTHER; 3354 + 3374 3355 do { 3375 - nfs4_bitmap_copy_adjust_setattr(bitmask, 3376 - nfs4_bitmask(server, olabel), 3377 - inode); 3356 + nfs4_bitmap_copy_adjust(bitmask, nfs4_bitmask(server, olabel), 3357 + inode, adjust_flags); 3378 3358 3379 3359 err = _nfs4_do_setattr(inode, &arg, &res, cred, ctx); 3380 3360 switch (err) { ··· 3621 3591 struct nfs4_closedata *calldata = data; 3622 3592 struct nfs4_state *state = calldata->state; 3623 3593 struct inode *inode = calldata->inode; 3594 + struct nfs_server *server = NFS_SERVER(inode); 3624 3595 struct pnfs_layout_hdr *lo; 3625 3596 bool is_rdonly, is_wronly, is_rdwr; 3626 3597 int call_close = 0; ··· 3678 3647 if (calldata->arg.fmode == 0 || calldata->arg.fmode == FMODE_READ) { 3679 3648 /* Close-to-open cache consistency revalidation */ 3680 3649 if (!nfs4_have_delegation(inode, FMODE_READ)) { 3681 - calldata->arg.bitmask = NFS_SERVER(inode)->cache_consistency_bitmask; 3682 - nfs4_bitmask_adjust(calldata->arg.bitmask, inode, NFS_SERVER(inode), NULL); 3650 + nfs4_bitmask_set(calldata->arg.bitmask_store, 3651 + server->cache_consistency_bitmask, 3652 + inode, server, NULL); 3653 + calldata->arg.bitmask = calldata->arg.bitmask_store; 3683 3654 } else 3684 3655 calldata->arg.bitmask = NULL; 3685 3656 } ··· 3868 3835 res.attr_bitmask[2] &= FATTR4_WORD2_NFS42_MASK; 3869 3836 } 3870 3837 memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); 3871 - server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| 3872 - NFS_CAP_SYMLINKS|NFS_CAP_FILEID| 3873 - NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| 3874 - NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| 3875 - NFS_CAP_CTIME|NFS_CAP_MTIME| 3876 - NFS_CAP_SECURITY_LABEL); 3838 + server->caps &= ~(NFS_CAP_ACLS | NFS_CAP_HARDLINKS | 3839 + NFS_CAP_SYMLINKS| NFS_CAP_SECURITY_LABEL); 3840 + server->fattr_valid = NFS_ATTR_FATTR_V4; 3877 3841 if (res.attr_bitmask[0] & FATTR4_WORD0_ACL && 3878 3842 res.acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) 3879 3843 server->caps |= NFS_CAP_ACLS; ··· 3878 3848 server->caps |= NFS_CAP_HARDLINKS; 3879 3849 if (res.has_symlinks != 0) 3880 3850 server->caps |= NFS_CAP_SYMLINKS; 3881 - if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) 3882 - server->caps |= NFS_CAP_FILEID; 3883 - if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) 3884 - server->caps |= NFS_CAP_MODE; 3885 - if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) 3886 - server->caps |= NFS_CAP_NLINK; 3887 - if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) 3888 - server->caps |= NFS_CAP_OWNER; 3889 - if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) 3890 - server->caps |= NFS_CAP_OWNER_GROUP; 3891 - if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) 3892 - server->caps |= NFS_CAP_ATIME; 3893 - if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) 3894 - server->caps |= NFS_CAP_CTIME; 3895 - if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) 3896 - server->caps |= NFS_CAP_MTIME; 3851 + if (!(res.attr_bitmask[0] & FATTR4_WORD0_FILEID)) 3852 + server->fattr_valid &= ~NFS_ATTR_FATTR_FILEID; 3853 + if (!(res.attr_bitmask[1] & FATTR4_WORD1_MODE)) 3854 + server->fattr_valid &= ~NFS_ATTR_FATTR_MODE; 3855 + if (!(res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS)) 3856 + server->fattr_valid &= ~NFS_ATTR_FATTR_NLINK; 3857 + if (!(res.attr_bitmask[1] & FATTR4_WORD1_OWNER)) 3858 + server->fattr_valid &= ~(NFS_ATTR_FATTR_OWNER | 3859 + NFS_ATTR_FATTR_OWNER_NAME); 3860 + if (!(res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP)) 3861 + server->fattr_valid &= ~(NFS_ATTR_FATTR_GROUP | 3862 + NFS_ATTR_FATTR_GROUP_NAME); 3863 + if (!(res.attr_bitmask[1] & FATTR4_WORD1_SPACE_USED)) 3864 + server->fattr_valid &= ~NFS_ATTR_FATTR_SPACE_USED; 3865 + if (!(res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS)) 3866 + server->fattr_valid &= ~NFS_ATTR_FATTR_ATIME; 3867 + if (!(res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA)) 3868 + server->fattr_valid &= ~NFS_ATTR_FATTR_CTIME; 3869 + if (!(res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY)) 3870 + server->fattr_valid &= ~NFS_ATTR_FATTR_MTIME; 3897 3871 #ifdef CONFIG_NFS_V4_SECURITY_LABEL 3898 - if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL) 3899 - server->caps |= NFS_CAP_SECURITY_LABEL; 3872 + if (!(res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL)) 3873 + server->fattr_valid &= ~NFS_ATTR_FATTR_V4_SECURITY_LABEL; 3900 3874 #endif 3901 3875 memcpy(server->attr_bitmask_nl, res.attr_bitmask, 3902 3876 sizeof(server->attr_bitmask)); ··· 4188 4154 if (inode && (server->flags & NFS_MOUNT_SOFTREVAL)) 4189 4155 task_flags |= RPC_TASK_TIMEOUT; 4190 4156 4191 - nfs4_bitmap_copy_adjust(bitmask, nfs4_bitmask(server, label), inode); 4192 - 4157 + nfs4_bitmap_copy_adjust(bitmask, nfs4_bitmask(server, label), inode, 0); 4193 4158 nfs_fattr_init(fattr); 4194 4159 nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 0); 4195 4160 return nfs4_do_call_sync(server->client, server, &msg, ··· 4615 4582 status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 1); 4616 4583 if (status == 0) { 4617 4584 spin_lock(&dir->i_lock); 4618 - nfs4_update_changeattr_locked(dir, &res.cinfo, timestamp, 4619 - NFS_INO_INVALID_DATA); 4620 4585 /* Removing a directory decrements nlink in the parent */ 4621 4586 if (ftype == NF4DIR && dir->i_nlink > 2) 4622 4587 nfs4_dec_nlink_locked(dir); 4588 + nfs4_update_changeattr_locked(dir, &res.cinfo, timestamp, 4589 + NFS_INO_INVALID_DATA); 4623 4590 spin_unlock(&dir->i_lock); 4624 4591 } 4625 4592 return status; ··· 4748 4715 /* Note: If we moved a directory, nlink will change */ 4749 4716 nfs4_update_changeattr(old_dir, &res->old_cinfo, 4750 4717 res->old_fattr->time_start, 4751 - NFS_INO_INVALID_OTHER | 4718 + NFS_INO_INVALID_NLINK | 4752 4719 NFS_INO_INVALID_DATA); 4753 4720 nfs4_update_changeattr(new_dir, &res->new_cinfo, 4754 4721 res->new_fattr->time_start, 4755 - NFS_INO_INVALID_OTHER | 4722 + NFS_INO_INVALID_NLINK | 4756 4723 NFS_INO_INVALID_DATA); 4757 4724 } else 4758 4725 nfs4_update_changeattr(old_dir, &res->old_cinfo, ··· 4794 4761 } 4795 4762 4796 4763 nfs4_inode_make_writeable(inode); 4797 - nfs4_bitmap_copy_adjust_setattr(bitmask, nfs4_bitmask(server, res.label), inode); 4798 - 4764 + nfs4_bitmap_copy_adjust(bitmask, nfs4_bitmask(server, res.label), inode, 4765 + NFS_INO_INVALID_CHANGE); 4799 4766 status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1); 4800 4767 if (!status) { 4801 4768 nfs4_update_changeattr(dir, &res.cinfo, res.fattr->time_start, 4802 4769 NFS_INO_INVALID_DATA); 4770 + nfs4_inc_nlink(inode); 4803 4771 status = nfs_post_op_update_inode(inode, res.fattr); 4804 4772 if (!status) 4805 4773 nfs_setsecurity(inode, res.fattr, res.label); ··· 4878 4844 &data->arg.seq_args, &data->res.seq_res, 1); 4879 4845 if (status == 0) { 4880 4846 spin_lock(&dir->i_lock); 4881 - nfs4_update_changeattr_locked(dir, &data->res.dir_cinfo, 4882 - data->res.fattr->time_start, 4883 - NFS_INO_INVALID_DATA); 4884 4847 /* Creating a directory bumps nlink in the parent */ 4885 4848 if (data->arg.ftype == NF4DIR) 4886 4849 nfs4_inc_nlink_locked(dir); 4850 + nfs4_update_changeattr_locked(dir, &data->res.dir_cinfo, 4851 + data->res.fattr->time_start, 4852 + NFS_INO_INVALID_DATA); 4887 4853 spin_unlock(&dir->i_lock); 4888 4854 status = nfs_instantiate(dentry, data->res.fh, data->res.fattr, data->res.label); 4889 4855 } ··· 5450 5416 return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; 5451 5417 } 5452 5418 5453 - static void nfs4_bitmask_adjust(__u32 *bitmask, struct inode *inode, 5454 - struct nfs_server *server, 5455 - struct nfs4_label *label) 5419 + static void nfs4_bitmask_set(__u32 bitmask[NFS4_BITMASK_SZ], const __u32 *src, 5420 + struct inode *inode, struct nfs_server *server, 5421 + struct nfs4_label *label) 5456 5422 { 5457 - 5458 5423 unsigned long cache_validity = READ_ONCE(NFS_I(inode)->cache_validity); 5424 + unsigned int i; 5459 5425 5460 - if ((cache_validity & NFS_INO_INVALID_DATA) || 5461 - (cache_validity & NFS_INO_REVAL_PAGECACHE) || 5462 - (cache_validity & NFS_INO_REVAL_FORCED) || 5463 - (cache_validity & NFS_INO_INVALID_OTHER)) 5464 - nfs4_bitmap_copy_adjust(bitmask, nfs4_bitmask(server, label), inode); 5426 + memcpy(bitmask, src, sizeof(*bitmask) * NFS4_BITMASK_SZ); 5465 5427 5466 - if (cache_validity & NFS_INO_INVALID_ATIME) 5467 - bitmask[1] |= FATTR4_WORD1_TIME_ACCESS; 5468 - if (cache_validity & NFS_INO_INVALID_OTHER) 5469 - bitmask[1] |= FATTR4_WORD1_MODE | FATTR4_WORD1_OWNER | 5470 - FATTR4_WORD1_OWNER_GROUP | 5471 - FATTR4_WORD1_NUMLINKS; 5472 - if (label && label->len && cache_validity & NFS_INO_INVALID_LABEL) 5473 - bitmask[2] |= FATTR4_WORD2_SECURITY_LABEL; 5474 5428 if (cache_validity & NFS_INO_INVALID_CHANGE) 5475 5429 bitmask[0] |= FATTR4_WORD0_CHANGE; 5430 + if (cache_validity & NFS_INO_INVALID_ATIME) 5431 + bitmask[1] |= FATTR4_WORD1_TIME_ACCESS; 5432 + if (cache_validity & NFS_INO_INVALID_MODE) 5433 + bitmask[1] |= FATTR4_WORD1_MODE; 5434 + if (cache_validity & NFS_INO_INVALID_OTHER) 5435 + bitmask[1] |= FATTR4_WORD1_OWNER | FATTR4_WORD1_OWNER_GROUP; 5436 + if (cache_validity & NFS_INO_INVALID_NLINK) 5437 + bitmask[1] |= FATTR4_WORD1_NUMLINKS; 5438 + if (label && label->len && cache_validity & NFS_INO_INVALID_LABEL) 5439 + bitmask[2] |= FATTR4_WORD2_SECURITY_LABEL; 5476 5440 if (cache_validity & NFS_INO_INVALID_CTIME) 5477 5441 bitmask[1] |= FATTR4_WORD1_TIME_METADATA; 5478 5442 if (cache_validity & NFS_INO_INVALID_MTIME) 5479 5443 bitmask[1] |= FATTR4_WORD1_TIME_MODIFY; 5480 - if (cache_validity & NFS_INO_INVALID_SIZE) 5481 - bitmask[0] |= FATTR4_WORD0_SIZE; 5482 5444 if (cache_validity & NFS_INO_INVALID_BLOCKS) 5483 5445 bitmask[1] |= FATTR4_WORD1_SPACE_USED; 5446 + 5447 + if (cache_validity & NFS_INO_INVALID_SIZE) 5448 + bitmask[0] |= FATTR4_WORD0_SIZE; 5449 + 5450 + for (i = 0; i < NFS4_BITMASK_SZ; i++) 5451 + bitmask[i] &= server->attr_bitmask[i]; 5484 5452 } 5485 5453 5486 5454 static void nfs4_proc_write_setup(struct nfs_pgio_header *hdr, ··· 5495 5459 hdr->args.bitmask = NULL; 5496 5460 hdr->res.fattr = NULL; 5497 5461 } else { 5498 - hdr->args.bitmask = server->cache_consistency_bitmask; 5499 - nfs4_bitmask_adjust(hdr->args.bitmask, hdr->inode, server, NULL); 5462 + nfs4_bitmask_set(hdr->args.bitmask_store, 5463 + server->cache_consistency_bitmask, 5464 + hdr->inode, server, NULL); 5465 + hdr->args.bitmask = hdr->args.bitmask_store; 5500 5466 } 5501 5467 5502 5468 if (!hdr->pgio_done_cb) ··· 5896 5858 5897 5859 if (!nfs4_server_supports_acls(server)) 5898 5860 return -EOPNOTSUPP; 5899 - ret = nfs_revalidate_inode(server, inode); 5861 + ret = nfs_revalidate_inode(inode, NFS_INO_INVALID_CHANGE); 5900 5862 if (ret < 0) 5901 5863 return ret; 5902 5864 if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) ··· 6540 6502 6541 6503 data->args.fhandle = &data->fh; 6542 6504 data->args.stateid = &data->stateid; 6543 - data->args.bitmask = server->cache_consistency_bitmask; 6544 - nfs4_bitmask_adjust(data->args.bitmask, inode, server, NULL); 6505 + nfs4_bitmask_set(data->args.bitmask_store, 6506 + server->cache_consistency_bitmask, inode, server, 6507 + NULL); 6508 + data->args.bitmask = data->args.bitmask_store; 6545 6509 nfs_copy_fh(&data->fh, NFS_FH(inode)); 6546 6510 nfs4_stateid_copy(&data->stateid, stateid); 6547 6511 data->res.fattr = &data->fattr; ··· 7290 7250 7291 7251 #ifdef CONFIG_NFS_V4_1 7292 7252 struct nfs4_lock_waiter { 7293 - struct task_struct *task; 7294 7253 struct inode *inode; 7295 - struct nfs_lowner *owner; 7254 + struct nfs_lowner owner; 7255 + wait_queue_entry_t wait; 7296 7256 }; 7297 7257 7298 7258 static int 7299 7259 nfs4_wake_lock_waiter(wait_queue_entry_t *wait, unsigned int mode, int flags, void *key) 7300 7260 { 7301 - int ret; 7302 - struct nfs4_lock_waiter *waiter = wait->private; 7261 + struct nfs4_lock_waiter *waiter = 7262 + container_of(wait, struct nfs4_lock_waiter, wait); 7303 7263 7304 7264 /* NULL key means to wake up everyone */ 7305 7265 if (key) { 7306 7266 struct cb_notify_lock_args *cbnl = key; 7307 7267 struct nfs_lowner *lowner = &cbnl->cbnl_owner, 7308 - *wowner = waiter->owner; 7268 + *wowner = &waiter->owner; 7309 7269 7310 7270 /* Only wake if the callback was for the same owner. */ 7311 7271 if (lowner->id != wowner->id || lowner->s_dev != wowner->s_dev) ··· 7316 7276 return 0; 7317 7277 } 7318 7278 7319 - /* override "private" so we can use default_wake_function */ 7320 - wait->private = waiter->task; 7321 - ret = woken_wake_function(wait, mode, flags, key); 7322 - if (ret) 7323 - list_del_init(&wait->entry); 7324 - wait->private = waiter; 7325 - return ret; 7279 + return woken_wake_function(wait, mode, flags, key); 7326 7280 } 7327 7281 7328 7282 static int 7329 7283 nfs4_retry_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) 7330 7284 { 7331 - int status = -ERESTARTSYS; 7332 7285 struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner; 7333 7286 struct nfs_server *server = NFS_SERVER(state->inode); 7334 7287 struct nfs_client *clp = server->nfs_client; 7335 7288 wait_queue_head_t *q = &clp->cl_lock_waitq; 7336 - struct nfs_lowner owner = { .clientid = clp->cl_clientid, 7337 - .id = lsp->ls_seqid.owner_id, 7338 - .s_dev = server->s_dev }; 7339 - struct nfs4_lock_waiter waiter = { .task = current, 7340 - .inode = state->inode, 7341 - .owner = &owner}; 7342 - wait_queue_entry_t wait; 7289 + struct nfs4_lock_waiter waiter = { 7290 + .inode = state->inode, 7291 + .owner = { .clientid = clp->cl_clientid, 7292 + .id = lsp->ls_seqid.owner_id, 7293 + .s_dev = server->s_dev }, 7294 + }; 7295 + int status; 7343 7296 7344 7297 /* Don't bother with waitqueue if we don't expect a callback */ 7345 7298 if (!test_bit(NFS_STATE_MAY_NOTIFY_LOCK, &state->flags)) 7346 7299 return nfs4_retry_setlk_simple(state, cmd, request); 7347 7300 7348 - init_wait(&wait); 7349 - wait.private = &waiter; 7350 - wait.func = nfs4_wake_lock_waiter; 7301 + init_wait(&waiter.wait); 7302 + waiter.wait.func = nfs4_wake_lock_waiter; 7303 + add_wait_queue(q, &waiter.wait); 7351 7304 7352 - while(!signalled()) { 7353 - add_wait_queue(q, &wait); 7305 + do { 7354 7306 status = nfs4_proc_setlk(state, cmd, request); 7355 - if ((status != -EAGAIN) || IS_SETLK(cmd)) { 7356 - finish_wait(q, &wait); 7307 + if (status != -EAGAIN || IS_SETLK(cmd)) 7357 7308 break; 7358 - } 7359 7309 7360 7310 status = -ERESTARTSYS; 7361 7311 freezer_do_not_count(); 7362 - wait_woken(&wait, TASK_INTERRUPTIBLE, NFS4_LOCK_MAXTIMEOUT); 7312 + wait_woken(&waiter.wait, TASK_INTERRUPTIBLE, 7313 + NFS4_LOCK_MAXTIMEOUT); 7363 7314 freezer_count(); 7364 - finish_wait(q, &wait); 7365 - } 7315 + } while (!signalled()); 7316 + 7317 + remove_wait_queue(q, &waiter.wait); 7366 7318 7367 7319 return status; 7368 7320 } ··· 7647 7615 return -EACCES; 7648 7616 } 7649 7617 7650 - ret = nfs_revalidate_inode(NFS_SERVER(inode), inode); 7618 + ret = nfs_revalidate_inode(inode, NFS_INO_INVALID_CHANGE); 7651 7619 if (ret) 7652 7620 return ret; 7653 7621 ··· 7678 7646 return 0; 7679 7647 } 7680 7648 7681 - ret = nfs_revalidate_inode(NFS_SERVER(inode), inode); 7649 + ret = nfs_revalidate_inode(inode, NFS_INO_INVALID_CHANGE); 7682 7650 if (ret) 7683 7651 return ret; 7684 7652
+1 -1
fs/nfs/nfs4state.c
··· 645 645 } 646 646 647 647 /** 648 - * nfs4_purge_state_owners - Release all cached state owners 648 + * nfs4_free_state_owners - Release all cached state owners 649 649 * @head: resulting list of state owners 650 650 * 651 651 * Frees a list of state owners that was generated by
+46 -1
fs/nfs/nfs4trace.h
··· 666 666 ) 667 667 ) 668 668 669 - TRACE_EVENT(nfs4_xdr_status, 669 + TRACE_EVENT(nfs4_xdr_bad_operation, 670 + TP_PROTO( 671 + const struct xdr_stream *xdr, 672 + u32 op, 673 + u32 expected 674 + ), 675 + 676 + TP_ARGS(xdr, op, expected), 677 + 678 + TP_STRUCT__entry( 679 + __field(unsigned int, task_id) 680 + __field(unsigned int, client_id) 681 + __field(u32, xid) 682 + __field(u32, op) 683 + __field(u32, expected) 684 + ), 685 + 686 + TP_fast_assign( 687 + const struct rpc_rqst *rqstp = xdr->rqst; 688 + const struct rpc_task *task = rqstp->rq_task; 689 + 690 + __entry->task_id = task->tk_pid; 691 + __entry->client_id = task->tk_client->cl_clid; 692 + __entry->xid = be32_to_cpu(rqstp->rq_xid); 693 + __entry->op = op; 694 + __entry->expected = expected; 695 + ), 696 + 697 + TP_printk( 698 + "task:%u@%d xid=0x%08x operation=%u, expected=%u", 699 + __entry->task_id, __entry->client_id, __entry->xid, 700 + __entry->op, __entry->expected 701 + ) 702 + ); 703 + 704 + DECLARE_EVENT_CLASS(nfs4_xdr_event, 670 705 TP_PROTO( 671 706 const struct xdr_stream *xdr, 672 707 u32 op, ··· 736 701 __entry->op 737 702 ) 738 703 ); 704 + #define DEFINE_NFS4_XDR_EVENT(name) \ 705 + DEFINE_EVENT(nfs4_xdr_event, name, \ 706 + TP_PROTO( \ 707 + const struct xdr_stream *xdr, \ 708 + u32 op, \ 709 + u32 error \ 710 + ), \ 711 + TP_ARGS(xdr, op, error)) 712 + DEFINE_NFS4_XDR_EVENT(nfs4_xdr_status); 713 + DEFINE_NFS4_XDR_EVENT(nfs4_xdr_bad_filehandle); 739 714 740 715 DECLARE_EVENT_CLASS(nfs4_cb_error_class, 741 716 TP_PROTO(
+52 -8
fs/nfs/nfs4xdr.c
··· 144 144 * layout types will be returned. 145 145 */ 146 146 #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \ 147 - nfs4_fattr_bitmap_maxsz + 4 + 8 + 5) 147 + nfs4_fattr_bitmap_maxsz + 1 + \ 148 + 1 /* lease time */ + \ 149 + 2 /* max filesize */ + \ 150 + 2 /* max read */ + \ 151 + 2 /* max write */ + \ 152 + nfstime4_maxsz /* time delta */ + \ 153 + 5 /* fs layout types */ + \ 154 + 1 /* layout blksize */ + \ 155 + 1 /* clone blksize */ + \ 156 + 1 /* change attr type */ + \ 157 + 1 /* xattr support */) 148 158 #define encode_renew_maxsz (op_encode_hdr_maxsz + 3) 149 159 #define decode_renew_maxsz (op_decode_hdr_maxsz) 150 160 #define encode_setclientid_maxsz \ ··· 3210 3200 *nfs_retval = nfs4_stat_to_errno(nfserr); 3211 3201 return true; 3212 3202 out_bad_operation: 3213 - dprintk("nfs: Server returned operation" 3214 - " %d but we issued a request for %d\n", 3215 - opnum, expected); 3203 + trace_nfs4_xdr_bad_operation(xdr, opnum, expected); 3216 3204 *nfs_retval = -EREMOTEIO; 3217 3205 return false; 3218 3206 out_overflow: ··· 3495 3487 if (unlikely(!p)) 3496 3488 return -EIO; 3497 3489 len = be32_to_cpup(p); 3498 - if (len > NFS4_FHSIZE) 3499 - return -EIO; 3490 + if (len > NFS4_FHSIZE || len == 0) { 3491 + trace_nfs4_xdr_bad_filehandle(xdr, OP_READDIR, 3492 + NFS4ERR_BADHANDLE); 3493 + return -EREMOTEIO; 3494 + } 3500 3495 p = xdr_inline_decode(xdr, len); 3501 3496 if (unlikely(!p)) 3502 3497 return -EIO; ··· 4848 4837 return 0; 4849 4838 } 4850 4839 4840 + static int decode_attr_change_attr_type(struct xdr_stream *xdr, 4841 + uint32_t *bitmap, 4842 + enum nfs4_change_attr_type *res) 4843 + { 4844 + u32 tmp = NFS4_CHANGE_TYPE_IS_UNDEFINED; 4845 + 4846 + dprintk("%s: bitmap is %x\n", __func__, bitmap[2]); 4847 + if (bitmap[2] & FATTR4_WORD2_CHANGE_ATTR_TYPE) { 4848 + if (xdr_stream_decode_u32(xdr, &tmp)) 4849 + return -EIO; 4850 + bitmap[2] &= ~FATTR4_WORD2_CHANGE_ATTR_TYPE; 4851 + } 4852 + 4853 + switch(tmp) { 4854 + case NFS4_CHANGE_TYPE_IS_MONOTONIC_INCR: 4855 + case NFS4_CHANGE_TYPE_IS_VERSION_COUNTER: 4856 + case NFS4_CHANGE_TYPE_IS_VERSION_COUNTER_NOPNFS: 4857 + case NFS4_CHANGE_TYPE_IS_TIME_METADATA: 4858 + *res = tmp; 4859 + break; 4860 + default: 4861 + *res = NFS4_CHANGE_TYPE_IS_UNDEFINED; 4862 + } 4863 + return 0; 4864 + } 4865 + 4851 4866 static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo) 4852 4867 { 4853 4868 unsigned int savep; ··· 4922 4885 if (status) 4923 4886 goto xdr_error; 4924 4887 4888 + status = decode_attr_change_attr_type(xdr, bitmap, 4889 + &fsinfo->change_attr_type); 4890 + if (status) 4891 + goto xdr_error; 4892 + 4925 4893 status = decode_attr_xattrsupport(xdr, bitmap, 4926 4894 &fsinfo->xattr_support); 4927 4895 if (status) ··· 4955 4913 if (unlikely(!p)) 4956 4914 return -EIO; 4957 4915 len = be32_to_cpup(p); 4958 - if (len > NFS4_FHSIZE) 4959 - return -EIO; 4916 + if (len > NFS4_FHSIZE || len == 0) { 4917 + trace_nfs4_xdr_bad_filehandle(xdr, OP_GETFH, NFS4ERR_BADHANDLE); 4918 + return -EREMOTEIO; 4919 + } 4960 4920 fh->size = len; 4961 4921 p = xdr_inline_decode(xdr, len); 4962 4922 if (unlikely(!p))
+1
fs/nfs/nfstrace.c
··· 12 12 EXPORT_TRACEPOINT_SYMBOL_GPL(nfs_fsync_enter); 13 13 EXPORT_TRACEPOINT_SYMBOL_GPL(nfs_fsync_exit); 14 14 EXPORT_TRACEPOINT_SYMBOL_GPL(nfs_xdr_status); 15 + EXPORT_TRACEPOINT_SYMBOL_GPL(nfs_xdr_bad_filehandle);
+20 -2
fs/nfs/nfstrace.h
··· 45 45 TRACE_DEFINE_ENUM(NFS_INO_INVALID_MTIME); 46 46 TRACE_DEFINE_ENUM(NFS_INO_INVALID_SIZE); 47 47 TRACE_DEFINE_ENUM(NFS_INO_INVALID_OTHER); 48 + TRACE_DEFINE_ENUM(NFS_INO_DATA_INVAL_DEFER); 49 + TRACE_DEFINE_ENUM(NFS_INO_INVALID_BLOCKS); 50 + TRACE_DEFINE_ENUM(NFS_INO_INVALID_XATTR); 51 + TRACE_DEFINE_ENUM(NFS_INO_INVALID_NLINK); 52 + TRACE_DEFINE_ENUM(NFS_INO_INVALID_MODE); 48 53 49 54 #define nfs_show_cache_validity(v) \ 50 55 __print_flags(v, "|", \ ··· 65 60 { NFS_INO_INVALID_MTIME, "INVALID_MTIME" }, \ 66 61 { NFS_INO_INVALID_SIZE, "INVALID_SIZE" }, \ 67 62 { NFS_INO_INVALID_OTHER, "INVALID_OTHER" }, \ 68 - { NFS_INO_INVALID_XATTR, "INVALID_XATTR" }) 63 + { NFS_INO_DATA_INVAL_DEFER, "DATA_INVAL_DEFER" }, \ 64 + { NFS_INO_INVALID_BLOCKS, "INVALID_BLOCKS" }, \ 65 + { NFS_INO_INVALID_XATTR, "INVALID_XATTR" }, \ 66 + { NFS_INO_INVALID_NLINK, "INVALID_NLINK" }, \ 67 + { NFS_INO_INVALID_MODE, "INVALID_MODE" }) 69 68 70 69 TRACE_DEFINE_ENUM(NFS_INO_ADVISE_RDPLUS); 71 70 TRACE_DEFINE_ENUM(NFS_INO_STALE); ··· 1401 1392 { NFSERR_BADTYPE, "BADTYPE" }, \ 1402 1393 { NFSERR_JUKEBOX, "JUKEBOX" }) 1403 1394 1404 - TRACE_EVENT(nfs_xdr_status, 1395 + DECLARE_EVENT_CLASS(nfs_xdr_event, 1405 1396 TP_PROTO( 1406 1397 const struct xdr_stream *xdr, 1407 1398 int error ··· 1443 1434 nfs_show_status(__entry->error) 1444 1435 ) 1445 1436 ); 1437 + #define DEFINE_NFS_XDR_EVENT(name) \ 1438 + DEFINE_EVENT(nfs_xdr_event, name, \ 1439 + TP_PROTO( \ 1440 + const struct xdr_stream *xdr, \ 1441 + int error \ 1442 + ), \ 1443 + TP_ARGS(xdr, error)) 1444 + DEFINE_NFS_XDR_EVENT(nfs_xdr_status); 1445 + DEFINE_NFS_XDR_EVENT(nfs_xdr_bad_filehandle); 1446 1446 1447 1447 #endif /* _TRACE_NFS_H */ 1448 1448
+2 -2
fs/nfs/pagelist.c
··· 577 577 } 578 578 579 579 /** 580 - * nfs_release_request - Release the count on an NFS read/write request 580 + * nfs_free_request - Release the count on an NFS read/write request 581 581 * @req: request to release 582 582 * 583 583 * Note: Should never be called with the spinlock held! ··· 1152 1152 } 1153 1153 1154 1154 /** 1155 - * nfs_pageio_add_request - Attempt to coalesce a request into a page list. 1155 + * __nfs_pageio_add_request - Attempt to coalesce a request into a page list. 1156 1156 * @desc: destination io descriptor 1157 1157 * @req: request 1158 1158 *
+7 -4
fs/nfs/pnfs.c
··· 1344 1344 } 1345 1345 valid_layout = pnfs_layout_is_valid(lo); 1346 1346 pnfs_clear_layoutcommit(ino, &tmp_list); 1347 - pnfs_mark_matching_lsegs_invalid(lo, &tmp_list, NULL, 0); 1347 + pnfs_mark_matching_lsegs_return(lo, &tmp_list, NULL, 0); 1348 1348 1349 1349 if (NFS_SERVER(ino)->pnfs_curr_ld->return_range) { 1350 1350 struct pnfs_layout_range range = { ··· 2410 2410 .iomode = IOMODE_ANY, 2411 2411 .length = NFS4_MAX_UINT64, 2412 2412 }; 2413 - pnfs_set_plh_return_info(lo, IOMODE_ANY, 0); 2414 - pnfs_mark_matching_lsegs_return(lo, &lo->plh_return_segs, 2415 - &range, 0); 2413 + pnfs_mark_matching_lsegs_return(lo, &free_me, &range, 0); 2416 2414 goto out_forget; 2417 2415 } else { 2418 2416 /* We have a completely new layout */ ··· 2466 2468 2467 2469 assert_spin_locked(&lo->plh_inode->i_lock); 2468 2470 2471 + if (test_bit(NFS_LAYOUT_RETURN_REQUESTED, &lo->plh_flags)) 2472 + tmp_list = &lo->plh_return_segs; 2473 + 2469 2474 list_for_each_entry_safe(lseg, next, &lo->plh_segs, pls_list) 2470 2475 if (pnfs_match_lseg_recall(lseg, return_range, seq)) { 2471 2476 dprintk("%s: marking lseg %p iomode %d " ··· 2476 2475 lseg, lseg->pls_range.iomode, 2477 2476 lseg->pls_range.offset, 2478 2477 lseg->pls_range.length); 2478 + if (test_bit(NFS_LSEG_LAYOUTRETURN, &lseg->pls_flags)) 2479 + tmp_list = &lo->plh_return_segs; 2479 2480 if (mark_lseg_invalid(lseg, tmp_list)) 2480 2481 continue; 2481 2482 remaining++;
+1
fs/nfs/proc.c
··· 91 91 info->dtpref = fsinfo.tsize; 92 92 info->maxfilesize = 0x7FFFFFFF; 93 93 info->lease_time = 0; 94 + info->change_attr_type = NFS4_CHANGE_TYPE_IS_TIME_METADATA; 94 95 return 0; 95 96 } 96 97
+1 -5
fs/nfs/super.c
··· 116 116 #ifdef CONFIG_NFS_V4_2 117 117 static void nfs_ssc_register_ops(void) 118 118 { 119 - #ifdef CONFIG_NFSD_V4 120 119 nfs_ssc_register(&nfs_ssc_clnt_ops_tbl); 121 - #endif 122 120 } 123 121 124 122 static void nfs_ssc_unregister_ops(void) 125 123 { 126 - #ifdef CONFIG_NFSD_V4 127 124 nfs_ssc_unregister(&nfs_ssc_clnt_ops_tbl); 128 - #endif 129 125 } 130 126 #endif /* CONFIG_NFS_V4_2 */ 131 127 ··· 863 867 * Now ask the mount server to map our export path 864 868 * to a file handle. 865 869 */ 866 - status = nfs_mount(&request); 870 + status = nfs_mount(&request, ctx->timeo, ctx->retrans); 867 871 if (status != 0) { 868 872 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n", 869 873 request.hostname, status);
+2 -5
fs/nfs/write.c
··· 764 764 * with invalidate/truncate. 765 765 */ 766 766 spin_lock(&mapping->private_lock); 767 - if (!nfs_have_writebacks(inode) && 768 - NFS_PROTO(inode)->have_delegation(inode, FMODE_WRITE)) 769 - inode_inc_iversion_raw(inode); 770 767 if (likely(!PageSwapCache(req->wb_page))) { 771 768 set_bit(PG_MAPPED, &req->wb_flags); 772 769 SetPagePrivate(req->wb_page); ··· 1290 1293 if (nfs_have_delegated_attributes(inode)) 1291 1294 goto out; 1292 1295 if (nfsi->cache_validity & 1293 - (NFS_INO_REVAL_PAGECACHE | NFS_INO_INVALID_SIZE)) 1296 + (NFS_INO_INVALID_CHANGE | NFS_INO_INVALID_SIZE)) 1294 1297 return false; 1295 1298 smp_rmb(); 1296 1299 if (test_bit(NFS_INO_INVALIDATING, &nfsi->flags) && pagelen != 0) ··· 1601 1604 /* Deal with the suid/sgid bit corner case */ 1602 1605 if (nfs_should_remove_suid(inode)) { 1603 1606 spin_lock(&inode->i_lock); 1604 - nfs_set_cache_invalid(inode, NFS_INO_INVALID_OTHER); 1607 + nfs_set_cache_invalid(inode, NFS_INO_INVALID_MODE); 1605 1608 spin_unlock(&inode->i_lock); 1606 1609 } 1607 1610 return 0;
+1 -1
fs/nfsd/Kconfig
··· 138 138 139 139 config NFSD_V4_2_INTER_SSC 140 140 bool "NFSv4.2 inter server to server COPY" 141 - depends on NFSD_V4 && NFS_V4_1 && NFS_V4_2 141 + depends on NFSD_V4 && NFS_V4_2 142 142 help 143 143 This option enables support for NFSv4.2 inter server to 144 144 server copy where the destination server calls the NFSv4.2
+9
include/linux/nfs4.h
··· 452 452 #define FATTR4_WORD2_LAYOUT_BLKSIZE (1UL << 1) 453 453 #define FATTR4_WORD2_MDSTHRESHOLD (1UL << 4) 454 454 #define FATTR4_WORD2_CLONE_BLKSIZE (1UL << 13) 455 + #define FATTR4_WORD2_CHANGE_ATTR_TYPE (1UL << 15) 455 456 #define FATTR4_WORD2_SECURITY_LABEL (1UL << 16) 456 457 #define FATTR4_WORD2_MODE_UMASK (1UL << 17) 457 458 #define FATTR4_WORD2_XATTR_SUPPORT (1UL << 18) ··· 708 707 }; 709 708 struct nfs42_netaddr nl4_addr; /* NL4_NETADDR */ 710 709 } u; 710 + }; 711 + 712 + enum nfs4_change_attr_type { 713 + NFS4_CHANGE_TYPE_IS_MONOTONIC_INCR = 0, 714 + NFS4_CHANGE_TYPE_IS_VERSION_COUNTER = 1, 715 + NFS4_CHANGE_TYPE_IS_VERSION_COUNTER_NOPNFS = 2, 716 + NFS4_CHANGE_TYPE_IS_TIME_METADATA = 3, 717 + NFS4_CHANGE_TYPE_IS_UNDEFINED = 4, 711 718 }; 712 719 713 720 /*
+5 -1
include/linux/nfs_fs.h
··· 246 246 BIT(13) /* Deferred cache invalidation */ 247 247 #define NFS_INO_INVALID_BLOCKS BIT(14) /* cached blocks are invalid */ 248 248 #define NFS_INO_INVALID_XATTR BIT(15) /* xattrs are invalid */ 249 + #define NFS_INO_INVALID_NLINK BIT(16) /* cached nlinks is invalid */ 250 + #define NFS_INO_INVALID_MODE BIT(17) /* cached mode is invalid */ 249 251 250 252 #define NFS_INO_INVALID_ATTR (NFS_INO_INVALID_CHANGE \ 251 253 | NFS_INO_INVALID_CTIME \ 252 254 | NFS_INO_INVALID_MTIME \ 253 255 | NFS_INO_INVALID_SIZE \ 256 + | NFS_INO_INVALID_NLINK \ 257 + | NFS_INO_INVALID_MODE \ 254 258 | NFS_INO_INVALID_OTHER) /* inode metadata is invalid */ 255 259 256 260 /* ··· 390 386 extern int nfs_permission(struct user_namespace *, struct inode *, int); 391 387 extern int nfs_open(struct inode *, struct file *); 392 388 extern int nfs_attribute_cache_expired(struct inode *inode); 393 - extern int nfs_revalidate_inode(struct nfs_server *server, struct inode *inode); 389 + extern int nfs_revalidate_inode(struct inode *inode, unsigned long flags); 394 390 extern int __nfs_revalidate_inode(struct nfs_server *, struct inode *); 395 391 extern int nfs_clear_invalid_mapping(struct address_space *mapping); 396 392 extern bool nfs_mapping_need_revalidate_inode(struct inode *inode);
+4 -9
include/linux/nfs_fs_sb.h
··· 156 156 #define NFS_MOUNT_WRITE_EAGER 0x01000000 157 157 #define NFS_MOUNT_WRITE_WAIT 0x02000000 158 158 159 + unsigned int fattr_valid; /* Valid attributes */ 159 160 unsigned int caps; /* server capabilities */ 160 161 unsigned int rsize; /* read size */ 161 162 unsigned int rpages; /* read size (in pages) */ ··· 180 179 unsigned int clone_blksize; /* granularity of a CLONE operation */ 181 180 #define NFS_OPTION_FSCACHE 0x00000001 /* - local caching enabled */ 182 181 #define NFS_OPTION_MIGRATION 0x00000002 /* - NFSv4 migration enabled */ 182 + 183 + enum nfs4_change_attr_type 184 + change_attr_type;/* Description of change attribute */ 183 185 184 186 struct nfs_fsid fsid; 185 187 __u64 maxfilesize; /* maximum file size */ ··· 269 265 #define NFS_CAP_SYMLINKS (1U << 2) 270 266 #define NFS_CAP_ACLS (1U << 3) 271 267 #define NFS_CAP_ATOMIC_OPEN (1U << 4) 272 - /* #define NFS_CAP_CHANGE_ATTR (1U << 5) */ 273 268 #define NFS_CAP_LGOPEN (1U << 5) 274 - #define NFS_CAP_FILEID (1U << 6) 275 - #define NFS_CAP_MODE (1U << 7) 276 - #define NFS_CAP_NLINK (1U << 8) 277 - #define NFS_CAP_OWNER (1U << 9) 278 - #define NFS_CAP_OWNER_GROUP (1U << 10) 279 - #define NFS_CAP_ATIME (1U << 11) 280 - #define NFS_CAP_CTIME (1U << 12) 281 - #define NFS_CAP_MTIME (1U << 13) 282 269 #define NFS_CAP_POSIX_LOCK (1U << 14) 283 270 #define NFS_CAP_UIDGID_NOMAP (1U << 15) 284 271 #define NFS_CAP_STATEID_NFSV41 (1U << 16)
+10 -3
include/linux/nfs_xdr.h
··· 15 15 #define NFS_DEF_FILE_IO_SIZE (4096U) 16 16 #define NFS_MIN_FILE_IO_SIZE (1024U) 17 17 18 + #define NFS_BITMASK_SZ 3 19 + 18 20 struct nfs4_string { 19 21 unsigned int len; 20 22 char *data; ··· 152 150 __u32 layouttype[NFS_MAX_LAYOUT_TYPES]; /* supported pnfs layout driver */ 153 151 __u32 blksize; /* preferred pnfs io block size */ 154 152 __u32 clone_blksize; /* granularity of a CLONE operation */ 153 + enum nfs4_change_attr_type 154 + change_attr_type; /* Info about change attr */ 155 155 __u32 xattr_support; /* User xattrs supported */ 156 156 }; 157 157 ··· 529 525 struct nfs_seqid * seqid; 530 526 fmode_t fmode; 531 527 u32 share_access; 532 - u32 * bitmask; 528 + const u32 * bitmask; 529 + u32 bitmask_store[NFS_BITMASK_SZ]; 533 530 struct nfs4_layoutreturn_args *lr_args; 534 531 }; 535 532 ··· 613 608 struct nfs4_sequence_args seq_args; 614 609 const struct nfs_fh *fhandle; 615 610 const nfs4_stateid *stateid; 616 - u32 * bitmask; 611 + const u32 *bitmask; 612 + u32 bitmask_store[NFS_BITMASK_SZ]; 617 613 struct nfs4_layoutreturn_args *lr_args; 618 614 }; 619 615 ··· 654 648 union { 655 649 unsigned int replen; /* used by read */ 656 650 struct { 657 - u32 * bitmask; /* used by write */ 651 + const u32 * bitmask; /* used by write */ 652 + u32 bitmask_store[NFS_BITMASK_SZ]; /* used by write */ 658 653 enum nfs3_stable_how stable; /* used by write */ 659 654 }; 660 655 };
+1
include/linux/sunrpc/xprt.h
··· 247 247 struct rpc_task * snd_task; /* Task blocked in send */ 248 248 249 249 struct list_head xmit_queue; /* Send queue */ 250 + atomic_long_t xmit_queuelen; 250 251 251 252 struct svc_xprt *bc_xprt; /* NFSv4.1 backchannel */ 252 253 #if defined(CONFIG_SUNRPC_BACKCHANNEL)
+71 -75
include/trace/events/rpcrdma.h
··· 60 60 ), \ 61 61 TP_ARGS(wc, cid)) 62 62 63 + DECLARE_EVENT_CLASS(rpcrdma_mr_completion_class, 64 + TP_PROTO( 65 + const struct ib_wc *wc, 66 + const struct rpc_rdma_cid *cid 67 + ), 68 + 69 + TP_ARGS(wc, cid), 70 + 71 + TP_STRUCT__entry( 72 + __field(u32, cq_id) 73 + __field(int, completion_id) 74 + __field(unsigned long, status) 75 + __field(unsigned int, vendor_err) 76 + ), 77 + 78 + TP_fast_assign( 79 + __entry->cq_id = cid->ci_queue_id; 80 + __entry->completion_id = cid->ci_completion_id; 81 + __entry->status = wc->status; 82 + if (wc->status) 83 + __entry->vendor_err = wc->vendor_err; 84 + else 85 + __entry->vendor_err = 0; 86 + ), 87 + 88 + TP_printk("cq.id=%u mr.id=%d status=%s (%lu/0x%x)", 89 + __entry->cq_id, __entry->completion_id, 90 + rdma_show_wc_status(__entry->status), 91 + __entry->status, __entry->vendor_err 92 + ) 93 + ); 94 + 95 + #define DEFINE_MR_COMPLETION_EVENT(name) \ 96 + DEFINE_EVENT(rpcrdma_mr_completion_class, name, \ 97 + TP_PROTO( \ 98 + const struct ib_wc *wc, \ 99 + const struct rpc_rdma_cid *cid \ 100 + ), \ 101 + TP_ARGS(wc, cid)) 102 + 63 103 DECLARE_EVENT_CLASS(rpcrdma_receive_completion_class, 64 104 TP_PROTO( 65 105 const struct ib_wc *wc, ··· 190 150 TP_ARGS(r_xprt), 191 151 192 152 TP_STRUCT__entry( 193 - __field(const void *, r_xprt) 194 153 __string(addr, rpcrdma_addrstr(r_xprt)) 195 154 __string(port, rpcrdma_portstr(r_xprt)) 196 155 ), 197 156 198 157 TP_fast_assign( 199 - __entry->r_xprt = r_xprt; 200 158 __assign_str(addr, rpcrdma_addrstr(r_xprt)); 201 159 __assign_str(port, rpcrdma_portstr(r_xprt)); 202 160 ), 203 161 204 - TP_printk("peer=[%s]:%s r_xprt=%p", 205 - __get_str(addr), __get_str(port), __entry->r_xprt 162 + TP_printk("peer=[%s]:%s", 163 + __get_str(addr), __get_str(port) 206 164 ) 207 165 ); 208 166 ··· 220 182 TP_ARGS(r_xprt, rc), 221 183 222 184 TP_STRUCT__entry( 223 - __field(const void *, r_xprt) 224 185 __field(int, rc) 225 186 __field(int, connect_status) 226 187 __string(addr, rpcrdma_addrstr(r_xprt)) ··· 227 190 ), 228 191 229 192 TP_fast_assign( 230 - __entry->r_xprt = r_xprt; 231 193 __entry->rc = rc; 232 194 __entry->connect_status = r_xprt->rx_ep->re_connect_status; 233 195 __assign_str(addr, rpcrdma_addrstr(r_xprt)); 234 196 __assign_str(port, rpcrdma_portstr(r_xprt)); 235 197 ), 236 198 237 - TP_printk("peer=[%s]:%s r_xprt=%p: rc=%d connection status=%d", 238 - __get_str(addr), __get_str(port), __entry->r_xprt, 199 + TP_printk("peer=[%s]:%s rc=%d connection status=%d", 200 + __get_str(addr), __get_str(port), 239 201 __entry->rc, __entry->connect_status 240 202 ) 241 203 ); ··· 379 343 380 344 __entry->task_id = task->tk_pid; 381 345 __entry->client_id = task->tk_client->cl_clid; 382 - __entry->mr_id = mr->frwr.fr_mr->res.id; 346 + __entry->mr_id = mr->mr_ibmr->res.id; 383 347 __entry->nents = mr->mr_nents; 384 348 __entry->handle = mr->mr_handle; 385 349 __entry->length = mr->mr_length; ··· 420 384 ), 421 385 422 386 TP_fast_assign( 423 - __entry->mr_id = mr->frwr.fr_mr->res.id; 387 + __entry->mr_id = mr->mr_ibmr->res.id; 424 388 __entry->nents = mr->mr_nents; 425 389 __entry->handle = mr->mr_handle; 426 390 __entry->length = mr->mr_length; ··· 531 495 TP_ARGS(r_xprt, delay), 532 496 533 497 TP_STRUCT__entry( 534 - __field(const void *, r_xprt) 535 498 __field(unsigned long, delay) 536 499 __string(addr, rpcrdma_addrstr(r_xprt)) 537 500 __string(port, rpcrdma_portstr(r_xprt)) 538 501 ), 539 502 540 503 TP_fast_assign( 541 - __entry->r_xprt = r_xprt; 542 504 __entry->delay = delay; 543 505 __assign_str(addr, rpcrdma_addrstr(r_xprt)); 544 506 __assign_str(port, rpcrdma_portstr(r_xprt)); 545 507 ), 546 508 547 - TP_printk("peer=[%s]:%s r_xprt=%p delay=%lu", 548 - __get_str(addr), __get_str(port), __entry->r_xprt, 549 - __entry->delay 509 + TP_printk("peer=[%s]:%s delay=%lu", 510 + __get_str(addr), __get_str(port), __entry->delay 550 511 ) 551 512 ); 552 513 ··· 558 525 TP_ARGS(r_xprt, connect, reconnect), 559 526 560 527 TP_STRUCT__entry( 561 - __field(const void *, r_xprt) 562 528 __field(unsigned long, connect) 563 529 __field(unsigned long, reconnect) 564 530 __string(addr, rpcrdma_addrstr(r_xprt)) ··· 565 533 ), 566 534 567 535 TP_fast_assign( 568 - __entry->r_xprt = r_xprt; 569 536 __entry->connect = connect; 570 537 __entry->reconnect = reconnect; 571 538 __assign_str(addr, rpcrdma_addrstr(r_xprt)); 572 539 __assign_str(port, rpcrdma_portstr(r_xprt)); 573 540 ), 574 541 575 - TP_printk("peer=[%s]:%s r_xprt=%p: connect=%lu reconnect=%lu", 576 - __get_str(addr), __get_str(port), __entry->r_xprt, 542 + TP_printk("peer=[%s]:%s connect=%lu reconnect=%lu", 543 + __get_str(addr), __get_str(port), 577 544 __entry->connect / HZ, __entry->reconnect / HZ 578 - ) 579 - ); 580 - 581 - TRACE_EVENT(xprtrdma_qp_event, 582 - TP_PROTO( 583 - const struct rpcrdma_ep *ep, 584 - const struct ib_event *event 585 - ), 586 - 587 - TP_ARGS(ep, event), 588 - 589 - TP_STRUCT__entry( 590 - __field(unsigned long, event) 591 - __string(name, event->device->name) 592 - __array(unsigned char, srcaddr, sizeof(struct sockaddr_in6)) 593 - __array(unsigned char, dstaddr, sizeof(struct sockaddr_in6)) 594 - ), 595 - 596 - TP_fast_assign( 597 - const struct rdma_cm_id *id = ep->re_id; 598 - 599 - __entry->event = event->event; 600 - __assign_str(name, event->device->name); 601 - memcpy(__entry->srcaddr, &id->route.addr.src_addr, 602 - sizeof(struct sockaddr_in6)); 603 - memcpy(__entry->dstaddr, &id->route.addr.dst_addr, 604 - sizeof(struct sockaddr_in6)); 605 - ), 606 - 607 - TP_printk("%pISpc -> %pISpc device=%s %s (%lu)", 608 - __entry->srcaddr, __entry->dstaddr, __get_str(name), 609 - rdma_show_ib_event(__entry->event), __entry->event 610 545 ) 611 546 ); 612 547 ··· 590 591 TP_ARGS(r_xprt, count), 591 592 592 593 TP_STRUCT__entry( 593 - __field(const void *, r_xprt) 594 594 __string(addr, rpcrdma_addrstr(r_xprt)) 595 595 __string(port, rpcrdma_portstr(r_xprt)) 596 596 __field(unsigned int, count) 597 597 ), 598 598 599 599 TP_fast_assign( 600 - __entry->r_xprt = r_xprt; 601 600 __entry->count = count; 602 601 __assign_str(addr, rpcrdma_addrstr(r_xprt)); 603 602 __assign_str(port, rpcrdma_portstr(r_xprt)); 604 603 ), 605 604 606 - TP_printk("peer=[%s]:%s r_xprt=%p: created %u MRs", 607 - __get_str(addr), __get_str(port), __entry->r_xprt, 608 - __entry->count 605 + TP_printk("peer=[%s]:%s created %u MRs", 606 + __get_str(addr), __get_str(port), __entry->count 609 607 ) 610 608 ); 611 609 ··· 825 829 TP_ARGS(r_xprt, count, status), 826 830 827 831 TP_STRUCT__entry( 828 - __field(const void *, r_xprt) 832 + __field(u32, cq_id) 829 833 __field(unsigned int, count) 830 834 __field(int, status) 831 835 __field(int, posted) ··· 834 838 ), 835 839 836 840 TP_fast_assign( 837 - __entry->r_xprt = r_xprt; 841 + const struct rpcrdma_ep *ep = r_xprt->rx_ep; 842 + 843 + __entry->cq_id = ep->re_attr.recv_cq->res.id; 838 844 __entry->count = count; 839 845 __entry->status = status; 840 - __entry->posted = r_xprt->rx_ep->re_receive_count; 846 + __entry->posted = ep->re_receive_count; 841 847 __assign_str(addr, rpcrdma_addrstr(r_xprt)); 842 848 __assign_str(port, rpcrdma_portstr(r_xprt)); 843 849 ), 844 850 845 - TP_printk("peer=[%s]:%s r_xprt=%p: %u new recvs, %d active (rc %d)", 846 - __get_str(addr), __get_str(port), __entry->r_xprt, 851 + TP_printk("peer=[%s]:%s cq.id=%d %u new recvs, %d active (rc %d)", 852 + __get_str(addr), __get_str(port), __entry->cq_id, 847 853 __entry->count, __entry->posted, __entry->status 848 854 ) 849 855 ); ··· 884 886 DEFINE_RECEIVE_COMPLETION_EVENT(xprtrdma_wc_receive); 885 887 886 888 DEFINE_COMPLETION_EVENT(xprtrdma_wc_send); 887 - DEFINE_COMPLETION_EVENT(xprtrdma_wc_fastreg); 888 - DEFINE_COMPLETION_EVENT(xprtrdma_wc_li); 889 - DEFINE_COMPLETION_EVENT(xprtrdma_wc_li_wake); 890 - DEFINE_COMPLETION_EVENT(xprtrdma_wc_li_done); 889 + DEFINE_MR_COMPLETION_EVENT(xprtrdma_wc_fastreg); 890 + DEFINE_MR_COMPLETION_EVENT(xprtrdma_wc_li); 891 + DEFINE_MR_COMPLETION_EVENT(xprtrdma_wc_li_wake); 892 + DEFINE_MR_COMPLETION_EVENT(xprtrdma_wc_li_done); 891 893 892 894 TRACE_EVENT(xprtrdma_frwr_alloc, 893 895 TP_PROTO( ··· 903 905 ), 904 906 905 907 TP_fast_assign( 906 - __entry->mr_id = mr->frwr.fr_mr->res.id; 908 + __entry->mr_id = mr->mr_ibmr->res.id; 907 909 __entry->rc = rc; 908 910 ), 909 911 ··· 931 933 ), 932 934 933 935 TP_fast_assign( 934 - __entry->mr_id = mr->frwr.fr_mr->res.id; 936 + __entry->mr_id = mr->mr_ibmr->res.id; 935 937 __entry->nents = mr->mr_nents; 936 938 __entry->handle = mr->mr_handle; 937 939 __entry->length = mr->mr_length; ··· 964 966 ), 965 967 966 968 TP_fast_assign( 967 - __entry->mr_id = mr->frwr.fr_mr->res.id; 969 + __entry->mr_id = mr->mr_ibmr->res.id; 968 970 __entry->addr = mr->mr_sg->dma_address; 969 971 __entry->dir = mr->mr_dir; 970 972 __entry->nents = sg_nents; ··· 994 996 ), 995 997 996 998 TP_fast_assign( 997 - __entry->mr_id = mr->frwr.fr_mr->res.id; 999 + __entry->mr_id = mr->mr_ibmr->res.id; 998 1000 __entry->addr = mr->mr_sg->dma_address; 999 1001 __entry->dir = mr->mr_dir; 1000 1002 __entry->num_mapped = num_mapped; ··· 1008 1010 ) 1009 1011 ); 1010 1012 1013 + DEFINE_MR_EVENT(fastreg); 1011 1014 DEFINE_MR_EVENT(localinv); 1015 + DEFINE_MR_EVENT(reminv); 1012 1016 DEFINE_MR_EVENT(map); 1013 1017 1014 1018 DEFINE_ANON_MR_EVENT(unmap); 1015 - DEFINE_ANON_MR_EVENT(recycle); 1016 1019 1017 1020 TRACE_EVENT(xprtrdma_dma_maperr, 1018 1021 TP_PROTO( ··· 1247 1248 TP_ARGS(r_xprt, reqs), 1248 1249 1249 1250 TP_STRUCT__entry( 1250 - __field(const void *, r_xprt) 1251 1251 __field(unsigned int, reqs) 1252 1252 __string(addr, rpcrdma_addrstr(r_xprt)) 1253 1253 __string(port, rpcrdma_portstr(r_xprt)) 1254 1254 ), 1255 1255 1256 1256 TP_fast_assign( 1257 - __entry->r_xprt = r_xprt; 1258 1257 __entry->reqs = reqs; 1259 1258 __assign_str(addr, rpcrdma_addrstr(r_xprt)); 1260 1259 __assign_str(port, rpcrdma_portstr(r_xprt)); 1261 1260 ), 1262 1261 1263 - TP_printk("peer=[%s]:%s r_xprt=%p: %u reqs", 1264 - __get_str(addr), __get_str(port), 1265 - __entry->r_xprt, __entry->reqs 1262 + TP_printk("peer=[%s]:%s %u reqs", 1263 + __get_str(addr), __get_str(port), __entry->reqs 1266 1264 ) 1267 1265 ); 1268 1266
+40 -1
include/trace/events/sunrpc.h
··· 1079 1079 __entry->seqno, __entry->status) 1080 1080 ); 1081 1081 1082 + TRACE_EVENT(xprt_retransmit, 1083 + TP_PROTO( 1084 + const struct rpc_rqst *rqst 1085 + ), 1086 + 1087 + TP_ARGS(rqst), 1088 + 1089 + TP_STRUCT__entry( 1090 + __field(unsigned int, task_id) 1091 + __field(unsigned int, client_id) 1092 + __field(u32, xid) 1093 + __field(int, ntrans) 1094 + __field(int, version) 1095 + __string(progname, 1096 + rqst->rq_task->tk_client->cl_program->name) 1097 + __string(procedure, 1098 + rqst->rq_task->tk_msg.rpc_proc->p_name) 1099 + ), 1100 + 1101 + TP_fast_assign( 1102 + struct rpc_task *task = rqst->rq_task; 1103 + 1104 + __entry->task_id = task->tk_pid; 1105 + __entry->client_id = task->tk_client ? 1106 + task->tk_client->cl_clid : -1; 1107 + __entry->xid = be32_to_cpu(rqst->rq_xid); 1108 + __entry->ntrans = rqst->rq_ntrans; 1109 + __assign_str(progname, 1110 + task->tk_client->cl_program->name) 1111 + __entry->version = task->tk_client->cl_vers; 1112 + __assign_str(procedure, task->tk_msg.rpc_proc->p_name) 1113 + ), 1114 + 1115 + TP_printk( 1116 + "task:%u@%u xid=0x%08x %sv%d %s ntrans=%d", 1117 + __entry->task_id, __entry->client_id, __entry->xid, 1118 + __get_str(progname), __entry->version, __get_str(procedure), 1119 + __entry->ntrans) 1120 + ); 1121 + 1082 1122 TRACE_EVENT(xprt_ping, 1083 1123 TP_PROTO(const struct rpc_xprt *xprt, int status), 1084 1124 ··· 1181 1141 1182 1142 DEFINE_WRITELOCK_EVENT(reserve_xprt); 1183 1143 DEFINE_WRITELOCK_EVENT(release_xprt); 1184 - DEFINE_WRITELOCK_EVENT(transmit_queued); 1185 1144 1186 1145 DECLARE_EVENT_CLASS(xprt_cong_event, 1187 1146 TP_PROTO(
+5 -7
net/sunrpc/clnt.c
··· 1799 1799 1800 1800 status = xprt->ops->buf_alloc(task); 1801 1801 trace_rpc_buf_alloc(task, status); 1802 - xprt_inject_disconnect(xprt); 1803 1802 if (status == 0) 1804 1803 return; 1805 1804 if (status != -ENOMEM) { ··· 2457 2458 } 2458 2459 2459 2460 /* 2460 - * Ensure that we see all writes made by xprt_complete_rqst() 2461 - * before it changed req->rq_reply_bytes_recvd. 2462 - */ 2463 - smp_rmb(); 2464 - 2465 - /* 2466 2461 * Did we ever call xprt_complete_rqst()? If not, we should assume 2467 2462 * the message is incomplete. 2468 2463 */ 2469 2464 err = -EAGAIN; 2470 2465 if (!req->rq_reply_bytes_recvd) 2471 2466 goto out; 2467 + 2468 + /* Ensure that we see all writes made by xprt_complete_rqst() 2469 + * before it changed req->rq_reply_bytes_recvd. 2470 + */ 2471 + smp_rmb(); 2472 2472 2473 2473 req->rq_rcv_buf.len = req->rq_private_buf.len; 2474 2474 trace_rpc_xdr_recvfrom(task, &req->rq_rcv_buf);
+5 -2
net/sunrpc/rpcb_clnt.c
··· 344 344 const char *hostname, 345 345 struct sockaddr *srvaddr, size_t salen, 346 346 int proto, u32 version, 347 - const struct cred *cred) 347 + const struct cred *cred, 348 + const struct rpc_timeout *timeo) 348 349 { 349 350 struct rpc_create_args args = { 350 351 .net = net, 351 352 .protocol = proto, 352 353 .address = srvaddr, 353 354 .addrsize = salen, 355 + .timeout = timeo, 354 356 .servername = hostname, 355 357 .nodename = nodename, 356 358 .program = &rpcb_program, ··· 707 705 clnt->cl_nodename, 708 706 xprt->servername, sap, salen, 709 707 xprt->prot, bind_version, 710 - clnt->cl_cred); 708 + clnt->cl_cred, 709 + task->tk_client->cl_timeout); 711 710 if (IS_ERR(rpcb_clnt)) { 712 711 status = PTR_ERR(rpcb_clnt); 713 712 goto bailout_nofree;
+11 -7
net/sunrpc/xprt.c
··· 698 698 const struct rpc_timeout *to = req->rq_task->tk_client->cl_timeout; 699 699 int status = 0; 700 700 701 - if (time_before(jiffies, req->rq_minortimeo)) 702 - return status; 703 701 if (time_before(jiffies, req->rq_majortimeo)) { 702 + if (time_before(jiffies, req->rq_minortimeo)) 703 + return status; 704 704 if (to->to_exponential) 705 705 req->rq_timeout <<= 1; 706 706 else ··· 1352 1352 list_add_tail(&req->rq_xmit, &xprt->xmit_queue); 1353 1353 INIT_LIST_HEAD(&req->rq_xmit2); 1354 1354 out: 1355 + atomic_long_inc(&xprt->xmit_queuelen); 1355 1356 set_bit(RPC_TASK_NEED_XMIT, &task->tk_runstate); 1356 1357 spin_unlock(&xprt->queue_lock); 1357 1358 } ··· 1382 1381 } 1383 1382 } else 1384 1383 list_del(&req->rq_xmit2); 1384 + atomic_long_dec(&req->rq_xprt->xmit_queuelen); 1385 1385 } 1386 1386 1387 1387 /** ··· 1471 1469 struct rpc_xprt *xprt = req->rq_xprt; 1472 1470 1473 1471 if (!xprt_lock_write(xprt, task)) { 1474 - trace_xprt_transmit_queued(xprt, task); 1475 - 1476 1472 /* Race breaker: someone may have transmitted us */ 1477 1473 if (!test_bit(RPC_TASK_NEED_XMIT, &task->tk_runstate)) 1478 1474 rpc_wake_up_queued_task_set_status(&xprt->sending, ··· 1483 1483 1484 1484 void xprt_end_transmit(struct rpc_task *task) 1485 1485 { 1486 - xprt_release_write(task->tk_rqstp->rq_xprt, task); 1486 + struct rpc_xprt *xprt = task->tk_rqstp->rq_xprt; 1487 + 1488 + xprt_inject_disconnect(xprt); 1489 + xprt_release_write(xprt, task); 1487 1490 } 1488 1491 1489 1492 /** ··· 1540 1537 return status; 1541 1538 } 1542 1539 1543 - if (is_retrans) 1540 + if (is_retrans) { 1544 1541 task->tk_client->cl_stats->rpcretrans++; 1542 + trace_xprt_retransmit(req); 1543 + } 1545 1544 1546 1545 xprt_inject_disconnect(xprt); 1547 1546 ··· 1890 1885 spin_unlock(&xprt->transport_lock); 1891 1886 if (req->rq_buffer) 1892 1887 xprt->ops->buf_free(task); 1893 - xprt_inject_disconnect(xprt); 1894 1888 xdr_free_bvec(&req->rq_rcv_buf); 1895 1889 xdr_free_bvec(&req->rq_snd_buf); 1896 1890 if (req->rq_cred != NULL)
+3 -1
net/sunrpc/xprtrdma/backchannel.c
··· 155 155 void xprt_rdma_bc_free_rqst(struct rpc_rqst *rqst) 156 156 { 157 157 struct rpcrdma_req *req = rpcr_to_rdmar(rqst); 158 + struct rpcrdma_rep *rep = req->rl_reply; 158 159 struct rpc_xprt *xprt = rqst->rq_xprt; 160 + struct rpcrdma_xprt *r_xprt = rpcx_to_rdmax(xprt); 159 161 160 - rpcrdma_recv_buffer_put(req->rl_reply); 162 + rpcrdma_rep_put(&r_xprt->rx_buf, rep); 161 163 req->rl_reply = NULL; 162 164 163 165 spin_lock(&xprt->bc_pa_lock);
+90 -119
net/sunrpc/xprtrdma/frwr_ops.c
··· 49 49 # define RPCDBG_FACILITY RPCDBG_TRANS 50 50 #endif 51 51 52 - /** 53 - * frwr_release_mr - Destroy one MR 54 - * @mr: MR allocated by frwr_mr_init 55 - * 56 - */ 57 - void frwr_release_mr(struct rpcrdma_mr *mr) 52 + static void frwr_cid_init(struct rpcrdma_ep *ep, 53 + struct rpcrdma_mr *mr) 58 54 { 59 - int rc; 55 + struct rpc_rdma_cid *cid = &mr->mr_cid; 60 56 61 - rc = ib_dereg_mr(mr->frwr.fr_mr); 62 - if (rc) 63 - trace_xprtrdma_frwr_dereg(mr, rc); 64 - kfree(mr->mr_sg); 65 - kfree(mr); 57 + cid->ci_queue_id = ep->re_attr.send_cq->res.id; 58 + cid->ci_completion_id = mr->mr_ibmr->res.id; 66 59 } 67 60 68 61 static void frwr_mr_unmap(struct rpcrdma_xprt *r_xprt, struct rpcrdma_mr *mr) ··· 68 75 } 69 76 } 70 77 71 - static void frwr_mr_recycle(struct rpcrdma_mr *mr) 78 + /** 79 + * frwr_mr_release - Destroy one MR 80 + * @mr: MR allocated by frwr_mr_init 81 + * 82 + */ 83 + void frwr_mr_release(struct rpcrdma_mr *mr) 72 84 { 73 - struct rpcrdma_xprt *r_xprt = mr->mr_xprt; 85 + int rc; 74 86 75 - trace_xprtrdma_mr_recycle(mr); 87 + frwr_mr_unmap(mr->mr_xprt, mr); 76 88 77 - frwr_mr_unmap(r_xprt, mr); 78 - 79 - spin_lock(&r_xprt->rx_buf.rb_lock); 80 - list_del(&mr->mr_all); 81 - r_xprt->rx_stats.mrs_recycled++; 82 - spin_unlock(&r_xprt->rx_buf.rb_lock); 83 - 84 - frwr_release_mr(mr); 89 + rc = ib_dereg_mr(mr->mr_ibmr); 90 + if (rc) 91 + trace_xprtrdma_frwr_dereg(mr, rc); 92 + kfree(mr->mr_sg); 93 + kfree(mr); 85 94 } 86 95 87 96 static void frwr_mr_put(struct rpcrdma_mr *mr) ··· 139 144 goto out_list_err; 140 145 141 146 mr->mr_xprt = r_xprt; 142 - mr->frwr.fr_mr = frmr; 147 + mr->mr_ibmr = frmr; 143 148 mr->mr_device = NULL; 144 149 INIT_LIST_HEAD(&mr->mr_list); 145 - init_completion(&mr->frwr.fr_linv_done); 150 + init_completion(&mr->mr_linv_done); 151 + frwr_cid_init(ep, mr); 146 152 147 153 sg_init_table(sg, depth); 148 154 mr->mr_sg = sg; ··· 253 257 ep->re_attr.cap.max_send_wr += 1; /* for ib_drain_sq */ 254 258 ep->re_attr.cap.max_recv_wr = ep->re_max_requests; 255 259 ep->re_attr.cap.max_recv_wr += RPCRDMA_BACKWARD_WRS; 260 + ep->re_attr.cap.max_recv_wr += RPCRDMA_MAX_RECV_BATCH; 256 261 ep->re_attr.cap.max_recv_wr += 1; /* for ib_drain_rq */ 257 262 258 263 ep->re_max_rdma_segs = ··· 323 326 goto out_dmamap_err; 324 327 mr->mr_device = ep->re_id->device; 325 328 326 - ibmr = mr->frwr.fr_mr; 329 + ibmr = mr->mr_ibmr; 327 330 n = ib_map_mr_sg(ibmr, mr->mr_sg, dma_nents, NULL, PAGE_SIZE); 328 331 if (n != dma_nents) 329 332 goto out_mapmr_err; ··· 333 336 key = (u8)(ibmr->rkey & 0x000000FF); 334 337 ib_update_fast_reg_key(ibmr, ++key); 335 338 336 - reg_wr = &mr->frwr.fr_regwr; 339 + reg_wr = &mr->mr_regwr; 337 340 reg_wr->mr = ibmr; 338 341 reg_wr->key = ibmr->rkey; 339 342 reg_wr->access = writing ? ··· 361 364 * @cq: completion queue 362 365 * @wc: WCE for a completed FastReg WR 363 366 * 367 + * Each flushed MR gets destroyed after the QP has drained. 364 368 */ 365 369 static void frwr_wc_fastreg(struct ib_cq *cq, struct ib_wc *wc) 366 370 { 367 371 struct ib_cqe *cqe = wc->wr_cqe; 368 - struct rpcrdma_frwr *frwr = 369 - container_of(cqe, struct rpcrdma_frwr, fr_cqe); 372 + struct rpcrdma_mr *mr = container_of(cqe, struct rpcrdma_mr, mr_cqe); 370 373 371 374 /* WARNING: Only wr_cqe and status are reliable at this point */ 372 - trace_xprtrdma_wc_fastreg(wc, &frwr->fr_cid); 373 - /* The MR will get recycled when the associated req is retransmitted */ 375 + trace_xprtrdma_wc_fastreg(wc, &mr->mr_cid); 374 376 375 377 rpcrdma_flush_disconnect(cq->cq_context, wc); 376 - } 377 - 378 - static void frwr_cid_init(struct rpcrdma_ep *ep, 379 - struct rpcrdma_frwr *frwr) 380 - { 381 - struct rpc_rdma_cid *cid = &frwr->fr_cid; 382 - 383 - cid->ci_queue_id = ep->re_attr.send_cq->res.id; 384 - cid->ci_completion_id = frwr->fr_mr->res.id; 385 378 } 386 379 387 380 /** ··· 390 403 */ 391 404 int frwr_send(struct rpcrdma_xprt *r_xprt, struct rpcrdma_req *req) 392 405 { 406 + struct ib_send_wr *post_wr, *send_wr = &req->rl_wr; 393 407 struct rpcrdma_ep *ep = r_xprt->rx_ep; 394 - struct ib_send_wr *post_wr; 395 408 struct rpcrdma_mr *mr; 409 + unsigned int num_wrs; 396 410 397 - post_wr = &req->rl_wr; 411 + num_wrs = 1; 412 + post_wr = send_wr; 398 413 list_for_each_entry(mr, &req->rl_registered, mr_list) { 399 - struct rpcrdma_frwr *frwr; 414 + trace_xprtrdma_mr_fastreg(mr); 400 415 401 - frwr = &mr->frwr; 402 - 403 - frwr->fr_cqe.done = frwr_wc_fastreg; 404 - frwr_cid_init(ep, frwr); 405 - frwr->fr_regwr.wr.next = post_wr; 406 - frwr->fr_regwr.wr.wr_cqe = &frwr->fr_cqe; 407 - frwr->fr_regwr.wr.num_sge = 0; 408 - frwr->fr_regwr.wr.opcode = IB_WR_REG_MR; 409 - frwr->fr_regwr.wr.send_flags = 0; 410 - 411 - post_wr = &frwr->fr_regwr.wr; 416 + mr->mr_cqe.done = frwr_wc_fastreg; 417 + mr->mr_regwr.wr.next = post_wr; 418 + mr->mr_regwr.wr.wr_cqe = &mr->mr_cqe; 419 + mr->mr_regwr.wr.num_sge = 0; 420 + mr->mr_regwr.wr.opcode = IB_WR_REG_MR; 421 + mr->mr_regwr.wr.send_flags = 0; 422 + post_wr = &mr->mr_regwr.wr; 423 + ++num_wrs; 412 424 } 413 425 426 + if ((kref_read(&req->rl_kref) > 1) || num_wrs > ep->re_send_count) { 427 + send_wr->send_flags |= IB_SEND_SIGNALED; 428 + ep->re_send_count = min_t(unsigned int, ep->re_send_batch, 429 + num_wrs - ep->re_send_count); 430 + } else { 431 + send_wr->send_flags &= ~IB_SEND_SIGNALED; 432 + ep->re_send_count -= num_wrs; 433 + } 434 + 435 + trace_xprtrdma_post_send(req); 414 436 return ib_post_send(ep->re_id->qp, post_wr, NULL); 415 437 } 416 438 ··· 436 440 list_for_each_entry(mr, mrs, mr_list) 437 441 if (mr->mr_handle == rep->rr_inv_rkey) { 438 442 list_del_init(&mr->mr_list); 443 + trace_xprtrdma_mr_reminv(mr); 439 444 frwr_mr_put(mr); 440 445 break; /* only one invalidated MR per RPC */ 441 446 } ··· 444 447 445 448 static void frwr_mr_done(struct ib_wc *wc, struct rpcrdma_mr *mr) 446 449 { 447 - if (wc->status != IB_WC_SUCCESS) 448 - frwr_mr_recycle(mr); 449 - else 450 + if (likely(wc->status == IB_WC_SUCCESS)) 450 451 frwr_mr_put(mr); 451 452 } 452 453 ··· 457 462 static void frwr_wc_localinv(struct ib_cq *cq, struct ib_wc *wc) 458 463 { 459 464 struct ib_cqe *cqe = wc->wr_cqe; 460 - struct rpcrdma_frwr *frwr = 461 - container_of(cqe, struct rpcrdma_frwr, fr_cqe); 462 - struct rpcrdma_mr *mr = container_of(frwr, struct rpcrdma_mr, frwr); 465 + struct rpcrdma_mr *mr = container_of(cqe, struct rpcrdma_mr, mr_cqe); 463 466 464 467 /* WARNING: Only wr_cqe and status are reliable at this point */ 465 - trace_xprtrdma_wc_li(wc, &frwr->fr_cid); 468 + trace_xprtrdma_wc_li(wc, &mr->mr_cid); 466 469 frwr_mr_done(wc, mr); 467 470 468 471 rpcrdma_flush_disconnect(cq->cq_context, wc); ··· 476 483 static void frwr_wc_localinv_wake(struct ib_cq *cq, struct ib_wc *wc) 477 484 { 478 485 struct ib_cqe *cqe = wc->wr_cqe; 479 - struct rpcrdma_frwr *frwr = 480 - container_of(cqe, struct rpcrdma_frwr, fr_cqe); 481 - struct rpcrdma_mr *mr = container_of(frwr, struct rpcrdma_mr, frwr); 486 + struct rpcrdma_mr *mr = container_of(cqe, struct rpcrdma_mr, mr_cqe); 482 487 483 488 /* WARNING: Only wr_cqe and status are reliable at this point */ 484 - trace_xprtrdma_wc_li_wake(wc, &frwr->fr_cid); 489 + trace_xprtrdma_wc_li_wake(wc, &mr->mr_cid); 485 490 frwr_mr_done(wc, mr); 486 - complete(&frwr->fr_linv_done); 491 + complete(&mr->mr_linv_done); 487 492 488 493 rpcrdma_flush_disconnect(cq->cq_context, wc); 489 494 } ··· 502 511 struct ib_send_wr *first, **prev, *last; 503 512 struct rpcrdma_ep *ep = r_xprt->rx_ep; 504 513 const struct ib_send_wr *bad_wr; 505 - struct rpcrdma_frwr *frwr; 506 514 struct rpcrdma_mr *mr; 507 515 int rc; 508 516 ··· 510 520 * Chain the LOCAL_INV Work Requests and post them with 511 521 * a single ib_post_send() call. 512 522 */ 513 - frwr = NULL; 514 523 prev = &first; 515 524 while ((mr = rpcrdma_mr_pop(&req->rl_registered))) { 516 525 517 526 trace_xprtrdma_mr_localinv(mr); 518 527 r_xprt->rx_stats.local_inv_needed++; 519 528 520 - frwr = &mr->frwr; 521 - frwr->fr_cqe.done = frwr_wc_localinv; 522 - frwr_cid_init(ep, frwr); 523 - last = &frwr->fr_invwr; 529 + last = &mr->mr_invwr; 524 530 last->next = NULL; 525 - last->wr_cqe = &frwr->fr_cqe; 531 + last->wr_cqe = &mr->mr_cqe; 526 532 last->sg_list = NULL; 527 533 last->num_sge = 0; 528 534 last->opcode = IB_WR_LOCAL_INV; 529 535 last->send_flags = IB_SEND_SIGNALED; 530 536 last->ex.invalidate_rkey = mr->mr_handle; 531 537 538 + last->wr_cqe->done = frwr_wc_localinv; 539 + 532 540 *prev = last; 533 541 prev = &last->next; 534 542 } 543 + mr = container_of(last, struct rpcrdma_mr, mr_invwr); 535 544 536 545 /* Strong send queue ordering guarantees that when the 537 546 * last WR in the chain completes, all WRs in the chain 538 547 * are complete. 539 548 */ 540 - frwr->fr_cqe.done = frwr_wc_localinv_wake; 541 - reinit_completion(&frwr->fr_linv_done); 549 + last->wr_cqe->done = frwr_wc_localinv_wake; 550 + reinit_completion(&mr->mr_linv_done); 542 551 543 552 /* Transport disconnect drains the receive CQ before it 544 553 * replaces the QP. The RPC reply handler won't call us ··· 551 562 * not happen, so don't wait in that case. 552 563 */ 553 564 if (bad_wr != first) 554 - wait_for_completion(&frwr->fr_linv_done); 565 + wait_for_completion(&mr->mr_linv_done); 555 566 if (!rc) 556 567 return; 557 568 558 - /* Recycle MRs in the LOCAL_INV chain that did not get posted. 559 - */ 569 + /* On error, the MRs get destroyed once the QP has drained. */ 560 570 trace_xprtrdma_post_linv_err(req, rc); 561 - while (bad_wr) { 562 - frwr = container_of(bad_wr, struct rpcrdma_frwr, 563 - fr_invwr); 564 - mr = container_of(frwr, struct rpcrdma_mr, frwr); 565 - bad_wr = bad_wr->next; 566 - 567 - list_del_init(&mr->mr_list); 568 - frwr_mr_recycle(mr); 569 - } 570 571 } 571 572 572 573 /** ··· 568 589 static void frwr_wc_localinv_done(struct ib_cq *cq, struct ib_wc *wc) 569 590 { 570 591 struct ib_cqe *cqe = wc->wr_cqe; 571 - struct rpcrdma_frwr *frwr = 572 - container_of(cqe, struct rpcrdma_frwr, fr_cqe); 573 - struct rpcrdma_mr *mr = container_of(frwr, struct rpcrdma_mr, frwr); 574 - struct rpcrdma_rep *rep = mr->mr_req->rl_reply; 592 + struct rpcrdma_mr *mr = container_of(cqe, struct rpcrdma_mr, mr_cqe); 593 + struct rpcrdma_rep *rep; 575 594 576 595 /* WARNING: Only wr_cqe and status are reliable at this point */ 577 - trace_xprtrdma_wc_li_done(wc, &frwr->fr_cid); 578 - frwr_mr_done(wc, mr); 596 + trace_xprtrdma_wc_li_done(wc, &mr->mr_cid); 579 597 580 - /* Ensure @rep is generated before frwr_mr_done */ 598 + /* Ensure that @rep is generated before the MR is released */ 599 + rep = mr->mr_req->rl_reply; 581 600 smp_rmb(); 582 - rpcrdma_complete_rqst(rep); 583 601 584 - rpcrdma_flush_disconnect(cq->cq_context, wc); 602 + if (wc->status != IB_WC_SUCCESS) { 603 + if (rep) 604 + rpcrdma_unpin_rqst(rep); 605 + rpcrdma_flush_disconnect(cq->cq_context, wc); 606 + return; 607 + } 608 + frwr_mr_put(mr); 609 + rpcrdma_complete_rqst(rep); 585 610 } 586 611 587 612 /** ··· 602 619 { 603 620 struct ib_send_wr *first, *last, **prev; 604 621 struct rpcrdma_ep *ep = r_xprt->rx_ep; 605 - const struct ib_send_wr *bad_wr; 606 - struct rpcrdma_frwr *frwr; 607 622 struct rpcrdma_mr *mr; 608 623 int rc; 609 624 610 625 /* Chain the LOCAL_INV Work Requests and post them with 611 626 * a single ib_post_send() call. 612 627 */ 613 - frwr = NULL; 614 628 prev = &first; 615 629 while ((mr = rpcrdma_mr_pop(&req->rl_registered))) { 616 630 617 631 trace_xprtrdma_mr_localinv(mr); 618 632 r_xprt->rx_stats.local_inv_needed++; 619 633 620 - frwr = &mr->frwr; 621 - frwr->fr_cqe.done = frwr_wc_localinv; 622 - frwr_cid_init(ep, frwr); 623 - last = &frwr->fr_invwr; 634 + last = &mr->mr_invwr; 624 635 last->next = NULL; 625 - last->wr_cqe = &frwr->fr_cqe; 636 + last->wr_cqe = &mr->mr_cqe; 626 637 last->sg_list = NULL; 627 638 last->num_sge = 0; 628 639 last->opcode = IB_WR_LOCAL_INV; 629 640 last->send_flags = IB_SEND_SIGNALED; 630 641 last->ex.invalidate_rkey = mr->mr_handle; 642 + 643 + last->wr_cqe->done = frwr_wc_localinv; 631 644 632 645 *prev = last; 633 646 prev = &last->next; ··· 634 655 * are complete. The last completion will wake up the 635 656 * RPC waiter. 636 657 */ 637 - frwr->fr_cqe.done = frwr_wc_localinv_done; 658 + last->wr_cqe->done = frwr_wc_localinv_done; 638 659 639 660 /* Transport disconnect drains the receive CQ before it 640 661 * replaces the QP. The RPC reply handler won't call us 641 662 * unless re_id->qp is a valid pointer. 642 663 */ 643 - bad_wr = NULL; 644 - rc = ib_post_send(ep->re_id->qp, first, &bad_wr); 664 + rc = ib_post_send(ep->re_id->qp, first, NULL); 645 665 if (!rc) 646 666 return; 647 667 648 - /* Recycle MRs in the LOCAL_INV chain that did not get posted. 649 - */ 668 + /* On error, the MRs get destroyed once the QP has drained. */ 650 669 trace_xprtrdma_post_linv_err(req, rc); 651 - while (bad_wr) { 652 - frwr = container_of(bad_wr, struct rpcrdma_frwr, fr_invwr); 653 - mr = container_of(frwr, struct rpcrdma_mr, frwr); 654 - bad_wr = bad_wr->next; 655 - 656 - frwr_mr_recycle(mr); 657 - } 658 670 659 671 /* The final LOCAL_INV WR in the chain is supposed to 660 - * do the wake. If it was never posted, the wake will 661 - * not happen, so wake here in that case. 672 + * do the wake. If it was never posted, the wake does 673 + * not happen. Unpin the rqst in preparation for its 674 + * retransmission. 662 675 */ 663 - rpcrdma_complete_rqst(req->rl_reply); 676 + rpcrdma_unpin_rqst(req->rl_reply); 664 677 }
+33 -6
net/sunrpc/xprtrdma/rpc_rdma.c
··· 1326 1326 return -EIO; 1327 1327 } 1328 1328 1329 - /* Perform XID lookup, reconstruction of the RPC reply, and 1330 - * RPC completion while holding the transport lock to ensure 1331 - * the rep, rqst, and rq_task pointers remain stable. 1329 + /** 1330 + * rpcrdma_unpin_rqst - Release rqst without completing it 1331 + * @rep: RPC/RDMA Receive context 1332 + * 1333 + * This is done when a connection is lost so that a Reply 1334 + * can be dropped and its matching Call can be subsequently 1335 + * retransmitted on a new connection. 1336 + */ 1337 + void rpcrdma_unpin_rqst(struct rpcrdma_rep *rep) 1338 + { 1339 + struct rpc_xprt *xprt = &rep->rr_rxprt->rx_xprt; 1340 + struct rpc_rqst *rqst = rep->rr_rqst; 1341 + struct rpcrdma_req *req = rpcr_to_rdmar(rqst); 1342 + 1343 + req->rl_reply = NULL; 1344 + rep->rr_rqst = NULL; 1345 + 1346 + spin_lock(&xprt->queue_lock); 1347 + xprt_unpin_rqst(rqst); 1348 + spin_unlock(&xprt->queue_lock); 1349 + } 1350 + 1351 + /** 1352 + * rpcrdma_complete_rqst - Pass completed rqst back to RPC 1353 + * @rep: RPC/RDMA Receive context 1354 + * 1355 + * Reconstruct the RPC reply and complete the transaction 1356 + * while @rqst is still pinned to ensure the rep, rqst, and 1357 + * rq_task pointers remain stable. 1332 1358 */ 1333 1359 void rpcrdma_complete_rqst(struct rpcrdma_rep *rep) 1334 1360 { ··· 1456 1430 credits = 1; /* don't deadlock */ 1457 1431 else if (credits > r_xprt->rx_ep->re_max_requests) 1458 1432 credits = r_xprt->rx_ep->re_max_requests; 1433 + rpcrdma_post_recvs(r_xprt, credits + (buf->rb_bc_srv_max_requests << 1), 1434 + false); 1459 1435 if (buf->rb_credits != credits) 1460 1436 rpcrdma_update_cwnd(r_xprt, credits); 1461 - rpcrdma_post_recvs(r_xprt, false); 1462 1437 1463 1438 req = rpcr_to_rdmar(rqst); 1464 1439 if (unlikely(req->rl_reply)) 1465 - rpcrdma_recv_buffer_put(req->rl_reply); 1440 + rpcrdma_rep_put(buf, req->rl_reply); 1466 1441 req->rl_reply = rep; 1467 1442 rep->rr_rqst = rqst; 1468 1443 ··· 1491 1464 trace_xprtrdma_reply_short_err(rep); 1492 1465 1493 1466 out: 1494 - rpcrdma_recv_buffer_put(rep); 1467 + rpcrdma_rep_put(buf, rep); 1495 1468 }
+4 -2
net/sunrpc/xprtrdma/transport.c
··· 262 262 * xprt_rdma_inject_disconnect - inject a connection fault 263 263 * @xprt: transport context 264 264 * 265 - * If @xprt is connected, disconnect it to simulate spurious connection 266 - * loss. 265 + * If @xprt is connected, disconnect it to simulate spurious 266 + * connection loss. Caller must hold @xprt's send lock to 267 + * ensure that data structures and hardware resources are 268 + * stable during the rdma_disconnect() call. 267 269 */ 268 270 static void 269 271 xprt_rdma_inject_disconnect(struct rpc_xprt *xprt)
+64 -67
net/sunrpc/xprtrdma/verbs.c
··· 101 101 struct rpcrdma_ep *ep = r_xprt->rx_ep; 102 102 struct rdma_cm_id *id = ep->re_id; 103 103 104 + /* Wait for rpcrdma_post_recvs() to leave its critical 105 + * section. 106 + */ 107 + if (atomic_inc_return(&ep->re_receiving) > 1) 108 + wait_for_completion(&ep->re_done); 109 + 104 110 /* Flush Receives, then wait for deferred Reply work 105 111 * to complete. 106 112 */ ··· 118 112 ib_drain_sq(id->qp); 119 113 120 114 rpcrdma_ep_put(ep); 121 - } 122 - 123 - /** 124 - * rpcrdma_qp_event_handler - Handle one QP event (error notification) 125 - * @event: details of the event 126 - * @context: ep that owns QP where event occurred 127 - * 128 - * Called from the RDMA provider (device driver) possibly in an interrupt 129 - * context. The QP is always destroyed before the ID, so the ID will be 130 - * reliably available when this handler is invoked. 131 - */ 132 - static void rpcrdma_qp_event_handler(struct ib_event *event, void *context) 133 - { 134 - struct rpcrdma_ep *ep = context; 135 - 136 - trace_xprtrdma_qp_event(ep, event); 137 115 } 138 116 139 117 /* Ensure xprt_force_disconnect() is invoked exactly once when a ··· 195 205 196 206 out_flushed: 197 207 rpcrdma_flush_disconnect(r_xprt, wc); 198 - rpcrdma_rep_destroy(rep); 208 + rpcrdma_rep_put(&r_xprt->rx_buf, rep); 199 209 } 200 210 201 211 static void rpcrdma_update_cm_private(struct rpcrdma_ep *ep, ··· 404 414 __module_get(THIS_MODULE); 405 415 device = id->device; 406 416 ep->re_id = id; 417 + reinit_completion(&ep->re_done); 407 418 408 419 ep->re_max_requests = r_xprt->rx_xprt.max_reqs; 409 420 ep->re_inline_send = xprt_rdma_max_inline_write; ··· 415 424 416 425 r_xprt->rx_buf.rb_max_requests = cpu_to_be32(ep->re_max_requests); 417 426 418 - ep->re_attr.event_handler = rpcrdma_qp_event_handler; 419 - ep->re_attr.qp_context = ep; 420 427 ep->re_attr.srq = NULL; 421 428 ep->re_attr.cap.max_inline_data = 0; 422 429 ep->re_attr.sq_sig_type = IB_SIGNAL_REQ_WR; ··· 524 535 * outstanding Receives. 525 536 */ 526 537 rpcrdma_ep_get(ep); 527 - rpcrdma_post_recvs(r_xprt, true); 538 + rpcrdma_post_recvs(r_xprt, 1, true); 528 539 529 540 rc = rdma_connect(ep->re_id, &ep->re_remote_cma); 530 541 if (rc) ··· 943 954 rpcrdma_req_reset(req); 944 955 } 945 956 946 - /* No locking needed here. This function is called only by the 947 - * Receive completion handler. 948 - */ 949 957 static noinline 950 958 struct rpcrdma_rep *rpcrdma_rep_create(struct rpcrdma_xprt *r_xprt, 951 959 bool temp) 952 960 { 961 + struct rpcrdma_buffer *buf = &r_xprt->rx_buf; 953 962 struct rpcrdma_rep *rep; 954 963 955 964 rep = kzalloc(sizeof(*rep), GFP_KERNEL); ··· 974 987 rep->rr_recv_wr.sg_list = &rep->rr_rdmabuf->rg_iov; 975 988 rep->rr_recv_wr.num_sge = 1; 976 989 rep->rr_temp = temp; 977 - list_add(&rep->rr_all, &r_xprt->rx_buf.rb_all_reps); 990 + 991 + spin_lock(&buf->rb_lock); 992 + list_add(&rep->rr_all, &buf->rb_all_reps); 993 + spin_unlock(&buf->rb_lock); 978 994 return rep; 979 995 980 996 out_free_regbuf: ··· 988 998 return NULL; 989 999 } 990 1000 991 - /* No locking needed here. This function is invoked only by the 992 - * Receive completion handler, or during transport shutdown. 993 - */ 994 - static void rpcrdma_rep_destroy(struct rpcrdma_rep *rep) 1001 + static void rpcrdma_rep_free(struct rpcrdma_rep *rep) 995 1002 { 996 - list_del(&rep->rr_all); 997 1003 rpcrdma_regbuf_free(rep->rr_rdmabuf); 998 1004 kfree(rep); 1005 + } 1006 + 1007 + static void rpcrdma_rep_destroy(struct rpcrdma_rep *rep) 1008 + { 1009 + struct rpcrdma_buffer *buf = &rep->rr_rxprt->rx_buf; 1010 + 1011 + spin_lock(&buf->rb_lock); 1012 + list_del(&rep->rr_all); 1013 + spin_unlock(&buf->rb_lock); 1014 + 1015 + rpcrdma_rep_free(rep); 999 1016 } 1000 1017 1001 1018 static struct rpcrdma_rep *rpcrdma_rep_get_locked(struct rpcrdma_buffer *buf) ··· 1016 1019 return llist_entry(node, struct rpcrdma_rep, rr_node); 1017 1020 } 1018 1021 1019 - static void rpcrdma_rep_put(struct rpcrdma_buffer *buf, 1020 - struct rpcrdma_rep *rep) 1022 + /** 1023 + * rpcrdma_rep_put - Release rpcrdma_rep back to free list 1024 + * @buf: buffer pool 1025 + * @rep: rep to release 1026 + * 1027 + */ 1028 + void rpcrdma_rep_put(struct rpcrdma_buffer *buf, struct rpcrdma_rep *rep) 1021 1029 { 1022 1030 llist_add(&rep->rr_node, &buf->rb_free_reps); 1023 1031 } 1024 1032 1033 + /* Caller must ensure the QP is quiescent (RQ is drained) before 1034 + * invoking this function, to guarantee rb_all_reps is not 1035 + * changing. 1036 + */ 1025 1037 static void rpcrdma_reps_unmap(struct rpcrdma_xprt *r_xprt) 1026 1038 { 1027 1039 struct rpcrdma_buffer *buf = &r_xprt->rx_buf; ··· 1038 1032 1039 1033 list_for_each_entry(rep, &buf->rb_all_reps, rr_all) { 1040 1034 rpcrdma_regbuf_dma_unmap(rep->rr_rdmabuf); 1041 - rep->rr_temp = true; 1035 + rep->rr_temp = true; /* Mark this rep for destruction */ 1042 1036 } 1043 1037 } 1044 1038 ··· 1046 1040 { 1047 1041 struct rpcrdma_rep *rep; 1048 1042 1049 - while ((rep = rpcrdma_rep_get_locked(buf)) != NULL) 1050 - rpcrdma_rep_destroy(rep); 1043 + spin_lock(&buf->rb_lock); 1044 + while ((rep = list_first_entry_or_null(&buf->rb_all_reps, 1045 + struct rpcrdma_rep, 1046 + rr_all)) != NULL) { 1047 + list_del(&rep->rr_all); 1048 + spin_unlock(&buf->rb_lock); 1049 + 1050 + rpcrdma_rep_free(rep); 1051 + 1052 + spin_lock(&buf->rb_lock); 1053 + } 1054 + spin_unlock(&buf->rb_lock); 1051 1055 } 1052 1056 1053 1057 /** ··· 1120 1104 list_del(&mr->mr_all); 1121 1105 spin_unlock(&buf->rb_lock); 1122 1106 1123 - frwr_release_mr(mr); 1107 + frwr_mr_release(mr); 1124 1108 } 1125 1109 1126 1110 rpcrdma_regbuf_free(req->rl_recvbuf); ··· 1151 1135 list_del(&mr->mr_all); 1152 1136 spin_unlock(&buf->rb_lock); 1153 1137 1154 - frwr_release_mr(mr); 1138 + frwr_mr_release(mr); 1155 1139 1156 1140 spin_lock(&buf->rb_lock); 1157 1141 } ··· 1235 1219 spin_lock(&buffers->rb_lock); 1236 1220 list_add(&req->rl_list, &buffers->rb_send_bufs); 1237 1221 spin_unlock(&buffers->rb_lock); 1238 - } 1239 - 1240 - /** 1241 - * rpcrdma_recv_buffer_put - Release rpcrdma_rep back to free list 1242 - * @rep: rep to release 1243 - * 1244 - * Used after error conditions. 1245 - */ 1246 - void rpcrdma_recv_buffer_put(struct rpcrdma_rep *rep) 1247 - { 1248 - rpcrdma_rep_put(&rep->rr_rxprt->rx_buf, rep); 1249 1222 } 1250 1223 1251 1224 /* Returns a pointer to a rpcrdma_regbuf object, or NULL. ··· 1347 1342 */ 1348 1343 int rpcrdma_post_sends(struct rpcrdma_xprt *r_xprt, struct rpcrdma_req *req) 1349 1344 { 1350 - struct ib_send_wr *send_wr = &req->rl_wr; 1351 - struct rpcrdma_ep *ep = r_xprt->rx_ep; 1352 - int rc; 1353 - 1354 - if (!ep->re_send_count || kref_read(&req->rl_kref) > 1) { 1355 - send_wr->send_flags |= IB_SEND_SIGNALED; 1356 - ep->re_send_count = ep->re_send_batch; 1357 - } else { 1358 - send_wr->send_flags &= ~IB_SEND_SIGNALED; 1359 - --ep->re_send_count; 1360 - } 1361 - 1362 - trace_xprtrdma_post_send(req); 1363 - rc = frwr_send(r_xprt, req); 1364 - if (rc) 1345 + if (frwr_send(r_xprt, req)) 1365 1346 return -ENOTCONN; 1366 1347 return 0; 1367 1348 } ··· 1355 1364 /** 1356 1365 * rpcrdma_post_recvs - Refill the Receive Queue 1357 1366 * @r_xprt: controlling transport instance 1358 - * @temp: mark Receive buffers to be deleted after use 1367 + * @needed: current credit grant 1368 + * @temp: mark Receive buffers to be deleted after one use 1359 1369 * 1360 1370 */ 1361 - void rpcrdma_post_recvs(struct rpcrdma_xprt *r_xprt, bool temp) 1371 + void rpcrdma_post_recvs(struct rpcrdma_xprt *r_xprt, int needed, bool temp) 1362 1372 { 1363 1373 struct rpcrdma_buffer *buf = &r_xprt->rx_buf; 1364 1374 struct rpcrdma_ep *ep = r_xprt->rx_ep; 1365 1375 struct ib_recv_wr *wr, *bad_wr; 1366 1376 struct rpcrdma_rep *rep; 1367 - int needed, count, rc; 1377 + int count, rc; 1368 1378 1369 1379 rc = 0; 1370 1380 count = 0; 1371 1381 1372 - needed = buf->rb_credits + (buf->rb_bc_srv_max_requests << 1); 1373 1382 if (likely(ep->re_receive_count > needed)) 1374 1383 goto out; 1375 1384 needed -= ep->re_receive_count; 1376 1385 if (!temp) 1377 1386 needed += RPCRDMA_MAX_RECV_BATCH; 1387 + 1388 + if (atomic_inc_return(&ep->re_receiving) > 1) 1389 + goto out; 1378 1390 1379 1391 /* fast path: all needed reps can be found on the free list */ 1380 1392 wr = NULL; ··· 1404 1410 1405 1411 rc = ib_post_recv(ep->re_id->qp, wr, 1406 1412 (const struct ib_recv_wr **)&bad_wr); 1413 + if (atomic_dec_return(&ep->re_receiving) > 0) 1414 + complete(&ep->re_done); 1415 + 1407 1416 out: 1408 1417 trace_xprtrdma_post_recvs(r_xprt, count, rc); 1409 1418 if (rc) { ··· 1415 1418 1416 1419 rep = container_of(wr, struct rpcrdma_rep, rr_recv_wr); 1417 1420 wr = wr->next; 1418 - rpcrdma_recv_buffer_put(rep); 1421 + rpcrdma_rep_put(buf, rep); 1419 1422 --count; 1420 1423 } 1421 1424 }
+14 -15
net/sunrpc/xprtrdma/xprt_rdma.h
··· 83 83 unsigned int re_max_inline_recv; 84 84 int re_async_rc; 85 85 int re_connect_status; 86 + atomic_t re_receiving; 86 87 atomic_t re_force_disconnect; 87 88 struct ib_qp_init_attr re_attr; 88 89 wait_queue_head_t re_connect_wait; ··· 229 228 * An external memory region is any buffer or page that is registered 230 229 * on the fly (ie, not pre-registered). 231 230 */ 232 - struct rpcrdma_frwr { 233 - struct ib_mr *fr_mr; 234 - struct ib_cqe fr_cqe; 235 - struct rpc_rdma_cid fr_cid; 236 - struct completion fr_linv_done; 237 - union { 238 - struct ib_reg_wr fr_regwr; 239 - struct ib_send_wr fr_invwr; 240 - }; 241 - }; 242 - 243 231 struct rpcrdma_req; 244 232 struct rpcrdma_mr { 245 233 struct list_head mr_list; 246 234 struct rpcrdma_req *mr_req; 235 + 236 + struct ib_mr *mr_ibmr; 247 237 struct ib_device *mr_device; 248 238 struct scatterlist *mr_sg; 249 239 int mr_nents; 250 240 enum dma_data_direction mr_dir; 251 - struct rpcrdma_frwr frwr; 241 + struct ib_cqe mr_cqe; 242 + struct completion mr_linv_done; 243 + union { 244 + struct ib_reg_wr mr_regwr; 245 + struct ib_send_wr mr_invwr; 246 + }; 252 247 struct rpcrdma_xprt *mr_xprt; 253 248 u32 mr_handle; 254 249 u32 mr_length; 255 250 u64 mr_offset; 256 251 struct list_head mr_all; 252 + struct rpc_rdma_cid mr_cid; 257 253 }; 258 254 259 255 /* ··· 459 461 void rpcrdma_xprt_disconnect(struct rpcrdma_xprt *r_xprt); 460 462 461 463 int rpcrdma_post_sends(struct rpcrdma_xprt *r_xprt, struct rpcrdma_req *req); 462 - void rpcrdma_post_recvs(struct rpcrdma_xprt *r_xprt, bool temp); 464 + void rpcrdma_post_recvs(struct rpcrdma_xprt *r_xprt, int needed, bool temp); 463 465 464 466 /* 465 467 * Buffer calls - xprtrdma/verbs.c ··· 478 480 struct rpcrdma_req *rpcrdma_buffer_get(struct rpcrdma_buffer *); 479 481 void rpcrdma_buffer_put(struct rpcrdma_buffer *buffers, 480 482 struct rpcrdma_req *req); 481 - void rpcrdma_recv_buffer_put(struct rpcrdma_rep *); 483 + void rpcrdma_rep_put(struct rpcrdma_buffer *buf, struct rpcrdma_rep *rep); 482 484 483 485 bool rpcrdma_regbuf_realloc(struct rpcrdma_regbuf *rb, size_t size, 484 486 gfp_t flags); ··· 525 527 void frwr_reset(struct rpcrdma_req *req); 526 528 int frwr_query_device(struct rpcrdma_ep *ep, const struct ib_device *device); 527 529 int frwr_mr_init(struct rpcrdma_xprt *r_xprt, struct rpcrdma_mr *mr); 528 - void frwr_release_mr(struct rpcrdma_mr *mr); 530 + void frwr_mr_release(struct rpcrdma_mr *mr); 529 531 struct rpcrdma_mr_seg *frwr_map(struct rpcrdma_xprt *r_xprt, 530 532 struct rpcrdma_mr_seg *seg, 531 533 int nsegs, bool writing, __be32 xid, ··· 558 560 void rpcrdma_set_max_header_sizes(struct rpcrdma_ep *ep); 559 561 void rpcrdma_reset_cwnd(struct rpcrdma_xprt *r_xprt); 560 562 void rpcrdma_complete_rqst(struct rpcrdma_rep *rep); 563 + void rpcrdma_unpin_rqst(struct rpcrdma_rep *rep); 561 564 void rpcrdma_reply_handler(struct rpcrdma_rep *rep); 562 565 563 566 static inline void rpcrdma_set_xdrlen(struct xdr_buf *xdr, size_t len)
+8 -1
net/sunrpc/xprtsock.c
··· 558 558 struct rpc_rqst *req; 559 559 ssize_t ret; 560 560 561 + /* Is this transport associated with the backchannel? */ 562 + if (!xprt->bc_serv) 563 + return -ESHUTDOWN; 564 + 561 565 /* Look up and lock the request corresponding to the given XID */ 562 566 req = xprt_lookup_bc_request(xprt, transport->recv.xid); 563 567 if (!req) { ··· 1022 1018 * to cope with writespace callbacks arriving _after_ we have 1023 1019 * called sendmsg(). */ 1024 1020 req->rq_xtime = ktime_get(); 1021 + tcp_sock_set_cork(transport->inet, true); 1025 1022 while (1) { 1026 1023 status = xprt_sock_sendmsg(transport->sock, &msg, xdr, 1027 1024 transport->xmit.offset, rm, &sent); ··· 1037 1032 if (likely(req->rq_bytes_sent >= msglen)) { 1038 1033 req->rq_xmit_bytes_sent += transport->xmit.offset; 1039 1034 transport->xmit.offset = 0; 1035 + if (atomic_long_read(&xprt->xmit_queuelen) == 1) 1036 + tcp_sock_set_cork(transport->inet, false); 1040 1037 return 0; 1041 1038 } 1042 1039 ··· 2170 2163 } 2171 2164 2172 2165 xs_tcp_set_socket_timeouts(xprt, sock); 2166 + tcp_sock_set_nodelay(sk); 2173 2167 2174 2168 write_lock_bh(&sk->sk_callback_lock); 2175 2169 ··· 2185 2177 2186 2178 /* socket options */ 2187 2179 sock_reset_flag(sk, SOCK_LINGER); 2188 - tcp_sk(sk)->nonagle |= TCP_NAGLE_OFF; 2189 2180 2190 2181 xprt_clear_connected(xprt); 2191 2182