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

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

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

- Full audit of BUG_ON asserts in the NFS, SUNRPC and lockd client
code. Remove altogether where possible, and replace with
WARN_ON_ONCE and appropriate error returns where not.
- NFSv4.1 client adds session dynamic slot table management. There
is matching server side code that has been submitted to Bruce for
consideration.

Together, this code allows the server to dynamically manage the
amount of memory it allocates to the duplicate request cache for
each client. It will constantly resize those caches to reserve
more memory for clients that are hot while shrinking caches for
those that are quiescent.

In addition, there are assorted bugfixes for the generic NFS write
code, fixes to deal with the drop_nlink() warnings, and yet another
fix for NFSv4 getacl."

* tag 'nfs-for-3.8-1' of git://git.linux-nfs.org/projects/trondmy/linux-nfs: (106 commits)
SUNRPC: continue run over clients list on PipeFS event instead of break
NFS: Don't use SetPageError in the NFS writeback code
SUNRPC: variable 'svsk' is unused in function bc_send_request
SUNRPC: Handle ECONNREFUSED in xs_local_setup_socket
NFSv4.1: Deal effectively with interrupted RPC calls.
NFSv4.1: Move the RPC timestamp out of the slot.
NFSv4.1: Try to deal with NFS4ERR_SEQ_MISORDERED.
NFS: nfs_lookup_revalidate should not trust an inode with i_nlink == 0
NFS: Fix calls to drop_nlink()
NFS: Ensure that we always drop inodes that have been marked as stale
nfs: Remove unused list nfs4_clientid_list
nfs: Remove duplicate function declaration in internal.h
NFS: avoid NULL dereference in nfs_destroy_server
SUNRPC handle EKEYEXPIRED in call_refreshresult
SUNRPC set gss gc_expiry to full lifetime
nfs: fix page dirtying in NFS DIO read codepath
nfs: don't zero out the rest of the page if we hit the EOF on a DIO READ
NFSv4.1: Be conservative about the client highest slotid
NFSv4.1: Handle NFS4ERR_BADSLOT errors correctly
nfs: don't extend writes to cover entire page if pagecache is invalid
...

+1335 -1174
-8
fs/lockd/clnt4xdr.c
··· 64 64 { 65 65 const struct file_lock *fl = &lock->fl; 66 66 67 - BUG_ON(fl->fl_start > NLM4_OFFSET_MAX); 68 - BUG_ON(fl->fl_end > NLM4_OFFSET_MAX && 69 - fl->fl_end != OFFSET_MAX); 70 - 71 67 *l_offset = loff_t_to_s64(fl->fl_start); 72 68 if (fl->fl_end == OFFSET_MAX) 73 69 *l_len = 0; ··· 118 122 { 119 123 __be32 *p; 120 124 121 - BUG_ON(length > XDR_MAX_NETOBJ); 122 125 p = xdr_reserve_space(xdr, 4 + length); 123 126 xdr_encode_opaque(p, data, length); 124 127 } ··· 151 156 static void encode_cookie(struct xdr_stream *xdr, 152 157 const struct nlm_cookie *cookie) 153 158 { 154 - BUG_ON(cookie->len > NLM_MAXCOOKIELEN); 155 159 encode_netobj(xdr, (u8 *)&cookie->data, cookie->len); 156 160 } 157 161 ··· 192 198 */ 193 199 static void encode_fh(struct xdr_stream *xdr, const struct nfs_fh *fh) 194 200 { 195 - BUG_ON(fh->size > NFS3_FHSIZE); 196 201 encode_netobj(xdr, (u8 *)&fh->data, fh->size); 197 202 } 198 203 ··· 329 336 u32 length = strlen(name); 330 337 __be32 *p; 331 338 332 - BUG_ON(length > NLM_MAXSTRLEN); 333 339 p = xdr_reserve_space(xdr, 4 + length); 334 340 xdr_encode_opaque(p, name, length); 335 341 }
+1 -2
fs/lockd/clntproc.c
··· 141 141 142 142 static void nlmclnt_release_lockargs(struct nlm_rqst *req) 143 143 { 144 - BUG_ON(req->a_args.lock.fl.fl_ops != NULL); 144 + WARN_ON_ONCE(req->a_args.lock.fl.fl_ops != NULL); 145 145 } 146 146 147 147 /** ··· 465 465 466 466 static void nlmclnt_locks_init_private(struct file_lock *fl, struct nlm_host *host) 467 467 { 468 - BUG_ON(fl->fl_ops != NULL); 469 468 fl->fl_u.nfs_fl.state = 0; 470 469 fl->fl_u.nfs_fl.owner = nlm_find_lockowner(host, fl->fl_owner); 471 470 INIT_LIST_HEAD(&fl->fl_u.nfs_fl.list);
-8
fs/lockd/clntxdr.c
··· 60 60 { 61 61 const struct file_lock *fl = &lock->fl; 62 62 63 - BUG_ON(fl->fl_start > NLM_OFFSET_MAX); 64 - BUG_ON(fl->fl_end > NLM_OFFSET_MAX && 65 - fl->fl_end != OFFSET_MAX); 66 - 67 63 *l_offset = loff_t_to_s32(fl->fl_start); 68 64 if (fl->fl_end == OFFSET_MAX) 69 65 *l_len = 0; ··· 115 119 { 116 120 __be32 *p; 117 121 118 - BUG_ON(length > XDR_MAX_NETOBJ); 119 122 p = xdr_reserve_space(xdr, 4 + length); 120 123 xdr_encode_opaque(p, data, length); 121 124 } ··· 148 153 static void encode_cookie(struct xdr_stream *xdr, 149 154 const struct nlm_cookie *cookie) 150 155 { 151 - BUG_ON(cookie->len > NLM_MAXCOOKIELEN); 152 156 encode_netobj(xdr, (u8 *)&cookie->data, cookie->len); 153 157 } 154 158 ··· 189 195 */ 190 196 static void encode_fh(struct xdr_stream *xdr, const struct nfs_fh *fh) 191 197 { 192 - BUG_ON(fh->size != NFS2_FHSIZE); 193 198 encode_netobj(xdr, (u8 *)&fh->data, NFS2_FHSIZE); 194 199 } 195 200 ··· 323 330 u32 length = strlen(name); 324 331 __be32 *p; 325 332 326 - BUG_ON(length > NLM_MAXSTRLEN); 327 333 p = xdr_reserve_space(xdr, 4 + length); 328 334 xdr_encode_opaque(p, name, length); 329 335 }
+5 -10
fs/lockd/host.c
··· 177 177 178 178 dprintk("lockd: destroy host %s\n", host->h_name); 179 179 180 - BUG_ON(!list_empty(&host->h_lockowners)); 181 - BUG_ON(atomic_read(&host->h_count)); 182 - 183 180 hlist_del_init(&host->h_hash); 184 181 185 182 nsm_unmonitor(host); ··· 286 289 287 290 dprintk("lockd: release client host %s\n", host->h_name); 288 291 289 - BUG_ON(atomic_read(&host->h_count) < 0); 290 - BUG_ON(host->h_server); 292 + WARN_ON_ONCE(host->h_server); 291 293 292 294 if (atomic_dec_and_test(&host->h_count)) { 293 - BUG_ON(!list_empty(&host->h_lockowners)); 294 - BUG_ON(!list_empty(&host->h_granted)); 295 - BUG_ON(!list_empty(&host->h_reclaim)); 295 + WARN_ON_ONCE(!list_empty(&host->h_lockowners)); 296 + WARN_ON_ONCE(!list_empty(&host->h_granted)); 297 + WARN_ON_ONCE(!list_empty(&host->h_reclaim)); 296 298 297 299 mutex_lock(&nlm_host_mutex); 298 300 nlm_destroy_host_locked(host); ··· 408 412 409 413 dprintk("lockd: release server host %s\n", host->h_name); 410 414 411 - BUG_ON(atomic_read(&host->h_count) < 0); 412 - BUG_ON(!host->h_server); 415 + WARN_ON_ONCE(!host->h_server); 413 416 atomic_dec(&host->h_count); 414 417 } 415 418
-3
fs/lockd/mon.c
··· 154 154 .rpc_resp = res, 155 155 }; 156 156 157 - BUG_ON(clnt == NULL); 158 - 159 157 memset(res, 0, sizeof(*res)); 160 158 161 159 msg.rpc_proc = &clnt->cl_procinfo[proc]; ··· 464 466 const u32 len = strlen(string); 465 467 __be32 *p; 466 468 467 - BUG_ON(len > SM_MAXSTRLEN); 468 469 p = xdr_reserve_space(xdr, 4 + len); 469 470 xdr_encode_opaque(p, string, len); 470 471 }
+1 -1
fs/nfs/Makefile
··· 24 24 delegation.o idmap.o callback.o callback_xdr.o callback_proc.o \ 25 25 nfs4namespace.o nfs4getroot.o nfs4client.o 26 26 nfsv4-$(CONFIG_SYSCTL) += nfs4sysctl.o 27 - nfsv4-$(CONFIG_NFS_V4_1) += pnfs.o pnfs_dev.o 27 + nfsv4-$(CONFIG_NFS_V4_1) += nfs4session.o pnfs.o pnfs_dev.o 28 28 29 29 obj-$(CONFIG_PNFS_FILE_LAYOUT) += nfs_layout_nfsv41_files.o 30 30 nfs_layout_nfsv41_files-y := nfs4filelayout.o nfs4filelayoutdev.o
+1
fs/nfs/blocklayout/blocklayout.c
··· 40 40 #include <linux/pagevec.h> 41 41 42 42 #include "../pnfs.h" 43 + #include "../nfs4session.h" 43 44 #include "../internal.h" 44 45 #include "blocklayout.h" 45 46
-1
fs/nfs/cache_lib.c
··· 118 118 struct dentry *dir; 119 119 120 120 dir = rpc_d_lookup_sb(sb, "cache"); 121 - BUG_ON(dir == NULL); 122 121 ret = sunrpc_cache_register_pipefs(dir, cd->name, 0600, cd); 123 122 dput(dir); 124 123 return ret;
+1 -3
fs/nfs/callback.h
··· 142 142 143 143 struct cb_recallslotargs { 144 144 struct sockaddr *crsa_addr; 145 - uint32_t crsa_target_max_slots; 145 + uint32_t crsa_target_highest_slotid; 146 146 }; 147 147 extern __be32 nfs4_callback_recallslot(struct cb_recallslotargs *args, 148 148 void *dummy, ··· 166 166 extern __be32 nfs4_callback_layoutrecall( 167 167 struct cb_layoutrecallargs *args, 168 168 void *dummy, struct cb_process_state *cps); 169 - 170 - extern void nfs4_check_drain_bc_complete(struct nfs4_session *ses); 171 169 172 170 struct cb_devicenotifyitem { 173 171 uint32_t cbd_notify_type;
+5 -12
fs/nfs/callback_proc.c
··· 14 14 #include "delegation.h" 15 15 #include "internal.h" 16 16 #include "pnfs.h" 17 + #include "nfs4session.h" 17 18 18 19 #ifdef NFS_DEBUG 19 20 #define NFSDBG_FACILITY NFSDBG_CALLBACK ··· 217 216 } 218 217 pnfs_get_layout_hdr(lo); 219 218 spin_unlock(&ino->i_lock); 220 - BUG_ON(!list_empty(&lo->plh_bulk_recall)); 221 219 list_add(&lo->plh_bulk_recall, &recall_list); 222 220 } 223 221 } ··· 562 562 if (!cps->clp) /* set in cb_sequence */ 563 563 goto out; 564 564 565 - dprintk_rcu("NFS: CB_RECALL_SLOT request from %s target max slots %d\n", 565 + dprintk_rcu("NFS: CB_RECALL_SLOT request from %s target highest slotid %d\n", 566 566 rpc_peeraddr2str(cps->clp->cl_rpcclient, RPC_DISPLAY_ADDR), 567 - args->crsa_target_max_slots); 567 + args->crsa_target_highest_slotid); 568 568 569 569 fc_tbl = &cps->clp->cl_session->fc_slot_table; 570 570 571 - status = htonl(NFS4ERR_BAD_HIGH_SLOT); 572 - if (args->crsa_target_max_slots > fc_tbl->max_slots || 573 - args->crsa_target_max_slots < 1) 574 - goto out; 575 - 576 571 status = htonl(NFS4_OK); 577 - if (args->crsa_target_max_slots == fc_tbl->max_slots) 578 - goto out; 579 572 580 - fc_tbl->target_max_slots = args->crsa_target_max_slots; 581 - nfs41_handle_recall_slot(cps->clp); 573 + nfs41_set_target_slotid(fc_tbl, args->crsa_target_highest_slotid); 574 + nfs41_server_notify_target_slotid_update(cps->clp); 582 575 out: 583 576 dprintk("%s: exit with status = %d\n", __func__, ntohl(status)); 584 577 return status;
+3 -2
fs/nfs/callback_xdr.c
··· 16 16 #include "nfs4_fs.h" 17 17 #include "callback.h" 18 18 #include "internal.h" 19 + #include "nfs4session.h" 19 20 20 21 #define CB_OP_TAGLEN_MAXSZ (512) 21 22 #define CB_OP_HDR_RES_MAXSZ (2 + CB_OP_TAGLEN_MAXSZ) ··· 521 520 p = read_buf(xdr, 4); 522 521 if (unlikely(p == NULL)) 523 522 return htonl(NFS4ERR_BADXDR); 524 - args->crsa_target_max_slots = ntohl(*p++); 523 + args->crsa_target_highest_slotid = ntohl(*p++); 525 524 return 0; 526 525 } 527 526 ··· 763 762 * A single slot, so highest used slotid is either 0 or -1 764 763 */ 765 764 tbl->highest_used_slotid = NFS4_NO_SLOT; 766 - nfs4_check_drain_bc_complete(session); 765 + nfs4_session_drain_complete(session, tbl); 767 766 spin_unlock(&tbl->slot_tbl_lock); 768 767 } 769 768
+2 -7
fs/nfs/client.c
··· 277 277 nfs_cb_idr_remove_locked(clp); 278 278 spin_unlock(&nn->nfs_client_lock); 279 279 280 - BUG_ON(!list_empty(&clp->cl_superblocks)); 280 + WARN_ON_ONCE(!list_empty(&clp->cl_superblocks)); 281 281 282 282 clp->rpc_ops->free_client(clp); 283 283 } ··· 615 615 */ 616 616 static void nfs_destroy_server(struct nfs_server *server) 617 617 { 618 - if (!(server->flags & NFS_MOUNT_LOCAL_FLOCK) || 619 - !(server->flags & NFS_MOUNT_LOCAL_FCNTL)) 618 + if (server->nlm_host) 620 619 nlmclnt_done(server->nlm_host); 621 620 } 622 621 ··· 1059 1060 error = nfs_init_server(server, mount_info->parsed, nfs_mod); 1060 1061 if (error < 0) 1061 1062 goto error; 1062 - 1063 - BUG_ON(!server->nfs_client); 1064 - BUG_ON(!server->nfs_client->rpc_ops); 1065 - BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops); 1066 1063 1067 1064 /* Probe the root fh to retrieve its FSID */ 1068 1065 error = nfs_probe_fsinfo(server, mount_info->mntfh, fattr);
+14 -8
fs/nfs/dir.c
··· 979 979 * particular file and the "nocto" mount flag is not set. 980 980 * 981 981 */ 982 - static inline 982 + static 983 983 int nfs_lookup_verify_inode(struct inode *inode, unsigned int flags) 984 984 { 985 985 struct nfs_server *server = NFS_SERVER(inode); 986 + int ret; 986 987 987 988 if (IS_AUTOMOUNT(inode)) 988 989 return 0; ··· 994 993 if ((flags & LOOKUP_OPEN) && !(server->flags & NFS_MOUNT_NOCTO) && 995 994 (S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode))) 996 995 goto out_force; 997 - return 0; 996 + out: 997 + return (inode->i_nlink == 0) ? -ENOENT : 0; 998 998 out_force: 999 - return __nfs_revalidate_inode(server, inode); 999 + ret = __nfs_revalidate_inode(server, inode); 1000 + if (ret != 0) 1001 + return ret; 1002 + goto out; 1000 1003 } 1001 1004 1002 1005 /* ··· 1161 1156 1162 1157 } 1163 1158 1159 + /* Ensure that we revalidate inode->i_nlink */ 1164 1160 static void nfs_drop_nlink(struct inode *inode) 1165 1161 { 1166 1162 spin_lock(&inode->i_lock); 1167 - if (inode->i_nlink > 0) 1168 - drop_nlink(inode); 1163 + /* drop the inode if we're reasonably sure this is the last link */ 1164 + if (inode->i_nlink == 1) 1165 + clear_nlink(inode); 1166 + NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; 1169 1167 spin_unlock(&inode->i_lock); 1170 1168 } 1171 1169 ··· 1183 1175 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_DATA; 1184 1176 1185 1177 if (dentry->d_flags & DCACHE_NFSFS_RENAMED) { 1186 - drop_nlink(inode); 1187 1178 nfs_complete_unlink(dentry, inode); 1179 + nfs_drop_nlink(inode); 1188 1180 } 1189 1181 iput(inode); 1190 1182 } ··· 1655 1647 if (inode != NULL) { 1656 1648 NFS_PROTO(inode)->return_delegation(inode); 1657 1649 error = NFS_PROTO(dir)->remove(dir, &dentry->d_name); 1658 - /* The VFS may want to delete this inode */ 1659 1650 if (error == 0) 1660 1651 nfs_drop_nlink(inode); 1661 - nfs_mark_for_revalidate(inode); 1662 1652 } else 1663 1653 error = NFS_PROTO(dir)->remove(dir, &dentry->d_name); 1664 1654 if (error == -ENOENT)
+2 -15
fs/nfs/direct.c
··· 266 266 struct nfs_page *req = nfs_list_entry(hdr->pages.next); 267 267 struct page *page = req->wb_page; 268 268 269 - if (test_bit(NFS_IOHDR_EOF, &hdr->flags)) { 270 - if (bytes > hdr->good_bytes) 271 - zero_user(page, 0, PAGE_SIZE); 272 - else if (hdr->good_bytes - bytes < PAGE_SIZE) 273 - zero_user_segment(page, 274 - hdr->good_bytes & ~PAGE_MASK, 275 - PAGE_SIZE); 276 - } 277 - if (!PageCompound(page)) { 278 - if (test_bit(NFS_IOHDR_ERROR, &hdr->flags)) { 279 - if (bytes < hdr->good_bytes) 280 - set_page_dirty(page); 281 - } else 282 - set_page_dirty(page); 283 - } 269 + if (!PageCompound(page) && bytes < hdr->good_bytes) 270 + set_page_dirty(page); 284 271 bytes += req->wb_bytes; 285 272 nfs_list_remove_request(req); 286 273 nfs_direct_readpage_release(req);
+8 -2
fs/nfs/inode.c
··· 107 107 return ino; 108 108 } 109 109 110 + int nfs_drop_inode(struct inode *inode) 111 + { 112 + return NFS_STALE(inode) || generic_drop_inode(inode); 113 + } 114 + EXPORT_SYMBOL_GPL(nfs_drop_inode); 115 + 110 116 void nfs_clear_inode(struct inode *inode) 111 117 { 112 118 /* 113 119 * The following should never happen... 114 120 */ 115 - BUG_ON(nfs_have_writebacks(inode)); 116 - BUG_ON(!list_empty(&NFS_I(inode)->open_files)); 121 + WARN_ON_ONCE(nfs_have_writebacks(inode)); 122 + WARN_ON_ONCE(!list_empty(&NFS_I(inode)->open_files)); 117 123 nfs_zap_acl_cache(inode); 118 124 nfs_access_zap_cache(inode); 119 125 nfs_fscache_release_inode_cookie(inode);
+1 -41
fs/nfs/internal.h
··· 18 18 */ 19 19 #define NFS_MAX_READAHEAD (RPC_DEF_SLOT_TABLE - 1) 20 20 21 - /* 22 - * Determine if sessions are in use. 23 - */ 24 - static inline int nfs4_has_session(const struct nfs_client *clp) 25 - { 26 - #ifdef CONFIG_NFS_V4_1 27 - if (clp->cl_session) 28 - return 1; 29 - #endif /* CONFIG_NFS_V4_1 */ 30 - return 0; 31 - } 32 - 33 - static inline int nfs4_has_persistent_session(const struct nfs_client *clp) 34 - { 35 - #ifdef CONFIG_NFS_V4_1 36 - if (nfs4_has_session(clp)) 37 - return (clp->cl_session->flags & SESSION4_PERSIST); 38 - #endif /* CONFIG_NFS_V4_1 */ 39 - return 0; 40 - } 41 - 42 21 static inline void nfs_attr_check_mountpoint(struct super_block *parent, struct nfs_fattr *fattr) 43 22 { 44 23 if (!nfs_fsid_equal(&NFS_SB(parent)->fsid, &fattr->fsid)) ··· 255 276 extern struct rpc_procinfo nfs4_procedures[]; 256 277 #endif 257 278 258 - extern int nfs4_init_ds_session(struct nfs_client *, unsigned long); 259 - 260 279 /* proc.c */ 261 280 void nfs_close_context(struct nfs_open_context *ctx, int is_sync); 262 281 extern struct nfs_client *nfs_init_client(struct nfs_client *clp, ··· 296 319 extern struct inode *nfs_alloc_inode(struct super_block *sb); 297 320 extern void nfs_destroy_inode(struct inode *); 298 321 extern int nfs_write_inode(struct inode *, struct writeback_control *); 322 + extern int nfs_drop_inode(struct inode *); 299 323 extern void nfs_clear_inode(struct inode *); 300 324 extern void nfs_evict_inode(struct inode *); 301 325 void nfs_zap_acl_cache(struct inode *inode); ··· 364 386 extern void nfs_read_prepare(struct rpc_task *task, void *calldata); 365 387 extern int nfs_generic_pagein(struct nfs_pageio_descriptor *desc, 366 388 struct nfs_pgio_header *hdr); 367 - extern void nfs_pageio_init_read(struct nfs_pageio_descriptor *pgio, 368 - struct inode *inode, 369 - const struct nfs_pgio_completion_ops *compl_ops); 370 389 extern void nfs_pageio_reset_read_mds(struct nfs_pageio_descriptor *pgio); 371 390 extern void nfs_readdata_release(struct nfs_read_data *rdata); 372 391 ··· 386 411 extern void nfs_writehdr_free(struct nfs_pgio_header *hdr); 387 412 extern int nfs_generic_flush(struct nfs_pageio_descriptor *desc, 388 413 struct nfs_pgio_header *hdr); 389 - extern void nfs_pageio_init_write(struct nfs_pageio_descriptor *pgio, 390 - struct inode *inode, int ioflags, 391 - const struct nfs_pgio_completion_ops *compl_ops); 392 414 extern void nfs_pageio_reset_write_mds(struct nfs_pageio_descriptor *pgio); 393 415 extern void nfs_writedata_release(struct nfs_write_data *wdata); 394 416 extern void nfs_commit_free(struct nfs_commit_data *p); ··· 446 474 const struct rpc_timeout *timeparms, 447 475 const char *ip_addr, 448 476 rpc_authflavor_t authflavour); 449 - extern int _nfs4_call_sync(struct rpc_clnt *clnt, 450 - struct nfs_server *server, 451 - struct rpc_message *msg, 452 - struct nfs4_sequence_args *args, 453 - struct nfs4_sequence_res *res, 454 - int cache_reply); 455 - extern int _nfs4_call_sync_session(struct rpc_clnt *clnt, 456 - struct nfs_server *server, 457 - struct rpc_message *msg, 458 - struct nfs4_sequence_args *args, 459 - struct nfs4_sequence_res *res, 460 - int cache_reply); 461 477 extern int nfs40_walk_client_list(struct nfs_client *clp, 462 478 struct nfs_client **result, 463 479 struct rpc_cred *cred);
+6 -1
fs/nfs/mount_clnt.c
··· 169 169 (info->hostname ? info->hostname : "server"), 170 170 info->dirpath); 171 171 172 + if (strlen(info->dirpath) > MNTPATHLEN) 173 + return -ENAMETOOLONG; 174 + 172 175 if (info->noresvport) 173 176 args.flags |= RPC_CLNT_CREATE_NONPRIVPORT; 174 177 ··· 245 242 struct rpc_clnt *clnt; 246 243 int status; 247 244 245 + if (strlen(info->dirpath) > MNTPATHLEN) 246 + return; 247 + 248 248 if (info->noresvport) 249 249 args.flags |= RPC_CLNT_CREATE_NONPRIVPORT; 250 250 ··· 289 283 const u32 pathname_len = strlen(pathname); 290 284 __be32 *p; 291 285 292 - BUG_ON(pathname_len > MNTPATHLEN); 293 286 p = xdr_reserve_space(xdr, 4 + pathname_len); 294 287 xdr_encode_opaque(p, pathname, pathname_len); 295 288 }
+1 -3
fs/nfs/nfs2xdr.c
··· 195 195 { 196 196 __be32 *p; 197 197 198 - BUG_ON(fh->size != NFS2_FHSIZE); 199 198 p = xdr_reserve_space(xdr, NFS2_FHSIZE); 200 199 memcpy(p, fh->data, NFS2_FHSIZE); 201 200 } ··· 387 388 { 388 389 __be32 *p; 389 390 390 - BUG_ON(length > NFS2_MAXNAMLEN); 391 + WARN_ON_ONCE(length > NFS2_MAXNAMLEN); 391 392 p = xdr_reserve_space(xdr, 4 + length); 392 393 xdr_encode_opaque(p, name, length); 393 394 } ··· 427 428 { 428 429 __be32 *p; 429 430 430 - BUG_ON(length > NFS2_MAXPATHLEN); 431 431 p = xdr_reserve_space(xdr, 4); 432 432 *p = cpu_to_be32(length); 433 433 xdr_write_pages(xdr, pages, 0, length);
+3 -3
fs/nfs/nfs3proc.c
··· 24 24 25 25 #define NFSDBG_FACILITY NFSDBG_PROC 26 26 27 - /* A wrapper to handle the EJUKEBOX and EKEYEXPIRED error messages */ 27 + /* A wrapper to handle the EJUKEBOX error messages */ 28 28 static int 29 29 nfs3_rpc_wrapper(struct rpc_clnt *clnt, struct rpc_message *msg, int flags) 30 30 { 31 31 int res; 32 32 do { 33 33 res = rpc_call_sync(clnt, msg, flags); 34 - if (res != -EJUKEBOX && res != -EKEYEXPIRED) 34 + if (res != -EJUKEBOX) 35 35 break; 36 36 freezable_schedule_timeout_killable(NFS_JUKEBOX_RETRY_TIME); 37 37 res = -ERESTARTSYS; ··· 44 44 static int 45 45 nfs3_async_handle_jukebox(struct rpc_task *task, struct inode *inode) 46 46 { 47 - if (task->tk_status != -EJUKEBOX && task->tk_status != -EKEYEXPIRED) 47 + if (task->tk_status != -EJUKEBOX) 48 48 return 0; 49 49 if (task->tk_status == -EJUKEBOX) 50 50 nfs_inc_stats(inode, NFSIOS_DELAY);
+3 -4
fs/nfs/nfs3xdr.c
··· 198 198 { 199 199 __be32 *p; 200 200 201 - BUG_ON(length > NFS3_MAXNAMLEN); 201 + WARN_ON_ONCE(length > NFS3_MAXNAMLEN); 202 202 p = xdr_reserve_space(xdr, 4 + length); 203 203 xdr_encode_opaque(p, name, length); 204 204 } ··· 238 238 static void encode_nfspath3(struct xdr_stream *xdr, struct page **pages, 239 239 const u32 length) 240 240 { 241 - BUG_ON(length > NFS3_MAXPATHLEN); 242 241 encode_uint32(xdr, length); 243 242 xdr_write_pages(xdr, pages, 0, length); 244 243 } ··· 387 388 */ 388 389 static void encode_ftype3(struct xdr_stream *xdr, const u32 type) 389 390 { 390 - BUG_ON(type > NF3FIFO); 391 391 encode_uint32(xdr, type); 392 392 } 393 393 ··· 441 443 { 442 444 __be32 *p; 443 445 444 - BUG_ON(fh->size > NFS3_FHSIZE); 446 + WARN_ON_ONCE(fh->size > NFS3_FHSIZE); 445 447 p = xdr_reserve_space(xdr, 4 + fh->size); 446 448 xdr_encode_opaque(p, fh->data, fh->size); 447 449 } ··· 1337 1339 error = nfsacl_encode(xdr->buf, base, args->inode, 1338 1340 (args->mask & NFS_ACL) ? 1339 1341 args->acl_access : NULL, 1, 0); 1342 + /* FIXME: this is just broken */ 1340 1343 BUG_ON(error < 0); 1341 1344 error = nfsacl_encode(xdr->buf, base + error, args->inode, 1342 1345 (args->mask & NFS_DFACL) ?
+10 -19
fs/nfs/nfs4_fs.h
··· 11 11 12 12 #if IS_ENABLED(CONFIG_NFS_V4) 13 13 14 + #define NFS4_MAX_LOOP_ON_RECOVER (10) 15 + 14 16 struct idmap; 15 17 16 18 enum nfs4_client_state { ··· 23 21 NFS4CLNT_RECLAIM_NOGRACE, 24 22 NFS4CLNT_DELEGRETURN, 25 23 NFS4CLNT_SESSION_RESET, 26 - NFS4CLNT_RECALL_SLOT, 27 24 NFS4CLNT_LEASE_CONFIRM, 28 25 NFS4CLNT_SERVER_SCOPE_MISMATCH, 29 26 NFS4CLNT_PURGE_STATE, 30 27 NFS4CLNT_BIND_CONN_TO_SESSION, 31 - }; 32 - 33 - enum nfs4_session_state { 34 - NFS4_SESSION_INITING, 35 - NFS4_SESSION_DRAINING, 36 28 }; 37 29 38 30 #define NFS4_RENEW_TIMEOUT 0x01 ··· 39 43 struct nfs_server *server, 40 44 struct rpc_message *msg, 41 45 struct nfs4_sequence_args *args, 42 - struct nfs4_sequence_res *res, 43 - int cache_reply); 46 + struct nfs4_sequence_res *res); 44 47 bool (*match_stateid)(const nfs4_stateid *, 45 48 const nfs4_stateid *); 46 49 int (*find_root_sec)(struct nfs_server *, struct nfs_fh *, ··· 236 241 return server->nfs_client->cl_session; 237 242 } 238 243 239 - extern bool nfs4_set_task_privileged(struct rpc_task *task, void *dummy); 240 244 extern int nfs4_setup_sequence(const struct nfs_server *server, 241 245 struct nfs4_sequence_args *args, struct nfs4_sequence_res *res, 242 246 struct rpc_task *task); 243 247 extern int nfs41_setup_sequence(struct nfs4_session *session, 244 248 struct nfs4_sequence_args *args, struct nfs4_sequence_res *res, 245 249 struct rpc_task *task); 246 - extern void nfs4_destroy_session(struct nfs4_session *session); 247 - extern struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp); 248 250 extern int nfs4_proc_create_session(struct nfs_client *, struct rpc_cred *); 249 251 extern int nfs4_proc_destroy_session(struct nfs4_session *, struct rpc_cred *); 250 - extern int nfs4_init_session(struct nfs_server *server); 251 252 extern int nfs4_proc_get_lease_time(struct nfs_client *clp, 252 253 struct nfs_fsinfo *fsinfo); 253 254 extern int nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, ··· 271 280 struct nfs4_sequence_args *args, struct nfs4_sequence_res *res, 272 281 struct rpc_task *task) 273 282 { 274 - return 0; 275 - } 276 - 277 - static inline int nfs4_init_session(struct nfs_server *server) 278 - { 283 + rpc_call_start(task); 279 284 return 0; 280 285 } 281 286 ··· 308 321 309 322 /* nfs4state.c */ 310 323 struct rpc_cred *nfs4_get_setclientid_cred(struct nfs_client *clp); 324 + struct rpc_cred *nfs4_get_machine_cred_locked(struct nfs_client *clp); 311 325 struct rpc_cred *nfs4_get_renew_cred_locked(struct nfs_client *clp); 312 326 int nfs4_discover_server_trunking(struct nfs_client *clp, 313 327 struct nfs_client **); 314 328 int nfs40_discover_server_trunking(struct nfs_client *clp, 315 329 struct nfs_client **, struct rpc_cred *); 316 330 #if defined(CONFIG_NFS_V4_1) 317 - struct rpc_cred *nfs4_get_machine_cred_locked(struct nfs_client *clp); 318 331 struct rpc_cred *nfs4_get_exchange_id_cred(struct nfs_client *clp); 319 332 int nfs41_discover_server_trunking(struct nfs_client *clp, 320 333 struct nfs_client **, struct rpc_cred *); 321 334 extern void nfs4_schedule_session_recovery(struct nfs4_session *, int); 335 + extern void nfs41_server_notify_target_slotid_update(struct nfs_client *clp); 336 + extern void nfs41_server_notify_highest_slotid_update(struct nfs_client *clp); 337 + 322 338 #else 323 339 static inline void nfs4_schedule_session_recovery(struct nfs4_session *session, int err) 324 340 { ··· 339 349 extern void nfs_inode_find_state_and_recover(struct inode *inode, 340 350 const nfs4_stateid *stateid); 341 351 extern void nfs4_schedule_lease_recovery(struct nfs_client *); 352 + extern int nfs4_wait_clnt_recover(struct nfs_client *clp); 353 + extern int nfs4_client_recover_expired_lease(struct nfs_client *clp); 342 354 extern void nfs4_schedule_state_manager(struct nfs_client *); 343 355 extern void nfs4_schedule_path_down_recovery(struct nfs_client *clp); 344 356 extern void nfs4_schedule_stateid_recovery(const struct nfs_server *, struct nfs4_state *); 345 357 extern void nfs41_handle_sequence_flag_errors(struct nfs_client *clp, u32 flags); 346 - extern void nfs41_handle_recall_slot(struct nfs_client *clp); 347 358 extern void nfs41_handle_server_scope(struct nfs_client *, 348 359 struct nfs41_server_scope **); 349 360 extern void nfs4_put_lock_state(struct nfs4_lock_state *lsp);
+1 -4
fs/nfs/nfs4client.c
··· 12 12 #include "internal.h" 13 13 #include "callback.h" 14 14 #include "delegation.h" 15 + #include "nfs4session.h" 15 16 #include "pnfs.h" 16 17 #include "netns.h" 17 18 ··· 713 712 { 714 713 struct nfs_fattr *fattr; 715 714 int error; 716 - 717 - BUG_ON(!server->nfs_client); 718 - BUG_ON(!server->nfs_client->rpc_ops); 719 - BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops); 720 715 721 716 /* data servers support only a subset of NFSv4.1 */ 722 717 if (is_ds_only_client(server->nfs_client))
-1
fs/nfs/nfs4file.c
··· 20 20 struct iattr attr; 21 21 int err; 22 22 23 - BUG_ON(inode != dentry->d_inode); 24 23 /* 25 24 * If no cached dentry exists or if it's negative, NFSv4 handled the 26 25 * opens in ->lookup() or ->create().
+17 -28
fs/nfs/nfs4filelayout.c
··· 35 35 36 36 #include <linux/sunrpc/metrics.h> 37 37 38 + #include "nfs4session.h" 38 39 #include "internal.h" 39 40 #include "delegation.h" 40 41 #include "nfs4filelayout.h" ··· 179 178 break; 180 179 case -NFS4ERR_DELAY: 181 180 case -NFS4ERR_GRACE: 182 - case -EKEYEXPIRED: 183 181 rpc_delay(task, FILELAYOUT_POLL_RETRY_MAX); 184 182 break; 185 183 case -NFS4ERR_RETRY_UNCACHED_REP: ··· 306 306 } 307 307 rdata->read_done_cb = filelayout_read_done_cb; 308 308 309 - if (nfs41_setup_sequence(rdata->ds_clp->cl_session, 310 - &rdata->args.seq_args, &rdata->res.seq_res, 311 - task)) 312 - return; 313 - 314 - rpc_call_start(task); 309 + nfs41_setup_sequence(rdata->ds_clp->cl_session, 310 + &rdata->args.seq_args, 311 + &rdata->res.seq_res, 312 + task); 315 313 } 316 314 317 315 static void filelayout_read_call_done(struct rpc_task *task, void *data) ··· 406 408 rpc_exit(task, 0); 407 409 return; 408 410 } 409 - if (nfs41_setup_sequence(wdata->ds_clp->cl_session, 410 - &wdata->args.seq_args, &wdata->res.seq_res, 411 - task)) 412 - return; 413 - 414 - rpc_call_start(task); 411 + nfs41_setup_sequence(wdata->ds_clp->cl_session, 412 + &wdata->args.seq_args, 413 + &wdata->res.seq_res, 414 + task); 415 415 } 416 416 417 417 static void filelayout_write_call_done(struct rpc_task *task, void *data) ··· 445 449 { 446 450 struct nfs_commit_data *wdata = data; 447 451 448 - if (nfs41_setup_sequence(wdata->ds_clp->cl_session, 449 - &wdata->args.seq_args, &wdata->res.seq_res, 450 - task)) 451 - return; 452 - 453 - rpc_call_start(task); 452 + nfs41_setup_sequence(wdata->ds_clp->cl_session, 453 + &wdata->args.seq_args, 454 + &wdata->res.seq_res, 455 + task); 454 456 } 455 457 456 458 static void filelayout_write_commit_done(struct rpc_task *task, void *data) ··· 506 512 loff_t offset = data->args.offset; 507 513 u32 j, idx; 508 514 struct nfs_fh *fh; 509 - int status; 510 515 511 516 dprintk("--> %s ino %lu pgbase %u req %Zu@%llu\n", 512 517 __func__, hdr->inode->i_ino, ··· 531 538 data->mds_offset = offset; 532 539 533 540 /* Perform an asynchronous read to ds */ 534 - status = nfs_initiate_read(ds->ds_clp->cl_rpcclient, data, 541 + nfs_initiate_read(ds->ds_clp->cl_rpcclient, data, 535 542 &filelayout_read_call_ops, RPC_TASK_SOFTCONN); 536 - BUG_ON(status != 0); 537 543 return PNFS_ATTEMPTED; 538 544 } 539 545 ··· 546 554 loff_t offset = data->args.offset; 547 555 u32 j, idx; 548 556 struct nfs_fh *fh; 549 - int status; 550 557 551 558 /* Retrieve the correct rpc_client for the byte range */ 552 559 j = nfs4_fl_calc_j_index(lseg, offset); ··· 570 579 data->args.offset = filelayout_get_dserver_offset(lseg, offset); 571 580 572 581 /* Perform an asynchronous write */ 573 - status = nfs_initiate_write(ds->ds_clp->cl_rpcclient, data, 582 + nfs_initiate_write(ds->ds_clp->cl_rpcclient, data, 574 583 &filelayout_write_call_ops, sync, 575 584 RPC_TASK_SOFTCONN); 576 - BUG_ON(status != 0); 577 585 return PNFS_ATTEMPTED; 578 586 } 579 587 ··· 899 909 filelayout_pg_init_read(struct nfs_pageio_descriptor *pgio, 900 910 struct nfs_page *req) 901 911 { 902 - BUG_ON(pgio->pg_lseg != NULL); 912 + WARN_ON_ONCE(pgio->pg_lseg != NULL); 903 913 904 914 if (req->wb_offset != req->wb_pgbase) { 905 915 /* ··· 929 939 struct nfs_commit_info cinfo; 930 940 int status; 931 941 932 - BUG_ON(pgio->pg_lseg != NULL); 942 + WARN_ON_ONCE(pgio->pg_lseg != NULL); 933 943 934 944 if (req->wb_offset != req->wb_pgbase) 935 945 goto out_mds; ··· 1177 1187 */ 1178 1188 for (i = 0, b = cinfo->ds->buckets; i < cinfo->ds->nbuckets; i++, b++) { 1179 1189 if (transfer_commit_list(&b->written, dst, cinfo, 0)) { 1180 - BUG_ON(!list_empty(&b->written)); 1181 1190 pnfs_put_lseg(b->wlseg); 1182 1191 b->wlseg = NULL; 1183 1192 }
+1 -2
fs/nfs/nfs4filelayoutdev.c
··· 33 33 #include <linux/module.h> 34 34 35 35 #include "internal.h" 36 + #include "nfs4session.h" 36 37 #include "nfs4filelayout.h" 37 38 38 39 #define NFSDBG_FACILITY NFSDBG_PNFS_LD ··· 162 161 163 162 dprintk("--> %s DS %s au_flavor %d\n", __func__, ds->ds_remotestr, 164 163 mds_srv->nfs_client->cl_rpcclient->cl_auth->au_flavor); 165 - 166 - BUG_ON(list_empty(&ds->ds_addrs)); 167 164 168 165 list_for_each_entry(da, &ds->ds_addrs, da_node) { 169 166 dprintk("%s: DS %s: trying address %s\n",
+229 -591
fs/nfs/nfs4proc.c
··· 52 52 #include <linux/mount.h> 53 53 #include <linux/module.h> 54 54 #include <linux/nfs_idmap.h> 55 - #include <linux/sunrpc/bc_xprt.h> 56 55 #include <linux/xattr.h> 57 56 #include <linux/utsname.h> 58 57 #include <linux/freezer.h> ··· 63 64 #include "callback.h" 64 65 #include "pnfs.h" 65 66 #include "netns.h" 67 + #include "nfs4session.h" 68 + 66 69 67 70 #define NFSDBG_FACILITY NFSDBG_PROC 68 71 69 72 #define NFS4_POLL_RETRY_MIN (HZ/10) 70 73 #define NFS4_POLL_RETRY_MAX (15*HZ) 71 - 72 - #define NFS4_MAX_LOOP_ON_RECOVER (10) 73 74 74 75 struct nfs4_opendata; 75 76 static int _nfs4_proc_open(struct nfs4_opendata *data); ··· 205 206 { 206 207 __be32 *start, *p; 207 208 208 - BUG_ON(readdir->count < 80); 209 209 if (cookie > 2) { 210 210 readdir->cookie = cookie; 211 211 memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); ··· 252 254 readdir->pgbase = (char *)p - (char *)start; 253 255 readdir->count -= readdir->pgbase; 254 256 kunmap_atomic(start); 255 - } 256 - 257 - static int nfs4_wait_clnt_recover(struct nfs_client *clp) 258 - { 259 - int res; 260 - 261 - might_sleep(); 262 - 263 - res = wait_on_bit(&clp->cl_state, NFS4CLNT_MANAGER_RUNNING, 264 - nfs_wait_bit_killable, TASK_KILLABLE); 265 - if (res) 266 - return res; 267 - 268 - if (clp->cl_cons_state < 0) 269 - return clp->cl_cons_state; 270 - return 0; 271 257 } 272 258 273 259 static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) ··· 333 351 } 334 352 case -NFS4ERR_GRACE: 335 353 case -NFS4ERR_DELAY: 336 - case -EKEYEXPIRED: 337 354 ret = nfs4_delay(server->client, &exception->timeout); 338 355 if (ret != 0) 339 356 break; ··· 378 397 379 398 #if defined(CONFIG_NFS_V4_1) 380 399 381 - /* 382 - * nfs4_free_slot - free a slot and efficiently update slot table. 383 - * 384 - * freeing a slot is trivially done by clearing its respective bit 385 - * in the bitmap. 386 - * If the freed slotid equals highest_used_slotid we want to update it 387 - * so that the server would be able to size down the slot table if needed, 388 - * otherwise we know that the highest_used_slotid is still in use. 389 - * When updating highest_used_slotid there may be "holes" in the bitmap 390 - * so we need to scan down from highest_used_slotid to 0 looking for the now 391 - * highest slotid in use. 392 - * If none found, highest_used_slotid is set to NFS4_NO_SLOT. 393 - * 394 - * Must be called while holding tbl->slot_tbl_lock 395 - */ 396 - static void 397 - nfs4_free_slot(struct nfs4_slot_table *tbl, u32 slotid) 398 - { 399 - BUG_ON(slotid >= NFS4_MAX_SLOT_TABLE); 400 - /* clear used bit in bitmap */ 401 - __clear_bit(slotid, tbl->used_slots); 402 - 403 - /* update highest_used_slotid when it is freed */ 404 - if (slotid == tbl->highest_used_slotid) { 405 - slotid = find_last_bit(tbl->used_slots, tbl->max_slots); 406 - if (slotid < tbl->max_slots) 407 - tbl->highest_used_slotid = slotid; 408 - else 409 - tbl->highest_used_slotid = NFS4_NO_SLOT; 410 - } 411 - dprintk("%s: slotid %u highest_used_slotid %d\n", __func__, 412 - slotid, tbl->highest_used_slotid); 413 - } 414 - 415 - bool nfs4_set_task_privileged(struct rpc_task *task, void *dummy) 416 - { 417 - rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); 418 - return true; 419 - } 420 - 421 - /* 422 - * Signal state manager thread if session fore channel is drained 423 - */ 424 - static void nfs4_check_drain_fc_complete(struct nfs4_session *ses) 425 - { 426 - if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state)) { 427 - rpc_wake_up_first(&ses->fc_slot_table.slot_tbl_waitq, 428 - nfs4_set_task_privileged, NULL); 429 - return; 430 - } 431 - 432 - if (ses->fc_slot_table.highest_used_slotid != NFS4_NO_SLOT) 433 - return; 434 - 435 - dprintk("%s COMPLETE: Session Fore Channel Drained\n", __func__); 436 - complete(&ses->fc_slot_table.complete); 437 - } 438 - 439 - /* 440 - * Signal state manager thread if session back channel is drained 441 - */ 442 - void nfs4_check_drain_bc_complete(struct nfs4_session *ses) 443 - { 444 - if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state) || 445 - ses->bc_slot_table.highest_used_slotid != NFS4_NO_SLOT) 446 - return; 447 - dprintk("%s COMPLETE: Session Back Channel Drained\n", __func__); 448 - complete(&ses->bc_slot_table.complete); 449 - } 450 - 451 400 static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) 452 401 { 402 + struct nfs4_session *session; 453 403 struct nfs4_slot_table *tbl; 404 + bool send_new_highest_used_slotid = false; 454 405 455 - tbl = &res->sr_session->fc_slot_table; 456 406 if (!res->sr_slot) { 457 407 /* just wake up the next guy waiting since 458 408 * we may have not consumed a slot after all */ 459 409 dprintk("%s: No slot\n", __func__); 460 410 return; 461 411 } 412 + tbl = res->sr_slot->table; 413 + session = tbl->session; 462 414 463 415 spin_lock(&tbl->slot_tbl_lock); 464 - nfs4_free_slot(tbl, res->sr_slot - tbl->slots); 465 - nfs4_check_drain_fc_complete(res->sr_session); 416 + /* Be nice to the server: try to ensure that the last transmitted 417 + * value for highest_user_slotid <= target_highest_slotid 418 + */ 419 + if (tbl->highest_used_slotid > tbl->target_highest_slotid) 420 + send_new_highest_used_slotid = true; 421 + 422 + if (nfs41_wake_and_assign_slot(tbl, res->sr_slot)) { 423 + send_new_highest_used_slotid = false; 424 + goto out_unlock; 425 + } 426 + nfs4_free_slot(tbl, res->sr_slot); 427 + 428 + if (tbl->highest_used_slotid != NFS4_NO_SLOT) 429 + send_new_highest_used_slotid = false; 430 + out_unlock: 466 431 spin_unlock(&tbl->slot_tbl_lock); 467 432 res->sr_slot = NULL; 433 + if (send_new_highest_used_slotid) 434 + nfs41_server_notify_highest_slotid_update(session->clp); 468 435 } 469 436 470 437 static int nfs41_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res) 471 438 { 472 - unsigned long timestamp; 439 + struct nfs4_session *session; 440 + struct nfs4_slot *slot; 473 441 struct nfs_client *clp; 474 - 475 - /* 476 - * sr_status remains 1 if an RPC level error occurred. The server 477 - * may or may not have processed the sequence operation.. 478 - * Proceed as if the server received and processed the sequence 479 - * operation. 480 - */ 481 - if (res->sr_status == 1) 482 - res->sr_status = NFS_OK; 442 + bool interrupted = false; 443 + int ret = 1; 483 444 484 445 /* don't increment the sequence number if the task wasn't sent */ 485 446 if (!RPC_WAS_SENT(task)) 486 447 goto out; 487 448 449 + slot = res->sr_slot; 450 + session = slot->table->session; 451 + 452 + if (slot->interrupted) { 453 + slot->interrupted = 0; 454 + interrupted = true; 455 + } 456 + 488 457 /* Check the SEQUENCE operation status */ 489 458 switch (res->sr_status) { 490 459 case 0: 491 460 /* Update the slot's sequence and clientid lease timer */ 492 - ++res->sr_slot->seq_nr; 493 - timestamp = res->sr_renewal_time; 494 - clp = res->sr_session->clp; 495 - do_renew_lease(clp, timestamp); 461 + ++slot->seq_nr; 462 + clp = session->clp; 463 + do_renew_lease(clp, res->sr_timestamp); 496 464 /* Check sequence flags */ 497 465 if (res->sr_status_flags != 0) 498 466 nfs4_schedule_lease_recovery(clp); 467 + nfs41_update_target_slotid(slot->table, slot, res); 499 468 break; 469 + case 1: 470 + /* 471 + * sr_status remains 1 if an RPC level error occurred. 472 + * The server may or may not have processed the sequence 473 + * operation.. 474 + * Mark the slot as having hosted an interrupted RPC call. 475 + */ 476 + slot->interrupted = 1; 477 + goto out; 500 478 case -NFS4ERR_DELAY: 501 479 /* The server detected a resend of the RPC call and 502 480 * returned NFS4ERR_DELAY as per Section 2.10.6.2 503 481 * of RFC5661. 504 482 */ 505 - dprintk("%s: slot=%td seq=%d: Operation in progress\n", 483 + dprintk("%s: slot=%u seq=%u: Operation in progress\n", 506 484 __func__, 507 - res->sr_slot - res->sr_session->fc_slot_table.slots, 508 - res->sr_slot->seq_nr); 485 + slot->slot_nr, 486 + slot->seq_nr); 509 487 goto out_retry; 488 + case -NFS4ERR_BADSLOT: 489 + /* 490 + * The slot id we used was probably retired. Try again 491 + * using a different slot id. 492 + */ 493 + goto retry_nowait; 494 + case -NFS4ERR_SEQ_MISORDERED: 495 + /* 496 + * Was the last operation on this sequence interrupted? 497 + * If so, retry after bumping the sequence number. 498 + */ 499 + if (interrupted) { 500 + ++slot->seq_nr; 501 + goto retry_nowait; 502 + } 503 + /* 504 + * Could this slot have been previously retired? 505 + * If so, then the server may be expecting seq_nr = 1! 506 + */ 507 + if (slot->seq_nr != 1) { 508 + slot->seq_nr = 1; 509 + goto retry_nowait; 510 + } 511 + break; 512 + case -NFS4ERR_SEQ_FALSE_RETRY: 513 + ++slot->seq_nr; 514 + goto retry_nowait; 510 515 default: 511 516 /* Just update the slot sequence no. */ 512 - ++res->sr_slot->seq_nr; 517 + ++slot->seq_nr; 513 518 } 514 519 out: 515 520 /* The session may be reset by one of the error handlers. */ 516 521 dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); 517 522 nfs41_sequence_free_slot(res); 518 - return 1; 523 + return ret; 524 + retry_nowait: 525 + if (rpc_restart_call_prepare(task)) { 526 + task->tk_status = 0; 527 + ret = 0; 528 + } 529 + goto out; 519 530 out_retry: 520 531 if (!rpc_restart_call(task)) 521 532 goto out; ··· 518 545 static int nfs4_sequence_done(struct rpc_task *task, 519 546 struct nfs4_sequence_res *res) 520 547 { 521 - if (res->sr_session == NULL) 548 + if (res->sr_slot == NULL) 522 549 return 1; 523 550 return nfs41_sequence_done(task, res); 524 - } 525 - 526 - /* 527 - * nfs4_find_slot - efficiently look for a free slot 528 - * 529 - * nfs4_find_slot looks for an unset bit in the used_slots bitmap. 530 - * If found, we mark the slot as used, update the highest_used_slotid, 531 - * and respectively set up the sequence operation args. 532 - * The slot number is returned if found, or NFS4_NO_SLOT otherwise. 533 - * 534 - * Note: must be called with under the slot_tbl_lock. 535 - */ 536 - static u32 537 - nfs4_find_slot(struct nfs4_slot_table *tbl) 538 - { 539 - u32 slotid; 540 - u32 ret_id = NFS4_NO_SLOT; 541 - 542 - dprintk("--> %s used_slots=%04lx highest_used=%u max_slots=%u\n", 543 - __func__, tbl->used_slots[0], tbl->highest_used_slotid, 544 - tbl->max_slots); 545 - slotid = find_first_zero_bit(tbl->used_slots, tbl->max_slots); 546 - if (slotid >= tbl->max_slots) 547 - goto out; 548 - __set_bit(slotid, tbl->used_slots); 549 - if (slotid > tbl->highest_used_slotid || 550 - tbl->highest_used_slotid == NFS4_NO_SLOT) 551 - tbl->highest_used_slotid = slotid; 552 - ret_id = slotid; 553 - out: 554 - dprintk("<-- %s used_slots=%04lx highest_used=%d slotid=%d \n", 555 - __func__, tbl->used_slots[0], tbl->highest_used_slotid, ret_id); 556 - return ret_id; 557 551 } 558 552 559 553 static void nfs41_init_sequence(struct nfs4_sequence_args *args, 560 554 struct nfs4_sequence_res *res, int cache_reply) 561 555 { 562 - args->sa_session = NULL; 556 + args->sa_slot = NULL; 563 557 args->sa_cache_this = 0; 558 + args->sa_privileged = 0; 564 559 if (cache_reply) 565 560 args->sa_cache_this = 1; 566 - res->sr_session = NULL; 567 561 res->sr_slot = NULL; 562 + } 563 + 564 + static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args) 565 + { 566 + args->sa_privileged = 1; 568 567 } 569 568 570 569 int nfs41_setup_sequence(struct nfs4_session *session, ··· 546 601 { 547 602 struct nfs4_slot *slot; 548 603 struct nfs4_slot_table *tbl; 549 - u32 slotid; 550 604 551 605 dprintk("--> %s\n", __func__); 552 606 /* slot already allocated? */ 553 607 if (res->sr_slot != NULL) 554 - return 0; 608 + goto out_success; 555 609 556 610 tbl = &session->fc_slot_table; 557 611 612 + task->tk_timeout = 0; 613 + 558 614 spin_lock(&tbl->slot_tbl_lock); 559 615 if (test_bit(NFS4_SESSION_DRAINING, &session->session_state) && 560 - !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { 616 + !args->sa_privileged) { 561 617 /* The state manager will wait until the slot table is empty */ 562 - rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); 563 - spin_unlock(&tbl->slot_tbl_lock); 564 618 dprintk("%s session is draining\n", __func__); 565 - return -EAGAIN; 619 + goto out_sleep; 566 620 } 567 621 568 - if (!rpc_queue_empty(&tbl->slot_tbl_waitq) && 569 - !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { 570 - rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); 571 - spin_unlock(&tbl->slot_tbl_lock); 572 - dprintk("%s enforce FIFO order\n", __func__); 573 - return -EAGAIN; 574 - } 575 - 576 - slotid = nfs4_find_slot(tbl); 577 - if (slotid == NFS4_NO_SLOT) { 578 - rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); 579 - spin_unlock(&tbl->slot_tbl_lock); 622 + slot = nfs4_alloc_slot(tbl); 623 + if (IS_ERR(slot)) { 624 + /* If out of memory, try again in 1/4 second */ 625 + if (slot == ERR_PTR(-ENOMEM)) 626 + task->tk_timeout = HZ >> 2; 580 627 dprintk("<-- %s: no free slots\n", __func__); 581 - return -EAGAIN; 628 + goto out_sleep; 582 629 } 583 630 spin_unlock(&tbl->slot_tbl_lock); 584 631 585 - rpc_task_set_priority(task, RPC_PRIORITY_NORMAL); 586 - slot = tbl->slots + slotid; 587 - args->sa_session = session; 588 - args->sa_slotid = slotid; 632 + args->sa_slot = slot; 589 633 590 - dprintk("<-- %s slotid=%d seqid=%d\n", __func__, slotid, slot->seq_nr); 634 + dprintk("<-- %s slotid=%d seqid=%d\n", __func__, 635 + slot->slot_nr, slot->seq_nr); 591 636 592 - res->sr_session = session; 593 637 res->sr_slot = slot; 594 - res->sr_renewal_time = jiffies; 638 + res->sr_timestamp = jiffies; 595 639 res->sr_status_flags = 0; 596 640 /* 597 641 * sr_status is only set in decode_sequence, and so will remain 598 642 * set to 1 if an rpc level failure occurs. 599 643 */ 600 644 res->sr_status = 1; 645 + out_success: 646 + rpc_call_start(task); 601 647 return 0; 648 + out_sleep: 649 + /* Privileged tasks are queued with top priority */ 650 + if (args->sa_privileged) 651 + rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, 652 + NULL, RPC_PRIORITY_PRIVILEGED); 653 + else 654 + rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); 655 + spin_unlock(&tbl->slot_tbl_lock); 656 + return -EAGAIN; 602 657 } 603 658 EXPORT_SYMBOL_GPL(nfs41_setup_sequence); 604 659 ··· 610 665 struct nfs4_session *session = nfs4_get_session(server); 611 666 int ret = 0; 612 667 613 - if (session == NULL) 668 + if (session == NULL) { 669 + rpc_call_start(task); 614 670 goto out; 671 + } 615 672 616 - dprintk("--> %s clp %p session %p sr_slot %td\n", 673 + dprintk("--> %s clp %p session %p sr_slot %d\n", 617 674 __func__, session->clp, session, res->sr_slot ? 618 - res->sr_slot - session->fc_slot_table.slots : -1); 675 + res->sr_slot->slot_nr : -1); 619 676 620 677 ret = nfs41_setup_sequence(session, args, res, task); 621 678 out: ··· 634 687 static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) 635 688 { 636 689 struct nfs41_call_sync_data *data = calldata; 690 + struct nfs4_session *session = nfs4_get_session(data->seq_server); 637 691 638 692 dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); 639 693 640 - if (nfs4_setup_sequence(data->seq_server, data->seq_args, 641 - data->seq_res, task)) 642 - return; 643 - rpc_call_start(task); 644 - } 645 - 646 - static void nfs41_call_priv_sync_prepare(struct rpc_task *task, void *calldata) 647 - { 648 - rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); 649 - nfs41_call_sync_prepare(task, calldata); 694 + nfs41_setup_sequence(session, data->seq_args, data->seq_res, task); 650 695 } 651 696 652 697 static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) ··· 653 714 .rpc_call_done = nfs41_call_sync_done, 654 715 }; 655 716 656 - static const struct rpc_call_ops nfs41_call_priv_sync_ops = { 657 - .rpc_call_prepare = nfs41_call_priv_sync_prepare, 658 - .rpc_call_done = nfs41_call_sync_done, 659 - }; 660 - 661 717 static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, 662 718 struct nfs_server *server, 663 719 struct rpc_message *msg, 664 720 struct nfs4_sequence_args *args, 665 - struct nfs4_sequence_res *res, 666 - int privileged) 721 + struct nfs4_sequence_res *res) 667 722 { 668 723 int ret; 669 724 struct rpc_task *task; ··· 673 740 .callback_data = &data 674 741 }; 675 742 676 - if (privileged) 677 - task_setup.callback_ops = &nfs41_call_priv_sync_ops; 678 743 task = rpc_run_task(&task_setup); 679 744 if (IS_ERR(task)) 680 745 ret = PTR_ERR(task); ··· 683 752 return ret; 684 753 } 685 754 686 - int _nfs4_call_sync_session(struct rpc_clnt *clnt, 687 - struct nfs_server *server, 688 - struct rpc_message *msg, 689 - struct nfs4_sequence_args *args, 690 - struct nfs4_sequence_res *res, 691 - int cache_reply) 692 - { 693 - nfs41_init_sequence(args, res, cache_reply); 694 - return nfs4_call_sync_sequence(clnt, server, msg, args, res, 0); 695 - } 696 - 697 755 #else 698 - static inline 756 + static 699 757 void nfs41_init_sequence(struct nfs4_sequence_args *args, 700 758 struct nfs4_sequence_res *res, int cache_reply) 701 759 { 702 760 } 761 + 762 + static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args) 763 + { 764 + } 765 + 703 766 704 767 static int nfs4_sequence_done(struct rpc_task *task, 705 768 struct nfs4_sequence_res *res) ··· 702 777 } 703 778 #endif /* CONFIG_NFS_V4_1 */ 704 779 780 + static 705 781 int _nfs4_call_sync(struct rpc_clnt *clnt, 706 782 struct nfs_server *server, 707 783 struct rpc_message *msg, 708 784 struct nfs4_sequence_args *args, 709 - struct nfs4_sequence_res *res, 710 - int cache_reply) 785 + struct nfs4_sequence_res *res) 711 786 { 712 - nfs41_init_sequence(args, res, cache_reply); 713 787 return rpc_call_sync(clnt, msg, 0); 714 788 } 715 789 716 - static inline 790 + static 717 791 int nfs4_call_sync(struct rpc_clnt *clnt, 718 792 struct nfs_server *server, 719 793 struct rpc_message *msg, ··· 720 796 struct nfs4_sequence_res *res, 721 797 int cache_reply) 722 798 { 799 + nfs41_init_sequence(args, res, cache_reply); 723 800 return server->nfs_client->cl_mvops->call_sync(clnt, server, msg, 724 - args, res, cache_reply); 801 + args, res); 725 802 } 726 803 727 804 static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) ··· 1370 1445 nfs_inode_find_state_and_recover(state->inode, 1371 1446 stateid); 1372 1447 nfs4_schedule_stateid_recovery(server, state); 1373 - case -EKEYEXPIRED: 1374 - /* 1375 - * User RPCSEC_GSS context has expired. 1376 - * We cannot recover this stateid now, so 1377 - * skip it and allow recovery thread to 1378 - * proceed. 1379 - */ 1380 1448 case -ENOMEM: 1381 1449 err = 0; 1382 1450 goto out; ··· 1492 1574 &data->o_res.seq_res, 1493 1575 task) != 0) 1494 1576 nfs_release_seqid(data->o_arg.seqid); 1495 - else 1496 - rpc_call_start(task); 1497 1577 return; 1498 1578 unlock_no_action: 1499 1579 rcu_read_unlock(); 1500 1580 out_no_action: 1501 1581 task->tk_action = NULL; 1502 - 1503 - } 1504 - 1505 - static void nfs4_recover_open_prepare(struct rpc_task *task, void *calldata) 1506 - { 1507 - rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); 1508 - nfs4_open_prepare(task, calldata); 1582 + nfs4_sequence_done(task, &data->o_res.seq_res); 1509 1583 } 1510 1584 1511 1585 static void nfs4_open_done(struct rpc_task *task, void *calldata) ··· 1558 1648 .rpc_release = nfs4_open_release, 1559 1649 }; 1560 1650 1561 - static const struct rpc_call_ops nfs4_recover_open_ops = { 1562 - .rpc_call_prepare = nfs4_recover_open_prepare, 1563 - .rpc_call_done = nfs4_open_done, 1564 - .rpc_release = nfs4_open_release, 1565 - }; 1566 - 1567 1651 static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) 1568 1652 { 1569 1653 struct inode *dir = data->dir->d_inode; ··· 1587 1683 data->rpc_status = 0; 1588 1684 data->cancelled = 0; 1589 1685 if (isrecover) 1590 - task_setup_data.callback_ops = &nfs4_recover_open_ops; 1686 + nfs4_set_sequence_privileged(&o_arg->seq_args); 1591 1687 task = rpc_run_task(&task_setup_data); 1592 1688 if (IS_ERR(task)) 1593 1689 return PTR_ERR(task); ··· 1691 1787 if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) 1692 1788 _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr); 1693 1789 return 0; 1694 - } 1695 - 1696 - static int nfs4_client_recover_expired_lease(struct nfs_client *clp) 1697 - { 1698 - unsigned int loop; 1699 - int ret; 1700 - 1701 - for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { 1702 - ret = nfs4_wait_clnt_recover(clp); 1703 - if (ret != 0) 1704 - break; 1705 - if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) && 1706 - !test_bit(NFS4CLNT_CHECK_LEASE,&clp->cl_state)) 1707 - break; 1708 - nfs4_schedule_state_manager(clp); 1709 - ret = -EIO; 1710 - } 1711 - return ret; 1712 1790 } 1713 1791 1714 1792 static int nfs4_recover_expired_lease(struct nfs_server *server) ··· 2168 2282 if (!call_close) { 2169 2283 /* Note: exit _without_ calling nfs4_close_done */ 2170 2284 task->tk_action = NULL; 2285 + nfs4_sequence_done(task, &calldata->res.seq_res); 2171 2286 goto out; 2172 2287 } 2173 2288 ··· 2186 2299 &calldata->res.seq_res, 2187 2300 task) != 0) 2188 2301 nfs_release_seqid(calldata->arg.seqid); 2189 - else 2190 - rpc_call_start(task); 2191 2302 out: 2192 2303 dprintk("%s: done!\n", __func__); 2193 2304 } ··· 2418 2533 rpc_authflavor_t flav_array[NFS_MAX_SECFLAVORS]; 2419 2534 2420 2535 len = rpcauth_list_flavors(flav_array, ARRAY_SIZE(flav_array)); 2421 - BUG_ON(len < 0); 2536 + if (len < 0) 2537 + return len; 2422 2538 2423 2539 for (i = 0; i < len; i++) { 2424 2540 /* AUTH_UNIX is the default flavor if none was specified, ··· 2924 3038 2925 3039 static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) 2926 3040 { 2927 - if (nfs4_setup_sequence(NFS_SERVER(data->dir), 2928 - &data->args.seq_args, 2929 - &data->res.seq_res, 2930 - task)) 2931 - return; 2932 - rpc_call_start(task); 3041 + nfs4_setup_sequence(NFS_SERVER(data->dir), 3042 + &data->args.seq_args, 3043 + &data->res.seq_res, 3044 + task); 2933 3045 } 2934 3046 2935 3047 static int nfs4_proc_unlink_done(struct rpc_task *task, struct inode *dir) ··· 2955 3071 2956 3072 static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) 2957 3073 { 2958 - if (nfs4_setup_sequence(NFS_SERVER(data->old_dir), 2959 - &data->args.seq_args, 2960 - &data->res.seq_res, 2961 - task)) 2962 - return; 2963 - rpc_call_start(task); 3074 + nfs4_setup_sequence(NFS_SERVER(data->old_dir), 3075 + &data->args.seq_args, 3076 + &data->res.seq_res, 3077 + task); 2964 3078 } 2965 3079 2966 3080 static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, ··· 3244 3362 int mode = sattr->ia_mode; 3245 3363 int status = -ENOMEM; 3246 3364 3247 - BUG_ON(!(sattr->ia_valid & ATTR_MODE)); 3248 - BUG_ON(!S_ISFIFO(mode) && !S_ISBLK(mode) && !S_ISCHR(mode) && !S_ISSOCK(mode)); 3249 - 3250 3365 data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); 3251 3366 if (data == NULL) 3252 3367 goto out; ··· 3259 3380 data->arg.ftype = NF4CHR; 3260 3381 data->arg.u.device.specdata1 = MAJOR(rdev); 3261 3382 data->arg.u.device.specdata2 = MINOR(rdev); 3383 + } else if (!S_ISSOCK(mode)) { 3384 + status = -EINVAL; 3385 + goto out_free; 3262 3386 } 3263 3387 3264 3388 status = nfs4_do_create(dir, dentry, data); 3265 - 3389 + out_free: 3266 3390 nfs4_free_createdata(data); 3267 3391 out: 3268 3392 return status; ··· 3447 3565 3448 3566 static void nfs4_proc_read_rpc_prepare(struct rpc_task *task, struct nfs_read_data *data) 3449 3567 { 3450 - if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), 3451 - &data->args.seq_args, 3452 - &data->res.seq_res, 3453 - task)) 3454 - return; 3455 - rpc_call_start(task); 3568 + nfs4_setup_sequence(NFS_SERVER(data->header->inode), 3569 + &data->args.seq_args, 3570 + &data->res.seq_res, 3571 + task); 3456 3572 } 3457 3573 3458 3574 static int nfs4_write_done_cb(struct rpc_task *task, struct nfs_write_data *data) ··· 3511 3631 3512 3632 static void nfs4_proc_write_rpc_prepare(struct rpc_task *task, struct nfs_write_data *data) 3513 3633 { 3514 - if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), 3515 - &data->args.seq_args, 3516 - &data->res.seq_res, 3517 - task)) 3518 - return; 3519 - rpc_call_start(task); 3634 + nfs4_setup_sequence(NFS_SERVER(data->header->inode), 3635 + &data->args.seq_args, 3636 + &data->res.seq_res, 3637 + task); 3520 3638 } 3521 3639 3522 3640 static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) 3523 3641 { 3524 - if (nfs4_setup_sequence(NFS_SERVER(data->inode), 3525 - &data->args.seq_args, 3526 - &data->res.seq_res, 3527 - task)) 3528 - return; 3529 - rpc_call_start(task); 3642 + nfs4_setup_sequence(NFS_SERVER(data->inode), 3643 + &data->args.seq_args, 3644 + &data->res.seq_res, 3645 + task); 3530 3646 } 3531 3647 3532 3648 static int nfs4_commit_done_cb(struct rpc_task *task, struct nfs_commit_data *data) ··· 3813 3937 goto out_free; 3814 3938 } 3815 3939 nfs4_write_cached_acl(inode, pages, res.acl_data_offset, res.acl_len); 3816 - if (buf) 3940 + if (buf) { 3941 + if (res.acl_len > buflen) { 3942 + ret = -ERANGE; 3943 + goto out_free; 3944 + } 3817 3945 _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); 3946 + } 3818 3947 out_ok: 3819 3948 ret = res.acl_len; 3820 3949 out_free: ··· 3966 4085 case -NFS4ERR_DELAY: 3967 4086 nfs_inc_server_stats(server, NFSIOS_DELAY); 3968 4087 case -NFS4ERR_GRACE: 3969 - case -EKEYEXPIRED: 3970 4088 rpc_delay(task, NFS4_POLL_RETRY_MAX); 3971 4089 task->tk_status = 0; 3972 4090 return -EAGAIN; ··· 4173 4293 4174 4294 d_data = (struct nfs4_delegreturndata *)data; 4175 4295 4176 - if (nfs4_setup_sequence(d_data->res.server, 4177 - &d_data->args.seq_args, 4178 - &d_data->res.seq_res, task)) 4179 - return; 4180 - rpc_call_start(task); 4296 + nfs4_setup_sequence(d_data->res.server, 4297 + &d_data->args.seq_args, 4298 + &d_data->res.seq_res, 4299 + task); 4181 4300 } 4182 4301 #endif /* CONFIG_NFS_V4_1 */ 4183 4302 ··· 4422 4543 if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { 4423 4544 /* Note: exit _without_ running nfs4_locku_done */ 4424 4545 task->tk_action = NULL; 4546 + nfs4_sequence_done(task, &calldata->res.seq_res); 4425 4547 return; 4426 4548 } 4427 4549 calldata->timestamp = jiffies; ··· 4431 4551 &calldata->res.seq_res, 4432 4552 task) != 0) 4433 4553 nfs_release_seqid(calldata->arg.seqid); 4434 - else 4435 - rpc_call_start(task); 4436 4554 } 4437 4555 4438 4556 static const struct rpc_call_ops nfs4_locku_ops = { ··· 4574 4696 return; 4575 4697 /* Do we need to do an open_to_lock_owner? */ 4576 4698 if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { 4577 - if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) 4699 + if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { 4578 4700 goto out_release_lock_seqid; 4701 + } 4579 4702 data->arg.open_stateid = &state->stateid; 4580 4703 data->arg.new_lock_owner = 1; 4581 4704 data->res.open_seqid = data->arg.open_seqid; ··· 4586 4707 if (nfs4_setup_sequence(data->server, 4587 4708 &data->arg.seq_args, 4588 4709 &data->res.seq_res, 4589 - task) == 0) { 4590 - rpc_call_start(task); 4710 + task) == 0) 4591 4711 return; 4592 - } 4593 4712 nfs_release_seqid(data->arg.open_seqid); 4594 4713 out_release_lock_seqid: 4595 4714 nfs_release_seqid(data->arg.lock_seqid); 4596 - dprintk("%s: done!, ret = %d\n", __func__, task->tk_status); 4597 - } 4598 - 4599 - static void nfs4_recover_lock_prepare(struct rpc_task *task, void *calldata) 4600 - { 4601 - rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); 4602 - nfs4_lock_prepare(task, calldata); 4715 + dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); 4603 4716 } 4604 4717 4605 4718 static void nfs4_lock_done(struct rpc_task *task, void *calldata) ··· 4646 4775 .rpc_release = nfs4_lock_release, 4647 4776 }; 4648 4777 4649 - static const struct rpc_call_ops nfs4_recover_lock_ops = { 4650 - .rpc_call_prepare = nfs4_recover_lock_prepare, 4651 - .rpc_call_done = nfs4_lock_done, 4652 - .rpc_release = nfs4_lock_release, 4653 - }; 4654 - 4655 4778 static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) 4656 4779 { 4657 4780 switch (error) { ··· 4688 4823 return -ENOMEM; 4689 4824 if (IS_SETLKW(cmd)) 4690 4825 data->arg.block = 1; 4691 - if (recovery_type > NFS_LOCK_NEW) { 4692 - if (recovery_type == NFS_LOCK_RECLAIM) 4693 - data->arg.reclaim = NFS_LOCK_RECLAIM; 4694 - task_setup_data.callback_ops = &nfs4_recover_lock_ops; 4695 - } 4696 4826 nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); 4697 4827 msg.rpc_argp = &data->arg; 4698 4828 msg.rpc_resp = &data->res; 4699 4829 task_setup_data.callback_data = data; 4830 + if (recovery_type > NFS_LOCK_NEW) { 4831 + if (recovery_type == NFS_LOCK_RECLAIM) 4832 + data->arg.reclaim = NFS_LOCK_RECLAIM; 4833 + nfs4_set_sequence_privileged(&data->arg.seq_args); 4834 + } 4700 4835 task = rpc_run_task(&task_setup_data); 4701 4836 if (IS_ERR(task)) 4702 4837 return PTR_ERR(task); ··· 4965 5100 nfs4_schedule_stateid_recovery(server, state); 4966 5101 err = 0; 4967 5102 goto out; 4968 - case -EKEYEXPIRED: 4969 - /* 4970 - * User RPCSEC_GSS context has expired. 4971 - * We cannot recover this stateid now, so 4972 - * skip it and allow recovery thread to 4973 - * proceed. 4974 - */ 4975 - err = 0; 4976 - goto out; 4977 5103 case -ENOMEM: 4978 5104 case -NFS4ERR_DENIED: 4979 5105 /* kill_proc(fl->fl_pid, SIGLOST, 1); */ ··· 5213 5357 }; 5214 5358 5215 5359 dprintk("--> %s\n", __func__); 5216 - BUG_ON(clp == NULL); 5217 5360 5218 5361 res.session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); 5219 5362 if (unlikely(res.session == NULL)) { ··· 5424 5569 static void nfs4_get_lease_time_prepare(struct rpc_task *task, 5425 5570 void *calldata) 5426 5571 { 5427 - int ret; 5428 5572 struct nfs4_get_lease_time_data *data = 5429 5573 (struct nfs4_get_lease_time_data *)calldata; 5430 5574 5431 5575 dprintk("--> %s\n", __func__); 5432 - rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); 5433 5576 /* just setup sequence, do not trigger session recovery 5434 5577 since we're invoked within one */ 5435 - ret = nfs41_setup_sequence(data->clp->cl_session, 5436 - &data->args->la_seq_args, 5437 - &data->res->lr_seq_res, task); 5438 - 5439 - BUG_ON(ret == -EAGAIN); 5440 - rpc_call_start(task); 5578 + nfs41_setup_sequence(data->clp->cl_session, 5579 + &data->args->la_seq_args, 5580 + &data->res->lr_seq_res, 5581 + task); 5441 5582 dprintk("<-- %s\n", __func__); 5442 5583 } 5443 5584 ··· 5495 5644 int status; 5496 5645 5497 5646 nfs41_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); 5647 + nfs4_set_sequence_privileged(&args.la_seq_args); 5498 5648 dprintk("--> %s\n", __func__); 5499 5649 task = rpc_run_task(&task_setup); 5500 5650 ··· 5510 5658 return status; 5511 5659 } 5512 5660 5513 - static struct nfs4_slot *nfs4_alloc_slots(u32 max_slots, gfp_t gfp_flags) 5514 - { 5515 - return kcalloc(max_slots, sizeof(struct nfs4_slot), gfp_flags); 5516 - } 5517 - 5518 - static void nfs4_add_and_init_slots(struct nfs4_slot_table *tbl, 5519 - struct nfs4_slot *new, 5520 - u32 max_slots, 5521 - u32 ivalue) 5522 - { 5523 - struct nfs4_slot *old = NULL; 5524 - u32 i; 5525 - 5526 - spin_lock(&tbl->slot_tbl_lock); 5527 - if (new) { 5528 - old = tbl->slots; 5529 - tbl->slots = new; 5530 - tbl->max_slots = max_slots; 5531 - } 5532 - tbl->highest_used_slotid = NFS4_NO_SLOT; 5533 - for (i = 0; i < tbl->max_slots; i++) 5534 - tbl->slots[i].seq_nr = ivalue; 5535 - spin_unlock(&tbl->slot_tbl_lock); 5536 - kfree(old); 5537 - } 5538 - 5539 - /* 5540 - * (re)Initialise a slot table 5541 - */ 5542 - static int nfs4_realloc_slot_table(struct nfs4_slot_table *tbl, u32 max_reqs, 5543 - u32 ivalue) 5544 - { 5545 - struct nfs4_slot *new = NULL; 5546 - int ret = -ENOMEM; 5547 - 5548 - dprintk("--> %s: max_reqs=%u, tbl->max_slots %d\n", __func__, 5549 - max_reqs, tbl->max_slots); 5550 - 5551 - /* Does the newly negotiated max_reqs match the existing slot table? */ 5552 - if (max_reqs != tbl->max_slots) { 5553 - new = nfs4_alloc_slots(max_reqs, GFP_NOFS); 5554 - if (!new) 5555 - goto out; 5556 - } 5557 - ret = 0; 5558 - 5559 - nfs4_add_and_init_slots(tbl, new, max_reqs, ivalue); 5560 - dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, 5561 - tbl, tbl->slots, tbl->max_slots); 5562 - out: 5563 - dprintk("<-- %s: return %d\n", __func__, ret); 5564 - return ret; 5565 - } 5566 - 5567 - /* Destroy the slot table */ 5568 - static void nfs4_destroy_slot_tables(struct nfs4_session *session) 5569 - { 5570 - if (session->fc_slot_table.slots != NULL) { 5571 - kfree(session->fc_slot_table.slots); 5572 - session->fc_slot_table.slots = NULL; 5573 - } 5574 - if (session->bc_slot_table.slots != NULL) { 5575 - kfree(session->bc_slot_table.slots); 5576 - session->bc_slot_table.slots = NULL; 5577 - } 5578 - return; 5579 - } 5580 - 5581 - /* 5582 - * Initialize or reset the forechannel and backchannel tables 5583 - */ 5584 - static int nfs4_setup_session_slot_tables(struct nfs4_session *ses) 5585 - { 5586 - struct nfs4_slot_table *tbl; 5587 - int status; 5588 - 5589 - dprintk("--> %s\n", __func__); 5590 - /* Fore channel */ 5591 - tbl = &ses->fc_slot_table; 5592 - status = nfs4_realloc_slot_table(tbl, ses->fc_attrs.max_reqs, 1); 5593 - if (status) /* -ENOMEM */ 5594 - return status; 5595 - /* Back channel */ 5596 - tbl = &ses->bc_slot_table; 5597 - status = nfs4_realloc_slot_table(tbl, ses->bc_attrs.max_reqs, 0); 5598 - if (status && tbl->slots == NULL) 5599 - /* Fore and back channel share a connection so get 5600 - * both slot tables or neither */ 5601 - nfs4_destroy_slot_tables(ses); 5602 - return status; 5603 - } 5604 - 5605 - struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp) 5606 - { 5607 - struct nfs4_session *session; 5608 - struct nfs4_slot_table *tbl; 5609 - 5610 - session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); 5611 - if (!session) 5612 - return NULL; 5613 - 5614 - tbl = &session->fc_slot_table; 5615 - tbl->highest_used_slotid = NFS4_NO_SLOT; 5616 - spin_lock_init(&tbl->slot_tbl_lock); 5617 - rpc_init_priority_wait_queue(&tbl->slot_tbl_waitq, "ForeChannel Slot table"); 5618 - init_completion(&tbl->complete); 5619 - 5620 - tbl = &session->bc_slot_table; 5621 - tbl->highest_used_slotid = NFS4_NO_SLOT; 5622 - spin_lock_init(&tbl->slot_tbl_lock); 5623 - rpc_init_wait_queue(&tbl->slot_tbl_waitq, "BackChannel Slot table"); 5624 - init_completion(&tbl->complete); 5625 - 5626 - session->session_state = 1<<NFS4_SESSION_INITING; 5627 - 5628 - session->clp = clp; 5629 - return session; 5630 - } 5631 - 5632 - void nfs4_destroy_session(struct nfs4_session *session) 5633 - { 5634 - struct rpc_xprt *xprt; 5635 - struct rpc_cred *cred; 5636 - 5637 - cred = nfs4_get_exchange_id_cred(session->clp); 5638 - nfs4_proc_destroy_session(session, cred); 5639 - if (cred) 5640 - put_rpccred(cred); 5641 - 5642 - rcu_read_lock(); 5643 - xprt = rcu_dereference(session->clp->cl_rpcclient->cl_xprt); 5644 - rcu_read_unlock(); 5645 - dprintk("%s Destroy backchannel for xprt %p\n", 5646 - __func__, xprt); 5647 - xprt_destroy_backchannel(xprt, NFS41_BC_MIN_CALLBACKS); 5648 - nfs4_destroy_slot_tables(session); 5649 - kfree(session); 5650 - } 5651 - 5652 5661 /* 5653 5662 * Initialize the values to be used by the client in CREATE_SESSION 5654 5663 * If nfs4_init_session set the fore channel request and response sizes, ··· 5522 5809 static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) 5523 5810 { 5524 5811 struct nfs4_session *session = args->client->cl_session; 5525 - unsigned int mxrqst_sz = session->fc_attrs.max_rqst_sz, 5526 - mxresp_sz = session->fc_attrs.max_resp_sz; 5812 + unsigned int mxrqst_sz = session->fc_target_max_rqst_sz, 5813 + mxresp_sz = session->fc_target_max_resp_sz; 5527 5814 5528 5815 if (mxrqst_sz == 0) 5529 5816 mxrqst_sz = NFS_MAX_FILE_IO_SIZE; ··· 5632 5919 5633 5920 status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); 5634 5921 5635 - if (!status) 5922 + if (!status) { 5636 5923 /* Verify the session's negotiated channel_attrs values */ 5637 5924 status = nfs4_verify_channel_attrs(&args, session); 5638 - if (!status) { 5639 5925 /* Increment the clientid slot sequence id */ 5640 5926 clp->cl_seqid++; 5641 5927 } ··· 5704 5992 } 5705 5993 5706 5994 /* 5707 - * With sessions, the client is not marked ready until after a 5708 - * successful EXCHANGE_ID and CREATE_SESSION. 5709 - * 5710 - * Map errors cl_cons_state errors to EPROTONOSUPPORT to indicate 5711 - * other versions of NFS can be tried. 5712 - */ 5713 - static int nfs41_check_session_ready(struct nfs_client *clp) 5714 - { 5715 - int ret; 5716 - 5717 - if (clp->cl_cons_state == NFS_CS_SESSION_INITING) { 5718 - ret = nfs4_client_recover_expired_lease(clp); 5719 - if (ret) 5720 - return ret; 5721 - } 5722 - if (clp->cl_cons_state < NFS_CS_READY) 5723 - return -EPROTONOSUPPORT; 5724 - smp_rmb(); 5725 - return 0; 5726 - } 5727 - 5728 - int nfs4_init_session(struct nfs_server *server) 5729 - { 5730 - struct nfs_client *clp = server->nfs_client; 5731 - struct nfs4_session *session; 5732 - unsigned int rsize, wsize; 5733 - 5734 - if (!nfs4_has_session(clp)) 5735 - return 0; 5736 - 5737 - session = clp->cl_session; 5738 - spin_lock(&clp->cl_lock); 5739 - if (test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) { 5740 - 5741 - rsize = server->rsize; 5742 - if (rsize == 0) 5743 - rsize = NFS_MAX_FILE_IO_SIZE; 5744 - wsize = server->wsize; 5745 - if (wsize == 0) 5746 - wsize = NFS_MAX_FILE_IO_SIZE; 5747 - 5748 - session->fc_attrs.max_rqst_sz = wsize + nfs41_maxwrite_overhead; 5749 - session->fc_attrs.max_resp_sz = rsize + nfs41_maxread_overhead; 5750 - } 5751 - spin_unlock(&clp->cl_lock); 5752 - 5753 - return nfs41_check_session_ready(clp); 5754 - } 5755 - 5756 - int nfs4_init_ds_session(struct nfs_client *clp, unsigned long lease_time) 5757 - { 5758 - struct nfs4_session *session = clp->cl_session; 5759 - int ret; 5760 - 5761 - spin_lock(&clp->cl_lock); 5762 - if (test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) { 5763 - /* 5764 - * Do not set NFS_CS_CHECK_LEASE_TIME instead set the 5765 - * DS lease to be equal to the MDS lease. 5766 - */ 5767 - clp->cl_lease_time = lease_time; 5768 - clp->cl_last_renewal = jiffies; 5769 - } 5770 - spin_unlock(&clp->cl_lock); 5771 - 5772 - ret = nfs41_check_session_ready(clp); 5773 - if (ret) 5774 - return ret; 5775 - /* Test for the DS role */ 5776 - if (!is_ds_client(clp)) 5777 - return -ENODEV; 5778 - return 0; 5779 - } 5780 - EXPORT_SYMBOL_GPL(nfs4_init_ds_session); 5781 - 5782 - 5783 - /* 5784 5995 * Renew the cl_session lease. 5785 5996 */ 5786 5997 struct nfs4_sequence_data { ··· 5768 6133 args = task->tk_msg.rpc_argp; 5769 6134 res = task->tk_msg.rpc_resp; 5770 6135 5771 - if (nfs41_setup_sequence(clp->cl_session, args, res, task)) 5772 - return; 5773 - rpc_call_start(task); 6136 + nfs41_setup_sequence(clp->cl_session, args, res, task); 5774 6137 } 5775 6138 5776 6139 static const struct rpc_call_ops nfs41_sequence_ops = { ··· 5777 6144 .rpc_release = nfs41_sequence_release, 5778 6145 }; 5779 6146 5780 - static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) 6147 + static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, 6148 + struct rpc_cred *cred, 6149 + bool is_privileged) 5781 6150 { 5782 6151 struct nfs4_sequence_data *calldata; 5783 6152 struct rpc_message msg = { ··· 5801 6166 return ERR_PTR(-ENOMEM); 5802 6167 } 5803 6168 nfs41_init_sequence(&calldata->args, &calldata->res, 0); 6169 + if (is_privileged) 6170 + nfs4_set_sequence_privileged(&calldata->args); 5804 6171 msg.rpc_argp = &calldata->args; 5805 6172 msg.rpc_resp = &calldata->res; 5806 6173 calldata->clp = clp; ··· 5818 6181 5819 6182 if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) 5820 6183 return 0; 5821 - task = _nfs41_proc_sequence(clp, cred); 6184 + task = _nfs41_proc_sequence(clp, cred, false); 5822 6185 if (IS_ERR(task)) 5823 6186 ret = PTR_ERR(task); 5824 6187 else ··· 5832 6195 struct rpc_task *task; 5833 6196 int ret; 5834 6197 5835 - task = _nfs41_proc_sequence(clp, cred); 6198 + task = _nfs41_proc_sequence(clp, cred, true); 5836 6199 if (IS_ERR(task)) { 5837 6200 ret = PTR_ERR(task); 5838 6201 goto out; ··· 5861 6224 { 5862 6225 struct nfs4_reclaim_complete_data *calldata = data; 5863 6226 5864 - rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); 5865 - if (nfs41_setup_sequence(calldata->clp->cl_session, 5866 - &calldata->arg.seq_args, 5867 - &calldata->res.seq_res, task)) 5868 - return; 5869 - 5870 - rpc_call_start(task); 6227 + nfs41_setup_sequence(calldata->clp->cl_session, 6228 + &calldata->arg.seq_args, 6229 + &calldata->res.seq_res, 6230 + task); 5871 6231 } 5872 6232 5873 6233 static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) ··· 5941 6307 calldata->arg.one_fs = 0; 5942 6308 5943 6309 nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); 6310 + nfs4_set_sequence_privileged(&calldata->arg.seq_args); 5944 6311 msg.rpc_argp = &calldata->arg; 5945 6312 msg.rpc_resp = &calldata->res; 5946 6313 task_setup_data.callback_data = calldata; ··· 5965 6330 { 5966 6331 struct nfs4_layoutget *lgp = calldata; 5967 6332 struct nfs_server *server = NFS_SERVER(lgp->args.inode); 6333 + struct nfs4_session *session = nfs4_get_session(server); 5968 6334 5969 6335 dprintk("--> %s\n", __func__); 5970 6336 /* Note the is a race here, where a CB_LAYOUTRECALL can come in ··· 5973 6337 * However, that is not so catastrophic, and there seems 5974 6338 * to be no way to prevent it completely. 5975 6339 */ 5976 - if (nfs4_setup_sequence(server, &lgp->args.seq_args, 6340 + if (nfs41_setup_sequence(session, &lgp->args.seq_args, 5977 6341 &lgp->res.seq_res, task)) 5978 6342 return; 5979 6343 if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, 5980 6344 NFS_I(lgp->args.inode)->layout, 5981 6345 lgp->args.ctx->state)) { 5982 6346 rpc_exit(task, NFS4_OK); 5983 - return; 5984 6347 } 5985 - rpc_call_start(task); 5986 6348 } 5987 6349 5988 6350 static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) ··· 5993 6359 5994 6360 dprintk("--> %s\n", __func__); 5995 6361 5996 - if (!nfs4_sequence_done(task, &lgp->res.seq_res)) 6362 + if (!nfs41_sequence_done(task, &lgp->res.seq_res)) 5997 6363 goto out; 5998 6364 5999 6365 switch (task->tk_status) { ··· 6144 6510 struct nfs4_layoutreturn *lrp = calldata; 6145 6511 6146 6512 dprintk("--> %s\n", __func__); 6147 - if (nfs41_setup_sequence(lrp->clp->cl_session, &lrp->args.seq_args, 6148 - &lrp->res.seq_res, task)) 6149 - return; 6150 - rpc_call_start(task); 6513 + nfs41_setup_sequence(lrp->clp->cl_session, 6514 + &lrp->args.seq_args, 6515 + &lrp->res.seq_res, 6516 + task); 6151 6517 } 6152 6518 6153 6519 static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) ··· 6157 6523 6158 6524 dprintk("--> %s\n", __func__); 6159 6525 6160 - if (!nfs4_sequence_done(task, &lrp->res.seq_res)) 6526 + if (!nfs41_sequence_done(task, &lrp->res.seq_res)) 6161 6527 return; 6162 6528 6163 6529 server = NFS_SERVER(lrp->args.inode); ··· 6306 6672 { 6307 6673 struct nfs4_layoutcommit_data *data = calldata; 6308 6674 struct nfs_server *server = NFS_SERVER(data->args.inode); 6675 + struct nfs4_session *session = nfs4_get_session(server); 6309 6676 6310 - if (nfs4_setup_sequence(server, &data->args.seq_args, 6311 - &data->res.seq_res, task)) 6312 - return; 6313 - rpc_call_start(task); 6677 + nfs41_setup_sequence(session, 6678 + &data->args.seq_args, 6679 + &data->res.seq_res, 6680 + task); 6314 6681 } 6315 6682 6316 6683 static void ··· 6320 6685 struct nfs4_layoutcommit_data *data = calldata; 6321 6686 struct nfs_server *server = NFS_SERVER(data->args.inode); 6322 6687 6323 - if (!nfs4_sequence_done(task, &data->res.seq_res)) 6688 + if (!nfs41_sequence_done(task, &data->res.seq_res)) 6324 6689 return; 6325 6690 6326 6691 switch (task->tk_status) { /* Just ignore these failures */ ··· 6508 6873 6509 6874 dprintk("NFS call test_stateid %p\n", stateid); 6510 6875 nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); 6511 - status = nfs4_call_sync_sequence(server->client, server, &msg, &args.seq_args, &res.seq_res, 1); 6876 + nfs4_set_sequence_privileged(&args.seq_args); 6877 + status = nfs4_call_sync_sequence(server->client, server, &msg, 6878 + &args.seq_args, &res.seq_res); 6512 6879 if (status != NFS_OK) { 6513 6880 dprintk("NFS reply test_stateid: failed, %d\n", status); 6514 6881 return status; ··· 6557 6920 6558 6921 dprintk("NFS call free_stateid %p\n", stateid); 6559 6922 nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); 6923 + nfs4_set_sequence_privileged(&args.seq_args); 6560 6924 status = nfs4_call_sync_sequence(server->client, server, &msg, 6561 - &args.seq_args, &res.seq_res, 1); 6925 + &args.seq_args, &res.seq_res); 6562 6926 dprintk("NFS reply free_stateid: %d\n", status); 6563 6927 return status; 6564 6928 } ··· 6679 7041 #if defined(CONFIG_NFS_V4_1) 6680 7042 static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { 6681 7043 .minor_version = 1, 6682 - .call_sync = _nfs4_call_sync_session, 7044 + .call_sync = nfs4_call_sync_sequence, 6683 7045 .match_stateid = nfs41_match_stateid, 6684 7046 .find_root_sec = nfs41_find_root_sec, 6685 7047 .reboot_recovery_ops = &nfs41_reboot_recovery_ops,
+552
fs/nfs/nfs4session.c
··· 1 + /* 2 + * fs/nfs/nfs4session.c 3 + * 4 + * Copyright (c) 2012 Trond Myklebust <Trond.Myklebust@netapp.com> 5 + * 6 + */ 7 + #include <linux/kernel.h> 8 + #include <linux/errno.h> 9 + #include <linux/string.h> 10 + #include <linux/printk.h> 11 + #include <linux/slab.h> 12 + #include <linux/sunrpc/sched.h> 13 + #include <linux/sunrpc/bc_xprt.h> 14 + #include <linux/nfs.h> 15 + #include <linux/nfs4.h> 16 + #include <linux/nfs_fs.h> 17 + #include <linux/module.h> 18 + 19 + #include "nfs4_fs.h" 20 + #include "internal.h" 21 + #include "nfs4session.h" 22 + #include "callback.h" 23 + 24 + #define NFSDBG_FACILITY NFSDBG_STATE 25 + 26 + /* 27 + * nfs4_shrink_slot_table - free retired slots from the slot table 28 + */ 29 + static void nfs4_shrink_slot_table(struct nfs4_slot_table *tbl, u32 newsize) 30 + { 31 + struct nfs4_slot **p; 32 + if (newsize >= tbl->max_slots) 33 + return; 34 + 35 + p = &tbl->slots; 36 + while (newsize--) 37 + p = &(*p)->next; 38 + while (*p) { 39 + struct nfs4_slot *slot = *p; 40 + 41 + *p = slot->next; 42 + kfree(slot); 43 + tbl->max_slots--; 44 + } 45 + } 46 + 47 + /* 48 + * nfs4_free_slot - free a slot and efficiently update slot table. 49 + * 50 + * freeing a slot is trivially done by clearing its respective bit 51 + * in the bitmap. 52 + * If the freed slotid equals highest_used_slotid we want to update it 53 + * so that the server would be able to size down the slot table if needed, 54 + * otherwise we know that the highest_used_slotid is still in use. 55 + * When updating highest_used_slotid there may be "holes" in the bitmap 56 + * so we need to scan down from highest_used_slotid to 0 looking for the now 57 + * highest slotid in use. 58 + * If none found, highest_used_slotid is set to NFS4_NO_SLOT. 59 + * 60 + * Must be called while holding tbl->slot_tbl_lock 61 + */ 62 + void nfs4_free_slot(struct nfs4_slot_table *tbl, struct nfs4_slot *slot) 63 + { 64 + u32 slotid = slot->slot_nr; 65 + 66 + /* clear used bit in bitmap */ 67 + __clear_bit(slotid, tbl->used_slots); 68 + 69 + /* update highest_used_slotid when it is freed */ 70 + if (slotid == tbl->highest_used_slotid) { 71 + u32 new_max = find_last_bit(tbl->used_slots, slotid); 72 + if (new_max < slotid) 73 + tbl->highest_used_slotid = new_max; 74 + else { 75 + tbl->highest_used_slotid = NFS4_NO_SLOT; 76 + nfs4_session_drain_complete(tbl->session, tbl); 77 + } 78 + } 79 + dprintk("%s: slotid %u highest_used_slotid %d\n", __func__, 80 + slotid, tbl->highest_used_slotid); 81 + } 82 + 83 + static struct nfs4_slot *nfs4_new_slot(struct nfs4_slot_table *tbl, 84 + u32 slotid, u32 seq_init, gfp_t gfp_mask) 85 + { 86 + struct nfs4_slot *slot; 87 + 88 + slot = kzalloc(sizeof(*slot), gfp_mask); 89 + if (slot) { 90 + slot->table = tbl; 91 + slot->slot_nr = slotid; 92 + slot->seq_nr = seq_init; 93 + } 94 + return slot; 95 + } 96 + 97 + static struct nfs4_slot *nfs4_find_or_create_slot(struct nfs4_slot_table *tbl, 98 + u32 slotid, u32 seq_init, gfp_t gfp_mask) 99 + { 100 + struct nfs4_slot **p, *slot; 101 + 102 + p = &tbl->slots; 103 + for (;;) { 104 + if (*p == NULL) { 105 + *p = nfs4_new_slot(tbl, tbl->max_slots, 106 + seq_init, gfp_mask); 107 + if (*p == NULL) 108 + break; 109 + tbl->max_slots++; 110 + } 111 + slot = *p; 112 + if (slot->slot_nr == slotid) 113 + return slot; 114 + p = &slot->next; 115 + } 116 + return ERR_PTR(-ENOMEM); 117 + } 118 + 119 + /* 120 + * nfs4_alloc_slot - efficiently look for a free slot 121 + * 122 + * nfs4_alloc_slot looks for an unset bit in the used_slots bitmap. 123 + * If found, we mark the slot as used, update the highest_used_slotid, 124 + * and respectively set up the sequence operation args. 125 + * 126 + * Note: must be called with under the slot_tbl_lock. 127 + */ 128 + struct nfs4_slot *nfs4_alloc_slot(struct nfs4_slot_table *tbl) 129 + { 130 + struct nfs4_slot *ret = ERR_PTR(-EBUSY); 131 + u32 slotid; 132 + 133 + dprintk("--> %s used_slots=%04lx highest_used=%u max_slots=%u\n", 134 + __func__, tbl->used_slots[0], tbl->highest_used_slotid, 135 + tbl->max_slotid + 1); 136 + slotid = find_first_zero_bit(tbl->used_slots, tbl->max_slotid + 1); 137 + if (slotid > tbl->max_slotid) 138 + goto out; 139 + ret = nfs4_find_or_create_slot(tbl, slotid, 1, GFP_NOWAIT); 140 + if (IS_ERR(ret)) 141 + goto out; 142 + __set_bit(slotid, tbl->used_slots); 143 + if (slotid > tbl->highest_used_slotid || 144 + tbl->highest_used_slotid == NFS4_NO_SLOT) 145 + tbl->highest_used_slotid = slotid; 146 + ret->generation = tbl->generation; 147 + 148 + out: 149 + dprintk("<-- %s used_slots=%04lx highest_used=%d slotid=%d \n", 150 + __func__, tbl->used_slots[0], tbl->highest_used_slotid, 151 + !IS_ERR(ret) ? ret->slot_nr : -1); 152 + return ret; 153 + } 154 + 155 + static int nfs4_grow_slot_table(struct nfs4_slot_table *tbl, 156 + u32 max_reqs, u32 ivalue) 157 + { 158 + if (max_reqs <= tbl->max_slots) 159 + return 0; 160 + if (!IS_ERR(nfs4_find_or_create_slot(tbl, max_reqs - 1, ivalue, GFP_NOFS))) 161 + return 0; 162 + return -ENOMEM; 163 + } 164 + 165 + static void nfs4_reset_slot_table(struct nfs4_slot_table *tbl, 166 + u32 server_highest_slotid, 167 + u32 ivalue) 168 + { 169 + struct nfs4_slot **p; 170 + 171 + nfs4_shrink_slot_table(tbl, server_highest_slotid + 1); 172 + p = &tbl->slots; 173 + while (*p) { 174 + (*p)->seq_nr = ivalue; 175 + (*p)->interrupted = 0; 176 + p = &(*p)->next; 177 + } 178 + tbl->highest_used_slotid = NFS4_NO_SLOT; 179 + tbl->target_highest_slotid = server_highest_slotid; 180 + tbl->server_highest_slotid = server_highest_slotid; 181 + tbl->d_target_highest_slotid = 0; 182 + tbl->d2_target_highest_slotid = 0; 183 + tbl->max_slotid = server_highest_slotid; 184 + } 185 + 186 + /* 187 + * (re)Initialise a slot table 188 + */ 189 + static int nfs4_realloc_slot_table(struct nfs4_slot_table *tbl, 190 + u32 max_reqs, u32 ivalue) 191 + { 192 + int ret; 193 + 194 + dprintk("--> %s: max_reqs=%u, tbl->max_slots %d\n", __func__, 195 + max_reqs, tbl->max_slots); 196 + 197 + if (max_reqs > NFS4_MAX_SLOT_TABLE) 198 + max_reqs = NFS4_MAX_SLOT_TABLE; 199 + 200 + ret = nfs4_grow_slot_table(tbl, max_reqs, ivalue); 201 + if (ret) 202 + goto out; 203 + 204 + spin_lock(&tbl->slot_tbl_lock); 205 + nfs4_reset_slot_table(tbl, max_reqs - 1, ivalue); 206 + spin_unlock(&tbl->slot_tbl_lock); 207 + 208 + dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, 209 + tbl, tbl->slots, tbl->max_slots); 210 + out: 211 + dprintk("<-- %s: return %d\n", __func__, ret); 212 + return ret; 213 + } 214 + 215 + /* Destroy the slot table */ 216 + static void nfs4_destroy_slot_tables(struct nfs4_session *session) 217 + { 218 + nfs4_shrink_slot_table(&session->fc_slot_table, 0); 219 + nfs4_shrink_slot_table(&session->bc_slot_table, 0); 220 + } 221 + 222 + static bool nfs41_assign_slot(struct rpc_task *task, void *pslot) 223 + { 224 + struct nfs4_sequence_args *args = task->tk_msg.rpc_argp; 225 + struct nfs4_sequence_res *res = task->tk_msg.rpc_resp; 226 + struct nfs4_slot *slot = pslot; 227 + struct nfs4_slot_table *tbl = slot->table; 228 + 229 + if (nfs4_session_draining(tbl->session) && !args->sa_privileged) 230 + return false; 231 + slot->generation = tbl->generation; 232 + args->sa_slot = slot; 233 + res->sr_timestamp = jiffies; 234 + res->sr_slot = slot; 235 + res->sr_status_flags = 0; 236 + res->sr_status = 1; 237 + return true; 238 + } 239 + 240 + static bool __nfs41_wake_and_assign_slot(struct nfs4_slot_table *tbl, 241 + struct nfs4_slot *slot) 242 + { 243 + if (rpc_wake_up_first(&tbl->slot_tbl_waitq, nfs41_assign_slot, slot)) 244 + return true; 245 + return false; 246 + } 247 + 248 + bool nfs41_wake_and_assign_slot(struct nfs4_slot_table *tbl, 249 + struct nfs4_slot *slot) 250 + { 251 + if (slot->slot_nr > tbl->max_slotid) 252 + return false; 253 + return __nfs41_wake_and_assign_slot(tbl, slot); 254 + } 255 + 256 + static bool nfs41_try_wake_next_slot_table_entry(struct nfs4_slot_table *tbl) 257 + { 258 + struct nfs4_slot *slot = nfs4_alloc_slot(tbl); 259 + if (!IS_ERR(slot)) { 260 + bool ret = __nfs41_wake_and_assign_slot(tbl, slot); 261 + if (ret) 262 + return ret; 263 + nfs4_free_slot(tbl, slot); 264 + } 265 + return false; 266 + } 267 + 268 + void nfs41_wake_slot_table(struct nfs4_slot_table *tbl) 269 + { 270 + for (;;) { 271 + if (!nfs41_try_wake_next_slot_table_entry(tbl)) 272 + break; 273 + } 274 + } 275 + 276 + static void nfs41_set_max_slotid_locked(struct nfs4_slot_table *tbl, 277 + u32 target_highest_slotid) 278 + { 279 + u32 max_slotid; 280 + 281 + max_slotid = min(NFS4_MAX_SLOT_TABLE - 1, target_highest_slotid); 282 + if (max_slotid > tbl->server_highest_slotid) 283 + max_slotid = tbl->server_highest_slotid; 284 + if (max_slotid > tbl->target_highest_slotid) 285 + max_slotid = tbl->target_highest_slotid; 286 + tbl->max_slotid = max_slotid; 287 + nfs41_wake_slot_table(tbl); 288 + } 289 + 290 + /* Update the client's idea of target_highest_slotid */ 291 + static void nfs41_set_target_slotid_locked(struct nfs4_slot_table *tbl, 292 + u32 target_highest_slotid) 293 + { 294 + if (tbl->target_highest_slotid == target_highest_slotid) 295 + return; 296 + tbl->target_highest_slotid = target_highest_slotid; 297 + tbl->generation++; 298 + } 299 + 300 + void nfs41_set_target_slotid(struct nfs4_slot_table *tbl, 301 + u32 target_highest_slotid) 302 + { 303 + spin_lock(&tbl->slot_tbl_lock); 304 + nfs41_set_target_slotid_locked(tbl, target_highest_slotid); 305 + tbl->d_target_highest_slotid = 0; 306 + tbl->d2_target_highest_slotid = 0; 307 + nfs41_set_max_slotid_locked(tbl, target_highest_slotid); 308 + spin_unlock(&tbl->slot_tbl_lock); 309 + } 310 + 311 + static void nfs41_set_server_slotid_locked(struct nfs4_slot_table *tbl, 312 + u32 highest_slotid) 313 + { 314 + if (tbl->server_highest_slotid == highest_slotid) 315 + return; 316 + if (tbl->highest_used_slotid > highest_slotid) 317 + return; 318 + /* Deallocate slots */ 319 + nfs4_shrink_slot_table(tbl, highest_slotid + 1); 320 + tbl->server_highest_slotid = highest_slotid; 321 + } 322 + 323 + static s32 nfs41_derivative_target_slotid(s32 s1, s32 s2) 324 + { 325 + s1 -= s2; 326 + if (s1 == 0) 327 + return 0; 328 + if (s1 < 0) 329 + return (s1 - 1) >> 1; 330 + return (s1 + 1) >> 1; 331 + } 332 + 333 + static int nfs41_sign_s32(s32 s1) 334 + { 335 + if (s1 > 0) 336 + return 1; 337 + if (s1 < 0) 338 + return -1; 339 + return 0; 340 + } 341 + 342 + static bool nfs41_same_sign_or_zero_s32(s32 s1, s32 s2) 343 + { 344 + if (!s1 || !s2) 345 + return true; 346 + return nfs41_sign_s32(s1) == nfs41_sign_s32(s2); 347 + } 348 + 349 + /* Try to eliminate outliers by checking for sharp changes in the 350 + * derivatives and second derivatives 351 + */ 352 + static bool nfs41_is_outlier_target_slotid(struct nfs4_slot_table *tbl, 353 + u32 new_target) 354 + { 355 + s32 d_target, d2_target; 356 + bool ret = true; 357 + 358 + d_target = nfs41_derivative_target_slotid(new_target, 359 + tbl->target_highest_slotid); 360 + d2_target = nfs41_derivative_target_slotid(d_target, 361 + tbl->d_target_highest_slotid); 362 + /* Is first derivative same sign? */ 363 + if (nfs41_same_sign_or_zero_s32(d_target, tbl->d_target_highest_slotid)) 364 + ret = false; 365 + /* Is second derivative same sign? */ 366 + if (nfs41_same_sign_or_zero_s32(d2_target, tbl->d2_target_highest_slotid)) 367 + ret = false; 368 + tbl->d_target_highest_slotid = d_target; 369 + tbl->d2_target_highest_slotid = d2_target; 370 + return ret; 371 + } 372 + 373 + void nfs41_update_target_slotid(struct nfs4_slot_table *tbl, 374 + struct nfs4_slot *slot, 375 + struct nfs4_sequence_res *res) 376 + { 377 + spin_lock(&tbl->slot_tbl_lock); 378 + if (!nfs41_is_outlier_target_slotid(tbl, res->sr_target_highest_slotid)) 379 + nfs41_set_target_slotid_locked(tbl, res->sr_target_highest_slotid); 380 + if (tbl->generation == slot->generation) 381 + nfs41_set_server_slotid_locked(tbl, res->sr_highest_slotid); 382 + nfs41_set_max_slotid_locked(tbl, res->sr_target_highest_slotid); 383 + spin_unlock(&tbl->slot_tbl_lock); 384 + } 385 + 386 + /* 387 + * Initialize or reset the forechannel and backchannel tables 388 + */ 389 + int nfs4_setup_session_slot_tables(struct nfs4_session *ses) 390 + { 391 + struct nfs4_slot_table *tbl; 392 + int status; 393 + 394 + dprintk("--> %s\n", __func__); 395 + /* Fore channel */ 396 + tbl = &ses->fc_slot_table; 397 + tbl->session = ses; 398 + status = nfs4_realloc_slot_table(tbl, ses->fc_attrs.max_reqs, 1); 399 + if (status) /* -ENOMEM */ 400 + return status; 401 + /* Back channel */ 402 + tbl = &ses->bc_slot_table; 403 + tbl->session = ses; 404 + status = nfs4_realloc_slot_table(tbl, ses->bc_attrs.max_reqs, 0); 405 + if (status && tbl->slots == NULL) 406 + /* Fore and back channel share a connection so get 407 + * both slot tables or neither */ 408 + nfs4_destroy_slot_tables(ses); 409 + return status; 410 + } 411 + 412 + struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp) 413 + { 414 + struct nfs4_session *session; 415 + struct nfs4_slot_table *tbl; 416 + 417 + session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); 418 + if (!session) 419 + return NULL; 420 + 421 + tbl = &session->fc_slot_table; 422 + tbl->highest_used_slotid = NFS4_NO_SLOT; 423 + spin_lock_init(&tbl->slot_tbl_lock); 424 + rpc_init_priority_wait_queue(&tbl->slot_tbl_waitq, "ForeChannel Slot table"); 425 + init_completion(&tbl->complete); 426 + 427 + tbl = &session->bc_slot_table; 428 + tbl->highest_used_slotid = NFS4_NO_SLOT; 429 + spin_lock_init(&tbl->slot_tbl_lock); 430 + rpc_init_wait_queue(&tbl->slot_tbl_waitq, "BackChannel Slot table"); 431 + init_completion(&tbl->complete); 432 + 433 + session->session_state = 1<<NFS4_SESSION_INITING; 434 + 435 + session->clp = clp; 436 + return session; 437 + } 438 + 439 + void nfs4_destroy_session(struct nfs4_session *session) 440 + { 441 + struct rpc_xprt *xprt; 442 + struct rpc_cred *cred; 443 + 444 + cred = nfs4_get_exchange_id_cred(session->clp); 445 + nfs4_proc_destroy_session(session, cred); 446 + if (cred) 447 + put_rpccred(cred); 448 + 449 + rcu_read_lock(); 450 + xprt = rcu_dereference(session->clp->cl_rpcclient->cl_xprt); 451 + rcu_read_unlock(); 452 + dprintk("%s Destroy backchannel for xprt %p\n", 453 + __func__, xprt); 454 + xprt_destroy_backchannel(xprt, NFS41_BC_MIN_CALLBACKS); 455 + nfs4_destroy_slot_tables(session); 456 + kfree(session); 457 + } 458 + 459 + /* 460 + * With sessions, the client is not marked ready until after a 461 + * successful EXCHANGE_ID and CREATE_SESSION. 462 + * 463 + * Map errors cl_cons_state errors to EPROTONOSUPPORT to indicate 464 + * other versions of NFS can be tried. 465 + */ 466 + static int nfs41_check_session_ready(struct nfs_client *clp) 467 + { 468 + int ret; 469 + 470 + if (clp->cl_cons_state == NFS_CS_SESSION_INITING) { 471 + ret = nfs4_client_recover_expired_lease(clp); 472 + if (ret) 473 + return ret; 474 + } 475 + if (clp->cl_cons_state < NFS_CS_READY) 476 + return -EPROTONOSUPPORT; 477 + smp_rmb(); 478 + return 0; 479 + } 480 + 481 + int nfs4_init_session(struct nfs_server *server) 482 + { 483 + struct nfs_client *clp = server->nfs_client; 484 + struct nfs4_session *session; 485 + unsigned int target_max_rqst_sz = NFS_MAX_FILE_IO_SIZE; 486 + unsigned int target_max_resp_sz = NFS_MAX_FILE_IO_SIZE; 487 + 488 + if (!nfs4_has_session(clp)) 489 + return 0; 490 + 491 + if (server->rsize != 0) 492 + target_max_resp_sz = server->rsize; 493 + target_max_resp_sz += nfs41_maxread_overhead; 494 + 495 + if (server->wsize != 0) 496 + target_max_rqst_sz = server->wsize; 497 + target_max_rqst_sz += nfs41_maxwrite_overhead; 498 + 499 + session = clp->cl_session; 500 + spin_lock(&clp->cl_lock); 501 + if (test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) { 502 + /* Initialise targets and channel attributes */ 503 + session->fc_target_max_rqst_sz = target_max_rqst_sz; 504 + session->fc_attrs.max_rqst_sz = target_max_rqst_sz; 505 + session->fc_target_max_resp_sz = target_max_resp_sz; 506 + session->fc_attrs.max_resp_sz = target_max_resp_sz; 507 + } else { 508 + /* Just adjust the targets */ 509 + if (target_max_rqst_sz > session->fc_target_max_rqst_sz) { 510 + session->fc_target_max_rqst_sz = target_max_rqst_sz; 511 + set_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state); 512 + } 513 + if (target_max_resp_sz > session->fc_target_max_resp_sz) { 514 + session->fc_target_max_resp_sz = target_max_resp_sz; 515 + set_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state); 516 + } 517 + } 518 + spin_unlock(&clp->cl_lock); 519 + 520 + if (test_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state)) 521 + nfs4_schedule_lease_recovery(clp); 522 + 523 + return nfs41_check_session_ready(clp); 524 + } 525 + 526 + int nfs4_init_ds_session(struct nfs_client *clp, unsigned long lease_time) 527 + { 528 + struct nfs4_session *session = clp->cl_session; 529 + int ret; 530 + 531 + spin_lock(&clp->cl_lock); 532 + if (test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) { 533 + /* 534 + * Do not set NFS_CS_CHECK_LEASE_TIME instead set the 535 + * DS lease to be equal to the MDS lease. 536 + */ 537 + clp->cl_lease_time = lease_time; 538 + clp->cl_last_renewal = jiffies; 539 + } 540 + spin_unlock(&clp->cl_lock); 541 + 542 + ret = nfs41_check_session_ready(clp); 543 + if (ret) 544 + return ret; 545 + /* Test for the DS role */ 546 + if (!is_ds_client(clp)) 547 + return -ENODEV; 548 + return 0; 549 + } 550 + EXPORT_SYMBOL_GPL(nfs4_init_ds_session); 551 + 552 +
+142
fs/nfs/nfs4session.h
··· 1 + /* 2 + * fs/nfs/nfs4session.h 3 + * 4 + * Copyright (c) 2012 Trond Myklebust <Trond.Myklebust@netapp.com> 5 + * 6 + */ 7 + #ifndef __LINUX_FS_NFS_NFS4SESSION_H 8 + #define __LINUX_FS_NFS_NFS4SESSION_H 9 + 10 + /* maximum number of slots to use */ 11 + #define NFS4_DEF_SLOT_TABLE_SIZE (16U) 12 + #define NFS4_MAX_SLOT_TABLE (1024U) 13 + #define NFS4_NO_SLOT ((u32)-1) 14 + 15 + #if IS_ENABLED(CONFIG_NFS_V4) 16 + 17 + /* Sessions slot seqid */ 18 + struct nfs4_slot { 19 + struct nfs4_slot_table *table; 20 + struct nfs4_slot *next; 21 + unsigned long generation; 22 + u32 slot_nr; 23 + u32 seq_nr; 24 + unsigned int interrupted : 1; 25 + }; 26 + 27 + /* Sessions */ 28 + #define SLOT_TABLE_SZ DIV_ROUND_UP(NFS4_MAX_SLOT_TABLE, 8*sizeof(long)) 29 + struct nfs4_slot_table { 30 + struct nfs4_session *session; /* Parent session */ 31 + struct nfs4_slot *slots; /* seqid per slot */ 32 + unsigned long used_slots[SLOT_TABLE_SZ]; /* used/unused bitmap */ 33 + spinlock_t slot_tbl_lock; 34 + struct rpc_wait_queue slot_tbl_waitq; /* allocators may wait here */ 35 + u32 max_slots; /* # slots in table */ 36 + u32 max_slotid; /* Max allowed slotid value */ 37 + u32 highest_used_slotid; /* sent to server on each SEQ. 38 + * op for dynamic resizing */ 39 + u32 target_highest_slotid; /* Server max_slot target */ 40 + u32 server_highest_slotid; /* Server highest slotid */ 41 + s32 d_target_highest_slotid; /* Derivative */ 42 + s32 d2_target_highest_slotid; /* 2nd derivative */ 43 + unsigned long generation; /* Generation counter for 44 + target_highest_slotid */ 45 + struct completion complete; 46 + }; 47 + 48 + /* 49 + * Session related parameters 50 + */ 51 + struct nfs4_session { 52 + struct nfs4_sessionid sess_id; 53 + u32 flags; 54 + unsigned long session_state; 55 + u32 hash_alg; 56 + u32 ssv_len; 57 + 58 + /* The fore and back channel */ 59 + struct nfs4_channel_attrs fc_attrs; 60 + struct nfs4_slot_table fc_slot_table; 61 + struct nfs4_channel_attrs bc_attrs; 62 + struct nfs4_slot_table bc_slot_table; 63 + struct nfs_client *clp; 64 + /* Create session arguments */ 65 + unsigned int fc_target_max_rqst_sz; 66 + unsigned int fc_target_max_resp_sz; 67 + }; 68 + 69 + enum nfs4_session_state { 70 + NFS4_SESSION_INITING, 71 + NFS4_SESSION_DRAINING, 72 + }; 73 + 74 + #if defined(CONFIG_NFS_V4_1) 75 + extern struct nfs4_slot *nfs4_alloc_slot(struct nfs4_slot_table *tbl); 76 + extern void nfs4_free_slot(struct nfs4_slot_table *tbl, struct nfs4_slot *slot); 77 + 78 + extern void nfs41_set_target_slotid(struct nfs4_slot_table *tbl, 79 + u32 target_highest_slotid); 80 + extern void nfs41_update_target_slotid(struct nfs4_slot_table *tbl, 81 + struct nfs4_slot *slot, 82 + struct nfs4_sequence_res *res); 83 + 84 + extern int nfs4_setup_session_slot_tables(struct nfs4_session *ses); 85 + 86 + extern struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp); 87 + extern void nfs4_destroy_session(struct nfs4_session *session); 88 + extern int nfs4_init_session(struct nfs_server *server); 89 + extern int nfs4_init_ds_session(struct nfs_client *, unsigned long); 90 + 91 + extern void nfs4_session_drain_complete(struct nfs4_session *session, 92 + struct nfs4_slot_table *tbl); 93 + 94 + static inline bool nfs4_session_draining(struct nfs4_session *session) 95 + { 96 + return !!test_bit(NFS4_SESSION_DRAINING, &session->session_state); 97 + } 98 + 99 + bool nfs41_wake_and_assign_slot(struct nfs4_slot_table *tbl, 100 + struct nfs4_slot *slot); 101 + void nfs41_wake_slot_table(struct nfs4_slot_table *tbl); 102 + 103 + /* 104 + * Determine if sessions are in use. 105 + */ 106 + static inline int nfs4_has_session(const struct nfs_client *clp) 107 + { 108 + if (clp->cl_session) 109 + return 1; 110 + return 0; 111 + } 112 + 113 + static inline int nfs4_has_persistent_session(const struct nfs_client *clp) 114 + { 115 + if (nfs4_has_session(clp)) 116 + return (clp->cl_session->flags & SESSION4_PERSIST); 117 + return 0; 118 + } 119 + 120 + #else /* defined(CONFIG_NFS_V4_1) */ 121 + 122 + static inline int nfs4_init_session(struct nfs_server *server) 123 + { 124 + return 0; 125 + } 126 + 127 + /* 128 + * Determine if sessions are in use. 129 + */ 130 + static inline int nfs4_has_session(const struct nfs_client *clp) 131 + { 132 + return 0; 133 + } 134 + 135 + static inline int nfs4_has_persistent_session(const struct nfs_client *clp) 136 + { 137 + return 0; 138 + } 139 + 140 + #endif /* defined(CONFIG_NFS_V4_1) */ 141 + #endif /* IS_ENABLED(CONFIG_NFS_V4) */ 142 + #endif /* __LINUX_FS_NFS_NFS4SESSION_H */
+62 -81
fs/nfs/nfs4state.c
··· 57 57 #include "callback.h" 58 58 #include "delegation.h" 59 59 #include "internal.h" 60 + #include "nfs4session.h" 60 61 #include "pnfs.h" 61 62 #include "netns.h" 62 63 ··· 67 66 68 67 const nfs4_stateid zero_stateid; 69 68 static DEFINE_MUTEX(nfs_clid_init_mutex); 70 - static LIST_HEAD(nfs4_clientid_list); 71 69 72 70 int nfs4_init_clientid(struct nfs_client *clp, struct rpc_cred *cred) 73 71 { ··· 254 254 { 255 255 struct nfs4_session *ses = clp->cl_session; 256 256 struct nfs4_slot_table *tbl; 257 - int max_slots; 258 257 259 258 if (ses == NULL) 260 259 return; 261 260 tbl = &ses->fc_slot_table; 262 261 if (test_and_clear_bit(NFS4_SESSION_DRAINING, &ses->session_state)) { 263 262 spin_lock(&tbl->slot_tbl_lock); 264 - max_slots = tbl->max_slots; 265 - while (max_slots--) { 266 - if (rpc_wake_up_first(&tbl->slot_tbl_waitq, 267 - nfs4_set_task_privileged, 268 - NULL) == NULL) 269 - break; 270 - } 263 + nfs41_wake_slot_table(tbl); 271 264 spin_unlock(&tbl->slot_tbl_lock); 272 265 } 266 + } 267 + 268 + /* 269 + * Signal state manager thread if session fore channel is drained 270 + */ 271 + void nfs4_session_drain_complete(struct nfs4_session *session, 272 + struct nfs4_slot_table *tbl) 273 + { 274 + if (nfs4_session_draining(session)) 275 + complete(&tbl->complete); 273 276 } 274 277 275 278 static int nfs4_wait_on_slot_tbl(struct nfs4_slot_table *tbl) ··· 306 303 clear_bit(NFS4CLNT_LEASE_CONFIRM, &clp->cl_state); 307 304 clear_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state); 308 305 /* create_session negotiated new slot table */ 309 - clear_bit(NFS4CLNT_RECALL_SLOT, &clp->cl_state); 310 306 clear_bit(NFS4CLNT_BIND_CONN_TO_SESSION, &clp->cl_state); 311 307 nfs41_setup_state_renewal(clp); 312 308 } ··· 1088 1086 */ 1089 1087 static void nfs_increment_seqid(int status, struct nfs_seqid *seqid) 1090 1088 { 1091 - BUG_ON(list_first_entry(&seqid->sequence->list, struct nfs_seqid, list) != seqid); 1092 1089 switch (status) { 1093 1090 case 0: 1094 1091 break; ··· 1209 1208 nfs4_schedule_state_manager(clp); 1210 1209 } 1211 1210 EXPORT_SYMBOL_GPL(nfs4_schedule_lease_recovery); 1211 + 1212 + int nfs4_wait_clnt_recover(struct nfs_client *clp) 1213 + { 1214 + int res; 1215 + 1216 + might_sleep(); 1217 + 1218 + res = wait_on_bit(&clp->cl_state, NFS4CLNT_MANAGER_RUNNING, 1219 + nfs_wait_bit_killable, TASK_KILLABLE); 1220 + if (res) 1221 + return res; 1222 + 1223 + if (clp->cl_cons_state < 0) 1224 + return clp->cl_cons_state; 1225 + return 0; 1226 + } 1227 + 1228 + int nfs4_client_recover_expired_lease(struct nfs_client *clp) 1229 + { 1230 + unsigned int loop; 1231 + int ret; 1232 + 1233 + for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { 1234 + ret = nfs4_wait_clnt_recover(clp); 1235 + if (ret != 0) 1236 + break; 1237 + if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) && 1238 + !test_bit(NFS4CLNT_CHECK_LEASE,&clp->cl_state)) 1239 + break; 1240 + nfs4_schedule_state_manager(clp); 1241 + ret = -EIO; 1242 + } 1243 + return ret; 1244 + } 1212 1245 1213 1246 /* 1214 1247 * nfs40_handle_cb_pathdown - return all delegations after NFS4ERR_CB_PATH_DOWN ··· 1436 1401 /* Mark the file as being 'closed' */ 1437 1402 state->state = 0; 1438 1403 break; 1439 - case -EKEYEXPIRED: 1440 - /* 1441 - * User RPCSEC_GSS context has expired. 1442 - * We cannot recover this stateid now, so 1443 - * skip it and allow recovery thread to 1444 - * proceed. 1445 - */ 1446 - break; 1447 1404 case -NFS4ERR_ADMIN_REVOKED: 1448 1405 case -NFS4ERR_STALE_STATEID: 1449 1406 case -NFS4ERR_BAD_STATEID: ··· 1588 1561 nfs4_state_mark_reclaim_helper(clp, nfs4_state_mark_reclaim_nograce); 1589 1562 } 1590 1563 1591 - static void nfs4_warn_keyexpired(const char *s) 1592 - { 1593 - printk_ratelimited(KERN_WARNING "Error: state manager" 1594 - " encountered RPCSEC_GSS session" 1595 - " expired against NFSv4 server %s.\n", 1596 - s); 1597 - } 1598 - 1599 1564 static int nfs4_recovery_handle_error(struct nfs_client *clp, int error) 1600 1565 { 1601 1566 switch (error) { ··· 1620 1601 break; 1621 1602 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: 1622 1603 set_bit(NFS4CLNT_BIND_CONN_TO_SESSION, &clp->cl_state); 1623 - break; 1624 - case -EKEYEXPIRED: 1625 - /* Nothing we can do */ 1626 - nfs4_warn_keyexpired(clp->cl_hostname); 1627 1604 break; 1628 1605 default: 1629 1606 dprintk("%s: failed to handle error %d for server %s\n", ··· 1737 1722 dprintk("%s: exit with error %d for server %s\n", 1738 1723 __func__, -EPROTONOSUPPORT, clp->cl_hostname); 1739 1724 return -EPROTONOSUPPORT; 1740 - case -EKEYEXPIRED: 1741 - nfs4_warn_keyexpired(clp->cl_hostname); 1742 1725 case -NFS4ERR_NOT_SAME: /* FixMe: implement recovery 1743 1726 * in nfs4_exchange_id */ 1744 1727 default: ··· 1889 1876 break; 1890 1877 1891 1878 case -EKEYEXPIRED: 1892 - nfs4_warn_keyexpired(clp->cl_hostname); 1893 1879 case -NFS4ERR_NOT_SAME: /* FixMe: implement recovery 1894 1880 * in nfs4_exchange_id */ 1895 1881 status = -EKEYEXPIRED; ··· 1919 1907 } 1920 1908 EXPORT_SYMBOL_GPL(nfs4_schedule_session_recovery); 1921 1909 1922 - void nfs41_handle_recall_slot(struct nfs_client *clp) 1910 + static void nfs41_ping_server(struct nfs_client *clp) 1923 1911 { 1924 - set_bit(NFS4CLNT_RECALL_SLOT, &clp->cl_state); 1925 - dprintk("%s: scheduling slot recall for server %s\n", __func__, 1926 - clp->cl_hostname); 1912 + /* Use CHECK_LEASE to ping the server with a SEQUENCE */ 1913 + set_bit(NFS4CLNT_CHECK_LEASE, &clp->cl_state); 1927 1914 nfs4_schedule_state_manager(clp); 1915 + } 1916 + 1917 + void nfs41_server_notify_target_slotid_update(struct nfs_client *clp) 1918 + { 1919 + nfs41_ping_server(clp); 1920 + } 1921 + 1922 + void nfs41_server_notify_highest_slotid_update(struct nfs_client *clp) 1923 + { 1924 + nfs41_ping_server(clp); 1928 1925 } 1929 1926 1930 1927 static void nfs4_reset_all_state(struct nfs_client *clp) ··· 2045 2024 return status; 2046 2025 } 2047 2026 2048 - static int nfs4_recall_slot(struct nfs_client *clp) 2049 - { 2050 - struct nfs4_slot_table *fc_tbl; 2051 - struct nfs4_slot *new, *old; 2052 - int i; 2053 - 2054 - if (!nfs4_has_session(clp)) 2055 - return 0; 2056 - nfs4_begin_drain_session(clp); 2057 - fc_tbl = &clp->cl_session->fc_slot_table; 2058 - new = kmalloc(fc_tbl->target_max_slots * sizeof(struct nfs4_slot), 2059 - GFP_NOFS); 2060 - if (!new) 2061 - return -ENOMEM; 2062 - 2063 - spin_lock(&fc_tbl->slot_tbl_lock); 2064 - for (i = 0; i < fc_tbl->target_max_slots; i++) 2065 - new[i].seq_nr = fc_tbl->slots[i].seq_nr; 2066 - old = fc_tbl->slots; 2067 - fc_tbl->slots = new; 2068 - fc_tbl->max_slots = fc_tbl->target_max_slots; 2069 - fc_tbl->target_max_slots = 0; 2070 - clp->cl_session->fc_attrs.max_reqs = fc_tbl->max_slots; 2071 - spin_unlock(&fc_tbl->slot_tbl_lock); 2072 - 2073 - kfree(old); 2074 - return 0; 2075 - } 2076 - 2077 2027 static int nfs4_bind_conn_to_session(struct nfs_client *clp) 2078 2028 { 2079 2029 struct rpc_cred *cred; ··· 2075 2083 #else /* CONFIG_NFS_V4_1 */ 2076 2084 static int nfs4_reset_session(struct nfs_client *clp) { return 0; } 2077 2085 static int nfs4_end_drain_session(struct nfs_client *clp) { return 0; } 2078 - static int nfs4_recall_slot(struct nfs_client *clp) { return 0; } 2079 2086 2080 2087 static int nfs4_bind_conn_to_session(struct nfs_client *clp) 2081 2088 { ··· 2106 2115 continue; 2107 2116 } 2108 2117 2109 - if (test_and_clear_bit(NFS4CLNT_CHECK_LEASE, &clp->cl_state)) { 2110 - section = "check lease"; 2111 - status = nfs4_check_lease(clp); 2112 - if (status < 0) 2113 - goto out_error; 2114 - if (test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state)) 2115 - continue; 2116 - } 2117 - 2118 2118 /* Initialize or reset the session */ 2119 2119 if (test_and_clear_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state)) { 2120 2120 section = "reset session"; ··· 2126 2144 continue; 2127 2145 } 2128 2146 2129 - /* Recall session slots */ 2130 - if (test_and_clear_bit(NFS4CLNT_RECALL_SLOT, &clp->cl_state)) { 2131 - section = "recall slot"; 2132 - status = nfs4_recall_slot(clp); 2147 + if (test_and_clear_bit(NFS4CLNT_CHECK_LEASE, &clp->cl_state)) { 2148 + section = "check lease"; 2149 + status = nfs4_check_lease(clp); 2133 2150 if (status < 0) 2134 2151 goto out_error; 2135 2152 continue;
+1
fs/nfs/nfs4super.c
··· 51 51 .alloc_inode = nfs_alloc_inode, 52 52 .destroy_inode = nfs_destroy_inode, 53 53 .write_inode = nfs4_write_inode, 54 + .drop_inode = nfs_drop_inode, 54 55 .put_super = nfs_put_super, 55 56 .statfs = nfs_statfs, 56 57 .evict_inode = nfs4_evict_inode,
+27 -25
fs/nfs/nfs4xdr.c
··· 56 56 57 57 #include "nfs4_fs.h" 58 58 #include "internal.h" 59 + #include "nfs4session.h" 59 60 #include "pnfs.h" 60 61 #include "netns.h" 61 62 ··· 271 270 272 271 #if defined(CONFIG_NFS_V4_1) 273 272 #define NFS4_MAX_MACHINE_NAME_LEN (64) 273 + #define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \ 274 + sizeof(utsname()->version) + sizeof(utsname()->machine) + 8) 274 275 275 276 #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \ 276 277 encode_verifier_maxsz + \ ··· 285 282 1 /* nii_domain */ + \ 286 283 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \ 287 284 1 /* nii_name */ + \ 288 - XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \ 285 + XDR_QUADLEN(IMPL_NAME_LIMIT) + \ 289 286 3 /* nii_date */) 290 287 #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \ 291 288 2 /* eir_clientid */ + \ ··· 939 936 * but this is not required as a MUST for the server to do so. */ 940 937 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen; 941 938 942 - BUG_ON(hdr->taglen > NFS4_MAXTAGLEN); 939 + WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN); 943 940 encode_string(xdr, hdr->taglen, hdr->tag); 944 941 p = reserve_space(xdr, 8); 945 942 *p++ = cpu_to_be32(hdr->minorversion); ··· 958 955 959 956 static void encode_nops(struct compound_hdr *hdr) 960 957 { 961 - BUG_ON(hdr->nops > NFS4_MAX_OPS); 958 + WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS); 962 959 *hdr->nops_p = htonl(hdr->nops); 963 960 } 964 961 ··· 1406 1403 *p = cpu_to_be32(NFS4_OPEN_NOCREATE); 1407 1404 break; 1408 1405 default: 1409 - BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL); 1410 1406 *p = cpu_to_be32(NFS4_OPEN_CREATE); 1411 1407 encode_createmode(xdr, arg); 1412 1408 } ··· 1623 1621 p = reserve_space(xdr, 2*4); 1624 1622 *p++ = cpu_to_be32(1); 1625 1623 *p = cpu_to_be32(FATTR4_WORD0_ACL); 1626 - BUG_ON(arg->acl_len % 4); 1627 1624 p = reserve_space(xdr, 4); 1628 1625 *p = cpu_to_be32(arg->acl_len); 1629 1626 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len); ··· 1714 1713 struct compound_hdr *hdr) 1715 1714 { 1716 1715 __be32 *p; 1717 - char impl_name[NFS4_OPAQUE_LIMIT]; 1716 + char impl_name[IMPL_NAME_LIMIT]; 1718 1717 int len = 0; 1719 1718 1720 1719 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr); ··· 1729 1728 if (send_implementation_id && 1730 1729 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 && 1731 1730 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) 1732 - <= NFS4_OPAQUE_LIMIT + 1) 1731 + <= sizeof(impl_name) + 1) 1733 1732 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s", 1734 1733 utsname()->sysname, utsname()->release, 1735 1734 utsname()->version, utsname()->machine); ··· 1836 1835 struct compound_hdr *hdr) 1837 1836 { 1838 1837 #if defined(CONFIG_NFS_V4_1) 1839 - struct nfs4_session *session = args->sa_session; 1838 + struct nfs4_session *session; 1840 1839 struct nfs4_slot_table *tp; 1841 - struct nfs4_slot *slot; 1840 + struct nfs4_slot *slot = args->sa_slot; 1842 1841 __be32 *p; 1843 1842 1844 - if (!session) 1843 + if (slot == NULL) 1845 1844 return; 1846 1845 1847 - tp = &session->fc_slot_table; 1848 - 1849 - WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE); 1850 - slot = tp->slots + args->sa_slotid; 1846 + tp = slot->table; 1847 + session = tp->session; 1851 1848 1852 1849 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr); 1853 1850 ··· 1859 1860 ((u32 *)session->sess_id.data)[1], 1860 1861 ((u32 *)session->sess_id.data)[2], 1861 1862 ((u32 *)session->sess_id.data)[3], 1862 - slot->seq_nr, args->sa_slotid, 1863 + slot->seq_nr, slot->slot_nr, 1863 1864 tp->highest_used_slotid, args->sa_cache_this); 1864 1865 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16); 1865 1866 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN); 1866 1867 *p++ = cpu_to_be32(slot->seq_nr); 1867 - *p++ = cpu_to_be32(args->sa_slotid); 1868 + *p++ = cpu_to_be32(slot->slot_nr); 1868 1869 *p++ = cpu_to_be32(tp->highest_used_slotid); 1869 1870 *p = cpu_to_be32(args->sa_cache_this); 1870 1871 #endif /* CONFIG_NFS_V4_1 */ ··· 2026 2027 static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args) 2027 2028 { 2028 2029 #if defined(CONFIG_NFS_V4_1) 2029 - if (args->sa_session) 2030 - return args->sa_session->clp->cl_mvops->minor_version; 2030 + 2031 + if (args->sa_slot) 2032 + return args->sa_slot->table->session->clp->cl_mvops->minor_version; 2031 2033 #endif /* CONFIG_NFS_V4_1 */ 2032 2034 return 0; 2033 2035 } ··· 5509 5509 struct rpc_rqst *rqstp) 5510 5510 { 5511 5511 #if defined(CONFIG_NFS_V4_1) 5512 + struct nfs4_session *session; 5512 5513 struct nfs4_sessionid id; 5513 5514 u32 dummy; 5514 5515 int status; 5515 5516 __be32 *p; 5516 5517 5517 - if (!res->sr_session) 5518 + if (res->sr_slot == NULL) 5518 5519 return 0; 5519 5520 5520 5521 status = decode_op_hdr(xdr, OP_SEQUENCE); ··· 5529 5528 * sequence number, the server is looney tunes. 5530 5529 */ 5531 5530 status = -EREMOTEIO; 5531 + session = res->sr_slot->table->session; 5532 5532 5533 - if (memcmp(id.data, res->sr_session->sess_id.data, 5533 + if (memcmp(id.data, session->sess_id.data, 5534 5534 NFS4_MAX_SESSIONID_LEN)) { 5535 5535 dprintk("%s Invalid session id\n", __func__); 5536 5536 goto out_err; ··· 5549 5547 } 5550 5548 /* slot id */ 5551 5549 dummy = be32_to_cpup(p++); 5552 - if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) { 5550 + if (dummy != res->sr_slot->slot_nr) { 5553 5551 dprintk("%s Invalid slot id\n", __func__); 5554 5552 goto out_err; 5555 5553 } 5556 - /* highest slot id - currently not processed */ 5557 - dummy = be32_to_cpup(p++); 5558 - /* target highest slot id - currently not processed */ 5559 - dummy = be32_to_cpup(p++); 5554 + /* highest slot id */ 5555 + res->sr_highest_slotid = be32_to_cpup(p++); 5556 + /* target highest slot id */ 5557 + res->sr_target_highest_slotid = be32_to_cpup(p++); 5560 5558 /* result flags */ 5561 5559 res->sr_status_flags = be32_to_cpup(p); 5562 5560 status = 0;
-11
fs/nfs/objlayout/objlayout.c
··· 148 148 return end >= start ? end : NFS4_MAX_UINT64; 149 149 } 150 150 151 - /* last octet in a range */ 152 - static inline u64 153 - last_byte_offset(u64 start, u64 len) 154 - { 155 - u64 end; 156 - 157 - BUG_ON(!len); 158 - end = start + len; 159 - return end > start ? end - 1 : NFS4_MAX_UINT64; 160 - } 161 - 162 151 static void _fix_verify_io_params(struct pnfs_layout_segment *lseg, 163 152 struct page ***p_pages, unsigned *p_pgbase, 164 153 u64 offset, unsigned long count)
+2 -15
fs/nfs/pnfs.c
··· 369 369 return end >= start ? end : NFS4_MAX_UINT64; 370 370 } 371 371 372 - /* last octet in a range */ 373 - static inline u64 374 - last_byte_offset(u64 start, u64 len) 375 - { 376 - u64 end; 377 - 378 - BUG_ON(!len); 379 - end = start + len; 380 - return end > start ? end - 1 : NFS4_MAX_UINT64; 381 - } 382 - 383 372 /* 384 373 * is l2 fully contained in l1? 385 374 * start1 end1 ··· 634 645 635 646 dprintk("--> %s\n", __func__); 636 647 637 - BUG_ON(ctx == NULL); 638 648 lgp = kzalloc(sizeof(*lgp), gfp_flags); 639 649 if (lgp == NULL) 640 650 return NULL; ··· 1114 1126 * chance of a CB_LAYOUTRECALL(FILE) coming in. 1115 1127 */ 1116 1128 spin_lock(&clp->cl_lock); 1117 - BUG_ON(!list_empty(&lo->plh_layouts)); 1118 1129 list_add_tail(&lo->plh_layouts, &server->layouts); 1119 1130 spin_unlock(&clp->cl_lock); 1120 1131 } ··· 1209 1222 { 1210 1223 u64 rd_size = req->wb_bytes; 1211 1224 1212 - BUG_ON(pgio->pg_lseg != NULL); 1225 + WARN_ON_ONCE(pgio->pg_lseg != NULL); 1213 1226 1214 1227 if (req->wb_offset != req->wb_pgbase) { 1215 1228 nfs_pageio_reset_read_mds(pgio); ··· 1238 1251 pnfs_generic_pg_init_write(struct nfs_pageio_descriptor *pgio, 1239 1252 struct nfs_page *req, u64 wb_size) 1240 1253 { 1241 - BUG_ON(pgio->pg_lseg != NULL); 1254 + WARN_ON_ONCE(pgio->pg_lseg != NULL); 1242 1255 1243 1256 if (req->wb_offset != req->wb_pgbase) { 1244 1257 nfs_pageio_reset_write_mds(pgio);
-43
fs/nfs/proc.c
··· 47 47 #define NFSDBG_FACILITY NFSDBG_PROC 48 48 49 49 /* 50 - * wrapper to handle the -EKEYEXPIRED error message. This should generally 51 - * only happen if using krb5 auth and a user's TGT expires. NFSv2 doesn't 52 - * support the NFSERR_JUKEBOX error code, but we handle this situation in the 53 - * same way that we handle that error with NFSv3. 54 - */ 55 - static int 56 - nfs_rpc_wrapper(struct rpc_clnt *clnt, struct rpc_message *msg, int flags) 57 - { 58 - int res; 59 - do { 60 - res = rpc_call_sync(clnt, msg, flags); 61 - if (res != -EKEYEXPIRED) 62 - break; 63 - freezable_schedule_timeout_killable(NFS_JUKEBOX_RETRY_TIME); 64 - res = -ERESTARTSYS; 65 - } while (!fatal_signal_pending(current)); 66 - return res; 67 - } 68 - 69 - #define rpc_call_sync(clnt, msg, flags) nfs_rpc_wrapper(clnt, msg, flags) 70 - 71 - static int 72 - nfs_async_handle_expired_key(struct rpc_task *task) 73 - { 74 - if (task->tk_status != -EKEYEXPIRED) 75 - return 0; 76 - task->tk_status = 0; 77 - rpc_restart_call(task); 78 - rpc_delay(task, NFS_JUKEBOX_RETRY_TIME); 79 - return 1; 80 - } 81 - 82 - /* 83 50 * Bare-bones access to getattr: this is for nfs_read_super. 84 51 */ 85 52 static int ··· 331 364 332 365 static int nfs_proc_unlink_done(struct rpc_task *task, struct inode *dir) 333 366 { 334 - if (nfs_async_handle_expired_key(task)) 335 - return 0; 336 367 nfs_mark_for_revalidate(dir); 337 368 return 1; 338 369 } ··· 350 385 nfs_proc_rename_done(struct rpc_task *task, struct inode *old_dir, 351 386 struct inode *new_dir) 352 387 { 353 - if (nfs_async_handle_expired_key(task)) 354 - return 0; 355 388 nfs_mark_for_revalidate(old_dir); 356 389 nfs_mark_for_revalidate(new_dir); 357 390 return 1; ··· 605 642 { 606 643 struct inode *inode = data->header->inode; 607 644 608 - if (nfs_async_handle_expired_key(task)) 609 - return -EAGAIN; 610 - 611 645 nfs_invalidate_atime(inode); 612 646 if (task->tk_status >= 0) { 613 647 nfs_refresh_inode(inode, data->res.fattr); ··· 630 670 static int nfs_write_done(struct rpc_task *task, struct nfs_write_data *data) 631 671 { 632 672 struct inode *inode = data->header->inode; 633 - 634 - if (nfs_async_handle_expired_key(task)) 635 - return -EAGAIN; 636 673 637 674 if (task->tk_status >= 0) 638 675 nfs_post_op_update_inode_force_wcc(inode, data->res.fattr);
+2
fs/nfs/super.c
··· 64 64 #include "iostat.h" 65 65 #include "internal.h" 66 66 #include "fscache.h" 67 + #include "nfs4session.h" 67 68 #include "pnfs.h" 68 69 #include "nfs.h" 69 70 ··· 308 307 .alloc_inode = nfs_alloc_inode, 309 308 .destroy_inode = nfs_destroy_inode, 310 309 .write_inode = nfs_write_inode, 310 + .drop_inode = nfs_drop_inode, 311 311 .put_super = nfs_put_super, 312 312 .statfs = nfs_statfs, 313 313 .evict_inode = nfs_evict_inode,
+12 -19
fs/nfs/write.c
··· 202 202 /* A writeback failed: mark the page as bad, and invalidate the page cache */ 203 203 static void nfs_set_pageerror(struct page *page) 204 204 { 205 - SetPageError(page); 206 205 nfs_zap_mapping(page_file_mapping(page)->host, page_file_mapping(page)); 207 206 } 208 207 ··· 238 239 #define NFS_CONGESTION_OFF_THRESH \ 239 240 (NFS_CONGESTION_ON_THRESH - (NFS_CONGESTION_ON_THRESH >> 2)) 240 241 241 - static int nfs_set_page_writeback(struct page *page) 242 + static void nfs_set_page_writeback(struct page *page) 242 243 { 244 + struct nfs_server *nfss = NFS_SERVER(page_file_mapping(page)->host); 243 245 int ret = test_set_page_writeback(page); 244 246 245 - if (!ret) { 246 - struct inode *inode = page_file_mapping(page)->host; 247 - struct nfs_server *nfss = NFS_SERVER(inode); 247 + WARN_ON_ONCE(ret != 0); 248 248 249 - if (atomic_long_inc_return(&nfss->writeback) > 250 - NFS_CONGESTION_ON_THRESH) { 251 - set_bdi_congested(&nfss->backing_dev_info, 252 - BLK_RW_ASYNC); 253 - } 249 + if (atomic_long_inc_return(&nfss->writeback) > 250 + NFS_CONGESTION_ON_THRESH) { 251 + set_bdi_congested(&nfss->backing_dev_info, 252 + BLK_RW_ASYNC); 254 253 } 255 - return ret; 256 254 } 257 255 258 256 static void nfs_end_page_writeback(struct page *page) ··· 311 315 if (IS_ERR(req)) 312 316 goto out; 313 317 314 - ret = nfs_set_page_writeback(page); 315 - BUG_ON(ret != 0); 316 - BUG_ON(test_bit(PG_CLEAN, &req->wb_flags)); 318 + nfs_set_page_writeback(page); 319 + WARN_ON_ONCE(test_bit(PG_CLEAN, &req->wb_flags)); 317 320 321 + ret = 0; 318 322 if (!nfs_pageio_add_request(pgio, req)) { 319 323 nfs_redirty_request(req); 320 324 ret = pgio->pg_error; ··· 446 450 { 447 451 struct inode *inode = req->wb_context->dentry->d_inode; 448 452 struct nfs_inode *nfsi = NFS_I(inode); 449 - 450 - BUG_ON (!NFS_WBACK_BUSY(req)); 451 453 452 454 spin_lock(&inode->i_lock); 453 455 if (likely(!PageSwapCache(req->wb_page))) { ··· 878 884 { 879 885 if (nfs_have_delegated_attributes(inode)) 880 886 goto out; 881 - if (NFS_I(inode)->cache_validity & NFS_INO_REVAL_PAGECACHE) 887 + if (NFS_I(inode)->cache_validity & (NFS_INO_INVALID_DATA|NFS_INO_REVAL_PAGECACHE)) 882 888 return false; 883 889 out: 884 890 return PageUptodate(page) != 0; ··· 1721 1727 struct nfs_page *req; 1722 1728 int ret = 0; 1723 1729 1724 - BUG_ON(!PageLocked(page)); 1725 1730 for (;;) { 1726 1731 wait_on_page_writeback(page); 1727 1732 req = nfs_page_find_request(page); ··· 1822 1829 goto out_destroy_write_mempool; 1823 1830 1824 1831 nfs_commit_mempool = mempool_create_slab_pool(MIN_POOL_COMMIT, 1825 - nfs_wdata_cachep); 1832 + nfs_cdata_cachep); 1826 1833 if (nfs_commit_mempool == NULL) 1827 1834 goto out_destroy_commit_cache; 1828 1835
-47
include/linux/nfs_fs_sb.h
··· 198 198 #define NFS_CAP_POSIX_LOCK (1U << 14) 199 199 #define NFS_CAP_UIDGID_NOMAP (1U << 15) 200 200 201 - 202 - /* maximum number of slots to use */ 203 - #define NFS4_DEF_SLOT_TABLE_SIZE (16U) 204 - #define NFS4_MAX_SLOT_TABLE (256U) 205 - #define NFS4_NO_SLOT ((u32)-1) 206 - 207 - #if IS_ENABLED(CONFIG_NFS_V4) 208 - 209 - /* Sessions */ 210 - #define SLOT_TABLE_SZ DIV_ROUND_UP(NFS4_MAX_SLOT_TABLE, 8*sizeof(long)) 211 - struct nfs4_slot_table { 212 - struct nfs4_slot *slots; /* seqid per slot */ 213 - unsigned long used_slots[SLOT_TABLE_SZ]; /* used/unused bitmap */ 214 - spinlock_t slot_tbl_lock; 215 - struct rpc_wait_queue slot_tbl_waitq; /* allocators may wait here */ 216 - u32 max_slots; /* # slots in table */ 217 - u32 highest_used_slotid; /* sent to server on each SEQ. 218 - * op for dynamic resizing */ 219 - u32 target_max_slots; /* Set by CB_RECALL_SLOT as 220 - * the new max_slots */ 221 - struct completion complete; 222 - }; 223 - 224 - static inline int slot_idx(struct nfs4_slot_table *tbl, struct nfs4_slot *sp) 225 - { 226 - return sp - tbl->slots; 227 - } 228 - 229 - /* 230 - * Session related parameters 231 - */ 232 - struct nfs4_session { 233 - struct nfs4_sessionid sess_id; 234 - u32 flags; 235 - unsigned long session_state; 236 - u32 hash_alg; 237 - u32 ssv_len; 238 - 239 - /* The fore and back channel */ 240 - struct nfs4_channel_attrs fc_attrs; 241 - struct nfs4_slot_table fc_slot_table; 242 - struct nfs4_channel_attrs bc_attrs; 243 - struct nfs4_slot_table bc_slot_table; 244 - struct nfs_client *clp; 245 - }; 246 - 247 - #endif /* CONFIG_NFS_V4 */ 248 201 #endif
+76 -79
include/linux/nfs_xdr.h
··· 185 185 u32 max_reqs; 186 186 }; 187 187 188 - /* nfs41 sessions slot seqid */ 189 - struct nfs4_slot { 190 - u32 seq_nr; 191 - }; 192 - 188 + struct nfs4_slot; 193 189 struct nfs4_sequence_args { 194 - struct nfs4_session *sa_session; 195 - u32 sa_slotid; 196 - u8 sa_cache_this; 190 + struct nfs4_slot *sa_slot; 191 + u8 sa_cache_this : 1, 192 + sa_privileged : 1; 197 193 }; 198 194 199 195 struct nfs4_sequence_res { 200 - struct nfs4_session *sr_session; 201 196 struct nfs4_slot *sr_slot; /* slot used to send request */ 197 + unsigned long sr_timestamp; 202 198 int sr_status; /* sequence operation status */ 203 - unsigned long sr_renewal_time; 204 199 u32 sr_status_flags; 200 + u32 sr_highest_slotid; 201 + u32 sr_target_highest_slotid; 205 202 }; 206 203 207 204 struct nfs4_get_lease_time_args { ··· 206 209 }; 207 210 208 211 struct nfs4_get_lease_time_res { 209 - struct nfs_fsinfo *lr_fsinfo; 210 212 struct nfs4_sequence_res lr_seq_res; 213 + struct nfs_fsinfo *lr_fsinfo; 211 214 }; 212 215 213 216 #define PNFS_LAYOUT_MAXSIZE 4096 ··· 225 228 }; 226 229 227 230 struct nfs4_layoutget_args { 231 + struct nfs4_sequence_args seq_args; 228 232 __u32 type; 229 233 struct pnfs_layout_range range; 230 234 __u64 minlength; 231 235 __u32 maxcount; 232 236 struct inode *inode; 233 237 struct nfs_open_context *ctx; 234 - struct nfs4_sequence_args seq_args; 235 238 nfs4_stateid stateid; 236 239 struct nfs4_layoutdriver_data layout; 237 240 }; 238 241 239 242 struct nfs4_layoutget_res { 243 + struct nfs4_sequence_res seq_res; 240 244 __u32 return_on_close; 241 245 struct pnfs_layout_range range; 242 246 __u32 type; 243 247 nfs4_stateid stateid; 244 - struct nfs4_sequence_res seq_res; 245 248 struct nfs4_layoutdriver_data *layoutp; 246 249 }; 247 250 ··· 252 255 }; 253 256 254 257 struct nfs4_getdevicelist_args { 258 + struct nfs4_sequence_args seq_args; 255 259 const struct nfs_fh *fh; 256 260 u32 layoutclass; 257 - struct nfs4_sequence_args seq_args; 258 261 }; 259 262 260 263 struct nfs4_getdevicelist_res { 261 - struct pnfs_devicelist *devlist; 262 264 struct nfs4_sequence_res seq_res; 265 + struct pnfs_devicelist *devlist; 263 266 }; 264 267 265 268 struct nfs4_getdeviceinfo_args { 266 - struct pnfs_device *pdev; 267 269 struct nfs4_sequence_args seq_args; 270 + struct pnfs_device *pdev; 268 271 }; 269 272 270 273 struct nfs4_getdeviceinfo_res { 271 - struct pnfs_device *pdev; 272 274 struct nfs4_sequence_res seq_res; 275 + struct pnfs_device *pdev; 273 276 }; 274 277 275 278 struct nfs4_layoutcommit_args { 279 + struct nfs4_sequence_args seq_args; 276 280 nfs4_stateid stateid; 277 281 __u64 lastbytewritten; 278 282 struct inode *inode; 279 283 const u32 *bitmask; 280 - struct nfs4_sequence_args seq_args; 281 284 }; 282 285 283 286 struct nfs4_layoutcommit_res { 287 + struct nfs4_sequence_res seq_res; 284 288 struct nfs_fattr *fattr; 285 289 const struct nfs_server *server; 286 - struct nfs4_sequence_res seq_res; 287 290 int status; 288 291 }; 289 292 ··· 297 300 }; 298 301 299 302 struct nfs4_layoutreturn_args { 303 + struct nfs4_sequence_args seq_args; 300 304 struct pnfs_layout_hdr *layout; 301 305 struct inode *inode; 302 306 nfs4_stateid stateid; 303 307 __u32 layout_type; 304 - struct nfs4_sequence_args seq_args; 305 308 }; 306 309 307 310 struct nfs4_layoutreturn_res { ··· 327 330 * Arguments to the open call. 328 331 */ 329 332 struct nfs_openargs { 333 + struct nfs4_sequence_args seq_args; 330 334 const struct nfs_fh * fh; 331 335 struct nfs_seqid * seqid; 332 336 int open_flags; ··· 348 350 const u32 * bitmask; 349 351 const u32 * open_bitmap; 350 352 __u32 claim; 351 - struct nfs4_sequence_args seq_args; 352 353 }; 353 354 354 355 struct nfs_openres { 356 + struct nfs4_sequence_res seq_res; 355 357 nfs4_stateid stateid; 356 358 struct nfs_fh fh; 357 359 struct nfs4_change_info cinfo; ··· 366 368 __u32 attrset[NFS4_BITMAP_SIZE]; 367 369 struct nfs4_string *owner; 368 370 struct nfs4_string *group_owner; 369 - struct nfs4_sequence_res seq_res; 370 371 __u32 access_request; 371 372 __u32 access_supported; 372 373 __u32 access_result; ··· 389 392 * Arguments to the close call. 390 393 */ 391 394 struct nfs_closeargs { 395 + struct nfs4_sequence_args seq_args; 392 396 struct nfs_fh * fh; 393 397 nfs4_stateid * stateid; 394 398 struct nfs_seqid * seqid; 395 399 fmode_t fmode; 396 400 const u32 * bitmask; 397 - struct nfs4_sequence_args seq_args; 398 401 }; 399 402 400 403 struct nfs_closeres { 404 + struct nfs4_sequence_res seq_res; 401 405 nfs4_stateid stateid; 402 406 struct nfs_fattr * fattr; 403 407 struct nfs_seqid * seqid; 404 408 const struct nfs_server *server; 405 - struct nfs4_sequence_res seq_res; 406 409 }; 407 410 /* 408 411 * * Arguments to the lock,lockt, and locku call. ··· 414 417 }; 415 418 416 419 struct nfs_lock_args { 420 + struct nfs4_sequence_args seq_args; 417 421 struct nfs_fh * fh; 418 422 struct file_lock * fl; 419 423 struct nfs_seqid * lock_seqid; ··· 425 427 unsigned char block : 1; 426 428 unsigned char reclaim : 1; 427 429 unsigned char new_lock_owner : 1; 428 - struct nfs4_sequence_args seq_args; 429 430 }; 430 431 431 432 struct nfs_lock_res { 433 + struct nfs4_sequence_res seq_res; 432 434 nfs4_stateid stateid; 433 435 struct nfs_seqid * lock_seqid; 434 436 struct nfs_seqid * open_seqid; 435 - struct nfs4_sequence_res seq_res; 436 437 }; 437 438 438 439 struct nfs_locku_args { 440 + struct nfs4_sequence_args seq_args; 439 441 struct nfs_fh * fh; 440 442 struct file_lock * fl; 441 443 struct nfs_seqid * seqid; 442 444 nfs4_stateid * stateid; 443 - struct nfs4_sequence_args seq_args; 444 445 }; 445 446 446 447 struct nfs_locku_res { 448 + struct nfs4_sequence_res seq_res; 447 449 nfs4_stateid stateid; 448 450 struct nfs_seqid * seqid; 449 - struct nfs4_sequence_res seq_res; 450 451 }; 451 452 452 453 struct nfs_lockt_args { 454 + struct nfs4_sequence_args seq_args; 453 455 struct nfs_fh * fh; 454 456 struct file_lock * fl; 455 457 struct nfs_lowner lock_owner; 456 - struct nfs4_sequence_args seq_args; 457 458 }; 458 459 459 460 struct nfs_lockt_res { 460 - struct file_lock * denied; /* LOCK, LOCKT failed */ 461 461 struct nfs4_sequence_res seq_res; 462 + struct file_lock * denied; /* LOCK, LOCKT failed */ 462 463 }; 463 464 464 465 struct nfs_release_lockowner_args { ··· 465 468 }; 466 469 467 470 struct nfs4_delegreturnargs { 471 + struct nfs4_sequence_args seq_args; 468 472 const struct nfs_fh *fhandle; 469 473 const nfs4_stateid *stateid; 470 474 const u32 * bitmask; 471 - struct nfs4_sequence_args seq_args; 472 475 }; 473 476 474 477 struct nfs4_delegreturnres { 478 + struct nfs4_sequence_res seq_res; 475 479 struct nfs_fattr * fattr; 476 480 const struct nfs_server *server; 477 - struct nfs4_sequence_res seq_res; 478 481 }; 479 482 480 483 /* 481 484 * Arguments to the read call. 482 485 */ 483 486 struct nfs_readargs { 487 + struct nfs4_sequence_args seq_args; 484 488 struct nfs_fh * fh; 485 489 struct nfs_open_context *context; 486 490 struct nfs_lock_context *lock_context; ··· 489 491 __u32 count; 490 492 unsigned int pgbase; 491 493 struct page ** pages; 492 - struct nfs4_sequence_args seq_args; 493 494 }; 494 495 495 496 struct nfs_readres { 497 + struct nfs4_sequence_res seq_res; 496 498 struct nfs_fattr * fattr; 497 499 __u32 count; 498 500 int eof; 499 - struct nfs4_sequence_res seq_res; 500 501 }; 501 502 502 503 /* 503 504 * Arguments to the write call. 504 505 */ 505 506 struct nfs_writeargs { 507 + struct nfs4_sequence_args seq_args; 506 508 struct nfs_fh * fh; 507 509 struct nfs_open_context *context; 508 510 struct nfs_lock_context *lock_context; ··· 512 514 unsigned int pgbase; 513 515 struct page ** pages; 514 516 const u32 * bitmask; 515 - struct nfs4_sequence_args seq_args; 516 517 }; 517 518 518 519 struct nfs_write_verifier { ··· 524 527 }; 525 528 526 529 struct nfs_writeres { 530 + struct nfs4_sequence_res seq_res; 527 531 struct nfs_fattr * fattr; 528 532 struct nfs_writeverf * verf; 529 533 __u32 count; 530 534 const struct nfs_server *server; 531 - struct nfs4_sequence_res seq_res; 532 535 }; 533 536 534 537 /* 535 538 * Arguments to the commit call. 536 539 */ 537 540 struct nfs_commitargs { 541 + struct nfs4_sequence_args seq_args; 538 542 struct nfs_fh *fh; 539 543 __u64 offset; 540 544 __u32 count; 541 545 const u32 *bitmask; 542 - struct nfs4_sequence_args seq_args; 543 546 }; 544 547 545 548 struct nfs_commitres { 549 + struct nfs4_sequence_res seq_res; 546 550 struct nfs_fattr *fattr; 547 551 struct nfs_writeverf *verf; 548 552 const struct nfs_server *server; 549 - struct nfs4_sequence_res seq_res; 550 553 }; 551 554 552 555 /* 553 556 * Common arguments to the unlink call 554 557 */ 555 558 struct nfs_removeargs { 559 + struct nfs4_sequence_args seq_args; 556 560 const struct nfs_fh *fh; 557 561 struct qstr name; 558 - struct nfs4_sequence_args seq_args; 559 562 }; 560 563 561 564 struct nfs_removeres { 565 + struct nfs4_sequence_res seq_res; 562 566 const struct nfs_server *server; 563 567 struct nfs_fattr *dir_attr; 564 568 struct nfs4_change_info cinfo; 565 - struct nfs4_sequence_res seq_res; 566 569 }; 567 570 568 571 /* 569 572 * Common arguments to the rename call 570 573 */ 571 574 struct nfs_renameargs { 575 + struct nfs4_sequence_args seq_args; 572 576 const struct nfs_fh *old_dir; 573 577 const struct nfs_fh *new_dir; 574 578 const struct qstr *old_name; 575 579 const struct qstr *new_name; 576 - struct nfs4_sequence_args seq_args; 577 580 }; 578 581 579 582 struct nfs_renameres { 583 + struct nfs4_sequence_res seq_res; 580 584 const struct nfs_server *server; 581 585 struct nfs4_change_info old_cinfo; 582 586 struct nfs_fattr *old_fattr; 583 587 struct nfs4_change_info new_cinfo; 584 588 struct nfs_fattr *new_fattr; 585 - struct nfs4_sequence_res seq_res; 586 589 }; 587 590 588 591 /* ··· 623 626 }; 624 627 625 628 struct nfs_setattrargs { 629 + struct nfs4_sequence_args seq_args; 626 630 struct nfs_fh * fh; 627 631 nfs4_stateid stateid; 628 632 struct iattr * iap; 629 633 const struct nfs_server * server; /* Needed for name mapping */ 630 634 const u32 * bitmask; 631 - struct nfs4_sequence_args seq_args; 632 635 }; 633 636 634 637 struct nfs_setaclargs { 638 + struct nfs4_sequence_args seq_args; 635 639 struct nfs_fh * fh; 636 640 size_t acl_len; 637 641 unsigned int acl_pgbase; 638 642 struct page ** acl_pages; 639 - struct nfs4_sequence_args seq_args; 640 643 }; 641 644 642 645 struct nfs_setaclres { ··· 644 647 }; 645 648 646 649 struct nfs_getaclargs { 650 + struct nfs4_sequence_args seq_args; 647 651 struct nfs_fh * fh; 648 652 size_t acl_len; 649 653 unsigned int acl_pgbase; 650 654 struct page ** acl_pages; 651 - struct nfs4_sequence_args seq_args; 652 655 }; 653 656 654 657 /* getxattr ACL interface flags */ 655 658 #define NFS4_ACL_TRUNC 0x0001 /* ACL was truncated */ 656 659 struct nfs_getaclres { 660 + struct nfs4_sequence_res seq_res; 657 661 size_t acl_len; 658 662 size_t acl_data_offset; 659 663 int acl_flags; 660 664 struct page * acl_scratch; 661 - struct nfs4_sequence_res seq_res; 662 665 }; 663 666 664 667 struct nfs_setattrres { 668 + struct nfs4_sequence_res seq_res; 665 669 struct nfs_fattr * fattr; 666 670 const struct nfs_server * server; 667 - struct nfs4_sequence_res seq_res; 668 671 }; 669 672 670 673 struct nfs_linkargs { ··· 829 832 typedef u64 clientid4; 830 833 831 834 struct nfs4_accessargs { 835 + struct nfs4_sequence_args seq_args; 832 836 const struct nfs_fh * fh; 833 837 const u32 * bitmask; 834 838 u32 access; 835 - struct nfs4_sequence_args seq_args; 836 839 }; 837 840 838 841 struct nfs4_accessres { 842 + struct nfs4_sequence_res seq_res; 839 843 const struct nfs_server * server; 840 844 struct nfs_fattr * fattr; 841 845 u32 supported; 842 846 u32 access; 843 - struct nfs4_sequence_res seq_res; 844 847 }; 845 848 846 849 struct nfs4_create_arg { 850 + struct nfs4_sequence_args seq_args; 847 851 u32 ftype; 848 852 union { 849 853 struct { ··· 861 863 const struct iattr * attrs; 862 864 const struct nfs_fh * dir_fh; 863 865 const u32 * bitmask; 864 - struct nfs4_sequence_args seq_args; 865 866 }; 866 867 867 868 struct nfs4_create_res { 869 + struct nfs4_sequence_res seq_res; 868 870 const struct nfs_server * server; 869 871 struct nfs_fh * fh; 870 872 struct nfs_fattr * fattr; 871 873 struct nfs4_change_info dir_cinfo; 872 - struct nfs4_sequence_res seq_res; 873 874 }; 874 875 875 876 struct nfs4_fsinfo_arg { 877 + struct nfs4_sequence_args seq_args; 876 878 const struct nfs_fh * fh; 877 879 const u32 * bitmask; 878 - struct nfs4_sequence_args seq_args; 879 880 }; 880 881 881 882 struct nfs4_fsinfo_res { 882 - struct nfs_fsinfo *fsinfo; 883 883 struct nfs4_sequence_res seq_res; 884 + struct nfs_fsinfo *fsinfo; 884 885 }; 885 886 886 887 struct nfs4_getattr_arg { 888 + struct nfs4_sequence_args seq_args; 887 889 const struct nfs_fh * fh; 888 890 const u32 * bitmask; 889 - struct nfs4_sequence_args seq_args; 890 891 }; 891 892 892 893 struct nfs4_getattr_res { 894 + struct nfs4_sequence_res seq_res; 893 895 const struct nfs_server * server; 894 896 struct nfs_fattr * fattr; 895 - struct nfs4_sequence_res seq_res; 896 897 }; 897 898 898 899 struct nfs4_link_arg { 900 + struct nfs4_sequence_args seq_args; 899 901 const struct nfs_fh * fh; 900 902 const struct nfs_fh * dir_fh; 901 903 const struct qstr * name; 902 904 const u32 * bitmask; 903 - struct nfs4_sequence_args seq_args; 904 905 }; 905 906 906 907 struct nfs4_link_res { 908 + struct nfs4_sequence_res seq_res; 907 909 const struct nfs_server * server; 908 910 struct nfs_fattr * fattr; 909 911 struct nfs4_change_info cinfo; 910 912 struct nfs_fattr * dir_attr; 911 - struct nfs4_sequence_res seq_res; 912 913 }; 913 914 914 915 915 916 struct nfs4_lookup_arg { 917 + struct nfs4_sequence_args seq_args; 916 918 const struct nfs_fh * dir_fh; 917 919 const struct qstr * name; 918 920 const u32 * bitmask; 919 - struct nfs4_sequence_args seq_args; 920 921 }; 921 922 922 923 struct nfs4_lookup_res { 924 + struct nfs4_sequence_res seq_res; 923 925 const struct nfs_server * server; 924 926 struct nfs_fattr * fattr; 925 927 struct nfs_fh * fh; 926 - struct nfs4_sequence_res seq_res; 927 928 }; 928 929 929 930 struct nfs4_lookup_root_arg { 930 - const u32 * bitmask; 931 931 struct nfs4_sequence_args seq_args; 932 + const u32 * bitmask; 932 933 }; 933 934 934 935 struct nfs4_pathconf_arg { 936 + struct nfs4_sequence_args seq_args; 935 937 const struct nfs_fh * fh; 936 938 const u32 * bitmask; 937 - struct nfs4_sequence_args seq_args; 938 939 }; 939 940 940 941 struct nfs4_pathconf_res { 941 - struct nfs_pathconf *pathconf; 942 942 struct nfs4_sequence_res seq_res; 943 + struct nfs_pathconf *pathconf; 943 944 }; 944 945 945 946 struct nfs4_readdir_arg { 947 + struct nfs4_sequence_args seq_args; 946 948 const struct nfs_fh * fh; 947 949 u64 cookie; 948 950 nfs4_verifier verifier; ··· 951 953 unsigned int pgbase; /* zero-copy data */ 952 954 const u32 * bitmask; 953 955 int plus; 954 - struct nfs4_sequence_args seq_args; 955 956 }; 956 957 957 958 struct nfs4_readdir_res { 959 + struct nfs4_sequence_res seq_res; 958 960 nfs4_verifier verifier; 959 961 unsigned int pgbase; 960 - struct nfs4_sequence_res seq_res; 961 962 }; 962 963 963 964 struct nfs4_readlink { 965 + struct nfs4_sequence_args seq_args; 964 966 const struct nfs_fh * fh; 965 967 unsigned int pgbase; 966 968 unsigned int pglen; /* zero-copy data */ 967 969 struct page ** pages; /* zero-copy data */ 968 - struct nfs4_sequence_args seq_args; 969 970 }; 970 971 971 972 struct nfs4_readlink_res { ··· 990 993 }; 991 994 992 995 struct nfs4_statfs_arg { 996 + struct nfs4_sequence_args seq_args; 993 997 const struct nfs_fh * fh; 994 998 const u32 * bitmask; 995 - struct nfs4_sequence_args seq_args; 996 999 }; 997 1000 998 1001 struct nfs4_statfs_res { 999 - struct nfs_fsstat *fsstat; 1000 1002 struct nfs4_sequence_res seq_res; 1003 + struct nfs_fsstat *fsstat; 1001 1004 }; 1002 1005 1003 1006 struct nfs4_server_caps_arg { 1004 - struct nfs_fh *fhandle; 1005 1007 struct nfs4_sequence_args seq_args; 1008 + struct nfs_fh *fhandle; 1006 1009 }; 1007 1010 1008 1011 struct nfs4_server_caps_res { 1012 + struct nfs4_sequence_res seq_res; 1009 1013 u32 attr_bitmask[3]; 1010 1014 u32 acl_bitmask; 1011 1015 u32 has_links; 1012 1016 u32 has_symlinks; 1013 1017 u32 fh_expire_type; 1014 - struct nfs4_sequence_res seq_res; 1015 1018 }; 1016 1019 1017 1020 #define NFS4_PATHNAME_MAXCOMPONENTS 512 ··· 1037 1040 }; 1038 1041 1039 1042 struct nfs4_fs_locations_arg { 1043 + struct nfs4_sequence_args seq_args; 1040 1044 const struct nfs_fh *dir_fh; 1041 1045 const struct qstr *name; 1042 1046 struct page *page; 1043 1047 const u32 *bitmask; 1044 - struct nfs4_sequence_args seq_args; 1045 1048 }; 1046 1049 1047 1050 struct nfs4_fs_locations_res { 1048 - struct nfs4_fs_locations *fs_locations; 1049 1051 struct nfs4_sequence_res seq_res; 1052 + struct nfs4_fs_locations *fs_locations; 1050 1053 }; 1051 1054 1052 1055 struct nfs4_secinfo_oid { ··· 1071 1074 }; 1072 1075 1073 1076 struct nfs4_secinfo_arg { 1077 + struct nfs4_sequence_args seq_args; 1074 1078 const struct nfs_fh *dir_fh; 1075 1079 const struct qstr *name; 1076 - struct nfs4_sequence_args seq_args; 1077 1080 }; 1078 1081 1079 1082 struct nfs4_secinfo_res { 1080 - struct nfs4_secinfo_flavors *flavors; 1081 1083 struct nfs4_sequence_res seq_res; 1084 + struct nfs4_secinfo_flavors *flavors; 1082 1085 }; 1083 1086 1084 1087 #endif /* CONFIG_NFS_V4 */ ··· 1158 1161 }; 1159 1162 1160 1163 struct nfs41_reclaim_complete_args { 1164 + struct nfs4_sequence_args seq_args; 1161 1165 /* In the future extend to include curr_fh for use with migration */ 1162 1166 unsigned char one_fs:1; 1163 - struct nfs4_sequence_args seq_args; 1164 1167 }; 1165 1168 1166 1169 struct nfs41_reclaim_complete_res { ··· 1170 1173 #define SECINFO_STYLE_CURRENT_FH 0 1171 1174 #define SECINFO_STYLE_PARENT 1 1172 1175 struct nfs41_secinfo_no_name_args { 1173 - int style; 1174 1176 struct nfs4_sequence_args seq_args; 1177 + int style; 1175 1178 }; 1176 1179 1177 1180 struct nfs41_test_stateid_args { 1178 - nfs4_stateid *stateid; 1179 1181 struct nfs4_sequence_args seq_args; 1182 + nfs4_stateid *stateid; 1180 1183 }; 1181 1184 1182 1185 struct nfs41_test_stateid_res { 1183 - unsigned int status; 1184 1186 struct nfs4_sequence_res seq_res; 1187 + unsigned int status; 1185 1188 }; 1186 1189 1187 1190 struct nfs41_free_stateid_args { 1188 - nfs4_stateid *stateid; 1189 1191 struct nfs4_sequence_args seq_args; 1192 + nfs4_stateid *stateid; 1190 1193 }; 1191 1194 1192 1195 struct nfs41_free_stateid_res { 1193 - unsigned int status; 1194 1196 struct nfs4_sequence_res seq_res; 1197 + unsigned int status; 1195 1198 }; 1196 1199 1197 1200 #else
-1
include/linux/sunrpc/sched.h
··· 192 192 pid_t owner; /* process id of last task serviced */ 193 193 unsigned char maxpriority; /* maximum priority (0 if queue is not a priority queue) */ 194 194 unsigned char priority; /* current priority */ 195 - unsigned char count; /* # task groups remaining serviced so far */ 196 195 unsigned char nr; /* # tasks remaining for cookie */ 197 196 unsigned short qlen; /* total # tasks waiting in queue */ 198 197 struct rpc_timer timer_list;
+13 -4
net/sunrpc/auth_gss/auth_gss.c
··· 192 192 const void *q; 193 193 unsigned int seclen; 194 194 unsigned int timeout; 195 + unsigned long now = jiffies; 195 196 u32 window_size; 196 197 int ret; 197 198 198 - /* First unsigned int gives the lifetime (in seconds) of the cred */ 199 + /* First unsigned int gives the remaining lifetime in seconds of the 200 + * credential - e.g. the remaining TGT lifetime for Kerberos or 201 + * the -t value passed to GSSD. 202 + */ 199 203 p = simple_get_bytes(p, end, &timeout, sizeof(timeout)); 200 204 if (IS_ERR(p)) 201 205 goto err; 202 206 if (timeout == 0) 203 207 timeout = GSSD_MIN_TIMEOUT; 204 - ctx->gc_expiry = jiffies + (unsigned long)timeout * HZ * 3 / 4; 205 - /* Sequence number window. Determines the maximum number of simultaneous requests */ 208 + ctx->gc_expiry = now + ((unsigned long)timeout * HZ); 209 + /* Sequence number window. Determines the maximum number of 210 + * simultaneous requests 211 + */ 206 212 p = simple_get_bytes(p, end, &window_size, sizeof(window_size)); 207 213 if (IS_ERR(p)) 208 214 goto err; ··· 243 237 p = ERR_PTR(ret); 244 238 goto err; 245 239 } 240 + dprintk("RPC: %s Success. gc_expiry %lu now %lu timeout %u\n", 241 + __func__, ctx->gc_expiry, now, timeout); 246 242 return q; 247 243 err: 248 - dprintk("RPC: %s returning %ld\n", __func__, -PTR_ERR(p)); 244 + dprintk("RPC: %s returns %ld gc_expiry %lu now %lu timeout %u\n", 245 + __func__, -PTR_ERR(p), ctx->gc_expiry, now, timeout); 249 246 return p; 250 247 } 251 248
+6 -3
net/sunrpc/backchannel_rqst.c
··· 59 59 struct xdr_buf *xbufp; 60 60 61 61 dprintk("RPC: free allocations for req= %p\n", req); 62 - BUG_ON(test_bit(RPC_BC_PA_IN_USE, &req->rq_bc_pa_state)); 62 + WARN_ON_ONCE(test_bit(RPC_BC_PA_IN_USE, &req->rq_bc_pa_state)); 63 63 xbufp = &req->rq_private_buf; 64 64 free_page((unsigned long)xbufp->head[0].iov_base); 65 65 xbufp = &req->rq_snd_buf; ··· 191 191 192 192 dprintk("RPC: destroy backchannel transport\n"); 193 193 194 - BUG_ON(max_reqs == 0); 194 + if (max_reqs == 0) 195 + goto out; 196 + 195 197 spin_lock_bh(&xprt->bc_pa_lock); 196 198 xprt_dec_alloc_count(xprt, max_reqs); 197 199 list_for_each_entry_safe(req, tmp, &xprt->bc_pa_list, rq_bc_pa_list) { ··· 204 202 } 205 203 spin_unlock_bh(&xprt->bc_pa_lock); 206 204 205 + out: 207 206 dprintk("RPC: backchannel list empty= %s\n", 208 207 list_empty(&xprt->bc_pa_list) ? "true" : "false"); 209 208 } ··· 258 255 dprintk("RPC: free backchannel req=%p\n", req); 259 256 260 257 smp_mb__before_clear_bit(); 261 - BUG_ON(!test_bit(RPC_BC_PA_IN_USE, &req->rq_bc_pa_state)); 258 + WARN_ON_ONCE(!test_bit(RPC_BC_PA_IN_USE, &req->rq_bc_pa_state)); 262 259 clear_bit(RPC_BC_PA_IN_USE, &req->rq_bc_pa_state); 263 260 smp_mb__after_clear_bit(); 264 261
+1 -1
net/sunrpc/bc_svc.c
··· 53 53 if (IS_ERR(task)) 54 54 ret = PTR_ERR(task); 55 55 else { 56 - BUG_ON(atomic_read(&task->tk_count) != 1); 56 + WARN_ON_ONCE(atomic_read(&task->tk_count) != 1); 57 57 ret = task->tk_status; 58 58 rpc_put_task(task); 59 59 }
+2 -2
net/sunrpc/cache.c
··· 775 775 if (rp->q.list.next == &cd->queue) { 776 776 spin_unlock(&queue_lock); 777 777 mutex_unlock(&inode->i_mutex); 778 - BUG_ON(rp->offset); 778 + WARN_ON_ONCE(rp->offset); 779 779 return 0; 780 780 } 781 781 rq = container_of(rp->q.list.next, struct cache_request, q.list); 782 - BUG_ON(rq->q.reader); 782 + WARN_ON_ONCE(rq->q.reader); 783 783 if (rp->offset == 0) 784 784 rq->readers++; 785 785 spin_unlock(&queue_lock);
+30 -18
net/sunrpc/clnt.c
··· 132 132 int error; 133 133 134 134 dir = rpc_d_lookup_sb(sb, dir_name); 135 - if (dir == NULL) 135 + if (dir == NULL) { 136 + pr_info("RPC: pipefs directory doesn't exist: %s\n", dir_name); 136 137 return dir; 138 + } 137 139 for (;;) { 138 140 q.len = snprintf(name, sizeof(name), "clnt%x", (unsigned int)clntid++); 139 141 name[sizeof(name) - 1] = '\0'; ··· 194 192 case RPC_PIPEFS_MOUNT: 195 193 dentry = rpc_setup_pipedir_sb(sb, clnt, 196 194 clnt->cl_program->pipe_dir_name); 197 - BUG_ON(dentry == NULL); 195 + if (!dentry) 196 + return -ENOENT; 198 197 if (IS_ERR(dentry)) 199 198 return PTR_ERR(dentry); 200 199 clnt->cl_dentry = dentry; ··· 237 234 spin_lock(&sn->rpc_client_lock); 238 235 list_for_each_entry(clnt, &sn->all_clients, cl_clients) { 239 236 if (clnt->cl_program->pipe_dir_name == NULL) 240 - break; 237 + continue; 241 238 if (rpc_clnt_skip_event(clnt, event)) 242 239 continue; 243 240 if (atomic_inc_not_zero(&clnt->cl_count) == 0) ··· 610 607 */ 611 608 void rpc_shutdown_client(struct rpc_clnt *clnt) 612 609 { 610 + /* 611 + * To avoid deadlock, never call rpc_shutdown_client from a 612 + * workqueue context! 613 + */ 614 + WARN_ON_ONCE(current->flags & PF_WQ_WORKER); 615 + might_sleep(); 616 + 613 617 dprintk_rcu("RPC: shutting down %s client for %s\n", 614 618 clnt->cl_protname, 615 619 rcu_dereference(clnt->cl_xprt)->servername); ··· 703 693 const struct rpc_program *program, 704 694 u32 vers) 705 695 { 696 + struct rpc_create_args args = { 697 + .program = program, 698 + .prognumber = program->number, 699 + .version = vers, 700 + .authflavor = old->cl_auth->au_flavor, 701 + .client_name = old->cl_principal, 702 + }; 706 703 struct rpc_clnt *clnt; 707 - const struct rpc_version *version; 708 704 int err; 709 705 710 - BUG_ON(vers >= program->nrvers || !program->version[vers]); 711 - version = program->version[vers]; 712 - clnt = rpc_clone_client(old); 706 + clnt = __rpc_clone_client(&args, old); 713 707 if (IS_ERR(clnt)) 714 708 goto out; 715 - clnt->cl_procinfo = version->procs; 716 - clnt->cl_maxproc = version->nrprocs; 717 - clnt->cl_protname = program->name; 718 - clnt->cl_prog = program->number; 719 - clnt->cl_vers = version->number; 720 - clnt->cl_stats = program->stats; 721 709 err = rpc_ping(clnt); 722 710 if (err != 0) { 723 711 rpc_shutdown_client(clnt); ··· 840 832 }; 841 833 int status; 842 834 843 - BUG_ON(flags & RPC_TASK_ASYNC); 835 + WARN_ON_ONCE(flags & RPC_TASK_ASYNC); 836 + if (flags & RPC_TASK_ASYNC) { 837 + rpc_release_calldata(task_setup_data.callback_ops, 838 + task_setup_data.callback_data); 839 + return -EINVAL; 840 + } 844 841 845 842 task = rpc_run_task(&task_setup_data); 846 843 if (IS_ERR(task)) ··· 921 908 922 909 task->tk_action = call_bc_transmit; 923 910 atomic_inc(&task->tk_count); 924 - BUG_ON(atomic_read(&task->tk_count) != 2); 911 + WARN_ON_ONCE(atomic_read(&task->tk_count) != 2); 925 912 rpc_execute(task); 926 913 927 914 out: ··· 1381 1368 return; 1382 1369 case -ETIMEDOUT: 1383 1370 rpc_delay(task, 3*HZ); 1371 + case -EKEYEXPIRED: 1384 1372 case -EAGAIN: 1385 1373 status = -EACCES; 1386 1374 if (!task->tk_cred_retry) ··· 1668 1654 task->tk_action = call_transmit_status; 1669 1655 /* Encode here so that rpcsec_gss can use correct sequence number. */ 1670 1656 if (rpc_task_need_encode(task)) { 1671 - BUG_ON(task->tk_rqstp->rq_bytes_sent != 0); 1672 1657 rpc_xdr_encode(task); 1673 1658 /* Did the encode result in an error condition? */ 1674 1659 if (task->tk_status != 0) { ··· 1751 1738 { 1752 1739 struct rpc_rqst *req = task->tk_rqstp; 1753 1740 1754 - BUG_ON(task->tk_status != 0); 1755 1741 task->tk_status = xprt_prepare_transmit(task); 1756 1742 if (task->tk_status == -EAGAIN) { 1757 1743 /* ··· 1797 1785 * We were unable to reply and will have to drop the 1798 1786 * request. The server should reconnect and retransmit. 1799 1787 */ 1800 - BUG_ON(task->tk_status == -EAGAIN); 1788 + WARN_ON_ONCE(task->tk_status == -EAGAIN); 1801 1789 printk(KERN_NOTICE "RPC: Could not send backchannel reply " 1802 1790 "error: %d\n", task->tk_status); 1803 1791 break;
+7 -2
net/sunrpc/rpc_pipe.c
··· 1093 1093 { 1094 1094 struct sunrpc_net *sn = net_generic(net, sunrpc_net_id); 1095 1095 1096 - BUG_ON(sn->pipefs_sb == NULL); 1096 + WARN_ON(sn->pipefs_sb == NULL); 1097 1097 mutex_unlock(&sn->pipefs_sb_lock); 1098 1098 } 1099 1099 EXPORT_SYMBOL_GPL(rpc_put_sb_net); ··· 1152 1152 struct sunrpc_net *sn = net_generic(net, sunrpc_net_id); 1153 1153 1154 1154 mutex_lock(&sn->pipefs_sb_lock); 1155 + if (sn->pipefs_sb != sb) { 1156 + mutex_unlock(&sn->pipefs_sb_lock); 1157 + goto out; 1158 + } 1155 1159 sn->pipefs_sb = NULL; 1156 1160 mutex_unlock(&sn->pipefs_sb_lock); 1157 - put_net(net); 1158 1161 dprintk("RPC: sending pipefs UMOUNT notification for net %p%s\n", 1159 1162 net, NET_NAME(net)); 1160 1163 blocking_notifier_call_chain(&rpc_pipefs_notifier_list, 1161 1164 RPC_PIPEFS_UMOUNT, 1162 1165 sb); 1166 + put_net(net); 1167 + out: 1163 1168 kill_litter_super(sb); 1164 1169 } 1165 1170
+4 -1
net/sunrpc/rpcb_clnt.c
··· 884 884 u32 len; 885 885 886 886 len = strlen(string); 887 - BUG_ON(len > maxstrlen); 887 + WARN_ON_ONCE(len > maxstrlen); 888 + if (len > maxstrlen) 889 + /* truncate and hope for the best */ 890 + len = maxstrlen; 888 891 p = xdr_reserve_space(xdr, 4 + len); 889 892 xdr_encode_opaque(p, string, len); 890 893 }
+43 -28
net/sunrpc/sched.c
··· 98 98 list_add(&task->u.tk_wait.timer_list, &queue->timer_list.list); 99 99 } 100 100 101 + static void rpc_set_waitqueue_priority(struct rpc_wait_queue *queue, int priority) 102 + { 103 + queue->priority = priority; 104 + } 105 + 106 + static void rpc_set_waitqueue_owner(struct rpc_wait_queue *queue, pid_t pid) 107 + { 108 + queue->owner = pid; 109 + queue->nr = RPC_BATCH_COUNT; 110 + } 111 + 112 + static void rpc_reset_waitqueue_priority(struct rpc_wait_queue *queue) 113 + { 114 + rpc_set_waitqueue_priority(queue, queue->maxpriority); 115 + rpc_set_waitqueue_owner(queue, 0); 116 + } 117 + 101 118 /* 102 119 * Add new request to a priority queue. 103 120 */ ··· 126 109 struct rpc_task *t; 127 110 128 111 INIT_LIST_HEAD(&task->u.tk_wait.links); 129 - q = &queue->tasks[queue_priority]; 130 112 if (unlikely(queue_priority > queue->maxpriority)) 131 - q = &queue->tasks[queue->maxpriority]; 113 + queue_priority = queue->maxpriority; 114 + if (queue_priority > queue->priority) 115 + rpc_set_waitqueue_priority(queue, queue_priority); 116 + q = &queue->tasks[queue_priority]; 132 117 list_for_each_entry(t, q, u.tk_wait.list) { 133 118 if (t->tk_owner == task->tk_owner) { 134 119 list_add_tail(&task->u.tk_wait.list, &t->u.tk_wait.links); ··· 152 133 struct rpc_task *task, 153 134 unsigned char queue_priority) 154 135 { 155 - BUG_ON (RPC_IS_QUEUED(task)); 136 + WARN_ON_ONCE(RPC_IS_QUEUED(task)); 137 + if (RPC_IS_QUEUED(task)) 138 + return; 156 139 157 140 if (RPC_IS_PRIORITY(queue)) 158 141 __rpc_add_wait_queue_priority(queue, task, queue_priority); ··· 197 176 queue->qlen--; 198 177 dprintk("RPC: %5u removed from queue %p \"%s\"\n", 199 178 task->tk_pid, queue, rpc_qname(queue)); 200 - } 201 - 202 - static inline void rpc_set_waitqueue_priority(struct rpc_wait_queue *queue, int priority) 203 - { 204 - queue->priority = priority; 205 - queue->count = 1 << (priority * 2); 206 - } 207 - 208 - static inline void rpc_set_waitqueue_owner(struct rpc_wait_queue *queue, pid_t pid) 209 - { 210 - queue->owner = pid; 211 - queue->nr = RPC_BATCH_COUNT; 212 - } 213 - 214 - static inline void rpc_reset_waitqueue_priority(struct rpc_wait_queue *queue) 215 - { 216 - rpc_set_waitqueue_priority(queue, queue->maxpriority); 217 - rpc_set_waitqueue_owner(queue, 0); 218 179 } 219 180 220 181 static void __rpc_init_priority_wait_queue(struct rpc_wait_queue *queue, const char *qname, unsigned char nr_queues) ··· 337 334 338 335 __rpc_add_wait_queue(q, task, queue_priority); 339 336 340 - BUG_ON(task->tk_callback != NULL); 337 + WARN_ON_ONCE(task->tk_callback != NULL); 341 338 task->tk_callback = action; 342 339 __rpc_add_timer(q, task); 343 340 } ··· 346 343 rpc_action action) 347 344 { 348 345 /* We shouldn't ever put an inactive task to sleep */ 349 - BUG_ON(!RPC_IS_ACTIVATED(task)); 346 + WARN_ON_ONCE(!RPC_IS_ACTIVATED(task)); 347 + if (!RPC_IS_ACTIVATED(task)) { 348 + task->tk_status = -EIO; 349 + rpc_put_task_async(task); 350 + return; 351 + } 350 352 351 353 /* 352 354 * Protect the queue operations. ··· 366 358 rpc_action action, int priority) 367 359 { 368 360 /* We shouldn't ever put an inactive task to sleep */ 369 - BUG_ON(!RPC_IS_ACTIVATED(task)); 361 + WARN_ON_ONCE(!RPC_IS_ACTIVATED(task)); 362 + if (!RPC_IS_ACTIVATED(task)) { 363 + task->tk_status = -EIO; 364 + rpc_put_task_async(task); 365 + return; 366 + } 370 367 371 368 /* 372 369 * Protect the queue operations. ··· 380 367 __rpc_sleep_on_priority(q, task, action, priority - RPC_PRIORITY_LOW); 381 368 spin_unlock_bh(&q->lock); 382 369 } 370 + EXPORT_SYMBOL_GPL(rpc_sleep_on_priority); 383 371 384 372 /** 385 373 * __rpc_do_wake_up_task - wake up a single rpc_task ··· 465 451 /* 466 452 * Check if we need to switch queues. 467 453 */ 468 - if (--queue->count) 469 - goto new_owner; 454 + goto new_owner; 470 455 } 471 456 472 457 /* ··· 710 697 dprintk("RPC: %5u __rpc_execute flags=0x%x\n", 711 698 task->tk_pid, task->tk_flags); 712 699 713 - BUG_ON(RPC_IS_QUEUED(task)); 700 + WARN_ON_ONCE(RPC_IS_QUEUED(task)); 701 + if (RPC_IS_QUEUED(task)) 702 + return; 714 703 715 704 for (;;) { 716 705 void (*do_action)(struct rpc_task *); ··· 996 981 { 997 982 dprintk("RPC: %5u release task\n", task->tk_pid); 998 983 999 - BUG_ON (RPC_IS_QUEUED(task)); 984 + WARN_ON_ONCE(RPC_IS_QUEUED(task)); 1000 985 1001 986 rpc_release_resources_task(task); 1002 987
+9 -3
net/sunrpc/svc.c
··· 324 324 * The caller checks for sv_nrpools > 1, which 325 325 * implies that we've been initialized. 326 326 */ 327 - BUG_ON(m->count == 0); 327 + WARN_ON_ONCE(m->count == 0); 328 + if (m->count == 0) 329 + return; 328 330 329 331 switch (m->mode) { 330 332 case SVC_POOL_PERCPU: ··· 587 585 * We assume one is at most one page 588 586 */ 589 587 arghi = 0; 590 - BUG_ON(pages > RPCSVC_MAXPAGES); 588 + WARN_ON_ONCE(pages > RPCSVC_MAXPAGES); 589 + if (pages > RPCSVC_MAXPAGES) 590 + pages = RPCSVC_MAXPAGES; 591 591 while (pages) { 592 592 struct page *p = alloc_pages_node(node, GFP_KERNEL, 0); 593 593 if (!p) ··· 950 946 unsigned int i; 951 947 int error = 0; 952 948 953 - BUG_ON(proto == 0 && port == 0); 949 + WARN_ON_ONCE(proto == 0 && port == 0); 950 + if (proto == 0 && port == 0) 951 + return -EINVAL; 954 952 955 953 for (progp = serv->sv_program; progp; progp = progp->pg_next) { 956 954 for (i = 0; i < progp->pg_nvers; i++) {
+8 -3
net/sunrpc/svc_xprt.c
··· 218 218 */ 219 219 static void svc_xprt_received(struct svc_xprt *xprt) 220 220 { 221 - BUG_ON(!test_bit(XPT_BUSY, &xprt->xpt_flags)); 221 + WARN_ON_ONCE(!test_bit(XPT_BUSY, &xprt->xpt_flags)); 222 + if (!test_bit(XPT_BUSY, &xprt->xpt_flags)) 223 + return; 222 224 /* As soon as we clear busy, the xprt could be closed and 223 225 * 'put', so we need a reference to call svc_xprt_enqueue with: 224 226 */ ··· 579 577 580 578 /* now allocate needed pages. If we get a failure, sleep briefly */ 581 579 pages = (serv->sv_max_mesg + PAGE_SIZE) / PAGE_SIZE; 582 - BUG_ON(pages >= RPCSVC_MAXPAGES); 580 + WARN_ON_ONCE(pages >= RPCSVC_MAXPAGES); 581 + if (pages >= RPCSVC_MAXPAGES) 582 + /* use as many pages as possible */ 583 + pages = RPCSVC_MAXPAGES - 1; 583 584 for (i = 0; i < pages ; i++) 584 585 while (rqstp->rq_pages[i] == NULL) { 585 586 struct page *p = alloc_page(GFP_KERNEL); ··· 931 926 spin_lock_bh(&serv->sv_lock); 932 927 if (!test_and_set_bit(XPT_DETACHED, &xprt->xpt_flags)) 933 928 list_del_init(&xprt->xpt_list); 934 - BUG_ON(!list_empty(&xprt->xpt_ready)); 929 + WARN_ON_ONCE(!list_empty(&xprt->xpt_ready)); 935 930 if (test_bit(XPT_TEMP, &xprt->xpt_flags)) 936 931 serv->sv_tmpcnt--; 937 932 spin_unlock_bh(&serv->sv_lock);
+5 -1
net/sunrpc/svcsock.c
··· 84 84 static void svc_reclassify_socket(struct socket *sock) 85 85 { 86 86 struct sock *sk = sock->sk; 87 - BUG_ON(sock_owned_by_user(sk)); 87 + 88 + WARN_ON_ONCE(sock_owned_by_user(sk)); 89 + if (sock_owned_by_user(sk)) 90 + return; 91 + 88 92 switch (sk->sk_family) { 89 93 case AF_INET: 90 94 sock_lock_init_class_and_name(sk, "slock-AF_INET-NFSD",
+4 -1
net/sunrpc/xdr.c
··· 318 318 319 319 tail = buf->tail; 320 320 head = buf->head; 321 - BUG_ON (len > head->iov_len); 321 + 322 + WARN_ON_ONCE(len > head->iov_len); 323 + if (len > head->iov_len) 324 + len = head->iov_len; 322 325 323 326 /* Shift the tail first */ 324 327 if (tail->iov_len != 0) {
+12 -7
net/sunrpc/xprtsock.c
··· 1746 1746 { 1747 1747 struct sock *sk = sock->sk; 1748 1748 1749 - BUG_ON(sock_owned_by_user(sk)); 1750 1749 sock_lock_init_class_and_name(sk, "slock-AF_LOCAL-RPC", 1751 1750 &xs_slock_key[1], "sk_lock-AF_LOCAL-RPC", &xs_key[1]); 1752 1751 } ··· 1754 1755 { 1755 1756 struct sock *sk = sock->sk; 1756 1757 1757 - BUG_ON(sock_owned_by_user(sk)); 1758 1758 sock_lock_init_class_and_name(sk, "slock-AF_INET-RPC", 1759 1759 &xs_slock_key[0], "sk_lock-AF_INET-RPC", &xs_key[0]); 1760 1760 } ··· 1762 1764 { 1763 1765 struct sock *sk = sock->sk; 1764 1766 1765 - BUG_ON(sock_owned_by_user(sk)); 1766 1767 sock_lock_init_class_and_name(sk, "slock-AF_INET6-RPC", 1767 1768 &xs_slock_key[1], "sk_lock-AF_INET6-RPC", &xs_key[1]); 1768 1769 } 1769 1770 1770 1771 static inline void xs_reclassify_socket(int family, struct socket *sock) 1771 1772 { 1773 + WARN_ON_ONCE(sock_owned_by_user(sock->sk)); 1774 + if (sock_owned_by_user(sock->sk)) 1775 + return; 1776 + 1772 1777 switch (family) { 1773 1778 case AF_LOCAL: 1774 1779 xs_reclassify_socketu(sock); ··· 1900 1899 break; 1901 1900 case -ENOENT: 1902 1901 dprintk("RPC: xprt %p: socket %s does not exist\n", 1902 + xprt, xprt->address_strings[RPC_DISPLAY_ADDR]); 1903 + break; 1904 + case -ECONNREFUSED: 1905 + dprintk("RPC: xprt %p: connection refused for %s\n", 1903 1906 xprt, xprt->address_strings[RPC_DISPLAY_ADDR]); 1904 1907 break; 1905 1908 default: ··· 2334 2329 struct page *page; 2335 2330 struct rpc_buffer *buf; 2336 2331 2337 - BUG_ON(size > PAGE_SIZE - sizeof(struct rpc_buffer)); 2338 - page = alloc_page(GFP_KERNEL); 2332 + WARN_ON_ONCE(size > PAGE_SIZE - sizeof(struct rpc_buffer)); 2333 + if (size > PAGE_SIZE - sizeof(struct rpc_buffer)) 2334 + return NULL; 2339 2335 2336 + page = alloc_page(GFP_KERNEL); 2340 2337 if (!page) 2341 2338 return NULL; 2342 2339 ··· 2400 2393 { 2401 2394 struct rpc_rqst *req = task->tk_rqstp; 2402 2395 struct svc_xprt *xprt; 2403 - struct svc_sock *svsk; 2404 2396 u32 len; 2405 2397 2406 2398 dprintk("sending request with xid: %08x\n", ntohl(req->rq_xid)); ··· 2407 2401 * Get the server socket associated with this callback xprt 2408 2402 */ 2409 2403 xprt = req->rq_xprt->bc_xprt; 2410 - svsk = container_of(xprt, struct svc_sock, sk_xprt); 2411 2404 2412 2405 /* 2413 2406 * Grab the mutex to serialize data as the connection is shared