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

Merge tag 'nfsd-6.15' of git://git.kernel.org/pub/scm/linux/kernel/git/cel/linux

Pull nfsd updates from Chuck Lever:
"Neil Brown contributed more scalability improvements to NFSD's open
file cache, and Jeff Layton contributed a menagerie of repairs to
NFSD's NFSv4 callback / backchannel implementation.

Mike Snitzer contributed a change to NFS re-export support that
disables support for file locking on a re-exported NFSv4 mount. This
is because NFSv4 state recovery is currently difficult if not
impossible for re-exported NFS mounts. The change aims to prevent data
integrity exposures after the re-export server crashes.

Work continues on the evolving NFSD netlink administrative API.

Many thanks to the contributors, reviewers, testers, and bug reporters
who participated during the v6.15 development cycle"

* tag 'nfsd-6.15' of git://git.kernel.org/pub/scm/linux/kernel/git/cel/linux: (45 commits)
NFSD: Add a Kconfig setting to enable delegated timestamps
sysctl: Fixes nsm_local_state bounds
nfsd: use a long for the count in nfsd4_state_shrinker_count()
nfsd: remove obsolete comment from nfs4_alloc_stid
nfsd: remove unneeded forward declaration of nfsd4_mark_cb_fault()
nfsd: reorganize struct nfs4_delegation for better packing
nfsd: handle errors from rpc_call_async()
nfsd: move cb_need_restart flag into cb_flags
nfsd: replace CB_GETATTR_BUSY with NFSD4_CALLBACK_RUNNING
nfsd: eliminate cl_ra_cblist and NFSD4_CLIENT_CB_RECALL_ANY
nfsd: prevent callback tasks running concurrently
nfsd: disallow file locking and delegations for NFSv4 reexport
nfsd: filecache: drop the list_lru lock during lock gc scans
nfsd: filecache: don't repeatedly add/remove files on the lru list
nfsd: filecache: introduce NFSD_FILE_RECENT
nfsd: filecache: use list_lru_walk_node() in nfsd_file_gc()
nfsd: filecache: use nfsd_file_dispose_list() in nfsd_file_close_inode_sync()
NFSD: Re-organize nfsd_file_gc_worker()
nfsd: filecache: remove race handling.
fs: nfs: acl: Avoid -Wflex-array-member-not-at-end warning
...

+685 -405
+7 -3
Documentation/filesystems/nfs/reexport.rst
··· 26 26 --------------- 27 27 28 28 The NFS protocol's normal reboot recovery mechanisms don't work for the 29 - case when the reexport server reboots. Clients will lose any locks 30 - they held before the reboot, and further IO will result in errors. 31 - Closing and reopening files should clear the errors. 29 + case when the reexport server reboots because the source server has not 30 + rebooted, and so it is not in grace. Since the source server is not in 31 + grace, it cannot offer any guarantees that the file won't have been 32 + changed between the locks getting lost and any attempt to recover them. 33 + The same applies to delegations and any associated locks. Clients are 34 + not allowed to get file locks or delegations from a reexport server, any 35 + attempts will fail with operation not supported. 32 36 33 37 Filehandle limits 34 38 -----------------
+45
Documentation/netlink/specs/lockd.yaml
··· 1 + # SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 2 + 3 + name: lockd 4 + protocol: genetlink 5 + uapi-header: linux/lockd_netlink.h 6 + 7 + doc: lockd configuration over generic netlink 8 + 9 + attribute-sets: 10 + - 11 + name: server 12 + attributes: 13 + - 14 + name: gracetime 15 + type: u32 16 + - 17 + name: tcp-port 18 + type: u16 19 + - 20 + name: udp-port 21 + type: u16 22 + 23 + operations: 24 + list: 25 + - 26 + name: server-set 27 + doc: set the lockd server parameters 28 + attribute-set: server 29 + flags: [ admin-perm ] 30 + do: 31 + request: 32 + attributes: 33 + - gracetime 34 + - tcp-port 35 + - udp-port 36 + - 37 + name: server-get 38 + doc: get the lockd server parameters 39 + attribute-set: server 40 + do: 41 + reply: 42 + attributes: 43 + - gracetime 44 + - tcp-port 45 + - udp-port
+1 -1
fs/lockd/Makefile
··· 8 8 obj-$(CONFIG_LOCKD) += lockd.o 9 9 10 10 lockd-y := clntlock.o clntproc.o clntxdr.o host.o svc.o svclock.o \ 11 - svcshare.o svcproc.o svcsubs.o mon.o trace.o xdr.o 11 + svcshare.o svcproc.o svcsubs.o mon.o trace.o xdr.o netlink.o 12 12 lockd-$(CONFIG_LOCKD_V4) += clnt4xdr.o xdr4.o svc4proc.o 13 13 lockd-$(CONFIG_PROC_FS) += procfs.o
+44
fs/lockd/netlink.c
··· 1 + // SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 2 + /* Do not edit directly, auto-generated from: */ 3 + /* Documentation/netlink/specs/lockd.yaml */ 4 + /* YNL-GEN kernel source */ 5 + 6 + #include <net/netlink.h> 7 + #include <net/genetlink.h> 8 + 9 + #include "netlink.h" 10 + 11 + #include <uapi/linux/lockd_netlink.h> 12 + 13 + /* LOCKD_CMD_SERVER_SET - do */ 14 + static const struct nla_policy lockd_server_set_nl_policy[LOCKD_A_SERVER_UDP_PORT + 1] = { 15 + [LOCKD_A_SERVER_GRACETIME] = { .type = NLA_U32, }, 16 + [LOCKD_A_SERVER_TCP_PORT] = { .type = NLA_U16, }, 17 + [LOCKD_A_SERVER_UDP_PORT] = { .type = NLA_U16, }, 18 + }; 19 + 20 + /* Ops table for lockd */ 21 + static const struct genl_split_ops lockd_nl_ops[] = { 22 + { 23 + .cmd = LOCKD_CMD_SERVER_SET, 24 + .doit = lockd_nl_server_set_doit, 25 + .policy = lockd_server_set_nl_policy, 26 + .maxattr = LOCKD_A_SERVER_UDP_PORT, 27 + .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO, 28 + }, 29 + { 30 + .cmd = LOCKD_CMD_SERVER_GET, 31 + .doit = lockd_nl_server_get_doit, 32 + .flags = GENL_CMD_CAP_DO, 33 + }, 34 + }; 35 + 36 + struct genl_family lockd_nl_family __ro_after_init = { 37 + .name = LOCKD_FAMILY_NAME, 38 + .version = LOCKD_FAMILY_VERSION, 39 + .netnsok = true, 40 + .parallel_ops = true, 41 + .module = THIS_MODULE, 42 + .split_ops = lockd_nl_ops, 43 + .n_split_ops = ARRAY_SIZE(lockd_nl_ops), 44 + };
+19
fs/lockd/netlink.h
··· 1 + /* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */ 2 + /* Do not edit directly, auto-generated from: */ 3 + /* Documentation/netlink/specs/lockd.yaml */ 4 + /* YNL-GEN kernel header */ 5 + 6 + #ifndef _LINUX_LOCKD_GEN_H 7 + #define _LINUX_LOCKD_GEN_H 8 + 9 + #include <net/netlink.h> 10 + #include <net/genetlink.h> 11 + 12 + #include <uapi/linux/lockd_netlink.h> 13 + 14 + int lockd_nl_server_set_doit(struct sk_buff *skb, struct genl_info *info); 15 + int lockd_nl_server_get_doit(struct sk_buff *skb, struct genl_info *info); 16 + 17 + extern struct genl_family lockd_nl_family; 18 + 19 + #endif /* _LINUX_LOCKD_GEN_H */
+3
fs/lockd/netns.h
··· 10 10 unsigned int nlmsvc_users; 11 11 unsigned long next_gc; 12 12 unsigned long nrhosts; 13 + u32 gracetime; 14 + u16 tcp_port; 15 + u16 udp_port; 13 16 14 17 struct delayed_work grace_period_end; 15 18 struct lock_manager lockd_manager;
+115 -8
fs/lockd/svc.c
··· 41 41 42 42 #include "netns.h" 43 43 #include "procfs.h" 44 + #include "netlink.h" 44 45 45 46 #define NLMDBG_FACILITY NLMDBG_SVC 46 47 #define LOCKD_BUFSIZE (1024 + NLMSVC_XDRSIZE) ··· 84 83 static struct ctl_table_header * nlm_sysctl_table; 85 84 #endif 86 85 87 - static unsigned long get_lockd_grace_period(void) 86 + static unsigned long get_lockd_grace_period(struct net *net) 88 87 { 88 + struct lockd_net *ln = net_generic(net, lockd_net_id); 89 + 90 + /* Return the net-ns specific grace period, if there is one */ 91 + if (ln->gracetime) 92 + return ln->gracetime * HZ; 93 + 89 94 /* Note: nlm_timeout should always be nonzero */ 90 95 if (nlm_grace_period) 91 96 return roundup(nlm_grace_period, nlm_timeout) * HZ; ··· 110 103 111 104 static void set_grace_period(struct net *net) 112 105 { 113 - unsigned long grace_period = get_lockd_grace_period(); 106 + unsigned long grace_period = get_lockd_grace_period(net); 114 107 struct lockd_net *ln = net_generic(net, lockd_net_id); 115 108 116 109 locks_start_grace(net, &ln->lockd_manager); ··· 173 166 static int create_lockd_family(struct svc_serv *serv, struct net *net, 174 167 const int family, const struct cred *cred) 175 168 { 169 + struct lockd_net *ln = net_generic(net, lockd_net_id); 176 170 int err; 177 171 178 - err = create_lockd_listener(serv, "udp", net, family, nlm_udpport, 179 - cred); 172 + err = create_lockd_listener(serv, "udp", net, family, 173 + ln->udp_port ? ln->udp_port : nlm_udpport, cred); 180 174 if (err < 0) 181 175 return err; 182 176 183 - return create_lockd_listener(serv, "tcp", net, family, nlm_tcpport, 184 - cred); 177 + return create_lockd_listener(serv, "tcp", net, family, 178 + ln->tcp_port ? ln->tcp_port : nlm_tcpport, cred); 185 179 } 186 180 187 181 /* ··· 467 459 { 468 460 .procname = "nsm_local_state", 469 461 .data = &nsm_local_state, 470 - .maxlen = sizeof(int), 462 + .maxlen = sizeof(nsm_local_state), 471 463 .mode = 0644, 472 - .proc_handler = proc_dointvec, 464 + .proc_handler = proc_douintvec, 465 + .extra1 = SYSCTL_ZERO, 473 466 }, 474 467 }; 475 468 ··· 597 588 if (err) 598 589 goto err_pernet; 599 590 591 + err = genl_register_family(&lockd_nl_family); 592 + if (err) 593 + goto err_netlink; 594 + 600 595 err = lockd_create_procfs(); 601 596 if (err) 602 597 goto err_procfs; ··· 608 595 return 0; 609 596 610 597 err_procfs: 598 + genl_unregister_family(&lockd_nl_family); 599 + err_netlink: 611 600 unregister_pernet_subsys(&lockd_net_ops); 612 601 err_pernet: 613 602 #ifdef CONFIG_SYSCTL ··· 623 608 { 624 609 /* FIXME: delete all NLM clients */ 625 610 nlm_shutdown_hosts(); 611 + genl_unregister_family(&lockd_nl_family); 626 612 lockd_remove_procfs(); 627 613 unregister_pernet_subsys(&lockd_net_ops); 628 614 #ifdef CONFIG_SYSCTL ··· 726 710 .pg_init_request = svc_generic_init_request, 727 711 .pg_rpcbind_set = svc_generic_rpcbind_set, 728 712 }; 713 + 714 + /** 715 + * lockd_nl_server_set_doit - set the lockd server parameters via netlink 716 + * @skb: reply buffer 717 + * @info: netlink metadata and command arguments 718 + * 719 + * This updates the per-net values. When updating the values in the init_net 720 + * namespace, also update the "legacy" global values. 721 + * 722 + * Return 0 on success or a negative errno. 723 + */ 724 + int lockd_nl_server_set_doit(struct sk_buff *skb, struct genl_info *info) 725 + { 726 + struct net *net = genl_info_net(info); 727 + struct lockd_net *ln = net_generic(net, lockd_net_id); 728 + const struct nlattr *attr; 729 + 730 + if (GENL_REQ_ATTR_CHECK(info, LOCKD_A_SERVER_GRACETIME)) 731 + return -EINVAL; 732 + 733 + if (info->attrs[LOCKD_A_SERVER_GRACETIME] || 734 + info->attrs[LOCKD_A_SERVER_TCP_PORT] || 735 + info->attrs[LOCKD_A_SERVER_UDP_PORT]) { 736 + attr = info->attrs[LOCKD_A_SERVER_GRACETIME]; 737 + if (attr) { 738 + u32 gracetime = nla_get_u32(attr); 739 + 740 + if (gracetime > nlm_grace_period_max) 741 + return -EINVAL; 742 + 743 + ln->gracetime = gracetime; 744 + 745 + if (net == &init_net) 746 + nlm_grace_period = gracetime; 747 + } 748 + 749 + attr = info->attrs[LOCKD_A_SERVER_TCP_PORT]; 750 + if (attr) { 751 + ln->tcp_port = nla_get_u16(attr); 752 + if (net == &init_net) 753 + nlm_tcpport = ln->tcp_port; 754 + } 755 + 756 + attr = info->attrs[LOCKD_A_SERVER_UDP_PORT]; 757 + if (attr) { 758 + ln->udp_port = nla_get_u16(attr); 759 + if (net == &init_net) 760 + nlm_udpport = ln->udp_port; 761 + } 762 + } 763 + return 0; 764 + } 765 + 766 + /** 767 + * lockd_nl_server_get_doit - get lockd server parameters via netlink 768 + * @skb: reply buffer 769 + * @info: netlink metadata and command arguments 770 + * 771 + * Return 0 on success or a negative errno. 772 + */ 773 + int lockd_nl_server_get_doit(struct sk_buff *skb, struct genl_info *info) 774 + { 775 + struct net *net = genl_info_net(info); 776 + struct lockd_net *ln = net_generic(net, lockd_net_id); 777 + void *hdr; 778 + int err; 779 + 780 + skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL); 781 + if (!skb) 782 + return -ENOMEM; 783 + 784 + hdr = genlmsg_iput(skb, info); 785 + if (!hdr) { 786 + err = -EMSGSIZE; 787 + goto err_free_msg; 788 + } 789 + 790 + err = nla_put_u32(skb, LOCKD_A_SERVER_GRACETIME, ln->gracetime) || 791 + nla_put_u16(skb, LOCKD_A_SERVER_TCP_PORT, ln->tcp_port) || 792 + nla_put_u16(skb, LOCKD_A_SERVER_UDP_PORT, ln->udp_port); 793 + if (err) 794 + goto err_free_msg; 795 + 796 + genlmsg_end(skb, hdr); 797 + 798 + return genlmsg_reply(skb, info); 799 + err_free_msg: 800 + nlmsg_free(skb); 801 + 802 + return err; 803 + }
+2 -1
fs/nfs/export.c
··· 154 154 EXPORT_OP_CLOSE_BEFORE_UNLINK | 155 155 EXPORT_OP_REMOTE_FS | 156 156 EXPORT_OP_NOATOMIC_ATTR | 157 - EXPORT_OP_FLUSH_ON_CLOSE, 157 + EXPORT_OP_FLUSH_ON_CLOSE | 158 + EXPORT_OP_NOLOCKS, 158 159 };
+5 -3
fs/nfs_common/nfsacl.c
··· 42 42 }; 43 43 44 44 struct nfsacl_simple_acl { 45 - struct posix_acl acl; 45 + struct posix_acl_hdr acl; 46 46 struct posix_acl_entry ace[4]; 47 47 }; 48 48 ··· 112 112 xdr_encode_word(buf, base, entries)) 113 113 return -EINVAL; 114 114 if (encode_entries && acl && acl->a_count == 3) { 115 - struct posix_acl *acl2 = &aclbuf.acl; 115 + struct posix_acl *acl2 = 116 + container_of(&aclbuf.acl, struct posix_acl, hdr); 116 117 117 118 /* Avoid the use of posix_acl_alloc(). nfsacl_encode() is 118 119 * invoked in contexts where a memory allocation failure is ··· 178 177 return false; 179 178 180 179 if (encode_entries && acl && acl->a_count == 3) { 181 - struct posix_acl *acl2 = &aclbuf.acl; 180 + struct posix_acl *acl2 = 181 + container_of(&aclbuf.acl, struct posix_acl, hdr); 182 182 183 183 /* Avoid the use of posix_acl_alloc(). nfsacl_encode() is 184 184 * invoked in contexts where a memory allocation failure is
+11 -1
fs/nfsd/Kconfig
··· 172 172 recoverydir, or spawn a process directly using a usermodehelper 173 173 upcall. 174 174 175 - These legacy client tracking methods have proven to be probelmatic 175 + These legacy client tracking methods have proven to be problematic 176 176 and will be removed in the future. Say Y here if you need support 177 177 for them in the interim. 178 + 179 + config NFSD_V4_DELEG_TIMESTAMPS 180 + bool "Support delegated timestamps" 181 + depends on NFSD_V4 182 + default n 183 + help 184 + NFSD implements delegated timestamps according to 185 + draft-ietf-nfsv4-delstid-08 "Extending the Opening of Files". This 186 + is currently an experimental feature and is therefore left disabled 187 + by default.
+67 -55
fs/nfsd/filecache.c
··· 319 319 mapping_tagged(mapping, PAGECACHE_TAG_WRITEBACK); 320 320 } 321 321 322 - 323 - static bool nfsd_file_lru_add(struct nfsd_file *nf) 322 + static void nfsd_file_lru_add(struct nfsd_file *nf) 324 323 { 325 - set_bit(NFSD_FILE_REFERENCED, &nf->nf_flags); 326 - if (list_lru_add_obj(&nfsd_file_lru, &nf->nf_lru)) { 324 + refcount_inc(&nf->nf_ref); 325 + if (list_lru_add_obj(&nfsd_file_lru, &nf->nf_lru)) 327 326 trace_nfsd_file_lru_add(nf); 328 - return true; 329 - } 330 - return false; 327 + else 328 + WARN_ON(1); 329 + nfsd_file_schedule_laundrette(); 331 330 } 332 331 333 332 static bool nfsd_file_lru_remove(struct nfsd_file *nf) ··· 362 363 363 364 if (test_bit(NFSD_FILE_GC, &nf->nf_flags) && 364 365 test_bit(NFSD_FILE_HASHED, &nf->nf_flags)) { 365 - /* 366 - * If this is the last reference (nf_ref == 1), then try to 367 - * transfer it to the LRU. 368 - */ 369 - if (refcount_dec_not_one(&nf->nf_ref)) 370 - return; 371 - 372 - /* Try to add it to the LRU. If that fails, decrement. */ 373 - if (nfsd_file_lru_add(nf)) { 374 - /* If it's still hashed, we're done */ 375 - if (test_bit(NFSD_FILE_HASHED, &nf->nf_flags)) { 376 - nfsd_file_schedule_laundrette(); 377 - return; 378 - } 379 - 380 - /* 381 - * We're racing with unhashing, so try to remove it from 382 - * the LRU. If removal fails, then someone else already 383 - * has our reference. 384 - */ 385 - if (!nfsd_file_lru_remove(nf)) 386 - return; 387 - } 366 + set_bit(NFSD_FILE_REFERENCED, &nf->nf_flags); 367 + set_bit(NFSD_FILE_RECENT, &nf->nf_flags); 388 368 } 369 + 389 370 if (refcount_dec_and_test(&nf->nf_ref)) 390 371 nfsd_file_free(nf); 391 372 } ··· 509 530 } 510 531 511 532 /* 512 - * Put the reference held on behalf of the LRU. If it wasn't the last 513 - * one, then just remove it from the LRU and ignore it. 533 + * Put the reference held on behalf of the LRU if it is the last 534 + * reference, else rotate. 514 535 */ 515 - if (!refcount_dec_and_test(&nf->nf_ref)) { 536 + if (!refcount_dec_if_one(&nf->nf_ref)) { 516 537 trace_nfsd_file_gc_in_use(nf); 517 - list_lru_isolate(lru, &nf->nf_lru); 518 - return LRU_REMOVED; 538 + return LRU_ROTATE; 519 539 } 520 540 521 541 /* Refcount went to zero. Unhash it and queue it to the dispose list */ ··· 526 548 return LRU_REMOVED; 527 549 } 528 550 551 + static enum lru_status 552 + nfsd_file_gc_cb(struct list_head *item, struct list_lru_one *lru, 553 + void *arg) 554 + { 555 + struct nfsd_file *nf = list_entry(item, struct nfsd_file, nf_lru); 556 + 557 + if (test_and_clear_bit(NFSD_FILE_RECENT, &nf->nf_flags)) { 558 + /* 559 + * "REFERENCED" really means "should be at the end of the 560 + * LRU. As we are putting it there we can clear the flag. 561 + */ 562 + clear_bit(NFSD_FILE_REFERENCED, &nf->nf_flags); 563 + trace_nfsd_file_gc_aged(nf); 564 + return LRU_ROTATE; 565 + } 566 + return nfsd_file_lru_cb(item, lru, arg); 567 + } 568 + 569 + /* If the shrinker runs between calls to list_lru_walk_node() in 570 + * nfsd_file_gc(), the "remaining" count will be wrong. This could 571 + * result in premature freeing of some files. This may not matter much 572 + * but is easy to fix with this spinlock which temporarily disables 573 + * the shrinker. 574 + */ 575 + static DEFINE_SPINLOCK(nfsd_gc_lock); 529 576 static void 530 577 nfsd_file_gc(void) 531 578 { 579 + unsigned long ret = 0; 532 580 LIST_HEAD(dispose); 533 - unsigned long ret; 581 + int nid; 534 582 535 - ret = list_lru_walk(&nfsd_file_lru, nfsd_file_lru_cb, 536 - &dispose, list_lru_count(&nfsd_file_lru)); 583 + spin_lock(&nfsd_gc_lock); 584 + for_each_node_state(nid, N_NORMAL_MEMORY) { 585 + unsigned long remaining = list_lru_count_node(&nfsd_file_lru, nid); 586 + 587 + while (remaining > 0) { 588 + unsigned long nr = min(remaining, NFSD_FILE_GC_BATCH); 589 + 590 + remaining -= nr; 591 + ret += list_lru_walk_node(&nfsd_file_lru, nid, nfsd_file_gc_cb, 592 + &dispose, &nr); 593 + if (nr) 594 + /* walk aborted early */ 595 + remaining = 0; 596 + } 597 + } 598 + spin_unlock(&nfsd_gc_lock); 537 599 trace_nfsd_file_gc_removed(ret, list_lru_count(&nfsd_file_lru)); 538 600 nfsd_file_dispose_list_delayed(&dispose); 539 601 } ··· 581 563 static void 582 564 nfsd_file_gc_worker(struct work_struct *work) 583 565 { 584 - nfsd_file_gc(); 585 566 if (list_lru_count(&nfsd_file_lru)) 586 - nfsd_file_schedule_laundrette(); 567 + nfsd_file_gc(); 568 + nfsd_file_schedule_laundrette(); 587 569 } 588 570 589 571 static unsigned long ··· 598 580 LIST_HEAD(dispose); 599 581 unsigned long ret; 600 582 583 + if (!spin_trylock(&nfsd_gc_lock)) 584 + return SHRINK_STOP; 585 + 601 586 ret = list_lru_shrink_walk(&nfsd_file_lru, sc, 602 587 nfsd_file_lru_cb, &dispose); 588 + spin_unlock(&nfsd_gc_lock); 603 589 trace_nfsd_file_shrinker_removed(ret, list_lru_count(&nfsd_file_lru)); 604 590 nfsd_file_dispose_list_delayed(&dispose); 605 591 return ret; ··· 708 686 void 709 687 nfsd_file_close_inode_sync(struct inode *inode) 710 688 { 711 - struct nfsd_file *nf; 712 689 LIST_HEAD(dispose); 713 690 714 691 trace_nfsd_file_close(inode); 715 692 716 693 nfsd_file_queue_for_close(inode, &dispose); 717 - while (!list_empty(&dispose)) { 718 - nf = list_first_entry(&dispose, struct nfsd_file, nf_gc); 719 - list_del_init(&nf->nf_gc); 720 - nfsd_file_free(nf); 721 - } 694 + nfsd_file_dispose_list(&dispose); 722 695 } 723 696 724 697 static int ··· 1075 1058 nf = nfsd_file_lookup_locked(net, current_cred(), inode, need, want_gc); 1076 1059 rcu_read_unlock(); 1077 1060 1078 - if (nf) { 1079 - /* 1080 - * If the nf is on the LRU then it holds an extra reference 1081 - * that must be put if it's removed. It had better not be 1082 - * the last one however, since we should hold another. 1083 - */ 1084 - if (nfsd_file_lru_remove(nf)) 1085 - refcount_dec(&nf->nf_ref); 1061 + if (nf) 1086 1062 goto wait_for_construction; 1087 - } 1088 1063 1089 1064 new = nfsd_file_alloc(net, inode, need, want_gc); 1090 1065 if (!new) { ··· 1170 1161 */ 1171 1162 if (status != nfs_ok || inode->i_nlink == 0) 1172 1163 nfsd_file_unhash(nf); 1164 + else if (want_gc) 1165 + nfsd_file_lru_add(nf); 1166 + 1173 1167 clear_and_wake_up_bit(NFSD_FILE_PENDING, &nf->nf_flags); 1174 1168 if (status == nfs_ok) 1175 1169 goto out;
+7
fs/nfsd/filecache.h
··· 4 4 #include <linux/fsnotify_backend.h> 5 5 6 6 /* 7 + * Limit the time that the list_lru_one lock is held during 8 + * an LRU scan. 9 + */ 10 + #define NFSD_FILE_GC_BATCH (16UL) 11 + 12 + /* 7 13 * This is the fsnotify_mark container that nfsd attaches to the files that it 8 14 * is holding open. Note that we have a separate refcount here aside from the 9 15 * one in the fsnotify_mark. We only want a single fsnotify_mark attached to ··· 44 38 #define NFSD_FILE_PENDING (1) 45 39 #define NFSD_FILE_REFERENCED (2) 46 40 #define NFSD_FILE_GC (3) 41 + #define NFSD_FILE_RECENT (4) 47 42 unsigned long nf_flags; 48 43 refcount_t nf_ref; 49 44 unsigned char nf_may;
+82 -64
fs/nfsd/nfs4callback.c
··· 46 46 47 47 #define NFSDDBG_FACILITY NFSDDBG_PROC 48 48 49 - static void nfsd4_mark_cb_fault(struct nfs4_client *clp); 50 - 51 49 #define NFSPROC4_CB_NULL 0 52 50 #define NFSPROC4_CB_COMPOUND 1 53 51 ··· 99 101 100 102 if (bitmap[0] & FATTR4_WORD0_CHANGE) 101 103 if (xdr_stream_decode_u64(xdr, &fattr->ncf_cb_change) < 0) 102 - return -NFSERR_BAD_XDR; 104 + return -EIO; 103 105 if (bitmap[0] & FATTR4_WORD0_SIZE) 104 106 if (xdr_stream_decode_u64(xdr, &fattr->ncf_cb_fsize) < 0) 105 - return -NFSERR_BAD_XDR; 107 + return -EIO; 106 108 if (bitmap[2] & FATTR4_WORD2_TIME_DELEG_ACCESS) { 107 109 fattr4_time_deleg_access access; 108 110 109 111 if (!xdrgen_decode_fattr4_time_deleg_access(xdr, &access)) 110 - return -NFSERR_BAD_XDR; 112 + return -EIO; 111 113 fattr->ncf_cb_atime.tv_sec = access.seconds; 112 114 fattr->ncf_cb_atime.tv_nsec = access.nseconds; 113 115 ··· 116 118 fattr4_time_deleg_modify modify; 117 119 118 120 if (!xdrgen_decode_fattr4_time_deleg_modify(xdr, &modify)) 119 - return -NFSERR_BAD_XDR; 121 + return -EIO; 120 122 fattr->ncf_cb_mtime.tv_sec = modify.seconds; 121 123 fattr->ncf_cb_mtime.tv_nsec = modify.nseconds; 122 124 ··· 680 682 if (unlikely(status || cb->cb_status)) 681 683 return status; 682 684 if (xdr_stream_decode_uint32_array(xdr, bitmap, 3) < 0) 683 - return -NFSERR_BAD_XDR; 685 + return -EIO; 684 686 if (xdr_stream_decode_u32(xdr, &attrlen) < 0) 685 - return -NFSERR_BAD_XDR; 687 + return -EIO; 686 688 maxlen = sizeof(ncf->ncf_cb_change) + sizeof(ncf->ncf_cb_fsize); 687 689 if (bitmap[2] != 0) 688 690 maxlen += (sizeof(ncf->ncf_cb_mtime.tv_sec) + 689 691 sizeof(ncf->ncf_cb_mtime.tv_nsec)) * 2; 690 692 if (attrlen > maxlen) 691 - return -NFSERR_BAD_XDR; 693 + return -EIO; 692 694 status = decode_cb_fattr4(xdr, bitmap, ncf); 693 695 return status; 694 696 } ··· 1062 1064 return queue_work(clp->cl_callback_wq, &cb->cb_work); 1063 1065 } 1064 1066 1067 + static void nfsd4_requeue_cb(struct rpc_task *task, struct nfsd4_callback *cb) 1068 + { 1069 + struct nfs4_client *clp = cb->cb_clp; 1070 + 1071 + if (!test_bit(NFSD4_CLIENT_CB_KILL, &clp->cl_flags)) { 1072 + trace_nfsd_cb_restart(clp, cb); 1073 + task->tk_status = 0; 1074 + set_bit(NFSD4_CALLBACK_REQUEUE, &cb->cb_flags); 1075 + } 1076 + } 1077 + 1065 1078 static void nfsd41_cb_inflight_begin(struct nfs4_client *clp) 1066 1079 { 1067 1080 atomic_inc(&clp->cl_cb_inflight); ··· 1310 1301 1311 1302 trace_nfsd_cb_destroy(clp, cb); 1312 1303 nfsd41_cb_release_slot(cb); 1304 + if (test_bit(NFSD4_CALLBACK_WAKE, &cb->cb_flags)) 1305 + clear_and_wake_up_bit(NFSD4_CALLBACK_RUNNING, &cb->cb_flags); 1306 + else 1307 + clear_bit(NFSD4_CALLBACK_RUNNING, &cb->cb_flags); 1308 + 1313 1309 if (cb->cb_ops && cb->cb_ops->release) 1314 1310 cb->cb_ops->release(cb); 1315 1311 nfsd41_cb_inflight_end(clp); ··· 1342 1328 rpc_call_start(task); 1343 1329 } 1344 1330 1331 + /* Returns true if CB_COMPOUND processing should continue */ 1345 1332 static bool nfsd4_cb_sequence_done(struct rpc_task *task, struct nfsd4_callback *cb) 1346 1333 { 1347 - struct nfs4_client *clp = cb->cb_clp; 1348 - struct nfsd4_session *session = clp->cl_cb_session; 1349 - bool ret = true; 1350 - 1351 - if (!clp->cl_minorversion) { 1352 - /* 1353 - * If the backchannel connection was shut down while this 1354 - * task was queued, we need to resubmit it after setting up 1355 - * a new backchannel connection. 1356 - * 1357 - * Note that if we lost our callback connection permanently 1358 - * the submission code will error out, so we don't need to 1359 - * handle that case here. 1360 - */ 1361 - if (RPC_SIGNALLED(task)) 1362 - goto need_restart; 1363 - 1364 - return true; 1365 - } 1334 + struct nfsd4_session *session = cb->cb_clp->cl_cb_session; 1335 + bool ret = false; 1366 1336 1367 1337 if (cb->cb_held_slot < 0) 1368 - goto need_restart; 1338 + goto requeue; 1369 1339 1370 1340 /* This is the operation status code for CB_SEQUENCE */ 1371 1341 trace_nfsd_cb_seq_status(task, cb); ··· 1363 1365 * (sequence ID, cached reply) MUST NOT change. 1364 1366 */ 1365 1367 ++session->se_cb_seq_nr[cb->cb_held_slot]; 1368 + ret = true; 1366 1369 break; 1367 1370 case -ESERVERFAULT: 1368 - ++session->se_cb_seq_nr[cb->cb_held_slot]; 1371 + /* 1372 + * Call succeeded, but the session, slot index, or slot 1373 + * sequence number in the response do not match the same 1374 + * in the server's call. The sequence information is thus 1375 + * untrustworthy. 1376 + */ 1369 1377 nfsd4_mark_cb_fault(cb->cb_clp); 1370 - ret = false; 1371 1378 break; 1372 1379 case 1: 1373 1380 /* ··· 1384 1381 fallthrough; 1385 1382 case -NFS4ERR_BADSESSION: 1386 1383 nfsd4_mark_cb_fault(cb->cb_clp); 1387 - ret = false; 1388 - goto need_restart; 1384 + goto requeue; 1389 1385 case -NFS4ERR_DELAY: 1390 1386 cb->cb_seq_status = 1; 1391 - if (!rpc_restart_call(task)) 1392 - goto out; 1393 - 1387 + if (RPC_SIGNALLED(task) || !rpc_restart_call(task)) 1388 + goto requeue; 1394 1389 rpc_delay(task, 2 * HZ); 1395 1390 return false; 1396 - case -NFS4ERR_BADSLOT: 1397 - goto retry_nowait; 1398 1391 case -NFS4ERR_SEQ_MISORDERED: 1399 - if (session->se_cb_seq_nr[cb->cb_held_slot] != 1) { 1400 - session->se_cb_seq_nr[cb->cb_held_slot] = 1; 1401 - goto retry_nowait; 1402 - } 1403 - break; 1392 + case -NFS4ERR_BADSLOT: 1393 + /* 1394 + * A SEQ_MISORDERED or BADSLOT error means that the client and 1395 + * server are out of sync as to the backchannel parameters. Mark 1396 + * the backchannel faulty and restart the RPC, but leak the slot 1397 + * so that it's no longer used. 1398 + */ 1399 + nfsd4_mark_cb_fault(cb->cb_clp); 1400 + cb->cb_held_slot = -1; 1401 + goto retry_nowait; 1404 1402 default: 1405 1403 nfsd4_mark_cb_fault(cb->cb_clp); 1406 1404 } 1407 1405 trace_nfsd_cb_free_slot(task, cb); 1408 1406 nfsd41_cb_release_slot(cb); 1409 - 1410 - if (RPC_SIGNALLED(task)) 1411 - goto need_restart; 1412 - out: 1413 1407 return ret; 1414 1408 retry_nowait: 1415 - if (rpc_restart_call_prepare(task)) 1416 - ret = false; 1417 - goto out; 1418 - need_restart: 1419 - if (!test_bit(NFSD4_CLIENT_CB_KILL, &clp->cl_flags)) { 1420 - trace_nfsd_cb_restart(clp, cb); 1421 - task->tk_status = 0; 1422 - cb->cb_need_restart = true; 1409 + /* 1410 + * RPC_SIGNALLED() means that the rpc_client is being torn down and 1411 + * (possibly) recreated. Requeue the call in that case. 1412 + */ 1413 + if (!RPC_SIGNALLED(task)) { 1414 + if (rpc_restart_call_prepare(task)) 1415 + return false; 1423 1416 } 1417 + requeue: 1418 + nfsd41_cb_release_slot(cb); 1419 + nfsd4_requeue_cb(task, cb); 1424 1420 return false; 1425 1421 } 1426 1422 ··· 1430 1428 1431 1429 trace_nfsd_cb_rpc_done(clp); 1432 1430 1433 - if (!nfsd4_cb_sequence_done(task, cb)) 1431 + if (!clp->cl_minorversion) { 1432 + /* 1433 + * If the backchannel connection was shut down while this 1434 + * task was queued, we need to resubmit it after setting up 1435 + * a new backchannel connection. 1436 + * 1437 + * Note that if we lost our callback connection permanently 1438 + * the submission code will error out, so we don't need to 1439 + * handle that case here. 1440 + */ 1441 + if (RPC_SIGNALLED(task)) 1442 + nfsd4_requeue_cb(task, cb); 1443 + } else if (!nfsd4_cb_sequence_done(task, cb)) { 1434 1444 return; 1445 + } 1435 1446 1436 1447 if (cb->cb_status) { 1437 1448 WARN_ONCE(task->tk_status, ··· 1477 1462 1478 1463 trace_nfsd_cb_rpc_release(cb->cb_clp); 1479 1464 1480 - if (cb->cb_need_restart) 1465 + if (test_bit(NFSD4_CALLBACK_REQUEUE, &cb->cb_flags)) 1481 1466 nfsd4_queue_cb(cb); 1482 1467 else 1483 1468 nfsd41_destroy_cb(cb); ··· 1590 1575 container_of(work, struct nfsd4_callback, cb_work); 1591 1576 struct nfs4_client *clp = cb->cb_clp; 1592 1577 struct rpc_clnt *clnt; 1593 - int flags; 1578 + int flags, ret; 1594 1579 1595 1580 trace_nfsd_cb_start(clp); 1596 1581 ··· 1616 1601 return; 1617 1602 } 1618 1603 1619 - if (cb->cb_need_restart) { 1620 - cb->cb_need_restart = false; 1621 - } else { 1604 + if (!test_and_clear_bit(NFSD4_CALLBACK_REQUEUE, &cb->cb_flags)) { 1622 1605 if (cb->cb_ops && cb->cb_ops->prepare) 1623 1606 cb->cb_ops->prepare(cb); 1624 1607 } 1608 + 1625 1609 cb->cb_msg.rpc_cred = clp->cl_cb_cred; 1626 1610 flags = clp->cl_minorversion ? RPC_TASK_NOCONNECT : RPC_TASK_SOFTCONN; 1627 - rpc_call_async(clnt, &cb->cb_msg, RPC_TASK_SOFT | flags, 1628 - cb->cb_ops ? &nfsd4_cb_ops : &nfsd4_cb_probe_ops, cb); 1611 + ret = rpc_call_async(clnt, &cb->cb_msg, RPC_TASK_SOFT | flags, 1612 + cb->cb_ops ? &nfsd4_cb_ops : &nfsd4_cb_probe_ops, cb); 1613 + if (ret != 0) { 1614 + set_bit(NFSD4_CALLBACK_REQUEUE, &cb->cb_flags); 1615 + nfsd4_queue_cb(cb); 1616 + } 1629 1617 } 1630 1618 1631 1619 void nfsd4_init_cb(struct nfsd4_callback *cb, struct nfs4_client *clp, ··· 1638 1620 cb->cb_msg.rpc_proc = &nfs4_cb_procedures[op]; 1639 1621 cb->cb_msg.rpc_argp = cb; 1640 1622 cb->cb_msg.rpc_resp = cb; 1623 + cb->cb_flags = 0; 1641 1624 cb->cb_ops = ops; 1642 1625 INIT_WORK(&cb->cb_work, nfsd4_run_cb_work); 1643 1626 cb->cb_status = 0; 1644 - cb->cb_need_restart = false; 1645 1627 cb->cb_held_slot = -1; 1646 1628 } 1647 1629
+4 -3
fs/nfsd/nfs4layouts.c
··· 344 344 atomic_inc(&ls->ls_stid.sc_file->fi_lo_recalls); 345 345 trace_nfsd_layout_recall(&ls->ls_stid.sc_stateid); 346 346 347 - refcount_inc(&ls->ls_stid.sc_count); 348 - nfsd4_run_cb(&ls->ls_recall); 349 - 347 + if (!test_and_set_bit(NFSD4_CALLBACK_RUNNING, &ls->ls_recall.cb_flags)) { 348 + refcount_inc(&ls->ls_stid.sc_count); 349 + nfsd4_run_cb(&ls->ls_recall); 350 + } 350 351 out_unlock: 351 352 spin_unlock(&ls->ls_lock); 352 353 }
+1 -1
fs/nfsd/nfs4proc.c
··· 1847 1847 NFSPROC4_CLNT_CB_OFFLOAD); 1848 1848 trace_nfsd_cb_offload(copy->cp_clp, &cbo->co_res.cb_stateid, 1849 1849 &cbo->co_fh, copy->cp_count, copy->nfserr); 1850 - nfsd4_run_cb(&cbo->co_cb); 1850 + nfsd4_try_run_cb(&cbo->co_cb); 1851 1851 } 1852 1852 1853 1853 /**
+73 -41
fs/nfsd/nfs4state.c
··· 946 946 spin_lock_init(&stid->sc_lock); 947 947 INIT_LIST_HEAD(&stid->sc_cp_list); 948 948 949 - /* 950 - * It shouldn't be a problem to reuse an opaque stateid value. 951 - * I don't think it is for 4.1. But with 4.0 I worry that, for 952 - * example, a stray write retransmission could be accepted by 953 - * the server when it should have been rejected. Therefore, 954 - * adopt a trick from the sctp code to attempt to maximize the 955 - * amount of time until an id is reused, by ensuring they always 956 - * "increase" (mod INT_MAX): 957 - */ 958 949 return stid; 959 950 out_free: 960 951 kmem_cache_free(slab, stid); ··· 1041 1050 return openlockstateid(stid); 1042 1051 } 1043 1052 1053 + /* 1054 + * As the sc_free callback of deleg, this may be called by nfs4_put_stid 1055 + * in nfsd_break_one_deleg. 1056 + * Considering nfsd_break_one_deleg is called with the flc->flc_lock held, 1057 + * this function mustn't ever sleep. 1058 + */ 1044 1059 static void nfs4_free_deleg(struct nfs4_stid *stid) 1045 1060 { 1046 1061 struct nfs4_delegation *dp = delegstateid(stid); ··· 1375 1378 struct nfs4_client *clp = dp->dl_stid.sc_client; 1376 1379 1377 1380 WARN_ON(!list_empty(&dp->dl_recall_lru)); 1378 - WARN_ON_ONCE(!(dp->dl_stid.sc_status & 1381 + WARN_ON_ONCE(dp->dl_stid.sc_client->cl_minorversion > 0 && 1382 + !(dp->dl_stid.sc_status & 1379 1383 (SC_STATUS_REVOKED | SC_STATUS_ADMIN_REVOKED))); 1380 1384 1381 1385 trace_nfsd_stid_revoke(&dp->dl_stid); ··· 3166 3168 { 3167 3169 struct nfs4_client *clp = cb->cb_clp; 3168 3170 3169 - clear_bit(NFSD4_CLIENT_CB_RECALL_ANY, &clp->cl_flags); 3170 3171 drop_client(clp); 3171 3172 } 3172 3173 ··· 3196 3199 struct nfs4_delegation *dp = 3197 3200 container_of(ncf, struct nfs4_delegation, dl_cb_fattr); 3198 3201 3199 - clear_and_wake_up_bit(CB_GETATTR_BUSY, &ncf->ncf_cb_flags); 3200 3202 nfs4_put_stid(&dp->dl_stid); 3201 3203 } 3202 3204 ··· 3216 3220 struct nfs4_delegation *dp = 3217 3221 container_of(ncf, struct nfs4_delegation, dl_cb_fattr); 3218 3222 3219 - if (test_and_set_bit(CB_GETATTR_BUSY, &ncf->ncf_cb_flags)) 3223 + if (test_and_set_bit(NFSD4_CALLBACK_RUNNING, &ncf->ncf_getattr.cb_flags)) 3220 3224 return; 3225 + 3221 3226 /* set to proper status when nfsd4_cb_getattr_done runs */ 3222 3227 ncf->ncf_cb_status = NFS4ERR_IO; 3228 + 3229 + /* ensure that wake_bit is done when RUNNING is cleared */ 3230 + set_bit(NFSD4_CALLBACK_WAKE, &ncf->ncf_getattr.cb_flags); 3223 3231 3224 3232 refcount_inc(&dp->dl_stid.sc_count); 3225 3233 nfsd4_run_cb(&ncf->ncf_getattr); ··· 4815 4815 static unsigned long 4816 4816 nfsd4_state_shrinker_count(struct shrinker *shrink, struct shrink_control *sc) 4817 4817 { 4818 - int count; 4819 4818 struct nfsd_net *nn = shrink->private_data; 4819 + long count; 4820 4820 4821 4821 count = atomic_read(&nn->nfsd_courtesy_clients); 4822 4822 if (!count) ··· 5414 5414 5415 5415 static void nfsd_break_one_deleg(struct nfs4_delegation *dp) 5416 5416 { 5417 + bool queued; 5418 + 5419 + if (test_and_set_bit(NFSD4_CALLBACK_RUNNING, &dp->dl_recall.cb_flags)) 5420 + return; 5421 + 5417 5422 /* 5418 5423 * We're assuming the state code never drops its reference 5419 5424 * without first removing the lease. Since we're in this lease ··· 5427 5422 * we know it's safe to take a reference. 5428 5423 */ 5429 5424 refcount_inc(&dp->dl_stid.sc_count); 5430 - WARN_ON_ONCE(!nfsd4_run_cb(&dp->dl_recall)); 5425 + queued = nfsd4_run_cb(&dp->dl_recall); 5426 + WARN_ON_ONCE(!queued); 5427 + if (!queued) 5428 + nfs4_put_stid(&dp->dl_stid); 5431 5429 } 5432 5430 5433 5431 /* Called from break_lease() with flc_lock held. */ ··· 5956 5948 return 0; 5957 5949 } 5958 5950 5951 + #ifdef CONFIG_NFSD_V4_DELEG_TIMESTAMPS 5952 + static bool nfsd4_want_deleg_timestamps(const struct nfsd4_open *open) 5953 + { 5954 + return open->op_deleg_want & OPEN4_SHARE_ACCESS_WANT_DELEG_TIMESTAMPS; 5955 + } 5956 + #else /* CONFIG_NFSD_V4_DELEG_TIMESTAMPS */ 5957 + static bool nfsd4_want_deleg_timestamps(const struct nfsd4_open *open) 5958 + { 5959 + return false; 5960 + } 5961 + #endif /* CONFIG NFSD_V4_DELEG_TIMESTAMPS */ 5962 + 5959 5963 static struct nfs4_delegation * 5960 5964 nfs4_set_delegation(struct nfsd4_open *open, struct nfs4_ol_stateid *stp, 5961 5965 struct svc_fh *parent) 5962 5966 { 5963 - bool deleg_ts = open->op_deleg_want & OPEN4_SHARE_ACCESS_WANT_DELEG_TIMESTAMPS; 5967 + bool deleg_ts = nfsd4_want_deleg_timestamps(open); 5964 5968 struct nfs4_client *clp = stp->st_stid.sc_client; 5965 5969 struct nfs4_file *fp = stp->st_stid.sc_file; 5966 5970 struct nfs4_clnt_odstate *odstate = stp->st_clnt_odstate; ··· 6018 5998 6019 5999 if (!nf) 6020 6000 return ERR_PTR(-EAGAIN); 6001 + 6002 + /* 6003 + * File delegations and associated locks cannot be recovered if the 6004 + * export is from an NFS proxy server. 6005 + */ 6006 + if (exportfs_cannot_lock(nf->nf_file->f_path.mnt->mnt_sb->s_export_op)) { 6007 + nfsd_file_put(nf); 6008 + return ERR_PTR(-EOPNOTSUPP); 6009 + } 6021 6010 6022 6011 spin_lock(&state_lock); 6023 6012 spin_lock(&fp->fi_lock); ··· 6180 6151 nfs4_open_delegation(struct nfsd4_open *open, struct nfs4_ol_stateid *stp, 6181 6152 struct svc_fh *currentfh) 6182 6153 { 6183 - bool deleg_ts = open->op_deleg_want & OPEN4_SHARE_ACCESS_WANT_DELEG_TIMESTAMPS; 6184 6154 struct nfs4_openowner *oo = openowner(stp->st_stateowner); 6155 + bool deleg_ts = nfsd4_want_deleg_timestamps(open); 6185 6156 struct nfs4_client *clp = stp->st_stid.sc_client; 6186 6157 struct svc_fh *parent = NULL; 6187 6158 struct nfs4_delegation *dp; ··· 6884 6855 { 6885 6856 struct list_head *pos, *next; 6886 6857 struct nfs4_client *clp; 6887 - LIST_HEAD(cblist); 6888 6858 6889 6859 spin_lock(&nn->client_lock); 6890 6860 list_for_each_safe(pos, next, &nn->client_lru) { 6891 6861 clp = list_entry(pos, struct nfs4_client, cl_lru); 6892 - if (clp->cl_state != NFSD4_ACTIVE || 6893 - list_empty(&clp->cl_delegations) || 6894 - atomic_read(&clp->cl_delegs_in_recall) || 6895 - test_bit(NFSD4_CLIENT_CB_RECALL_ANY, &clp->cl_flags) || 6896 - (ktime_get_boottime_seconds() - 6897 - clp->cl_ra_time < 5)) { 6862 + 6863 + if (clp->cl_state != NFSD4_ACTIVE) 6898 6864 continue; 6899 - } 6900 - list_add(&clp->cl_ra_cblist, &cblist); 6865 + if (list_empty(&clp->cl_delegations)) 6866 + continue; 6867 + if (atomic_read(&clp->cl_delegs_in_recall)) 6868 + continue; 6869 + if (test_and_set_bit(NFSD4_CALLBACK_RUNNING, &clp->cl_ra->ra_cb.cb_flags)) 6870 + continue; 6871 + if (ktime_get_boottime_seconds() - clp->cl_ra_time < 5) 6872 + continue; 6873 + if (clp->cl_cb_state != NFSD4_CB_UP) 6874 + continue; 6901 6875 6902 6876 /* release in nfsd4_cb_recall_any_release */ 6903 6877 kref_get(&clp->cl_nfsdfs.cl_ref); 6904 - set_bit(NFSD4_CLIENT_CB_RECALL_ANY, &clp->cl_flags); 6905 6878 clp->cl_ra_time = ktime_get_boottime_seconds(); 6906 - } 6907 - spin_unlock(&nn->client_lock); 6908 - 6909 - while (!list_empty(&cblist)) { 6910 - clp = list_first_entry(&cblist, struct nfs4_client, 6911 - cl_ra_cblist); 6912 - list_del_init(&clp->cl_ra_cblist); 6913 6879 clp->cl_ra->ra_keep = 0; 6914 6880 clp->cl_ra->ra_bmval[0] = BIT(RCA4_TYPE_MASK_RDATA_DLG) | 6915 6881 BIT(RCA4_TYPE_MASK_WDATA_DLG); 6916 6882 trace_nfsd_cb_recall_any(clp->cl_ra); 6917 6883 nfsd4_run_cb(&clp->cl_ra->ra_cb); 6918 6884 } 6885 + spin_unlock(&nn->client_lock); 6919 6886 } 6920 6887 6921 6888 static void ··· 7076 7051 */ 7077 7052 statusmask |= SC_STATUS_REVOKED; 7078 7053 7079 - statusmask |= SC_STATUS_ADMIN_REVOKED; 7054 + statusmask |= SC_STATUS_ADMIN_REVOKED | SC_STATUS_FREEABLE; 7080 7055 7081 7056 if (ZERO_STATEID(stateid) || ONE_STATEID(stateid) || 7082 7057 CLOSE_STATEID(stateid)) ··· 7731 7706 if ((status = fh_verify(rqstp, &cstate->current_fh, S_IFREG, 0))) 7732 7707 return status; 7733 7708 7734 - status = nfsd4_lookup_stateid(cstate, stateid, SC_TYPE_DELEG, 7735 - SC_STATUS_REVOKED | SC_STATUS_FREEABLE, 7736 - &s, nn); 7709 + status = nfsd4_lookup_stateid(cstate, stateid, SC_TYPE_DELEG, SC_STATUS_REVOKED, &s, nn); 7737 7710 if (status) 7738 7711 goto out; 7739 7712 dp = delegstateid(s); ··· 7839 7816 7840 7817 if (queue) { 7841 7818 trace_nfsd_cb_notify_lock(lo, nbl); 7842 - nfsd4_run_cb(&nbl->nbl_cb); 7819 + nfsd4_try_run_cb(&nbl->nbl_cb); 7843 7820 } 7844 7821 } 7845 7822 ··· 8157 8134 status = fh_verify(rqstp, &cstate->current_fh, S_IFREG, 0); 8158 8135 if (status != nfs_ok) 8159 8136 return status; 8137 + if (exportfs_cannot_lock(cstate->current_fh.fh_dentry->d_sb->s_export_op)) { 8138 + status = nfserr_notsupp; 8139 + goto out; 8140 + } 8160 8141 8161 8142 if (lock->lk_is_new) { 8162 8143 if (nfsd4_has_session(cstate)) ··· 8500 8473 status = nfserr_lock_range; 8501 8474 goto put_stateid; 8502 8475 } 8476 + if (exportfs_cannot_lock(nf->nf_file->f_path.mnt->mnt_sb->s_export_op)) { 8477 + status = nfserr_notsupp; 8478 + goto put_file; 8479 + } 8480 + 8503 8481 file_lock = locks_alloc_lock(); 8504 8482 if (!file_lock) { 8505 8483 dprintk("NFSD: %s: unable to allocate lock!\n", __func__); ··· 9214 9182 nfs4_cb_getattr(&dp->dl_cb_fattr); 9215 9183 spin_unlock(&ctx->flc_lock); 9216 9184 9217 - wait_on_bit_timeout(&ncf->ncf_cb_flags, CB_GETATTR_BUSY, 9218 - TASK_INTERRUPTIBLE, NFSD_CB_GETATTR_TIMEOUT); 9185 + wait_on_bit_timeout(&ncf->ncf_getattr.cb_flags, NFSD4_CALLBACK_RUNNING, 9186 + TASK_UNINTERRUPTIBLE, NFSD_CB_GETATTR_TIMEOUT); 9219 9187 if (ncf->ncf_cb_status) { 9220 9188 /* Recall delegation only if client didn't respond */ 9221 9189 status = nfserrno(nfsd_open_break_lease(inode, NFSD_MAY_READ));
+29 -24
fs/nfsd/nfsctl.c
··· 1917 1917 struct svc_serv *serv; 1918 1918 LIST_HEAD(permsocks); 1919 1919 struct nfsd_net *nn; 1920 + bool delete = false; 1920 1921 int err, rem; 1921 1922 1922 1923 mutex_lock(&nfsd_mutex); ··· 1978 1977 } 1979 1978 } 1980 1979 1981 - /* For now, no removing old sockets while server is running */ 1982 - if (serv->sv_nrthreads && !list_empty(&permsocks)) { 1980 + /* 1981 + * If there are listener transports remaining on the permsocks list, 1982 + * it means we were asked to remove a listener. 1983 + */ 1984 + if (!list_empty(&permsocks)) { 1983 1985 list_splice_init(&permsocks, &serv->sv_permsocks); 1984 - spin_unlock_bh(&serv->sv_lock); 1986 + delete = true; 1987 + } 1988 + spin_unlock_bh(&serv->sv_lock); 1989 + 1990 + /* Do not remove listeners while there are active threads. */ 1991 + if (serv->sv_nrthreads) { 1985 1992 err = -EBUSY; 1986 1993 goto out_unlock_mtx; 1987 1994 } 1988 1995 1989 - /* Close the remaining sockets on the permsocks list */ 1990 - while (!list_empty(&permsocks)) { 1991 - xprt = list_first_entry(&permsocks, struct svc_xprt, xpt_list); 1992 - list_move(&xprt->xpt_list, &serv->sv_permsocks); 1993 - 1994 - /* 1995 - * Newly-created sockets are born with the BUSY bit set. Clear 1996 - * it if there are no threads, since nothing can pick it up 1997 - * in that case. 1998 - */ 1999 - if (!serv->sv_nrthreads) 2000 - clear_bit(XPT_BUSY, &xprt->xpt_flags); 2001 - 2002 - set_bit(XPT_CLOSE, &xprt->xpt_flags); 2003 - spin_unlock_bh(&serv->sv_lock); 2004 - svc_xprt_close(xprt); 2005 - spin_lock_bh(&serv->sv_lock); 2006 - } 2007 - 2008 - spin_unlock_bh(&serv->sv_lock); 1996 + /* 1997 + * Since we can't delete an arbitrary llist entry, destroy the 1998 + * remaining listeners and recreate the list. 1999 + */ 2000 + if (delete) 2001 + svc_xprt_destroy_all(serv, net); 2009 2002 2010 2003 /* walk list of addrs again, open any that still don't exist */ 2011 2004 nlmsg_for_each_attr(attr, info->nlhdr, GENL_HDRLEN, rem) { ··· 2026 2031 2027 2032 xprt = svc_find_listener(serv, xcl_name, net, sa); 2028 2033 if (xprt) { 2034 + if (delete) 2035 + WARN_ONCE(1, "Transport type=%s already exists\n", 2036 + xcl_name); 2029 2037 svc_xprt_put(xprt); 2030 2038 continue; 2031 2039 } ··· 2202 2204 NFSD_STATS_COUNTERS_NUM); 2203 2205 if (retval) 2204 2206 goto out_repcache_error; 2207 + 2205 2208 memset(&nn->nfsd_svcstats, 0, sizeof(nn->nfsd_svcstats)); 2206 2209 nn->nfsd_svcstats.program = &nfsd_programs[0]; 2210 + if (!nfsd_proc_stat_init(net)) { 2211 + retval = -ENOMEM; 2212 + goto out_proc_error; 2213 + } 2214 + 2207 2215 for (i = 0; i < sizeof(nn->nfsd_versions); i++) 2208 2216 nn->nfsd_versions[i] = nfsd_support_version(i); 2209 2217 for (i = 0; i < sizeof(nn->nfsd4_minorversions); i++) ··· 2219 2215 nfsd4_init_leases_net(nn); 2220 2216 get_random_bytes(&nn->siphash_key, sizeof(nn->siphash_key)); 2221 2217 seqlock_init(&nn->writeverf_lock); 2222 - nfsd_proc_stat_init(net); 2223 2218 #if IS_ENABLED(CONFIG_NFS_LOCALIO) 2224 2219 spin_lock_init(&nn->local_clients_lock); 2225 2220 INIT_LIST_HEAD(&nn->local_clients); 2226 2221 #endif 2227 2222 return 0; 2228 2223 2224 + out_proc_error: 2225 + percpu_counter_destroy_many(nn->counter, NFSD_STATS_COUNTERS_NUM); 2229 2226 out_repcache_error: 2230 2227 nfsd_idmap_shutdown(net); 2231 2228 out_idmap_error:
+12 -8
fs/nfsd/state.h
··· 67 67 struct nfsd4_callback { 68 68 struct nfs4_client *cb_clp; 69 69 struct rpc_message cb_msg; 70 + #define NFSD4_CALLBACK_RUNNING (0) 71 + #define NFSD4_CALLBACK_WAKE (1) 72 + #define NFSD4_CALLBACK_REQUEUE (2) 73 + unsigned long cb_flags; 70 74 const struct nfsd4_callback_ops *cb_ops; 71 75 struct work_struct cb_work; 72 76 int cb_seq_status; 73 77 int cb_status; 74 78 int cb_held_slot; 75 - bool cb_need_restart; 76 79 }; 77 80 78 81 struct nfsd4_callback_ops { ··· 165 162 struct timespec64 ncf_cb_mtime; 166 163 struct timespec64 ncf_cb_atime; 167 164 168 - unsigned long ncf_cb_flags; 169 165 bool ncf_file_modified; 170 166 u64 ncf_initial_cinfo; 171 167 u64 ncf_cur_fsize; 172 168 }; 173 - 174 - /* bits for ncf_cb_flags */ 175 - #define CB_GETATTR_BUSY 0 176 169 177 170 /* 178 171 * Represents a delegation stateid. The nfs4_client holds references to these ··· 197 198 struct list_head dl_perclnt; 198 199 struct list_head dl_recall_lru; /* delegation recalled */ 199 200 struct nfs4_clnt_odstate *dl_clnt_odstate; 200 - u32 dl_type; 201 201 time64_t dl_time; 202 + u32 dl_type; 202 203 /* For recall: */ 203 204 int dl_retries; 204 205 struct nfsd4_callback dl_recall; ··· 451 452 #define NFSD4_CLIENT_UPCALL_LOCK (5) /* upcall serialization */ 452 453 #define NFSD4_CLIENT_CB_FLAG_MASK (1 << NFSD4_CLIENT_CB_UPDATE | \ 453 454 1 << NFSD4_CLIENT_CB_KILL) 454 - #define NFSD4_CLIENT_CB_RECALL_ANY (6) 455 455 unsigned long cl_flags; 456 456 457 457 struct workqueue_struct *cl_callback_wq; ··· 496 498 497 499 struct nfsd4_cb_recall_any *cl_ra; 498 500 time64_t cl_ra_time; 499 - struct list_head cl_ra_cblist; 500 501 }; 501 502 502 503 /* struct nfs4_client_reset ··· 777 780 extern void nfsd4_init_cb(struct nfsd4_callback *cb, struct nfs4_client *clp, 778 781 const struct nfsd4_callback_ops *ops, enum nfsd4_cb_op op); 779 782 extern bool nfsd4_run_cb(struct nfsd4_callback *cb); 783 + 784 + static inline void nfsd4_try_run_cb(struct nfsd4_callback *cb) 785 + { 786 + if (!test_and_set_bit(NFSD4_CALLBACK_RUNNING, &cb->cb_flags)) 787 + WARN_ON_ONCE(!nfsd4_run_cb(cb)); 788 + } 789 + 780 790 extern void nfsd4_shutdown_callback(struct nfs4_client *); 781 791 extern void nfsd4_shutdown_copy(struct nfs4_client *clp); 782 792 void nfsd4_async_copy_reaper(struct nfsd_net *nn);
+2 -2
fs/nfsd/stats.c
··· 73 73 74 74 DEFINE_PROC_SHOW_ATTRIBUTE(nfsd); 75 75 76 - void nfsd_proc_stat_init(struct net *net) 76 + struct proc_dir_entry *nfsd_proc_stat_init(struct net *net) 77 77 { 78 78 struct nfsd_net *nn = net_generic(net, nfsd_net_id); 79 79 80 - svc_proc_register(net, &nn->nfsd_svcstats, &nfsd_proc_ops); 80 + return svc_proc_register(net, &nn->nfsd_svcstats, &nfsd_proc_ops); 81 81 } 82 82 83 83 void nfsd_proc_stat_shutdown(struct net *net)
+1 -1
fs/nfsd/stats.h
··· 10 10 #include <uapi/linux/nfsd/stats.h> 11 11 #include <linux/percpu_counter.h> 12 12 13 - void nfsd_proc_stat_init(struct net *net); 13 + struct proc_dir_entry *nfsd_proc_stat_init(struct net *net); 14 14 void nfsd_proc_stat_shutdown(struct net *net); 15 15 16 16 static inline void nfsd_stats_rc_hits_inc(struct nfsd_net *nn)
+19 -5
fs/nfsd/trace.h
··· 803 803 DEFINE_CS_SLOT_EVENT(slot_seqid_conf); 804 804 DEFINE_CS_SLOT_EVENT(slot_seqid_unconf); 805 805 806 + #define show_nfs_slot_flags(val) \ 807 + __print_flags(val, "|", \ 808 + { NFSD4_SLOT_INUSE, "INUSE" }, \ 809 + { NFSD4_SLOT_CACHETHIS, "CACHETHIS" }, \ 810 + { NFSD4_SLOT_INITIALIZED, "INITIALIZED" }, \ 811 + { NFSD4_SLOT_CACHED, "CACHED" }, \ 812 + { NFSD4_SLOT_REUSED, "REUSED" }) 813 + 806 814 TRACE_EVENT(nfsd_slot_seqid_sequence, 807 815 TP_PROTO( 808 816 const struct nfs4_client *clp, ··· 821 813 TP_STRUCT__entry( 822 814 __field(u32, seqid) 823 815 __field(u32, slot_seqid) 816 + __field(u32, slot_index) 817 + __field(unsigned long, slot_flags) 824 818 __field(u32, cl_boot) 825 819 __field(u32, cl_id) 826 820 __sockaddr(addr, clp->cl_cb_conn.cb_addrlen) 827 - __field(bool, in_use) 828 821 ), 829 822 TP_fast_assign( 830 823 __entry->cl_boot = clp->cl_clientid.cl_boot; ··· 834 825 clp->cl_cb_conn.cb_addrlen); 835 826 __entry->seqid = seq->seqid; 836 827 __entry->slot_seqid = slot->sl_seqid; 828 + __entry->slot_index = seq->slotid; 829 + __entry->slot_flags = slot->sl_flags; 837 830 ), 838 - TP_printk("addr=%pISpc client %08x:%08x seqid=%u slot_seqid=%u (%sin use)", 831 + TP_printk("addr=%pISpc client %08x:%08x idx=%u seqid=%u slot_seqid=%u flags=%s", 839 832 __get_sockaddr(addr), __entry->cl_boot, __entry->cl_id, 840 - __entry->seqid, __entry->slot_seqid, 841 - __entry->in_use ? "" : "not " 833 + __entry->slot_index, __entry->seqid, __entry->slot_seqid, 834 + show_nfs_slot_flags(__entry->slot_flags) 842 835 ) 843 836 ); 844 837 ··· 1050 1039 { 1 << NFSD_FILE_HASHED, "HASHED" }, \ 1051 1040 { 1 << NFSD_FILE_PENDING, "PENDING" }, \ 1052 1041 { 1 << NFSD_FILE_REFERENCED, "REFERENCED" }, \ 1042 + { 1 << NFSD_FILE_RECENT, "RECENT" }, \ 1053 1043 { 1 << NFSD_FILE_GC, "GC" }) 1054 1044 1055 1045 DECLARE_EVENT_CLASS(nfsd_file_class, ··· 1329 1317 DEFINE_NFSD_FILE_GC_EVENT(nfsd_file_gc_in_use); 1330 1318 DEFINE_NFSD_FILE_GC_EVENT(nfsd_file_gc_writeback); 1331 1319 DEFINE_NFSD_FILE_GC_EVENT(nfsd_file_gc_referenced); 1320 + DEFINE_NFSD_FILE_GC_EVENT(nfsd_file_gc_aged); 1332 1321 DEFINE_NFSD_FILE_GC_EVENT(nfsd_file_gc_disposed); 1333 1322 1334 1323 DECLARE_EVENT_CLASS(nfsd_file_lruwalk_class, ··· 1359 1346 TP_ARGS(removed, remaining)) 1360 1347 1361 1348 DEFINE_NFSD_FILE_LRUWALK_EVENT(nfsd_file_gc_removed); 1349 + DEFINE_NFSD_FILE_LRUWALK_EVENT(nfsd_file_gc_recent); 1362 1350 DEFINE_NFSD_FILE_LRUWALK_EVENT(nfsd_file_shrinker_removed); 1363 1351 1364 1352 TRACE_EVENT(nfsd_file_close, ··· 1616 1602 __entry->cl_id = clp->cl_clientid.cl_id; 1617 1603 __entry->cb = cb; 1618 1604 __entry->opcode = cb->cb_ops ? cb->cb_ops->opcode : _CB_NULL; 1619 - __entry->need_restart = cb->cb_need_restart; 1605 + __entry->need_restart = test_bit(NFSD4_CALLBACK_REQUEUE, &cb->cb_flags); 1620 1606 __assign_sockaddr(addr, &clp->cl_cb_conn.cb_addr, 1621 1607 clp->cl_cb_conn.cb_addrlen) 1622 1608 ),
+79 -27
fs/nfsd/vfs.c
··· 71 71 { nfserr_acces, -EACCES }, 72 72 { nfserr_exist, -EEXIST }, 73 73 { nfserr_xdev, -EXDEV }, 74 - { nfserr_mlink, -EMLINK }, 75 74 { nfserr_nodev, -ENODEV }, 76 75 { nfserr_notdir, -ENOTDIR }, 77 76 { nfserr_isdir, -EISDIR }, ··· 1686 1687 return err; 1687 1688 } 1688 1689 1689 - /* 1690 - * Create a hardlink 1691 - * N.B. After this call _both_ ffhp and tfhp need an fh_put 1690 + /** 1691 + * nfsd_link - create a link 1692 + * @rqstp: RPC transaction context 1693 + * @ffhp: the file handle of the directory where the new link is to be created 1694 + * @name: the filename of the new link 1695 + * @len: the length of @name in octets 1696 + * @tfhp: the file handle of an existing file object 1697 + * 1698 + * After this call _both_ ffhp and tfhp need an fh_put. 1699 + * 1700 + * Returns a generic NFS status code in network byte-order. 1692 1701 */ 1693 1702 __be32 1694 1703 nfsd_link(struct svc_rqst *rqstp, struct svc_fh *ffhp, ··· 1704 1697 { 1705 1698 struct dentry *ddir, *dnew, *dold; 1706 1699 struct inode *dirp; 1700 + int type; 1707 1701 __be32 err; 1708 1702 int host_err; 1709 1703 ··· 1724 1716 if (isdotent(name, len)) 1725 1717 goto out; 1726 1718 1719 + err = nfs_ok; 1720 + type = d_inode(tfhp->fh_dentry)->i_mode & S_IFMT; 1727 1721 host_err = fh_want_write(tfhp); 1728 - if (host_err) { 1729 - err = nfserrno(host_err); 1722 + if (host_err) 1730 1723 goto out; 1731 - } 1732 1724 1733 1725 ddir = ffhp->fh_dentry; 1734 1726 dirp = d_inode(ddir); ··· 1736 1728 1737 1729 dnew = lookup_one_len(name, ddir, len); 1738 1730 if (IS_ERR(dnew)) { 1739 - err = nfserrno(PTR_ERR(dnew)); 1731 + host_err = PTR_ERR(dnew); 1740 1732 goto out_unlock; 1741 1733 } 1742 1734 ··· 1752 1744 fh_fill_post_attrs(ffhp); 1753 1745 inode_unlock(dirp); 1754 1746 if (!host_err) { 1755 - err = nfserrno(commit_metadata(ffhp)); 1756 - if (!err) 1757 - err = nfserrno(commit_metadata(tfhp)); 1758 - } else { 1759 - err = nfserrno(host_err); 1747 + host_err = commit_metadata(ffhp); 1748 + if (!host_err) 1749 + host_err = commit_metadata(tfhp); 1760 1750 } 1751 + 1761 1752 dput(dnew); 1762 1753 out_drop_write: 1763 1754 fh_drop_write(tfhp); 1755 + if (host_err == -EBUSY) { 1756 + /* 1757 + * See RFC 8881 Section 18.9.4 para 1-2: NFSv4 LINK 1758 + * wants a status unique to the object type. 1759 + */ 1760 + if (type != S_IFDIR) 1761 + err = nfserr_file_open; 1762 + else 1763 + err = nfserr_acces; 1764 + } 1764 1765 out: 1765 - return err; 1766 + return err != nfs_ok ? err : nfserrno(host_err); 1766 1767 1767 1768 out_dput: 1768 1769 dput(dnew); ··· 1800 1783 return ret; 1801 1784 } 1802 1785 1803 - /* 1804 - * Rename a file 1805 - * N.B. After this call _both_ ffhp and tfhp need an fh_put 1786 + /** 1787 + * nfsd_rename - rename a directory entry 1788 + * @rqstp: RPC transaction context 1789 + * @ffhp: the file handle of parent directory containing the entry to be renamed 1790 + * @fname: the filename of directory entry to be renamed 1791 + * @flen: the length of @fname in octets 1792 + * @tfhp: the file handle of parent directory to contain the renamed entry 1793 + * @tname: the filename of the new entry 1794 + * @tlen: the length of @tlen in octets 1795 + * 1796 + * After this call _both_ ffhp and tfhp need an fh_put. 1797 + * 1798 + * Returns a generic NFS status code in network byte-order. 1806 1799 */ 1807 1800 __be32 1808 1801 nfsd_rename(struct svc_rqst *rqstp, struct svc_fh *ffhp, char *fname, int flen, ··· 1820 1793 { 1821 1794 struct dentry *fdentry, *tdentry, *odentry, *ndentry, *trap; 1822 1795 struct inode *fdir, *tdir; 1796 + int type = S_IFDIR; 1823 1797 __be32 err; 1824 1798 int host_err; 1825 1799 bool close_cached = false; ··· 1878 1850 host_err = -EINVAL; 1879 1851 if (odentry == trap) 1880 1852 goto out_dput_old; 1853 + type = d_inode(odentry)->i_mode & S_IFMT; 1881 1854 1882 1855 ndentry = lookup_one_len(tname, tdentry, tlen); 1883 1856 host_err = PTR_ERR(ndentry); 1884 1857 if (IS_ERR(ndentry)) 1885 1858 goto out_dput_old; 1859 + if (d_inode(ndentry)) 1860 + type = d_inode(ndentry)->i_mode & S_IFMT; 1886 1861 host_err = -ENOTEMPTY; 1887 1862 if (ndentry == trap) 1888 1863 goto out_dput_new; ··· 1923 1892 out_dput_old: 1924 1893 dput(odentry); 1925 1894 out_nfserr: 1926 - err = nfserrno(host_err); 1895 + if (host_err == -EBUSY) { 1896 + /* 1897 + * See RFC 8881 Section 18.26.4 para 1-3: NFSv4 RENAME 1898 + * wants a status unique to the object type. 1899 + */ 1900 + if (type != S_IFDIR) 1901 + err = nfserr_file_open; 1902 + else 1903 + err = nfserr_acces; 1904 + } else { 1905 + err = nfserrno(host_err); 1906 + } 1927 1907 1928 1908 if (!close_cached) { 1929 1909 fh_fill_post_attrs(ffhp); ··· 1961 1919 return err; 1962 1920 } 1963 1921 1964 - /* 1965 - * Unlink a file or directory 1966 - * N.B. After this call fhp needs an fh_put 1922 + /** 1923 + * nfsd_unlink - remove a directory entry 1924 + * @rqstp: RPC transaction context 1925 + * @fhp: the file handle of the parent directory to be modified 1926 + * @type: enforced file type of the object to be removed 1927 + * @fname: the name of directory entry to be removed 1928 + * @flen: length of @fname in octets 1929 + * 1930 + * After this call fhp needs an fh_put. 1931 + * 1932 + * Returns a generic NFS status code in network byte-order. 1967 1933 */ 1968 1934 __be32 1969 1935 nfsd_unlink(struct svc_rqst *rqstp, struct svc_fh *fhp, int type, ··· 2045 1995 fh_drop_write(fhp); 2046 1996 out_nfserr: 2047 1997 if (host_err == -EBUSY) { 2048 - /* name is mounted-on. There is no perfect 2049 - * error status. 1998 + /* 1999 + * See RFC 8881 Section 18.25.4 para 4: NFSv4 REMOVE 2000 + * wants a status unique to the object type. 2050 2001 */ 2051 - err = nfserr_file_open; 2052 - } else { 2053 - err = nfserrno(host_err); 2002 + if (type != S_IFDIR) 2003 + err = nfserr_file_open; 2004 + else 2005 + err = nfserr_acces; 2054 2006 } 2055 2007 out: 2056 - return err; 2008 + return err != nfs_ok ? err : nfserrno(host_err); 2057 2009 out_unlock: 2058 2010 inode_unlock(dirp); 2059 2011 goto out_drop_write;
+13 -1
include/linux/exportfs.h
··· 279 279 atomic attribute updates 280 280 */ 281 281 #define EXPORT_OP_FLUSH_ON_CLOSE (0x20) /* fs flushes file data on close */ 282 - #define EXPORT_OP_ASYNC_LOCK (0x40) /* fs can do async lock request */ 282 + #define EXPORT_OP_NOLOCKS (0x40) /* no file locking support */ 283 283 unsigned long flags; 284 284 }; 285 + 286 + /** 287 + * exportfs_cannot_lock() - check if export implements file locking 288 + * @export_ops: the nfs export operations to check 289 + * 290 + * Returns true if the export does not support file locking. 291 + */ 292 + static inline bool 293 + exportfs_cannot_lock(const struct export_operations *export_ops) 294 + { 295 + return export_ops->flags & EXPORT_OP_NOLOCKS; 296 + } 285 297 286 298 extern int exportfs_encode_inode_fh(struct inode *inode, struct fid *fid, 287 299 int *max_len, struct inode *parent,
+8 -3
include/linux/posix_acl.h
··· 27 27 }; 28 28 29 29 struct posix_acl { 30 - refcount_t a_refcount; 31 - unsigned int a_count; 32 - struct rcu_head a_rcu; 30 + /* New members MUST be added within the struct_group() macro below. */ 31 + struct_group_tagged(posix_acl_hdr, hdr, 32 + refcount_t a_refcount; 33 + unsigned int a_count; 34 + struct rcu_head a_rcu; 35 + ); 33 36 struct posix_acl_entry a_entries[] __counted_by(a_count); 34 37 }; 38 + static_assert(offsetof(struct posix_acl, a_entries) == sizeof(struct posix_acl_hdr), 39 + "struct member likely outside of struct_group_tagged()"); 35 40 36 41 #define FOREACH_ACL_ENTRY(pa, acl, pe) \ 37 42 for(pa=(acl)->a_entries, pe=pa+(acl)->a_count; pa<pe; pa++)
+29
include/uapi/linux/lockd_netlink.h
··· 1 + /* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */ 2 + /* Do not edit directly, auto-generated from: */ 3 + /* Documentation/netlink/specs/lockd.yaml */ 4 + /* YNL-GEN uapi header */ 5 + 6 + #ifndef _UAPI_LINUX_LOCKD_NETLINK_H 7 + #define _UAPI_LINUX_LOCKD_NETLINK_H 8 + 9 + #define LOCKD_FAMILY_NAME "lockd" 10 + #define LOCKD_FAMILY_VERSION 1 11 + 12 + enum { 13 + LOCKD_A_SERVER_GRACETIME = 1, 14 + LOCKD_A_SERVER_TCP_PORT, 15 + LOCKD_A_SERVER_UDP_PORT, 16 + 17 + __LOCKD_A_SERVER_MAX, 18 + LOCKD_A_SERVER_MAX = (__LOCKD_A_SERVER_MAX - 1) 19 + }; 20 + 21 + enum { 22 + LOCKD_CMD_SERVER_SET = 1, 23 + LOCKD_CMD_SERVER_GET, 24 + 25 + __LOCKD_CMD_MAX, 26 + LOCKD_CMD_MAX = (__LOCKD_CMD_MAX - 1) 27 + }; 28 + 29 + #endif /* _UAPI_LINUX_LOCKD_NETLINK_H */
-144
net/sunrpc/auth_gss/gss_krb5_crypto.c
··· 138 138 return ret; 139 139 } 140 140 141 - /** 142 - * krb5_decrypt - simple decryption of an RPCSEC GSS payload 143 - * @tfm: initialized cipher transform 144 - * @iv: pointer to an IV 145 - * @in: ciphertext to decrypt 146 - * @out: OUT: plaintext 147 - * @length: length of input and output buffers, in bytes 148 - * 149 - * @iv may be NULL to force the use of an all-zero IV. 150 - * The buffer containing the IV must be as large as the 151 - * cipher's ivsize. 152 - * 153 - * Return values: 154 - * %0: @in successfully decrypted into @out 155 - * negative errno: @in not decrypted 156 - */ 157 - u32 158 - krb5_decrypt( 159 - struct crypto_sync_skcipher *tfm, 160 - void * iv, 161 - void * in, 162 - void * out, 163 - int length) 164 - { 165 - u32 ret = -EINVAL; 166 - struct scatterlist sg[1]; 167 - u8 local_iv[GSS_KRB5_MAX_BLOCKSIZE] = {0}; 168 - SYNC_SKCIPHER_REQUEST_ON_STACK(req, tfm); 169 - 170 - if (length % crypto_sync_skcipher_blocksize(tfm) != 0) 171 - goto out; 172 - 173 - if (crypto_sync_skcipher_ivsize(tfm) > GSS_KRB5_MAX_BLOCKSIZE) { 174 - dprintk("RPC: gss_k5decrypt: tfm iv size too large %d\n", 175 - crypto_sync_skcipher_ivsize(tfm)); 176 - goto out; 177 - } 178 - if (iv) 179 - memcpy(local_iv, iv, crypto_sync_skcipher_ivsize(tfm)); 180 - 181 - memcpy(out, in, length); 182 - sg_init_one(sg, out, length); 183 - 184 - skcipher_request_set_sync_tfm(req, tfm); 185 - skcipher_request_set_callback(req, 0, NULL, NULL); 186 - skcipher_request_set_crypt(req, sg, sg, length, local_iv); 187 - 188 - ret = crypto_skcipher_decrypt(req); 189 - skcipher_request_zero(req); 190 - out: 191 - dprintk("RPC: gss_k5decrypt returns %d\n",ret); 192 - return ret; 193 - } 194 - 195 141 static int 196 142 checksummer(struct scatterlist *sg, void *data) 197 143 { ··· 146 200 ahash_request_set_crypt(req, sg, NULL, sg->length); 147 201 148 202 return crypto_ahash_update(req); 149 - } 150 - 151 - /* 152 - * checksum the plaintext data and hdrlen bytes of the token header 153 - * The checksum is performed over the first 8 bytes of the 154 - * gss token header and then over the data body 155 - */ 156 - u32 157 - make_checksum(struct krb5_ctx *kctx, char *header, int hdrlen, 158 - struct xdr_buf *body, int body_offset, u8 *cksumkey, 159 - unsigned int usage, struct xdr_netobj *cksumout) 160 - { 161 - struct crypto_ahash *tfm; 162 - struct ahash_request *req; 163 - struct scatterlist sg[1]; 164 - int err = -1; 165 - u8 *checksumdata; 166 - unsigned int checksumlen; 167 - 168 - if (cksumout->len < kctx->gk5e->cksumlength) { 169 - dprintk("%s: checksum buffer length, %u, too small for %s\n", 170 - __func__, cksumout->len, kctx->gk5e->name); 171 - return GSS_S_FAILURE; 172 - } 173 - 174 - checksumdata = kmalloc(GSS_KRB5_MAX_CKSUM_LEN, GFP_KERNEL); 175 - if (checksumdata == NULL) 176 - return GSS_S_FAILURE; 177 - 178 - tfm = crypto_alloc_ahash(kctx->gk5e->cksum_name, 0, CRYPTO_ALG_ASYNC); 179 - if (IS_ERR(tfm)) 180 - goto out_free_cksum; 181 - 182 - req = ahash_request_alloc(tfm, GFP_KERNEL); 183 - if (!req) 184 - goto out_free_ahash; 185 - 186 - ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_SLEEP, NULL, NULL); 187 - 188 - checksumlen = crypto_ahash_digestsize(tfm); 189 - 190 - if (cksumkey != NULL) { 191 - err = crypto_ahash_setkey(tfm, cksumkey, 192 - kctx->gk5e->keylength); 193 - if (err) 194 - goto out; 195 - } 196 - 197 - err = crypto_ahash_init(req); 198 - if (err) 199 - goto out; 200 - sg_init_one(sg, header, hdrlen); 201 - ahash_request_set_crypt(req, sg, NULL, hdrlen); 202 - err = crypto_ahash_update(req); 203 - if (err) 204 - goto out; 205 - err = xdr_process_buf(body, body_offset, body->len - body_offset, 206 - checksummer, req); 207 - if (err) 208 - goto out; 209 - ahash_request_set_crypt(req, NULL, checksumdata, 0); 210 - err = crypto_ahash_final(req); 211 - if (err) 212 - goto out; 213 - 214 - switch (kctx->gk5e->ctype) { 215 - case CKSUMTYPE_RSA_MD5: 216 - err = krb5_encrypt(kctx->seq, NULL, checksumdata, 217 - checksumdata, checksumlen); 218 - if (err) 219 - goto out; 220 - memcpy(cksumout->data, 221 - checksumdata + checksumlen - kctx->gk5e->cksumlength, 222 - kctx->gk5e->cksumlength); 223 - break; 224 - case CKSUMTYPE_HMAC_SHA1_DES3: 225 - memcpy(cksumout->data, checksumdata, kctx->gk5e->cksumlength); 226 - break; 227 - default: 228 - BUG(); 229 - break; 230 - } 231 - cksumout->len = kctx->gk5e->cksumlength; 232 - out: 233 - ahash_request_free(req); 234 - out_free_ahash: 235 - crypto_free_ahash(tfm); 236 - out_free_cksum: 237 - kfree(checksumdata); 238 - return err ? GSS_S_FAILURE : 0; 239 203 } 240 204 241 205 /**
-7
net/sunrpc/auth_gss/gss_krb5_internal.h
··· 155 155 156 156 void krb5_make_confounder(u8 *p, int conflen); 157 157 158 - u32 make_checksum(struct krb5_ctx *kctx, char *header, int hdrlen, 159 - struct xdr_buf *body, int body_offset, u8 *cksumkey, 160 - unsigned int usage, struct xdr_netobj *cksumout); 161 - 162 158 u32 gss_krb5_checksum(struct crypto_ahash *tfm, char *header, int hdrlen, 163 159 const struct xdr_buf *body, int body_offset, 164 160 struct xdr_netobj *cksumout); 165 161 166 162 u32 krb5_encrypt(struct crypto_sync_skcipher *key, void *iv, void *in, 167 - void *out, int length); 168 - 169 - u32 krb5_decrypt(struct crypto_sync_skcipher *key, void *iv, void *in, 170 163 void *out, int length); 171 164 172 165 int xdr_extend_head(struct xdr_buf *buf, unsigned int base,
+5 -1
net/sunrpc/cache.c
··· 1536 1536 * or by one second if it has already reached the current time. 1537 1537 * Newly added cache entries will always have ->last_refresh greater 1538 1538 * that ->flush_time, so they don't get flushed prematurely. 1539 + * 1540 + * If someone frequently calls the flush interface, we should 1541 + * immediately clean the corresponding cache_detail instead of 1542 + * continuously accumulating nextcheck. 1539 1543 */ 1540 1544 1541 - if (cd->flush_time >= now) 1545 + if (cd->flush_time >= now && cd->flush_time < (now + 5)) 1542 1546 now = cd->flush_time + 1; 1543 1547 1544 1548 cd->flush_time = now;
+2 -1
net/sunrpc/xprtrdma/svc_rdma_transport.c
··· 621 621 /* Destroy the CM ID */ 622 622 rdma_destroy_id(rdma->sc_cm_id); 623 623 624 - rpcrdma_rn_unregister(device, &rdma->sc_rn); 624 + if (!test_bit(XPT_LISTENER, &rdma->sc_xprt.xpt_flags)) 625 + rpcrdma_rn_unregister(device, &rdma->sc_rn); 625 626 kfree(rdma); 626 627 } 627 628