forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/fs/nfs/write.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * linux/fs/nfs/write.c
34 *
....@@ -26,6 +27,7 @@
2627 #include <linux/iversion.h>
2728
2829 #include <linux/uaccess.h>
30
+#include <linux/sched/mm.h>
2931
3032 #include "delegation.h"
3133 #include "internal.h"
....@@ -55,6 +57,7 @@
5557 static const struct nfs_pgio_completion_ops nfs_async_write_completion_ops;
5658 static const struct nfs_commit_completion_ops nfs_commit_completion_ops;
5759 static const struct nfs_rw_ops nfs_rw_write_ops;
60
+static void nfs_inode_remove_request(struct nfs_page *req);
5861 static void nfs_clear_request_commit(struct nfs_page *req);
5962 static void nfs_init_cinfo_from_inode(struct nfs_commit_info *cinfo,
6063 struct inode *inode);
....@@ -67,27 +70,17 @@
6770 static struct kmem_cache *nfs_cdata_cachep;
6871 static mempool_t *nfs_commit_mempool;
6972
70
-struct nfs_commit_data *nfs_commitdata_alloc(bool never_fail)
73
+struct nfs_commit_data *nfs_commitdata_alloc(void)
7174 {
7275 struct nfs_commit_data *p;
7376
74
- if (never_fail)
75
- p = mempool_alloc(nfs_commit_mempool, GFP_NOIO);
76
- else {
77
- /* It is OK to do some reclaim, not no safe to wait
78
- * for anything to be returned to the pool.
79
- * mempool_alloc() cannot handle that particular combination,
80
- * so we need two separate attempts.
81
- */
77
+ p = kmem_cache_zalloc(nfs_cdata_cachep, nfs_io_gfp_mask());
78
+ if (!p) {
8279 p = mempool_alloc(nfs_commit_mempool, GFP_NOWAIT);
8380 if (!p)
84
- p = kmem_cache_alloc(nfs_cdata_cachep, GFP_NOIO |
85
- __GFP_NOWARN | __GFP_NORETRY);
86
- if (!p)
8781 return NULL;
82
+ memset(p, 0, sizeof(*p));
8883 }
89
-
90
- memset(p, 0, sizeof(*p));
9184 INIT_LIST_HEAD(&p->pages);
9285 return p;
9386 }
....@@ -101,9 +94,15 @@
10194
10295 static struct nfs_pgio_header *nfs_writehdr_alloc(void)
10396 {
104
- struct nfs_pgio_header *p = mempool_alloc(nfs_wdata_mempool, GFP_NOIO);
97
+ struct nfs_pgio_header *p;
10598
106
- memset(p, 0, sizeof(*p));
99
+ p = kmem_cache_zalloc(nfs_wdata_cachep, nfs_io_gfp_mask());
100
+ if (!p) {
101
+ p = mempool_alloc(nfs_wdata_mempool, GFP_NOWAIT);
102
+ if (!p)
103
+ return NULL;
104
+ memset(p, 0, sizeof(*p));
105
+ }
107106 p->rw_mode = FMODE_WRITE;
108107 return p;
109108 }
....@@ -144,6 +143,31 @@
144143 {
145144 if (ioc != NULL)
146145 kref_put(&ioc->refcount, nfs_io_completion_release);
146
+}
147
+
148
+static void
149
+nfs_page_set_inode_ref(struct nfs_page *req, struct inode *inode)
150
+{
151
+ if (!test_and_set_bit(PG_INODE_REF, &req->wb_flags)) {
152
+ kref_get(&req->wb_kref);
153
+ atomic_long_inc(&NFS_I(inode)->nrequests);
154
+ }
155
+}
156
+
157
+static int
158
+nfs_cancel_remove_inode(struct nfs_page *req, struct inode *inode)
159
+{
160
+ int ret;
161
+
162
+ if (!test_bit(PG_REMOVE, &req->wb_flags))
163
+ return 0;
164
+ ret = nfs_page_group_lock(req);
165
+ if (ret)
166
+ return ret;
167
+ if (test_and_clear_bit(PG_REMOVE, &req->wb_flags))
168
+ nfs_page_set_inode_ref(req, inode);
169
+ nfs_page_group_unlock(req);
170
+ return 0;
147171 }
148172
149173 static struct nfs_page *
....@@ -215,6 +239,36 @@
215239 return req;
216240 }
217241
242
+static struct nfs_page *nfs_find_and_lock_page_request(struct page *page)
243
+{
244
+ struct inode *inode = page_file_mapping(page)->host;
245
+ struct nfs_page *req, *head;
246
+ int ret;
247
+
248
+ for (;;) {
249
+ req = nfs_page_find_head_request(page);
250
+ if (!req)
251
+ return req;
252
+ head = nfs_page_group_lock_head(req);
253
+ if (head != req)
254
+ nfs_release_request(req);
255
+ if (IS_ERR(head))
256
+ return head;
257
+ ret = nfs_cancel_remove_inode(head, inode);
258
+ if (ret < 0) {
259
+ nfs_unlock_and_release_request(head);
260
+ return ERR_PTR(ret);
261
+ }
262
+ /* Ensure that nobody removed the request before we locked it */
263
+ if (head == nfs_page_private_request(page))
264
+ break;
265
+ if (PageSwapCache(page))
266
+ break;
267
+ nfs_unlock_and_release_request(head);
268
+ }
269
+ return head;
270
+}
271
+
218272 /* Adjust the file length if we're writing beyond the end */
219273 static void nfs_grow_file(struct page *page, unsigned int offset, unsigned int count)
220274 {
....@@ -249,6 +303,18 @@
249303 NFS_INO_REVAL_PAGECACHE |
250304 NFS_INO_INVALID_SIZE;
251305 spin_unlock(&inode->i_lock);
306
+}
307
+
308
+static void nfs_mapping_set_error(struct page *page, int error)
309
+{
310
+ struct address_space *mapping = page_file_mapping(page);
311
+
312
+ SetPageError(page);
313
+ filemap_set_wb_err(mapping, error);
314
+ if (mapping->host)
315
+ errseq_set(&mapping->host->i_sb->s_wb_err,
316
+ error == -ENOSPC ? -ENOSPC : -EIO);
317
+ nfs_set_pageerror(mapping);
252318 }
253319
254320 /*
....@@ -368,34 +434,6 @@
368434 }
369435
370436 /*
371
- * nfs_unroll_locks_and_wait - unlock all newly locked reqs and wait on @req
372
- *
373
- * this is a helper function for nfs_lock_and_join_requests
374
- *
375
- * @inode - inode associated with request page group, must be holding inode lock
376
- * @head - head request of page group, must be holding head lock
377
- * @req - request that couldn't lock and needs to wait on the req bit lock
378
- *
379
- * NOTE: this must be called holding page_group bit lock
380
- * which will be released before returning.
381
- *
382
- * returns 0 on success, < 0 on error.
383
- */
384
-static void
385
-nfs_unroll_locks(struct inode *inode, struct nfs_page *head,
386
- struct nfs_page *req)
387
-{
388
- struct nfs_page *tmp;
389
-
390
- /* relinquish all the locks successfully grabbed this run */
391
- for (tmp = head->wb_this_page ; tmp != req; tmp = tmp->wb_this_page) {
392
- if (!kref_read(&tmp->wb_kref))
393
- continue;
394
- nfs_unlock_and_release_request(tmp);
395
- }
396
-}
397
-
398
-/*
399437 * nfs_destroy_unlinked_subrequests - destroy recently unlinked subrequests
400438 *
401439 * @destroy_list - request list (using wb_this_page) terminated by @old_head
....@@ -452,11 +490,64 @@
452490 }
453491
454492 /*
455
- * nfs_lock_and_join_requests - join all subreqs to the head req and return
456
- * a locked reference, cancelling any pending
457
- * operations for this page.
493
+ * nfs_join_page_group - destroy subrequests of the head req
494
+ * @head: the page used to lookup the "page group" of nfs_page structures
495
+ * @inode: Inode to which the request belongs.
458496 *
459
- * @page - the page used to lookup the "page group" of nfs_page structures
497
+ * This function joins all sub requests to the head request by first
498
+ * locking all requests in the group, cancelling any pending operations
499
+ * and finally updating the head request to cover the whole range covered by
500
+ * the (former) group. All subrequests are removed from any write or commit
501
+ * lists, unlinked from the group and destroyed.
502
+ */
503
+void
504
+nfs_join_page_group(struct nfs_page *head, struct inode *inode)
505
+{
506
+ struct nfs_page *subreq;
507
+ struct nfs_page *destroy_list = NULL;
508
+ unsigned int pgbase, off, bytes;
509
+
510
+ pgbase = head->wb_pgbase;
511
+ bytes = head->wb_bytes;
512
+ off = head->wb_offset;
513
+ for (subreq = head->wb_this_page; subreq != head;
514
+ subreq = subreq->wb_this_page) {
515
+ /* Subrequests should always form a contiguous range */
516
+ if (pgbase > subreq->wb_pgbase) {
517
+ off -= pgbase - subreq->wb_pgbase;
518
+ bytes += pgbase - subreq->wb_pgbase;
519
+ pgbase = subreq->wb_pgbase;
520
+ }
521
+ bytes = max(subreq->wb_pgbase + subreq->wb_bytes
522
+ - pgbase, bytes);
523
+ }
524
+
525
+ /* Set the head request's range to cover the former page group */
526
+ head->wb_pgbase = pgbase;
527
+ head->wb_bytes = bytes;
528
+ head->wb_offset = off;
529
+
530
+ /* Now that all requests are locked, make sure they aren't on any list.
531
+ * Commit list removal accounting is done after locks are dropped */
532
+ subreq = head;
533
+ do {
534
+ nfs_clear_request_commit(subreq);
535
+ subreq = subreq->wb_this_page;
536
+ } while (subreq != head);
537
+
538
+ /* unlink subrequests from head, destroy them later */
539
+ if (head->wb_this_page != head) {
540
+ /* destroy list will be terminated by head */
541
+ destroy_list = head->wb_this_page;
542
+ head->wb_this_page = head;
543
+ }
544
+
545
+ nfs_destroy_unlinked_subrequests(destroy_list, head, inode);
546
+}
547
+
548
+/*
549
+ * nfs_lock_and_join_requests - join all subreqs to the head req
550
+ * @page: the page used to lookup the "page group" of nfs_page structures
460551 *
461552 * This function joins all sub requests to the head request by first
462553 * locking all requests in the group, cancelling any pending operations
....@@ -473,147 +564,37 @@
473564 nfs_lock_and_join_requests(struct page *page)
474565 {
475566 struct inode *inode = page_file_mapping(page)->host;
476
- struct nfs_page *head, *subreq;
477
- struct nfs_page *destroy_list = NULL;
478
- unsigned int total_bytes;
567
+ struct nfs_page *head;
479568 int ret;
480569
481
-try_again:
482570 /*
483571 * A reference is taken only on the head request which acts as a
484572 * reference to the whole page group - the group will not be destroyed
485573 * until the head reference is released.
486574 */
487
- head = nfs_page_find_head_request(page);
488
- if (!head)
489
- return NULL;
490
-
491
- /* lock the page head first in order to avoid an ABBA inefficiency */
492
- if (!nfs_lock_request(head)) {
493
- ret = nfs_wait_on_request(head);
494
- nfs_release_request(head);
495
- if (ret < 0)
496
- return ERR_PTR(ret);
497
- goto try_again;
498
- }
499
-
500
- /* Ensure that nobody removed the request before we locked it */
501
- if (head != nfs_page_private_request(page) && !PageSwapCache(page)) {
502
- nfs_unlock_and_release_request(head);
503
- goto try_again;
504
- }
505
-
506
- ret = nfs_page_group_lock(head);
507
- if (ret < 0)
508
- goto release_request;
575
+ head = nfs_find_and_lock_page_request(page);
576
+ if (IS_ERR_OR_NULL(head))
577
+ return head;
509578
510579 /* lock each request in the page group */
511
- total_bytes = head->wb_bytes;
512
- for (subreq = head->wb_this_page; subreq != head;
513
- subreq = subreq->wb_this_page) {
514
-
515
- if (!kref_get_unless_zero(&subreq->wb_kref)) {
516
- if (subreq->wb_offset == head->wb_offset + total_bytes)
517
- total_bytes += subreq->wb_bytes;
518
- continue;
519
- }
520
-
521
- while (!nfs_lock_request(subreq)) {
522
- /*
523
- * Unlock page to allow nfs_page_group_sync_on_bit()
524
- * to succeed
525
- */
526
- nfs_page_group_unlock(head);
527
- ret = nfs_wait_on_request(subreq);
528
- if (!ret)
529
- ret = nfs_page_group_lock(head);
530
- if (ret < 0) {
531
- nfs_unroll_locks(inode, head, subreq);
532
- nfs_release_request(subreq);
533
- goto release_request;
534
- }
535
- }
536
- /*
537
- * Subrequests are always contiguous, non overlapping
538
- * and in order - but may be repeated (mirrored writes).
539
- */
540
- if (subreq->wb_offset == (head->wb_offset + total_bytes)) {
541
- /* keep track of how many bytes this group covers */
542
- total_bytes += subreq->wb_bytes;
543
- } else if (WARN_ON_ONCE(subreq->wb_offset < head->wb_offset ||
544
- ((subreq->wb_offset + subreq->wb_bytes) >
545
- (head->wb_offset + total_bytes)))) {
546
- nfs_page_group_unlock(head);
547
- nfs_unroll_locks(inode, head, subreq);
548
- nfs_unlock_and_release_request(subreq);
549
- ret = -EIO;
550
- goto release_request;
551
- }
552
- }
553
-
554
- /* Now that all requests are locked, make sure they aren't on any list.
555
- * Commit list removal accounting is done after locks are dropped */
556
- subreq = head;
557
- do {
558
- nfs_clear_request_commit(subreq);
559
- subreq = subreq->wb_this_page;
560
- } while (subreq != head);
561
-
562
- /* unlink subrequests from head, destroy them later */
563
- if (head->wb_this_page != head) {
564
- /* destroy list will be terminated by head */
565
- destroy_list = head->wb_this_page;
566
- head->wb_this_page = head;
567
-
568
- /* change head request to cover whole range that
569
- * the former page group covered */
570
- head->wb_bytes = total_bytes;
571
- }
572
-
573
- /* Postpone destruction of this request */
574
- if (test_and_clear_bit(PG_REMOVE, &head->wb_flags)) {
575
- set_bit(PG_INODE_REF, &head->wb_flags);
576
- kref_get(&head->wb_kref);
577
- atomic_long_inc(&NFS_I(inode)->nrequests);
578
- }
579
-
580
- nfs_page_group_unlock(head);
581
-
582
- nfs_destroy_unlinked_subrequests(destroy_list, head, inode);
583
-
584
- /* Did we lose a race with nfs_inode_remove_request()? */
585
- if (!(PagePrivate(page) || PageSwapCache(page))) {
580
+ ret = nfs_page_group_lock_subrequests(head);
581
+ if (ret < 0) {
586582 nfs_unlock_and_release_request(head);
587
- return NULL;
583
+ return ERR_PTR(ret);
588584 }
589585
590
- /* still holds ref on head from nfs_page_find_head_request
591
- * and still has lock on head from lock loop */
586
+ nfs_join_page_group(head, inode);
587
+
592588 return head;
593
-
594
-release_request:
595
- nfs_unlock_and_release_request(head);
596
- return ERR_PTR(ret);
597589 }
598590
599
-static void nfs_write_error_remove_page(struct nfs_page *req)
591
+static void nfs_write_error(struct nfs_page *req, int error)
600592 {
593
+ trace_nfs_write_error(req, error);
594
+ nfs_mapping_set_error(req->wb_page, error);
595
+ nfs_inode_remove_request(req);
601596 nfs_end_page_writeback(req);
602
- generic_error_remove_page(page_file_mapping(req->wb_page),
603
- req->wb_page);
604597 nfs_release_request(req);
605
-}
606
-
607
-static bool
608
-nfs_error_is_fatal_on_server(int err)
609
-{
610
- switch (err) {
611
- case 0:
612
- case -ERESTARTSYS:
613
- case -EINTR:
614
- return false;
615
- }
616
- return nfs_error_is_fatal(err);
617598 }
618599
619600 /*
....@@ -636,8 +617,8 @@
636617 nfs_set_page_writeback(page);
637618 WARN_ON_ONCE(test_bit(PG_CLEAN, &req->wb_flags));
638619
639
- ret = req->wb_context->error;
640620 /* If there is a fatal error that covers this write, just exit */
621
+ ret = pgio->pg_error;
641622 if (nfs_error_is_fatal_on_server(ret))
642623 goto out_launder;
643624
....@@ -648,19 +629,19 @@
648629 * Remove the problematic req upon fatal errors on the server
649630 */
650631 if (nfs_error_is_fatal(ret)) {
651
- nfs_context_set_write_error(req->wb_context, ret);
652632 if (nfs_error_is_fatal_on_server(ret))
653633 goto out_launder;
654634 } else
655635 ret = -EAGAIN;
656636 nfs_redirty_request(req);
637
+ pgio->pg_error = 0;
657638 } else
658639 nfs_add_stats(page_file_mapping(page)->host,
659640 NFSIOS_WRITEPAGES, 1);
660641 out:
661642 return ret;
662643 out_launder:
663
- nfs_write_error_remove_page(req);
644
+ nfs_write_error(req, ret);
664645 return 0;
665646 }
666647
....@@ -673,7 +654,7 @@
673654 ret = nfs_page_async_flush(pgio, page);
674655 if (ret == -EAGAIN) {
675656 redirty_page_for_writepage(wbc, page);
676
- ret = 0;
657
+ ret = AOP_WRITEPAGE_ACTIVATE;
677658 }
678659 return ret;
679660 }
....@@ -692,12 +673,9 @@
692673 nfs_pageio_init_write(&pgio, inode, 0,
693674 false, &nfs_async_write_completion_ops);
694675 err = nfs_do_writepage(page, wbc, &pgio);
676
+ pgio.pg_error = 0;
695677 nfs_pageio_complete(&pgio);
696
- if (err < 0)
697
- return err;
698
- if (pgio.pg_error < 0)
699
- return pgio.pg_error;
700
- return 0;
678
+ return err;
701679 }
702680
703681 int nfs_writepage(struct page *page, struct writeback_control *wbc)
....@@ -705,7 +683,8 @@
705683 int ret;
706684
707685 ret = nfs_writepage_locked(page, wbc);
708
- unlock_page(page);
686
+ if (ret != AOP_WRITEPAGE_ACTIVATE)
687
+ unlock_page(page);
709688 return ret;
710689 }
711690
....@@ -714,7 +693,8 @@
714693 int ret;
715694
716695 ret = nfs_do_writepage(page, wbc, data);
717
- unlock_page(page);
696
+ if (ret != AOP_WRITEPAGE_ACTIVATE)
697
+ unlock_page(page);
718698 return ret;
719699 }
720700
....@@ -727,11 +707,12 @@
727707 {
728708 struct inode *inode = mapping->host;
729709 struct nfs_pageio_descriptor pgio;
730
- struct nfs_io_completion *ioc = nfs_io_completion_alloc(GFP_NOFS);
710
+ struct nfs_io_completion *ioc;
731711 int err;
732712
733713 nfs_inc_stats(inode, NFSIOS_VFSWRITEPAGES);
734714
715
+ ioc = nfs_io_completion_alloc(GFP_KERNEL);
735716 if (ioc)
736717 nfs_io_completion_init(ioc, nfs_io_completion_commit, inode);
737718
....@@ -739,12 +720,10 @@
739720 &nfs_async_write_completion_ops);
740721 pgio.pg_io_completion = ioc;
741722 err = write_cache_pages(mapping, wbc, nfs_writepages_callback, &pgio);
723
+ pgio.pg_error = 0;
742724 nfs_pageio_complete(&pgio);
743725 nfs_io_completion_put(ioc);
744726
745
- if (err < 0)
746
- goto out_err;
747
- err = pgio.pg_error;
748727 if (err < 0)
749728 goto out_err;
750729 return 0;
....@@ -881,7 +860,6 @@
881860 /**
882861 * nfs_request_add_commit_list - add request to a commit list
883862 * @req: pointer to a struct nfs_page
884
- * @dst: commit list head
885863 * @cinfo: holds list lock and accounting info
886864 *
887865 * This sets the PG_CLEAN bit, updates the cinfo count of
....@@ -960,9 +938,9 @@
960938 static void
961939 nfs_clear_page_commit(struct page *page)
962940 {
963
- dec_node_page_state(page, NR_UNSTABLE_NFS);
941
+ dec_node_page_state(page, NR_WRITEBACK);
964942 dec_wb_stat(&inode_to_bdi(page_file_mapping(page)->host)->wb,
965
- WB_RECLAIMABLE);
943
+ WB_WRITEBACK);
966944 }
967945
968946 /* Called holding the request lock on @req */
....@@ -970,7 +948,8 @@
970948 nfs_clear_request_commit(struct nfs_page *req)
971949 {
972950 if (test_bit(PG_CLEAN, &req->wb_flags)) {
973
- struct inode *inode = d_inode(req->wb_context->dentry);
951
+ struct nfs_open_context *ctx = nfs_req_openctx(req);
952
+ struct inode *inode = d_inode(ctx->dentry);
974953 struct nfs_commit_info cinfo;
975954
976955 nfs_init_cinfo_from_inode(&cinfo, inode);
....@@ -1010,11 +989,13 @@
1010989 nfs_list_remove_request(req);
1011990 if (test_bit(NFS_IOHDR_ERROR, &hdr->flags) &&
1012991 (hdr->good_bytes < bytes)) {
1013
- nfs_set_pageerror(page_file_mapping(req->wb_page));
1014
- nfs_context_set_write_error(req->wb_context, hdr->error);
992
+ trace_nfs_comp_error(req, hdr->error);
993
+ nfs_mapping_set_error(req->wb_page, hdr->error);
1015994 goto remove_req;
1016995 }
1017996 if (nfs_write_need_commit(hdr)) {
997
+ /* Reset wb_nio, since the write was successful. */
998
+ req->wb_nio = 0;
1018999 memcpy(&req->wb_verf, &hdr->verf.verifier, sizeof(req->wb_verf));
10191000 nfs_mark_request_commit(req, hdr->lseg, &cinfo,
10201001 hdr->pgio_mirror_idx);
....@@ -1134,6 +1115,7 @@
11341115 req->wb_bytes = end - req->wb_offset;
11351116 else
11361117 req->wb_bytes = rqend - req->wb_offset;
1118
+ req->wb_nio = 0;
11371119 return req;
11381120 out_flushme:
11391121 /*
....@@ -1163,7 +1145,7 @@
11631145 req = nfs_try_to_update_request(inode, page, offset, bytes);
11641146 if (req != NULL)
11651147 goto out;
1166
- req = nfs_create_request(ctx, page, NULL, offset, bytes);
1148
+ req = nfs_create_request(ctx, page, offset, bytes);
11671149 if (IS_ERR(req))
11681150 goto out;
11691151 nfs_inode_add_request(inode, req);
....@@ -1208,7 +1190,7 @@
12081190 return 0;
12091191 l_ctx = req->wb_lock_context;
12101192 do_flush = req->wb_page != page ||
1211
- !nfs_match_open_context(req->wb_context, ctx);
1193
+ !nfs_match_open_context(nfs_req_openctx(req), ctx);
12121194 if (l_ctx && flctx &&
12131195 !(list_empty_careful(&flctx->flc_posix) &&
12141196 list_empty_careful(&flctx->flc_flock))) {
....@@ -1236,9 +1218,12 @@
12361218 nfs_key_timeout_notify(struct file *filp, struct inode *inode)
12371219 {
12381220 struct nfs_open_context *ctx = nfs_file_open_context(filp);
1239
- struct rpc_auth *auth = NFS_SERVER(inode)->client->cl_auth;
12401221
1241
- return rpcauth_key_timeout_notify(auth, ctx->cred);
1222
+ if (nfs_ctx_key_to_expire(ctx, inode) &&
1223
+ !ctx->ll_cred)
1224
+ /* Already expired! */
1225
+ return -EACCES;
1226
+ return 0;
12421227 }
12431228
12441229 /*
....@@ -1247,8 +1232,23 @@
12471232 bool nfs_ctx_key_to_expire(struct nfs_open_context *ctx, struct inode *inode)
12481233 {
12491234 struct rpc_auth *auth = NFS_SERVER(inode)->client->cl_auth;
1235
+ struct rpc_cred *cred = ctx->ll_cred;
1236
+ struct auth_cred acred = {
1237
+ .cred = ctx->cred,
1238
+ };
12501239
1251
- return rpcauth_cred_key_to_expire(auth, ctx->cred);
1240
+ if (cred && !cred->cr_ops->crmatch(&acred, cred, 0)) {
1241
+ put_rpccred(cred);
1242
+ ctx->ll_cred = NULL;
1243
+ cred = NULL;
1244
+ }
1245
+ if (!cred)
1246
+ cred = auth->au_ops->lookup_cred(auth, &acred, 0);
1247
+ if (!cred || IS_ERR(cred))
1248
+ return true;
1249
+ ctx->ll_cred = cred;
1250
+ return !!(cred->cr_ops->crkey_timeout &&
1251
+ cred->cr_ops->crkey_timeout(cred));
12521252 }
12531253
12541254 /*
....@@ -1380,8 +1380,7 @@
13801380
13811381 task_setup_data->priority = priority;
13821382 rpc_ops->write_setup(hdr, msg, &task_setup_data->rpc_client);
1383
- trace_nfs_initiate_write(hdr->inode, hdr->io_start, hdr->good_bytes,
1384
- hdr->args.stable);
1383
+ trace_nfs_initiate_write(hdr);
13851384 }
13861385
13871386 /* If a nfs_flush_* function fails, it should remove reqs from @head and
....@@ -1390,8 +1389,10 @@
13901389 */
13911390 static void nfs_redirty_request(struct nfs_page *req)
13921391 {
1392
+ /* Bump the transmission count */
1393
+ req->wb_nio++;
13931394 nfs_mark_request_dirty(req);
1394
- set_bit(NFS_CONTEXT_RESEND_WRITES, &req->wb_context->flags);
1395
+ set_bit(NFS_CONTEXT_RESEND_WRITES, &nfs_req_openctx(req)->flags);
13951396 nfs_end_page_writeback(req);
13961397 nfs_release_request(req);
13971398 }
....@@ -1403,14 +1404,10 @@
14031404 while (!list_empty(head)) {
14041405 req = nfs_list_entry(head->next);
14051406 nfs_list_remove_request(req);
1406
- if (nfs_error_is_fatal(error)) {
1407
- nfs_context_set_write_error(req->wb_context, error);
1408
- if (nfs_error_is_fatal_on_server(error)) {
1409
- nfs_write_error_remove_page(req);
1410
- continue;
1411
- }
1412
- }
1413
- nfs_redirty_request(req);
1407
+ if (nfs_error_is_fatal_on_server(error))
1408
+ nfs_write_error(req, error);
1409
+ else
1410
+ nfs_redirty_request(req);
14141411 }
14151412 }
14161413
....@@ -1547,8 +1544,7 @@
15471544 return status;
15481545
15491546 nfs_add_stats(inode, NFSIOS_SERVERWRITTENBYTES, hdr->res.count);
1550
- trace_nfs_writeback_done(inode, task->tk_status,
1551
- hdr->args.offset, hdr->res.verf);
1547
+ trace_nfs_writeback_done(task, hdr);
15521548
15531549 if (hdr->res.verf->committed < hdr->args.stable &&
15541550 task->tk_status >= 0) {
....@@ -1628,6 +1624,8 @@
16281624 */
16291625 argp->stable = NFS_FILE_SYNC;
16301626 }
1627
+ resp->count = 0;
1628
+ resp->verf->committed = 0;
16311629 rpc_restart_call_prepare(task);
16321630 }
16331631 }
....@@ -1643,10 +1641,13 @@
16431641 atomic_inc(&cinfo->rpcs_out);
16441642 }
16451643
1646
-static void nfs_commit_end(struct nfs_mds_commit_info *cinfo)
1644
+bool nfs_commit_end(struct nfs_mds_commit_info *cinfo)
16471645 {
1648
- if (atomic_dec_and_test(&cinfo->rpcs_out))
1646
+ if (atomic_dec_and_test(&cinfo->rpcs_out)) {
16491647 wake_up_var(&cinfo->rpcs_out);
1648
+ return true;
1649
+ }
1650
+ return false;
16501651 }
16511652
16521653 void nfs_commitdata_release(struct nfs_commit_data *data)
....@@ -1714,16 +1715,22 @@
17141715 struct pnfs_layout_segment *lseg,
17151716 struct nfs_commit_info *cinfo)
17161717 {
1717
- struct nfs_page *first = nfs_list_entry(head->next);
1718
- struct inode *inode = d_inode(first->wb_context->dentry);
1718
+ struct nfs_page *first;
1719
+ struct nfs_open_context *ctx;
1720
+ struct inode *inode;
17191721
17201722 /* Set up the RPC argument and reply structs
17211723 * NB: take care not to mess about with data->commit et al. */
17221724
1723
- list_splice_init(head, &data->pages);
1725
+ if (head)
1726
+ list_splice_init(head, &data->pages);
1727
+
1728
+ first = nfs_list_entry(data->pages.next);
1729
+ ctx = nfs_req_openctx(first);
1730
+ inode = d_inode(ctx->dentry);
17241731
17251732 data->inode = inode;
1726
- data->cred = first->wb_context->cred;
1733
+ data->cred = ctx->cred;
17271734 data->lseg = lseg; /* reference transferred */
17281735 /* only set lwb for pnfs commit */
17291736 if (lseg)
....@@ -1736,10 +1743,11 @@
17361743 /* Note: we always request a commit of the entire inode */
17371744 data->args.offset = 0;
17381745 data->args.count = 0;
1739
- data->context = get_nfs_open_context(first->wb_context);
1746
+ data->context = get_nfs_open_context(ctx);
17401747 data->res.fattr = &data->fattr;
17411748 data->res.verf = &data->verf;
17421749 nfs_fattr_init(&data->fattr);
1750
+ nfs_commit_begin(cinfo->mds);
17431751 }
17441752 EXPORT_SYMBOL_GPL(nfs_init_commit);
17451753
....@@ -1781,13 +1789,16 @@
17811789 if (list_empty(head))
17821790 return 0;
17831791
1784
- data = nfs_commitdata_alloc(true);
1792
+ data = nfs_commitdata_alloc();
1793
+ if (!data) {
1794
+ nfs_retry_commit(head, NULL, cinfo, -1);
1795
+ return -ENOMEM;
1796
+ }
17851797
17861798 /* Set up the argument struct */
17871799 nfs_init_commit(data, head, NULL, cinfo);
1788
- atomic_inc(&cinfo->mds->rpcs_out);
17891800 return nfs_initiate_commit(NFS_CLIENT(inode), data, NFS_PROTO(inode),
1790
- data->mds_ops, how, 0);
1801
+ data->mds_ops, how, RPC_TASK_CRED_NOREF);
17911802 }
17921803
17931804 /*
....@@ -1802,7 +1813,7 @@
18021813
18031814 /* Call the NFS version-specific code */
18041815 NFS_PROTO(data->inode)->commit_done(task, data);
1805
- trace_nfs_commit_done(data);
1816
+ trace_nfs_commit_done(task, data);
18061817 }
18071818
18081819 static void nfs_commit_release_pages(struct nfs_commit_data *data)
....@@ -1820,22 +1831,23 @@
18201831 nfs_clear_page_commit(req->wb_page);
18211832
18221833 dprintk("NFS: commit (%s/%llu %d@%lld)",
1823
- req->wb_context->dentry->d_sb->s_id,
1824
- (unsigned long long)NFS_FILEID(d_inode(req->wb_context->dentry)),
1834
+ nfs_req_openctx(req)->dentry->d_sb->s_id,
1835
+ (unsigned long long)NFS_FILEID(d_inode(nfs_req_openctx(req)->dentry)),
18251836 req->wb_bytes,
18261837 (long long)req_offset(req));
18271838 if (status < 0) {
1828
- nfs_context_set_write_error(req->wb_context, status);
1829
- if (req->wb_page)
1839
+ if (req->wb_page) {
1840
+ trace_nfs_commit_error(req, status);
1841
+ nfs_mapping_set_error(req->wb_page, status);
18301842 nfs_inode_remove_request(req);
1843
+ }
18311844 dprintk_cont(", error = %d\n", status);
18321845 goto next;
18331846 }
18341847
18351848 /* Okay, COMMIT succeeded, apparently. Check the verifier
18361849 * returned by the server against all stored verfs. */
1837
- if (verf->committed > NFS_UNSTABLE &&
1838
- !nfs_write_verifier_cmp(&req->wb_verf, &verf->verifier)) {
1850
+ if (nfs_write_match_verf(verf, req)) {
18391851 /* We have a match */
18401852 if (req->wb_page)
18411853 nfs_inode_remove_request(req);
....@@ -1845,7 +1857,7 @@
18451857 /* We have a mismatch. Write the page again */
18461858 dprintk_cont(" mismatch\n");
18471859 nfs_mark_request_dirty(req);
1848
- set_bit(NFS_CONTEXT_RESEND_WRITES, &req->wb_context->flags);
1860
+ set_bit(NFS_CONTEXT_RESEND_WRITES, &nfs_req_openctx(req)->flags);
18491861 next:
18501862 nfs_unlock_and_release_request(req);
18511863 /* Latency breaker */
....@@ -2135,7 +2147,7 @@
21352147 * This allows larger machines to have larger/more transfers.
21362148 * Limit the default to 256M
21372149 */
2138
- nfs_congestion_kb = (16*int_sqrt(totalram_pages)) << (PAGE_SHIFT-10);
2150
+ nfs_congestion_kb = (16*int_sqrt(totalram_pages())) << (PAGE_SHIFT-10);
21392151 if (nfs_congestion_kb > 256*1024)
21402152 nfs_congestion_kb = 256*1024;
21412153