aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
Diffstat (limited to 'fs')
-rw-r--r--fs/nfs/dir.c18
-rw-r--r--fs/nfs/direct.c279
-rw-r--r--fs/nfs/file.c6
-rw-r--r--fs/nfs/inode.c48
-rw-r--r--fs/nfs/nfs4client.c25
-rw-r--r--fs/nfs/nfs4filelayout.c16
-rw-r--r--fs/nfs/nfs4filelayoutdev.c2
-rw-r--r--fs/nfs/nfs4proc.c43
-rw-r--r--fs/nfs/nfs4state.c4
-rw-r--r--fs/nfs/nfs4super.c14
-rw-r--r--fs/nfs/nfs4xdr.c47
-rw-r--r--fs/nfs/pnfs.c67
-rw-r--r--fs/nfs/pnfs.h16
-rw-r--r--fs/nfs/read.c12
-rw-r--r--fs/nfs/write.c19
15 files changed, 359 insertions, 257 deletions
diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
index 812154aff981..b266f734bd53 100644
--- a/fs/nfs/dir.c
+++ b/fs/nfs/dir.c
@@ -1404,7 +1404,7 @@ int nfs_atomic_open(struct inode *dir, struct dentry *dentry,
1404 /* Expect a negative dentry */ 1404 /* Expect a negative dentry */
1405 BUG_ON(dentry->d_inode); 1405 BUG_ON(dentry->d_inode);
1406 1406
1407 dfprintk(VFS, "NFS: atomic_open(%s/%ld), %pd\n", 1407 dfprintk(VFS, "NFS: atomic_open(%s/%lu), %pd\n",
1408 dir->i_sb->s_id, dir->i_ino, dentry); 1408 dir->i_sb->s_id, dir->i_ino, dentry);
1409 1409
1410 err = nfs_check_flags(open_flags); 1410 err = nfs_check_flags(open_flags);
@@ -1594,7 +1594,7 @@ int nfs_create(struct inode *dir, struct dentry *dentry,
1594 int open_flags = excl ? O_CREAT | O_EXCL : O_CREAT; 1594 int open_flags = excl ? O_CREAT | O_EXCL : O_CREAT;
1595 int error; 1595 int error;
1596 1596
1597 dfprintk(VFS, "NFS: create(%s/%ld), %pd\n", 1597 dfprintk(VFS, "NFS: create(%s/%lu), %pd\n",
1598 dir->i_sb->s_id, dir->i_ino, dentry); 1598 dir->i_sb->s_id, dir->i_ino, dentry);
1599 1599
1600 attr.ia_mode = mode; 1600 attr.ia_mode = mode;
@@ -1621,7 +1621,7 @@ nfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t rdev)
1621 struct iattr attr; 1621 struct iattr attr;
1622 int status; 1622 int status;
1623 1623
1624 dfprintk(VFS, "NFS: mknod(%s/%ld), %pd\n", 1624 dfprintk(VFS, "NFS: mknod(%s/%lu), %pd\n",
1625 dir->i_sb->s_id, dir->i_ino, dentry); 1625 dir->i_sb->s_id, dir->i_ino, dentry);
1626 1626
1627 if (!new_valid_dev(rdev)) 1627 if (!new_valid_dev(rdev))
@@ -1650,7 +1650,7 @@ int nfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
1650 struct iattr attr; 1650 struct iattr attr;
1651 int error; 1651 int error;
1652 1652
1653 dfprintk(VFS, "NFS: mkdir(%s/%ld), %pd\n", 1653 dfprintk(VFS, "NFS: mkdir(%s/%lu), %pd\n",
1654 dir->i_sb->s_id, dir->i_ino, dentry); 1654 dir->i_sb->s_id, dir->i_ino, dentry);
1655 1655
1656 attr.ia_valid = ATTR_MODE; 1656 attr.ia_valid = ATTR_MODE;
@@ -1678,7 +1678,7 @@ int nfs_rmdir(struct inode *dir, struct dentry *dentry)
1678{ 1678{
1679 int error; 1679 int error;
1680 1680
1681 dfprintk(VFS, "NFS: rmdir(%s/%ld), %pd\n", 1681 dfprintk(VFS, "NFS: rmdir(%s/%lu), %pd\n",
1682 dir->i_sb->s_id, dir->i_ino, dentry); 1682 dir->i_sb->s_id, dir->i_ino, dentry);
1683 1683
1684 trace_nfs_rmdir_enter(dir, dentry); 1684 trace_nfs_rmdir_enter(dir, dentry);
@@ -1747,7 +1747,7 @@ int nfs_unlink(struct inode *dir, struct dentry *dentry)
1747 int error; 1747 int error;
1748 int need_rehash = 0; 1748 int need_rehash = 0;
1749 1749
1750 dfprintk(VFS, "NFS: unlink(%s/%ld, %pd)\n", dir->i_sb->s_id, 1750 dfprintk(VFS, "NFS: unlink(%s/%lu, %pd)\n", dir->i_sb->s_id,
1751 dir->i_ino, dentry); 1751 dir->i_ino, dentry);
1752 1752
1753 trace_nfs_unlink_enter(dir, dentry); 1753 trace_nfs_unlink_enter(dir, dentry);
@@ -1798,7 +1798,7 @@ int nfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
1798 unsigned int pathlen = strlen(symname); 1798 unsigned int pathlen = strlen(symname);
1799 int error; 1799 int error;
1800 1800
1801 dfprintk(VFS, "NFS: symlink(%s/%ld, %pd, %s)\n", dir->i_sb->s_id, 1801 dfprintk(VFS, "NFS: symlink(%s/%lu, %pd, %s)\n", dir->i_sb->s_id,
1802 dir->i_ino, dentry, symname); 1802 dir->i_ino, dentry, symname);
1803 1803
1804 if (pathlen > PAGE_SIZE) 1804 if (pathlen > PAGE_SIZE)
@@ -1821,7 +1821,7 @@ int nfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
1821 error = NFS_PROTO(dir)->symlink(dir, dentry, page, pathlen, &attr); 1821 error = NFS_PROTO(dir)->symlink(dir, dentry, page, pathlen, &attr);
1822 trace_nfs_symlink_exit(dir, dentry, error); 1822 trace_nfs_symlink_exit(dir, dentry, error);
1823 if (error != 0) { 1823 if (error != 0) {
1824 dfprintk(VFS, "NFS: symlink(%s/%ld, %pd, %s) error %d\n", 1824 dfprintk(VFS, "NFS: symlink(%s/%lu, %pd, %s) error %d\n",
1825 dir->i_sb->s_id, dir->i_ino, 1825 dir->i_sb->s_id, dir->i_ino,
1826 dentry, symname, error); 1826 dentry, symname, error);
1827 d_drop(dentry); 1827 d_drop(dentry);
@@ -2304,7 +2304,7 @@ out:
2304 if (!res && (mask & MAY_EXEC) && !execute_ok(inode)) 2304 if (!res && (mask & MAY_EXEC) && !execute_ok(inode))
2305 res = -EACCES; 2305 res = -EACCES;
2306 2306
2307 dfprintk(VFS, "NFS: permission(%s/%ld), mask=0x%x, res=%d\n", 2307 dfprintk(VFS, "NFS: permission(%s/%lu), mask=0x%x, res=%d\n",
2308 inode->i_sb->s_id, inode->i_ino, mask, res); 2308 inode->i_sb->s_id, inode->i_ino, mask, res);
2309 return res; 2309 return res;
2310out_notsup: 2310out_notsup:
diff --git a/fs/nfs/direct.c b/fs/nfs/direct.c
index d71d66c9e0a1..b8797ae6831f 100644
--- a/fs/nfs/direct.c
+++ b/fs/nfs/direct.c
@@ -222,14 +222,31 @@ out:
222 * Synchronous I/O uses a stack-allocated iocb. Thus we can't trust 222 * Synchronous I/O uses a stack-allocated iocb. Thus we can't trust
223 * the iocb is still valid here if this is a synchronous request. 223 * the iocb is still valid here if this is a synchronous request.
224 */ 224 */
225static void nfs_direct_complete(struct nfs_direct_req *dreq) 225static void nfs_direct_complete(struct nfs_direct_req *dreq, bool write)
226{ 226{
227 struct inode *inode = dreq->inode;
228
229 if (dreq->iocb && write) {
230 loff_t pos = dreq->iocb->ki_pos + dreq->count;
231
232 spin_lock(&inode->i_lock);
233 if (i_size_read(inode) < pos)
234 i_size_write(inode, pos);
235 spin_unlock(&inode->i_lock);
236 }
237
238 if (write)
239 nfs_zap_mapping(inode, inode->i_mapping);
240
241 inode_dio_done(inode);
242
227 if (dreq->iocb) { 243 if (dreq->iocb) {
228 long res = (long) dreq->error; 244 long res = (long) dreq->error;
229 if (!res) 245 if (!res)
230 res = (long) dreq->count; 246 res = (long) dreq->count;
231 aio_complete(dreq->iocb, res, 0); 247 aio_complete(dreq->iocb, res, 0);
232 } 248 }
249
233 complete_all(&dreq->completion); 250 complete_all(&dreq->completion);
234 251
235 nfs_direct_req_release(dreq); 252 nfs_direct_req_release(dreq);
@@ -237,9 +254,9 @@ static void nfs_direct_complete(struct nfs_direct_req *dreq)
237 254
238static void nfs_direct_readpage_release(struct nfs_page *req) 255static void nfs_direct_readpage_release(struct nfs_page *req)
239{ 256{
240 dprintk("NFS: direct read done (%s/%lld %d@%lld)\n", 257 dprintk("NFS: direct read done (%s/%llu %d@%lld)\n",
241 req->wb_context->dentry->d_inode->i_sb->s_id, 258 req->wb_context->dentry->d_inode->i_sb->s_id,
242 (long long)NFS_FILEID(req->wb_context->dentry->d_inode), 259 (unsigned long long)NFS_FILEID(req->wb_context->dentry->d_inode),
243 req->wb_bytes, 260 req->wb_bytes,
244 (long long)req_offset(req)); 261 (long long)req_offset(req));
245 nfs_release_request(req); 262 nfs_release_request(req);
@@ -272,7 +289,7 @@ static void nfs_direct_read_completion(struct nfs_pgio_header *hdr)
272 } 289 }
273out_put: 290out_put:
274 if (put_dreq(dreq)) 291 if (put_dreq(dreq))
275 nfs_direct_complete(dreq); 292 nfs_direct_complete(dreq, false);
276 hdr->release(hdr); 293 hdr->release(hdr);
277} 294}
278 295
@@ -402,6 +419,7 @@ static ssize_t nfs_direct_read_schedule_iovec(struct nfs_direct_req *dreq,
402 loff_t pos, bool uio) 419 loff_t pos, bool uio)
403{ 420{
404 struct nfs_pageio_descriptor desc; 421 struct nfs_pageio_descriptor desc;
422 struct inode *inode = dreq->inode;
405 ssize_t result = -EINVAL; 423 ssize_t result = -EINVAL;
406 size_t requested_bytes = 0; 424 size_t requested_bytes = 0;
407 unsigned long seg; 425 unsigned long seg;
@@ -410,6 +428,7 @@ static ssize_t nfs_direct_read_schedule_iovec(struct nfs_direct_req *dreq,
410 &nfs_direct_read_completion_ops); 428 &nfs_direct_read_completion_ops);
411 get_dreq(dreq); 429 get_dreq(dreq);
412 desc.pg_dreq = dreq; 430 desc.pg_dreq = dreq;
431 atomic_inc(&inode->i_dio_count);
413 432
414 for (seg = 0; seg < nr_segs; seg++) { 433 for (seg = 0; seg < nr_segs; seg++) {
415 const struct iovec *vec = &iov[seg]; 434 const struct iovec *vec = &iov[seg];
@@ -429,26 +448,69 @@ static ssize_t nfs_direct_read_schedule_iovec(struct nfs_direct_req *dreq,
429 * generic layer handle the completion. 448 * generic layer handle the completion.
430 */ 449 */
431 if (requested_bytes == 0) { 450 if (requested_bytes == 0) {
451 inode_dio_done(inode);
432 nfs_direct_req_release(dreq); 452 nfs_direct_req_release(dreq);
433 return result < 0 ? result : -EIO; 453 return result < 0 ? result : -EIO;
434 } 454 }
435 455
436 if (put_dreq(dreq)) 456 if (put_dreq(dreq))
437 nfs_direct_complete(dreq); 457 nfs_direct_complete(dreq, false);
438 return 0; 458 return 0;
439} 459}
440 460
441static ssize_t nfs_direct_read(struct kiocb *iocb, const struct iovec *iov, 461/**
442 unsigned long nr_segs, loff_t pos, bool uio) 462 * nfs_file_direct_read - file direct read operation for NFS files
463 * @iocb: target I/O control block
464 * @iov: vector of user buffers into which to read data
465 * @nr_segs: size of iov vector
466 * @pos: byte offset in file where reading starts
467 *
468 * We use this function for direct reads instead of calling
469 * generic_file_aio_read() in order to avoid gfar's check to see if
470 * the request starts before the end of the file. For that check
471 * to work, we must generate a GETATTR before each direct read, and
472 * even then there is a window between the GETATTR and the subsequent
473 * READ where the file size could change. Our preference is simply
474 * to do all reads the application wants, and the server will take
475 * care of managing the end of file boundary.
476 *
477 * This function also eliminates unnecessarily updating the file's
478 * atime locally, as the NFS server sets the file's atime, and this
479 * client must read the updated atime from the server back into its
480 * cache.
481 */
482ssize_t nfs_file_direct_read(struct kiocb *iocb, const struct iovec *iov,
483 unsigned long nr_segs, loff_t pos, bool uio)
443{ 484{
444 ssize_t result = -ENOMEM; 485 struct file *file = iocb->ki_filp;
445 struct inode *inode = iocb->ki_filp->f_mapping->host; 486 struct address_space *mapping = file->f_mapping;
487 struct inode *inode = mapping->host;
446 struct nfs_direct_req *dreq; 488 struct nfs_direct_req *dreq;
447 struct nfs_lock_context *l_ctx; 489 struct nfs_lock_context *l_ctx;
490 ssize_t result = -EINVAL;
491 size_t count;
448 492
493 count = iov_length(iov, nr_segs);
494 nfs_add_stats(mapping->host, NFSIOS_DIRECTREADBYTES, count);
495
496 dfprintk(FILE, "NFS: direct read(%pD2, %zd@%Ld)\n",
497 file, count, (long long) pos);
498
499 result = 0;
500 if (!count)
501 goto out;
502
503 mutex_lock(&inode->i_mutex);
504 result = nfs_sync_mapping(mapping);
505 if (result)
506 goto out_unlock;
507
508 task_io_account_read(count);
509
510 result = -ENOMEM;
449 dreq = nfs_direct_req_alloc(); 511 dreq = nfs_direct_req_alloc();
450 if (dreq == NULL) 512 if (dreq == NULL)
451 goto out; 513 goto out_unlock;
452 514
453 dreq->inode = inode; 515 dreq->inode = inode;
454 dreq->bytes_left = iov_length(iov, nr_segs); 516 dreq->bytes_left = iov_length(iov, nr_segs);
@@ -464,20 +526,26 @@ static ssize_t nfs_direct_read(struct kiocb *iocb, const struct iovec *iov,
464 526
465 NFS_I(inode)->read_io += iov_length(iov, nr_segs); 527 NFS_I(inode)->read_io += iov_length(iov, nr_segs);
466 result = nfs_direct_read_schedule_iovec(dreq, iov, nr_segs, pos, uio); 528 result = nfs_direct_read_schedule_iovec(dreq, iov, nr_segs, pos, uio);
467 if (!result) 529
530 mutex_unlock(&inode->i_mutex);
531
532 if (!result) {
468 result = nfs_direct_wait(dreq); 533 result = nfs_direct_wait(dreq);
534 if (result > 0)
535 iocb->ki_pos = pos + result;
536 }
537
538 nfs_direct_req_release(dreq);
539 return result;
540
469out_release: 541out_release:
470 nfs_direct_req_release(dreq); 542 nfs_direct_req_release(dreq);
543out_unlock:
544 mutex_unlock(&inode->i_mutex);
471out: 545out:
472 return result; 546 return result;
473} 547}
474 548
475static void nfs_inode_dio_write_done(struct inode *inode)
476{
477 nfs_zap_mapping(inode, inode->i_mapping);
478 inode_dio_done(inode);
479}
480
481#if IS_ENABLED(CONFIG_NFS_V3) || IS_ENABLED(CONFIG_NFS_V4) 549#if IS_ENABLED(CONFIG_NFS_V3) || IS_ENABLED(CONFIG_NFS_V4)
482static void nfs_direct_write_reschedule(struct nfs_direct_req *dreq) 550static void nfs_direct_write_reschedule(struct nfs_direct_req *dreq)
483{ 551{
@@ -593,8 +661,7 @@ static void nfs_direct_write_schedule_work(struct work_struct *work)
593 nfs_direct_write_reschedule(dreq); 661 nfs_direct_write_reschedule(dreq);
594 break; 662 break;
595 default: 663 default:
596 nfs_inode_dio_write_done(dreq->inode); 664 nfs_direct_complete(dreq, true);
597 nfs_direct_complete(dreq);
598 } 665 }
599} 666}
600 667
@@ -610,8 +677,7 @@ static void nfs_direct_write_schedule_work(struct work_struct *work)
610 677
611static void nfs_direct_write_complete(struct nfs_direct_req *dreq, struct inode *inode) 678static void nfs_direct_write_complete(struct nfs_direct_req *dreq, struct inode *inode)
612{ 679{
613 nfs_inode_dio_write_done(inode); 680 nfs_direct_complete(dreq, true);
614 nfs_direct_complete(dreq);
615} 681}
616#endif 682#endif
617 683
@@ -842,93 +908,6 @@ static ssize_t nfs_direct_write_schedule_iovec(struct nfs_direct_req *dreq,
842 return 0; 908 return 0;
843} 909}
844 910
845static ssize_t nfs_direct_write(struct kiocb *iocb, const struct iovec *iov,
846 unsigned long nr_segs, loff_t pos,
847 size_t count, bool uio)
848{
849 ssize_t result = -ENOMEM;
850 struct inode *inode = iocb->ki_filp->f_mapping->host;
851 struct nfs_direct_req *dreq;
852 struct nfs_lock_context *l_ctx;
853
854 dreq = nfs_direct_req_alloc();
855 if (!dreq)
856 goto out;
857
858 dreq->inode = inode;
859 dreq->bytes_left = count;
860 dreq->ctx = get_nfs_open_context(nfs_file_open_context(iocb->ki_filp));
861 l_ctx = nfs_get_lock_context(dreq->ctx);
862 if (IS_ERR(l_ctx)) {
863 result = PTR_ERR(l_ctx);
864 goto out_release;
865 }
866 dreq->l_ctx = l_ctx;
867 if (!is_sync_kiocb(iocb))
868 dreq->iocb = iocb;
869
870 result = nfs_direct_write_schedule_iovec(dreq, iov, nr_segs, pos, uio);
871 if (!result)
872 result = nfs_direct_wait(dreq);
873out_release:
874 nfs_direct_req_release(dreq);
875out:
876 return result;
877}
878
879/**
880 * nfs_file_direct_read - file direct read operation for NFS files
881 * @iocb: target I/O control block
882 * @iov: vector of user buffers into which to read data
883 * @nr_segs: size of iov vector
884 * @pos: byte offset in file where reading starts
885 *
886 * We use this function for direct reads instead of calling
887 * generic_file_aio_read() in order to avoid gfar's check to see if
888 * the request starts before the end of the file. For that check
889 * to work, we must generate a GETATTR before each direct read, and
890 * even then there is a window between the GETATTR and the subsequent
891 * READ where the file size could change. Our preference is simply
892 * to do all reads the application wants, and the server will take
893 * care of managing the end of file boundary.
894 *
895 * This function also eliminates unnecessarily updating the file's
896 * atime locally, as the NFS server sets the file's atime, and this
897 * client must read the updated atime from the server back into its
898 * cache.
899 */
900ssize_t nfs_file_direct_read(struct kiocb *iocb, const struct iovec *iov,
901 unsigned long nr_segs, loff_t pos, bool uio)
902{
903 ssize_t retval = -EINVAL;
904 struct file *file = iocb->ki_filp;
905 struct address_space *mapping = file->f_mapping;
906 size_t count;
907
908 count = iov_length(iov, nr_segs);
909 nfs_add_stats(mapping->host, NFSIOS_DIRECTREADBYTES, count);
910
911 dfprintk(FILE, "NFS: direct read(%pD2, %zd@%Ld)\n",
912 file, count, (long long) pos);
913
914 retval = 0;
915 if (!count)
916 goto out;
917
918 retval = nfs_sync_mapping(mapping);
919 if (retval)
920 goto out;
921
922 task_io_account_read(count);
923
924 retval = nfs_direct_read(iocb, iov, nr_segs, pos, uio);
925 if (retval > 0)
926 iocb->ki_pos = pos + retval;
927
928out:
929 return retval;
930}
931
932/** 911/**
933 * nfs_file_direct_write - file direct write operation for NFS files 912 * nfs_file_direct_write - file direct write operation for NFS files
934 * @iocb: target I/O control block 913 * @iocb: target I/O control block
@@ -954,46 +933,96 @@ out:
954ssize_t nfs_file_direct_write(struct kiocb *iocb, const struct iovec *iov, 933ssize_t nfs_file_direct_write(struct kiocb *iocb, const struct iovec *iov,
955 unsigned long nr_segs, loff_t pos, bool uio) 934 unsigned long nr_segs, loff_t pos, bool uio)
956{ 935{
957 ssize_t retval = -EINVAL; 936 ssize_t result = -EINVAL;
958 struct file *file = iocb->ki_filp; 937 struct file *file = iocb->ki_filp;
959 struct address_space *mapping = file->f_mapping; 938 struct address_space *mapping = file->f_mapping;
939 struct inode *inode = mapping->host;
940 struct nfs_direct_req *dreq;
941 struct nfs_lock_context *l_ctx;
942 loff_t end;
960 size_t count; 943 size_t count;
961 944
962 count = iov_length(iov, nr_segs); 945 count = iov_length(iov, nr_segs);
946 end = (pos + count - 1) >> PAGE_CACHE_SHIFT;
947
963 nfs_add_stats(mapping->host, NFSIOS_DIRECTWRITTENBYTES, count); 948 nfs_add_stats(mapping->host, NFSIOS_DIRECTWRITTENBYTES, count);
964 949
965 dfprintk(FILE, "NFS: direct write(%pD2, %zd@%Ld)\n", 950 dfprintk(FILE, "NFS: direct write(%pD2, %zd@%Ld)\n",
966 file, count, (long long) pos); 951 file, count, (long long) pos);
967 952
968 retval = generic_write_checks(file, &pos, &count, 0); 953 result = generic_write_checks(file, &pos, &count, 0);
969 if (retval) 954 if (result)
970 goto out; 955 goto out;
971 956
972 retval = -EINVAL; 957 result = -EINVAL;
973 if ((ssize_t) count < 0) 958 if ((ssize_t) count < 0)
974 goto out; 959 goto out;
975 retval = 0; 960 result = 0;
976 if (!count) 961 if (!count)
977 goto out; 962 goto out;
978 963
979 retval = nfs_sync_mapping(mapping); 964 mutex_lock(&inode->i_mutex);
980 if (retval) 965
981 goto out; 966 result = nfs_sync_mapping(mapping);
967 if (result)
968 goto out_unlock;
969
970 if (mapping->nrpages) {
971 result = invalidate_inode_pages2_range(mapping,
972 pos >> PAGE_CACHE_SHIFT, end);
973 if (result)
974 goto out_unlock;
975 }
982 976
983 task_io_account_write(count); 977 task_io_account_write(count);
984 978
985 retval = nfs_direct_write(iocb, iov, nr_segs, pos, count, uio); 979 result = -ENOMEM;
986 if (retval > 0) { 980 dreq = nfs_direct_req_alloc();
987 struct inode *inode = mapping->host; 981 if (!dreq)
982 goto out_unlock;
988 983
989 iocb->ki_pos = pos + retval; 984 dreq->inode = inode;
990 spin_lock(&inode->i_lock); 985 dreq->bytes_left = count;
991 if (i_size_read(inode) < iocb->ki_pos) 986 dreq->ctx = get_nfs_open_context(nfs_file_open_context(iocb->ki_filp));
992 i_size_write(inode, iocb->ki_pos); 987 l_ctx = nfs_get_lock_context(dreq->ctx);
993 spin_unlock(&inode->i_lock); 988 if (IS_ERR(l_ctx)) {
989 result = PTR_ERR(l_ctx);
990 goto out_release;
991 }
992 dreq->l_ctx = l_ctx;
993 if (!is_sync_kiocb(iocb))
994 dreq->iocb = iocb;
995
996 result = nfs_direct_write_schedule_iovec(dreq, iov, nr_segs, pos, uio);
997
998 if (mapping->nrpages) {
999 invalidate_inode_pages2_range(mapping,
1000 pos >> PAGE_CACHE_SHIFT, end);
994 } 1001 }
1002
1003 mutex_unlock(&inode->i_mutex);
1004
1005 if (!result) {
1006 result = nfs_direct_wait(dreq);
1007 if (result > 0) {
1008 struct inode *inode = mapping->host;
1009
1010 iocb->ki_pos = pos + result;
1011 spin_lock(&inode->i_lock);
1012 if (i_size_read(inode) < iocb->ki_pos)
1013 i_size_write(inode, iocb->ki_pos);
1014 spin_unlock(&inode->i_lock);
1015 }
1016 }
1017 nfs_direct_req_release(dreq);
1018 return result;
1019
1020out_release:
1021 nfs_direct_req_release(dreq);
1022out_unlock:
1023 mutex_unlock(&inode->i_mutex);
995out: 1024out:
996 return retval; 1025 return result;
997} 1026}
998 1027
999/** 1028/**
diff --git a/fs/nfs/file.c b/fs/nfs/file.c
index e2fcacf07de3..5bb790a69c71 100644
--- a/fs/nfs/file.c
+++ b/fs/nfs/file.c
@@ -354,7 +354,7 @@ static int nfs_write_begin(struct file *file, struct address_space *mapping,
354 struct page *page; 354 struct page *page;
355 int once_thru = 0; 355 int once_thru = 0;
356 356
357 dfprintk(PAGECACHE, "NFS: write_begin(%pD2(%ld), %u@%lld)\n", 357 dfprintk(PAGECACHE, "NFS: write_begin(%pD2(%lu), %u@%lld)\n",
358 file, mapping->host->i_ino, len, (long long) pos); 358 file, mapping->host->i_ino, len, (long long) pos);
359 359
360start: 360start:
@@ -395,7 +395,7 @@ static int nfs_write_end(struct file *file, struct address_space *mapping,
395 struct nfs_open_context *ctx = nfs_file_open_context(file); 395 struct nfs_open_context *ctx = nfs_file_open_context(file);
396 int status; 396 int status;
397 397
398 dfprintk(PAGECACHE, "NFS: write_end(%pD2(%ld), %u@%lld)\n", 398 dfprintk(PAGECACHE, "NFS: write_end(%pD2(%lu), %u@%lld)\n",
399 file, mapping->host->i_ino, len, (long long) pos); 399 file, mapping->host->i_ino, len, (long long) pos);
400 400
401 /* 401 /*
@@ -585,7 +585,7 @@ static int nfs_vm_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
585 int ret = VM_FAULT_NOPAGE; 585 int ret = VM_FAULT_NOPAGE;
586 struct address_space *mapping; 586 struct address_space *mapping;
587 587
588 dfprintk(PAGECACHE, "NFS: vm_page_mkwrite(%pD2(%ld), offset %lld)\n", 588 dfprintk(PAGECACHE, "NFS: vm_page_mkwrite(%pD2(%lu), offset %lld)\n",
589 filp, filp->f_mapping->host->i_ino, 589 filp, filp->f_mapping->host->i_ino,
590 (long long)page_offset(page)); 590 (long long)page_offset(page));
591 591
diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
index ecd11ba7f960..ea00b34ff071 100644
--- a/fs/nfs/inode.c
+++ b/fs/nfs/inode.c
@@ -458,9 +458,9 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr, st
458 unlock_new_inode(inode); 458 unlock_new_inode(inode);
459 } else 459 } else
460 nfs_refresh_inode(inode, fattr); 460 nfs_refresh_inode(inode, fattr);
461 dprintk("NFS: nfs_fhget(%s/%Ld fh_crc=0x%08x ct=%d)\n", 461 dprintk("NFS: nfs_fhget(%s/%Lu fh_crc=0x%08x ct=%d)\n",
462 inode->i_sb->s_id, 462 inode->i_sb->s_id,
463 (long long)NFS_FILEID(inode), 463 (unsigned long long)NFS_FILEID(inode),
464 nfs_display_fhandle_hash(fh), 464 nfs_display_fhandle_hash(fh),
465 atomic_read(&inode->i_count)); 465 atomic_read(&inode->i_count));
466 466
@@ -870,8 +870,8 @@ __nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
870 struct nfs_fattr *fattr = NULL; 870 struct nfs_fattr *fattr = NULL;
871 struct nfs_inode *nfsi = NFS_I(inode); 871 struct nfs_inode *nfsi = NFS_I(inode);
872 872
873 dfprintk(PAGECACHE, "NFS: revalidating (%s/%Ld)\n", 873 dfprintk(PAGECACHE, "NFS: revalidating (%s/%Lu)\n",
874 inode->i_sb->s_id, (long long)NFS_FILEID(inode)); 874 inode->i_sb->s_id, (unsigned long long)NFS_FILEID(inode));
875 875
876 trace_nfs_revalidate_inode_enter(inode); 876 trace_nfs_revalidate_inode_enter(inode);
877 877
@@ -895,9 +895,9 @@ __nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
895 895
896 status = NFS_PROTO(inode)->getattr(server, NFS_FH(inode), fattr, label); 896 status = NFS_PROTO(inode)->getattr(server, NFS_FH(inode), fattr, label);
897 if (status != 0) { 897 if (status != 0) {
898 dfprintk(PAGECACHE, "nfs_revalidate_inode: (%s/%Ld) getattr failed, error=%d\n", 898 dfprintk(PAGECACHE, "nfs_revalidate_inode: (%s/%Lu) getattr failed, error=%d\n",
899 inode->i_sb->s_id, 899 inode->i_sb->s_id,
900 (long long)NFS_FILEID(inode), status); 900 (unsigned long long)NFS_FILEID(inode), status);
901 if (status == -ESTALE) { 901 if (status == -ESTALE) {
902 nfs_zap_caches(inode); 902 nfs_zap_caches(inode);
903 if (!S_ISDIR(inode->i_mode)) 903 if (!S_ISDIR(inode->i_mode))
@@ -908,9 +908,9 @@ __nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
908 908
909 status = nfs_refresh_inode(inode, fattr); 909 status = nfs_refresh_inode(inode, fattr);
910 if (status) { 910 if (status) {
911 dfprintk(PAGECACHE, "nfs_revalidate_inode: (%s/%Ld) refresh failed, error=%d\n", 911 dfprintk(PAGECACHE, "nfs_revalidate_inode: (%s/%Lu) refresh failed, error=%d\n",
912 inode->i_sb->s_id, 912 inode->i_sb->s_id,
913 (long long)NFS_FILEID(inode), status); 913 (unsigned long long)NFS_FILEID(inode), status);
914 goto err_out; 914 goto err_out;
915 } 915 }
916 916
@@ -919,9 +919,9 @@ __nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
919 919
920 nfs_setsecurity(inode, fattr, label); 920 nfs_setsecurity(inode, fattr, label);
921 921
922 dfprintk(PAGECACHE, "NFS: (%s/%Ld) revalidation complete\n", 922 dfprintk(PAGECACHE, "NFS: (%s/%Lu) revalidation complete\n",
923 inode->i_sb->s_id, 923 inode->i_sb->s_id,
924 (long long)NFS_FILEID(inode)); 924 (unsigned long long)NFS_FILEID(inode));
925 925
926err_out: 926err_out:
927 nfs4_label_free(label); 927 nfs4_label_free(label);
@@ -985,8 +985,9 @@ static int nfs_invalidate_mapping(struct inode *inode, struct address_space *map
985 nfs_inc_stats(inode, NFSIOS_DATAINVALIDATE); 985 nfs_inc_stats(inode, NFSIOS_DATAINVALIDATE);
986 nfs_fscache_wait_on_invalidate(inode); 986 nfs_fscache_wait_on_invalidate(inode);
987 987
988 dfprintk(PAGECACHE, "NFS: (%s/%Ld) data cache invalidated\n", 988 dfprintk(PAGECACHE, "NFS: (%s/%Lu) data cache invalidated\n",
989 inode->i_sb->s_id, (long long)NFS_FILEID(inode)); 989 inode->i_sb->s_id,
990 (unsigned long long)NFS_FILEID(inode));
990 return 0; 991 return 0;
991} 992}
992 993
@@ -1282,12 +1283,28 @@ static int nfs_inode_attrs_need_update(const struct inode *inode, const struct n
1282 ((long)nfsi->attr_gencount - (long)nfs_read_attr_generation_counter() > 0); 1283 ((long)nfsi->attr_gencount - (long)nfs_read_attr_generation_counter() > 0);
1283} 1284}
1284 1285
1286/*
1287 * Don't trust the change_attribute, mtime, ctime or size if
1288 * a pnfs LAYOUTCOMMIT is outstanding
1289 */
1290static void nfs_inode_attrs_handle_layoutcommit(struct inode *inode,
1291 struct nfs_fattr *fattr)
1292{
1293 if (pnfs_layoutcommit_outstanding(inode))
1294 fattr->valid &= ~(NFS_ATTR_FATTR_CHANGE |
1295 NFS_ATTR_FATTR_MTIME |
1296 NFS_ATTR_FATTR_CTIME |
1297 NFS_ATTR_FATTR_SIZE);
1298}
1299
1285static int nfs_refresh_inode_locked(struct inode *inode, struct nfs_fattr *fattr) 1300static int nfs_refresh_inode_locked(struct inode *inode, struct nfs_fattr *fattr)
1286{ 1301{
1287 int ret; 1302 int ret;
1288 1303
1289 trace_nfs_refresh_inode_enter(inode); 1304 trace_nfs_refresh_inode_enter(inode);
1290 1305
1306 nfs_inode_attrs_handle_layoutcommit(inode, fattr);
1307
1291 if (nfs_inode_attrs_need_update(inode, fattr)) 1308 if (nfs_inode_attrs_need_update(inode, fattr))
1292 ret = nfs_update_inode(inode, fattr); 1309 ret = nfs_update_inode(inode, fattr);
1293 else 1310 else
@@ -1434,7 +1451,7 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1434 unsigned long now = jiffies; 1451 unsigned long now = jiffies;
1435 unsigned long save_cache_validity; 1452 unsigned long save_cache_validity;
1436 1453
1437 dfprintk(VFS, "NFS: %s(%s/%ld fh_crc=0x%08x ct=%d info=0x%x)\n", 1454 dfprintk(VFS, "NFS: %s(%s/%lu fh_crc=0x%08x ct=%d info=0x%x)\n",
1438 __func__, inode->i_sb->s_id, inode->i_ino, 1455 __func__, inode->i_sb->s_id, inode->i_ino,
1439 nfs_display_fhandle_hash(NFS_FH(inode)), 1456 nfs_display_fhandle_hash(NFS_FH(inode)),
1440 atomic_read(&inode->i_count), fattr->valid); 1457 atomic_read(&inode->i_count), fattr->valid);
@@ -1455,7 +1472,7 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1455 /* 1472 /*
1456 * Big trouble! The inode has become a different object. 1473 * Big trouble! The inode has become a different object.
1457 */ 1474 */
1458 printk(KERN_DEBUG "NFS: %s: inode %ld mode changed, %07o to %07o\n", 1475 printk(KERN_DEBUG "NFS: %s: inode %lu mode changed, %07o to %07o\n",
1459 __func__, inode->i_ino, inode->i_mode, fattr->mode); 1476 __func__, inode->i_ino, inode->i_mode, fattr->mode);
1460 goto out_err; 1477 goto out_err;
1461 } 1478 }
@@ -1517,8 +1534,7 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1517 if (new_isize != cur_isize) { 1534 if (new_isize != cur_isize) {
1518 /* Do we perhaps have any outstanding writes, or has 1535 /* Do we perhaps have any outstanding writes, or has
1519 * the file grown beyond our last write? */ 1536 * the file grown beyond our last write? */
1520 if ((nfsi->npages == 0 && !test_bit(NFS_INO_LAYOUTCOMMIT, &nfsi->flags)) || 1537 if ((nfsi->npages == 0) || new_isize > cur_isize) {
1521 new_isize > cur_isize) {
1522 i_size_write(inode, new_isize); 1538 i_size_write(inode, new_isize);
1523 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; 1539 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA;
1524 } 1540 }
diff --git a/fs/nfs/nfs4client.c b/fs/nfs/nfs4client.c
index b4a160a405ce..73d4ecda1e36 100644
--- a/fs/nfs/nfs4client.c
+++ b/fs/nfs/nfs4client.c
@@ -10,6 +10,7 @@
10#include <linux/sunrpc/auth.h> 10#include <linux/sunrpc/auth.h>
11#include <linux/sunrpc/xprt.h> 11#include <linux/sunrpc/xprt.h>
12#include <linux/sunrpc/bc_xprt.h> 12#include <linux/sunrpc/bc_xprt.h>
13#include <linux/sunrpc/rpc_pipe_fs.h>
13#include "internal.h" 14#include "internal.h"
14#include "callback.h" 15#include "callback.h"
15#include "delegation.h" 16#include "delegation.h"
@@ -370,7 +371,11 @@ struct nfs_client *nfs4_init_client(struct nfs_client *clp,
370 __set_bit(NFS_CS_INFINITE_SLOTS, &clp->cl_flags); 371 __set_bit(NFS_CS_INFINITE_SLOTS, &clp->cl_flags);
371 __set_bit(NFS_CS_DISCRTRY, &clp->cl_flags); 372 __set_bit(NFS_CS_DISCRTRY, &clp->cl_flags);
372 __set_bit(NFS_CS_NO_RETRANS_TIMEOUT, &clp->cl_flags); 373 __set_bit(NFS_CS_NO_RETRANS_TIMEOUT, &clp->cl_flags);
373 error = nfs_create_rpc_client(clp, timeparms, RPC_AUTH_GSS_KRB5I); 374
375 error = -EINVAL;
376 if (gssd_running(clp->cl_net))
377 error = nfs_create_rpc_client(clp, timeparms,
378 RPC_AUTH_GSS_KRB5I);
374 if (error == -EINVAL) 379 if (error == -EINVAL)
375 error = nfs_create_rpc_client(clp, timeparms, RPC_AUTH_UNIX); 380 error = nfs_create_rpc_client(clp, timeparms, RPC_AUTH_UNIX);
376 if (error < 0) 381 if (error < 0)
@@ -409,13 +414,11 @@ struct nfs_client *nfs4_init_client(struct nfs_client *clp,
409 error = nfs4_discover_server_trunking(clp, &old); 414 error = nfs4_discover_server_trunking(clp, &old);
410 if (error < 0) 415 if (error < 0)
411 goto error; 416 goto error;
412 nfs_put_client(clp);
413 if (clp != old) {
414 clp->cl_preserve_clid = true;
415 clp = old;
416 }
417 417
418 return clp; 418 if (clp != old)
419 clp->cl_preserve_clid = true;
420 nfs_put_client(clp);
421 return old;
419 422
420error: 423error:
421 nfs_mark_client_ready(clp, error); 424 nfs_mark_client_ready(clp, error);
@@ -493,9 +496,10 @@ int nfs40_walk_client_list(struct nfs_client *new,
493 prev = pos; 496 prev = pos;
494 497
495 status = nfs_wait_client_init_complete(pos); 498 status = nfs_wait_client_init_complete(pos);
496 spin_lock(&nn->nfs_client_lock);
497 if (status < 0) 499 if (status < 0)
498 continue; 500 goto out;
501 status = -NFS4ERR_STALE_CLIENTID;
502 spin_lock(&nn->nfs_client_lock);
499 } 503 }
500 if (pos->cl_cons_state != NFS_CS_READY) 504 if (pos->cl_cons_state != NFS_CS_READY)
501 continue; 505 continue;
@@ -633,7 +637,8 @@ int nfs41_walk_client_list(struct nfs_client *new,
633 } 637 }
634 spin_lock(&nn->nfs_client_lock); 638 spin_lock(&nn->nfs_client_lock);
635 if (status < 0) 639 if (status < 0)
636 continue; 640 break;
641 status = -NFS4ERR_STALE_CLIENTID;
637 } 642 }
638 if (pos->cl_cons_state != NFS_CS_READY) 643 if (pos->cl_cons_state != NFS_CS_READY)
639 continue; 644 continue;
diff --git a/fs/nfs/nfs4filelayout.c b/fs/nfs/nfs4filelayout.c
index b86464ba25e1..03fd8be8c0c5 100644
--- a/fs/nfs/nfs4filelayout.c
+++ b/fs/nfs/nfs4filelayout.c
@@ -91,10 +91,10 @@ static void filelayout_reset_write(struct nfs_write_data *data)
91 91
92 if (!test_and_set_bit(NFS_IOHDR_REDO, &hdr->flags)) { 92 if (!test_and_set_bit(NFS_IOHDR_REDO, &hdr->flags)) {
93 dprintk("%s Reset task %5u for i/o through MDS " 93 dprintk("%s Reset task %5u for i/o through MDS "
94 "(req %s/%lld, %u bytes @ offset %llu)\n", __func__, 94 "(req %s/%llu, %u bytes @ offset %llu)\n", __func__,
95 data->task.tk_pid, 95 data->task.tk_pid,
96 hdr->inode->i_sb->s_id, 96 hdr->inode->i_sb->s_id,
97 (long long)NFS_FILEID(hdr->inode), 97 (unsigned long long)NFS_FILEID(hdr->inode),
98 data->args.count, 98 data->args.count,
99 (unsigned long long)data->args.offset); 99 (unsigned long long)data->args.offset);
100 100
@@ -112,10 +112,10 @@ static void filelayout_reset_read(struct nfs_read_data *data)
112 112
113 if (!test_and_set_bit(NFS_IOHDR_REDO, &hdr->flags)) { 113 if (!test_and_set_bit(NFS_IOHDR_REDO, &hdr->flags)) {
114 dprintk("%s Reset task %5u for i/o through MDS " 114 dprintk("%s Reset task %5u for i/o through MDS "
115 "(req %s/%lld, %u bytes @ offset %llu)\n", __func__, 115 "(req %s/%llu, %u bytes @ offset %llu)\n", __func__,
116 data->task.tk_pid, 116 data->task.tk_pid,
117 hdr->inode->i_sb->s_id, 117 hdr->inode->i_sb->s_id,
118 (long long)NFS_FILEID(hdr->inode), 118 (unsigned long long)NFS_FILEID(hdr->inode),
119 data->args.count, 119 data->args.count,
120 (unsigned long long)data->args.offset); 120 (unsigned long long)data->args.offset);
121 121
@@ -1216,17 +1216,17 @@ static void filelayout_recover_commit_reqs(struct list_head *dst,
1216 struct pnfs_commit_bucket *b; 1216 struct pnfs_commit_bucket *b;
1217 int i; 1217 int i;
1218 1218
1219 /* NOTE cinfo->lock is NOT held, relying on fact that this is 1219 spin_lock(cinfo->lock);
1220 * only called on single thread per dreq.
1221 * Can't take the lock because need to do pnfs_put_lseg
1222 */
1223 for (i = 0, b = cinfo->ds->buckets; i < cinfo->ds->nbuckets; i++, b++) { 1220 for (i = 0, b = cinfo->ds->buckets; i < cinfo->ds->nbuckets; i++, b++) {
1224 if (transfer_commit_list(&b->written, dst, cinfo, 0)) { 1221 if (transfer_commit_list(&b->written, dst, cinfo, 0)) {
1222 spin_unlock(cinfo->lock);
1225 pnfs_put_lseg(b->wlseg); 1223 pnfs_put_lseg(b->wlseg);
1226 b->wlseg = NULL; 1224 b->wlseg = NULL;
1225 spin_lock(cinfo->lock);
1227 } 1226 }
1228 } 1227 }
1229 cinfo->ds->nwritten = 0; 1228 cinfo->ds->nwritten = 0;
1229 spin_unlock(cinfo->lock);
1230} 1230}
1231 1231
1232static unsigned int 1232static unsigned int
diff --git a/fs/nfs/nfs4filelayoutdev.c b/fs/nfs/nfs4filelayoutdev.c
index c7c295e556ed..efac602edb37 100644
--- a/fs/nfs/nfs4filelayoutdev.c
+++ b/fs/nfs/nfs4filelayoutdev.c
@@ -95,7 +95,7 @@ same_sockaddr(struct sockaddr *addr1, struct sockaddr *addr2)
95 b6 = (struct sockaddr_in6 *)addr2; 95 b6 = (struct sockaddr_in6 *)addr2;
96 96
97 /* LINKLOCAL addresses must have matching scope_id */ 97 /* LINKLOCAL addresses must have matching scope_id */
98 if (ipv6_addr_scope(&a6->sin6_addr) == 98 if (ipv6_addr_src_scope(&a6->sin6_addr) ==
99 IPV6_ADDR_SCOPE_LINKLOCAL && 99 IPV6_ADDR_SCOPE_LINKLOCAL &&
100 a6->sin6_scope_id != b6->sin6_scope_id) 100 a6->sin6_scope_id != b6->sin6_scope_id)
101 return false; 101 return false;
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index 15052b81df42..a1965329a12c 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -7409,9 +7409,9 @@ static void nfs4_layoutget_done(struct rpc_task *task, void *calldata)
7409 struct nfs_server *server = NFS_SERVER(inode); 7409 struct nfs_server *server = NFS_SERVER(inode);
7410 struct pnfs_layout_hdr *lo; 7410 struct pnfs_layout_hdr *lo;
7411 struct nfs4_state *state = NULL; 7411 struct nfs4_state *state = NULL;
7412 unsigned long timeo, giveup; 7412 unsigned long timeo, now, giveup;
7413 7413
7414 dprintk("--> %s\n", __func__); 7414 dprintk("--> %s tk_status => %d\n", __func__, -task->tk_status);
7415 7415
7416 if (!nfs41_sequence_done(task, &lgp->res.seq_res)) 7416 if (!nfs41_sequence_done(task, &lgp->res.seq_res))
7417 goto out; 7417 goto out;
@@ -7419,12 +7419,38 @@ static void nfs4_layoutget_done(struct rpc_task *task, void *calldata)
7419 switch (task->tk_status) { 7419 switch (task->tk_status) {
7420 case 0: 7420 case 0:
7421 goto out; 7421 goto out;
7422 /*
7423 * NFS4ERR_LAYOUTTRYLATER is a conflict with another client
7424 * (or clients) writing to the same RAID stripe
7425 */
7422 case -NFS4ERR_LAYOUTTRYLATER: 7426 case -NFS4ERR_LAYOUTTRYLATER:
7427 /*
7428 * NFS4ERR_RECALLCONFLICT is when conflict with self (must recall
7429 * existing layout before getting a new one).
7430 */
7423 case -NFS4ERR_RECALLCONFLICT: 7431 case -NFS4ERR_RECALLCONFLICT:
7424 timeo = rpc_get_timeout(task->tk_client); 7432 timeo = rpc_get_timeout(task->tk_client);
7425 giveup = lgp->args.timestamp + timeo; 7433 giveup = lgp->args.timestamp + timeo;
7426 if (time_after(giveup, jiffies)) 7434 now = jiffies;
7427 task->tk_status = -NFS4ERR_DELAY; 7435 if (time_after(giveup, now)) {
7436 unsigned long delay;
7437
7438 /* Delay for:
7439 * - Not less then NFS4_POLL_RETRY_MIN.
7440 * - One last time a jiffie before we give up
7441 * - exponential backoff (time_now minus start_attempt)
7442 */
7443 delay = max_t(unsigned long, NFS4_POLL_RETRY_MIN,
7444 min((giveup - now - 1),
7445 now - lgp->args.timestamp));
7446
7447 dprintk("%s: NFS4ERR_RECALLCONFLICT waiting %lu\n",
7448 __func__, delay);
7449 rpc_delay(task, delay);
7450 task->tk_status = 0;
7451 rpc_restart_call_prepare(task);
7452 goto out; /* Do not call nfs4_async_handle_error() */
7453 }
7428 break; 7454 break;
7429 case -NFS4ERR_EXPIRED: 7455 case -NFS4ERR_EXPIRED:
7430 case -NFS4ERR_BAD_STATEID: 7456 case -NFS4ERR_BAD_STATEID:
@@ -7780,10 +7806,7 @@ nfs4_layoutcommit_done(struct rpc_task *task, void *calldata)
7780 case -NFS4ERR_BADLAYOUT: /* no layout */ 7806 case -NFS4ERR_BADLAYOUT: /* no layout */
7781 case -NFS4ERR_GRACE: /* loca_recalim always false */ 7807 case -NFS4ERR_GRACE: /* loca_recalim always false */
7782 task->tk_status = 0; 7808 task->tk_status = 0;
7783 break;
7784 case 0: 7809 case 0:
7785 nfs_post_op_update_inode_force_wcc(data->args.inode,
7786 data->res.fattr);
7787 break; 7810 break;
7788 default: 7811 default:
7789 if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { 7812 if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) {
@@ -7798,6 +7821,8 @@ static void nfs4_layoutcommit_release(void *calldata)
7798 struct nfs4_layoutcommit_data *data = calldata; 7821 struct nfs4_layoutcommit_data *data = calldata;
7799 7822
7800 pnfs_cleanup_layoutcommit(data); 7823 pnfs_cleanup_layoutcommit(data);
7824 nfs_post_op_update_inode_force_wcc(data->args.inode,
7825 data->res.fattr);
7801 put_rpccred(data->cred); 7826 put_rpccred(data->cred);
7802 kfree(data); 7827 kfree(data);
7803} 7828}
@@ -7920,7 +7945,7 @@ nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle,
7920 switch (err) { 7945 switch (err) {
7921 case 0: 7946 case 0:
7922 case -NFS4ERR_WRONGSEC: 7947 case -NFS4ERR_WRONGSEC:
7923 case -NFS4ERR_NOTSUPP: 7948 case -ENOTSUPP:
7924 goto out; 7949 goto out;
7925 default: 7950 default:
7926 err = nfs4_handle_exception(server, err, &exception); 7951 err = nfs4_handle_exception(server, err, &exception);
@@ -7954,7 +7979,7 @@ nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle,
7954 * Fall back on "guess and check" method if 7979 * Fall back on "guess and check" method if
7955 * the server doesn't support SECINFO_NO_NAME 7980 * the server doesn't support SECINFO_NO_NAME
7956 */ 7981 */
7957 if (err == -NFS4ERR_WRONGSEC || err == -NFS4ERR_NOTSUPP) { 7982 if (err == -NFS4ERR_WRONGSEC || err == -ENOTSUPP) {
7958 err = nfs4_find_root_sec(server, fhandle, info); 7983 err = nfs4_find_root_sec(server, fhandle, info);
7959 goto out_freepage; 7984 goto out_freepage;
7960 } 7985 }
diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c
index 059c01b67a71..e5be72518bd7 100644
--- a/fs/nfs/nfs4state.c
+++ b/fs/nfs/nfs4state.c
@@ -1071,7 +1071,7 @@ void nfs_free_seqid(struct nfs_seqid *seqid)
1071/* 1071/*
1072 * Increment the seqid if the OPEN/OPEN_DOWNGRADE/CLOSE succeeded, or 1072 * Increment the seqid if the OPEN/OPEN_DOWNGRADE/CLOSE succeeded, or
1073 * failed with a seqid incrementing error - 1073 * failed with a seqid incrementing error -
1074 * see comments nfs_fs.h:seqid_mutating_error() 1074 * see comments nfs4.h:seqid_mutating_error()
1075 */ 1075 */
1076static void nfs_increment_seqid(int status, struct nfs_seqid *seqid) 1076static void nfs_increment_seqid(int status, struct nfs_seqid *seqid)
1077{ 1077{
@@ -1116,7 +1116,7 @@ void nfs_increment_open_seqid(int status, struct nfs_seqid *seqid)
1116/* 1116/*
1117 * Increment the seqid if the LOCK/LOCKU succeeded, or 1117 * Increment the seqid if the LOCK/LOCKU succeeded, or
1118 * failed with a seqid incrementing error - 1118 * failed with a seqid incrementing error -
1119 * see comments nfs_fs.h:seqid_mutating_error() 1119 * see comments nfs4.h:seqid_mutating_error()
1120 */ 1120 */
1121void nfs_increment_lock_seqid(int status, struct nfs_seqid *seqid) 1121void nfs_increment_lock_seqid(int status, struct nfs_seqid *seqid)
1122{ 1122{
diff --git a/fs/nfs/nfs4super.c b/fs/nfs/nfs4super.c
index 65ab0a0ca1c4..808f29574412 100644
--- a/fs/nfs/nfs4super.c
+++ b/fs/nfs/nfs4super.c
@@ -77,17 +77,9 @@ static int nfs4_write_inode(struct inode *inode, struct writeback_control *wbc)
77{ 77{
78 int ret = nfs_write_inode(inode, wbc); 78 int ret = nfs_write_inode(inode, wbc);
79 79
80 if (ret >= 0 && test_bit(NFS_INO_LAYOUTCOMMIT, &NFS_I(inode)->flags)) { 80 if (ret == 0)
81 int status; 81 ret = pnfs_layoutcommit_inode(inode,
82 bool sync = true; 82 wbc->sync_mode == WB_SYNC_ALL);
83
84 if (wbc->sync_mode == WB_SYNC_NONE)
85 sync = false;
86
87 status = pnfs_layoutcommit_inode(inode, sync);
88 if (status < 0)
89 return status;
90 }
91 return ret; 83 return ret;
92} 84}
93 85
diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
index 5be2868c02f1..8c21d69a9dc1 100644
--- a/fs/nfs/nfs4xdr.c
+++ b/fs/nfs/nfs4xdr.c
@@ -3097,7 +3097,8 @@ out_overflow:
3097 return -EIO; 3097 return -EIO;
3098} 3098}
3099 3099
3100static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected) 3100static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
3101 int *nfs_retval)
3101{ 3102{
3102 __be32 *p; 3103 __be32 *p;
3103 uint32_t opnum; 3104 uint32_t opnum;
@@ -3107,19 +3108,32 @@ static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3107 if (unlikely(!p)) 3108 if (unlikely(!p))
3108 goto out_overflow; 3109 goto out_overflow;
3109 opnum = be32_to_cpup(p++); 3110 opnum = be32_to_cpup(p++);
3110 if (opnum != expected) { 3111 if (unlikely(opnum != expected))
3111 dprintk("nfs: Server returned operation" 3112 goto out_bad_operation;
3112 " %d but we issued a request for %d\n",
3113 opnum, expected);
3114 return -EIO;
3115 }
3116 nfserr = be32_to_cpup(p); 3113 nfserr = be32_to_cpup(p);
3117 if (nfserr != NFS_OK) 3114 if (nfserr == NFS_OK)
3118 return nfs4_stat_to_errno(nfserr); 3115 *nfs_retval = 0;
3119 return 0; 3116 else
3117 *nfs_retval = nfs4_stat_to_errno(nfserr);
3118 return true;
3119out_bad_operation:
3120 dprintk("nfs: Server returned operation"
3121 " %d but we issued a request for %d\n",
3122 opnum, expected);
3123 *nfs_retval = -EREMOTEIO;
3124 return false;
3120out_overflow: 3125out_overflow:
3121 print_overflow_msg(__func__, xdr); 3126 print_overflow_msg(__func__, xdr);
3122 return -EIO; 3127 *nfs_retval = -EIO;
3128 return false;
3129}
3130
3131static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3132{
3133 int retval;
3134
3135 __decode_op_hdr(xdr, expected, &retval);
3136 return retval;
3123} 3137}
3124 3138
3125/* Dummy routine */ 3139/* Dummy routine */
@@ -5001,11 +5015,12 @@ static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
5001 uint32_t savewords, bmlen, i; 5015 uint32_t savewords, bmlen, i;
5002 int status; 5016 int status;
5003 5017
5004 status = decode_op_hdr(xdr, OP_OPEN); 5018 if (!__decode_op_hdr(xdr, OP_OPEN, &status))
5005 if (status != -EIO) 5019 return status;
5006 nfs_increment_open_seqid(status, res->seqid); 5020 nfs_increment_open_seqid(status, res->seqid);
5007 if (!status) 5021 if (status)
5008 status = decode_stateid(xdr, &res->stateid); 5022 return status;
5023 status = decode_stateid(xdr, &res->stateid);
5009 if (unlikely(status)) 5024 if (unlikely(status))
5010 return status; 5025 return status;
5011 5026
diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c
index d75d938d36cb..4755858e37a0 100644
--- a/fs/nfs/pnfs.c
+++ b/fs/nfs/pnfs.c
@@ -1790,6 +1790,15 @@ pnfs_generic_pg_readpages(struct nfs_pageio_descriptor *desc)
1790} 1790}
1791EXPORT_SYMBOL_GPL(pnfs_generic_pg_readpages); 1791EXPORT_SYMBOL_GPL(pnfs_generic_pg_readpages);
1792 1792
1793static void pnfs_clear_layoutcommitting(struct inode *inode)
1794{
1795 unsigned long *bitlock = &NFS_I(inode)->flags;
1796
1797 clear_bit_unlock(NFS_INO_LAYOUTCOMMITTING, bitlock);
1798 smp_mb__after_clear_bit();
1799 wake_up_bit(bitlock, NFS_INO_LAYOUTCOMMITTING);
1800}
1801
1793/* 1802/*
1794 * There can be multiple RW segments. 1803 * There can be multiple RW segments.
1795 */ 1804 */
@@ -1807,7 +1816,6 @@ static void pnfs_list_write_lseg(struct inode *inode, struct list_head *listp)
1807static void pnfs_list_write_lseg_done(struct inode *inode, struct list_head *listp) 1816static void pnfs_list_write_lseg_done(struct inode *inode, struct list_head *listp)
1808{ 1817{
1809 struct pnfs_layout_segment *lseg, *tmp; 1818 struct pnfs_layout_segment *lseg, *tmp;
1810 unsigned long *bitlock = &NFS_I(inode)->flags;
1811 1819
1812 /* Matched by references in pnfs_set_layoutcommit */ 1820 /* Matched by references in pnfs_set_layoutcommit */
1813 list_for_each_entry_safe(lseg, tmp, listp, pls_lc_list) { 1821 list_for_each_entry_safe(lseg, tmp, listp, pls_lc_list) {
@@ -1815,9 +1823,7 @@ static void pnfs_list_write_lseg_done(struct inode *inode, struct list_head *lis
1815 pnfs_put_lseg(lseg); 1823 pnfs_put_lseg(lseg);
1816 } 1824 }
1817 1825
1818 clear_bit_unlock(NFS_INO_LAYOUTCOMMITTING, bitlock); 1826 pnfs_clear_layoutcommitting(inode);
1819 smp_mb__after_clear_bit();
1820 wake_up_bit(bitlock, NFS_INO_LAYOUTCOMMITTING);
1821} 1827}
1822 1828
1823void pnfs_set_lo_fail(struct pnfs_layout_segment *lseg) 1829void pnfs_set_lo_fail(struct pnfs_layout_segment *lseg)
@@ -1881,43 +1887,37 @@ pnfs_layoutcommit_inode(struct inode *inode, bool sync)
1881 struct nfs4_layoutcommit_data *data; 1887 struct nfs4_layoutcommit_data *data;
1882 struct nfs_inode *nfsi = NFS_I(inode); 1888 struct nfs_inode *nfsi = NFS_I(inode);
1883 loff_t end_pos; 1889 loff_t end_pos;
1884 int status = 0; 1890 int status;
1885 1891
1886 dprintk("--> %s inode %lu\n", __func__, inode->i_ino); 1892 if (!pnfs_layoutcommit_outstanding(inode))
1887
1888 if (!test_bit(NFS_INO_LAYOUTCOMMIT, &nfsi->flags))
1889 return 0; 1893 return 0;
1890 1894
1891 /* Note kzalloc ensures data->res.seq_res.sr_slot == NULL */ 1895 dprintk("--> %s inode %lu\n", __func__, inode->i_ino);
1892 data = kzalloc(sizeof(*data), GFP_NOFS);
1893 if (!data) {
1894 status = -ENOMEM;
1895 goto out;
1896 }
1897
1898 if (!test_bit(NFS_INO_LAYOUTCOMMIT, &nfsi->flags))
1899 goto out_free;
1900 1896
1897 status = -EAGAIN;
1901 if (test_and_set_bit(NFS_INO_LAYOUTCOMMITTING, &nfsi->flags)) { 1898 if (test_and_set_bit(NFS_INO_LAYOUTCOMMITTING, &nfsi->flags)) {
1902 if (!sync) { 1899 if (!sync)
1903 status = -EAGAIN; 1900 goto out;
1904 goto out_free; 1901 status = wait_on_bit_lock(&nfsi->flags,
1905 } 1902 NFS_INO_LAYOUTCOMMITTING,
1906 status = wait_on_bit_lock(&nfsi->flags, NFS_INO_LAYOUTCOMMITTING, 1903 nfs_wait_bit_killable,
1907 nfs_wait_bit_killable, TASK_KILLABLE); 1904 TASK_KILLABLE);
1908 if (status) 1905 if (status)
1909 goto out_free; 1906 goto out;
1910 } 1907 }
1911 1908
1912 INIT_LIST_HEAD(&data->lseg_list); 1909 status = -ENOMEM;
1910 /* Note kzalloc ensures data->res.seq_res.sr_slot == NULL */
1911 data = kzalloc(sizeof(*data), GFP_NOFS);
1912 if (!data)
1913 goto clear_layoutcommitting;
1914
1915 status = 0;
1913 spin_lock(&inode->i_lock); 1916 spin_lock(&inode->i_lock);
1914 if (!test_and_clear_bit(NFS_INO_LAYOUTCOMMIT, &nfsi->flags)) { 1917 if (!test_and_clear_bit(NFS_INO_LAYOUTCOMMIT, &nfsi->flags))
1915 clear_bit(NFS_INO_LAYOUTCOMMITTING, &nfsi->flags); 1918 goto out_unlock;
1916 spin_unlock(&inode->i_lock);
1917 wake_up_bit(&nfsi->flags, NFS_INO_LAYOUTCOMMITTING);
1918 goto out_free;
1919 }
1920 1919
1920 INIT_LIST_HEAD(&data->lseg_list);
1921 pnfs_list_write_lseg(inode, &data->lseg_list); 1921 pnfs_list_write_lseg(inode, &data->lseg_list);
1922 1922
1923 end_pos = nfsi->layout->plh_lwb; 1923 end_pos = nfsi->layout->plh_lwb;
@@ -1940,8 +1940,11 @@ out:
1940 mark_inode_dirty_sync(inode); 1940 mark_inode_dirty_sync(inode);
1941 dprintk("<-- %s status %d\n", __func__, status); 1941 dprintk("<-- %s status %d\n", __func__, status);
1942 return status; 1942 return status;
1943out_free: 1943out_unlock:
1944 spin_unlock(&inode->i_lock);
1944 kfree(data); 1945 kfree(data);
1946clear_layoutcommitting:
1947 pnfs_clear_layoutcommitting(inode);
1945 goto out; 1948 goto out;
1946} 1949}
1947 1950
diff --git a/fs/nfs/pnfs.h b/fs/nfs/pnfs.h
index a4f41810a7f4..023793909778 100644
--- a/fs/nfs/pnfs.h
+++ b/fs/nfs/pnfs.h
@@ -359,6 +359,15 @@ pnfs_ld_layoutret_on_setattr(struct inode *inode)
359 PNFS_LAYOUTRET_ON_SETATTR; 359 PNFS_LAYOUTRET_ON_SETATTR;
360} 360}
361 361
362static inline bool
363pnfs_layoutcommit_outstanding(struct inode *inode)
364{
365 struct nfs_inode *nfsi = NFS_I(inode);
366
367 return test_bit(NFS_INO_LAYOUTCOMMIT, &nfsi->flags) != 0 ||
368 test_bit(NFS_INO_LAYOUTCOMMITTING, &nfsi->flags) != 0;
369}
370
362static inline int pnfs_return_layout(struct inode *ino) 371static inline int pnfs_return_layout(struct inode *ino)
363{ 372{
364 struct nfs_inode *nfsi = NFS_I(ino); 373 struct nfs_inode *nfsi = NFS_I(ino);
@@ -515,6 +524,13 @@ pnfs_use_threshold(struct nfs4_threshold **dst, struct nfs4_threshold *src,
515 return false; 524 return false;
516} 525}
517 526
527static inline bool
528pnfs_layoutcommit_outstanding(struct inode *inode)
529{
530 return false;
531}
532
533
518static inline struct nfs4_threshold *pnfs_mdsthreshold_alloc(void) 534static inline struct nfs4_threshold *pnfs_mdsthreshold_alloc(void)
519{ 535{
520 return NULL; 536 return NULL;
diff --git a/fs/nfs/read.c b/fs/nfs/read.c
index 31db5c366b81..411aedda14bb 100644
--- a/fs/nfs/read.c
+++ b/fs/nfs/read.c
@@ -163,9 +163,9 @@ static void nfs_readpage_release(struct nfs_page *req)
163 163
164 unlock_page(req->wb_page); 164 unlock_page(req->wb_page);
165 165
166 dprintk("NFS: read done (%s/%Ld %d@%Ld)\n", 166 dprintk("NFS: read done (%s/%Lu %d@%Ld)\n",
167 req->wb_context->dentry->d_inode->i_sb->s_id, 167 req->wb_context->dentry->d_inode->i_sb->s_id,
168 (long long)NFS_FILEID(req->wb_context->dentry->d_inode), 168 (unsigned long long)NFS_FILEID(req->wb_context->dentry->d_inode),
169 req->wb_bytes, 169 req->wb_bytes,
170 (long long)req_offset(req)); 170 (long long)req_offset(req));
171 nfs_release_request(req); 171 nfs_release_request(req);
@@ -228,11 +228,11 @@ int nfs_initiate_read(struct rpc_clnt *clnt,
228 /* Set up the initial task struct. */ 228 /* Set up the initial task struct. */
229 NFS_PROTO(inode)->read_setup(data, &msg); 229 NFS_PROTO(inode)->read_setup(data, &msg);
230 230
231 dprintk("NFS: %5u initiated read call (req %s/%lld, %u bytes @ " 231 dprintk("NFS: %5u initiated read call (req %s/%llu, %u bytes @ "
232 "offset %llu)\n", 232 "offset %llu)\n",
233 data->task.tk_pid, 233 data->task.tk_pid,
234 inode->i_sb->s_id, 234 inode->i_sb->s_id,
235 (long long)NFS_FILEID(inode), 235 (unsigned long long)NFS_FILEID(inode),
236 data->args.count, 236 data->args.count,
237 (unsigned long long)data->args.offset); 237 (unsigned long long)data->args.offset);
238 238
@@ -630,9 +630,9 @@ int nfs_readpages(struct file *filp, struct address_space *mapping,
630 unsigned long npages; 630 unsigned long npages;
631 int ret = -ESTALE; 631 int ret = -ESTALE;
632 632
633 dprintk("NFS: nfs_readpages (%s/%Ld %d)\n", 633 dprintk("NFS: nfs_readpages (%s/%Lu %d)\n",
634 inode->i_sb->s_id, 634 inode->i_sb->s_id,
635 (long long)NFS_FILEID(inode), 635 (unsigned long long)NFS_FILEID(inode),
636 nr_pages); 636 nr_pages);
637 nfs_inc_stats(inode, NFSIOS_VFSREADPAGES); 637 nfs_inc_stats(inode, NFSIOS_VFSREADPAGES);
638 638
diff --git a/fs/nfs/write.c b/fs/nfs/write.c
index c1d548211c31..a44a87268a6e 100644
--- a/fs/nfs/write.c
+++ b/fs/nfs/write.c
@@ -922,19 +922,20 @@ out:
922 * extend the write to cover the entire page in order to avoid fragmentation 922 * extend the write to cover the entire page in order to avoid fragmentation
923 * inefficiencies. 923 * inefficiencies.
924 * 924 *
925 * If the file is opened for synchronous writes or if we have a write delegation 925 * If the file is opened for synchronous writes then we can just skip the rest
926 * from the server then we can just skip the rest of the checks. 926 * of the checks.
927 */ 927 */
928static int nfs_can_extend_write(struct file *file, struct page *page, struct inode *inode) 928static int nfs_can_extend_write(struct file *file, struct page *page, struct inode *inode)
929{ 929{
930 if (file->f_flags & O_DSYNC) 930 if (file->f_flags & O_DSYNC)
931 return 0; 931 return 0;
932 if (!nfs_write_pageuptodate(page, inode))
933 return 0;
932 if (NFS_PROTO(inode)->have_delegation(inode, FMODE_WRITE)) 934 if (NFS_PROTO(inode)->have_delegation(inode, FMODE_WRITE))
933 return 1; 935 return 1;
934 if (nfs_write_pageuptodate(page, inode) && (inode->i_flock == NULL || 936 if (inode->i_flock == NULL || (inode->i_flock->fl_start == 0 &&
935 (inode->i_flock->fl_start == 0 &&
936 inode->i_flock->fl_end == OFFSET_MAX && 937 inode->i_flock->fl_end == OFFSET_MAX &&
937 inode->i_flock->fl_type != F_RDLCK))) 938 inode->i_flock->fl_type != F_RDLCK))
938 return 1; 939 return 1;
939 return 0; 940 return 0;
940} 941}
@@ -1013,10 +1014,10 @@ int nfs_initiate_write(struct rpc_clnt *clnt,
1013 NFS_PROTO(inode)->write_setup(data, &msg); 1014 NFS_PROTO(inode)->write_setup(data, &msg);
1014 1015
1015 dprintk("NFS: %5u initiated write call " 1016 dprintk("NFS: %5u initiated write call "
1016 "(req %s/%lld, %u bytes @ offset %llu)\n", 1017 "(req %s/%llu, %u bytes @ offset %llu)\n",
1017 data->task.tk_pid, 1018 data->task.tk_pid,
1018 inode->i_sb->s_id, 1019 inode->i_sb->s_id,
1019 (long long)NFS_FILEID(inode), 1020 (unsigned long long)NFS_FILEID(inode),
1020 data->args.count, 1021 data->args.count,
1021 (unsigned long long)data->args.offset); 1022 (unsigned long long)data->args.offset);
1022 1023
@@ -1606,9 +1607,9 @@ static void nfs_commit_release_pages(struct nfs_commit_data *data)
1606 nfs_list_remove_request(req); 1607 nfs_list_remove_request(req);
1607 nfs_clear_page_commit(req->wb_page); 1608 nfs_clear_page_commit(req->wb_page);
1608 1609
1609 dprintk("NFS: commit (%s/%lld %d@%lld)", 1610 dprintk("NFS: commit (%s/%llu %d@%lld)",
1610 req->wb_context->dentry->d_sb->s_id, 1611 req->wb_context->dentry->d_sb->s_id,
1611 (long long)NFS_FILEID(req->wb_context->dentry->d_inode), 1612 (unsigned long long)NFS_FILEID(req->wb_context->dentry->d_inode),
1612 req->wb_bytes, 1613 req->wb_bytes,
1613 (long long)req_offset(req)); 1614 (long long)req_offset(req));
1614 if (status < 0) { 1615 if (status < 0) {