diff options
Diffstat (limited to 'fs/nfs')
-rw-r--r-- | fs/nfs/direct.c | 2 | ||||
-rw-r--r-- | fs/nfs/inode.c | 76 | ||||
-rw-r--r-- | fs/nfs/internal.h | 1 | ||||
-rw-r--r-- | fs/nfs/nfs3acl.c | 43 | ||||
-rw-r--r-- | fs/nfs/nfs3proc.c | 4 | ||||
-rw-r--r-- | fs/nfs/nfs4_fs.h | 2 | ||||
-rw-r--r-- | fs/nfs/nfs4namespace.c | 102 | ||||
-rw-r--r-- | fs/nfs/nfs4proc.c | 2 | ||||
-rw-r--r-- | fs/nfs/pagelist.c | 20 | ||||
-rw-r--r-- | fs/nfs/write.c | 339 |
10 files changed, 446 insertions, 145 deletions
diff --git a/fs/nfs/direct.c b/fs/nfs/direct.c index 8f98138cbc43..f11b9eed0de1 100644 --- a/fs/nfs/direct.c +++ b/fs/nfs/direct.c | |||
@@ -756,7 +756,6 @@ static void nfs_direct_write_completion(struct nfs_pgio_header *hdr) | |||
756 | spin_unlock(&dreq->lock); | 756 | spin_unlock(&dreq->lock); |
757 | 757 | ||
758 | while (!list_empty(&hdr->pages)) { | 758 | while (!list_empty(&hdr->pages)) { |
759 | bool do_destroy = true; | ||
760 | 759 | ||
761 | req = nfs_list_entry(hdr->pages.next); | 760 | req = nfs_list_entry(hdr->pages.next); |
762 | nfs_list_remove_request(req); | 761 | nfs_list_remove_request(req); |
@@ -765,7 +764,6 @@ static void nfs_direct_write_completion(struct nfs_pgio_header *hdr) | |||
765 | case NFS_IOHDR_NEED_COMMIT: | 764 | case NFS_IOHDR_NEED_COMMIT: |
766 | kref_get(&req->wb_kref); | 765 | kref_get(&req->wb_kref); |
767 | nfs_mark_request_commit(req, hdr->lseg, &cinfo); | 766 | nfs_mark_request_commit(req, hdr->lseg, &cinfo); |
768 | do_destroy = false; | ||
769 | } | 767 | } |
770 | nfs_unlock_and_release_request(req); | 768 | nfs_unlock_and_release_request(req); |
771 | } | 769 | } |
diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c index c496f8a74639..9927913c97c2 100644 --- a/fs/nfs/inode.c +++ b/fs/nfs/inode.c | |||
@@ -147,6 +147,17 @@ int nfs_sync_mapping(struct address_space *mapping) | |||
147 | return ret; | 147 | return ret; |
148 | } | 148 | } |
149 | 149 | ||
150 | static void nfs_set_cache_invalid(struct inode *inode, unsigned long flags) | ||
151 | { | ||
152 | struct nfs_inode *nfsi = NFS_I(inode); | ||
153 | |||
154 | if (inode->i_mapping->nrpages == 0) | ||
155 | flags &= ~NFS_INO_INVALID_DATA; | ||
156 | nfsi->cache_validity |= flags; | ||
157 | if (flags & NFS_INO_INVALID_DATA) | ||
158 | nfs_fscache_invalidate(inode); | ||
159 | } | ||
160 | |||
150 | /* | 161 | /* |
151 | * Invalidate the local caches | 162 | * Invalidate the local caches |
152 | */ | 163 | */ |
@@ -162,17 +173,16 @@ static void nfs_zap_caches_locked(struct inode *inode) | |||
162 | 173 | ||
163 | memset(NFS_I(inode)->cookieverf, 0, sizeof(NFS_I(inode)->cookieverf)); | 174 | memset(NFS_I(inode)->cookieverf, 0, sizeof(NFS_I(inode)->cookieverf)); |
164 | if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)) { | 175 | if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)) { |
165 | nfs_fscache_invalidate(inode); | 176 | nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR |
166 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR | ||
167 | | NFS_INO_INVALID_DATA | 177 | | NFS_INO_INVALID_DATA |
168 | | NFS_INO_INVALID_ACCESS | 178 | | NFS_INO_INVALID_ACCESS |
169 | | NFS_INO_INVALID_ACL | 179 | | NFS_INO_INVALID_ACL |
170 | | NFS_INO_REVAL_PAGECACHE; | 180 | | NFS_INO_REVAL_PAGECACHE); |
171 | } else | 181 | } else |
172 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR | 182 | nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR |
173 | | NFS_INO_INVALID_ACCESS | 183 | | NFS_INO_INVALID_ACCESS |
174 | | NFS_INO_INVALID_ACL | 184 | | NFS_INO_INVALID_ACL |
175 | | NFS_INO_REVAL_PAGECACHE; | 185 | | NFS_INO_REVAL_PAGECACHE); |
176 | nfs_zap_label_cache_locked(nfsi); | 186 | nfs_zap_label_cache_locked(nfsi); |
177 | } | 187 | } |
178 | 188 | ||
@@ -187,8 +197,7 @@ void nfs_zap_mapping(struct inode *inode, struct address_space *mapping) | |||
187 | { | 197 | { |
188 | if (mapping->nrpages != 0) { | 198 | if (mapping->nrpages != 0) { |
189 | spin_lock(&inode->i_lock); | 199 | spin_lock(&inode->i_lock); |
190 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_DATA; | 200 | nfs_set_cache_invalid(inode, NFS_INO_INVALID_DATA); |
191 | nfs_fscache_invalidate(inode); | ||
192 | spin_unlock(&inode->i_lock); | 201 | spin_unlock(&inode->i_lock); |
193 | } | 202 | } |
194 | } | 203 | } |
@@ -209,7 +218,7 @@ EXPORT_SYMBOL_GPL(nfs_zap_acl_cache); | |||
209 | void nfs_invalidate_atime(struct inode *inode) | 218 | void nfs_invalidate_atime(struct inode *inode) |
210 | { | 219 | { |
211 | spin_lock(&inode->i_lock); | 220 | spin_lock(&inode->i_lock); |
212 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATIME; | 221 | nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATIME); |
213 | spin_unlock(&inode->i_lock); | 222 | spin_unlock(&inode->i_lock); |
214 | } | 223 | } |
215 | EXPORT_SYMBOL_GPL(nfs_invalidate_atime); | 224 | EXPORT_SYMBOL_GPL(nfs_invalidate_atime); |
@@ -369,7 +378,7 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr, st | |||
369 | inode->i_mode = fattr->mode; | 378 | inode->i_mode = fattr->mode; |
370 | if ((fattr->valid & NFS_ATTR_FATTR_MODE) == 0 | 379 | if ((fattr->valid & NFS_ATTR_FATTR_MODE) == 0 |
371 | && nfs_server_capable(inode, NFS_CAP_MODE)) | 380 | && nfs_server_capable(inode, NFS_CAP_MODE)) |
372 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR; | 381 | nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR); |
373 | /* Why so? Because we want revalidate for devices/FIFOs, and | 382 | /* Why so? Because we want revalidate for devices/FIFOs, and |
374 | * that's precisely what we have in nfs_file_inode_operations. | 383 | * that's precisely what we have in nfs_file_inode_operations. |
375 | */ | 384 | */ |
@@ -415,36 +424,36 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr, st | |||
415 | if (fattr->valid & NFS_ATTR_FATTR_ATIME) | 424 | if (fattr->valid & NFS_ATTR_FATTR_ATIME) |
416 | inode->i_atime = fattr->atime; | 425 | inode->i_atime = fattr->atime; |
417 | else if (nfs_server_capable(inode, NFS_CAP_ATIME)) | 426 | else if (nfs_server_capable(inode, NFS_CAP_ATIME)) |
418 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR; | 427 | nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR); |
419 | if (fattr->valid & NFS_ATTR_FATTR_MTIME) | 428 | if (fattr->valid & NFS_ATTR_FATTR_MTIME) |
420 | inode->i_mtime = fattr->mtime; | 429 | inode->i_mtime = fattr->mtime; |
421 | else if (nfs_server_capable(inode, NFS_CAP_MTIME)) | 430 | else if (nfs_server_capable(inode, NFS_CAP_MTIME)) |
422 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR; | 431 | nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR); |
423 | if (fattr->valid & NFS_ATTR_FATTR_CTIME) | 432 | if (fattr->valid & NFS_ATTR_FATTR_CTIME) |
424 | inode->i_ctime = fattr->ctime; | 433 | inode->i_ctime = fattr->ctime; |
425 | else if (nfs_server_capable(inode, NFS_CAP_CTIME)) | 434 | else if (nfs_server_capable(inode, NFS_CAP_CTIME)) |
426 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR; | 435 | nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR); |
427 | if (fattr->valid & NFS_ATTR_FATTR_CHANGE) | 436 | if (fattr->valid & NFS_ATTR_FATTR_CHANGE) |
428 | inode->i_version = fattr->change_attr; | 437 | inode->i_version = fattr->change_attr; |
429 | else if (nfs_server_capable(inode, NFS_CAP_CHANGE_ATTR)) | 438 | else if (nfs_server_capable(inode, NFS_CAP_CHANGE_ATTR)) |
430 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR; | 439 | nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR); |
431 | if (fattr->valid & NFS_ATTR_FATTR_SIZE) | 440 | if (fattr->valid & NFS_ATTR_FATTR_SIZE) |
432 | inode->i_size = nfs_size_to_loff_t(fattr->size); | 441 | inode->i_size = nfs_size_to_loff_t(fattr->size); |
433 | else | 442 | else |
434 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR | 443 | nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR |
435 | | NFS_INO_REVAL_PAGECACHE; | 444 | | NFS_INO_REVAL_PAGECACHE); |
436 | if (fattr->valid & NFS_ATTR_FATTR_NLINK) | 445 | if (fattr->valid & NFS_ATTR_FATTR_NLINK) |
437 | set_nlink(inode, fattr->nlink); | 446 | set_nlink(inode, fattr->nlink); |
438 | else if (nfs_server_capable(inode, NFS_CAP_NLINK)) | 447 | else if (nfs_server_capable(inode, NFS_CAP_NLINK)) |
439 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR; | 448 | nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR); |
440 | if (fattr->valid & NFS_ATTR_FATTR_OWNER) | 449 | if (fattr->valid & NFS_ATTR_FATTR_OWNER) |
441 | inode->i_uid = fattr->uid; | 450 | inode->i_uid = fattr->uid; |
442 | else if (nfs_server_capable(inode, NFS_CAP_OWNER)) | 451 | else if (nfs_server_capable(inode, NFS_CAP_OWNER)) |
443 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR; | 452 | nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR); |
444 | if (fattr->valid & NFS_ATTR_FATTR_GROUP) | 453 | if (fattr->valid & NFS_ATTR_FATTR_GROUP) |
445 | inode->i_gid = fattr->gid; | 454 | inode->i_gid = fattr->gid; |
446 | else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP)) | 455 | else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP)) |
447 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR; | 456 | nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR); |
448 | if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED) | 457 | if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED) |
449 | inode->i_blocks = fattr->du.nfs2.blocks; | 458 | inode->i_blocks = fattr->du.nfs2.blocks; |
450 | if (fattr->valid & NFS_ATTR_FATTR_SPACE_USED) { | 459 | if (fattr->valid & NFS_ATTR_FATTR_SPACE_USED) { |
@@ -550,6 +559,9 @@ static int nfs_vmtruncate(struct inode * inode, loff_t offset) | |||
550 | 559 | ||
551 | spin_lock(&inode->i_lock); | 560 | spin_lock(&inode->i_lock); |
552 | i_size_write(inode, offset); | 561 | i_size_write(inode, offset); |
562 | /* Optimisation */ | ||
563 | if (offset == 0) | ||
564 | NFS_I(inode)->cache_validity &= ~NFS_INO_INVALID_DATA; | ||
553 | spin_unlock(&inode->i_lock); | 565 | spin_unlock(&inode->i_lock); |
554 | 566 | ||
555 | truncate_pagecache(inode, offset); | 567 | truncate_pagecache(inode, offset); |
@@ -578,7 +590,8 @@ void nfs_setattr_update_inode(struct inode *inode, struct iattr *attr) | |||
578 | inode->i_uid = attr->ia_uid; | 590 | inode->i_uid = attr->ia_uid; |
579 | if ((attr->ia_valid & ATTR_GID) != 0) | 591 | if ((attr->ia_valid & ATTR_GID) != 0) |
580 | inode->i_gid = attr->ia_gid; | 592 | inode->i_gid = attr->ia_gid; |
581 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL; | 593 | nfs_set_cache_invalid(inode, NFS_INO_INVALID_ACCESS |
594 | | NFS_INO_INVALID_ACL); | ||
582 | spin_unlock(&inode->i_lock); | 595 | spin_unlock(&inode->i_lock); |
583 | } | 596 | } |
584 | if ((attr->ia_valid & ATTR_SIZE) != 0) { | 597 | if ((attr->ia_valid & ATTR_SIZE) != 0) { |
@@ -1101,7 +1114,7 @@ static unsigned long nfs_wcc_update_inode(struct inode *inode, struct nfs_fattr | |||
1101 | && inode->i_version == fattr->pre_change_attr) { | 1114 | && inode->i_version == fattr->pre_change_attr) { |
1102 | inode->i_version = fattr->change_attr; | 1115 | inode->i_version = fattr->change_attr; |
1103 | if (S_ISDIR(inode->i_mode)) | 1116 | if (S_ISDIR(inode->i_mode)) |
1104 | nfsi->cache_validity |= NFS_INO_INVALID_DATA; | 1117 | nfs_set_cache_invalid(inode, NFS_INO_INVALID_DATA); |
1105 | ret |= NFS_INO_INVALID_ATTR; | 1118 | ret |= NFS_INO_INVALID_ATTR; |
1106 | } | 1119 | } |
1107 | /* If we have atomic WCC data, we may update some attributes */ | 1120 | /* If we have atomic WCC data, we may update some attributes */ |
@@ -1117,7 +1130,7 @@ static unsigned long nfs_wcc_update_inode(struct inode *inode, struct nfs_fattr | |||
1117 | && timespec_equal(&inode->i_mtime, &fattr->pre_mtime)) { | 1130 | && timespec_equal(&inode->i_mtime, &fattr->pre_mtime)) { |
1118 | memcpy(&inode->i_mtime, &fattr->mtime, sizeof(inode->i_mtime)); | 1131 | memcpy(&inode->i_mtime, &fattr->mtime, sizeof(inode->i_mtime)); |
1119 | if (S_ISDIR(inode->i_mode)) | 1132 | if (S_ISDIR(inode->i_mode)) |
1120 | nfsi->cache_validity |= NFS_INO_INVALID_DATA; | 1133 | nfs_set_cache_invalid(inode, NFS_INO_INVALID_DATA); |
1121 | ret |= NFS_INO_INVALID_ATTR; | 1134 | ret |= NFS_INO_INVALID_ATTR; |
1122 | } | 1135 | } |
1123 | if ((fattr->valid & NFS_ATTR_FATTR_PRESIZE) | 1136 | if ((fattr->valid & NFS_ATTR_FATTR_PRESIZE) |
@@ -1128,9 +1141,6 @@ static unsigned long nfs_wcc_update_inode(struct inode *inode, struct nfs_fattr | |||
1128 | ret |= NFS_INO_INVALID_ATTR; | 1141 | ret |= NFS_INO_INVALID_ATTR; |
1129 | } | 1142 | } |
1130 | 1143 | ||
1131 | if (nfsi->cache_validity & NFS_INO_INVALID_DATA) | ||
1132 | nfs_fscache_invalidate(inode); | ||
1133 | |||
1134 | return ret; | 1144 | return ret; |
1135 | } | 1145 | } |
1136 | 1146 | ||
@@ -1189,7 +1199,7 @@ static int nfs_check_inode_attributes(struct inode *inode, struct nfs_fattr *fat | |||
1189 | invalid |= NFS_INO_INVALID_ATIME; | 1199 | invalid |= NFS_INO_INVALID_ATIME; |
1190 | 1200 | ||
1191 | if (invalid != 0) | 1201 | if (invalid != 0) |
1192 | nfsi->cache_validity |= invalid; | 1202 | nfs_set_cache_invalid(inode, invalid); |
1193 | 1203 | ||
1194 | nfsi->read_cache_jiffies = fattr->time_start; | 1204 | nfsi->read_cache_jiffies = fattr->time_start; |
1195 | return 0; | 1205 | return 0; |
@@ -1402,13 +1412,11 @@ EXPORT_SYMBOL_GPL(nfs_refresh_inode); | |||
1402 | 1412 | ||
1403 | static int nfs_post_op_update_inode_locked(struct inode *inode, struct nfs_fattr *fattr) | 1413 | static int nfs_post_op_update_inode_locked(struct inode *inode, struct nfs_fattr *fattr) |
1404 | { | 1414 | { |
1405 | struct nfs_inode *nfsi = NFS_I(inode); | 1415 | unsigned long invalid = NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE; |
1406 | 1416 | ||
1407 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE; | 1417 | if (S_ISDIR(inode->i_mode)) |
1408 | if (S_ISDIR(inode->i_mode)) { | 1418 | invalid |= NFS_INO_INVALID_DATA; |
1409 | nfsi->cache_validity |= NFS_INO_INVALID_DATA; | 1419 | nfs_set_cache_invalid(inode, invalid); |
1410 | nfs_fscache_invalidate(inode); | ||
1411 | } | ||
1412 | if ((fattr->valid & NFS_ATTR_FATTR) == 0) | 1420 | if ((fattr->valid & NFS_ATTR_FATTR) == 0) |
1413 | return 0; | 1421 | return 0; |
1414 | return nfs_refresh_inode_locked(inode, fattr); | 1422 | return nfs_refresh_inode_locked(inode, fattr); |
@@ -1601,6 +1609,7 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr) | |||
1601 | if ((nfsi->npages == 0) || new_isize > cur_isize) { | 1609 | if ((nfsi->npages == 0) || new_isize > cur_isize) { |
1602 | i_size_write(inode, new_isize); | 1610 | i_size_write(inode, new_isize); |
1603 | invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; | 1611 | invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
1612 | invalid &= ~NFS_INO_REVAL_PAGECACHE; | ||
1604 | } | 1613 | } |
1605 | dprintk("NFS: isize change on server for file %s/%ld " | 1614 | dprintk("NFS: isize change on server for file %s/%ld " |
1606 | "(%Ld to %Ld)\n", | 1615 | "(%Ld to %Ld)\n", |
@@ -1702,10 +1711,7 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr) | |||
1702 | invalid &= ~NFS_INO_INVALID_DATA; | 1711 | invalid &= ~NFS_INO_INVALID_DATA; |
1703 | if (!NFS_PROTO(inode)->have_delegation(inode, FMODE_READ) || | 1712 | if (!NFS_PROTO(inode)->have_delegation(inode, FMODE_READ) || |
1704 | (save_cache_validity & NFS_INO_REVAL_FORCED)) | 1713 | (save_cache_validity & NFS_INO_REVAL_FORCED)) |
1705 | nfsi->cache_validity |= invalid; | 1714 | nfs_set_cache_invalid(inode, invalid); |
1706 | |||
1707 | if (invalid & NFS_INO_INVALID_DATA) | ||
1708 | nfs_fscache_invalidate(inode); | ||
1709 | 1715 | ||
1710 | return 0; | 1716 | return 0; |
1711 | out_err: | 1717 | out_err: |
diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h index 82ddbf46660e..f415cbf9f6c3 100644 --- a/fs/nfs/internal.h +++ b/fs/nfs/internal.h | |||
@@ -244,6 +244,7 @@ void nfs_pgio_data_release(struct nfs_pgio_data *); | |||
244 | int nfs_generic_pgio(struct nfs_pageio_descriptor *, struct nfs_pgio_header *); | 244 | int nfs_generic_pgio(struct nfs_pageio_descriptor *, struct nfs_pgio_header *); |
245 | int nfs_initiate_pgio(struct rpc_clnt *, struct nfs_pgio_data *, | 245 | int nfs_initiate_pgio(struct rpc_clnt *, struct nfs_pgio_data *, |
246 | const struct rpc_call_ops *, int, int); | 246 | const struct rpc_call_ops *, int, int); |
247 | void nfs_free_request(struct nfs_page *req); | ||
247 | 248 | ||
248 | static inline void nfs_iocounter_init(struct nfs_io_counter *c) | 249 | static inline void nfs_iocounter_init(struct nfs_io_counter *c) |
249 | { | 250 | { |
diff --git a/fs/nfs/nfs3acl.c b/fs/nfs/nfs3acl.c index 871d6eda8dba..8f854dde4150 100644 --- a/fs/nfs/nfs3acl.c +++ b/fs/nfs/nfs3acl.c | |||
@@ -247,3 +247,46 @@ const struct xattr_handler *nfs3_xattr_handlers[] = { | |||
247 | &posix_acl_default_xattr_handler, | 247 | &posix_acl_default_xattr_handler, |
248 | NULL, | 248 | NULL, |
249 | }; | 249 | }; |
250 | |||
251 | static int | ||
252 | nfs3_list_one_acl(struct inode *inode, int type, const char *name, void *data, | ||
253 | size_t size, ssize_t *result) | ||
254 | { | ||
255 | struct posix_acl *acl; | ||
256 | char *p = data + *result; | ||
257 | |||
258 | acl = get_acl(inode, type); | ||
259 | if (!acl) | ||
260 | return 0; | ||
261 | |||
262 | posix_acl_release(acl); | ||
263 | |||
264 | *result += strlen(name); | ||
265 | *result += 1; | ||
266 | if (!size) | ||
267 | return 0; | ||
268 | if (*result > size) | ||
269 | return -ERANGE; | ||
270 | |||
271 | strcpy(p, name); | ||
272 | return 0; | ||
273 | } | ||
274 | |||
275 | ssize_t | ||
276 | nfs3_listxattr(struct dentry *dentry, char *data, size_t size) | ||
277 | { | ||
278 | struct inode *inode = dentry->d_inode; | ||
279 | ssize_t result = 0; | ||
280 | int error; | ||
281 | |||
282 | error = nfs3_list_one_acl(inode, ACL_TYPE_ACCESS, | ||
283 | POSIX_ACL_XATTR_ACCESS, data, size, &result); | ||
284 | if (error) | ||
285 | return error; | ||
286 | |||
287 | error = nfs3_list_one_acl(inode, ACL_TYPE_DEFAULT, | ||
288 | POSIX_ACL_XATTR_DEFAULT, data, size, &result); | ||
289 | if (error) | ||
290 | return error; | ||
291 | return result; | ||
292 | } | ||
diff --git a/fs/nfs/nfs3proc.c b/fs/nfs/nfs3proc.c index e7daa42bbc86..f0afa291fd58 100644 --- a/fs/nfs/nfs3proc.c +++ b/fs/nfs/nfs3proc.c | |||
@@ -885,7 +885,7 @@ static const struct inode_operations nfs3_dir_inode_operations = { | |||
885 | .getattr = nfs_getattr, | 885 | .getattr = nfs_getattr, |
886 | .setattr = nfs_setattr, | 886 | .setattr = nfs_setattr, |
887 | #ifdef CONFIG_NFS_V3_ACL | 887 | #ifdef CONFIG_NFS_V3_ACL |
888 | .listxattr = generic_listxattr, | 888 | .listxattr = nfs3_listxattr, |
889 | .getxattr = generic_getxattr, | 889 | .getxattr = generic_getxattr, |
890 | .setxattr = generic_setxattr, | 890 | .setxattr = generic_setxattr, |
891 | .removexattr = generic_removexattr, | 891 | .removexattr = generic_removexattr, |
@@ -899,7 +899,7 @@ static const struct inode_operations nfs3_file_inode_operations = { | |||
899 | .getattr = nfs_getattr, | 899 | .getattr = nfs_getattr, |
900 | .setattr = nfs_setattr, | 900 | .setattr = nfs_setattr, |
901 | #ifdef CONFIG_NFS_V3_ACL | 901 | #ifdef CONFIG_NFS_V3_ACL |
902 | .listxattr = generic_listxattr, | 902 | .listxattr = nfs3_listxattr, |
903 | .getxattr = generic_getxattr, | 903 | .getxattr = generic_getxattr, |
904 | .setxattr = generic_setxattr, | 904 | .setxattr = generic_setxattr, |
905 | .removexattr = generic_removexattr, | 905 | .removexattr = generic_removexattr, |
diff --git a/fs/nfs/nfs4_fs.h b/fs/nfs/nfs4_fs.h index f63cb87cd730..ba2affa51941 100644 --- a/fs/nfs/nfs4_fs.h +++ b/fs/nfs/nfs4_fs.h | |||
@@ -230,7 +230,7 @@ int nfs_atomic_open(struct inode *, struct dentry *, struct file *, | |||
230 | extern struct file_system_type nfs4_fs_type; | 230 | extern struct file_system_type nfs4_fs_type; |
231 | 231 | ||
232 | /* nfs4namespace.c */ | 232 | /* nfs4namespace.c */ |
233 | struct rpc_clnt *nfs4_create_sec_client(struct rpc_clnt *, struct inode *, struct qstr *); | 233 | struct rpc_clnt *nfs4_negotiate_security(struct rpc_clnt *, struct inode *, struct qstr *); |
234 | struct vfsmount *nfs4_submount(struct nfs_server *, struct dentry *, | 234 | struct vfsmount *nfs4_submount(struct nfs_server *, struct dentry *, |
235 | struct nfs_fh *, struct nfs_fattr *); | 235 | struct nfs_fh *, struct nfs_fattr *); |
236 | int nfs4_replace_transport(struct nfs_server *server, | 236 | int nfs4_replace_transport(struct nfs_server *server, |
diff --git a/fs/nfs/nfs4namespace.c b/fs/nfs/nfs4namespace.c index 3d5dbf80d46a..3d83cb1fdc70 100644 --- a/fs/nfs/nfs4namespace.c +++ b/fs/nfs/nfs4namespace.c | |||
@@ -139,16 +139,22 @@ static size_t nfs_parse_server_name(char *string, size_t len, | |||
139 | * @server: NFS server struct | 139 | * @server: NFS server struct |
140 | * @flavors: List of security tuples returned by SECINFO procedure | 140 | * @flavors: List of security tuples returned by SECINFO procedure |
141 | * | 141 | * |
142 | * Return the pseudoflavor of the first security mechanism in | 142 | * Return an rpc client that uses the first security mechanism in |
143 | * "flavors" that is locally supported. Return RPC_AUTH_UNIX if | 143 | * "flavors" that is locally supported. The "flavors" array |
144 | * no matching flavor is found in the array. The "flavors" array | ||
145 | * is searched in the order returned from the server, per RFC 3530 | 144 | * is searched in the order returned from the server, per RFC 3530 |
146 | * recommendation. | 145 | * recommendation and each flavor is checked for membership in the |
146 | * sec= mount option list if it exists. | ||
147 | * | ||
148 | * Return -EPERM if no matching flavor is found in the array. | ||
149 | * | ||
150 | * Please call rpc_shutdown_client() when you are done with this rpc client. | ||
151 | * | ||
147 | */ | 152 | */ |
148 | static rpc_authflavor_t nfs_find_best_sec(struct nfs_server *server, | 153 | static struct rpc_clnt *nfs_find_best_sec(struct rpc_clnt *clnt, |
154 | struct nfs_server *server, | ||
149 | struct nfs4_secinfo_flavors *flavors) | 155 | struct nfs4_secinfo_flavors *flavors) |
150 | { | 156 | { |
151 | rpc_authflavor_t pseudoflavor; | 157 | rpc_authflavor_t pflavor; |
152 | struct nfs4_secinfo4 *secinfo; | 158 | struct nfs4_secinfo4 *secinfo; |
153 | unsigned int i; | 159 | unsigned int i; |
154 | 160 | ||
@@ -159,62 +165,73 @@ static rpc_authflavor_t nfs_find_best_sec(struct nfs_server *server, | |||
159 | case RPC_AUTH_NULL: | 165 | case RPC_AUTH_NULL: |
160 | case RPC_AUTH_UNIX: | 166 | case RPC_AUTH_UNIX: |
161 | case RPC_AUTH_GSS: | 167 | case RPC_AUTH_GSS: |
162 | pseudoflavor = rpcauth_get_pseudoflavor(secinfo->flavor, | 168 | pflavor = rpcauth_get_pseudoflavor(secinfo->flavor, |
163 | &secinfo->flavor_info); | 169 | &secinfo->flavor_info); |
164 | /* make sure pseudoflavor matches sec= mount opt */ | 170 | /* does the pseudoflavor match a sec= mount opt? */ |
165 | if (pseudoflavor != RPC_AUTH_MAXFLAVOR && | 171 | if (pflavor != RPC_AUTH_MAXFLAVOR && |
166 | nfs_auth_info_match(&server->auth_info, | 172 | nfs_auth_info_match(&server->auth_info, pflavor)) { |
167 | pseudoflavor)) | 173 | struct rpc_clnt *new; |
168 | return pseudoflavor; | 174 | struct rpc_cred *cred; |
169 | break; | 175 | |
176 | /* Cloning creates an rpc_auth for the flavor */ | ||
177 | new = rpc_clone_client_set_auth(clnt, pflavor); | ||
178 | if (IS_ERR(new)) | ||
179 | continue; | ||
180 | /** | ||
181 | * Check that the user actually can use the | ||
182 | * flavor. This is mostly for RPC_AUTH_GSS | ||
183 | * where cr_init obtains a gss context | ||
184 | */ | ||
185 | cred = rpcauth_lookupcred(new->cl_auth, 0); | ||
186 | if (IS_ERR(cred)) { | ||
187 | rpc_shutdown_client(new); | ||
188 | continue; | ||
189 | } | ||
190 | put_rpccred(cred); | ||
191 | return new; | ||
192 | } | ||
170 | } | 193 | } |
171 | } | 194 | } |
172 | 195 | return ERR_PTR(-EPERM); | |
173 | /* if there were any sec= options then nothing matched */ | ||
174 | if (server->auth_info.flavor_len > 0) | ||
175 | return -EPERM; | ||
176 | |||
177 | return RPC_AUTH_UNIX; | ||
178 | } | 196 | } |
179 | 197 | ||
180 | static rpc_authflavor_t nfs4_negotiate_security(struct inode *inode, struct qstr *name) | 198 | /** |
199 | * nfs4_negotiate_security - in response to an NFS4ERR_WRONGSEC on lookup, | ||
200 | * return an rpc_clnt that uses the best available security flavor with | ||
201 | * respect to the secinfo flavor list and the sec= mount options. | ||
202 | * | ||
203 | * @clnt: RPC client to clone | ||
204 | * @inode: directory inode | ||
205 | * @name: lookup name | ||
206 | * | ||
207 | * Please call rpc_shutdown_client() when you are done with this rpc client. | ||
208 | */ | ||
209 | struct rpc_clnt * | ||
210 | nfs4_negotiate_security(struct rpc_clnt *clnt, struct inode *inode, | ||
211 | struct qstr *name) | ||
181 | { | 212 | { |
182 | struct page *page; | 213 | struct page *page; |
183 | struct nfs4_secinfo_flavors *flavors; | 214 | struct nfs4_secinfo_flavors *flavors; |
184 | rpc_authflavor_t flavor; | 215 | struct rpc_clnt *new; |
185 | int err; | 216 | int err; |
186 | 217 | ||
187 | page = alloc_page(GFP_KERNEL); | 218 | page = alloc_page(GFP_KERNEL); |
188 | if (!page) | 219 | if (!page) |
189 | return -ENOMEM; | 220 | return ERR_PTR(-ENOMEM); |
221 | |||
190 | flavors = page_address(page); | 222 | flavors = page_address(page); |
191 | 223 | ||
192 | err = nfs4_proc_secinfo(inode, name, flavors); | 224 | err = nfs4_proc_secinfo(inode, name, flavors); |
193 | if (err < 0) { | 225 | if (err < 0) { |
194 | flavor = err; | 226 | new = ERR_PTR(err); |
195 | goto out; | 227 | goto out; |
196 | } | 228 | } |
197 | 229 | ||
198 | flavor = nfs_find_best_sec(NFS_SERVER(inode), flavors); | 230 | new = nfs_find_best_sec(clnt, NFS_SERVER(inode), flavors); |
199 | 231 | ||
200 | out: | 232 | out: |
201 | put_page(page); | 233 | put_page(page); |
202 | return flavor; | 234 | return new; |
203 | } | ||
204 | |||
205 | /* | ||
206 | * Please call rpc_shutdown_client() when you are done with this client. | ||
207 | */ | ||
208 | struct rpc_clnt *nfs4_create_sec_client(struct rpc_clnt *clnt, struct inode *inode, | ||
209 | struct qstr *name) | ||
210 | { | ||
211 | rpc_authflavor_t flavor; | ||
212 | |||
213 | flavor = nfs4_negotiate_security(inode, name); | ||
214 | if ((int)flavor < 0) | ||
215 | return ERR_PTR((int)flavor); | ||
216 | |||
217 | return rpc_clone_client_set_auth(clnt, flavor); | ||
218 | } | 235 | } |
219 | 236 | ||
220 | static struct vfsmount *try_location(struct nfs_clone_mount *mountdata, | 237 | static struct vfsmount *try_location(struct nfs_clone_mount *mountdata, |
@@ -397,11 +414,6 @@ struct vfsmount *nfs4_submount(struct nfs_server *server, struct dentry *dentry, | |||
397 | 414 | ||
398 | if (client->cl_auth->au_flavor != flavor) | 415 | if (client->cl_auth->au_flavor != flavor) |
399 | flavor = client->cl_auth->au_flavor; | 416 | flavor = client->cl_auth->au_flavor; |
400 | else { | ||
401 | rpc_authflavor_t new = nfs4_negotiate_security(dir, name); | ||
402 | if ((int)new >= 0) | ||
403 | flavor = new; | ||
404 | } | ||
405 | mnt = nfs_do_submount(dentry, fh, fattr, flavor); | 417 | mnt = nfs_do_submount(dentry, fh, fattr, flavor); |
406 | out: | 418 | out: |
407 | rpc_shutdown_client(client); | 419 | rpc_shutdown_client(client); |
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index 285ad5334018..4bf3d97cc5a0 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c | |||
@@ -3247,7 +3247,7 @@ static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir, | |||
3247 | err = -EPERM; | 3247 | err = -EPERM; |
3248 | if (client != *clnt) | 3248 | if (client != *clnt) |
3249 | goto out; | 3249 | goto out; |
3250 | client = nfs4_create_sec_client(client, dir, name); | 3250 | client = nfs4_negotiate_security(client, dir, name); |
3251 | if (IS_ERR(client)) | 3251 | if (IS_ERR(client)) |
3252 | return PTR_ERR(client); | 3252 | return PTR_ERR(client); |
3253 | 3253 | ||
diff --git a/fs/nfs/pagelist.c b/fs/nfs/pagelist.c index b6ee3a6ee96d..17fab89f6358 100644 --- a/fs/nfs/pagelist.c +++ b/fs/nfs/pagelist.c | |||
@@ -29,8 +29,6 @@ | |||
29 | static struct kmem_cache *nfs_page_cachep; | 29 | static struct kmem_cache *nfs_page_cachep; |
30 | static const struct rpc_call_ops nfs_pgio_common_ops; | 30 | static const struct rpc_call_ops nfs_pgio_common_ops; |
31 | 31 | ||
32 | static void nfs_free_request(struct nfs_page *); | ||
33 | |||
34 | static bool nfs_pgarray_set(struct nfs_page_array *p, unsigned int pagecount) | 32 | static bool nfs_pgarray_set(struct nfs_page_array *p, unsigned int pagecount) |
35 | { | 33 | { |
36 | p->npages = pagecount; | 34 | p->npages = pagecount; |
@@ -239,20 +237,28 @@ nfs_page_group_init(struct nfs_page *req, struct nfs_page *prev) | |||
239 | WARN_ON_ONCE(prev == req); | 237 | WARN_ON_ONCE(prev == req); |
240 | 238 | ||
241 | if (!prev) { | 239 | if (!prev) { |
240 | /* a head request */ | ||
242 | req->wb_head = req; | 241 | req->wb_head = req; |
243 | req->wb_this_page = req; | 242 | req->wb_this_page = req; |
244 | } else { | 243 | } else { |
244 | /* a subrequest */ | ||
245 | WARN_ON_ONCE(prev->wb_this_page != prev->wb_head); | 245 | WARN_ON_ONCE(prev->wb_this_page != prev->wb_head); |
246 | WARN_ON_ONCE(!test_bit(PG_HEADLOCK, &prev->wb_head->wb_flags)); | 246 | WARN_ON_ONCE(!test_bit(PG_HEADLOCK, &prev->wb_head->wb_flags)); |
247 | req->wb_head = prev->wb_head; | 247 | req->wb_head = prev->wb_head; |
248 | req->wb_this_page = prev->wb_this_page; | 248 | req->wb_this_page = prev->wb_this_page; |
249 | prev->wb_this_page = req; | 249 | prev->wb_this_page = req; |
250 | 250 | ||
251 | /* All subrequests take a ref on the head request until | ||
252 | * nfs_page_group_destroy is called */ | ||
253 | kref_get(&req->wb_head->wb_kref); | ||
254 | |||
251 | /* grab extra ref if head request has extra ref from | 255 | /* grab extra ref if head request has extra ref from |
252 | * the write/commit path to handle handoff between write | 256 | * the write/commit path to handle handoff between write |
253 | * and commit lists */ | 257 | * and commit lists */ |
254 | if (test_bit(PG_INODE_REF, &prev->wb_head->wb_flags)) | 258 | if (test_bit(PG_INODE_REF, &prev->wb_head->wb_flags)) { |
259 | set_bit(PG_INODE_REF, &req->wb_flags); | ||
255 | kref_get(&req->wb_kref); | 260 | kref_get(&req->wb_kref); |
261 | } | ||
256 | } | 262 | } |
257 | } | 263 | } |
258 | 264 | ||
@@ -269,6 +275,10 @@ nfs_page_group_destroy(struct kref *kref) | |||
269 | struct nfs_page *req = container_of(kref, struct nfs_page, wb_kref); | 275 | struct nfs_page *req = container_of(kref, struct nfs_page, wb_kref); |
270 | struct nfs_page *tmp, *next; | 276 | struct nfs_page *tmp, *next; |
271 | 277 | ||
278 | /* subrequests must release the ref on the head request */ | ||
279 | if (req->wb_head != req) | ||
280 | nfs_release_request(req->wb_head); | ||
281 | |||
272 | if (!nfs_page_group_sync_on_bit(req, PG_TEARDOWN)) | 282 | if (!nfs_page_group_sync_on_bit(req, PG_TEARDOWN)) |
273 | return; | 283 | return; |
274 | 284 | ||
@@ -394,7 +404,7 @@ static void nfs_clear_request(struct nfs_page *req) | |||
394 | * | 404 | * |
395 | * Note: Should never be called with the spinlock held! | 405 | * Note: Should never be called with the spinlock held! |
396 | */ | 406 | */ |
397 | static void nfs_free_request(struct nfs_page *req) | 407 | void nfs_free_request(struct nfs_page *req) |
398 | { | 408 | { |
399 | WARN_ON_ONCE(req->wb_this_page != req); | 409 | WARN_ON_ONCE(req->wb_this_page != req); |
400 | 410 | ||
@@ -925,7 +935,6 @@ static int __nfs_pageio_add_request(struct nfs_pageio_descriptor *desc, | |||
925 | nfs_pageio_doio(desc); | 935 | nfs_pageio_doio(desc); |
926 | if (desc->pg_error < 0) | 936 | if (desc->pg_error < 0) |
927 | return 0; | 937 | return 0; |
928 | desc->pg_moreio = 0; | ||
929 | if (desc->pg_recoalesce) | 938 | if (desc->pg_recoalesce) |
930 | return 0; | 939 | return 0; |
931 | /* retry add_request for this subreq */ | 940 | /* retry add_request for this subreq */ |
@@ -972,6 +981,7 @@ static int nfs_do_recoalesce(struct nfs_pageio_descriptor *desc) | |||
972 | desc->pg_count = 0; | 981 | desc->pg_count = 0; |
973 | desc->pg_base = 0; | 982 | desc->pg_base = 0; |
974 | desc->pg_recoalesce = 0; | 983 | desc->pg_recoalesce = 0; |
984 | desc->pg_moreio = 0; | ||
975 | 985 | ||
976 | while (!list_empty(&head)) { | 986 | while (!list_empty(&head)) { |
977 | struct nfs_page *req; | 987 | struct nfs_page *req; |
diff --git a/fs/nfs/write.c b/fs/nfs/write.c index 3ee5af4e738e..5e2f10304548 100644 --- a/fs/nfs/write.c +++ b/fs/nfs/write.c | |||
@@ -46,6 +46,7 @@ static const struct rpc_call_ops nfs_commit_ops; | |||
46 | static const struct nfs_pgio_completion_ops nfs_async_write_completion_ops; | 46 | static const struct nfs_pgio_completion_ops nfs_async_write_completion_ops; |
47 | static const struct nfs_commit_completion_ops nfs_commit_completion_ops; | 47 | static const struct nfs_commit_completion_ops nfs_commit_completion_ops; |
48 | static const struct nfs_rw_ops nfs_rw_write_ops; | 48 | static const struct nfs_rw_ops nfs_rw_write_ops; |
49 | static void nfs_clear_request_commit(struct nfs_page *req); | ||
49 | 50 | ||
50 | static struct kmem_cache *nfs_wdata_cachep; | 51 | static struct kmem_cache *nfs_wdata_cachep; |
51 | static mempool_t *nfs_wdata_mempool; | 52 | static mempool_t *nfs_wdata_mempool; |
@@ -91,8 +92,15 @@ static void nfs_context_set_write_error(struct nfs_open_context *ctx, int error) | |||
91 | set_bit(NFS_CONTEXT_ERROR_WRITE, &ctx->flags); | 92 | set_bit(NFS_CONTEXT_ERROR_WRITE, &ctx->flags); |
92 | } | 93 | } |
93 | 94 | ||
95 | /* | ||
96 | * nfs_page_find_head_request_locked - find head request associated with @page | ||
97 | * | ||
98 | * must be called while holding the inode lock. | ||
99 | * | ||
100 | * returns matching head request with reference held, or NULL if not found. | ||
101 | */ | ||
94 | static struct nfs_page * | 102 | static struct nfs_page * |
95 | nfs_page_find_request_locked(struct nfs_inode *nfsi, struct page *page) | 103 | nfs_page_find_head_request_locked(struct nfs_inode *nfsi, struct page *page) |
96 | { | 104 | { |
97 | struct nfs_page *req = NULL; | 105 | struct nfs_page *req = NULL; |
98 | 106 | ||
@@ -104,25 +112,33 @@ nfs_page_find_request_locked(struct nfs_inode *nfsi, struct page *page) | |||
104 | /* Linearly search the commit list for the correct req */ | 112 | /* Linearly search the commit list for the correct req */ |
105 | list_for_each_entry_safe(freq, t, &nfsi->commit_info.list, wb_list) { | 113 | list_for_each_entry_safe(freq, t, &nfsi->commit_info.list, wb_list) { |
106 | if (freq->wb_page == page) { | 114 | if (freq->wb_page == page) { |
107 | req = freq; | 115 | req = freq->wb_head; |
108 | break; | 116 | break; |
109 | } | 117 | } |
110 | } | 118 | } |
111 | } | 119 | } |
112 | 120 | ||
113 | if (req) | 121 | if (req) { |
122 | WARN_ON_ONCE(req->wb_head != req); | ||
123 | |||
114 | kref_get(&req->wb_kref); | 124 | kref_get(&req->wb_kref); |
125 | } | ||
115 | 126 | ||
116 | return req; | 127 | return req; |
117 | } | 128 | } |
118 | 129 | ||
119 | static struct nfs_page *nfs_page_find_request(struct page *page) | 130 | /* |
131 | * nfs_page_find_head_request - find head request associated with @page | ||
132 | * | ||
133 | * returns matching head request with reference held, or NULL if not found. | ||
134 | */ | ||
135 | static struct nfs_page *nfs_page_find_head_request(struct page *page) | ||
120 | { | 136 | { |
121 | struct inode *inode = page_file_mapping(page)->host; | 137 | struct inode *inode = page_file_mapping(page)->host; |
122 | struct nfs_page *req = NULL; | 138 | struct nfs_page *req = NULL; |
123 | 139 | ||
124 | spin_lock(&inode->i_lock); | 140 | spin_lock(&inode->i_lock); |
125 | req = nfs_page_find_request_locked(NFS_I(inode), page); | 141 | req = nfs_page_find_head_request_locked(NFS_I(inode), page); |
126 | spin_unlock(&inode->i_lock); | 142 | spin_unlock(&inode->i_lock); |
127 | return req; | 143 | return req; |
128 | } | 144 | } |
@@ -274,36 +290,246 @@ static void nfs_end_page_writeback(struct nfs_page *req) | |||
274 | clear_bdi_congested(&nfss->backing_dev_info, BLK_RW_ASYNC); | 290 | clear_bdi_congested(&nfss->backing_dev_info, BLK_RW_ASYNC); |
275 | } | 291 | } |
276 | 292 | ||
277 | static struct nfs_page *nfs_find_and_lock_request(struct page *page, bool nonblock) | 293 | |
294 | /* nfs_page_group_clear_bits | ||
295 | * @req - an nfs request | ||
296 | * clears all page group related bits from @req | ||
297 | */ | ||
298 | static void | ||
299 | nfs_page_group_clear_bits(struct nfs_page *req) | ||
300 | { | ||
301 | clear_bit(PG_TEARDOWN, &req->wb_flags); | ||
302 | clear_bit(PG_UNLOCKPAGE, &req->wb_flags); | ||
303 | clear_bit(PG_UPTODATE, &req->wb_flags); | ||
304 | clear_bit(PG_WB_END, &req->wb_flags); | ||
305 | clear_bit(PG_REMOVE, &req->wb_flags); | ||
306 | } | ||
307 | |||
308 | |||
309 | /* | ||
310 | * nfs_unroll_locks_and_wait - unlock all newly locked reqs and wait on @req | ||
311 | * | ||
312 | * this is a helper function for nfs_lock_and_join_requests | ||
313 | * | ||
314 | * @inode - inode associated with request page group, must be holding inode lock | ||
315 | * @head - head request of page group, must be holding head lock | ||
316 | * @req - request that couldn't lock and needs to wait on the req bit lock | ||
317 | * @nonblock - if true, don't actually wait | ||
318 | * | ||
319 | * NOTE: this must be called holding page_group bit lock and inode spin lock | ||
320 | * and BOTH will be released before returning. | ||
321 | * | ||
322 | * returns 0 on success, < 0 on error. | ||
323 | */ | ||
324 | static int | ||
325 | nfs_unroll_locks_and_wait(struct inode *inode, struct nfs_page *head, | ||
326 | struct nfs_page *req, bool nonblock) | ||
327 | __releases(&inode->i_lock) | ||
328 | { | ||
329 | struct nfs_page *tmp; | ||
330 | int ret; | ||
331 | |||
332 | /* relinquish all the locks successfully grabbed this run */ | ||
333 | for (tmp = head ; tmp != req; tmp = tmp->wb_this_page) | ||
334 | nfs_unlock_request(tmp); | ||
335 | |||
336 | WARN_ON_ONCE(test_bit(PG_TEARDOWN, &req->wb_flags)); | ||
337 | |||
338 | /* grab a ref on the request that will be waited on */ | ||
339 | kref_get(&req->wb_kref); | ||
340 | |||
341 | nfs_page_group_unlock(head); | ||
342 | spin_unlock(&inode->i_lock); | ||
343 | |||
344 | /* release ref from nfs_page_find_head_request_locked */ | ||
345 | nfs_release_request(head); | ||
346 | |||
347 | if (!nonblock) | ||
348 | ret = nfs_wait_on_request(req); | ||
349 | else | ||
350 | ret = -EAGAIN; | ||
351 | nfs_release_request(req); | ||
352 | |||
353 | return ret; | ||
354 | } | ||
355 | |||
356 | /* | ||
357 | * nfs_destroy_unlinked_subrequests - destroy recently unlinked subrequests | ||
358 | * | ||
359 | * @destroy_list - request list (using wb_this_page) terminated by @old_head | ||
360 | * @old_head - the old head of the list | ||
361 | * | ||
362 | * All subrequests must be locked and removed from all lists, so at this point | ||
363 | * they are only "active" in this function, and possibly in nfs_wait_on_request | ||
364 | * with a reference held by some other context. | ||
365 | */ | ||
366 | static void | ||
367 | nfs_destroy_unlinked_subrequests(struct nfs_page *destroy_list, | ||
368 | struct nfs_page *old_head) | ||
369 | { | ||
370 | while (destroy_list) { | ||
371 | struct nfs_page *subreq = destroy_list; | ||
372 | |||
373 | destroy_list = (subreq->wb_this_page == old_head) ? | ||
374 | NULL : subreq->wb_this_page; | ||
375 | |||
376 | WARN_ON_ONCE(old_head != subreq->wb_head); | ||
377 | |||
378 | /* make sure old group is not used */ | ||
379 | subreq->wb_head = subreq; | ||
380 | subreq->wb_this_page = subreq; | ||
381 | |||
382 | nfs_clear_request_commit(subreq); | ||
383 | |||
384 | /* subreq is now totally disconnected from page group or any | ||
385 | * write / commit lists. last chance to wake any waiters */ | ||
386 | nfs_unlock_request(subreq); | ||
387 | |||
388 | if (!test_bit(PG_TEARDOWN, &subreq->wb_flags)) { | ||
389 | /* release ref on old head request */ | ||
390 | nfs_release_request(old_head); | ||
391 | |||
392 | nfs_page_group_clear_bits(subreq); | ||
393 | |||
394 | /* release the PG_INODE_REF reference */ | ||
395 | if (test_and_clear_bit(PG_INODE_REF, &subreq->wb_flags)) | ||
396 | nfs_release_request(subreq); | ||
397 | else | ||
398 | WARN_ON_ONCE(1); | ||
399 | } else { | ||
400 | WARN_ON_ONCE(test_bit(PG_CLEAN, &subreq->wb_flags)); | ||
401 | /* zombie requests have already released the last | ||
402 | * reference and were waiting on the rest of the | ||
403 | * group to complete. Since it's no longer part of a | ||
404 | * group, simply free the request */ | ||
405 | nfs_page_group_clear_bits(subreq); | ||
406 | nfs_free_request(subreq); | ||
407 | } | ||
408 | } | ||
409 | } | ||
410 | |||
411 | /* | ||
412 | * nfs_lock_and_join_requests - join all subreqs to the head req and return | ||
413 | * a locked reference, cancelling any pending | ||
414 | * operations for this page. | ||
415 | * | ||
416 | * @page - the page used to lookup the "page group" of nfs_page structures | ||
417 | * @nonblock - if true, don't block waiting for request locks | ||
418 | * | ||
419 | * This function joins all sub requests to the head request by first | ||
420 | * locking all requests in the group, cancelling any pending operations | ||
421 | * and finally updating the head request to cover the whole range covered by | ||
422 | * the (former) group. All subrequests are removed from any write or commit | ||
423 | * lists, unlinked from the group and destroyed. | ||
424 | * | ||
425 | * Returns a locked, referenced pointer to the head request - which after | ||
426 | * this call is guaranteed to be the only request associated with the page. | ||
427 | * Returns NULL if no requests are found for @page, or a ERR_PTR if an | ||
428 | * error was encountered. | ||
429 | */ | ||
430 | static struct nfs_page * | ||
431 | nfs_lock_and_join_requests(struct page *page, bool nonblock) | ||
278 | { | 432 | { |
279 | struct inode *inode = page_file_mapping(page)->host; | 433 | struct inode *inode = page_file_mapping(page)->host; |
280 | struct nfs_page *req; | 434 | struct nfs_page *head, *subreq; |
435 | struct nfs_page *destroy_list = NULL; | ||
436 | unsigned int total_bytes; | ||
281 | int ret; | 437 | int ret; |
282 | 438 | ||
439 | try_again: | ||
440 | total_bytes = 0; | ||
441 | |||
442 | WARN_ON_ONCE(destroy_list); | ||
443 | |||
283 | spin_lock(&inode->i_lock); | 444 | spin_lock(&inode->i_lock); |
284 | for (;;) { | 445 | |
285 | req = nfs_page_find_request_locked(NFS_I(inode), page); | 446 | /* |
286 | if (req == NULL) | 447 | * A reference is taken only on the head request which acts as a |
287 | break; | 448 | * reference to the whole page group - the group will not be destroyed |
288 | if (nfs_lock_request(req)) | 449 | * until the head reference is released. |
289 | break; | 450 | */ |
290 | /* Note: If we hold the page lock, as is the case in nfs_writepage, | 451 | head = nfs_page_find_head_request_locked(NFS_I(inode), page); |
291 | * then the call to nfs_lock_request() will always | 452 | |
292 | * succeed provided that someone hasn't already marked the | 453 | if (!head) { |
293 | * request as dirty (in which case we don't care). | ||
294 | */ | ||
295 | spin_unlock(&inode->i_lock); | 454 | spin_unlock(&inode->i_lock); |
296 | if (!nonblock) | 455 | return NULL; |
297 | ret = nfs_wait_on_request(req); | 456 | } |
298 | else | 457 | |
299 | ret = -EAGAIN; | 458 | /* lock each request in the page group */ |
300 | nfs_release_request(req); | 459 | nfs_page_group_lock(head); |
301 | if (ret != 0) | 460 | subreq = head; |
461 | do { | ||
462 | /* | ||
463 | * Subrequests are always contiguous, non overlapping | ||
464 | * and in order. If not, it's a programming error. | ||
465 | */ | ||
466 | WARN_ON_ONCE(subreq->wb_offset != | ||
467 | (head->wb_offset + total_bytes)); | ||
468 | |||
469 | /* keep track of how many bytes this group covers */ | ||
470 | total_bytes += subreq->wb_bytes; | ||
471 | |||
472 | if (!nfs_lock_request(subreq)) { | ||
473 | /* releases page group bit lock and | ||
474 | * inode spin lock and all references */ | ||
475 | ret = nfs_unroll_locks_and_wait(inode, head, | ||
476 | subreq, nonblock); | ||
477 | |||
478 | if (ret == 0) | ||
479 | goto try_again; | ||
480 | |||
302 | return ERR_PTR(ret); | 481 | return ERR_PTR(ret); |
303 | spin_lock(&inode->i_lock); | 482 | } |
483 | |||
484 | subreq = subreq->wb_this_page; | ||
485 | } while (subreq != head); | ||
486 | |||
487 | /* Now that all requests are locked, make sure they aren't on any list. | ||
488 | * Commit list removal accounting is done after locks are dropped */ | ||
489 | subreq = head; | ||
490 | do { | ||
491 | nfs_list_remove_request(subreq); | ||
492 | subreq = subreq->wb_this_page; | ||
493 | } while (subreq != head); | ||
494 | |||
495 | /* unlink subrequests from head, destroy them later */ | ||
496 | if (head->wb_this_page != head) { | ||
497 | /* destroy list will be terminated by head */ | ||
498 | destroy_list = head->wb_this_page; | ||
499 | head->wb_this_page = head; | ||
500 | |||
501 | /* change head request to cover whole range that | ||
502 | * the former page group covered */ | ||
503 | head->wb_bytes = total_bytes; | ||
304 | } | 504 | } |
505 | |||
506 | /* | ||
507 | * prepare head request to be added to new pgio descriptor | ||
508 | */ | ||
509 | nfs_page_group_clear_bits(head); | ||
510 | |||
511 | /* | ||
512 | * some part of the group was still on the inode list - otherwise | ||
513 | * the group wouldn't be involved in async write. | ||
514 | * grab a reference for the head request, iff it needs one. | ||
515 | */ | ||
516 | if (!test_and_set_bit(PG_INODE_REF, &head->wb_flags)) | ||
517 | kref_get(&head->wb_kref); | ||
518 | |||
519 | nfs_page_group_unlock(head); | ||
520 | |||
521 | /* drop lock to clear_request_commit the head req and clean up | ||
522 | * requests on destroy list */ | ||
305 | spin_unlock(&inode->i_lock); | 523 | spin_unlock(&inode->i_lock); |
306 | return req; | 524 | |
525 | nfs_destroy_unlinked_subrequests(destroy_list, head); | ||
526 | |||
527 | /* clean up commit list state */ | ||
528 | nfs_clear_request_commit(head); | ||
529 | |||
530 | /* still holds ref on head from nfs_page_find_head_request_locked | ||
531 | * and still has lock on head from lock loop */ | ||
532 | return head; | ||
307 | } | 533 | } |
308 | 534 | ||
309 | /* | 535 | /* |
@@ -316,7 +542,7 @@ static int nfs_page_async_flush(struct nfs_pageio_descriptor *pgio, | |||
316 | struct nfs_page *req; | 542 | struct nfs_page *req; |
317 | int ret = 0; | 543 | int ret = 0; |
318 | 544 | ||
319 | req = nfs_find_and_lock_request(page, nonblock); | 545 | req = nfs_lock_and_join_requests(page, nonblock); |
320 | if (!req) | 546 | if (!req) |
321 | goto out; | 547 | goto out; |
322 | ret = PTR_ERR(req); | 548 | ret = PTR_ERR(req); |
@@ -448,7 +674,9 @@ static void nfs_inode_add_request(struct inode *inode, struct nfs_page *req) | |||
448 | set_page_private(req->wb_page, (unsigned long)req); | 674 | set_page_private(req->wb_page, (unsigned long)req); |
449 | } | 675 | } |
450 | nfsi->npages++; | 676 | nfsi->npages++; |
451 | set_bit(PG_INODE_REF, &req->wb_flags); | 677 | /* this a head request for a page group - mark it as having an |
678 | * extra reference so sub groups can follow suit */ | ||
679 | WARN_ON(test_and_set_bit(PG_INODE_REF, &req->wb_flags)); | ||
452 | kref_get(&req->wb_kref); | 680 | kref_get(&req->wb_kref); |
453 | spin_unlock(&inode->i_lock); | 681 | spin_unlock(&inode->i_lock); |
454 | } | 682 | } |
@@ -474,7 +702,9 @@ static void nfs_inode_remove_request(struct nfs_page *req) | |||
474 | nfsi->npages--; | 702 | nfsi->npages--; |
475 | spin_unlock(&inode->i_lock); | 703 | spin_unlock(&inode->i_lock); |
476 | } | 704 | } |
477 | nfs_release_request(req); | 705 | |
706 | if (test_and_clear_bit(PG_INODE_REF, &req->wb_flags)) | ||
707 | nfs_release_request(req); | ||
478 | } | 708 | } |
479 | 709 | ||
480 | static void | 710 | static void |
@@ -638,7 +868,6 @@ static void nfs_write_completion(struct nfs_pgio_header *hdr) | |||
638 | { | 868 | { |
639 | struct nfs_commit_info cinfo; | 869 | struct nfs_commit_info cinfo; |
640 | unsigned long bytes = 0; | 870 | unsigned long bytes = 0; |
641 | bool do_destroy; | ||
642 | 871 | ||
643 | if (test_bit(NFS_IOHDR_REDO, &hdr->flags)) | 872 | if (test_bit(NFS_IOHDR_REDO, &hdr->flags)) |
644 | goto out; | 873 | goto out; |
@@ -668,7 +897,6 @@ remove_req: | |||
668 | next: | 897 | next: |
669 | nfs_unlock_request(req); | 898 | nfs_unlock_request(req); |
670 | nfs_end_page_writeback(req); | 899 | nfs_end_page_writeback(req); |
671 | do_destroy = !test_bit(NFS_IOHDR_NEED_COMMIT, &hdr->flags); | ||
672 | nfs_release_request(req); | 900 | nfs_release_request(req); |
673 | } | 901 | } |
674 | out: | 902 | out: |
@@ -769,7 +997,7 @@ static struct nfs_page *nfs_try_to_update_request(struct inode *inode, | |||
769 | spin_lock(&inode->i_lock); | 997 | spin_lock(&inode->i_lock); |
770 | 998 | ||
771 | for (;;) { | 999 | for (;;) { |
772 | req = nfs_page_find_request_locked(NFS_I(inode), page); | 1000 | req = nfs_page_find_head_request_locked(NFS_I(inode), page); |
773 | if (req == NULL) | 1001 | if (req == NULL) |
774 | goto out_unlock; | 1002 | goto out_unlock; |
775 | 1003 | ||
@@ -877,7 +1105,7 @@ int nfs_flush_incompatible(struct file *file, struct page *page) | |||
877 | * dropped page. | 1105 | * dropped page. |
878 | */ | 1106 | */ |
879 | do { | 1107 | do { |
880 | req = nfs_page_find_request(page); | 1108 | req = nfs_page_find_head_request(page); |
881 | if (req == NULL) | 1109 | if (req == NULL) |
882 | return 0; | 1110 | return 0; |
883 | l_ctx = req->wb_lock_context; | 1111 | l_ctx = req->wb_lock_context; |
@@ -934,12 +1162,14 @@ static bool nfs_write_pageuptodate(struct page *page, struct inode *inode) | |||
934 | 1162 | ||
935 | if (nfs_have_delegated_attributes(inode)) | 1163 | if (nfs_have_delegated_attributes(inode)) |
936 | goto out; | 1164 | goto out; |
937 | if (nfsi->cache_validity & (NFS_INO_INVALID_DATA|NFS_INO_REVAL_PAGECACHE)) | 1165 | if (nfsi->cache_validity & NFS_INO_REVAL_PAGECACHE) |
938 | return false; | 1166 | return false; |
939 | smp_rmb(); | 1167 | smp_rmb(); |
940 | if (test_bit(NFS_INO_INVALIDATING, &nfsi->flags)) | 1168 | if (test_bit(NFS_INO_INVALIDATING, &nfsi->flags)) |
941 | return false; | 1169 | return false; |
942 | out: | 1170 | out: |
1171 | if (nfsi->cache_validity & NFS_INO_INVALID_DATA) | ||
1172 | return false; | ||
943 | return PageUptodate(page) != 0; | 1173 | return PageUptodate(page) != 0; |
944 | } | 1174 | } |
945 | 1175 | ||
@@ -1567,27 +1797,28 @@ int nfs_wb_page_cancel(struct inode *inode, struct page *page) | |||
1567 | struct nfs_page *req; | 1797 | struct nfs_page *req; |
1568 | int ret = 0; | 1798 | int ret = 0; |
1569 | 1799 | ||
1570 | for (;;) { | 1800 | wait_on_page_writeback(page); |
1571 | wait_on_page_writeback(page); | 1801 | |
1572 | req = nfs_page_find_request(page); | 1802 | /* blocking call to cancel all requests and join to a single (head) |
1573 | if (req == NULL) | 1803 | * request */ |
1574 | break; | 1804 | req = nfs_lock_and_join_requests(page, false); |
1575 | if (nfs_lock_request(req)) { | 1805 | |
1576 | nfs_clear_request_commit(req); | 1806 | if (IS_ERR(req)) { |
1577 | nfs_inode_remove_request(req); | 1807 | ret = PTR_ERR(req); |
1578 | /* | 1808 | } else if (req) { |
1579 | * In case nfs_inode_remove_request has marked the | 1809 | /* all requests from this page have been cancelled by |
1580 | * page as being dirty | 1810 | * nfs_lock_and_join_requests, so just remove the head |
1581 | */ | 1811 | * request from the inode / page_private pointer and |
1582 | cancel_dirty_page(page, PAGE_CACHE_SIZE); | 1812 | * release it */ |
1583 | nfs_unlock_and_release_request(req); | 1813 | nfs_inode_remove_request(req); |
1584 | break; | 1814 | /* |
1585 | } | 1815 | * In case nfs_inode_remove_request has marked the |
1586 | ret = nfs_wait_on_request(req); | 1816 | * page as being dirty |
1587 | nfs_release_request(req); | 1817 | */ |
1588 | if (ret < 0) | 1818 | cancel_dirty_page(page, PAGE_CACHE_SIZE); |
1589 | break; | 1819 | nfs_unlock_and_release_request(req); |
1590 | } | 1820 | } |
1821 | |||
1591 | return ret; | 1822 | return ret; |
1592 | } | 1823 | } |
1593 | 1824 | ||