.. | .. |
---|
63 | 63 | #include "callback.h" |
---|
64 | 64 | #include "pnfs.h" |
---|
65 | 65 | #include "netns.h" |
---|
| 66 | +#include "sysfs.h" |
---|
66 | 67 | #include "nfs4idmap.h" |
---|
67 | 68 | #include "nfs4session.h" |
---|
68 | 69 | #include "fscache.h" |
---|
| 70 | +#include "nfs42.h" |
---|
69 | 71 | |
---|
70 | 72 | #include "nfs4trace.h" |
---|
| 73 | + |
---|
| 74 | +#ifdef CONFIG_NFS_V4_2 |
---|
| 75 | +#include "nfs42.h" |
---|
| 76 | +#endif /* CONFIG_NFS_V4_2 */ |
---|
71 | 77 | |
---|
72 | 78 | #define NFSDBG_FACILITY NFSDBG_PROC |
---|
73 | 79 | |
---|
.. | .. |
---|
91 | 97 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
---|
92 | 98 | static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *); |
---|
93 | 99 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr); |
---|
94 | | -static int nfs4_proc_getattr(struct nfs_server *, struct nfs_fh *, struct nfs_fattr *, struct nfs4_label *label, struct inode *inode); |
---|
95 | 100 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr, struct nfs4_label *label, struct inode *inode); |
---|
96 | | -static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
---|
| 101 | +static int nfs4_do_setattr(struct inode *inode, const struct cred *cred, |
---|
97 | 102 | struct nfs_fattr *fattr, struct iattr *sattr, |
---|
98 | 103 | struct nfs_open_context *ctx, struct nfs4_label *ilabel, |
---|
99 | 104 | struct nfs4_label *olabel); |
---|
100 | 105 | #ifdef CONFIG_NFS_V4_1 |
---|
101 | 106 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
---|
102 | | - struct rpc_cred *cred, |
---|
| 107 | + const struct cred *cred, |
---|
103 | 108 | struct nfs4_slot *slot, |
---|
104 | 109 | bool is_privileged); |
---|
105 | 110 | static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *, |
---|
106 | | - struct rpc_cred *); |
---|
| 111 | + const struct cred *); |
---|
107 | 112 | static int nfs41_free_stateid(struct nfs_server *, const nfs4_stateid *, |
---|
108 | | - struct rpc_cred *, bool); |
---|
| 113 | + const struct cred *, bool); |
---|
109 | 114 | #endif |
---|
| 115 | +static void nfs4_bitmask_set(__u32 bitmask[NFS4_BITMASK_SZ], |
---|
| 116 | + const __u32 *src, struct inode *inode, |
---|
| 117 | + struct nfs_server *server, |
---|
| 118 | + struct nfs4_label *label); |
---|
110 | 119 | |
---|
111 | 120 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
---|
112 | 121 | static inline struct nfs4_label * |
---|
.. | .. |
---|
120 | 129 | |
---|
121 | 130 | if (nfs_server_capable(dir, NFS_CAP_SECURITY_LABEL) == 0) |
---|
122 | 131 | return NULL; |
---|
| 132 | + |
---|
| 133 | + label->lfs = 0; |
---|
| 134 | + label->pi = 0; |
---|
| 135 | + label->len = 0; |
---|
| 136 | + label->label = NULL; |
---|
123 | 137 | |
---|
124 | 138 | err = security_dentry_init_security(dentry, sattr->ia_mode, |
---|
125 | 139 | &dentry->d_name, (void **)&label->label, &label->len); |
---|
.. | .. |
---|
257 | 271 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
---|
258 | 272 | FATTR4_WORD2_LAYOUT_BLKSIZE |
---|
259 | 273 | | FATTR4_WORD2_CLONE_BLKSIZE |
---|
| 274 | + | FATTR4_WORD2_XATTR_SUPPORT |
---|
260 | 275 | }; |
---|
261 | 276 | |
---|
262 | 277 | const u32 nfs4_fs_locations_bitmap[3] = { |
---|
.. | .. |
---|
359 | 374 | kunmap_atomic(start); |
---|
360 | 375 | } |
---|
361 | 376 | |
---|
| 377 | +static void nfs4_fattr_set_prechange(struct nfs_fattr *fattr, u64 version) |
---|
| 378 | +{ |
---|
| 379 | + if (!(fattr->valid & NFS_ATTR_FATTR_PRECHANGE)) { |
---|
| 380 | + fattr->pre_change_attr = version; |
---|
| 381 | + fattr->valid |= NFS_ATTR_FATTR_PRECHANGE; |
---|
| 382 | + } |
---|
| 383 | +} |
---|
| 384 | + |
---|
362 | 385 | static void nfs4_test_and_free_stateid(struct nfs_server *server, |
---|
363 | 386 | nfs4_stateid *stateid, |
---|
364 | | - struct rpc_cred *cred) |
---|
| 387 | + const struct cred *cred) |
---|
365 | 388 | { |
---|
366 | 389 | const struct nfs4_minor_version_ops *ops = server->nfs_client->cl_mvops; |
---|
367 | 390 | |
---|
.. | .. |
---|
370 | 393 | |
---|
371 | 394 | static void __nfs4_free_revoked_stateid(struct nfs_server *server, |
---|
372 | 395 | nfs4_stateid *stateid, |
---|
373 | | - struct rpc_cred *cred) |
---|
| 396 | + const struct cred *cred) |
---|
374 | 397 | { |
---|
375 | 398 | stateid->type = NFS4_REVOKED_STATEID_TYPE; |
---|
376 | 399 | nfs4_test_and_free_stateid(server, stateid, cred); |
---|
.. | .. |
---|
378 | 401 | |
---|
379 | 402 | static void nfs4_free_revoked_stateid(struct nfs_server *server, |
---|
380 | 403 | const nfs4_stateid *stateid, |
---|
381 | | - struct rpc_cred *cred) |
---|
| 404 | + const struct cred *cred) |
---|
382 | 405 | { |
---|
383 | 406 | nfs4_stateid tmp; |
---|
384 | 407 | |
---|
.. | .. |
---|
400 | 423 | return ret; |
---|
401 | 424 | } |
---|
402 | 425 | |
---|
403 | | -static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
---|
| 426 | +static int nfs4_delay_killable(long *timeout) |
---|
404 | 427 | { |
---|
405 | | - int res = 0; |
---|
406 | | - |
---|
407 | 428 | might_sleep(); |
---|
408 | 429 | |
---|
409 | 430 | freezable_schedule_timeout_killable_unsafe( |
---|
410 | 431 | nfs4_update_delay(timeout)); |
---|
411 | | - if (fatal_signal_pending(current)) |
---|
412 | | - res = -ERESTARTSYS; |
---|
413 | | - return res; |
---|
| 432 | + if (!__fatal_signal_pending(current)) |
---|
| 433 | + return 0; |
---|
| 434 | + return -EINTR; |
---|
| 435 | +} |
---|
| 436 | + |
---|
| 437 | +static int nfs4_delay_interruptible(long *timeout) |
---|
| 438 | +{ |
---|
| 439 | + might_sleep(); |
---|
| 440 | + |
---|
| 441 | + freezable_schedule_timeout_interruptible_unsafe(nfs4_update_delay(timeout)); |
---|
| 442 | + if (!signal_pending(current)) |
---|
| 443 | + return 0; |
---|
| 444 | + return __fatal_signal_pending(current) ? -EINTR :-ERESTARTSYS; |
---|
| 445 | +} |
---|
| 446 | + |
---|
| 447 | +static int nfs4_delay(long *timeout, bool interruptible) |
---|
| 448 | +{ |
---|
| 449 | + if (interruptible) |
---|
| 450 | + return nfs4_delay_interruptible(timeout); |
---|
| 451 | + return nfs4_delay_killable(timeout); |
---|
| 452 | +} |
---|
| 453 | + |
---|
| 454 | +static const nfs4_stateid * |
---|
| 455 | +nfs4_recoverable_stateid(const nfs4_stateid *stateid) |
---|
| 456 | +{ |
---|
| 457 | + if (!stateid) |
---|
| 458 | + return NULL; |
---|
| 459 | + switch (stateid->type) { |
---|
| 460 | + case NFS4_OPEN_STATEID_TYPE: |
---|
| 461 | + case NFS4_LOCK_STATEID_TYPE: |
---|
| 462 | + case NFS4_DELEGATION_STATEID_TYPE: |
---|
| 463 | + return stateid; |
---|
| 464 | + default: |
---|
| 465 | + break; |
---|
| 466 | + } |
---|
| 467 | + return NULL; |
---|
414 | 468 | } |
---|
415 | 469 | |
---|
416 | 470 | /* This is the error handling routine for processes that are allowed |
---|
.. | .. |
---|
421 | 475 | { |
---|
422 | 476 | struct nfs_client *clp = server->nfs_client; |
---|
423 | 477 | struct nfs4_state *state = exception->state; |
---|
424 | | - const nfs4_stateid *stateid = exception->stateid; |
---|
| 478 | + const nfs4_stateid *stateid; |
---|
425 | 479 | struct inode *inode = exception->inode; |
---|
426 | 480 | int ret = errorcode; |
---|
427 | 481 | |
---|
.. | .. |
---|
429 | 483 | exception->recovering = 0; |
---|
430 | 484 | exception->retry = 0; |
---|
431 | 485 | |
---|
| 486 | + stateid = nfs4_recoverable_stateid(exception->stateid); |
---|
432 | 487 | if (stateid == NULL && state != NULL) |
---|
433 | | - stateid = &state->stateid; |
---|
| 488 | + stateid = nfs4_recoverable_stateid(&state->stateid); |
---|
434 | 489 | |
---|
435 | 490 | switch(errorcode) { |
---|
436 | 491 | case 0: |
---|
.. | .. |
---|
444 | 499 | case -NFS4ERR_ADMIN_REVOKED: |
---|
445 | 500 | case -NFS4ERR_EXPIRED: |
---|
446 | 501 | case -NFS4ERR_BAD_STATEID: |
---|
| 502 | + case -NFS4ERR_PARTNER_NO_AUTH: |
---|
447 | 503 | if (inode != NULL && stateid != NULL) { |
---|
448 | 504 | nfs_inode_find_state_and_recover(inode, |
---|
449 | 505 | stateid); |
---|
450 | 506 | goto wait_on_recovery; |
---|
451 | 507 | } |
---|
452 | | - /* Fall through */ |
---|
| 508 | + fallthrough; |
---|
453 | 509 | case -NFS4ERR_OPENMODE: |
---|
454 | 510 | if (inode) { |
---|
455 | 511 | int err; |
---|
.. | .. |
---|
489 | 545 | case -NFS4ERR_DEADSESSION: |
---|
490 | 546 | case -NFS4ERR_SEQ_FALSE_RETRY: |
---|
491 | 547 | case -NFS4ERR_SEQ_MISORDERED: |
---|
492 | | - dprintk("%s ERROR: %d Reset session\n", __func__, |
---|
493 | | - errorcode); |
---|
494 | | - nfs4_schedule_session_recovery(clp->cl_session, errorcode); |
---|
| 548 | + /* Handled in nfs41_sequence_process() */ |
---|
495 | 549 | goto wait_on_recovery; |
---|
496 | 550 | #endif /* defined(CONFIG_NFS_V4_1) */ |
---|
497 | 551 | case -NFS4ERR_FILE_OPEN: |
---|
.. | .. |
---|
502 | 556 | ret = -EBUSY; |
---|
503 | 557 | break; |
---|
504 | 558 | } |
---|
505 | | - /* Fall through */ |
---|
| 559 | + fallthrough; |
---|
506 | 560 | case -NFS4ERR_DELAY: |
---|
507 | 561 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
---|
508 | | - /* Fall through */ |
---|
| 562 | + fallthrough; |
---|
509 | 563 | case -NFS4ERR_GRACE: |
---|
510 | 564 | case -NFS4ERR_LAYOUTTRYLATER: |
---|
511 | 565 | case -NFS4ERR_RECALLCONFLICT: |
---|
.. | .. |
---|
546 | 600 | |
---|
547 | 601 | ret = nfs4_do_handle_exception(server, errorcode, exception); |
---|
548 | 602 | if (exception->delay) { |
---|
549 | | - ret = nfs4_delay(server->client, &exception->timeout); |
---|
| 603 | + ret = nfs4_delay(&exception->timeout, |
---|
| 604 | + exception->interruptible); |
---|
550 | 605 | goto out_retry; |
---|
551 | 606 | } |
---|
552 | 607 | if (exception->recovering) { |
---|
.. | .. |
---|
734 | 789 | res->sr_slot = NULL; |
---|
735 | 790 | } |
---|
736 | 791 | |
---|
| 792 | +static void nfs4_slot_sequence_record_sent(struct nfs4_slot *slot, |
---|
| 793 | + u32 seqnr) |
---|
| 794 | +{ |
---|
| 795 | + if ((s32)(seqnr - slot->seq_nr_highest_sent) > 0) |
---|
| 796 | + slot->seq_nr_highest_sent = seqnr; |
---|
| 797 | +} |
---|
| 798 | +static void nfs4_slot_sequence_acked(struct nfs4_slot *slot, u32 seqnr) |
---|
| 799 | +{ |
---|
| 800 | + nfs4_slot_sequence_record_sent(slot, seqnr); |
---|
| 801 | + slot->seq_nr_last_acked = seqnr; |
---|
| 802 | +} |
---|
| 803 | + |
---|
| 804 | +static void nfs4_probe_sequence(struct nfs_client *client, const struct cred *cred, |
---|
| 805 | + struct nfs4_slot *slot) |
---|
| 806 | +{ |
---|
| 807 | + struct rpc_task *task = _nfs41_proc_sequence(client, cred, slot, true); |
---|
| 808 | + if (!IS_ERR(task)) |
---|
| 809 | + rpc_put_task_async(task); |
---|
| 810 | +} |
---|
| 811 | + |
---|
737 | 812 | static int nfs41_sequence_process(struct rpc_task *task, |
---|
738 | 813 | struct nfs4_sequence_res *res) |
---|
739 | 814 | { |
---|
740 | 815 | struct nfs4_session *session; |
---|
741 | 816 | struct nfs4_slot *slot = res->sr_slot; |
---|
742 | 817 | struct nfs_client *clp; |
---|
743 | | - bool interrupted = false; |
---|
| 818 | + int status; |
---|
744 | 819 | int ret = 1; |
---|
745 | 820 | |
---|
746 | 821 | if (slot == NULL) |
---|
747 | 822 | goto out_noaction; |
---|
748 | 823 | /* don't increment the sequence number if the task wasn't sent */ |
---|
749 | | - if (!RPC_WAS_SENT(task)) |
---|
| 824 | + if (!RPC_WAS_SENT(task) || slot->seq_done) |
---|
750 | 825 | goto out; |
---|
751 | 826 | |
---|
752 | 827 | session = slot->table->session; |
---|
753 | | - |
---|
754 | | - if (slot->interrupted) { |
---|
755 | | - if (res->sr_status != -NFS4ERR_DELAY) |
---|
756 | | - slot->interrupted = 0; |
---|
757 | | - interrupted = true; |
---|
758 | | - } |
---|
| 828 | + clp = session->clp; |
---|
759 | 829 | |
---|
760 | 830 | trace_nfs4_sequence_done(session, res); |
---|
| 831 | + |
---|
| 832 | + status = res->sr_status; |
---|
| 833 | + if (task->tk_status == -NFS4ERR_DEADSESSION) |
---|
| 834 | + status = -NFS4ERR_DEADSESSION; |
---|
| 835 | + |
---|
761 | 836 | /* Check the SEQUENCE operation status */ |
---|
762 | | - switch (res->sr_status) { |
---|
| 837 | + switch (status) { |
---|
763 | 838 | case 0: |
---|
| 839 | + /* Mark this sequence number as having been acked */ |
---|
| 840 | + nfs4_slot_sequence_acked(slot, slot->seq_nr); |
---|
764 | 841 | /* Update the slot's sequence and clientid lease timer */ |
---|
765 | 842 | slot->seq_done = 1; |
---|
766 | | - clp = session->clp; |
---|
767 | 843 | do_renew_lease(clp, res->sr_timestamp); |
---|
768 | 844 | /* Check sequence flags */ |
---|
769 | 845 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags, |
---|
.. | .. |
---|
775 | 851 | * sr_status remains 1 if an RPC level error occurred. |
---|
776 | 852 | * The server may or may not have processed the sequence |
---|
777 | 853 | * operation.. |
---|
778 | | - * Mark the slot as having hosted an interrupted RPC call. |
---|
779 | 854 | */ |
---|
780 | | - slot->interrupted = 1; |
---|
| 855 | + nfs4_slot_sequence_record_sent(slot, slot->seq_nr); |
---|
| 856 | + slot->seq_done = 1; |
---|
781 | 857 | goto out; |
---|
782 | 858 | case -NFS4ERR_DELAY: |
---|
783 | 859 | /* The server detected a resend of the RPC call and |
---|
.. | .. |
---|
795 | 871 | * The server thinks we tried to replay a request. |
---|
796 | 872 | * Retry the call after bumping the sequence ID. |
---|
797 | 873 | */ |
---|
| 874 | + nfs4_slot_sequence_acked(slot, slot->seq_nr); |
---|
798 | 875 | goto retry_new_seq; |
---|
799 | 876 | case -NFS4ERR_BADSLOT: |
---|
800 | 877 | /* |
---|
.. | .. |
---|
805 | 882 | goto session_recover; |
---|
806 | 883 | goto retry_nowait; |
---|
807 | 884 | case -NFS4ERR_SEQ_MISORDERED: |
---|
| 885 | + nfs4_slot_sequence_record_sent(slot, slot->seq_nr); |
---|
808 | 886 | /* |
---|
809 | | - * Was the last operation on this sequence interrupted? |
---|
810 | | - * If so, retry after bumping the sequence number. |
---|
| 887 | + * Were one or more calls using this slot interrupted? |
---|
| 888 | + * If the server never received the request, then our |
---|
| 889 | + * transmitted slot sequence number may be too high. However, |
---|
| 890 | + * if the server did receive the request then it might |
---|
| 891 | + * accidentally give us a reply with a mismatched operation. |
---|
| 892 | + * We can sort this out by sending a lone sequence operation |
---|
| 893 | + * to the server on the same slot. |
---|
811 | 894 | */ |
---|
812 | | - if (interrupted) |
---|
813 | | - goto retry_new_seq; |
---|
814 | | - /* |
---|
815 | | - * Could this slot have been previously retired? |
---|
816 | | - * If so, then the server may be expecting seq_nr = 1! |
---|
817 | | - */ |
---|
818 | | - if (slot->seq_nr != 1) { |
---|
819 | | - slot->seq_nr = 1; |
---|
| 895 | + if ((s32)(slot->seq_nr - slot->seq_nr_last_acked) > 1) { |
---|
| 896 | + slot->seq_nr--; |
---|
| 897 | + if (task->tk_msg.rpc_proc != &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE]) { |
---|
| 898 | + nfs4_probe_sequence(clp, task->tk_msg.rpc_cred, slot); |
---|
| 899 | + res->sr_slot = NULL; |
---|
| 900 | + } |
---|
820 | 901 | goto retry_nowait; |
---|
821 | 902 | } |
---|
| 903 | + /* |
---|
| 904 | + * RFC5661: |
---|
| 905 | + * A retry might be sent while the original request is |
---|
| 906 | + * still in progress on the replier. The replier SHOULD |
---|
| 907 | + * deal with the issue by returning NFS4ERR_DELAY as the |
---|
| 908 | + * reply to SEQUENCE or CB_SEQUENCE operation, but |
---|
| 909 | + * implementations MAY return NFS4ERR_SEQ_MISORDERED. |
---|
| 910 | + * |
---|
| 911 | + * Restart the search after a delay. |
---|
| 912 | + */ |
---|
| 913 | + slot->seq_nr = slot->seq_nr_highest_sent; |
---|
| 914 | + goto out_retry; |
---|
| 915 | + case -NFS4ERR_BADSESSION: |
---|
| 916 | + case -NFS4ERR_DEADSESSION: |
---|
| 917 | + case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
---|
822 | 918 | goto session_recover; |
---|
823 | 919 | default: |
---|
824 | 920 | /* Just update the slot sequence no. */ |
---|
.. | .. |
---|
830 | 926 | out_noaction: |
---|
831 | 927 | return ret; |
---|
832 | 928 | session_recover: |
---|
833 | | - nfs4_schedule_session_recovery(session, res->sr_status); |
---|
834 | | - goto retry_nowait; |
---|
| 929 | + set_bit(NFS4_SLOT_TBL_DRAINING, &session->fc_slot_table.slot_tbl_state); |
---|
| 930 | + nfs4_schedule_session_recovery(session, status); |
---|
| 931 | + dprintk("%s ERROR: %d Reset session\n", __func__, status); |
---|
| 932 | + nfs41_sequence_free_slot(res); |
---|
| 933 | + goto out; |
---|
835 | 934 | retry_new_seq: |
---|
836 | 935 | ++slot->seq_nr; |
---|
837 | 936 | retry_nowait: |
---|
.. | .. |
---|
910 | 1009 | .rpc_call_done = nfs41_call_sync_done, |
---|
911 | 1010 | }; |
---|
912 | 1011 | |
---|
913 | | -static void |
---|
914 | | -nfs4_sequence_process_interrupted(struct nfs_client *client, |
---|
915 | | - struct nfs4_slot *slot, struct rpc_cred *cred) |
---|
916 | | -{ |
---|
917 | | - struct rpc_task *task; |
---|
918 | | - |
---|
919 | | - task = _nfs41_proc_sequence(client, cred, slot, true); |
---|
920 | | - if (!IS_ERR(task)) |
---|
921 | | - rpc_put_task_async(task); |
---|
922 | | -} |
---|
923 | | - |
---|
924 | 1012 | #else /* !CONFIG_NFS_V4_1 */ |
---|
925 | 1013 | |
---|
926 | 1014 | static int nfs4_sequence_process(struct rpc_task *task, struct nfs4_sequence_res *res) |
---|
.. | .. |
---|
940 | 1028 | return nfs40_sequence_done(task, res); |
---|
941 | 1029 | } |
---|
942 | 1030 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); |
---|
943 | | - |
---|
944 | | -static void |
---|
945 | | -nfs4_sequence_process_interrupted(struct nfs_client *client, |
---|
946 | | - struct nfs4_slot *slot, struct rpc_cred *cred) |
---|
947 | | -{ |
---|
948 | | - WARN_ON_ONCE(1); |
---|
949 | | - slot->interrupted = 0; |
---|
950 | | -} |
---|
951 | 1031 | |
---|
952 | 1032 | #endif /* !CONFIG_NFS_V4_1 */ |
---|
953 | 1033 | |
---|
.. | .. |
---|
984 | 1064 | if (res->sr_slot != NULL) |
---|
985 | 1065 | goto out_start; |
---|
986 | 1066 | |
---|
987 | | - if (session) { |
---|
| 1067 | + if (session) |
---|
988 | 1068 | tbl = &session->fc_slot_table; |
---|
989 | | - task->tk_timeout = 0; |
---|
| 1069 | + |
---|
| 1070 | + spin_lock(&tbl->slot_tbl_lock); |
---|
| 1071 | + /* The state manager will wait until the slot table is empty */ |
---|
| 1072 | + if (nfs4_slot_tbl_draining(tbl) && !args->sa_privileged) |
---|
| 1073 | + goto out_sleep; |
---|
| 1074 | + |
---|
| 1075 | + slot = nfs4_alloc_slot(tbl); |
---|
| 1076 | + if (IS_ERR(slot)) { |
---|
| 1077 | + if (slot == ERR_PTR(-ENOMEM)) |
---|
| 1078 | + goto out_sleep_timeout; |
---|
| 1079 | + goto out_sleep; |
---|
990 | 1080 | } |
---|
991 | | - |
---|
992 | | - for (;;) { |
---|
993 | | - spin_lock(&tbl->slot_tbl_lock); |
---|
994 | | - /* The state manager will wait until the slot table is empty */ |
---|
995 | | - if (nfs4_slot_tbl_draining(tbl) && !args->sa_privileged) |
---|
996 | | - goto out_sleep; |
---|
997 | | - |
---|
998 | | - slot = nfs4_alloc_slot(tbl); |
---|
999 | | - if (IS_ERR(slot)) { |
---|
1000 | | - /* Try again in 1/4 second */ |
---|
1001 | | - if (slot == ERR_PTR(-ENOMEM)) |
---|
1002 | | - task->tk_timeout = HZ >> 2; |
---|
1003 | | - goto out_sleep; |
---|
1004 | | - } |
---|
1005 | | - spin_unlock(&tbl->slot_tbl_lock); |
---|
1006 | | - |
---|
1007 | | - if (likely(!slot->interrupted)) |
---|
1008 | | - break; |
---|
1009 | | - nfs4_sequence_process_interrupted(client, |
---|
1010 | | - slot, task->tk_msg.rpc_cred); |
---|
1011 | | - } |
---|
| 1081 | + spin_unlock(&tbl->slot_tbl_lock); |
---|
1012 | 1082 | |
---|
1013 | 1083 | nfs4_sequence_attach_slot(args, res, slot); |
---|
1014 | 1084 | |
---|
.. | .. |
---|
1017 | 1087 | nfs41_sequence_res_init(res); |
---|
1018 | 1088 | rpc_call_start(task); |
---|
1019 | 1089 | return 0; |
---|
1020 | | - |
---|
| 1090 | +out_sleep_timeout: |
---|
| 1091 | + /* Try again in 1/4 second */ |
---|
| 1092 | + if (args->sa_privileged) |
---|
| 1093 | + rpc_sleep_on_priority_timeout(&tbl->slot_tbl_waitq, task, |
---|
| 1094 | + jiffies + (HZ >> 2), RPC_PRIORITY_PRIVILEGED); |
---|
| 1095 | + else |
---|
| 1096 | + rpc_sleep_on_timeout(&tbl->slot_tbl_waitq, task, |
---|
| 1097 | + NULL, jiffies + (HZ >> 2)); |
---|
| 1098 | + spin_unlock(&tbl->slot_tbl_lock); |
---|
| 1099 | + return -EAGAIN; |
---|
1021 | 1100 | out_sleep: |
---|
1022 | 1101 | if (args->sa_privileged) |
---|
1023 | 1102 | rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task, |
---|
1024 | | - NULL, RPC_PRIORITY_PRIVILEGED); |
---|
| 1103 | + RPC_PRIORITY_PRIVILEGED); |
---|
1025 | 1104 | else |
---|
1026 | 1105 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
---|
1027 | 1106 | spin_unlock(&tbl->slot_tbl_lock); |
---|
.. | .. |
---|
1047 | 1126 | .rpc_call_done = nfs40_call_sync_done, |
---|
1048 | 1127 | }; |
---|
1049 | 1128 | |
---|
1050 | | -static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
---|
1051 | | - struct nfs_server *server, |
---|
1052 | | - struct rpc_message *msg, |
---|
1053 | | - struct nfs4_sequence_args *args, |
---|
1054 | | - struct nfs4_sequence_res *res) |
---|
| 1129 | +static int nfs4_call_sync_custom(struct rpc_task_setup *task_setup) |
---|
1055 | 1130 | { |
---|
1056 | 1131 | int ret; |
---|
1057 | 1132 | struct rpc_task *task; |
---|
| 1133 | + |
---|
| 1134 | + task = rpc_run_task(task_setup); |
---|
| 1135 | + if (IS_ERR(task)) |
---|
| 1136 | + return PTR_ERR(task); |
---|
| 1137 | + |
---|
| 1138 | + ret = task->tk_status; |
---|
| 1139 | + rpc_put_task(task); |
---|
| 1140 | + return ret; |
---|
| 1141 | +} |
---|
| 1142 | + |
---|
| 1143 | +static int nfs4_do_call_sync(struct rpc_clnt *clnt, |
---|
| 1144 | + struct nfs_server *server, |
---|
| 1145 | + struct rpc_message *msg, |
---|
| 1146 | + struct nfs4_sequence_args *args, |
---|
| 1147 | + struct nfs4_sequence_res *res, |
---|
| 1148 | + unsigned short task_flags) |
---|
| 1149 | +{ |
---|
1058 | 1150 | struct nfs_client *clp = server->nfs_client; |
---|
1059 | 1151 | struct nfs4_call_sync_data data = { |
---|
1060 | 1152 | .seq_server = server, |
---|
.. | .. |
---|
1065 | 1157 | .rpc_client = clnt, |
---|
1066 | 1158 | .rpc_message = msg, |
---|
1067 | 1159 | .callback_ops = clp->cl_mvops->call_sync_ops, |
---|
1068 | | - .callback_data = &data |
---|
| 1160 | + .callback_data = &data, |
---|
| 1161 | + .flags = task_flags, |
---|
1069 | 1162 | }; |
---|
1070 | 1163 | |
---|
1071 | | - task = rpc_run_task(&task_setup); |
---|
1072 | | - if (IS_ERR(task)) |
---|
1073 | | - ret = PTR_ERR(task); |
---|
1074 | | - else { |
---|
1075 | | - ret = task->tk_status; |
---|
1076 | | - rpc_put_task(task); |
---|
1077 | | - } |
---|
1078 | | - return ret; |
---|
| 1164 | + return nfs4_call_sync_custom(&task_setup); |
---|
1079 | 1165 | } |
---|
| 1166 | + |
---|
| 1167 | +static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
---|
| 1168 | + struct nfs_server *server, |
---|
| 1169 | + struct rpc_message *msg, |
---|
| 1170 | + struct nfs4_sequence_args *args, |
---|
| 1171 | + struct nfs4_sequence_res *res) |
---|
| 1172 | +{ |
---|
| 1173 | + return nfs4_do_call_sync(clnt, server, msg, args, res, 0); |
---|
| 1174 | +} |
---|
| 1175 | + |
---|
1080 | 1176 | |
---|
1081 | 1177 | int nfs4_call_sync(struct rpc_clnt *clnt, |
---|
1082 | 1178 | struct nfs_server *server, |
---|
.. | .. |
---|
1104 | 1200 | } |
---|
1105 | 1201 | |
---|
1106 | 1202 | static void |
---|
1107 | | -update_changeattr_locked(struct inode *dir, struct nfs4_change_info *cinfo, |
---|
| 1203 | +nfs4_update_changeattr_locked(struct inode *inode, |
---|
| 1204 | + struct nfs4_change_info *cinfo, |
---|
1108 | 1205 | unsigned long timestamp, unsigned long cache_validity) |
---|
1109 | 1206 | { |
---|
1110 | | - struct nfs_inode *nfsi = NFS_I(dir); |
---|
| 1207 | + struct nfs_inode *nfsi = NFS_I(inode); |
---|
1111 | 1208 | |
---|
1112 | 1209 | nfsi->cache_validity |= NFS_INO_INVALID_CTIME |
---|
1113 | 1210 | | NFS_INO_INVALID_MTIME |
---|
1114 | | - | NFS_INO_INVALID_DATA |
---|
1115 | 1211 | | cache_validity; |
---|
1116 | | - if (cinfo->atomic && cinfo->before == inode_peek_iversion_raw(dir)) { |
---|
| 1212 | + |
---|
| 1213 | + if (cinfo->atomic && cinfo->before == inode_peek_iversion_raw(inode)) { |
---|
1117 | 1214 | nfsi->cache_validity &= ~NFS_INO_REVAL_PAGECACHE; |
---|
1118 | 1215 | nfsi->attrtimeo_timestamp = jiffies; |
---|
1119 | 1216 | } else { |
---|
1120 | | - nfs_force_lookup_revalidate(dir); |
---|
1121 | | - if (cinfo->before != inode_peek_iversion_raw(dir)) |
---|
| 1217 | + if (S_ISDIR(inode->i_mode)) { |
---|
| 1218 | + nfsi->cache_validity |= NFS_INO_INVALID_DATA; |
---|
| 1219 | + nfs_force_lookup_revalidate(inode); |
---|
| 1220 | + } else { |
---|
| 1221 | + if (!NFS_PROTO(inode)->have_delegation(inode, |
---|
| 1222 | + FMODE_READ)) |
---|
| 1223 | + nfsi->cache_validity |= NFS_INO_REVAL_PAGECACHE; |
---|
| 1224 | + } |
---|
| 1225 | + |
---|
| 1226 | + if (cinfo->before != inode_peek_iversion_raw(inode)) |
---|
1122 | 1227 | nfsi->cache_validity |= NFS_INO_INVALID_ACCESS | |
---|
1123 | | - NFS_INO_INVALID_ACL; |
---|
| 1228 | + NFS_INO_INVALID_ACL | |
---|
| 1229 | + NFS_INO_INVALID_XATTR; |
---|
1124 | 1230 | } |
---|
1125 | | - inode_set_iversion_raw(dir, cinfo->after); |
---|
| 1231 | + inode_set_iversion_raw(inode, cinfo->after); |
---|
1126 | 1232 | nfsi->read_cache_jiffies = timestamp; |
---|
1127 | 1233 | nfsi->attr_gencount = nfs_inc_attr_generation_counter(); |
---|
1128 | 1234 | nfsi->cache_validity &= ~NFS_INO_INVALID_CHANGE; |
---|
1129 | | - nfs_fscache_invalidate(dir); |
---|
| 1235 | + |
---|
| 1236 | + if (nfsi->cache_validity & NFS_INO_INVALID_DATA) |
---|
| 1237 | + nfs_fscache_invalidate(inode); |
---|
1130 | 1238 | } |
---|
1131 | 1239 | |
---|
1132 | | -static void |
---|
1133 | | -update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo, |
---|
| 1240 | +void |
---|
| 1241 | +nfs4_update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo, |
---|
1134 | 1242 | unsigned long timestamp, unsigned long cache_validity) |
---|
1135 | 1243 | { |
---|
1136 | 1244 | spin_lock(&dir->i_lock); |
---|
1137 | | - update_changeattr_locked(dir, cinfo, timestamp, cache_validity); |
---|
| 1245 | + nfs4_update_changeattr_locked(dir, cinfo, timestamp, cache_validity); |
---|
1138 | 1246 | spin_unlock(&dir->i_lock); |
---|
1139 | 1247 | } |
---|
1140 | 1248 | |
---|
.. | .. |
---|
1154 | 1262 | server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1; |
---|
1155 | 1263 | exception->retry = 1; |
---|
1156 | 1264 | return true; |
---|
| 1265 | +} |
---|
| 1266 | + |
---|
| 1267 | +static fmode_t _nfs4_ctx_to_accessmode(const struct nfs_open_context *ctx) |
---|
| 1268 | +{ |
---|
| 1269 | + return ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); |
---|
| 1270 | +} |
---|
| 1271 | + |
---|
| 1272 | +static fmode_t _nfs4_ctx_to_openmode(const struct nfs_open_context *ctx) |
---|
| 1273 | +{ |
---|
| 1274 | + fmode_t ret = ctx->mode & (FMODE_READ|FMODE_WRITE); |
---|
| 1275 | + |
---|
| 1276 | + return (ctx->mode & FMODE_EXEC) ? FMODE_READ | ret : ret; |
---|
1157 | 1277 | } |
---|
1158 | 1278 | |
---|
1159 | 1279 | static u32 |
---|
.. | .. |
---|
1275 | 1395 | NFS4_ACCESS_MODIFY | |
---|
1276 | 1396 | NFS4_ACCESS_EXTEND | |
---|
1277 | 1397 | NFS4_ACCESS_EXECUTE; |
---|
| 1398 | +#ifdef CONFIG_NFS_V4_2 |
---|
| 1399 | + if (server->caps & NFS_CAP_XATTR) |
---|
| 1400 | + p->o_arg.access |= NFS4_ACCESS_XAREAD | |
---|
| 1401 | + NFS4_ACCESS_XAWRITE | |
---|
| 1402 | + NFS4_ACCESS_XALIST; |
---|
| 1403 | +#endif |
---|
1278 | 1404 | } |
---|
1279 | 1405 | } |
---|
1280 | 1406 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
---|
.. | .. |
---|
1404 | 1530 | case NFS4_OPEN_CLAIM_PREVIOUS: |
---|
1405 | 1531 | if (!test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
---|
1406 | 1532 | break; |
---|
1407 | | - /* Fall through */ |
---|
| 1533 | + fallthrough; |
---|
1408 | 1534 | default: |
---|
1409 | 1535 | return 0; |
---|
1410 | 1536 | } |
---|
.. | .. |
---|
1446 | 1572 | wake_up_all(&state->waitq); |
---|
1447 | 1573 | } |
---|
1448 | 1574 | |
---|
1449 | | -static void nfs_state_log_out_of_order_open_stateid(struct nfs4_state *state, |
---|
1450 | | - const nfs4_stateid *stateid) |
---|
1451 | | -{ |
---|
1452 | | - u32 state_seqid = be32_to_cpu(state->open_stateid.seqid); |
---|
1453 | | - u32 stateid_seqid = be32_to_cpu(stateid->seqid); |
---|
1454 | | - |
---|
1455 | | - if (stateid_seqid == state_seqid + 1U || |
---|
1456 | | - (stateid_seqid == 1U && state_seqid == 0xffffffffU)) |
---|
1457 | | - nfs_state_log_update_open_stateid(state); |
---|
1458 | | - else |
---|
1459 | | - set_bit(NFS_STATE_CHANGE_WAIT, &state->flags); |
---|
1460 | | -} |
---|
1461 | | - |
---|
1462 | 1575 | static void nfs_test_and_clear_all_open_stateid(struct nfs4_state *state) |
---|
1463 | 1576 | { |
---|
1464 | 1577 | struct nfs_client *clp = state->owner->so_server->nfs_client; |
---|
.. | .. |
---|
1484 | 1597 | * i.e. The stateid seqids have to be initialised to 1, and |
---|
1485 | 1598 | * are then incremented on every state transition. |
---|
1486 | 1599 | */ |
---|
1487 | | -static bool nfs_need_update_open_stateid(struct nfs4_state *state, |
---|
| 1600 | +static bool nfs_stateid_is_sequential(struct nfs4_state *state, |
---|
1488 | 1601 | const nfs4_stateid *stateid) |
---|
1489 | 1602 | { |
---|
1490 | | - if (test_bit(NFS_OPEN_STATE, &state->flags) == 0 || |
---|
1491 | | - !nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
---|
1492 | | - if (stateid->seqid == cpu_to_be32(1)) |
---|
1493 | | - nfs_state_log_update_open_stateid(state); |
---|
1494 | | - else |
---|
1495 | | - set_bit(NFS_STATE_CHANGE_WAIT, &state->flags); |
---|
1496 | | - return true; |
---|
| 1603 | + if (test_bit(NFS_OPEN_STATE, &state->flags)) { |
---|
| 1604 | + /* The common case - we're updating to a new sequence number */ |
---|
| 1605 | + if (nfs4_stateid_match_other(stateid, &state->open_stateid)) { |
---|
| 1606 | + if (nfs4_stateid_is_next(&state->open_stateid, stateid)) |
---|
| 1607 | + return true; |
---|
| 1608 | + return false; |
---|
| 1609 | + } |
---|
| 1610 | + /* The server returned a new stateid */ |
---|
1497 | 1611 | } |
---|
1498 | | - |
---|
1499 | | - if (nfs4_stateid_is_newer(stateid, &state->open_stateid)) { |
---|
1500 | | - nfs_state_log_out_of_order_open_stateid(state, stateid); |
---|
| 1612 | + /* This is the first OPEN in this generation */ |
---|
| 1613 | + if (stateid->seqid == cpu_to_be32(1)) |
---|
1501 | 1614 | return true; |
---|
1502 | | - } |
---|
1503 | 1615 | return false; |
---|
1504 | 1616 | } |
---|
1505 | 1617 | |
---|
.. | .. |
---|
1563 | 1675 | |
---|
1564 | 1676 | static void nfs_set_open_stateid_locked(struct nfs4_state *state, |
---|
1565 | 1677 | const nfs4_stateid *stateid, nfs4_stateid *freeme) |
---|
| 1678 | + __must_hold(&state->owner->so_lock) |
---|
| 1679 | + __must_hold(&state->seqlock) |
---|
| 1680 | + __must_hold(RCU) |
---|
| 1681 | + |
---|
1566 | 1682 | { |
---|
1567 | 1683 | DEFINE_WAIT(wait); |
---|
1568 | 1684 | int status = 0; |
---|
1569 | 1685 | for (;;) { |
---|
1570 | 1686 | |
---|
1571 | | - if (!nfs_need_update_open_stateid(state, stateid)) |
---|
1572 | | - return; |
---|
1573 | | - if (!test_bit(NFS_STATE_CHANGE_WAIT, &state->flags)) |
---|
| 1687 | + if (nfs_stateid_is_sequential(state, stateid)) |
---|
1574 | 1688 | break; |
---|
| 1689 | + |
---|
1575 | 1690 | if (status) |
---|
1576 | 1691 | break; |
---|
1577 | 1692 | /* Rely on seqids for serialisation with NFSv4.0 */ |
---|
1578 | 1693 | if (!nfs4_has_session(NFS_SERVER(state->inode)->nfs_client)) |
---|
1579 | 1694 | break; |
---|
1580 | 1695 | |
---|
| 1696 | + set_bit(NFS_STATE_CHANGE_WAIT, &state->flags); |
---|
1581 | 1697 | prepare_to_wait(&state->waitq, &wait, TASK_KILLABLE); |
---|
1582 | 1698 | /* |
---|
1583 | 1699 | * Ensure we process the state changes in the same order |
---|
.. | .. |
---|
1588 | 1704 | spin_unlock(&state->owner->so_lock); |
---|
1589 | 1705 | rcu_read_unlock(); |
---|
1590 | 1706 | trace_nfs4_open_stateid_update_wait(state->inode, stateid, 0); |
---|
1591 | | - if (!signal_pending(current)) { |
---|
| 1707 | + |
---|
| 1708 | + if (!fatal_signal_pending(current)) { |
---|
1592 | 1709 | if (schedule_timeout(5*HZ) == 0) |
---|
1593 | 1710 | status = -EAGAIN; |
---|
1594 | 1711 | else |
---|
.. | .. |
---|
1639 | 1756 | write_sequnlock(&state->seqlock); |
---|
1640 | 1757 | } |
---|
1641 | 1758 | |
---|
| 1759 | +static void nfs_state_clear_open_state_flags(struct nfs4_state *state) |
---|
| 1760 | +{ |
---|
| 1761 | + clear_bit(NFS_O_RDWR_STATE, &state->flags); |
---|
| 1762 | + clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
---|
| 1763 | + clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
---|
| 1764 | + clear_bit(NFS_OPEN_STATE, &state->flags); |
---|
| 1765 | +} |
---|
| 1766 | + |
---|
1642 | 1767 | static void nfs_state_set_delegation(struct nfs4_state *state, |
---|
1643 | 1768 | const nfs4_stateid *deleg_stateid, |
---|
1644 | 1769 | fmode_t fmode) |
---|
.. | .. |
---|
1661 | 1786 | write_sequnlock(&state->seqlock); |
---|
1662 | 1787 | } |
---|
1663 | 1788 | |
---|
1664 | | -static int update_open_stateid(struct nfs4_state *state, |
---|
| 1789 | +int update_open_stateid(struct nfs4_state *state, |
---|
1665 | 1790 | const nfs4_stateid *open_stateid, |
---|
1666 | 1791 | const nfs4_stateid *delegation, |
---|
1667 | 1792 | fmode_t fmode) |
---|
.. | .. |
---|
1682 | 1807 | ret = 1; |
---|
1683 | 1808 | } |
---|
1684 | 1809 | |
---|
1685 | | - deleg_cur = rcu_dereference(nfsi->delegation); |
---|
| 1810 | + deleg_cur = nfs4_get_valid_delegation(state->inode); |
---|
1686 | 1811 | if (deleg_cur == NULL) |
---|
1687 | 1812 | goto no_delegation; |
---|
1688 | 1813 | |
---|
.. | .. |
---|
1694 | 1819 | |
---|
1695 | 1820 | if (delegation == NULL) |
---|
1696 | 1821 | delegation = &deleg_cur->stateid; |
---|
1697 | | - else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
---|
| 1822 | + else if (!nfs4_stateid_match_other(&deleg_cur->stateid, delegation)) |
---|
1698 | 1823 | goto no_delegation_unlock; |
---|
1699 | 1824 | |
---|
1700 | 1825 | nfs_mark_delegation_referenced(deleg_cur); |
---|
.. | .. |
---|
1741 | 1866 | |
---|
1742 | 1867 | fmode &= FMODE_READ|FMODE_WRITE; |
---|
1743 | 1868 | rcu_read_lock(); |
---|
1744 | | - delegation = rcu_dereference(NFS_I(inode)->delegation); |
---|
| 1869 | + delegation = nfs4_get_valid_delegation(inode); |
---|
1745 | 1870 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
---|
1746 | 1871 | rcu_read_unlock(); |
---|
1747 | 1872 | return; |
---|
.. | .. |
---|
1792 | 1917 | out: |
---|
1793 | 1918 | return ERR_PTR(ret); |
---|
1794 | 1919 | out_return_state: |
---|
1795 | | - atomic_inc(&state->count); |
---|
| 1920 | + refcount_inc(&state->count); |
---|
1796 | 1921 | return state; |
---|
1797 | 1922 | } |
---|
1798 | 1923 | |
---|
.. | .. |
---|
1851 | 1976 | if (!data->rpc_done) { |
---|
1852 | 1977 | if (data->rpc_status) |
---|
1853 | 1978 | return ERR_PTR(data->rpc_status); |
---|
1854 | | - /* cached opens have already been processed */ |
---|
1855 | | - goto update; |
---|
| 1979 | + return nfs4_try_open_cached(data); |
---|
1856 | 1980 | } |
---|
1857 | 1981 | |
---|
1858 | 1982 | ret = nfs_refresh_inode(inode, &data->f_attr); |
---|
.. | .. |
---|
1861 | 1985 | |
---|
1862 | 1986 | if (data->o_res.delegation_type != 0) |
---|
1863 | 1987 | nfs4_opendata_check_deleg(data, state); |
---|
1864 | | -update: |
---|
1865 | | - update_open_stateid(state, &data->o_res.stateid, NULL, |
---|
1866 | | - data->o_arg.fmode); |
---|
1867 | | - atomic_inc(&state->count); |
---|
| 1988 | + |
---|
| 1989 | + if (!update_open_stateid(state, &data->o_res.stateid, |
---|
| 1990 | + NULL, data->o_arg.fmode)) |
---|
| 1991 | + return ERR_PTR(-EAGAIN); |
---|
| 1992 | + refcount_inc(&state->count); |
---|
1868 | 1993 | |
---|
1869 | 1994 | return state; |
---|
1870 | 1995 | } |
---|
.. | .. |
---|
1902 | 2027 | return ERR_CAST(inode); |
---|
1903 | 2028 | if (data->state != NULL && data->state->inode == inode) { |
---|
1904 | 2029 | state = data->state; |
---|
1905 | | - atomic_inc(&state->count); |
---|
| 2030 | + refcount_inc(&state->count); |
---|
1906 | 2031 | } else |
---|
1907 | 2032 | state = nfs4_get_open_state(inode, data->owner); |
---|
1908 | 2033 | iput(inode); |
---|
.. | .. |
---|
1928 | 2053 | |
---|
1929 | 2054 | if (data->o_res.delegation_type != 0) |
---|
1930 | 2055 | nfs4_opendata_check_deleg(data, state); |
---|
1931 | | - update_open_stateid(state, &data->o_res.stateid, NULL, |
---|
1932 | | - data->o_arg.fmode); |
---|
| 2056 | + if (!update_open_stateid(state, &data->o_res.stateid, |
---|
| 2057 | + NULL, data->o_arg.fmode)) { |
---|
| 2058 | + nfs4_put_open_state(state); |
---|
| 2059 | + state = ERR_PTR(-EAGAIN); |
---|
| 2060 | + } |
---|
1933 | 2061 | out: |
---|
1934 | 2062 | nfs_release_seqid(data->o_arg.seqid); |
---|
1935 | 2063 | return state; |
---|
.. | .. |
---|
1948 | 2076 | return ret; |
---|
1949 | 2077 | } |
---|
1950 | 2078 | |
---|
1951 | | -static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
---|
| 2079 | +static struct nfs_open_context * |
---|
| 2080 | +nfs4_state_find_open_context_mode(struct nfs4_state *state, fmode_t mode) |
---|
1952 | 2081 | { |
---|
1953 | 2082 | struct nfs_inode *nfsi = NFS_I(state->inode); |
---|
1954 | 2083 | struct nfs_open_context *ctx; |
---|
1955 | 2084 | |
---|
1956 | | - spin_lock(&state->inode->i_lock); |
---|
1957 | | - list_for_each_entry(ctx, &nfsi->open_files, list) { |
---|
| 2085 | + rcu_read_lock(); |
---|
| 2086 | + list_for_each_entry_rcu(ctx, &nfsi->open_files, list) { |
---|
1958 | 2087 | if (ctx->state != state) |
---|
1959 | 2088 | continue; |
---|
1960 | | - get_nfs_open_context(ctx); |
---|
1961 | | - spin_unlock(&state->inode->i_lock); |
---|
| 2089 | + if ((ctx->mode & mode) != mode) |
---|
| 2090 | + continue; |
---|
| 2091 | + if (!get_nfs_open_context(ctx)) |
---|
| 2092 | + continue; |
---|
| 2093 | + rcu_read_unlock(); |
---|
1962 | 2094 | return ctx; |
---|
1963 | 2095 | } |
---|
1964 | | - spin_unlock(&state->inode->i_lock); |
---|
| 2096 | + rcu_read_unlock(); |
---|
1965 | 2097 | return ERR_PTR(-ENOENT); |
---|
| 2098 | +} |
---|
| 2099 | + |
---|
| 2100 | +static struct nfs_open_context * |
---|
| 2101 | +nfs4_state_find_open_context(struct nfs4_state *state) |
---|
| 2102 | +{ |
---|
| 2103 | + struct nfs_open_context *ctx; |
---|
| 2104 | + |
---|
| 2105 | + ctx = nfs4_state_find_open_context_mode(state, FMODE_READ|FMODE_WRITE); |
---|
| 2106 | + if (!IS_ERR(ctx)) |
---|
| 2107 | + return ctx; |
---|
| 2108 | + ctx = nfs4_state_find_open_context_mode(state, FMODE_WRITE); |
---|
| 2109 | + if (!IS_ERR(ctx)) |
---|
| 2110 | + return ctx; |
---|
| 2111 | + return nfs4_state_find_open_context_mode(state, FMODE_READ); |
---|
1966 | 2112 | } |
---|
1967 | 2113 | |
---|
1968 | 2114 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, |
---|
.. | .. |
---|
1975 | 2121 | if (opendata == NULL) |
---|
1976 | 2122 | return ERR_PTR(-ENOMEM); |
---|
1977 | 2123 | opendata->state = state; |
---|
1978 | | - atomic_inc(&state->count); |
---|
| 2124 | + refcount_inc(&state->count); |
---|
1979 | 2125 | return opendata; |
---|
1980 | 2126 | } |
---|
1981 | 2127 | |
---|
1982 | 2128 | static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, |
---|
1983 | | - fmode_t fmode) |
---|
| 2129 | + fmode_t fmode) |
---|
1984 | 2130 | { |
---|
1985 | 2131 | struct nfs4_state *newstate; |
---|
| 2132 | + struct nfs_server *server = NFS_SB(opendata->dentry->d_sb); |
---|
| 2133 | + int openflags = opendata->o_arg.open_flags; |
---|
1986 | 2134 | int ret; |
---|
1987 | 2135 | |
---|
1988 | 2136 | if (!nfs4_mode_match_open_stateid(opendata->state, fmode)) |
---|
1989 | 2137 | return 0; |
---|
1990 | | - opendata->o_arg.open_flags = 0; |
---|
1991 | 2138 | opendata->o_arg.fmode = fmode; |
---|
1992 | | - opendata->o_arg.share_access = nfs4_map_atomic_open_share( |
---|
1993 | | - NFS_SB(opendata->dentry->d_sb), |
---|
1994 | | - fmode, 0); |
---|
| 2139 | + opendata->o_arg.share_access = |
---|
| 2140 | + nfs4_map_atomic_open_share(server, fmode, openflags); |
---|
1995 | 2141 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
---|
1996 | 2142 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
---|
1997 | 2143 | nfs4_init_opendata_res(opendata); |
---|
.. | .. |
---|
2011 | 2157 | { |
---|
2012 | 2158 | int ret; |
---|
2013 | 2159 | |
---|
2014 | | - /* Don't trigger recovery in nfs_test_and_clear_all_open_stateid */ |
---|
2015 | | - clear_bit(NFS_O_RDWR_STATE, &state->flags); |
---|
2016 | | - clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
---|
2017 | | - clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
---|
2018 | 2160 | /* memory barrier prior to reading state->n_* */ |
---|
2019 | | - clear_bit(NFS_DELEGATED_STATE, &state->flags); |
---|
2020 | | - clear_bit(NFS_OPEN_STATE, &state->flags); |
---|
2021 | 2161 | smp_rmb(); |
---|
2022 | 2162 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE); |
---|
2023 | 2163 | if (ret != 0) |
---|
.. | .. |
---|
2093 | 2233 | ctx = nfs4_state_find_open_context(state); |
---|
2094 | 2234 | if (IS_ERR(ctx)) |
---|
2095 | 2235 | return -EAGAIN; |
---|
| 2236 | + clear_bit(NFS_DELEGATED_STATE, &state->flags); |
---|
| 2237 | + nfs_state_clear_open_state_flags(state); |
---|
2096 | 2238 | ret = nfs4_do_open_reclaim(ctx, state); |
---|
2097 | 2239 | put_nfs_open_context(ctx); |
---|
2098 | 2240 | return ret; |
---|
.. | .. |
---|
2108 | 2250 | case -ENOENT: |
---|
2109 | 2251 | case -EAGAIN: |
---|
2110 | 2252 | case -ESTALE: |
---|
| 2253 | + case -ETIMEDOUT: |
---|
2111 | 2254 | break; |
---|
2112 | 2255 | case -NFS4ERR_BADSESSION: |
---|
2113 | 2256 | case -NFS4ERR_BADSLOT: |
---|
2114 | 2257 | case -NFS4ERR_BAD_HIGH_SLOT: |
---|
2115 | 2258 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
---|
2116 | 2259 | case -NFS4ERR_DEADSESSION: |
---|
2117 | | - nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
---|
2118 | 2260 | return -EAGAIN; |
---|
2119 | 2261 | case -NFS4ERR_STALE_CLIENTID: |
---|
2120 | 2262 | case -NFS4ERR_STALE_STATEID: |
---|
.. | .. |
---|
2251 | 2393 | .callback_ops = &nfs4_open_confirm_ops, |
---|
2252 | 2394 | .callback_data = data, |
---|
2253 | 2395 | .workqueue = nfsiod_workqueue, |
---|
2254 | | - .flags = RPC_TASK_ASYNC, |
---|
| 2396 | + .flags = RPC_TASK_ASYNC | RPC_TASK_CRED_NOREF, |
---|
2255 | 2397 | }; |
---|
2256 | 2398 | int status; |
---|
2257 | 2399 | |
---|
.. | .. |
---|
2308 | 2450 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
---|
2309 | 2451 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
---|
2310 | 2452 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
---|
2311 | | - /* Fall through */ |
---|
| 2453 | + fallthrough; |
---|
2312 | 2454 | case NFS4_OPEN_CLAIM_FH: |
---|
2313 | 2455 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
---|
2314 | 2456 | } |
---|
.. | .. |
---|
2416 | 2558 | .callback_ops = &nfs4_open_ops, |
---|
2417 | 2559 | .callback_data = data, |
---|
2418 | 2560 | .workqueue = nfsiod_workqueue, |
---|
2419 | | - .flags = RPC_TASK_ASYNC, |
---|
| 2561 | + .flags = RPC_TASK_ASYNC | RPC_TASK_CRED_NOREF, |
---|
2420 | 2562 | }; |
---|
2421 | 2563 | int status; |
---|
2422 | 2564 | |
---|
.. | .. |
---|
2428 | 2570 | if (!ctx) { |
---|
2429 | 2571 | nfs4_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1, 1); |
---|
2430 | 2572 | data->is_recover = true; |
---|
| 2573 | + task_setup_data.flags |= RPC_TASK_TIMEOUT; |
---|
2431 | 2574 | } else { |
---|
2432 | 2575 | nfs4_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1, 0); |
---|
2433 | 2576 | pnfs_lgopen_prepare(data, ctx); |
---|
.. | .. |
---|
2472 | 2615 | * Note that in the non-execute case, we want to turn off permission |
---|
2473 | 2616 | * checking if we just created a new file (POSIX open() semantics). |
---|
2474 | 2617 | */ |
---|
2475 | | -static int nfs4_opendata_access(struct rpc_cred *cred, |
---|
| 2618 | +static int nfs4_opendata_access(const struct cred *cred, |
---|
2476 | 2619 | struct nfs4_opendata *opendata, |
---|
2477 | 2620 | struct nfs4_state *state, fmode_t fmode, |
---|
2478 | 2621 | int openflags) |
---|
.. | .. |
---|
2541 | 2684 | data->file_created = true; |
---|
2542 | 2685 | if (data->file_created || |
---|
2543 | 2686 | inode_peek_iversion_raw(dir) != o_res->cinfo.after) |
---|
2544 | | - update_changeattr(dir, &o_res->cinfo, |
---|
2545 | | - o_res->f_attr->time_start, 0); |
---|
| 2687 | + nfs4_update_changeattr(dir, &o_res->cinfo, |
---|
| 2688 | + o_res->f_attr->time_start, |
---|
| 2689 | + NFS_INO_INVALID_DATA); |
---|
2546 | 2690 | } |
---|
2547 | 2691 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
---|
2548 | 2692 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
---|
.. | .. |
---|
2569 | 2713 | struct nfs4_opendata *opendata; |
---|
2570 | 2714 | int ret; |
---|
2571 | 2715 | |
---|
2572 | | - opendata = nfs4_open_recoverdata_alloc(ctx, state, |
---|
2573 | | - NFS4_OPEN_CLAIM_FH); |
---|
| 2716 | + opendata = nfs4_open_recoverdata_alloc(ctx, state, NFS4_OPEN_CLAIM_FH); |
---|
2574 | 2717 | if (IS_ERR(opendata)) |
---|
2575 | 2718 | return PTR_ERR(opendata); |
---|
| 2719 | + /* |
---|
| 2720 | + * We're not recovering a delegation, so ask for no delegation. |
---|
| 2721 | + * Otherwise the recovery thread could deadlock with an outstanding |
---|
| 2722 | + * delegation return. |
---|
| 2723 | + */ |
---|
| 2724 | + opendata->o_arg.open_flags = O_DIRECT; |
---|
2576 | 2725 | ret = nfs4_open_recover(opendata, state); |
---|
2577 | 2726 | if (ret == -ESTALE) |
---|
2578 | 2727 | d_drop(ctx->dentry); |
---|
.. | .. |
---|
2634 | 2783 | { |
---|
2635 | 2784 | /* NFSv4.0 doesn't allow for delegation recovery on open expire */ |
---|
2636 | 2785 | nfs40_clear_delegation_stateid(state); |
---|
| 2786 | + nfs_state_clear_open_state_flags(state); |
---|
2637 | 2787 | return nfs4_open_expired(sp, state); |
---|
2638 | 2788 | } |
---|
2639 | 2789 | |
---|
2640 | 2790 | static int nfs40_test_and_free_expired_stateid(struct nfs_server *server, |
---|
2641 | 2791 | nfs4_stateid *stateid, |
---|
2642 | | - struct rpc_cred *cred) |
---|
| 2792 | + const struct cred *cred) |
---|
2643 | 2793 | { |
---|
2644 | 2794 | return -NFS4ERR_BAD_STATEID; |
---|
2645 | 2795 | } |
---|
.. | .. |
---|
2647 | 2797 | #if defined(CONFIG_NFS_V4_1) |
---|
2648 | 2798 | static int nfs41_test_and_free_expired_stateid(struct nfs_server *server, |
---|
2649 | 2799 | nfs4_stateid *stateid, |
---|
2650 | | - struct rpc_cred *cred) |
---|
| 2800 | + const struct cred *cred) |
---|
2651 | 2801 | { |
---|
2652 | 2802 | int status; |
---|
2653 | 2803 | |
---|
.. | .. |
---|
2676 | 2826 | return -NFS4ERR_EXPIRED; |
---|
2677 | 2827 | } |
---|
2678 | 2828 | |
---|
2679 | | -static void nfs41_check_delegation_stateid(struct nfs4_state *state) |
---|
| 2829 | +static int nfs41_check_delegation_stateid(struct nfs4_state *state) |
---|
2680 | 2830 | { |
---|
2681 | 2831 | struct nfs_server *server = NFS_SERVER(state->inode); |
---|
2682 | 2832 | nfs4_stateid stateid; |
---|
2683 | 2833 | struct nfs_delegation *delegation; |
---|
2684 | | - struct rpc_cred *cred; |
---|
2685 | | - int status; |
---|
| 2834 | + const struct cred *cred = NULL; |
---|
| 2835 | + int status, ret = NFS_OK; |
---|
2686 | 2836 | |
---|
2687 | 2837 | /* Get the delegation credential for use by test/free_stateid */ |
---|
2688 | 2838 | rcu_read_lock(); |
---|
.. | .. |
---|
2690 | 2840 | if (delegation == NULL) { |
---|
2691 | 2841 | rcu_read_unlock(); |
---|
2692 | 2842 | nfs_state_clear_delegation(state); |
---|
2693 | | - return; |
---|
| 2843 | + return NFS_OK; |
---|
2694 | 2844 | } |
---|
2695 | 2845 | |
---|
| 2846 | + spin_lock(&delegation->lock); |
---|
2696 | 2847 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
---|
2697 | | - if (test_bit(NFS_DELEGATION_REVOKED, &delegation->flags)) { |
---|
2698 | | - rcu_read_unlock(); |
---|
2699 | | - nfs_state_clear_delegation(state); |
---|
2700 | | - return; |
---|
2701 | | - } |
---|
2702 | 2848 | |
---|
2703 | 2849 | if (!test_and_clear_bit(NFS_DELEGATION_TEST_EXPIRED, |
---|
2704 | 2850 | &delegation->flags)) { |
---|
| 2851 | + spin_unlock(&delegation->lock); |
---|
2705 | 2852 | rcu_read_unlock(); |
---|
2706 | | - return; |
---|
| 2853 | + return NFS_OK; |
---|
2707 | 2854 | } |
---|
2708 | 2855 | |
---|
2709 | | - cred = get_rpccred(delegation->cred); |
---|
| 2856 | + if (delegation->cred) |
---|
| 2857 | + cred = get_cred(delegation->cred); |
---|
| 2858 | + spin_unlock(&delegation->lock); |
---|
2710 | 2859 | rcu_read_unlock(); |
---|
2711 | 2860 | status = nfs41_test_and_free_expired_stateid(server, &stateid, cred); |
---|
2712 | 2861 | trace_nfs4_test_delegation_stateid(state, NULL, status); |
---|
2713 | 2862 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) |
---|
2714 | 2863 | nfs_finish_clear_delegation_stateid(state, &stateid); |
---|
| 2864 | + else |
---|
| 2865 | + ret = status; |
---|
2715 | 2866 | |
---|
2716 | | - put_rpccred(cred); |
---|
| 2867 | + put_cred(cred); |
---|
| 2868 | + return ret; |
---|
| 2869 | +} |
---|
| 2870 | + |
---|
| 2871 | +static void nfs41_delegation_recover_stateid(struct nfs4_state *state) |
---|
| 2872 | +{ |
---|
| 2873 | + nfs4_stateid tmp; |
---|
| 2874 | + |
---|
| 2875 | + if (test_bit(NFS_DELEGATED_STATE, &state->flags) && |
---|
| 2876 | + nfs4_copy_delegation_stateid(state->inode, state->state, |
---|
| 2877 | + &tmp, NULL) && |
---|
| 2878 | + nfs4_stateid_match_other(&state->stateid, &tmp)) |
---|
| 2879 | + nfs_state_set_delegation(state, &tmp, state->state); |
---|
| 2880 | + else |
---|
| 2881 | + nfs_state_clear_delegation(state); |
---|
2717 | 2882 | } |
---|
2718 | 2883 | |
---|
2719 | 2884 | /** |
---|
.. | .. |
---|
2736 | 2901 | spin_lock(&state->state_lock); |
---|
2737 | 2902 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
---|
2738 | 2903 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
---|
2739 | | - struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
---|
| 2904 | + const struct cred *cred = lsp->ls_state->owner->so_cred; |
---|
2740 | 2905 | |
---|
2741 | 2906 | refcount_inc(&lsp->ls_count); |
---|
2742 | 2907 | spin_unlock(&state->state_lock); |
---|
.. | .. |
---|
2780 | 2945 | { |
---|
2781 | 2946 | struct nfs_server *server = NFS_SERVER(state->inode); |
---|
2782 | 2947 | nfs4_stateid *stateid = &state->open_stateid; |
---|
2783 | | - struct rpc_cred *cred = state->owner->so_cred; |
---|
| 2948 | + const struct cred *cred = state->owner->so_cred; |
---|
2784 | 2949 | int status; |
---|
2785 | 2950 | |
---|
2786 | | - if (test_bit(NFS_OPEN_STATE, &state->flags) == 0) { |
---|
2787 | | - if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) { |
---|
2788 | | - if (nfs4_have_delegation(state->inode, state->state)) |
---|
2789 | | - return NFS_OK; |
---|
2790 | | - return -NFS4ERR_OPENMODE; |
---|
2791 | | - } |
---|
| 2951 | + if (test_bit(NFS_OPEN_STATE, &state->flags) == 0) |
---|
2792 | 2952 | return -NFS4ERR_BAD_STATEID; |
---|
2793 | | - } |
---|
2794 | 2953 | status = nfs41_test_and_free_expired_stateid(server, stateid, cred); |
---|
2795 | 2954 | trace_nfs4_test_open_stateid(state, NULL, status); |
---|
2796 | 2955 | if (status == -NFS4ERR_EXPIRED || status == -NFS4ERR_BAD_STATEID) { |
---|
2797 | | - clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
---|
2798 | | - clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
---|
2799 | | - clear_bit(NFS_O_RDWR_STATE, &state->flags); |
---|
2800 | | - clear_bit(NFS_OPEN_STATE, &state->flags); |
---|
| 2956 | + nfs_state_clear_open_state_flags(state); |
---|
2801 | 2957 | stateid->type = NFS4_INVALID_STATEID_TYPE; |
---|
2802 | 2958 | return status; |
---|
2803 | 2959 | } |
---|
.. | .. |
---|
2810 | 2966 | { |
---|
2811 | 2967 | int status; |
---|
2812 | 2968 | |
---|
2813 | | - nfs41_check_delegation_stateid(state); |
---|
| 2969 | + status = nfs41_check_delegation_stateid(state); |
---|
| 2970 | + if (status != NFS_OK) |
---|
| 2971 | + return status; |
---|
| 2972 | + nfs41_delegation_recover_stateid(state); |
---|
| 2973 | + |
---|
2814 | 2974 | status = nfs41_check_expired_locks(state); |
---|
2815 | 2975 | if (status != NFS_OK) |
---|
2816 | 2976 | return status; |
---|
.. | .. |
---|
2863 | 3023 | } |
---|
2864 | 3024 | |
---|
2865 | 3025 | static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, |
---|
2866 | | - fmode_t fmode, |
---|
2867 | | - int flags, |
---|
2868 | | - struct nfs_open_context *ctx) |
---|
| 3026 | + int flags, struct nfs_open_context *ctx) |
---|
2869 | 3027 | { |
---|
2870 | 3028 | struct nfs4_state_owner *sp = opendata->owner; |
---|
2871 | 3029 | struct nfs_server *server = sp->so_server; |
---|
2872 | 3030 | struct dentry *dentry; |
---|
2873 | 3031 | struct nfs4_state *state; |
---|
| 3032 | + fmode_t acc_mode = _nfs4_ctx_to_accessmode(ctx); |
---|
| 3033 | + struct inode *dir = d_inode(opendata->dir); |
---|
| 3034 | + unsigned long dir_verifier; |
---|
2874 | 3035 | unsigned int seq; |
---|
2875 | 3036 | int ret; |
---|
2876 | 3037 | |
---|
2877 | | - seq = raw_seqcount_begin(&sp->so_reclaim_seqlock.seqcount); |
---|
| 3038 | + seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); |
---|
| 3039 | + dir_verifier = nfs_save_change_attribute(dir); |
---|
2878 | 3040 | |
---|
2879 | 3041 | ret = _nfs4_proc_open(opendata, ctx); |
---|
2880 | 3042 | if (ret != 0) |
---|
.. | .. |
---|
2902 | 3064 | dput(ctx->dentry); |
---|
2903 | 3065 | ctx->dentry = dentry = alias; |
---|
2904 | 3066 | } |
---|
2905 | | - nfs_set_verifier(dentry, |
---|
2906 | | - nfs_save_change_attribute(d_inode(opendata->dir))); |
---|
| 3067 | + } |
---|
| 3068 | + |
---|
| 3069 | + switch(opendata->o_arg.claim) { |
---|
| 3070 | + default: |
---|
| 3071 | + break; |
---|
| 3072 | + case NFS4_OPEN_CLAIM_NULL: |
---|
| 3073 | + case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
---|
| 3074 | + case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
---|
| 3075 | + if (!opendata->rpc_done) |
---|
| 3076 | + break; |
---|
| 3077 | + if (opendata->o_res.delegation_type != 0) |
---|
| 3078 | + dir_verifier = nfs_save_change_attribute(dir); |
---|
| 3079 | + nfs_set_verifier(dentry, dir_verifier); |
---|
2907 | 3080 | } |
---|
2908 | 3081 | |
---|
2909 | 3082 | /* Parse layoutget results before we check for access */ |
---|
2910 | 3083 | pnfs_parse_lgopen(state->inode, opendata->lgp, ctx); |
---|
2911 | 3084 | |
---|
2912 | | - ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags); |
---|
| 3085 | + ret = nfs4_opendata_access(sp->so_cred, opendata, state, |
---|
| 3086 | + acc_mode, flags); |
---|
2913 | 3087 | if (ret != 0) |
---|
2914 | 3088 | goto out; |
---|
2915 | 3089 | |
---|
2916 | 3090 | if (d_inode(dentry) == state->inode) { |
---|
2917 | 3091 | nfs_inode_attach_open_context(ctx); |
---|
2918 | | - if (read_seqretry(&sp->so_reclaim_seqlock, seq)) |
---|
| 3092 | + if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) |
---|
2919 | 3093 | nfs4_schedule_stateid_recovery(server, state); |
---|
2920 | 3094 | } |
---|
2921 | 3095 | |
---|
2922 | 3096 | out: |
---|
2923 | | - if (!opendata->cancelled) |
---|
| 3097 | + if (!opendata->cancelled) { |
---|
| 3098 | + if (opendata->lgp) { |
---|
| 3099 | + nfs4_lgopen_release(opendata->lgp); |
---|
| 3100 | + opendata->lgp = NULL; |
---|
| 3101 | + } |
---|
2924 | 3102 | nfs4_sequence_free_slot(&opendata->o_res.seq_res); |
---|
| 3103 | + } |
---|
2925 | 3104 | return ret; |
---|
2926 | 3105 | } |
---|
2927 | 3106 | |
---|
.. | .. |
---|
2939 | 3118 | struct nfs_server *server = NFS_SERVER(dir); |
---|
2940 | 3119 | struct nfs4_opendata *opendata; |
---|
2941 | 3120 | struct dentry *dentry = ctx->dentry; |
---|
2942 | | - struct rpc_cred *cred = ctx->cred; |
---|
| 3121 | + const struct cred *cred = ctx->cred; |
---|
2943 | 3122 | struct nfs4_threshold **ctx_th = &ctx->mdsthreshold; |
---|
2944 | | - fmode_t fmode = ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC); |
---|
| 3123 | + fmode_t fmode = _nfs4_ctx_to_openmode(ctx); |
---|
2945 | 3124 | enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL; |
---|
2946 | 3125 | struct iattr *sattr = c->sattr; |
---|
2947 | 3126 | struct nfs4_label *label = c->label; |
---|
.. | .. |
---|
2987 | 3166 | if (d_really_is_positive(dentry)) |
---|
2988 | 3167 | opendata->state = nfs4_get_open_state(d_inode(dentry), sp); |
---|
2989 | 3168 | |
---|
2990 | | - status = _nfs4_open_and_get_state(opendata, fmode, flags, ctx); |
---|
| 3169 | + status = _nfs4_open_and_get_state(opendata, flags, ctx); |
---|
2991 | 3170 | if (status != 0) |
---|
2992 | 3171 | goto err_free_label; |
---|
2993 | 3172 | state = ctx->state; |
---|
.. | .. |
---|
3047 | 3226 | int *opened) |
---|
3048 | 3227 | { |
---|
3049 | 3228 | struct nfs_server *server = NFS_SERVER(dir); |
---|
3050 | | - struct nfs4_exception exception = { }; |
---|
| 3229 | + struct nfs4_exception exception = { |
---|
| 3230 | + .interruptible = true, |
---|
| 3231 | + }; |
---|
3051 | 3232 | struct nfs4_state *res; |
---|
3052 | 3233 | struct nfs4_open_createattrs c = { |
---|
3053 | 3234 | .label = label, |
---|
.. | .. |
---|
3114 | 3295 | static int _nfs4_do_setattr(struct inode *inode, |
---|
3115 | 3296 | struct nfs_setattrargs *arg, |
---|
3116 | 3297 | struct nfs_setattrres *res, |
---|
3117 | | - struct rpc_cred *cred, |
---|
| 3298 | + const struct cred *cred, |
---|
3118 | 3299 | struct nfs_open_context *ctx) |
---|
3119 | 3300 | { |
---|
3120 | 3301 | struct nfs_server *server = NFS_SERVER(inode); |
---|
.. | .. |
---|
3124 | 3305 | .rpc_resp = res, |
---|
3125 | 3306 | .rpc_cred = cred, |
---|
3126 | 3307 | }; |
---|
3127 | | - struct rpc_cred *delegation_cred = NULL; |
---|
| 3308 | + const struct cred *delegation_cred = NULL; |
---|
3128 | 3309 | unsigned long timestamp = jiffies; |
---|
3129 | 3310 | bool truncate; |
---|
3130 | 3311 | int status; |
---|
.. | .. |
---|
3152 | 3333 | nfs_put_lock_context(l_ctx); |
---|
3153 | 3334 | if (status == -EIO) |
---|
3154 | 3335 | return -EBADF; |
---|
| 3336 | + else if (status == -EAGAIN) |
---|
| 3337 | + goto zero_stateid; |
---|
3155 | 3338 | } else { |
---|
3156 | 3339 | zero_stateid: |
---|
3157 | 3340 | nfs4_stateid_copy(&arg->stateid, &zero_stateid); |
---|
.. | .. |
---|
3161 | 3344 | |
---|
3162 | 3345 | status = nfs4_call_sync(server->client, server, &msg, &arg->seq_args, &res->seq_res, 1); |
---|
3163 | 3346 | |
---|
3164 | | - put_rpccred(delegation_cred); |
---|
| 3347 | + put_cred(delegation_cred); |
---|
3165 | 3348 | if (status == 0 && ctx != NULL) |
---|
3166 | 3349 | renew_lease(server, timestamp); |
---|
3167 | 3350 | trace_nfs4_setattr(inode, &arg->stateid, status); |
---|
3168 | 3351 | return status; |
---|
3169 | 3352 | } |
---|
3170 | 3353 | |
---|
3171 | | -static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
---|
| 3354 | +static int nfs4_do_setattr(struct inode *inode, const struct cred *cred, |
---|
3172 | 3355 | struct nfs_fattr *fattr, struct iattr *sattr, |
---|
3173 | 3356 | struct nfs_open_context *ctx, struct nfs4_label *ilabel, |
---|
3174 | 3357 | struct nfs4_label *olabel) |
---|
.. | .. |
---|
3232 | 3415 | return pnfs_wait_on_layoutreturn(inode, task); |
---|
3233 | 3416 | } |
---|
3234 | 3417 | |
---|
| 3418 | +/* |
---|
| 3419 | + * Update the seqid of an open stateid |
---|
| 3420 | + */ |
---|
| 3421 | +static void nfs4_sync_open_stateid(nfs4_stateid *dst, |
---|
| 3422 | + struct nfs4_state *state) |
---|
| 3423 | +{ |
---|
| 3424 | + __be32 seqid_open; |
---|
| 3425 | + u32 dst_seqid; |
---|
| 3426 | + int seq; |
---|
| 3427 | + |
---|
| 3428 | + for (;;) { |
---|
| 3429 | + if (!nfs4_valid_open_stateid(state)) |
---|
| 3430 | + break; |
---|
| 3431 | + seq = read_seqbegin(&state->seqlock); |
---|
| 3432 | + if (!nfs4_state_match_open_stateid_other(state, dst)) { |
---|
| 3433 | + nfs4_stateid_copy(dst, &state->open_stateid); |
---|
| 3434 | + if (read_seqretry(&state->seqlock, seq)) |
---|
| 3435 | + continue; |
---|
| 3436 | + break; |
---|
| 3437 | + } |
---|
| 3438 | + seqid_open = state->open_stateid.seqid; |
---|
| 3439 | + if (read_seqretry(&state->seqlock, seq)) |
---|
| 3440 | + continue; |
---|
| 3441 | + |
---|
| 3442 | + dst_seqid = be32_to_cpu(dst->seqid); |
---|
| 3443 | + if ((s32)(dst_seqid - be32_to_cpu(seqid_open)) < 0) |
---|
| 3444 | + dst->seqid = seqid_open; |
---|
| 3445 | + break; |
---|
| 3446 | + } |
---|
| 3447 | +} |
---|
| 3448 | + |
---|
| 3449 | +/* |
---|
| 3450 | + * Update the seqid of an open stateid after receiving |
---|
| 3451 | + * NFS4ERR_OLD_STATEID |
---|
| 3452 | + */ |
---|
| 3453 | +static bool nfs4_refresh_open_old_stateid(nfs4_stateid *dst, |
---|
| 3454 | + struct nfs4_state *state) |
---|
| 3455 | +{ |
---|
| 3456 | + __be32 seqid_open; |
---|
| 3457 | + u32 dst_seqid; |
---|
| 3458 | + bool ret; |
---|
| 3459 | + int seq, status = -EAGAIN; |
---|
| 3460 | + DEFINE_WAIT(wait); |
---|
| 3461 | + |
---|
| 3462 | + for (;;) { |
---|
| 3463 | + ret = false; |
---|
| 3464 | + if (!nfs4_valid_open_stateid(state)) |
---|
| 3465 | + break; |
---|
| 3466 | + seq = read_seqbegin(&state->seqlock); |
---|
| 3467 | + if (!nfs4_state_match_open_stateid_other(state, dst)) { |
---|
| 3468 | + if (read_seqretry(&state->seqlock, seq)) |
---|
| 3469 | + continue; |
---|
| 3470 | + break; |
---|
| 3471 | + } |
---|
| 3472 | + |
---|
| 3473 | + write_seqlock(&state->seqlock); |
---|
| 3474 | + seqid_open = state->open_stateid.seqid; |
---|
| 3475 | + |
---|
| 3476 | + dst_seqid = be32_to_cpu(dst->seqid); |
---|
| 3477 | + |
---|
| 3478 | + /* Did another OPEN bump the state's seqid? try again: */ |
---|
| 3479 | + if ((s32)(be32_to_cpu(seqid_open) - dst_seqid) > 0) { |
---|
| 3480 | + dst->seqid = seqid_open; |
---|
| 3481 | + write_sequnlock(&state->seqlock); |
---|
| 3482 | + ret = true; |
---|
| 3483 | + break; |
---|
| 3484 | + } |
---|
| 3485 | + |
---|
| 3486 | + /* server says we're behind but we haven't seen the update yet */ |
---|
| 3487 | + set_bit(NFS_STATE_CHANGE_WAIT, &state->flags); |
---|
| 3488 | + prepare_to_wait(&state->waitq, &wait, TASK_KILLABLE); |
---|
| 3489 | + write_sequnlock(&state->seqlock); |
---|
| 3490 | + trace_nfs4_close_stateid_update_wait(state->inode, dst, 0); |
---|
| 3491 | + |
---|
| 3492 | + if (fatal_signal_pending(current)) |
---|
| 3493 | + status = -EINTR; |
---|
| 3494 | + else |
---|
| 3495 | + if (schedule_timeout(5*HZ) != 0) |
---|
| 3496 | + status = 0; |
---|
| 3497 | + |
---|
| 3498 | + finish_wait(&state->waitq, &wait); |
---|
| 3499 | + |
---|
| 3500 | + if (!status) |
---|
| 3501 | + continue; |
---|
| 3502 | + if (status == -EINTR) |
---|
| 3503 | + break; |
---|
| 3504 | + |
---|
| 3505 | + /* we slept the whole 5 seconds, we must have lost a seqid */ |
---|
| 3506 | + dst->seqid = cpu_to_be32(dst_seqid + 1); |
---|
| 3507 | + ret = true; |
---|
| 3508 | + break; |
---|
| 3509 | + } |
---|
| 3510 | + |
---|
| 3511 | + return ret; |
---|
| 3512 | +} |
---|
| 3513 | + |
---|
3235 | 3514 | struct nfs4_closedata { |
---|
3236 | 3515 | struct inode *inode; |
---|
3237 | 3516 | struct nfs4_state *state; |
---|
.. | .. |
---|
3282 | 3561 | trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); |
---|
3283 | 3562 | |
---|
3284 | 3563 | /* Handle Layoutreturn errors */ |
---|
3285 | | - if (calldata->arg.lr_args && task->tk_status != 0) { |
---|
3286 | | - switch (calldata->res.lr_ret) { |
---|
3287 | | - default: |
---|
3288 | | - calldata->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
---|
3289 | | - break; |
---|
3290 | | - case 0: |
---|
3291 | | - calldata->arg.lr_args = NULL; |
---|
3292 | | - calldata->res.lr_res = NULL; |
---|
3293 | | - break; |
---|
3294 | | - case -NFS4ERR_OLD_STATEID: |
---|
3295 | | - if (nfs4_layoutreturn_refresh_stateid(&calldata->arg.lr_args->stateid, |
---|
3296 | | - &calldata->arg.lr_args->range, |
---|
3297 | | - calldata->inode)) |
---|
3298 | | - goto lr_restart; |
---|
3299 | | - /* Fallthrough */ |
---|
3300 | | - case -NFS4ERR_ADMIN_REVOKED: |
---|
3301 | | - case -NFS4ERR_DELEG_REVOKED: |
---|
3302 | | - case -NFS4ERR_EXPIRED: |
---|
3303 | | - case -NFS4ERR_BAD_STATEID: |
---|
3304 | | - case -NFS4ERR_UNKNOWN_LAYOUTTYPE: |
---|
3305 | | - case -NFS4ERR_WRONG_CRED: |
---|
3306 | | - calldata->arg.lr_args = NULL; |
---|
3307 | | - calldata->res.lr_res = NULL; |
---|
3308 | | - goto lr_restart; |
---|
3309 | | - } |
---|
3310 | | - } |
---|
| 3564 | + if (pnfs_roc_done(task, &calldata->arg.lr_args, &calldata->res.lr_res, |
---|
| 3565 | + &calldata->res.lr_ret) == -EAGAIN) |
---|
| 3566 | + goto out_restart; |
---|
3311 | 3567 | |
---|
3312 | 3568 | /* hmm. we are done with the inode, and in the process of freeing |
---|
3313 | 3569 | * the state_owner. we keep this around to process errors |
---|
.. | .. |
---|
3327 | 3583 | break; |
---|
3328 | 3584 | case -NFS4ERR_OLD_STATEID: |
---|
3329 | 3585 | /* Did we race with OPEN? */ |
---|
3330 | | - if (nfs4_refresh_open_stateid(&calldata->arg.stateid, |
---|
| 3586 | + if (nfs4_refresh_open_old_stateid(&calldata->arg.stateid, |
---|
3331 | 3587 | state)) |
---|
3332 | 3588 | goto out_restart; |
---|
3333 | 3589 | goto out_release; |
---|
.. | .. |
---|
3337 | 3593 | nfs4_free_revoked_stateid(server, |
---|
3338 | 3594 | &calldata->arg.stateid, |
---|
3339 | 3595 | task->tk_msg.rpc_cred); |
---|
3340 | | - /* Fallthrough */ |
---|
| 3596 | + fallthrough; |
---|
3341 | 3597 | case -NFS4ERR_BAD_STATEID: |
---|
3342 | | - break; |
---|
| 3598 | + if (calldata->arg.fmode == 0) |
---|
| 3599 | + break; |
---|
| 3600 | + fallthrough; |
---|
3343 | 3601 | default: |
---|
3344 | 3602 | task->tk_status = nfs4_async_handle_exception(task, |
---|
3345 | 3603 | server, task->tk_status, &exception); |
---|
.. | .. |
---|
3354 | 3612 | nfs_refresh_inode(calldata->inode, &calldata->fattr); |
---|
3355 | 3613 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
---|
3356 | 3614 | return; |
---|
3357 | | -lr_restart: |
---|
3358 | | - calldata->res.lr_ret = 0; |
---|
3359 | 3615 | out_restart: |
---|
3360 | 3616 | task->tk_status = 0; |
---|
3361 | 3617 | rpc_restart_call_prepare(task); |
---|
.. | .. |
---|
3367 | 3623 | struct nfs4_closedata *calldata = data; |
---|
3368 | 3624 | struct nfs4_state *state = calldata->state; |
---|
3369 | 3625 | struct inode *inode = calldata->inode; |
---|
| 3626 | + struct nfs_server *server = NFS_SERVER(inode); |
---|
3370 | 3627 | struct pnfs_layout_hdr *lo; |
---|
3371 | 3628 | bool is_rdonly, is_wronly, is_rdwr; |
---|
3372 | 3629 | int call_close = 0; |
---|
.. | .. |
---|
3396 | 3653 | } else if (is_rdwr) |
---|
3397 | 3654 | calldata->arg.fmode |= FMODE_READ|FMODE_WRITE; |
---|
3398 | 3655 | |
---|
3399 | | - if (!nfs4_valid_open_stateid(state) || |
---|
3400 | | - !nfs4_refresh_open_stateid(&calldata->arg.stateid, state)) |
---|
| 3656 | + nfs4_sync_open_stateid(&calldata->arg.stateid, state); |
---|
| 3657 | + if (!nfs4_valid_open_stateid(state)) |
---|
3401 | 3658 | call_close = 0; |
---|
3402 | 3659 | spin_unlock(&state->owner->so_lock); |
---|
3403 | 3660 | |
---|
.. | .. |
---|
3422 | 3679 | |
---|
3423 | 3680 | if (calldata->arg.fmode == 0 || calldata->arg.fmode == FMODE_READ) { |
---|
3424 | 3681 | /* Close-to-open cache consistency revalidation */ |
---|
3425 | | - if (!nfs4_have_delegation(inode, FMODE_READ)) |
---|
3426 | | - calldata->arg.bitmask = NFS_SERVER(inode)->cache_consistency_bitmask; |
---|
3427 | | - else |
---|
| 3682 | + if (!nfs4_have_delegation(inode, FMODE_READ)) { |
---|
| 3683 | + nfs4_bitmask_set(calldata->arg.bitmask_store, |
---|
| 3684 | + server->cache_consistency_bitmask, |
---|
| 3685 | + inode, server, NULL); |
---|
| 3686 | + calldata->arg.bitmask = calldata->arg.bitmask_store; |
---|
| 3687 | + } else |
---|
3428 | 3688 | calldata->arg.bitmask = NULL; |
---|
3429 | 3689 | } |
---|
3430 | 3690 | |
---|
.. | .. |
---|
3483 | 3743 | .rpc_message = &msg, |
---|
3484 | 3744 | .callback_ops = &nfs4_close_ops, |
---|
3485 | 3745 | .workqueue = nfsiod_workqueue, |
---|
3486 | | - .flags = RPC_TASK_ASYNC, |
---|
| 3746 | + .flags = RPC_TASK_ASYNC | RPC_TASK_CRED_NOREF, |
---|
3487 | 3747 | }; |
---|
3488 | 3748 | int status = -ENOMEM; |
---|
3489 | 3749 | |
---|
.. | .. |
---|
3543 | 3803 | int open_flags, struct iattr *attr, int *opened) |
---|
3544 | 3804 | { |
---|
3545 | 3805 | struct nfs4_state *state; |
---|
3546 | | - struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL; |
---|
| 3806 | + struct nfs4_label l, *label; |
---|
3547 | 3807 | |
---|
3548 | 3808 | label = nfs4_label_init_security(dir, ctx->dentry, attr, &l); |
---|
3549 | 3809 | |
---|
.. | .. |
---|
3562 | 3822 | if (ctx->state == NULL) |
---|
3563 | 3823 | return; |
---|
3564 | 3824 | if (is_sync) |
---|
3565 | | - nfs4_close_sync(ctx->state, ctx->mode); |
---|
| 3825 | + nfs4_close_sync(ctx->state, _nfs4_ctx_to_openmode(ctx)); |
---|
3566 | 3826 | else |
---|
3567 | | - nfs4_close_state(ctx->state, ctx->mode); |
---|
| 3827 | + nfs4_close_state(ctx->state, _nfs4_ctx_to_openmode(ctx)); |
---|
3568 | 3828 | } |
---|
3569 | 3829 | |
---|
3570 | 3830 | #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL) |
---|
3571 | 3831 | #define FATTR4_WORD2_NFS41_MASK (2*FATTR4_WORD2_SUPPATTR_EXCLCREAT - 1UL) |
---|
3572 | | -#define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_MODE_UMASK - 1UL) |
---|
| 3832 | +#define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_XATTR_SUPPORT - 1UL) |
---|
3573 | 3833 | |
---|
3574 | 3834 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
---|
3575 | 3835 | { |
---|
.. | .. |
---|
3667 | 3927 | |
---|
3668 | 3928 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
---|
3669 | 3929 | { |
---|
3670 | | - struct nfs4_exception exception = { }; |
---|
| 3930 | + struct nfs4_exception exception = { |
---|
| 3931 | + .interruptible = true, |
---|
| 3932 | + }; |
---|
3671 | 3933 | int err; |
---|
3672 | 3934 | do { |
---|
3673 | 3935 | err = nfs4_handle_exception(server, |
---|
.. | .. |
---|
3709 | 3971 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
---|
3710 | 3972 | struct nfs_fsinfo *info) |
---|
3711 | 3973 | { |
---|
3712 | | - struct nfs4_exception exception = { }; |
---|
| 3974 | + struct nfs4_exception exception = { |
---|
| 3975 | + .interruptible = true, |
---|
| 3976 | + }; |
---|
3713 | 3977 | int err; |
---|
3714 | 3978 | do { |
---|
3715 | 3979 | err = _nfs4_lookup_root(server, fhandle, info); |
---|
.. | .. |
---|
3784 | 4048 | } |
---|
3785 | 4049 | |
---|
3786 | 4050 | /* |
---|
3787 | | - * -EACCESS could mean that the user doesn't have correct permissions |
---|
| 4051 | + * -EACCES could mean that the user doesn't have correct permissions |
---|
3788 | 4052 | * to access the mount. It could also mean that we tried to mount |
---|
3789 | 4053 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
---|
3790 | 4054 | * existing mount programs don't handle -EACCES very well so it should |
---|
.. | .. |
---|
3830 | 4094 | { |
---|
3831 | 4095 | int error; |
---|
3832 | 4096 | struct nfs_fattr *fattr = info->fattr; |
---|
3833 | | - struct nfs4_label *label = NULL; |
---|
| 4097 | + struct nfs4_label *label = fattr->label; |
---|
3834 | 4098 | |
---|
3835 | 4099 | error = nfs4_server_capabilities(server, mntfh); |
---|
3836 | 4100 | if (error < 0) { |
---|
.. | .. |
---|
3838 | 4102 | return error; |
---|
3839 | 4103 | } |
---|
3840 | 4104 | |
---|
3841 | | - label = nfs4_label_alloc(server, GFP_KERNEL); |
---|
3842 | | - if (IS_ERR(label)) |
---|
3843 | | - return PTR_ERR(label); |
---|
3844 | | - |
---|
3845 | 4105 | error = nfs4_proc_getattr(server, mntfh, fattr, label, NULL); |
---|
3846 | 4106 | if (error < 0) { |
---|
3847 | 4107 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
---|
3848 | | - goto err_free_label; |
---|
| 4108 | + goto out; |
---|
3849 | 4109 | } |
---|
3850 | 4110 | |
---|
3851 | 4111 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
---|
3852 | 4112 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
---|
3853 | 4113 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
---|
3854 | 4114 | |
---|
3855 | | -err_free_label: |
---|
3856 | | - nfs4_label_free(label); |
---|
3857 | | - |
---|
| 4115 | +out: |
---|
3858 | 4116 | return error; |
---|
3859 | 4117 | } |
---|
3860 | 4118 | |
---|
.. | .. |
---|
3925 | 4183 | .rpc_argp = &args, |
---|
3926 | 4184 | .rpc_resp = &res, |
---|
3927 | 4185 | }; |
---|
| 4186 | + unsigned short task_flags = 0; |
---|
| 4187 | + |
---|
| 4188 | + /* Is this is an attribute revalidation, subject to softreval? */ |
---|
| 4189 | + if (inode && (server->flags & NFS_MOUNT_SOFTREVAL)) |
---|
| 4190 | + task_flags |= RPC_TASK_TIMEOUT; |
---|
3928 | 4191 | |
---|
3929 | 4192 | nfs4_bitmap_copy_adjust(bitmask, nfs4_bitmask(server, label), inode); |
---|
3930 | 4193 | |
---|
3931 | 4194 | nfs_fattr_init(fattr); |
---|
3932 | | - return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
---|
| 4195 | + nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 0); |
---|
| 4196 | + return nfs4_do_call_sync(server->client, server, &msg, |
---|
| 4197 | + &args.seq_args, &res.seq_res, task_flags); |
---|
3933 | 4198 | } |
---|
3934 | 4199 | |
---|
3935 | | -static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
---|
| 4200 | +int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
---|
3936 | 4201 | struct nfs_fattr *fattr, struct nfs4_label *label, |
---|
3937 | 4202 | struct inode *inode) |
---|
3938 | 4203 | { |
---|
3939 | | - struct nfs4_exception exception = { }; |
---|
| 4204 | + struct nfs4_exception exception = { |
---|
| 4205 | + .interruptible = true, |
---|
| 4206 | + }; |
---|
3940 | 4207 | int err; |
---|
3941 | 4208 | do { |
---|
3942 | 4209 | err = _nfs4_proc_getattr(server, fhandle, fattr, label, inode); |
---|
.. | .. |
---|
3969 | 4236 | struct iattr *sattr) |
---|
3970 | 4237 | { |
---|
3971 | 4238 | struct inode *inode = d_inode(dentry); |
---|
3972 | | - struct rpc_cred *cred = NULL; |
---|
| 4239 | + const struct cred *cred = NULL; |
---|
3973 | 4240 | struct nfs_open_context *ctx = NULL; |
---|
3974 | 4241 | struct nfs4_label *label = NULL; |
---|
3975 | 4242 | int status; |
---|
.. | .. |
---|
4015 | 4282 | } |
---|
4016 | 4283 | |
---|
4017 | 4284 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
---|
4018 | | - const struct qstr *name, struct nfs_fh *fhandle, |
---|
| 4285 | + struct dentry *dentry, struct nfs_fh *fhandle, |
---|
4019 | 4286 | struct nfs_fattr *fattr, struct nfs4_label *label) |
---|
4020 | 4287 | { |
---|
4021 | 4288 | struct nfs_server *server = NFS_SERVER(dir); |
---|
.. | .. |
---|
4023 | 4290 | struct nfs4_lookup_arg args = { |
---|
4024 | 4291 | .bitmask = server->attr_bitmask, |
---|
4025 | 4292 | .dir_fh = NFS_FH(dir), |
---|
4026 | | - .name = name, |
---|
| 4293 | + .name = &dentry->d_name, |
---|
4027 | 4294 | }; |
---|
4028 | 4295 | struct nfs4_lookup_res res = { |
---|
4029 | 4296 | .server = server, |
---|
.. | .. |
---|
4036 | 4303 | .rpc_argp = &args, |
---|
4037 | 4304 | .rpc_resp = &res, |
---|
4038 | 4305 | }; |
---|
| 4306 | + unsigned short task_flags = 0; |
---|
| 4307 | + |
---|
| 4308 | + /* Is this is an attribute revalidation, subject to softreval? */ |
---|
| 4309 | + if (nfs_lookup_is_soft_revalidate(dentry)) |
---|
| 4310 | + task_flags |= RPC_TASK_TIMEOUT; |
---|
4039 | 4311 | |
---|
4040 | 4312 | args.bitmask = nfs4_bitmask(server, label); |
---|
4041 | 4313 | |
---|
4042 | 4314 | nfs_fattr_init(fattr); |
---|
4043 | 4315 | |
---|
4044 | | - dprintk("NFS call lookup %s\n", name->name); |
---|
4045 | | - status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, &res.seq_res, 0); |
---|
| 4316 | + dprintk("NFS call lookup %pd2\n", dentry); |
---|
| 4317 | + nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 0); |
---|
| 4318 | + status = nfs4_do_call_sync(clnt, server, &msg, |
---|
| 4319 | + &args.seq_args, &res.seq_res, task_flags); |
---|
4046 | 4320 | dprintk("NFS reply lookup: %d\n", status); |
---|
4047 | 4321 | return status; |
---|
4048 | 4322 | } |
---|
.. | .. |
---|
4056 | 4330 | } |
---|
4057 | 4331 | |
---|
4058 | 4332 | static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir, |
---|
4059 | | - const struct qstr *name, struct nfs_fh *fhandle, |
---|
| 4333 | + struct dentry *dentry, struct nfs_fh *fhandle, |
---|
4060 | 4334 | struct nfs_fattr *fattr, struct nfs4_label *label) |
---|
4061 | 4335 | { |
---|
4062 | | - struct nfs4_exception exception = { }; |
---|
| 4336 | + struct nfs4_exception exception = { |
---|
| 4337 | + .interruptible = true, |
---|
| 4338 | + }; |
---|
4063 | 4339 | struct rpc_clnt *client = *clnt; |
---|
| 4340 | + const struct qstr *name = &dentry->d_name; |
---|
4064 | 4341 | int err; |
---|
4065 | 4342 | do { |
---|
4066 | | - err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr, label); |
---|
| 4343 | + err = _nfs4_proc_lookup(client, dir, dentry, fhandle, fattr, label); |
---|
4067 | 4344 | trace_nfs4_lookup(dir, name, err); |
---|
4068 | 4345 | switch (err) { |
---|
4069 | 4346 | case -NFS4ERR_BADNAME: |
---|
.. | .. |
---|
4098 | 4375 | return err; |
---|
4099 | 4376 | } |
---|
4100 | 4377 | |
---|
4101 | | -static int nfs4_proc_lookup(struct inode *dir, const struct qstr *name, |
---|
| 4378 | +static int nfs4_proc_lookup(struct inode *dir, struct dentry *dentry, |
---|
4102 | 4379 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
---|
4103 | 4380 | struct nfs4_label *label) |
---|
4104 | 4381 | { |
---|
4105 | 4382 | int status; |
---|
4106 | 4383 | struct rpc_clnt *client = NFS_CLIENT(dir); |
---|
4107 | 4384 | |
---|
4108 | | - status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, label); |
---|
| 4385 | + status = nfs4_proc_lookup_common(&client, dir, dentry, fhandle, fattr, label); |
---|
4109 | 4386 | if (client != NFS_CLIENT(dir)) { |
---|
4110 | 4387 | rpc_shutdown_client(client); |
---|
4111 | 4388 | nfs_fixup_secinfo_attributes(fattr); |
---|
.. | .. |
---|
4114 | 4391 | } |
---|
4115 | 4392 | |
---|
4116 | 4393 | struct rpc_clnt * |
---|
4117 | | -nfs4_proc_lookup_mountpoint(struct inode *dir, const struct qstr *name, |
---|
| 4394 | +nfs4_proc_lookup_mountpoint(struct inode *dir, struct dentry *dentry, |
---|
4118 | 4395 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
---|
4119 | 4396 | { |
---|
4120 | 4397 | struct rpc_clnt *client = NFS_CLIENT(dir); |
---|
4121 | 4398 | int status; |
---|
4122 | 4399 | |
---|
4123 | | - status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, NULL); |
---|
| 4400 | + status = nfs4_proc_lookup_common(&client, dir, dentry, fhandle, fattr, NULL); |
---|
4124 | 4401 | if (status < 0) |
---|
4125 | 4402 | return ERR_PTR(status); |
---|
4126 | 4403 | return (client == NFS_CLIENT(dir)) ? rpc_clone_client(client) : client; |
---|
.. | .. |
---|
4163 | 4440 | static int nfs4_proc_lookupp(struct inode *inode, struct nfs_fh *fhandle, |
---|
4164 | 4441 | struct nfs_fattr *fattr, struct nfs4_label *label) |
---|
4165 | 4442 | { |
---|
4166 | | - struct nfs4_exception exception = { }; |
---|
| 4443 | + struct nfs4_exception exception = { |
---|
| 4444 | + .interruptible = true, |
---|
| 4445 | + }; |
---|
4167 | 4446 | int err; |
---|
4168 | 4447 | do { |
---|
4169 | 4448 | err = _nfs4_proc_lookupp(inode, fhandle, fattr, label); |
---|
.. | .. |
---|
4198 | 4477 | return -ENOMEM; |
---|
4199 | 4478 | args.bitmask = server->cache_consistency_bitmask; |
---|
4200 | 4479 | } |
---|
4201 | | - |
---|
4202 | 4480 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
---|
4203 | 4481 | if (!status) { |
---|
4204 | 4482 | nfs_access_set_mask(entry, res.access); |
---|
.. | .. |
---|
4211 | 4489 | |
---|
4212 | 4490 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
---|
4213 | 4491 | { |
---|
4214 | | - struct nfs4_exception exception = { }; |
---|
| 4492 | + struct nfs4_exception exception = { |
---|
| 4493 | + .interruptible = true, |
---|
| 4494 | + }; |
---|
4215 | 4495 | int err; |
---|
4216 | 4496 | do { |
---|
4217 | 4497 | err = _nfs4_proc_access(inode, entry); |
---|
.. | .. |
---|
4266 | 4546 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
---|
4267 | 4547 | unsigned int pgbase, unsigned int pglen) |
---|
4268 | 4548 | { |
---|
4269 | | - struct nfs4_exception exception = { }; |
---|
| 4549 | + struct nfs4_exception exception = { |
---|
| 4550 | + .interruptible = true, |
---|
| 4551 | + }; |
---|
4270 | 4552 | int err; |
---|
4271 | 4553 | do { |
---|
4272 | 4554 | err = _nfs4_proc_readlink(inode, page, pgbase, pglen); |
---|
.. | .. |
---|
4285 | 4567 | int flags) |
---|
4286 | 4568 | { |
---|
4287 | 4569 | struct nfs_server *server = NFS_SERVER(dir); |
---|
4288 | | - struct nfs4_label l, *ilabel = NULL; |
---|
| 4570 | + struct nfs4_label l, *ilabel; |
---|
4289 | 4571 | struct nfs_open_context *ctx; |
---|
4290 | 4572 | struct nfs4_state *state; |
---|
4291 | 4573 | int status = 0; |
---|
.. | .. |
---|
4331 | 4613 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 1); |
---|
4332 | 4614 | if (status == 0) { |
---|
4333 | 4615 | spin_lock(&dir->i_lock); |
---|
4334 | | - update_changeattr_locked(dir, &res.cinfo, timestamp, 0); |
---|
| 4616 | + nfs4_update_changeattr_locked(dir, &res.cinfo, timestamp, |
---|
| 4617 | + NFS_INO_INVALID_DATA); |
---|
4335 | 4618 | /* Removing a directory decrements nlink in the parent */ |
---|
4336 | 4619 | if (ftype == NF4DIR && dir->i_nlink > 2) |
---|
4337 | 4620 | nfs4_dec_nlink_locked(dir); |
---|
.. | .. |
---|
4342 | 4625 | |
---|
4343 | 4626 | static int nfs4_proc_remove(struct inode *dir, struct dentry *dentry) |
---|
4344 | 4627 | { |
---|
4345 | | - struct nfs4_exception exception = { }; |
---|
| 4628 | + struct nfs4_exception exception = { |
---|
| 4629 | + .interruptible = true, |
---|
| 4630 | + }; |
---|
4346 | 4631 | struct inode *inode = d_inode(dentry); |
---|
4347 | 4632 | int err; |
---|
4348 | 4633 | |
---|
.. | .. |
---|
4363 | 4648 | |
---|
4364 | 4649 | static int nfs4_proc_rmdir(struct inode *dir, const struct qstr *name) |
---|
4365 | 4650 | { |
---|
4366 | | - struct nfs4_exception exception = { }; |
---|
| 4651 | + struct nfs4_exception exception = { |
---|
| 4652 | + .interruptible = true, |
---|
| 4653 | + }; |
---|
4367 | 4654 | int err; |
---|
4368 | 4655 | |
---|
4369 | 4656 | do { |
---|
.. | .. |
---|
4411 | 4698 | &data->timeout) == -EAGAIN) |
---|
4412 | 4699 | return 0; |
---|
4413 | 4700 | if (task->tk_status == 0) |
---|
4414 | | - update_changeattr(dir, &res->cinfo, |
---|
4415 | | - res->dir_attr->time_start, 0); |
---|
| 4701 | + nfs4_update_changeattr(dir, &res->cinfo, |
---|
| 4702 | + res->dir_attr->time_start, |
---|
| 4703 | + NFS_INO_INVALID_DATA); |
---|
4416 | 4704 | return 1; |
---|
4417 | 4705 | } |
---|
4418 | 4706 | |
---|
.. | .. |
---|
4456 | 4744 | if (task->tk_status == 0) { |
---|
4457 | 4745 | if (new_dir != old_dir) { |
---|
4458 | 4746 | /* Note: If we moved a directory, nlink will change */ |
---|
4459 | | - update_changeattr(old_dir, &res->old_cinfo, |
---|
| 4747 | + nfs4_update_changeattr(old_dir, &res->old_cinfo, |
---|
4460 | 4748 | res->old_fattr->time_start, |
---|
4461 | | - NFS_INO_INVALID_OTHER); |
---|
4462 | | - update_changeattr(new_dir, &res->new_cinfo, |
---|
| 4749 | + NFS_INO_INVALID_OTHER | |
---|
| 4750 | + NFS_INO_INVALID_DATA); |
---|
| 4751 | + nfs4_update_changeattr(new_dir, &res->new_cinfo, |
---|
4463 | 4752 | res->new_fattr->time_start, |
---|
4464 | | - NFS_INO_INVALID_OTHER); |
---|
| 4753 | + NFS_INO_INVALID_OTHER | |
---|
| 4754 | + NFS_INO_INVALID_DATA); |
---|
4465 | 4755 | } else |
---|
4466 | | - update_changeattr(old_dir, &res->old_cinfo, |
---|
| 4756 | + nfs4_update_changeattr(old_dir, &res->old_cinfo, |
---|
4467 | 4757 | res->old_fattr->time_start, |
---|
4468 | | - 0); |
---|
| 4758 | + NFS_INO_INVALID_DATA); |
---|
4469 | 4759 | } |
---|
4470 | 4760 | return 1; |
---|
4471 | 4761 | } |
---|
.. | .. |
---|
4506 | 4796 | |
---|
4507 | 4797 | status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1); |
---|
4508 | 4798 | if (!status) { |
---|
4509 | | - update_changeattr(dir, &res.cinfo, res.fattr->time_start, 0); |
---|
| 4799 | + nfs4_update_changeattr(dir, &res.cinfo, res.fattr->time_start, |
---|
| 4800 | + NFS_INO_INVALID_DATA); |
---|
4510 | 4801 | status = nfs_post_op_update_inode(inode, res.fattr); |
---|
4511 | 4802 | if (!status) |
---|
4512 | 4803 | nfs_setsecurity(inode, res.fattr, res.label); |
---|
.. | .. |
---|
4522 | 4813 | |
---|
4523 | 4814 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, const struct qstr *name) |
---|
4524 | 4815 | { |
---|
4525 | | - struct nfs4_exception exception = { }; |
---|
| 4816 | + struct nfs4_exception exception = { |
---|
| 4817 | + .interruptible = true, |
---|
| 4818 | + }; |
---|
4526 | 4819 | int err; |
---|
4527 | 4820 | do { |
---|
4528 | 4821 | err = nfs4_handle_exception(NFS_SERVER(inode), |
---|
.. | .. |
---|
4582 | 4875 | &data->arg.seq_args, &data->res.seq_res, 1); |
---|
4583 | 4876 | if (status == 0) { |
---|
4584 | 4877 | spin_lock(&dir->i_lock); |
---|
4585 | | - update_changeattr_locked(dir, &data->res.dir_cinfo, |
---|
4586 | | - data->res.fattr->time_start, 0); |
---|
| 4878 | + nfs4_update_changeattr_locked(dir, &data->res.dir_cinfo, |
---|
| 4879 | + data->res.fattr->time_start, |
---|
| 4880 | + NFS_INO_INVALID_DATA); |
---|
4587 | 4881 | /* Creating a directory bumps nlink in the parent */ |
---|
4588 | 4882 | if (data->arg.ftype == NF4DIR) |
---|
4589 | 4883 | nfs4_inc_nlink_locked(dir); |
---|
.. | .. |
---|
4629 | 4923 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
---|
4630 | 4924 | struct page *page, unsigned int len, struct iattr *sattr) |
---|
4631 | 4925 | { |
---|
4632 | | - struct nfs4_exception exception = { }; |
---|
4633 | | - struct nfs4_label l, *label = NULL; |
---|
| 4926 | + struct nfs4_exception exception = { |
---|
| 4927 | + .interruptible = true, |
---|
| 4928 | + }; |
---|
| 4929 | + struct nfs4_label l, *label; |
---|
4634 | 4930 | int err; |
---|
4635 | 4931 | |
---|
4636 | 4932 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
---|
.. | .. |
---|
4668 | 4964 | struct iattr *sattr) |
---|
4669 | 4965 | { |
---|
4670 | 4966 | struct nfs_server *server = NFS_SERVER(dir); |
---|
4671 | | - struct nfs4_exception exception = { }; |
---|
4672 | | - struct nfs4_label l, *label = NULL; |
---|
| 4967 | + struct nfs4_exception exception = { |
---|
| 4968 | + .interruptible = true, |
---|
| 4969 | + }; |
---|
| 4970 | + struct nfs4_label l, *label; |
---|
4673 | 4971 | int err; |
---|
4674 | 4972 | |
---|
4675 | 4973 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
---|
.. | .. |
---|
4687 | 4985 | return err; |
---|
4688 | 4986 | } |
---|
4689 | 4987 | |
---|
4690 | | -static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
---|
| 4988 | +static int _nfs4_proc_readdir(struct dentry *dentry, const struct cred *cred, |
---|
4691 | 4989 | u64 cookie, struct page **pages, unsigned int count, bool plus) |
---|
4692 | 4990 | { |
---|
4693 | 4991 | struct inode *dir = d_inode(dentry); |
---|
.. | .. |
---|
4731 | 5029 | return status; |
---|
4732 | 5030 | } |
---|
4733 | 5031 | |
---|
4734 | | -static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
---|
| 5032 | +static int nfs4_proc_readdir(struct dentry *dentry, const struct cred *cred, |
---|
4735 | 5033 | u64 cookie, struct page **pages, unsigned int count, bool plus) |
---|
4736 | 5034 | { |
---|
4737 | | - struct nfs4_exception exception = { }; |
---|
| 5035 | + struct nfs4_exception exception = { |
---|
| 5036 | + .interruptible = true, |
---|
| 5037 | + }; |
---|
4738 | 5038 | int err; |
---|
4739 | 5039 | do { |
---|
4740 | 5040 | err = _nfs4_proc_readdir(dentry, cred, cookie, |
---|
.. | .. |
---|
4785 | 5085 | struct iattr *sattr, dev_t rdev) |
---|
4786 | 5086 | { |
---|
4787 | 5087 | struct nfs_server *server = NFS_SERVER(dir); |
---|
4788 | | - struct nfs4_exception exception = { }; |
---|
4789 | | - struct nfs4_label l, *label = NULL; |
---|
| 5088 | + struct nfs4_exception exception = { |
---|
| 5089 | + .interruptible = true, |
---|
| 5090 | + }; |
---|
| 5091 | + struct nfs4_label l, *label; |
---|
4790 | 5092 | int err; |
---|
4791 | 5093 | |
---|
4792 | 5094 | label = nfs4_label_init_security(dir, dentry, sattr, &l); |
---|
.. | .. |
---|
4827 | 5129 | |
---|
4828 | 5130 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
---|
4829 | 5131 | { |
---|
4830 | | - struct nfs4_exception exception = { }; |
---|
| 5132 | + struct nfs4_exception exception = { |
---|
| 5133 | + .interruptible = true, |
---|
| 5134 | + }; |
---|
4831 | 5135 | int err; |
---|
4832 | 5136 | do { |
---|
4833 | 5137 | err = nfs4_handle_exception(server, |
---|
.. | .. |
---|
4858 | 5162 | |
---|
4859 | 5163 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
---|
4860 | 5164 | { |
---|
4861 | | - struct nfs4_exception exception = { }; |
---|
4862 | | - unsigned long now = jiffies; |
---|
| 5165 | + struct nfs4_exception exception = { |
---|
| 5166 | + .interruptible = true, |
---|
| 5167 | + }; |
---|
4863 | 5168 | int err; |
---|
4864 | 5169 | |
---|
4865 | 5170 | do { |
---|
4866 | 5171 | err = _nfs4_do_fsinfo(server, fhandle, fsinfo); |
---|
4867 | 5172 | trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err); |
---|
4868 | 5173 | if (err == 0) { |
---|
4869 | | - nfs4_set_lease_period(server->nfs_client, |
---|
4870 | | - fsinfo->lease_time * HZ, |
---|
4871 | | - now); |
---|
| 5174 | + nfs4_set_lease_period(server->nfs_client, fsinfo->lease_time * HZ); |
---|
4872 | 5175 | break; |
---|
4873 | 5176 | } |
---|
4874 | 5177 | err = nfs4_handle_exception(server, err, &exception); |
---|
.. | .. |
---|
4920 | 5223 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
---|
4921 | 5224 | struct nfs_pathconf *pathconf) |
---|
4922 | 5225 | { |
---|
4923 | | - struct nfs4_exception exception = { }; |
---|
| 5226 | + struct nfs4_exception exception = { |
---|
| 5227 | + .interruptible = true, |
---|
| 5228 | + }; |
---|
4924 | 5229 | int err; |
---|
4925 | 5230 | |
---|
4926 | 5231 | do { |
---|
.. | .. |
---|
4945 | 5250 | const struct nfs_lock_context *l_ctx, |
---|
4946 | 5251 | fmode_t fmode) |
---|
4947 | 5252 | { |
---|
4948 | | - nfs4_stateid current_stateid; |
---|
| 5253 | + nfs4_stateid _current_stateid; |
---|
4949 | 5254 | |
---|
4950 | 5255 | /* If the current stateid represents a lost lock, then exit */ |
---|
4951 | | - if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode) == -EIO) |
---|
| 5256 | + if (nfs4_set_rw_stateid(&_current_stateid, ctx, l_ctx, fmode) == -EIO) |
---|
4952 | 5257 | return true; |
---|
4953 | | - return nfs4_stateid_match(stateid, ¤t_stateid); |
---|
| 5258 | + return nfs4_stateid_match(stateid, &_current_stateid); |
---|
4954 | 5259 | } |
---|
4955 | 5260 | |
---|
4956 | 5261 | static bool nfs4_error_stateid_expired(int err) |
---|
.. | .. |
---|
5006 | 5311 | return true; |
---|
5007 | 5312 | } |
---|
5008 | 5313 | |
---|
| 5314 | +static bool nfs4_read_plus_not_supported(struct rpc_task *task, |
---|
| 5315 | + struct nfs_pgio_header *hdr) |
---|
| 5316 | +{ |
---|
| 5317 | + struct nfs_server *server = NFS_SERVER(hdr->inode); |
---|
| 5318 | + struct rpc_message *msg = &task->tk_msg; |
---|
| 5319 | + |
---|
| 5320 | + if (msg->rpc_proc == &nfs4_procedures[NFSPROC4_CLNT_READ_PLUS] && |
---|
| 5321 | + server->caps & NFS_CAP_READ_PLUS && task->tk_status == -ENOTSUPP) { |
---|
| 5322 | + server->caps &= ~NFS_CAP_READ_PLUS; |
---|
| 5323 | + msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
---|
| 5324 | + rpc_restart_call_prepare(task); |
---|
| 5325 | + return true; |
---|
| 5326 | + } |
---|
| 5327 | + return false; |
---|
| 5328 | +} |
---|
| 5329 | + |
---|
5009 | 5330 | static int nfs4_read_done(struct rpc_task *task, struct nfs_pgio_header *hdr) |
---|
5010 | 5331 | { |
---|
5011 | | - |
---|
5012 | 5332 | dprintk("--> %s\n", __func__); |
---|
5013 | 5333 | |
---|
5014 | 5334 | if (!nfs4_sequence_done(task, &hdr->res.seq_res)) |
---|
5015 | 5335 | return -EAGAIN; |
---|
5016 | 5336 | if (nfs4_read_stateid_changed(task, &hdr->args)) |
---|
| 5337 | + return -EAGAIN; |
---|
| 5338 | + if (nfs4_read_plus_not_supported(task, hdr)) |
---|
5017 | 5339 | return -EAGAIN; |
---|
5018 | 5340 | if (task->tk_status > 0) |
---|
5019 | 5341 | nfs_invalidate_atime(hdr->inode); |
---|
.. | .. |
---|
5021 | 5343 | nfs4_read_done_cb(task, hdr); |
---|
5022 | 5344 | } |
---|
5023 | 5345 | |
---|
| 5346 | +#if defined CONFIG_NFS_V4_2 && defined CONFIG_NFS_V4_2_READ_PLUS |
---|
| 5347 | +static void nfs42_read_plus_support(struct nfs_server *server, struct rpc_message *msg) |
---|
| 5348 | +{ |
---|
| 5349 | + if (server->caps & NFS_CAP_READ_PLUS) |
---|
| 5350 | + msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ_PLUS]; |
---|
| 5351 | + else |
---|
| 5352 | + msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
---|
| 5353 | +} |
---|
| 5354 | +#else |
---|
| 5355 | +static void nfs42_read_plus_support(struct nfs_server *server, struct rpc_message *msg) |
---|
| 5356 | +{ |
---|
| 5357 | + msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
---|
| 5358 | +} |
---|
| 5359 | +#endif /* CONFIG_NFS_V4_2 */ |
---|
| 5360 | + |
---|
5024 | 5361 | static void nfs4_proc_read_setup(struct nfs_pgio_header *hdr, |
---|
5025 | 5362 | struct rpc_message *msg) |
---|
5026 | 5363 | { |
---|
5027 | 5364 | hdr->timestamp = jiffies; |
---|
5028 | 5365 | if (!hdr->pgio_done_cb) |
---|
5029 | 5366 | hdr->pgio_done_cb = nfs4_read_done_cb; |
---|
5030 | | - msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
---|
| 5367 | + nfs42_read_plus_support(NFS_SERVER(hdr->inode), msg); |
---|
5031 | 5368 | nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 0, 0); |
---|
5032 | 5369 | } |
---|
5033 | 5370 | |
---|
.. | .. |
---|
5111 | 5448 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
---|
5112 | 5449 | } |
---|
5113 | 5450 | |
---|
| 5451 | +static void nfs4_bitmask_set(__u32 bitmask[NFS4_BITMASK_SZ], const __u32 *src, |
---|
| 5452 | + struct inode *inode, struct nfs_server *server, |
---|
| 5453 | + struct nfs4_label *label) |
---|
| 5454 | +{ |
---|
| 5455 | + unsigned long cache_validity = READ_ONCE(NFS_I(inode)->cache_validity); |
---|
| 5456 | + unsigned int i; |
---|
| 5457 | + |
---|
| 5458 | + memcpy(bitmask, src, sizeof(*bitmask) * NFS4_BITMASK_SZ); |
---|
| 5459 | + |
---|
| 5460 | + if (cache_validity & (NFS_INO_INVALID_CHANGE | NFS_INO_REVAL_PAGECACHE)) |
---|
| 5461 | + bitmask[0] |= FATTR4_WORD0_CHANGE; |
---|
| 5462 | + if (cache_validity & NFS_INO_INVALID_ATIME) |
---|
| 5463 | + bitmask[1] |= FATTR4_WORD1_TIME_ACCESS; |
---|
| 5464 | + if (cache_validity & NFS_INO_INVALID_OTHER) |
---|
| 5465 | + bitmask[1] |= FATTR4_WORD1_MODE | FATTR4_WORD1_OWNER | |
---|
| 5466 | + FATTR4_WORD1_OWNER_GROUP | |
---|
| 5467 | + FATTR4_WORD1_NUMLINKS; |
---|
| 5468 | + if (label && label->len && cache_validity & NFS_INO_INVALID_LABEL) |
---|
| 5469 | + bitmask[2] |= FATTR4_WORD2_SECURITY_LABEL; |
---|
| 5470 | + if (cache_validity & NFS_INO_INVALID_CTIME) |
---|
| 5471 | + bitmask[1] |= FATTR4_WORD1_TIME_METADATA; |
---|
| 5472 | + if (cache_validity & NFS_INO_INVALID_MTIME) |
---|
| 5473 | + bitmask[1] |= FATTR4_WORD1_TIME_MODIFY; |
---|
| 5474 | + if (cache_validity & NFS_INO_INVALID_BLOCKS) |
---|
| 5475 | + bitmask[1] |= FATTR4_WORD1_SPACE_USED; |
---|
| 5476 | + |
---|
| 5477 | + if (nfs4_have_delegation(inode, FMODE_READ) && |
---|
| 5478 | + !(cache_validity & NFS_INO_REVAL_FORCED)) |
---|
| 5479 | + bitmask[0] &= ~FATTR4_WORD0_SIZE; |
---|
| 5480 | + else if (cache_validity & |
---|
| 5481 | + (NFS_INO_INVALID_SIZE | NFS_INO_REVAL_PAGECACHE)) |
---|
| 5482 | + bitmask[0] |= FATTR4_WORD0_SIZE; |
---|
| 5483 | + |
---|
| 5484 | + for (i = 0; i < NFS4_BITMASK_SZ; i++) |
---|
| 5485 | + bitmask[i] &= server->attr_bitmask[i]; |
---|
| 5486 | +} |
---|
| 5487 | + |
---|
5114 | 5488 | static void nfs4_proc_write_setup(struct nfs_pgio_header *hdr, |
---|
5115 | 5489 | struct rpc_message *msg, |
---|
5116 | 5490 | struct rpc_clnt **clnt) |
---|
.. | .. |
---|
5120 | 5494 | if (!nfs4_write_need_cache_consistency_data(hdr)) { |
---|
5121 | 5495 | hdr->args.bitmask = NULL; |
---|
5122 | 5496 | hdr->res.fattr = NULL; |
---|
5123 | | - } else |
---|
5124 | | - hdr->args.bitmask = server->cache_consistency_bitmask; |
---|
| 5497 | + } else { |
---|
| 5498 | + nfs4_bitmask_set(hdr->args.bitmask_store, |
---|
| 5499 | + server->cache_consistency_bitmask, |
---|
| 5500 | + hdr->inode, server, NULL); |
---|
| 5501 | + hdr->args.bitmask = hdr->args.bitmask_store; |
---|
| 5502 | + } |
---|
5125 | 5503 | |
---|
5126 | 5504 | if (!hdr->pgio_done_cb) |
---|
5127 | 5505 | hdr->pgio_done_cb = nfs4_write_done_cb; |
---|
.. | .. |
---|
5259 | 5637 | .rpc_release = nfs4_renew_release, |
---|
5260 | 5638 | }; |
---|
5261 | 5639 | |
---|
5262 | | -static int nfs4_proc_async_renew(struct nfs_client *clp, struct rpc_cred *cred, unsigned renew_flags) |
---|
| 5640 | +static int nfs4_proc_async_renew(struct nfs_client *clp, const struct cred *cred, unsigned renew_flags) |
---|
5263 | 5641 | { |
---|
5264 | 5642 | struct rpc_message msg = { |
---|
5265 | 5643 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
---|
.. | .. |
---|
5283 | 5661 | &nfs4_renew_ops, data); |
---|
5284 | 5662 | } |
---|
5285 | 5663 | |
---|
5286 | | -static int nfs4_proc_renew(struct nfs_client *clp, struct rpc_cred *cred) |
---|
| 5664 | +static int nfs4_proc_renew(struct nfs_client *clp, const struct cred *cred) |
---|
5287 | 5665 | { |
---|
5288 | 5666 | struct rpc_message msg = { |
---|
5289 | 5667 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
---|
.. | .. |
---|
5311 | 5689 | */ |
---|
5312 | 5690 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
---|
5313 | 5691 | |
---|
5314 | | -static int buf_to_pages_noslab(const void *buf, size_t buflen, |
---|
| 5692 | +int nfs4_buf_to_pages_noslab(const void *buf, size_t buflen, |
---|
5315 | 5693 | struct page **pages) |
---|
5316 | 5694 | { |
---|
5317 | 5695 | struct page *newpage, **spages; |
---|
.. | .. |
---|
5343 | 5721 | struct nfs4_cached_acl { |
---|
5344 | 5722 | int cached; |
---|
5345 | 5723 | size_t len; |
---|
5346 | | - char data[0]; |
---|
| 5724 | + char data[]; |
---|
5347 | 5725 | }; |
---|
5348 | 5726 | |
---|
5349 | 5727 | static void nfs4_set_cached_acl(struct inode *inode, struct nfs4_cached_acl *acl) |
---|
.. | .. |
---|
5420 | 5798 | */ |
---|
5421 | 5799 | static ssize_t __nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
---|
5422 | 5800 | { |
---|
5423 | | - struct page *pages[NFS4ACL_MAXPAGES + 1] = {NULL, }; |
---|
| 5801 | + struct page **pages; |
---|
5424 | 5802 | struct nfs_getaclargs args = { |
---|
5425 | 5803 | .fh = NFS_FH(inode), |
---|
5426 | | - .acl_pages = pages, |
---|
5427 | 5804 | .acl_len = buflen, |
---|
5428 | 5805 | }; |
---|
5429 | 5806 | struct nfs_getaclres res = { |
---|
.. | .. |
---|
5434 | 5811 | .rpc_argp = &args, |
---|
5435 | 5812 | .rpc_resp = &res, |
---|
5436 | 5813 | }; |
---|
5437 | | - unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE) + 1; |
---|
| 5814 | + unsigned int npages; |
---|
5438 | 5815 | int ret = -ENOMEM, i; |
---|
| 5816 | + struct nfs_server *server = NFS_SERVER(inode); |
---|
5439 | 5817 | |
---|
5440 | | - if (npages > ARRAY_SIZE(pages)) |
---|
5441 | | - return -ERANGE; |
---|
| 5818 | + if (buflen == 0) |
---|
| 5819 | + buflen = server->rsize; |
---|
| 5820 | + |
---|
| 5821 | + npages = DIV_ROUND_UP(buflen, PAGE_SIZE) + 1; |
---|
| 5822 | + pages = kmalloc_array(npages, sizeof(struct page *), GFP_NOFS); |
---|
| 5823 | + if (!pages) |
---|
| 5824 | + return -ENOMEM; |
---|
| 5825 | + |
---|
| 5826 | + args.acl_pages = pages; |
---|
5442 | 5827 | |
---|
5443 | 5828 | for (i = 0; i < npages; i++) { |
---|
5444 | 5829 | pages[i] = alloc_page(GFP_KERNEL); |
---|
.. | .. |
---|
5479 | 5864 | out_ok: |
---|
5480 | 5865 | ret = res.acl_len; |
---|
5481 | 5866 | out_free: |
---|
5482 | | - for (i = 0; i < npages; i++) |
---|
5483 | | - if (pages[i]) |
---|
5484 | | - __free_page(pages[i]); |
---|
| 5867 | + while (--i >= 0) |
---|
| 5868 | + __free_page(pages[i]); |
---|
5485 | 5869 | if (res.acl_scratch) |
---|
5486 | 5870 | __free_page(res.acl_scratch); |
---|
| 5871 | + kfree(pages); |
---|
5487 | 5872 | return ret; |
---|
5488 | 5873 | } |
---|
5489 | 5874 | |
---|
5490 | 5875 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
---|
5491 | 5876 | { |
---|
5492 | | - struct nfs4_exception exception = { }; |
---|
| 5877 | + struct nfs4_exception exception = { |
---|
| 5878 | + .interruptible = true, |
---|
| 5879 | + }; |
---|
5493 | 5880 | ssize_t ret; |
---|
5494 | 5881 | do { |
---|
5495 | 5882 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
---|
.. | .. |
---|
5546 | 5933 | return -EOPNOTSUPP; |
---|
5547 | 5934 | if (npages > ARRAY_SIZE(pages)) |
---|
5548 | 5935 | return -ERANGE; |
---|
5549 | | - i = buf_to_pages_noslab(buf, buflen, arg.acl_pages); |
---|
| 5936 | + i = nfs4_buf_to_pages_noslab(buf, buflen, arg.acl_pages); |
---|
5550 | 5937 | if (i < 0) |
---|
5551 | 5938 | return i; |
---|
5552 | 5939 | nfs4_inode_make_writeable(inode); |
---|
.. | .. |
---|
5632 | 6019 | static int nfs4_get_security_label(struct inode *inode, void *buf, |
---|
5633 | 6020 | size_t buflen) |
---|
5634 | 6021 | { |
---|
5635 | | - struct nfs4_exception exception = { }; |
---|
| 6022 | + struct nfs4_exception exception = { |
---|
| 6023 | + .interruptible = true, |
---|
| 6024 | + }; |
---|
5636 | 6025 | int err; |
---|
5637 | 6026 | |
---|
5638 | 6027 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
---|
.. | .. |
---|
5707 | 6096 | { |
---|
5708 | 6097 | struct nfs4_label ilabel, *olabel = NULL; |
---|
5709 | 6098 | struct nfs_fattr fattr; |
---|
5710 | | - struct rpc_cred *cred; |
---|
5711 | 6099 | int status; |
---|
5712 | 6100 | |
---|
5713 | 6101 | if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) |
---|
.. | .. |
---|
5719 | 6107 | ilabel.lfs = 0; |
---|
5720 | 6108 | ilabel.label = (char *)buf; |
---|
5721 | 6109 | ilabel.len = buflen; |
---|
5722 | | - |
---|
5723 | | - cred = rpc_lookup_cred(); |
---|
5724 | | - if (IS_ERR(cred)) |
---|
5725 | | - return PTR_ERR(cred); |
---|
5726 | 6110 | |
---|
5727 | 6111 | olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL); |
---|
5728 | 6112 | if (IS_ERR(olabel)) { |
---|
.. | .. |
---|
5736 | 6120 | |
---|
5737 | 6121 | nfs4_label_free(olabel); |
---|
5738 | 6122 | out: |
---|
5739 | | - put_rpccred(cred); |
---|
5740 | 6123 | return status; |
---|
5741 | 6124 | } |
---|
5742 | 6125 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
---|
.. | .. |
---|
5762 | 6145 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
---|
5763 | 6146 | } |
---|
5764 | 6147 | |
---|
| 6148 | +static size_t |
---|
| 6149 | +nfs4_get_uniquifier(struct nfs_client *clp, char *buf, size_t buflen) |
---|
| 6150 | +{ |
---|
| 6151 | + struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
---|
| 6152 | + struct nfs_netns_client *nn_clp = nn->nfs_client; |
---|
| 6153 | + const char *id; |
---|
| 6154 | + |
---|
| 6155 | + buf[0] = '\0'; |
---|
| 6156 | + |
---|
| 6157 | + if (nn_clp) { |
---|
| 6158 | + rcu_read_lock(); |
---|
| 6159 | + id = rcu_dereference(nn_clp->identifier); |
---|
| 6160 | + if (id) |
---|
| 6161 | + strscpy(buf, id, buflen); |
---|
| 6162 | + rcu_read_unlock(); |
---|
| 6163 | + } |
---|
| 6164 | + |
---|
| 6165 | + if (nfs4_client_id_uniquifier[0] != '\0' && buf[0] == '\0') |
---|
| 6166 | + strscpy(buf, nfs4_client_id_uniquifier, buflen); |
---|
| 6167 | + |
---|
| 6168 | + return strlen(buf); |
---|
| 6169 | +} |
---|
| 6170 | + |
---|
5765 | 6171 | static int |
---|
5766 | 6172 | nfs4_init_nonuniform_client_string(struct nfs_client *clp) |
---|
5767 | 6173 | { |
---|
| 6174 | + char buf[NFS4_CLIENT_ID_UNIQ_LEN]; |
---|
| 6175 | + size_t buflen; |
---|
5768 | 6176 | size_t len; |
---|
5769 | 6177 | char *str; |
---|
5770 | 6178 | |
---|
.. | .. |
---|
5778 | 6186 | strlen(rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)) + |
---|
5779 | 6187 | 1; |
---|
5780 | 6188 | rcu_read_unlock(); |
---|
5781 | | - if (nfs4_client_id_uniquifier[0] != '\0') |
---|
5782 | | - len += strlen(nfs4_client_id_uniquifier) + 1; |
---|
| 6189 | + |
---|
| 6190 | + buflen = nfs4_get_uniquifier(clp, buf, sizeof(buf)); |
---|
| 6191 | + if (buflen) |
---|
| 6192 | + len += buflen + 1; |
---|
| 6193 | + |
---|
5783 | 6194 | if (len > NFS4_OPAQUE_LIMIT + 1) |
---|
5784 | 6195 | return -EINVAL; |
---|
5785 | 6196 | |
---|
.. | .. |
---|
5793 | 6204 | return -ENOMEM; |
---|
5794 | 6205 | |
---|
5795 | 6206 | rcu_read_lock(); |
---|
5796 | | - if (nfs4_client_id_uniquifier[0] != '\0') |
---|
| 6207 | + if (buflen) |
---|
5797 | 6208 | scnprintf(str, len, "Linux NFSv4.0 %s/%s/%s", |
---|
5798 | | - clp->cl_rpcclient->cl_nodename, |
---|
5799 | | - nfs4_client_id_uniquifier, |
---|
| 6209 | + clp->cl_rpcclient->cl_nodename, buf, |
---|
5800 | 6210 | rpc_peeraddr2str(clp->cl_rpcclient, |
---|
5801 | 6211 | RPC_DISPLAY_ADDR)); |
---|
5802 | 6212 | else |
---|
.. | .. |
---|
5811 | 6221 | } |
---|
5812 | 6222 | |
---|
5813 | 6223 | static int |
---|
5814 | | -nfs4_init_uniquifier_client_string(struct nfs_client *clp) |
---|
5815 | | -{ |
---|
5816 | | - size_t len; |
---|
5817 | | - char *str; |
---|
5818 | | - |
---|
5819 | | - len = 10 + 10 + 1 + 10 + 1 + |
---|
5820 | | - strlen(nfs4_client_id_uniquifier) + 1 + |
---|
5821 | | - strlen(clp->cl_rpcclient->cl_nodename) + 1; |
---|
5822 | | - |
---|
5823 | | - if (len > NFS4_OPAQUE_LIMIT + 1) |
---|
5824 | | - return -EINVAL; |
---|
5825 | | - |
---|
5826 | | - /* |
---|
5827 | | - * Since this string is allocated at mount time, and held until the |
---|
5828 | | - * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying |
---|
5829 | | - * about a memory-reclaim deadlock. |
---|
5830 | | - */ |
---|
5831 | | - str = kmalloc(len, GFP_KERNEL); |
---|
5832 | | - if (!str) |
---|
5833 | | - return -ENOMEM; |
---|
5834 | | - |
---|
5835 | | - scnprintf(str, len, "Linux NFSv%u.%u %s/%s", |
---|
5836 | | - clp->rpc_ops->version, clp->cl_minorversion, |
---|
5837 | | - nfs4_client_id_uniquifier, |
---|
5838 | | - clp->cl_rpcclient->cl_nodename); |
---|
5839 | | - clp->cl_owner_id = str; |
---|
5840 | | - return 0; |
---|
5841 | | -} |
---|
5842 | | - |
---|
5843 | | -static int |
---|
5844 | 6224 | nfs4_init_uniform_client_string(struct nfs_client *clp) |
---|
5845 | 6225 | { |
---|
| 6226 | + char buf[NFS4_CLIENT_ID_UNIQ_LEN]; |
---|
| 6227 | + size_t buflen; |
---|
5846 | 6228 | size_t len; |
---|
5847 | 6229 | char *str; |
---|
5848 | 6230 | |
---|
5849 | 6231 | if (clp->cl_owner_id != NULL) |
---|
5850 | 6232 | return 0; |
---|
5851 | 6233 | |
---|
5852 | | - if (nfs4_client_id_uniquifier[0] != '\0') |
---|
5853 | | - return nfs4_init_uniquifier_client_string(clp); |
---|
5854 | | - |
---|
5855 | 6234 | len = 10 + 10 + 1 + 10 + 1 + |
---|
5856 | 6235 | strlen(clp->cl_rpcclient->cl_nodename) + 1; |
---|
| 6236 | + |
---|
| 6237 | + buflen = nfs4_get_uniquifier(clp, buf, sizeof(buf)); |
---|
| 6238 | + if (buflen) |
---|
| 6239 | + len += buflen + 1; |
---|
5857 | 6240 | |
---|
5858 | 6241 | if (len > NFS4_OPAQUE_LIMIT + 1) |
---|
5859 | 6242 | return -EINVAL; |
---|
.. | .. |
---|
5867 | 6250 | if (!str) |
---|
5868 | 6251 | return -ENOMEM; |
---|
5869 | 6252 | |
---|
5870 | | - scnprintf(str, len, "Linux NFSv%u.%u %s", |
---|
5871 | | - clp->rpc_ops->version, clp->cl_minorversion, |
---|
5872 | | - clp->cl_rpcclient->cl_nodename); |
---|
| 6253 | + if (buflen) |
---|
| 6254 | + scnprintf(str, len, "Linux NFSv%u.%u %s/%s", |
---|
| 6255 | + clp->rpc_ops->version, clp->cl_minorversion, |
---|
| 6256 | + buf, clp->cl_rpcclient->cl_nodename); |
---|
| 6257 | + else |
---|
| 6258 | + scnprintf(str, len, "Linux NFSv%u.%u %s", |
---|
| 6259 | + clp->rpc_ops->version, clp->cl_minorversion, |
---|
| 6260 | + clp->cl_rpcclient->cl_nodename); |
---|
5873 | 6261 | clp->cl_owner_id = str; |
---|
5874 | 6262 | return 0; |
---|
5875 | 6263 | } |
---|
.. | .. |
---|
5905 | 6293 | * @clp: state data structure |
---|
5906 | 6294 | * @program: RPC program for NFSv4 callback service |
---|
5907 | 6295 | * @port: IP port number for NFS4 callback service |
---|
5908 | | - * @cred: RPC credential to use for this call |
---|
| 6296 | + * @cred: credential to use for this call |
---|
5909 | 6297 | * @res: where to place the result |
---|
5910 | 6298 | * |
---|
5911 | 6299 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
---|
5912 | 6300 | */ |
---|
5913 | 6301 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
---|
5914 | | - unsigned short port, struct rpc_cred *cred, |
---|
| 6302 | + unsigned short port, const struct cred *cred, |
---|
5915 | 6303 | struct nfs4_setclientid_res *res) |
---|
5916 | 6304 | { |
---|
5917 | 6305 | nfs4_verifier sc_verifier; |
---|
.. | .. |
---|
5926 | 6314 | .rpc_resp = res, |
---|
5927 | 6315 | .rpc_cred = cred, |
---|
5928 | 6316 | }; |
---|
5929 | | - struct rpc_task *task; |
---|
5930 | 6317 | struct rpc_task_setup task_setup_data = { |
---|
5931 | 6318 | .rpc_client = clp->cl_rpcclient, |
---|
5932 | 6319 | .rpc_message = &msg, |
---|
5933 | 6320 | .callback_ops = &nfs4_setclientid_ops, |
---|
5934 | 6321 | .callback_data = &setclientid, |
---|
5935 | | - .flags = RPC_TASK_TIMEOUT, |
---|
| 6322 | + .flags = RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN, |
---|
5936 | 6323 | }; |
---|
| 6324 | + unsigned long now = jiffies; |
---|
5937 | 6325 | int status; |
---|
5938 | 6326 | |
---|
5939 | 6327 | /* nfs_client_id4 */ |
---|
.. | .. |
---|
5959 | 6347 | dprintk("NFS call setclientid auth=%s, '%s'\n", |
---|
5960 | 6348 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
---|
5961 | 6349 | clp->cl_owner_id); |
---|
5962 | | - task = rpc_run_task(&task_setup_data); |
---|
5963 | | - if (IS_ERR(task)) { |
---|
5964 | | - status = PTR_ERR(task); |
---|
5965 | | - goto out; |
---|
5966 | | - } |
---|
5967 | | - status = task->tk_status; |
---|
| 6350 | + |
---|
| 6351 | + status = nfs4_call_sync_custom(&task_setup_data); |
---|
5968 | 6352 | if (setclientid.sc_cred) { |
---|
5969 | 6353 | kfree(clp->cl_acceptor); |
---|
5970 | 6354 | clp->cl_acceptor = rpcauth_stringify_acceptor(setclientid.sc_cred); |
---|
5971 | 6355 | put_rpccred(setclientid.sc_cred); |
---|
5972 | 6356 | } |
---|
5973 | | - rpc_put_task(task); |
---|
| 6357 | + |
---|
| 6358 | + if (status == 0) |
---|
| 6359 | + do_renew_lease(clp, now); |
---|
5974 | 6360 | out: |
---|
5975 | 6361 | trace_nfs4_setclientid(clp, status); |
---|
5976 | 6362 | dprintk("NFS reply setclientid: %d\n", status); |
---|
.. | .. |
---|
5980 | 6366 | /** |
---|
5981 | 6367 | * nfs4_proc_setclientid_confirm - Confirm client ID |
---|
5982 | 6368 | * @clp: state data structure |
---|
5983 | | - * @res: result of a previous SETCLIENTID |
---|
5984 | | - * @cred: RPC credential to use for this call |
---|
| 6369 | + * @arg: result of a previous SETCLIENTID |
---|
| 6370 | + * @cred: credential to use for this call |
---|
5985 | 6371 | * |
---|
5986 | 6372 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
---|
5987 | 6373 | */ |
---|
5988 | 6374 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
---|
5989 | 6375 | struct nfs4_setclientid_res *arg, |
---|
5990 | | - struct rpc_cred *cred) |
---|
| 6376 | + const struct cred *cred) |
---|
5991 | 6377 | { |
---|
5992 | 6378 | struct rpc_message msg = { |
---|
5993 | 6379 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
---|
.. | .. |
---|
5999 | 6385 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
---|
6000 | 6386 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
---|
6001 | 6387 | clp->cl_clientid); |
---|
6002 | | - status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
---|
| 6388 | + status = rpc_call_sync(clp->cl_rpcclient, &msg, |
---|
| 6389 | + RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN); |
---|
6003 | 6390 | trace_nfs4_setclientid_confirm(clp, status); |
---|
6004 | 6391 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
---|
6005 | 6392 | return status; |
---|
.. | .. |
---|
6038 | 6425 | trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); |
---|
6039 | 6426 | |
---|
6040 | 6427 | /* Handle Layoutreturn errors */ |
---|
6041 | | - if (data->args.lr_args && task->tk_status != 0) { |
---|
6042 | | - switch(data->res.lr_ret) { |
---|
6043 | | - default: |
---|
6044 | | - data->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; |
---|
6045 | | - break; |
---|
6046 | | - case 0: |
---|
6047 | | - data->args.lr_args = NULL; |
---|
6048 | | - data->res.lr_res = NULL; |
---|
6049 | | - break; |
---|
6050 | | - case -NFS4ERR_OLD_STATEID: |
---|
6051 | | - if (nfs4_layoutreturn_refresh_stateid(&data->args.lr_args->stateid, |
---|
6052 | | - &data->args.lr_args->range, |
---|
6053 | | - data->inode)) |
---|
6054 | | - goto lr_restart; |
---|
6055 | | - /* Fallthrough */ |
---|
6056 | | - case -NFS4ERR_ADMIN_REVOKED: |
---|
6057 | | - case -NFS4ERR_DELEG_REVOKED: |
---|
6058 | | - case -NFS4ERR_EXPIRED: |
---|
6059 | | - case -NFS4ERR_BAD_STATEID: |
---|
6060 | | - case -NFS4ERR_UNKNOWN_LAYOUTTYPE: |
---|
6061 | | - case -NFS4ERR_WRONG_CRED: |
---|
6062 | | - data->args.lr_args = NULL; |
---|
6063 | | - data->res.lr_res = NULL; |
---|
6064 | | - goto lr_restart; |
---|
6065 | | - } |
---|
6066 | | - } |
---|
| 6428 | + if (pnfs_roc_done(task, &data->args.lr_args, &data->res.lr_res, |
---|
| 6429 | + &data->res.lr_ret) == -EAGAIN) |
---|
| 6430 | + goto out_restart; |
---|
6067 | 6431 | |
---|
6068 | 6432 | switch (task->tk_status) { |
---|
6069 | 6433 | case 0: |
---|
.. | .. |
---|
6075 | 6439 | nfs4_free_revoked_stateid(data->res.server, |
---|
6076 | 6440 | data->args.stateid, |
---|
6077 | 6441 | task->tk_msg.rpc_cred); |
---|
6078 | | - /* Fallthrough */ |
---|
| 6442 | + fallthrough; |
---|
6079 | 6443 | case -NFS4ERR_BAD_STATEID: |
---|
6080 | 6444 | case -NFS4ERR_STALE_STATEID: |
---|
| 6445 | + case -ETIMEDOUT: |
---|
6081 | 6446 | task->tk_status = 0; |
---|
6082 | 6447 | break; |
---|
6083 | 6448 | case -NFS4ERR_OLD_STATEID: |
---|
6084 | | - if (nfs4_refresh_delegation_stateid(&data->stateid, data->inode)) |
---|
6085 | | - goto out_restart; |
---|
6086 | | - task->tk_status = 0; |
---|
6087 | | - break; |
---|
| 6449 | + if (!nfs4_refresh_delegation_stateid(&data->stateid, data->inode)) |
---|
| 6450 | + nfs4_stateid_seqid_inc(&data->stateid); |
---|
| 6451 | + if (data->args.bitmask) { |
---|
| 6452 | + data->args.bitmask = NULL; |
---|
| 6453 | + data->res.fattr = NULL; |
---|
| 6454 | + } |
---|
| 6455 | + goto out_restart; |
---|
6088 | 6456 | case -NFS4ERR_ACCESS: |
---|
6089 | 6457 | if (data->args.bitmask) { |
---|
6090 | 6458 | data->args.bitmask = NULL; |
---|
6091 | 6459 | data->res.fattr = NULL; |
---|
6092 | 6460 | goto out_restart; |
---|
6093 | 6461 | } |
---|
6094 | | - /* Fallthrough */ |
---|
| 6462 | + fallthrough; |
---|
6095 | 6463 | default: |
---|
6096 | 6464 | task->tk_status = nfs4_async_handle_exception(task, |
---|
6097 | 6465 | data->res.server, task->tk_status, |
---|
.. | .. |
---|
6099 | 6467 | if (exception.retry) |
---|
6100 | 6468 | goto out_restart; |
---|
6101 | 6469 | } |
---|
| 6470 | + nfs_delegation_mark_returned(data->inode, data->args.stateid); |
---|
6102 | 6471 | data->rpc_status = task->tk_status; |
---|
6103 | 6472 | return; |
---|
6104 | | -lr_restart: |
---|
6105 | | - data->res.lr_ret = 0; |
---|
6106 | 6473 | out_restart: |
---|
6107 | 6474 | task->tk_status = 0; |
---|
6108 | 6475 | rpc_restart_call_prepare(task); |
---|
.. | .. |
---|
6113 | 6480 | struct nfs4_delegreturndata *data = calldata; |
---|
6114 | 6481 | struct inode *inode = data->inode; |
---|
6115 | 6482 | |
---|
| 6483 | + if (data->lr.roc) |
---|
| 6484 | + pnfs_roc_release(&data->lr.arg, &data->lr.res, |
---|
| 6485 | + data->res.lr_ret); |
---|
6116 | 6486 | if (inode) { |
---|
6117 | | - if (data->lr.roc) |
---|
6118 | | - pnfs_roc_release(&data->lr.arg, &data->lr.res, |
---|
6119 | | - data->res.lr_ret); |
---|
6120 | | - nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
---|
| 6487 | + nfs4_fattr_set_prechange(&data->fattr, |
---|
| 6488 | + inode_peek_iversion_raw(inode)); |
---|
| 6489 | + nfs_refresh_inode(inode, &data->fattr); |
---|
6121 | 6490 | nfs_iput_and_deactive(inode); |
---|
6122 | 6491 | } |
---|
6123 | 6492 | kfree(calldata); |
---|
.. | .. |
---|
6153 | 6522 | .rpc_release = nfs4_delegreturn_release, |
---|
6154 | 6523 | }; |
---|
6155 | 6524 | |
---|
6156 | | -static int _nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync) |
---|
| 6525 | +static int _nfs4_proc_delegreturn(struct inode *inode, const struct cred *cred, const nfs4_stateid *stateid, int issync) |
---|
6157 | 6526 | { |
---|
6158 | 6527 | struct nfs4_delegreturndata *data; |
---|
6159 | 6528 | struct nfs_server *server = NFS_SERVER(inode); |
---|
.. | .. |
---|
6166 | 6535 | .rpc_client = server->client, |
---|
6167 | 6536 | .rpc_message = &msg, |
---|
6168 | 6537 | .callback_ops = &nfs4_delegreturn_ops, |
---|
6169 | | - .flags = RPC_TASK_ASYNC, |
---|
| 6538 | + .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT, |
---|
6170 | 6539 | }; |
---|
6171 | 6540 | int status = 0; |
---|
6172 | 6541 | |
---|
.. | .. |
---|
6180 | 6549 | |
---|
6181 | 6550 | data->args.fhandle = &data->fh; |
---|
6182 | 6551 | data->args.stateid = &data->stateid; |
---|
6183 | | - data->args.bitmask = server->cache_consistency_bitmask; |
---|
| 6552 | + nfs4_bitmask_set(data->args.bitmask_store, |
---|
| 6553 | + server->cache_consistency_bitmask, inode, server, |
---|
| 6554 | + NULL); |
---|
| 6555 | + data->args.bitmask = data->args.bitmask_store; |
---|
6184 | 6556 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
---|
6185 | 6557 | nfs4_stateid_copy(&data->stateid, stateid); |
---|
6186 | 6558 | data->res.fattr = &data->fattr; |
---|
.. | .. |
---|
6190 | 6562 | nfs_fattr_init(data->res.fattr); |
---|
6191 | 6563 | data->timestamp = jiffies; |
---|
6192 | 6564 | data->rpc_status = 0; |
---|
6193 | | - data->lr.roc = pnfs_roc(inode, &data->lr.arg, &data->lr.res, cred); |
---|
6194 | 6565 | data->inode = nfs_igrab_and_active(inode); |
---|
6195 | | - if (data->inode) { |
---|
| 6566 | + if (data->inode || issync) { |
---|
| 6567 | + data->lr.roc = pnfs_roc(inode, &data->lr.arg, &data->lr.res, |
---|
| 6568 | + cred); |
---|
6196 | 6569 | if (data->lr.roc) { |
---|
6197 | 6570 | data->args.lr_args = &data->lr.arg; |
---|
6198 | 6571 | data->res.lr_res = &data->lr.res; |
---|
6199 | 6572 | } |
---|
6200 | | - } else if (data->lr.roc) { |
---|
6201 | | - pnfs_roc_release(&data->lr.arg, &data->lr.res, 0); |
---|
6202 | | - data->lr.roc = false; |
---|
6203 | 6573 | } |
---|
6204 | 6574 | |
---|
6205 | 6575 | if (!data->inode) |
---|
.. | .. |
---|
6225 | 6595 | return status; |
---|
6226 | 6596 | } |
---|
6227 | 6597 | |
---|
6228 | | -int nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync) |
---|
| 6598 | +int nfs4_proc_delegreturn(struct inode *inode, const struct cred *cred, const nfs4_stateid *stateid, int issync) |
---|
6229 | 6599 | { |
---|
6230 | 6600 | struct nfs_server *server = NFS_SERVER(inode); |
---|
6231 | 6601 | struct nfs4_exception exception = { }; |
---|
.. | .. |
---|
6288 | 6658 | |
---|
6289 | 6659 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
---|
6290 | 6660 | { |
---|
6291 | | - struct nfs4_exception exception = { }; |
---|
| 6661 | + struct nfs4_exception exception = { |
---|
| 6662 | + .interruptible = true, |
---|
| 6663 | + }; |
---|
6292 | 6664 | int err; |
---|
6293 | 6665 | |
---|
6294 | 6666 | do { |
---|
.. | .. |
---|
6298 | 6670 | &exception); |
---|
6299 | 6671 | } while (exception.retry); |
---|
6300 | 6672 | return err; |
---|
| 6673 | +} |
---|
| 6674 | + |
---|
| 6675 | +/* |
---|
| 6676 | + * Update the seqid of a lock stateid after receiving |
---|
| 6677 | + * NFS4ERR_OLD_STATEID |
---|
| 6678 | + */ |
---|
| 6679 | +static bool nfs4_refresh_lock_old_stateid(nfs4_stateid *dst, |
---|
| 6680 | + struct nfs4_lock_state *lsp) |
---|
| 6681 | +{ |
---|
| 6682 | + struct nfs4_state *state = lsp->ls_state; |
---|
| 6683 | + bool ret = false; |
---|
| 6684 | + |
---|
| 6685 | + spin_lock(&state->state_lock); |
---|
| 6686 | + if (!nfs4_stateid_match_other(dst, &lsp->ls_stateid)) |
---|
| 6687 | + goto out; |
---|
| 6688 | + if (!nfs4_stateid_is_newer(&lsp->ls_stateid, dst)) |
---|
| 6689 | + nfs4_stateid_seqid_inc(dst); |
---|
| 6690 | + else |
---|
| 6691 | + dst->seqid = lsp->ls_stateid.seqid; |
---|
| 6692 | + ret = true; |
---|
| 6693 | +out: |
---|
| 6694 | + spin_unlock(&state->state_lock); |
---|
| 6695 | + return ret; |
---|
| 6696 | +} |
---|
| 6697 | + |
---|
| 6698 | +static bool nfs4_sync_lock_stateid(nfs4_stateid *dst, |
---|
| 6699 | + struct nfs4_lock_state *lsp) |
---|
| 6700 | +{ |
---|
| 6701 | + struct nfs4_state *state = lsp->ls_state; |
---|
| 6702 | + bool ret; |
---|
| 6703 | + |
---|
| 6704 | + spin_lock(&state->state_lock); |
---|
| 6705 | + ret = !nfs4_stateid_match_other(dst, &lsp->ls_stateid); |
---|
| 6706 | + nfs4_stateid_copy(dst, &lsp->ls_stateid); |
---|
| 6707 | + spin_unlock(&state->state_lock); |
---|
| 6708 | + return ret; |
---|
6301 | 6709 | } |
---|
6302 | 6710 | |
---|
6303 | 6711 | struct nfs4_unlockdata { |
---|
.. | .. |
---|
6317 | 6725 | struct nfs_seqid *seqid) |
---|
6318 | 6726 | { |
---|
6319 | 6727 | struct nfs4_unlockdata *p; |
---|
6320 | | - struct inode *inode = lsp->ls_state->inode; |
---|
| 6728 | + struct nfs4_state *state = lsp->ls_state; |
---|
| 6729 | + struct inode *inode = state->inode; |
---|
6321 | 6730 | |
---|
6322 | 6731 | p = kzalloc(sizeof(*p), GFP_NOFS); |
---|
6323 | 6732 | if (p == NULL) |
---|
.. | .. |
---|
6327 | 6736 | p->arg.seqid = seqid; |
---|
6328 | 6737 | p->res.seqid = seqid; |
---|
6329 | 6738 | p->lsp = lsp; |
---|
6330 | | - refcount_inc(&lsp->ls_count); |
---|
6331 | 6739 | /* Ensure we don't close file until we're done freeing locks! */ |
---|
6332 | 6740 | p->ctx = get_nfs_open_context(ctx); |
---|
6333 | 6741 | p->l_ctx = nfs_get_lock_context(ctx); |
---|
6334 | | - memcpy(&p->fl, fl, sizeof(p->fl)); |
---|
| 6742 | + locks_init_lock(&p->fl); |
---|
| 6743 | + locks_copy_lock(&p->fl, fl); |
---|
6335 | 6744 | p->server = NFS_SERVER(inode); |
---|
| 6745 | + spin_lock(&state->state_lock); |
---|
| 6746 | + nfs4_stateid_copy(&p->arg.stateid, &lsp->ls_stateid); |
---|
| 6747 | + spin_unlock(&state->state_lock); |
---|
6336 | 6748 | return p; |
---|
6337 | 6749 | } |
---|
6338 | 6750 | |
---|
.. | .. |
---|
6363 | 6775 | if (nfs4_update_lock_stateid(calldata->lsp, |
---|
6364 | 6776 | &calldata->res.stateid)) |
---|
6365 | 6777 | break; |
---|
6366 | | - /* Fall through */ |
---|
| 6778 | + fallthrough; |
---|
6367 | 6779 | case -NFS4ERR_ADMIN_REVOKED: |
---|
6368 | 6780 | case -NFS4ERR_EXPIRED: |
---|
6369 | 6781 | nfs4_free_revoked_stateid(calldata->server, |
---|
6370 | 6782 | &calldata->arg.stateid, |
---|
6371 | 6783 | task->tk_msg.rpc_cred); |
---|
6372 | | - /* Fall through */ |
---|
| 6784 | + fallthrough; |
---|
6373 | 6785 | case -NFS4ERR_BAD_STATEID: |
---|
6374 | | - case -NFS4ERR_OLD_STATEID: |
---|
6375 | 6786 | case -NFS4ERR_STALE_STATEID: |
---|
6376 | | - if (!nfs4_stateid_match(&calldata->arg.stateid, |
---|
6377 | | - &calldata->lsp->ls_stateid)) |
---|
| 6787 | + if (nfs4_sync_lock_stateid(&calldata->arg.stateid, |
---|
| 6788 | + calldata->lsp)) |
---|
| 6789 | + rpc_restart_call_prepare(task); |
---|
| 6790 | + break; |
---|
| 6791 | + case -NFS4ERR_OLD_STATEID: |
---|
| 6792 | + if (nfs4_refresh_lock_old_stateid(&calldata->arg.stateid, |
---|
| 6793 | + calldata->lsp)) |
---|
6378 | 6794 | rpc_restart_call_prepare(task); |
---|
6379 | 6795 | break; |
---|
6380 | 6796 | default: |
---|
.. | .. |
---|
6397 | 6813 | |
---|
6398 | 6814 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
---|
6399 | 6815 | goto out_wait; |
---|
6400 | | - nfs4_stateid_copy(&calldata->arg.stateid, &calldata->lsp->ls_stateid); |
---|
6401 | 6816 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
---|
6402 | 6817 | /* Note: exit _without_ running nfs4_locku_done */ |
---|
6403 | 6818 | goto out_no_action; |
---|
.. | .. |
---|
6551 | 6966 | p->res.lock_seqid = p->arg.lock_seqid; |
---|
6552 | 6967 | p->lsp = lsp; |
---|
6553 | 6968 | p->server = server; |
---|
6554 | | - refcount_inc(&lsp->ls_count); |
---|
6555 | 6969 | p->ctx = get_nfs_open_context(ctx); |
---|
6556 | | - memcpy(&p->fl, fl, sizeof(p->fl)); |
---|
| 6970 | + locks_init_lock(&p->fl); |
---|
| 6971 | + locks_copy_lock(&p->fl, fl); |
---|
6557 | 6972 | return p; |
---|
6558 | 6973 | out_free_seqid: |
---|
6559 | 6974 | nfs_free_seqid(p->arg.open_seqid); |
---|
.. | .. |
---|
6608 | 7023 | { |
---|
6609 | 7024 | struct nfs4_lockdata *data = calldata; |
---|
6610 | 7025 | struct nfs4_lock_state *lsp = data->lsp; |
---|
| 7026 | + struct nfs_server *server = NFS_SERVER(d_inode(data->ctx->dentry)); |
---|
6611 | 7027 | |
---|
6612 | 7028 | dprintk("%s: begin!\n", __func__); |
---|
6613 | 7029 | |
---|
.. | .. |
---|
6617 | 7033 | data->rpc_status = task->tk_status; |
---|
6618 | 7034 | switch (task->tk_status) { |
---|
6619 | 7035 | case 0: |
---|
6620 | | - renew_lease(NFS_SERVER(d_inode(data->ctx->dentry)), |
---|
6621 | | - data->timestamp); |
---|
| 7036 | + renew_lease(server, data->timestamp); |
---|
6622 | 7037 | if (data->arg.new_lock && !data->cancelled) { |
---|
6623 | 7038 | data->fl.fl_flags &= ~(FL_SLEEP | FL_ACCESS); |
---|
6624 | 7039 | if (locks_lock_inode_wait(lsp->ls_state->inode, &data->fl) < 0) |
---|
.. | .. |
---|
6631 | 7046 | } else if (!nfs4_update_lock_stateid(lsp, &data->res.stateid)) |
---|
6632 | 7047 | goto out_restart; |
---|
6633 | 7048 | break; |
---|
6634 | | - case -NFS4ERR_BAD_STATEID: |
---|
6635 | 7049 | case -NFS4ERR_OLD_STATEID: |
---|
| 7050 | + if (data->arg.new_lock_owner != 0 && |
---|
| 7051 | + nfs4_refresh_open_old_stateid(&data->arg.open_stateid, |
---|
| 7052 | + lsp->ls_state)) |
---|
| 7053 | + goto out_restart; |
---|
| 7054 | + if (nfs4_refresh_lock_old_stateid(&data->arg.lock_stateid, lsp)) |
---|
| 7055 | + goto out_restart; |
---|
| 7056 | + fallthrough; |
---|
| 7057 | + case -NFS4ERR_BAD_STATEID: |
---|
6636 | 7058 | case -NFS4ERR_STALE_STATEID: |
---|
6637 | 7059 | case -NFS4ERR_EXPIRED: |
---|
6638 | 7060 | if (data->arg.new_lock_owner != 0) { |
---|
6639 | 7061 | if (!nfs4_stateid_match(&data->arg.open_stateid, |
---|
6640 | 7062 | &lsp->ls_state->open_stateid)) |
---|
| 7063 | + goto out_restart; |
---|
| 7064 | + else if (nfs4_async_handle_error(task, server, lsp->ls_state, NULL) == -EAGAIN) |
---|
6641 | 7065 | goto out_restart; |
---|
6642 | 7066 | } else if (!nfs4_stateid_match(&data->arg.lock_stateid, |
---|
6643 | 7067 | &lsp->ls_stateid)) |
---|
.. | .. |
---|
6693 | 7117 | case -NFS4ERR_STALE_STATEID: |
---|
6694 | 7118 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
---|
6695 | 7119 | nfs4_schedule_lease_recovery(server->nfs_client); |
---|
6696 | | - }; |
---|
| 7120 | + } |
---|
6697 | 7121 | } |
---|
6698 | 7122 | |
---|
6699 | 7123 | static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *fl, int recovery_type) |
---|
.. | .. |
---|
6709 | 7133 | .rpc_message = &msg, |
---|
6710 | 7134 | .callback_ops = &nfs4_lock_ops, |
---|
6711 | 7135 | .workqueue = nfsiod_workqueue, |
---|
6712 | | - .flags = RPC_TASK_ASYNC, |
---|
| 7136 | + .flags = RPC_TASK_ASYNC | RPC_TASK_CRED_NOREF, |
---|
6713 | 7137 | }; |
---|
6714 | 7138 | int ret; |
---|
6715 | 7139 | |
---|
.. | .. |
---|
6852 | 7276 | struct nfs4_exception exception = { |
---|
6853 | 7277 | .state = state, |
---|
6854 | 7278 | .inode = state->inode, |
---|
| 7279 | + .interruptible = true, |
---|
6855 | 7280 | }; |
---|
6856 | 7281 | int err; |
---|
6857 | 7282 | |
---|
.. | .. |
---|
7136 | 7561 | |
---|
7137 | 7562 | static int nfs4_xattr_get_nfs4_acl(const struct xattr_handler *handler, |
---|
7138 | 7563 | struct dentry *unused, struct inode *inode, |
---|
7139 | | - const char *key, void *buf, size_t buflen) |
---|
| 7564 | + const char *key, void *buf, size_t buflen, |
---|
| 7565 | + int flags) |
---|
7140 | 7566 | { |
---|
7141 | 7567 | return nfs4_proc_get_acl(inode, buf, buflen); |
---|
7142 | 7568 | } |
---|
.. | .. |
---|
7161 | 7587 | |
---|
7162 | 7588 | static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler, |
---|
7163 | 7589 | struct dentry *unused, struct inode *inode, |
---|
7164 | | - const char *key, void *buf, size_t buflen) |
---|
| 7590 | + const char *key, void *buf, size_t buflen, |
---|
| 7591 | + int flags) |
---|
7165 | 7592 | { |
---|
7166 | 7593 | if (security_ismaclabel(key)) |
---|
7167 | 7594 | return nfs4_get_security_label(inode, buf, buflen); |
---|
.. | .. |
---|
7175 | 7602 | |
---|
7176 | 7603 | if (nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL)) { |
---|
7177 | 7604 | len = security_inode_listsecurity(inode, list, list_len); |
---|
7178 | | - if (list_len && len > list_len) |
---|
| 7605 | + if (len >= 0 && list_len && len > list_len) |
---|
7179 | 7606 | return -ERANGE; |
---|
7180 | 7607 | } |
---|
7181 | 7608 | return len; |
---|
.. | .. |
---|
7196 | 7623 | } |
---|
7197 | 7624 | |
---|
7198 | 7625 | #endif |
---|
| 7626 | + |
---|
| 7627 | +#ifdef CONFIG_NFS_V4_2 |
---|
| 7628 | +static int nfs4_xattr_set_nfs4_user(const struct xattr_handler *handler, |
---|
| 7629 | + struct dentry *unused, struct inode *inode, |
---|
| 7630 | + const char *key, const void *buf, |
---|
| 7631 | + size_t buflen, int flags) |
---|
| 7632 | +{ |
---|
| 7633 | + u32 mask; |
---|
| 7634 | + int ret; |
---|
| 7635 | + |
---|
| 7636 | + if (!nfs_server_capable(inode, NFS_CAP_XATTR)) |
---|
| 7637 | + return -EOPNOTSUPP; |
---|
| 7638 | + |
---|
| 7639 | + /* |
---|
| 7640 | + * There is no mapping from the MAY_* flags to the NFS_ACCESS_XA* |
---|
| 7641 | + * flags right now. Handling of xattr operations use the normal |
---|
| 7642 | + * file read/write permissions. |
---|
| 7643 | + * |
---|
| 7644 | + * Just in case the server has other ideas (which RFC 8276 allows), |
---|
| 7645 | + * do a cached access check for the XA* flags to possibly avoid |
---|
| 7646 | + * doing an RPC and getting EACCES back. |
---|
| 7647 | + */ |
---|
| 7648 | + if (!nfs_access_get_cached(inode, current_cred(), &mask, true)) { |
---|
| 7649 | + if (!(mask & NFS_ACCESS_XAWRITE)) |
---|
| 7650 | + return -EACCES; |
---|
| 7651 | + } |
---|
| 7652 | + |
---|
| 7653 | + if (buf == NULL) { |
---|
| 7654 | + ret = nfs42_proc_removexattr(inode, key); |
---|
| 7655 | + if (!ret) |
---|
| 7656 | + nfs4_xattr_cache_remove(inode, key); |
---|
| 7657 | + } else { |
---|
| 7658 | + ret = nfs42_proc_setxattr(inode, key, buf, buflen, flags); |
---|
| 7659 | + if (!ret) |
---|
| 7660 | + nfs4_xattr_cache_add(inode, key, buf, NULL, buflen); |
---|
| 7661 | + } |
---|
| 7662 | + |
---|
| 7663 | + return ret; |
---|
| 7664 | +} |
---|
| 7665 | + |
---|
| 7666 | +static int nfs4_xattr_get_nfs4_user(const struct xattr_handler *handler, |
---|
| 7667 | + struct dentry *unused, struct inode *inode, |
---|
| 7668 | + const char *key, void *buf, size_t buflen, |
---|
| 7669 | + int flags) |
---|
| 7670 | +{ |
---|
| 7671 | + u32 mask; |
---|
| 7672 | + ssize_t ret; |
---|
| 7673 | + |
---|
| 7674 | + if (!nfs_server_capable(inode, NFS_CAP_XATTR)) |
---|
| 7675 | + return -EOPNOTSUPP; |
---|
| 7676 | + |
---|
| 7677 | + if (!nfs_access_get_cached(inode, current_cred(), &mask, true)) { |
---|
| 7678 | + if (!(mask & NFS_ACCESS_XAREAD)) |
---|
| 7679 | + return -EACCES; |
---|
| 7680 | + } |
---|
| 7681 | + |
---|
| 7682 | + ret = nfs_revalidate_inode(NFS_SERVER(inode), inode); |
---|
| 7683 | + if (ret) |
---|
| 7684 | + return ret; |
---|
| 7685 | + |
---|
| 7686 | + ret = nfs4_xattr_cache_get(inode, key, buf, buflen); |
---|
| 7687 | + if (ret >= 0 || (ret < 0 && ret != -ENOENT)) |
---|
| 7688 | + return ret; |
---|
| 7689 | + |
---|
| 7690 | + ret = nfs42_proc_getxattr(inode, key, buf, buflen); |
---|
| 7691 | + |
---|
| 7692 | + return ret; |
---|
| 7693 | +} |
---|
| 7694 | + |
---|
| 7695 | +static ssize_t |
---|
| 7696 | +nfs4_listxattr_nfs4_user(struct inode *inode, char *list, size_t list_len) |
---|
| 7697 | +{ |
---|
| 7698 | + u64 cookie; |
---|
| 7699 | + bool eof; |
---|
| 7700 | + ssize_t ret, size; |
---|
| 7701 | + char *buf; |
---|
| 7702 | + size_t buflen; |
---|
| 7703 | + u32 mask; |
---|
| 7704 | + |
---|
| 7705 | + if (!nfs_server_capable(inode, NFS_CAP_XATTR)) |
---|
| 7706 | + return 0; |
---|
| 7707 | + |
---|
| 7708 | + if (!nfs_access_get_cached(inode, current_cred(), &mask, true)) { |
---|
| 7709 | + if (!(mask & NFS_ACCESS_XALIST)) |
---|
| 7710 | + return 0; |
---|
| 7711 | + } |
---|
| 7712 | + |
---|
| 7713 | + ret = nfs_revalidate_inode(NFS_SERVER(inode), inode); |
---|
| 7714 | + if (ret) |
---|
| 7715 | + return ret; |
---|
| 7716 | + |
---|
| 7717 | + ret = nfs4_xattr_cache_list(inode, list, list_len); |
---|
| 7718 | + if (ret >= 0 || (ret < 0 && ret != -ENOENT)) |
---|
| 7719 | + return ret; |
---|
| 7720 | + |
---|
| 7721 | + cookie = 0; |
---|
| 7722 | + eof = false; |
---|
| 7723 | + buflen = list_len ? list_len : XATTR_LIST_MAX; |
---|
| 7724 | + buf = list_len ? list : NULL; |
---|
| 7725 | + size = 0; |
---|
| 7726 | + |
---|
| 7727 | + while (!eof) { |
---|
| 7728 | + ret = nfs42_proc_listxattrs(inode, buf, buflen, |
---|
| 7729 | + &cookie, &eof); |
---|
| 7730 | + if (ret < 0) |
---|
| 7731 | + return ret; |
---|
| 7732 | + |
---|
| 7733 | + if (list_len) { |
---|
| 7734 | + buf += ret; |
---|
| 7735 | + buflen -= ret; |
---|
| 7736 | + } |
---|
| 7737 | + size += ret; |
---|
| 7738 | + } |
---|
| 7739 | + |
---|
| 7740 | + if (list_len) |
---|
| 7741 | + nfs4_xattr_cache_set_list(inode, list, size); |
---|
| 7742 | + |
---|
| 7743 | + return size; |
---|
| 7744 | +} |
---|
| 7745 | + |
---|
| 7746 | +#else |
---|
| 7747 | + |
---|
| 7748 | +static ssize_t |
---|
| 7749 | +nfs4_listxattr_nfs4_user(struct inode *inode, char *list, size_t list_len) |
---|
| 7750 | +{ |
---|
| 7751 | + return 0; |
---|
| 7752 | +} |
---|
| 7753 | +#endif /* CONFIG_NFS_V4_2 */ |
---|
7199 | 7754 | |
---|
7200 | 7755 | /* |
---|
7201 | 7756 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
---|
.. | .. |
---|
7262 | 7817 | struct nfs4_fs_locations *fs_locations, |
---|
7263 | 7818 | struct page *page) |
---|
7264 | 7819 | { |
---|
7265 | | - struct nfs4_exception exception = { }; |
---|
| 7820 | + struct nfs4_exception exception = { |
---|
| 7821 | + .interruptible = true, |
---|
| 7822 | + }; |
---|
7266 | 7823 | int err; |
---|
7267 | 7824 | do { |
---|
7268 | 7825 | err = _nfs4_proc_fs_locations(client, dir, name, |
---|
.. | .. |
---|
7283 | 7840 | */ |
---|
7284 | 7841 | static int _nfs40_proc_get_locations(struct inode *inode, |
---|
7285 | 7842 | struct nfs4_fs_locations *locations, |
---|
7286 | | - struct page *page, struct rpc_cred *cred) |
---|
| 7843 | + struct page *page, const struct cred *cred) |
---|
7287 | 7844 | { |
---|
7288 | 7845 | struct nfs_server *server = NFS_SERVER(inode); |
---|
7289 | 7846 | struct rpc_clnt *clnt = server->client; |
---|
.. | .. |
---|
7340 | 7897 | */ |
---|
7341 | 7898 | static int _nfs41_proc_get_locations(struct inode *inode, |
---|
7342 | 7899 | struct nfs4_fs_locations *locations, |
---|
7343 | | - struct page *page, struct rpc_cred *cred) |
---|
| 7900 | + struct page *page, const struct cred *cred) |
---|
7344 | 7901 | { |
---|
7345 | 7902 | struct nfs_server *server = NFS_SERVER(inode); |
---|
7346 | 7903 | struct rpc_clnt *clnt = server->client; |
---|
.. | .. |
---|
7399 | 7956 | */ |
---|
7400 | 7957 | int nfs4_proc_get_locations(struct inode *inode, |
---|
7401 | 7958 | struct nfs4_fs_locations *locations, |
---|
7402 | | - struct page *page, struct rpc_cred *cred) |
---|
| 7959 | + struct page *page, const struct cred *cred) |
---|
7403 | 7960 | { |
---|
7404 | 7961 | struct nfs_server *server = NFS_SERVER(inode); |
---|
7405 | 7962 | struct nfs_client *clp = server->nfs_client; |
---|
7406 | 7963 | const struct nfs4_mig_recovery_ops *ops = |
---|
7407 | 7964 | clp->cl_mvops->mig_recovery_ops; |
---|
7408 | | - struct nfs4_exception exception = { }; |
---|
| 7965 | + struct nfs4_exception exception = { |
---|
| 7966 | + .interruptible = true, |
---|
| 7967 | + }; |
---|
7409 | 7968 | int status; |
---|
7410 | 7969 | |
---|
7411 | 7970 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
---|
.. | .. |
---|
7430 | 7989 | * is appended to this compound to identify the client ID which is |
---|
7431 | 7990 | * performing recovery. |
---|
7432 | 7991 | */ |
---|
7433 | | -static int _nfs40_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
---|
| 7992 | +static int _nfs40_proc_fsid_present(struct inode *inode, const struct cred *cred) |
---|
7434 | 7993 | { |
---|
7435 | 7994 | struct nfs_server *server = NFS_SERVER(inode); |
---|
7436 | 7995 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
---|
.. | .. |
---|
7476 | 8035 | * this operation is identified in the SEQUENCE operation in this |
---|
7477 | 8036 | * compound. |
---|
7478 | 8037 | */ |
---|
7479 | | -static int _nfs41_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
---|
| 8038 | +static int _nfs41_proc_fsid_present(struct inode *inode, const struct cred *cred) |
---|
7480 | 8039 | { |
---|
7481 | 8040 | struct nfs_server *server = NFS_SERVER(inode); |
---|
7482 | 8041 | struct rpc_clnt *clnt = server->client; |
---|
.. | .. |
---|
7523 | 8082 | * NFS4ERR code if some error occurred on the server, or a |
---|
7524 | 8083 | * negative errno if a local failure occurred. |
---|
7525 | 8084 | */ |
---|
7526 | | -int nfs4_proc_fsid_present(struct inode *inode, struct rpc_cred *cred) |
---|
| 8085 | +int nfs4_proc_fsid_present(struct inode *inode, const struct cred *cred) |
---|
7527 | 8086 | { |
---|
7528 | 8087 | struct nfs_server *server = NFS_SERVER(inode); |
---|
7529 | 8088 | struct nfs_client *clp = server->nfs_client; |
---|
7530 | 8089 | const struct nfs4_mig_recovery_ops *ops = |
---|
7531 | 8090 | clp->cl_mvops->mig_recovery_ops; |
---|
7532 | | - struct nfs4_exception exception = { }; |
---|
| 8091 | + struct nfs4_exception exception = { |
---|
| 8092 | + .interruptible = true, |
---|
| 8093 | + }; |
---|
7533 | 8094 | int status; |
---|
7534 | 8095 | |
---|
7535 | 8096 | dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__, |
---|
.. | .. |
---|
7547 | 8108 | return status; |
---|
7548 | 8109 | } |
---|
7549 | 8110 | |
---|
7550 | | -/** |
---|
| 8111 | +/* |
---|
7551 | 8112 | * If 'use_integrity' is true and the state managment nfs_client |
---|
7552 | 8113 | * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient |
---|
7553 | 8114 | * and the machine credential as per RFC3530bis and RFC5661 Security |
---|
.. | .. |
---|
7557 | 8118 | static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors, bool use_integrity) |
---|
7558 | 8119 | { |
---|
7559 | 8120 | int status; |
---|
| 8121 | + struct rpc_clnt *clnt = NFS_SERVER(dir)->client; |
---|
| 8122 | + struct nfs_client *clp = NFS_SERVER(dir)->nfs_client; |
---|
7560 | 8123 | struct nfs4_secinfo_arg args = { |
---|
7561 | 8124 | .dir_fh = NFS_FH(dir), |
---|
7562 | 8125 | .name = name, |
---|
.. | .. |
---|
7569 | 8132 | .rpc_argp = &args, |
---|
7570 | 8133 | .rpc_resp = &res, |
---|
7571 | 8134 | }; |
---|
7572 | | - struct rpc_clnt *clnt = NFS_SERVER(dir)->client; |
---|
7573 | | - struct rpc_cred *cred = NULL; |
---|
| 8135 | + struct nfs4_call_sync_data data = { |
---|
| 8136 | + .seq_server = NFS_SERVER(dir), |
---|
| 8137 | + .seq_args = &args.seq_args, |
---|
| 8138 | + .seq_res = &res.seq_res, |
---|
| 8139 | + }; |
---|
| 8140 | + struct rpc_task_setup task_setup = { |
---|
| 8141 | + .rpc_client = clnt, |
---|
| 8142 | + .rpc_message = &msg, |
---|
| 8143 | + .callback_ops = clp->cl_mvops->call_sync_ops, |
---|
| 8144 | + .callback_data = &data, |
---|
| 8145 | + .flags = RPC_TASK_NO_ROUND_ROBIN, |
---|
| 8146 | + }; |
---|
| 8147 | + const struct cred *cred = NULL; |
---|
7574 | 8148 | |
---|
7575 | 8149 | if (use_integrity) { |
---|
7576 | | - clnt = NFS_SERVER(dir)->nfs_client->cl_rpcclient; |
---|
7577 | | - cred = nfs4_get_clid_cred(NFS_SERVER(dir)->nfs_client); |
---|
| 8150 | + clnt = clp->cl_rpcclient; |
---|
| 8151 | + task_setup.rpc_client = clnt; |
---|
| 8152 | + |
---|
| 8153 | + cred = nfs4_get_clid_cred(clp); |
---|
7578 | 8154 | msg.rpc_cred = cred; |
---|
7579 | 8155 | } |
---|
7580 | 8156 | |
---|
7581 | 8157 | dprintk("NFS call secinfo %s\n", name->name); |
---|
7582 | 8158 | |
---|
7583 | | - nfs4_state_protect(NFS_SERVER(dir)->nfs_client, |
---|
7584 | | - NFS_SP4_MACH_CRED_SECINFO, &clnt, &msg); |
---|
| 8159 | + nfs4_state_protect(clp, NFS_SP4_MACH_CRED_SECINFO, &clnt, &msg); |
---|
| 8160 | + nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 0); |
---|
| 8161 | + status = nfs4_call_sync_custom(&task_setup); |
---|
7585 | 8162 | |
---|
7586 | | - status = nfs4_call_sync(clnt, NFS_SERVER(dir), &msg, &args.seq_args, |
---|
7587 | | - &res.seq_res, 0); |
---|
7588 | 8163 | dprintk("NFS reply secinfo: %d\n", status); |
---|
7589 | 8164 | |
---|
7590 | | - if (cred) |
---|
7591 | | - put_rpccred(cred); |
---|
7592 | | - |
---|
| 8165 | + put_cred(cred); |
---|
7593 | 8166 | return status; |
---|
7594 | 8167 | } |
---|
7595 | 8168 | |
---|
7596 | 8169 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
---|
7597 | 8170 | struct nfs4_secinfo_flavors *flavors) |
---|
7598 | 8171 | { |
---|
7599 | | - struct nfs4_exception exception = { }; |
---|
| 8172 | + struct nfs4_exception exception = { |
---|
| 8173 | + .interruptible = true, |
---|
| 8174 | + }; |
---|
7600 | 8175 | int err; |
---|
7601 | 8176 | do { |
---|
7602 | 8177 | err = -NFS4ERR_WRONGSEC; |
---|
.. | .. |
---|
7655 | 8230 | static void |
---|
7656 | 8231 | nfs4_bind_one_conn_to_session_done(struct rpc_task *task, void *calldata) |
---|
7657 | 8232 | { |
---|
| 8233 | + struct nfs41_bind_conn_to_session_args *args = task->tk_msg.rpc_argp; |
---|
| 8234 | + struct nfs41_bind_conn_to_session_res *res = task->tk_msg.rpc_resp; |
---|
| 8235 | + struct nfs_client *clp = args->client; |
---|
| 8236 | + |
---|
| 8237 | + switch (task->tk_status) { |
---|
| 8238 | + case -NFS4ERR_BADSESSION: |
---|
| 8239 | + case -NFS4ERR_DEADSESSION: |
---|
| 8240 | + nfs4_schedule_session_recovery(clp->cl_session, |
---|
| 8241 | + task->tk_status); |
---|
| 8242 | + return; |
---|
| 8243 | + } |
---|
| 8244 | + if (args->dir == NFS4_CDFC4_FORE_OR_BOTH && |
---|
| 8245 | + res->dir != NFS4_CDFS4_BOTH) { |
---|
| 8246 | + rpc_task_close_connection(task); |
---|
| 8247 | + if (args->retries++ < MAX_BIND_CONN_TO_SESSION_RETRIES) |
---|
| 8248 | + rpc_restart_call(task); |
---|
| 8249 | + } |
---|
7658 | 8250 | } |
---|
7659 | 8251 | |
---|
7660 | 8252 | static const struct rpc_call_ops nfs4_bind_one_conn_to_session_ops = { |
---|
.. | .. |
---|
7671 | 8263 | int nfs4_proc_bind_one_conn_to_session(struct rpc_clnt *clnt, |
---|
7672 | 8264 | struct rpc_xprt *xprt, |
---|
7673 | 8265 | struct nfs_client *clp, |
---|
7674 | | - struct rpc_cred *cred) |
---|
| 8266 | + const struct cred *cred) |
---|
7675 | 8267 | { |
---|
7676 | 8268 | int status; |
---|
7677 | 8269 | struct nfs41_bind_conn_to_session_args args = { |
---|
7678 | 8270 | .client = clp, |
---|
7679 | 8271 | .dir = NFS4_CDFC4_FORE_OR_BOTH, |
---|
| 8272 | + .retries = 0, |
---|
7680 | 8273 | }; |
---|
7681 | 8274 | struct nfs41_bind_conn_to_session_res res; |
---|
7682 | 8275 | struct rpc_message msg = { |
---|
.. | .. |
---|
7733 | 8326 | |
---|
7734 | 8327 | struct rpc_bind_conn_calldata { |
---|
7735 | 8328 | struct nfs_client *clp; |
---|
7736 | | - struct rpc_cred *cred; |
---|
| 8329 | + const struct cred *cred; |
---|
7737 | 8330 | }; |
---|
7738 | 8331 | |
---|
7739 | 8332 | static int |
---|
.. | .. |
---|
7746 | 8339 | return nfs4_proc_bind_one_conn_to_session(clnt, xprt, p->clp, p->cred); |
---|
7747 | 8340 | } |
---|
7748 | 8341 | |
---|
7749 | | -int nfs4_proc_bind_conn_to_session(struct nfs_client *clp, struct rpc_cred *cred) |
---|
| 8342 | +int nfs4_proc_bind_conn_to_session(struct nfs_client *clp, const struct cred *cred) |
---|
7750 | 8343 | { |
---|
7751 | 8344 | struct rpc_bind_conn_calldata data = { |
---|
7752 | 8345 | .clp = clp, |
---|
.. | .. |
---|
7912 | 8505 | * Wrapper for EXCHANGE_ID operation. |
---|
7913 | 8506 | */ |
---|
7914 | 8507 | static struct rpc_task * |
---|
7915 | | -nfs4_run_exchange_id(struct nfs_client *clp, struct rpc_cred *cred, |
---|
| 8508 | +nfs4_run_exchange_id(struct nfs_client *clp, const struct cred *cred, |
---|
7916 | 8509 | u32 sp4_how, struct rpc_xprt *xprt) |
---|
7917 | 8510 | { |
---|
7918 | 8511 | struct rpc_message msg = { |
---|
.. | .. |
---|
7923 | 8516 | .rpc_client = clp->cl_rpcclient, |
---|
7924 | 8517 | .callback_ops = &nfs4_exchange_id_call_ops, |
---|
7925 | 8518 | .rpc_message = &msg, |
---|
7926 | | - .flags = RPC_TASK_TIMEOUT, |
---|
| 8519 | + .flags = RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN, |
---|
7927 | 8520 | }; |
---|
7928 | 8521 | struct nfs41_exchange_id_data *calldata; |
---|
7929 | 8522 | int status; |
---|
.. | .. |
---|
8008 | 8601 | * |
---|
8009 | 8602 | * Wrapper for EXCHANGE_ID operation. |
---|
8010 | 8603 | */ |
---|
8011 | | -static int _nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred, |
---|
| 8604 | +static int _nfs4_proc_exchange_id(struct nfs_client *clp, const struct cred *cred, |
---|
8012 | 8605 | u32 sp4_how) |
---|
8013 | 8606 | { |
---|
8014 | 8607 | struct rpc_task *task; |
---|
8015 | 8608 | struct nfs41_exchange_id_args *argp; |
---|
8016 | 8609 | struct nfs41_exchange_id_res *resp; |
---|
| 8610 | + unsigned long now = jiffies; |
---|
8017 | 8611 | int status; |
---|
8018 | 8612 | |
---|
8019 | 8613 | task = nfs4_run_exchange_id(clp, cred, sp4_how, NULL); |
---|
.. | .. |
---|
8034 | 8628 | status = nfs4_sp4_select_mode(clp, &resp->state_protect); |
---|
8035 | 8629 | if (status != 0) |
---|
8036 | 8630 | goto out; |
---|
| 8631 | + |
---|
| 8632 | + do_renew_lease(clp, now); |
---|
8037 | 8633 | |
---|
8038 | 8634 | clp->cl_clientid = resp->clientid; |
---|
8039 | 8635 | clp->cl_exchange_flags = resp->flags; |
---|
.. | .. |
---|
8076 | 8672 | * |
---|
8077 | 8673 | * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used. |
---|
8078 | 8674 | */ |
---|
8079 | | -int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred) |
---|
| 8675 | +int nfs4_proc_exchange_id(struct nfs_client *clp, const struct cred *cred) |
---|
8080 | 8676 | { |
---|
8081 | 8677 | rpc_authflavor_t authflavor = clp->cl_rpcclient->cl_auth->au_flavor; |
---|
8082 | 8678 | int status; |
---|
.. | .. |
---|
8108 | 8704 | * @xprt: the rpc_xprt to test |
---|
8109 | 8705 | * @data: call data for _nfs4_proc_exchange_id. |
---|
8110 | 8706 | */ |
---|
8111 | | -int nfs4_test_session_trunk(struct rpc_clnt *clnt, struct rpc_xprt *xprt, |
---|
| 8707 | +void nfs4_test_session_trunk(struct rpc_clnt *clnt, struct rpc_xprt *xprt, |
---|
8112 | 8708 | void *data) |
---|
8113 | 8709 | { |
---|
8114 | 8710 | struct nfs4_add_xprt_data *adata = (struct nfs4_add_xprt_data *)data; |
---|
.. | .. |
---|
8125 | 8721 | /* Test connection for session trunking. Async exchange_id call */ |
---|
8126 | 8722 | task = nfs4_run_exchange_id(adata->clp, adata->cred, sp4_how, xprt); |
---|
8127 | 8723 | if (IS_ERR(task)) |
---|
8128 | | - return PTR_ERR(task); |
---|
| 8724 | + return; |
---|
8129 | 8725 | |
---|
8130 | 8726 | status = task->tk_status; |
---|
8131 | 8727 | if (status == 0) |
---|
8132 | 8728 | status = nfs4_detect_session_trunking(adata->clp, |
---|
8133 | 8729 | task->tk_msg.rpc_resp, xprt); |
---|
8134 | 8730 | |
---|
| 8731 | + if (status == 0) |
---|
| 8732 | + rpc_clnt_xprt_switch_add_xprt(clnt, xprt); |
---|
| 8733 | + |
---|
8135 | 8734 | rpc_put_task(task); |
---|
8136 | | - return status; |
---|
8137 | 8735 | } |
---|
8138 | 8736 | EXPORT_SYMBOL_GPL(nfs4_test_session_trunk); |
---|
8139 | 8737 | |
---|
8140 | 8738 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
---|
8141 | | - struct rpc_cred *cred) |
---|
| 8739 | + const struct cred *cred) |
---|
8142 | 8740 | { |
---|
8143 | 8741 | struct rpc_message msg = { |
---|
8144 | 8742 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
---|
.. | .. |
---|
8147 | 8745 | }; |
---|
8148 | 8746 | int status; |
---|
8149 | 8747 | |
---|
8150 | | - status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
---|
| 8748 | + status = rpc_call_sync(clp->cl_rpcclient, &msg, |
---|
| 8749 | + RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN); |
---|
8151 | 8750 | trace_nfs4_destroy_clientid(clp, status); |
---|
8152 | 8751 | if (status) |
---|
8153 | 8752 | dprintk("NFS: Got error %d from the server %s on " |
---|
.. | .. |
---|
8156 | 8755 | } |
---|
8157 | 8756 | |
---|
8158 | 8757 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
---|
8159 | | - struct rpc_cred *cred) |
---|
| 8758 | + const struct cred *cred) |
---|
8160 | 8759 | { |
---|
8161 | 8760 | unsigned int loop; |
---|
8162 | 8761 | int ret; |
---|
.. | .. |
---|
8177 | 8776 | |
---|
8178 | 8777 | int nfs4_destroy_clientid(struct nfs_client *clp) |
---|
8179 | 8778 | { |
---|
8180 | | - struct rpc_cred *cred; |
---|
| 8779 | + const struct cred *cred; |
---|
8181 | 8780 | int ret = 0; |
---|
8182 | 8781 | |
---|
8183 | 8782 | if (clp->cl_mvops->minor_version < 1) |
---|
.. | .. |
---|
8188 | 8787 | goto out; |
---|
8189 | 8788 | cred = nfs4_get_clid_cred(clp); |
---|
8190 | 8789 | ret = nfs4_proc_destroy_clientid(clp, cred); |
---|
8191 | | - if (cred) |
---|
8192 | | - put_rpccred(cred); |
---|
| 8790 | + put_cred(cred); |
---|
8193 | 8791 | switch (ret) { |
---|
8194 | 8792 | case 0: |
---|
8195 | 8793 | case -NFS4ERR_STALE_CLIENTID: |
---|
.. | .. |
---|
8198 | 8796 | out: |
---|
8199 | 8797 | return ret; |
---|
8200 | 8798 | } |
---|
| 8799 | + |
---|
| 8800 | +#endif /* CONFIG_NFS_V4_1 */ |
---|
8201 | 8801 | |
---|
8202 | 8802 | struct nfs4_get_lease_time_data { |
---|
8203 | 8803 | struct nfs4_get_lease_time_args *args; |
---|
.. | .. |
---|
8231 | 8831 | (struct nfs4_get_lease_time_data *)calldata; |
---|
8232 | 8832 | |
---|
8233 | 8833 | dprintk("--> %s\n", __func__); |
---|
8234 | | - if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
---|
| 8834 | + if (!nfs4_sequence_done(task, &data->res->lr_seq_res)) |
---|
8235 | 8835 | return; |
---|
8236 | 8836 | switch (task->tk_status) { |
---|
8237 | 8837 | case -NFS4ERR_DELAY: |
---|
.. | .. |
---|
8239 | 8839 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
---|
8240 | 8840 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
---|
8241 | 8841 | task->tk_status = 0; |
---|
8242 | | - /* fall through */ |
---|
| 8842 | + fallthrough; |
---|
8243 | 8843 | case -NFS4ERR_RETRY_UNCACHED_REP: |
---|
8244 | 8844 | rpc_restart_call_prepare(task); |
---|
8245 | 8845 | return; |
---|
.. | .. |
---|
8254 | 8854 | |
---|
8255 | 8855 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
---|
8256 | 8856 | { |
---|
8257 | | - struct rpc_task *task; |
---|
8258 | 8857 | struct nfs4_get_lease_time_args args; |
---|
8259 | 8858 | struct nfs4_get_lease_time_res res = { |
---|
8260 | 8859 | .lr_fsinfo = fsinfo, |
---|
.. | .. |
---|
8276 | 8875 | .callback_data = &data, |
---|
8277 | 8876 | .flags = RPC_TASK_TIMEOUT, |
---|
8278 | 8877 | }; |
---|
8279 | | - int status; |
---|
8280 | 8878 | |
---|
8281 | 8879 | nfs4_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0, 1); |
---|
8282 | | - task = rpc_run_task(&task_setup); |
---|
8283 | | - |
---|
8284 | | - if (IS_ERR(task)) |
---|
8285 | | - return PTR_ERR(task); |
---|
8286 | | - |
---|
8287 | | - status = task->tk_status; |
---|
8288 | | - rpc_put_task(task); |
---|
8289 | | - return status; |
---|
| 8880 | + return nfs4_call_sync_custom(&task_setup); |
---|
8290 | 8881 | } |
---|
| 8882 | + |
---|
| 8883 | +#ifdef CONFIG_NFS_V4_1 |
---|
8291 | 8884 | |
---|
8292 | 8885 | /* |
---|
8293 | 8886 | * Initialize the values to be used by the client in CREATE_SESSION |
---|
.. | .. |
---|
8303 | 8896 | { |
---|
8304 | 8897 | unsigned int max_rqst_sz, max_resp_sz; |
---|
8305 | 8898 | unsigned int max_bc_payload = rpc_max_bc_payload(clnt); |
---|
| 8899 | + unsigned int max_bc_slots = rpc_num_bc_slots(clnt); |
---|
8306 | 8900 | |
---|
8307 | 8901 | max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead; |
---|
8308 | 8902 | max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead; |
---|
.. | .. |
---|
8325 | 8919 | args->bc_attrs.max_resp_sz_cached = 0; |
---|
8326 | 8920 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
---|
8327 | 8921 | args->bc_attrs.max_reqs = max_t(unsigned short, max_session_cb_slots, 1); |
---|
| 8922 | + if (args->bc_attrs.max_reqs > max_bc_slots) |
---|
| 8923 | + args->bc_attrs.max_reqs = max_bc_slots; |
---|
8328 | 8924 | |
---|
8329 | 8925 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
---|
8330 | 8926 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
---|
.. | .. |
---|
8405 | 9001 | } |
---|
8406 | 9002 | |
---|
8407 | 9003 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
---|
8408 | | - struct rpc_cred *cred) |
---|
| 9004 | + const struct cred *cred) |
---|
8409 | 9005 | { |
---|
8410 | 9006 | struct nfs4_session *session = clp->cl_session; |
---|
8411 | 9007 | struct nfs41_create_session_args args = { |
---|
.. | .. |
---|
8427 | 9023 | nfs4_init_channel_attrs(&args, clp->cl_rpcclient); |
---|
8428 | 9024 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
---|
8429 | 9025 | |
---|
8430 | | - status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
---|
| 9026 | + status = rpc_call_sync(session->clp->cl_rpcclient, &msg, |
---|
| 9027 | + RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN); |
---|
8431 | 9028 | trace_nfs4_create_session(clp, status); |
---|
8432 | 9029 | |
---|
8433 | 9030 | switch (status) { |
---|
.. | .. |
---|
8437 | 9034 | case -EACCES: |
---|
8438 | 9035 | case -EAGAIN: |
---|
8439 | 9036 | goto out; |
---|
8440 | | - }; |
---|
| 9037 | + } |
---|
8441 | 9038 | |
---|
8442 | 9039 | clp->cl_seqid++; |
---|
8443 | 9040 | if (!status) { |
---|
.. | .. |
---|
8457 | 9054 | * It is the responsibility of the caller to verify the session is |
---|
8458 | 9055 | * expired before calling this routine. |
---|
8459 | 9056 | */ |
---|
8460 | | -int nfs4_proc_create_session(struct nfs_client *clp, struct rpc_cred *cred) |
---|
| 9057 | +int nfs4_proc_create_session(struct nfs_client *clp, const struct cred *cred) |
---|
8461 | 9058 | { |
---|
8462 | 9059 | int status; |
---|
8463 | 9060 | unsigned *ptr; |
---|
.. | .. |
---|
8488 | 9085 | * The caller must serialize access to this routine. |
---|
8489 | 9086 | */ |
---|
8490 | 9087 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
---|
8491 | | - struct rpc_cred *cred) |
---|
| 9088 | + const struct cred *cred) |
---|
8492 | 9089 | { |
---|
8493 | 9090 | struct rpc_message msg = { |
---|
8494 | 9091 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
---|
.. | .. |
---|
8503 | 9100 | if (!test_and_clear_bit(NFS4_SESSION_ESTABLISHED, &session->session_state)) |
---|
8504 | 9101 | return 0; |
---|
8505 | 9102 | |
---|
8506 | | - status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
---|
| 9103 | + status = rpc_call_sync(session->clp->cl_rpcclient, &msg, |
---|
| 9104 | + RPC_TASK_TIMEOUT | RPC_TASK_NO_ROUND_ROBIN); |
---|
8507 | 9105 | trace_nfs4_destroy_session(session->clp, status); |
---|
8508 | 9106 | |
---|
8509 | 9107 | if (status) |
---|
.. | .. |
---|
8590 | 9188 | }; |
---|
8591 | 9189 | |
---|
8592 | 9190 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, |
---|
8593 | | - struct rpc_cred *cred, |
---|
| 9191 | + const struct cred *cred, |
---|
8594 | 9192 | struct nfs4_slot *slot, |
---|
8595 | 9193 | bool is_privileged) |
---|
8596 | 9194 | { |
---|
.. | .. |
---|
8633 | 9231 | return ret; |
---|
8634 | 9232 | } |
---|
8635 | 9233 | |
---|
8636 | | -static int nfs41_proc_async_sequence(struct nfs_client *clp, struct rpc_cred *cred, unsigned renew_flags) |
---|
| 9234 | +static int nfs41_proc_async_sequence(struct nfs_client *clp, const struct cred *cred, unsigned renew_flags) |
---|
8637 | 9235 | { |
---|
8638 | 9236 | struct rpc_task *task; |
---|
8639 | 9237 | int ret = 0; |
---|
.. | .. |
---|
8649 | 9247 | return ret; |
---|
8650 | 9248 | } |
---|
8651 | 9249 | |
---|
8652 | | -static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
---|
| 9250 | +static int nfs4_proc_sequence(struct nfs_client *clp, const struct cred *cred) |
---|
8653 | 9251 | { |
---|
8654 | 9252 | struct rpc_task *task; |
---|
8655 | 9253 | int ret; |
---|
.. | .. |
---|
8689 | 9287 | switch(task->tk_status) { |
---|
8690 | 9288 | case 0: |
---|
8691 | 9289 | wake_up_all(&clp->cl_lock_waitq); |
---|
8692 | | - /* Fallthrough */ |
---|
| 9290 | + fallthrough; |
---|
8693 | 9291 | case -NFS4ERR_COMPLETE_ALREADY: |
---|
8694 | 9292 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
---|
8695 | 9293 | break; |
---|
8696 | 9294 | case -NFS4ERR_DELAY: |
---|
8697 | 9295 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
---|
8698 | | - /* fall through */ |
---|
| 9296 | + fallthrough; |
---|
8699 | 9297 | case -NFS4ERR_RETRY_UNCACHED_REP: |
---|
| 9298 | + case -EACCES: |
---|
| 9299 | + dprintk("%s: failed to reclaim complete error %d for server %s, retrying\n", |
---|
| 9300 | + __func__, task->tk_status, clp->cl_hostname); |
---|
8700 | 9301 | return -EAGAIN; |
---|
8701 | 9302 | case -NFS4ERR_BADSESSION: |
---|
8702 | 9303 | case -NFS4ERR_DEADSESSION: |
---|
8703 | 9304 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
---|
8704 | | - nfs4_schedule_session_recovery(clp->cl_session, |
---|
8705 | | - task->tk_status); |
---|
8706 | 9305 | break; |
---|
8707 | 9306 | default: |
---|
8708 | 9307 | nfs4_schedule_lease_recovery(clp); |
---|
.. | .. |
---|
8745 | 9344 | * Issue a global reclaim complete. |
---|
8746 | 9345 | */ |
---|
8747 | 9346 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp, |
---|
8748 | | - struct rpc_cred *cred) |
---|
| 9347 | + const struct cred *cred) |
---|
8749 | 9348 | { |
---|
8750 | 9349 | struct nfs4_reclaim_complete_data *calldata; |
---|
8751 | | - struct rpc_task *task; |
---|
8752 | 9350 | struct rpc_message msg = { |
---|
8753 | 9351 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
---|
8754 | 9352 | .rpc_cred = cred, |
---|
.. | .. |
---|
8757 | 9355 | .rpc_client = clp->cl_rpcclient, |
---|
8758 | 9356 | .rpc_message = &msg, |
---|
8759 | 9357 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
---|
8760 | | - .flags = RPC_TASK_ASYNC, |
---|
| 9358 | + .flags = RPC_TASK_NO_ROUND_ROBIN, |
---|
8761 | 9359 | }; |
---|
8762 | 9360 | int status = -ENOMEM; |
---|
8763 | 9361 | |
---|
.. | .. |
---|
8772 | 9370 | msg.rpc_argp = &calldata->arg; |
---|
8773 | 9371 | msg.rpc_resp = &calldata->res; |
---|
8774 | 9372 | task_setup_data.callback_data = calldata; |
---|
8775 | | - task = rpc_run_task(&task_setup_data); |
---|
8776 | | - if (IS_ERR(task)) { |
---|
8777 | | - status = PTR_ERR(task); |
---|
8778 | | - goto out; |
---|
8779 | | - } |
---|
8780 | | - status = rpc_wait_for_completion_task(task); |
---|
8781 | | - if (status == 0) |
---|
8782 | | - status = task->tk_status; |
---|
8783 | | - rpc_put_task(task); |
---|
| 9373 | + status = nfs4_call_sync_custom(&task_setup_data); |
---|
8784 | 9374 | out: |
---|
8785 | 9375 | dprintk("<-- %s status=%d\n", __func__, status); |
---|
8786 | 9376 | return status; |
---|
.. | .. |
---|
8937 | 9527 | .rpc_message = &msg, |
---|
8938 | 9528 | .callback_ops = &nfs4_layoutget_call_ops, |
---|
8939 | 9529 | .callback_data = lgp, |
---|
8940 | | - .flags = RPC_TASK_ASYNC, |
---|
| 9530 | + .flags = RPC_TASK_ASYNC | RPC_TASK_CRED_NOREF, |
---|
8941 | 9531 | }; |
---|
8942 | 9532 | struct pnfs_layout_segment *lseg = NULL; |
---|
8943 | 9533 | struct nfs4_exception exception = { |
---|
.. | .. |
---|
8954 | 9544 | nfs4_init_sequence(&lgp->args.seq_args, &lgp->res.seq_res, 0, 0); |
---|
8955 | 9545 | |
---|
8956 | 9546 | task = rpc_run_task(&task_setup_data); |
---|
8957 | | - if (IS_ERR(task)) |
---|
8958 | | - return ERR_CAST(task); |
---|
| 9547 | + |
---|
8959 | 9548 | status = rpc_wait_for_completion_task(task); |
---|
8960 | 9549 | if (status != 0) |
---|
8961 | 9550 | goto out; |
---|
8962 | 9551 | |
---|
8963 | | - /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */ |
---|
8964 | | - if (task->tk_status < 0 || lgp->res.layoutp->len == 0) { |
---|
| 9552 | + if (task->tk_status < 0) { |
---|
8965 | 9553 | status = nfs4_layoutget_handle_exception(task, lgp, &exception); |
---|
8966 | 9554 | *timeout = exception.timeout; |
---|
| 9555 | + } else if (lgp->res.layoutp->len == 0) { |
---|
| 9556 | + status = -EAGAIN; |
---|
| 9557 | + *timeout = nfs4_update_delay(&exception.timeout); |
---|
8967 | 9558 | } else |
---|
8968 | 9559 | lseg = pnfs_layout_process(lgp); |
---|
8969 | 9560 | out: |
---|
.. | .. |
---|
9004 | 9595 | if (!nfs41_sequence_process(task, &lrp->res.seq_res)) |
---|
9005 | 9596 | return; |
---|
9006 | 9597 | |
---|
| 9598 | + /* |
---|
| 9599 | + * Was there an RPC level error? Assume the call succeeded, |
---|
| 9600 | + * and that we need to release the layout |
---|
| 9601 | + */ |
---|
| 9602 | + if (task->tk_rpc_status != 0 && RPC_WAS_SENT(task)) { |
---|
| 9603 | + lrp->res.lrs_present = 0; |
---|
| 9604 | + return; |
---|
| 9605 | + } |
---|
| 9606 | + |
---|
9007 | 9607 | server = NFS_SERVER(lrp->args.inode); |
---|
9008 | 9608 | switch (task->tk_status) { |
---|
9009 | 9609 | case -NFS4ERR_OLD_STATEID: |
---|
9010 | | - if (nfs4_layoutreturn_refresh_stateid(&lrp->args.stateid, |
---|
| 9610 | + if (nfs4_layout_refresh_old_stateid(&lrp->args.stateid, |
---|
9011 | 9611 | &lrp->args.range, |
---|
9012 | 9612 | lrp->args.inode)) |
---|
9013 | 9613 | goto out_restart; |
---|
9014 | | - /* Fallthrough */ |
---|
| 9614 | + fallthrough; |
---|
9015 | 9615 | default: |
---|
9016 | 9616 | task->tk_status = 0; |
---|
9017 | | - /* Fallthrough */ |
---|
| 9617 | + fallthrough; |
---|
9018 | 9618 | case 0: |
---|
9019 | 9619 | break; |
---|
9020 | 9620 | case -NFS4ERR_DELAY: |
---|
.. | .. |
---|
9043 | 9643 | lrp->ld_private.ops->free(&lrp->ld_private); |
---|
9044 | 9644 | pnfs_put_layout_hdr(lrp->args.layout); |
---|
9045 | 9645 | nfs_iput_and_deactive(lrp->inode); |
---|
| 9646 | + put_cred(lrp->cred); |
---|
9046 | 9647 | kfree(calldata); |
---|
9047 | 9648 | dprintk("<-- %s\n", __func__); |
---|
9048 | 9649 | } |
---|
.. | .. |
---|
9103 | 9704 | static int |
---|
9104 | 9705 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, |
---|
9105 | 9706 | struct pnfs_device *pdev, |
---|
9106 | | - struct rpc_cred *cred) |
---|
| 9707 | + const struct cred *cred) |
---|
9107 | 9708 | { |
---|
9108 | 9709 | struct nfs4_getdeviceinfo_args args = { |
---|
9109 | 9710 | .pdev = pdev, |
---|
.. | .. |
---|
9135 | 9736 | |
---|
9136 | 9737 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, |
---|
9137 | 9738 | struct pnfs_device *pdev, |
---|
9138 | | - struct rpc_cred *cred) |
---|
| 9739 | + const struct cred *cred) |
---|
9139 | 9740 | { |
---|
9140 | 9741 | struct nfs4_exception exception = { }; |
---|
9141 | 9742 | int err; |
---|
.. | .. |
---|
9192 | 9793 | pnfs_cleanup_layoutcommit(data); |
---|
9193 | 9794 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
---|
9194 | 9795 | data->res.fattr); |
---|
9195 | | - put_rpccred(data->cred); |
---|
| 9796 | + put_cred(data->cred); |
---|
9196 | 9797 | nfs_iput_and_deactive(data->inode); |
---|
9197 | 9798 | kfree(data); |
---|
9198 | 9799 | } |
---|
.. | .. |
---|
9247 | 9848 | return status; |
---|
9248 | 9849 | } |
---|
9249 | 9850 | |
---|
9250 | | -/** |
---|
| 9851 | +/* |
---|
9251 | 9852 | * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if |
---|
9252 | 9853 | * possible) as per RFC3530bis and RFC5661 Security Considerations sections |
---|
9253 | 9854 | */ |
---|
.. | .. |
---|
9267 | 9868 | .rpc_argp = &args, |
---|
9268 | 9869 | .rpc_resp = &res, |
---|
9269 | 9870 | }; |
---|
9270 | | - struct rpc_clnt *clnt = server->client; |
---|
9271 | | - struct rpc_cred *cred = NULL; |
---|
| 9871 | + struct nfs4_call_sync_data data = { |
---|
| 9872 | + .seq_server = server, |
---|
| 9873 | + .seq_args = &args.seq_args, |
---|
| 9874 | + .seq_res = &res.seq_res, |
---|
| 9875 | + }; |
---|
| 9876 | + struct rpc_task_setup task_setup = { |
---|
| 9877 | + .rpc_client = server->client, |
---|
| 9878 | + .rpc_message = &msg, |
---|
| 9879 | + .callback_ops = server->nfs_client->cl_mvops->call_sync_ops, |
---|
| 9880 | + .callback_data = &data, |
---|
| 9881 | + .flags = RPC_TASK_NO_ROUND_ROBIN, |
---|
| 9882 | + }; |
---|
| 9883 | + const struct cred *cred = NULL; |
---|
9272 | 9884 | int status; |
---|
9273 | 9885 | |
---|
9274 | 9886 | if (use_integrity) { |
---|
9275 | | - clnt = server->nfs_client->cl_rpcclient; |
---|
| 9887 | + task_setup.rpc_client = server->nfs_client->cl_rpcclient; |
---|
| 9888 | + |
---|
9276 | 9889 | cred = nfs4_get_clid_cred(server->nfs_client); |
---|
9277 | 9890 | msg.rpc_cred = cred; |
---|
9278 | 9891 | } |
---|
9279 | 9892 | |
---|
9280 | 9893 | dprintk("--> %s\n", __func__); |
---|
9281 | | - status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, |
---|
9282 | | - &res.seq_res, 0); |
---|
| 9894 | + nfs4_init_sequence(&args.seq_args, &res.seq_res, 0, 0); |
---|
| 9895 | + status = nfs4_call_sync_custom(&task_setup); |
---|
9283 | 9896 | dprintk("<-- %s status=%d\n", __func__, status); |
---|
9284 | 9897 | |
---|
9285 | | - if (cred) |
---|
9286 | | - put_rpccred(cred); |
---|
| 9898 | + put_cred(cred); |
---|
9287 | 9899 | |
---|
9288 | 9900 | return status; |
---|
9289 | 9901 | } |
---|
.. | .. |
---|
9292 | 9904 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
---|
9293 | 9905 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
---|
9294 | 9906 | { |
---|
9295 | | - struct nfs4_exception exception = { }; |
---|
| 9907 | + struct nfs4_exception exception = { |
---|
| 9908 | + .interruptible = true, |
---|
| 9909 | + }; |
---|
9296 | 9910 | int err; |
---|
9297 | 9911 | do { |
---|
9298 | 9912 | /* first try using integrity protection */ |
---|
.. | .. |
---|
9396 | 10010 | |
---|
9397 | 10011 | static int _nfs41_test_stateid(struct nfs_server *server, |
---|
9398 | 10012 | nfs4_stateid *stateid, |
---|
9399 | | - struct rpc_cred *cred) |
---|
| 10013 | + const struct cred *cred) |
---|
9400 | 10014 | { |
---|
9401 | 10015 | int status; |
---|
9402 | 10016 | struct nfs41_test_stateid_args args = { |
---|
.. | .. |
---|
9457 | 10071 | */ |
---|
9458 | 10072 | static int nfs41_test_stateid(struct nfs_server *server, |
---|
9459 | 10073 | nfs4_stateid *stateid, |
---|
9460 | | - struct rpc_cred *cred) |
---|
| 10074 | + const struct cred *cred) |
---|
9461 | 10075 | { |
---|
9462 | | - struct nfs4_exception exception = { }; |
---|
| 10076 | + struct nfs4_exception exception = { |
---|
| 10077 | + .interruptible = true, |
---|
| 10078 | + }; |
---|
9463 | 10079 | int err; |
---|
9464 | 10080 | do { |
---|
9465 | 10081 | err = _nfs41_test_stateid(server, stateid, cred); |
---|
.. | .. |
---|
9513 | 10129 | * @server: server / transport on which to perform the operation |
---|
9514 | 10130 | * @stateid: state ID to release |
---|
9515 | 10131 | * @cred: credential |
---|
9516 | | - * @is_recovery: set to true if this call needs to be privileged |
---|
| 10132 | + * @privileged: set to true if this call needs to be privileged |
---|
9517 | 10133 | * |
---|
9518 | 10134 | * Note: this function is always asynchronous. |
---|
9519 | 10135 | */ |
---|
9520 | 10136 | static int nfs41_free_stateid(struct nfs_server *server, |
---|
9521 | 10137 | const nfs4_stateid *stateid, |
---|
9522 | | - struct rpc_cred *cred, |
---|
| 10138 | + const struct cred *cred, |
---|
9523 | 10139 | bool privileged) |
---|
9524 | 10140 | { |
---|
9525 | 10141 | struct rpc_message msg = { |
---|
.. | .. |
---|
9560 | 10176 | static void |
---|
9561 | 10177 | nfs41_free_lock_state(struct nfs_server *server, struct nfs4_lock_state *lsp) |
---|
9562 | 10178 | { |
---|
9563 | | - struct rpc_cred *cred = lsp->ls_state->owner->so_cred; |
---|
| 10179 | + const struct cred *cred = lsp->ls_state->owner->so_cred; |
---|
9564 | 10180 | |
---|
9565 | 10181 | nfs41_free_stateid(server, &lsp->ls_stateid, cred, false); |
---|
9566 | 10182 | nfs4_free_lock_state(server, lsp); |
---|
.. | .. |
---|
9631 | 10247 | |
---|
9632 | 10248 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
---|
9633 | 10249 | .sched_state_renewal = nfs4_proc_async_renew, |
---|
9634 | | - .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
---|
| 10250 | + .get_state_renewal_cred = nfs4_get_renew_cred, |
---|
9635 | 10251 | .renew_lease = nfs4_proc_renew, |
---|
9636 | 10252 | }; |
---|
9637 | 10253 | |
---|
9638 | 10254 | #if defined(CONFIG_NFS_V4_1) |
---|
9639 | 10255 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
---|
9640 | 10256 | .sched_state_renewal = nfs41_proc_async_sequence, |
---|
9641 | | - .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
---|
| 10257 | + .get_state_renewal_cred = nfs4_get_machine_cred, |
---|
9642 | 10258 | .renew_lease = nfs4_proc_sequence, |
---|
9643 | 10259 | }; |
---|
9644 | 10260 | #endif |
---|
.. | .. |
---|
9717 | 10333 | | NFS_CAP_ALLOCATE |
---|
9718 | 10334 | | NFS_CAP_COPY |
---|
9719 | 10335 | | NFS_CAP_OFFLOAD_CANCEL |
---|
| 10336 | + | NFS_CAP_COPY_NOTIFY |
---|
9720 | 10337 | | NFS_CAP_DEALLOCATE |
---|
9721 | 10338 | | NFS_CAP_SEEK |
---|
9722 | 10339 | | NFS_CAP_LAYOUTSTATS |
---|
9723 | | - | NFS_CAP_CLONE, |
---|
| 10340 | + | NFS_CAP_CLONE |
---|
| 10341 | + | NFS_CAP_LAYOUTERROR |
---|
| 10342 | + | NFS_CAP_READ_PLUS, |
---|
9724 | 10343 | .init_client = nfs41_init_client, |
---|
9725 | 10344 | .shutdown_client = nfs41_shutdown_client, |
---|
9726 | 10345 | .match_stateid = nfs41_match_stateid, |
---|
.. | .. |
---|
9749 | 10368 | |
---|
9750 | 10369 | static ssize_t nfs4_listxattr(struct dentry *dentry, char *list, size_t size) |
---|
9751 | 10370 | { |
---|
9752 | | - ssize_t error, error2; |
---|
| 10371 | + ssize_t error, error2, error3; |
---|
9753 | 10372 | |
---|
9754 | 10373 | error = generic_listxattr(dentry, list, size); |
---|
9755 | 10374 | if (error < 0) |
---|
.. | .. |
---|
9762 | 10381 | error2 = nfs4_listxattr_nfs4_label(d_inode(dentry), list, size); |
---|
9763 | 10382 | if (error2 < 0) |
---|
9764 | 10383 | return error2; |
---|
9765 | | - return error + error2; |
---|
| 10384 | + |
---|
| 10385 | + if (list) { |
---|
| 10386 | + list += error2; |
---|
| 10387 | + size -= error2; |
---|
| 10388 | + } |
---|
| 10389 | + |
---|
| 10390 | + error3 = nfs4_listxattr_nfs4_user(d_inode(dentry), list, size); |
---|
| 10391 | + if (error3 < 0) |
---|
| 10392 | + return error3; |
---|
| 10393 | + |
---|
| 10394 | + return error + error2 + error3; |
---|
| 10395 | +} |
---|
| 10396 | + |
---|
| 10397 | +static void nfs4_enable_swap(struct inode *inode) |
---|
| 10398 | +{ |
---|
| 10399 | + /* The state manager thread must always be running. |
---|
| 10400 | + * It will notice the client is a swapper, and stay put. |
---|
| 10401 | + */ |
---|
| 10402 | + struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
---|
| 10403 | + |
---|
| 10404 | + nfs4_schedule_state_manager(clp); |
---|
| 10405 | +} |
---|
| 10406 | + |
---|
| 10407 | +static void nfs4_disable_swap(struct inode *inode) |
---|
| 10408 | +{ |
---|
| 10409 | + /* The state manager thread will now exit once it is |
---|
| 10410 | + * woken. |
---|
| 10411 | + */ |
---|
| 10412 | + struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
---|
| 10413 | + |
---|
| 10414 | + set_bit(NFS4CLNT_RUN_MANAGER, &clp->cl_state); |
---|
| 10415 | + clear_bit(NFS4CLNT_MANAGER_AVAILABLE, &clp->cl_state); |
---|
| 10416 | + wake_up_var(&clp->cl_state); |
---|
9766 | 10417 | } |
---|
9767 | 10418 | |
---|
9768 | 10419 | static const struct inode_operations nfs4_dir_inode_operations = { |
---|
.. | .. |
---|
9797 | 10448 | .file_ops = &nfs4_file_operations, |
---|
9798 | 10449 | .getroot = nfs4_proc_get_root, |
---|
9799 | 10450 | .submount = nfs4_submount, |
---|
9800 | | - .try_mount = nfs4_try_mount, |
---|
| 10451 | + .try_get_tree = nfs4_try_get_tree, |
---|
9801 | 10452 | .getattr = nfs4_proc_getattr, |
---|
9802 | 10453 | .setattr = nfs4_proc_setattr, |
---|
9803 | 10454 | .lookup = nfs4_proc_lookup, |
---|
.. | .. |
---|
9841 | 10492 | .free_client = nfs4_free_client, |
---|
9842 | 10493 | .create_server = nfs4_create_server, |
---|
9843 | 10494 | .clone_server = nfs_clone_server, |
---|
| 10495 | + .enable_swap = nfs4_enable_swap, |
---|
| 10496 | + .disable_swap = nfs4_disable_swap, |
---|
9844 | 10497 | }; |
---|
9845 | 10498 | |
---|
9846 | 10499 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
---|
.. | .. |
---|
9850 | 10503 | .set = nfs4_xattr_set_nfs4_acl, |
---|
9851 | 10504 | }; |
---|
9852 | 10505 | |
---|
| 10506 | +#ifdef CONFIG_NFS_V4_2 |
---|
| 10507 | +static const struct xattr_handler nfs4_xattr_nfs4_user_handler = { |
---|
| 10508 | + .prefix = XATTR_USER_PREFIX, |
---|
| 10509 | + .get = nfs4_xattr_get_nfs4_user, |
---|
| 10510 | + .set = nfs4_xattr_set_nfs4_user, |
---|
| 10511 | +}; |
---|
| 10512 | +#endif |
---|
| 10513 | + |
---|
9853 | 10514 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
---|
9854 | 10515 | &nfs4_xattr_nfs4_acl_handler, |
---|
9855 | 10516 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
---|
9856 | 10517 | &nfs4_xattr_nfs4_label_handler, |
---|
9857 | 10518 | #endif |
---|
| 10519 | +#ifdef CONFIG_NFS_V4_2 |
---|
| 10520 | + &nfs4_xattr_nfs4_user_handler, |
---|
| 10521 | +#endif |
---|
9858 | 10522 | NULL |
---|
9859 | 10523 | }; |
---|
9860 | 10524 | |
---|