diff options
| author | Trond Myklebust <trond.myklebust@primarydata.com> | 2015-02-03 16:01:27 -0500 |
|---|---|---|
| committer | Trond Myklebust <trond.myklebust@primarydata.com> | 2015-02-03 16:01:27 -0500 |
| commit | e2c63e091e29786a34ecf42c169e627a3d1d96d7 (patch) | |
| tree | 4e96723b969bd6b3d39613de601f18da678cca71 | |
| parent | cc3ea893cbb386e657d775f299f61bb9ba3bc435 (diff) | |
| parent | 7c13789e3e6c66dbcaade1760087429240eb3d27 (diff) | |
Merge branch 'flexfiles'
* flexfiles: (53 commits)
pnfs: lookup new lseg at lseg boundary
nfs41: .init_read and .init_write can be called with valid pg_lseg
pnfs: Update documentation on the Layout Drivers
pnfs/flexfiles: Add the FlexFile Layout Driver
nfs: count DIO good bytes correctly with mirroring
nfs41: wait for LAYOUTRETURN before retrying LAYOUTGET
nfs: add a helper to set NFS_ODIRECT_RESCHED_WRITES to direct writes
nfs41: add NFS_LAYOUT_RETRY_LAYOUTGET to layout header flags
nfs/flexfiles: send layoutreturn before freeing lseg
nfs41: introduce NFS_LAYOUT_RETURN_BEFORE_CLOSE
nfs41: allow async version layoutreturn
nfs41: add range to layoutreturn args
pnfs: allow LD to ask to resend read through pnfs
nfs: add nfs_pgio_current_mirror helper
nfs: only reset desc->pg_mirror_idx when mirroring is supported
nfs41: add a debug warning if we destroy an unempty layout
pnfs: fail comparison when bucket verifier not set
nfs: mirroring support for direct io
nfs: add mirroring support to pgio layer
pnfs: pass ds_commit_idx through the commit path
...
Conflicts:
fs/nfs/pnfs.c
fs/nfs/pnfs.h
39 files changed, 4268 insertions, 1041 deletions
diff --git a/Documentation/filesystems/nfs/pnfs.txt b/Documentation/filesystems/nfs/pnfs.txt index adc81a35fe2d..44a9f2493a88 100644 --- a/Documentation/filesystems/nfs/pnfs.txt +++ b/Documentation/filesystems/nfs/pnfs.txt | |||
| @@ -57,15 +57,16 @@ bit is set, preventing any new lsegs from being added. | |||
| 57 | layout drivers | 57 | layout drivers |
| 58 | -------------- | 58 | -------------- |
| 59 | 59 | ||
| 60 | PNFS utilizes what is called layout drivers. The STD defines 3 basic | 60 | PNFS utilizes what is called layout drivers. The STD defines 4 basic |
| 61 | layout types: "files" "objects" and "blocks". For each of these types | 61 | layout types: "files", "objects", "blocks", and "flexfiles". For each |
| 62 | there is a layout-driver with a common function-vectors table which | 62 | of these types there is a layout-driver with a common function-vectors |
| 63 | are called by the nfs-client pnfs-core to implement the different layout | 63 | table which are called by the nfs-client pnfs-core to implement the |
| 64 | types. | 64 | different layout types. |
| 65 | 65 | ||
| 66 | Files-layout-driver code is in: fs/nfs/nfs4filelayout.c && nfs4filelayoutdev.c | 66 | Files-layout-driver code is in: fs/nfs/filelayout/.. directory |
| 67 | Objects-layout-deriver code is in: fs/nfs/objlayout/.. directory | 67 | Objects-layout-deriver code is in: fs/nfs/objlayout/.. directory |
| 68 | Blocks-layout-deriver code is in: fs/nfs/blocklayout/.. directory | 68 | Blocks-layout-deriver code is in: fs/nfs/blocklayout/.. directory |
| 69 | Flexfiles-layout-driver code is in: fs/nfs/flexfilelayout/.. directory | ||
| 69 | 70 | ||
| 70 | objects-layout setup | 71 | objects-layout setup |
| 71 | -------------------- | 72 | -------------------- |
diff --git a/fs/nfs/Kconfig b/fs/nfs/Kconfig index 3dece03f2fc8..c7abc10279af 100644 --- a/fs/nfs/Kconfig +++ b/fs/nfs/Kconfig | |||
| @@ -128,6 +128,11 @@ config PNFS_OBJLAYOUT | |||
| 128 | depends on NFS_V4_1 && SCSI_OSD_ULD | 128 | depends on NFS_V4_1 && SCSI_OSD_ULD |
| 129 | default NFS_V4 | 129 | default NFS_V4 |
| 130 | 130 | ||
| 131 | config PNFS_FLEXFILE_LAYOUT | ||
| 132 | tristate | ||
| 133 | depends on NFS_V4_1 && NFS_V3 | ||
| 134 | default m | ||
| 135 | |||
| 131 | config NFS_V4_1_IMPLEMENTATION_ID_DOMAIN | 136 | config NFS_V4_1_IMPLEMENTATION_ID_DOMAIN |
| 132 | string "NFSv4.1 Implementation ID Domain" | 137 | string "NFSv4.1 Implementation ID Domain" |
| 133 | depends on NFS_V4_1 | 138 | depends on NFS_V4_1 |
diff --git a/fs/nfs/Makefile b/fs/nfs/Makefile index 04cb830fa09f..1e987acf20c9 100644 --- a/fs/nfs/Makefile +++ b/fs/nfs/Makefile | |||
| @@ -27,9 +27,10 @@ nfsv4-y := nfs4proc.o nfs4xdr.o nfs4state.o nfs4renewd.o nfs4super.o nfs4file.o | |||
| 27 | dns_resolve.o nfs4trace.o | 27 | dns_resolve.o nfs4trace.o |
| 28 | nfsv4-$(CONFIG_NFS_USE_LEGACY_DNS) += cache_lib.o | 28 | nfsv4-$(CONFIG_NFS_USE_LEGACY_DNS) += cache_lib.o |
| 29 | nfsv4-$(CONFIG_SYSCTL) += nfs4sysctl.o | 29 | nfsv4-$(CONFIG_SYSCTL) += nfs4sysctl.o |
| 30 | nfsv4-$(CONFIG_NFS_V4_1) += pnfs.o pnfs_dev.o | 30 | nfsv4-$(CONFIG_NFS_V4_1) += pnfs.o pnfs_dev.o pnfs_nfs.o |
| 31 | nfsv4-$(CONFIG_NFS_V4_2) += nfs42proc.o | 31 | nfsv4-$(CONFIG_NFS_V4_2) += nfs42proc.o |
| 32 | 32 | ||
| 33 | obj-$(CONFIG_PNFS_FILE_LAYOUT) += filelayout/ | 33 | obj-$(CONFIG_PNFS_FILE_LAYOUT) += filelayout/ |
| 34 | obj-$(CONFIG_PNFS_OBJLAYOUT) += objlayout/ | 34 | obj-$(CONFIG_PNFS_OBJLAYOUT) += objlayout/ |
| 35 | obj-$(CONFIG_PNFS_BLOCK) += blocklayout/ | 35 | obj-$(CONFIG_PNFS_BLOCK) += blocklayout/ |
| 36 | obj-$(CONFIG_PNFS_FLEXFILE_LAYOUT) += flexfilelayout/ | ||
diff --git a/fs/nfs/blocklayout/blocklayout.c b/fs/nfs/blocklayout/blocklayout.c index 77fec6a55f57..1cac3c175d18 100644 --- a/fs/nfs/blocklayout/blocklayout.c +++ b/fs/nfs/blocklayout/blocklayout.c | |||
| @@ -860,12 +860,14 @@ static const struct nfs_pageio_ops bl_pg_read_ops = { | |||
| 860 | .pg_init = bl_pg_init_read, | 860 | .pg_init = bl_pg_init_read, |
| 861 | .pg_test = bl_pg_test_read, | 861 | .pg_test = bl_pg_test_read, |
| 862 | .pg_doio = pnfs_generic_pg_readpages, | 862 | .pg_doio = pnfs_generic_pg_readpages, |
| 863 | .pg_cleanup = pnfs_generic_pg_cleanup, | ||
| 863 | }; | 864 | }; |
| 864 | 865 | ||
| 865 | static const struct nfs_pageio_ops bl_pg_write_ops = { | 866 | static const struct nfs_pageio_ops bl_pg_write_ops = { |
| 866 | .pg_init = bl_pg_init_write, | 867 | .pg_init = bl_pg_init_write, |
| 867 | .pg_test = bl_pg_test_write, | 868 | .pg_test = bl_pg_test_write, |
| 868 | .pg_doio = pnfs_generic_pg_writepages, | 869 | .pg_doio = pnfs_generic_pg_writepages, |
| 870 | .pg_cleanup = pnfs_generic_pg_cleanup, | ||
| 869 | }; | 871 | }; |
| 870 | 872 | ||
| 871 | static struct pnfs_layoutdriver_type blocklayout_type = { | 873 | static struct pnfs_layoutdriver_type blocklayout_type = { |
diff --git a/fs/nfs/direct.c b/fs/nfs/direct.c index 294692ff83b1..7077521acdf4 100644 --- a/fs/nfs/direct.c +++ b/fs/nfs/direct.c | |||
| @@ -66,6 +66,10 @@ static struct kmem_cache *nfs_direct_cachep; | |||
| 66 | /* | 66 | /* |
| 67 | * This represents a set of asynchronous requests that we're waiting on | 67 | * This represents a set of asynchronous requests that we're waiting on |
| 68 | */ | 68 | */ |
| 69 | struct nfs_direct_mirror { | ||
| 70 | ssize_t count; | ||
| 71 | }; | ||
| 72 | |||
| 69 | struct nfs_direct_req { | 73 | struct nfs_direct_req { |
| 70 | struct kref kref; /* release manager */ | 74 | struct kref kref; /* release manager */ |
| 71 | 75 | ||
| @@ -78,8 +82,13 @@ struct nfs_direct_req { | |||
| 78 | /* completion state */ | 82 | /* completion state */ |
| 79 | atomic_t io_count; /* i/os we're waiting for */ | 83 | atomic_t io_count; /* i/os we're waiting for */ |
| 80 | spinlock_t lock; /* protect completion state */ | 84 | spinlock_t lock; /* protect completion state */ |
| 85 | |||
| 86 | struct nfs_direct_mirror mirrors[NFS_PAGEIO_DESCRIPTOR_MIRROR_MAX]; | ||
| 87 | int mirror_count; | ||
| 88 | |||
| 81 | ssize_t count, /* bytes actually processed */ | 89 | ssize_t count, /* bytes actually processed */ |
| 82 | bytes_left, /* bytes left to be sent */ | 90 | bytes_left, /* bytes left to be sent */ |
| 91 | io_start, /* start of IO */ | ||
| 83 | error; /* any reported error */ | 92 | error; /* any reported error */ |
| 84 | struct completion completion; /* wait for i/o completion */ | 93 | struct completion completion; /* wait for i/o completion */ |
| 85 | 94 | ||
| @@ -108,26 +117,56 @@ static inline int put_dreq(struct nfs_direct_req *dreq) | |||
| 108 | return atomic_dec_and_test(&dreq->io_count); | 117 | return atomic_dec_and_test(&dreq->io_count); |
| 109 | } | 118 | } |
| 110 | 119 | ||
| 120 | void nfs_direct_set_resched_writes(struct nfs_direct_req *dreq) | ||
| 121 | { | ||
| 122 | dreq->flags = NFS_ODIRECT_RESCHED_WRITES; | ||
| 123 | } | ||
| 124 | EXPORT_SYMBOL_GPL(nfs_direct_set_resched_writes); | ||
| 125 | |||
| 126 | static void | ||
| 127 | nfs_direct_good_bytes(struct nfs_direct_req *dreq, struct nfs_pgio_header *hdr) | ||
| 128 | { | ||
| 129 | int i; | ||
| 130 | ssize_t count; | ||
| 131 | |||
| 132 | WARN_ON_ONCE(hdr->pgio_mirror_idx >= dreq->mirror_count); | ||
| 133 | |||
| 134 | count = dreq->mirrors[hdr->pgio_mirror_idx].count; | ||
| 135 | if (count + dreq->io_start < hdr->io_start + hdr->good_bytes) { | ||
| 136 | count = hdr->io_start + hdr->good_bytes - dreq->io_start; | ||
| 137 | dreq->mirrors[hdr->pgio_mirror_idx].count = count; | ||
| 138 | } | ||
| 139 | |||
| 140 | /* update the dreq->count by finding the minimum agreed count from all | ||
| 141 | * mirrors */ | ||
| 142 | count = dreq->mirrors[0].count; | ||
| 143 | |||
| 144 | for (i = 1; i < dreq->mirror_count; i++) | ||
| 145 | count = min(count, dreq->mirrors[i].count); | ||
| 146 | |||
| 147 | dreq->count = count; | ||
| 148 | } | ||
| 149 | |||
| 111 | /* | 150 | /* |
| 112 | * nfs_direct_select_verf - select the right verifier | 151 | * nfs_direct_select_verf - select the right verifier |
| 113 | * @dreq - direct request possibly spanning multiple servers | 152 | * @dreq - direct request possibly spanning multiple servers |
| 114 | * @ds_clp - nfs_client of data server or NULL if MDS / non-pnfs | 153 | * @ds_clp - nfs_client of data server or NULL if MDS / non-pnfs |
| 115 | * @ds_idx - index of data server in data server list, only valid if ds_clp set | 154 | * @commit_idx - commit bucket index for the DS |
| 116 | * | 155 | * |
| 117 | * returns the correct verifier to use given the role of the server | 156 | * returns the correct verifier to use given the role of the server |
| 118 | */ | 157 | */ |
| 119 | static struct nfs_writeverf * | 158 | static struct nfs_writeverf * |
| 120 | nfs_direct_select_verf(struct nfs_direct_req *dreq, | 159 | nfs_direct_select_verf(struct nfs_direct_req *dreq, |
| 121 | struct nfs_client *ds_clp, | 160 | struct nfs_client *ds_clp, |
| 122 | int ds_idx) | 161 | int commit_idx) |
| 123 | { | 162 | { |
| 124 | struct nfs_writeverf *verfp = &dreq->verf; | 163 | struct nfs_writeverf *verfp = &dreq->verf; |
| 125 | 164 | ||
| 126 | #ifdef CONFIG_NFS_V4_1 | 165 | #ifdef CONFIG_NFS_V4_1 |
| 127 | if (ds_clp) { | 166 | if (ds_clp) { |
| 128 | /* pNFS is in use, use the DS verf */ | 167 | /* pNFS is in use, use the DS verf */ |
| 129 | if (ds_idx >= 0 && ds_idx < dreq->ds_cinfo.nbuckets) | 168 | if (commit_idx >= 0 && commit_idx < dreq->ds_cinfo.nbuckets) |
| 130 | verfp = &dreq->ds_cinfo.buckets[ds_idx].direct_verf; | 169 | verfp = &dreq->ds_cinfo.buckets[commit_idx].direct_verf; |
| 131 | else | 170 | else |
| 132 | WARN_ON_ONCE(1); | 171 | WARN_ON_ONCE(1); |
| 133 | } | 172 | } |
| @@ -148,8 +187,7 @@ static void nfs_direct_set_hdr_verf(struct nfs_direct_req *dreq, | |||
| 148 | { | 187 | { |
| 149 | struct nfs_writeverf *verfp; | 188 | struct nfs_writeverf *verfp; |
| 150 | 189 | ||
| 151 | verfp = nfs_direct_select_verf(dreq, hdr->ds_clp, | 190 | verfp = nfs_direct_select_verf(dreq, hdr->ds_clp, hdr->ds_commit_idx); |
| 152 | hdr->ds_idx); | ||
| 153 | WARN_ON_ONCE(verfp->committed >= 0); | 191 | WARN_ON_ONCE(verfp->committed >= 0); |
| 154 | memcpy(verfp, &hdr->verf, sizeof(struct nfs_writeverf)); | 192 | memcpy(verfp, &hdr->verf, sizeof(struct nfs_writeverf)); |
| 155 | WARN_ON_ONCE(verfp->committed < 0); | 193 | WARN_ON_ONCE(verfp->committed < 0); |
| @@ -169,8 +207,7 @@ static int nfs_direct_set_or_cmp_hdr_verf(struct nfs_direct_req *dreq, | |||
| 169 | { | 207 | { |
| 170 | struct nfs_writeverf *verfp; | 208 | struct nfs_writeverf *verfp; |
| 171 | 209 | ||
| 172 | verfp = nfs_direct_select_verf(dreq, hdr->ds_clp, | 210 | verfp = nfs_direct_select_verf(dreq, hdr->ds_clp, hdr->ds_commit_idx); |
| 173 | hdr->ds_idx); | ||
| 174 | if (verfp->committed < 0) { | 211 | if (verfp->committed < 0) { |
| 175 | nfs_direct_set_hdr_verf(dreq, hdr); | 212 | nfs_direct_set_hdr_verf(dreq, hdr); |
| 176 | return 0; | 213 | return 0; |
| @@ -193,7 +230,11 @@ static int nfs_direct_cmp_commit_data_verf(struct nfs_direct_req *dreq, | |||
| 193 | 230 | ||
| 194 | verfp = nfs_direct_select_verf(dreq, data->ds_clp, | 231 | verfp = nfs_direct_select_verf(dreq, data->ds_clp, |
| 195 | data->ds_commit_index); | 232 | data->ds_commit_index); |
| 196 | WARN_ON_ONCE(verfp->committed < 0); | 233 | |
| 234 | /* verifier not set so always fail */ | ||
| 235 | if (verfp->committed < 0) | ||
| 236 | return 1; | ||
| 237 | |||
| 197 | return memcmp(verfp, &data->verf, sizeof(struct nfs_writeverf)); | 238 | return memcmp(verfp, &data->verf, sizeof(struct nfs_writeverf)); |
| 198 | } | 239 | } |
| 199 | 240 | ||
| @@ -249,6 +290,18 @@ void nfs_init_cinfo_from_dreq(struct nfs_commit_info *cinfo, | |||
| 249 | cinfo->completion_ops = &nfs_direct_commit_completion_ops; | 290 | cinfo->completion_ops = &nfs_direct_commit_completion_ops; |
| 250 | } | 291 | } |
| 251 | 292 | ||
| 293 | static inline void nfs_direct_setup_mirroring(struct nfs_direct_req *dreq, | ||
| 294 | struct nfs_pageio_descriptor *pgio, | ||
| 295 | struct nfs_page *req) | ||
| 296 | { | ||
| 297 | int mirror_count = 1; | ||
| 298 | |||
| 299 | if (pgio->pg_ops->pg_get_mirror_count) | ||
| 300 | mirror_count = pgio->pg_ops->pg_get_mirror_count(pgio, req); | ||
| 301 | |||
| 302 | dreq->mirror_count = mirror_count; | ||
| 303 | } | ||
| 304 | |||
| 252 | static inline struct nfs_direct_req *nfs_direct_req_alloc(void) | 305 | static inline struct nfs_direct_req *nfs_direct_req_alloc(void) |
| 253 | { | 306 | { |
| 254 | struct nfs_direct_req *dreq; | 307 | struct nfs_direct_req *dreq; |
| @@ -263,6 +316,7 @@ static inline struct nfs_direct_req *nfs_direct_req_alloc(void) | |||
| 263 | INIT_LIST_HEAD(&dreq->mds_cinfo.list); | 316 | INIT_LIST_HEAD(&dreq->mds_cinfo.list); |
| 264 | dreq->verf.committed = NFS_INVALID_STABLE_HOW; /* not set yet */ | 317 | dreq->verf.committed = NFS_INVALID_STABLE_HOW; /* not set yet */ |
| 265 | INIT_WORK(&dreq->work, nfs_direct_write_schedule_work); | 318 | INIT_WORK(&dreq->work, nfs_direct_write_schedule_work); |
| 319 | dreq->mirror_count = 1; | ||
| 266 | spin_lock_init(&dreq->lock); | 320 | spin_lock_init(&dreq->lock); |
| 267 | 321 | ||
| 268 | return dreq; | 322 | return dreq; |
| @@ -369,7 +423,8 @@ static void nfs_direct_read_completion(struct nfs_pgio_header *hdr) | |||
| 369 | if (test_bit(NFS_IOHDR_ERROR, &hdr->flags) && (hdr->good_bytes == 0)) | 423 | if (test_bit(NFS_IOHDR_ERROR, &hdr->flags) && (hdr->good_bytes == 0)) |
| 370 | dreq->error = hdr->error; | 424 | dreq->error = hdr->error; |
| 371 | else | 425 | else |
| 372 | dreq->count += hdr->good_bytes; | 426 | nfs_direct_good_bytes(dreq, hdr); |
| 427 | |||
| 373 | spin_unlock(&dreq->lock); | 428 | spin_unlock(&dreq->lock); |
| 374 | 429 | ||
| 375 | while (!list_empty(&hdr->pages)) { | 430 | while (!list_empty(&hdr->pages)) { |
| @@ -547,6 +602,7 @@ ssize_t nfs_file_direct_read(struct kiocb *iocb, struct iov_iter *iter, | |||
| 547 | 602 | ||
| 548 | dreq->inode = inode; | 603 | dreq->inode = inode; |
| 549 | dreq->bytes_left = count; | 604 | dreq->bytes_left = count; |
| 605 | dreq->io_start = pos; | ||
| 550 | dreq->ctx = get_nfs_open_context(nfs_file_open_context(iocb->ki_filp)); | 606 | dreq->ctx = get_nfs_open_context(nfs_file_open_context(iocb->ki_filp)); |
| 551 | l_ctx = nfs_get_lock_context(dreq->ctx); | 607 | l_ctx = nfs_get_lock_context(dreq->ctx); |
| 552 | if (IS_ERR(l_ctx)) { | 608 | if (IS_ERR(l_ctx)) { |
| @@ -579,6 +635,20 @@ out: | |||
| 579 | return result; | 635 | return result; |
| 580 | } | 636 | } |
| 581 | 637 | ||
| 638 | static void | ||
| 639 | nfs_direct_write_scan_commit_list(struct inode *inode, | ||
| 640 | struct list_head *list, | ||
| 641 | struct nfs_commit_info *cinfo) | ||
| 642 | { | ||
| 643 | spin_lock(cinfo->lock); | ||
| 644 | #ifdef CONFIG_NFS_V4_1 | ||
| 645 | if (cinfo->ds != NULL && cinfo->ds->nwritten != 0) | ||
| 646 | NFS_SERVER(inode)->pnfs_curr_ld->recover_commit_reqs(list, cinfo); | ||
| 647 | #endif | ||
| 648 | nfs_scan_commit_list(&cinfo->mds->list, list, cinfo, 0); | ||
| 649 | spin_unlock(cinfo->lock); | ||
| 650 | } | ||
| 651 | |||
| 582 | static void nfs_direct_write_reschedule(struct nfs_direct_req *dreq) | 652 | static void nfs_direct_write_reschedule(struct nfs_direct_req *dreq) |
| 583 | { | 653 | { |
| 584 | struct nfs_pageio_descriptor desc; | 654 | struct nfs_pageio_descriptor desc; |
| @@ -586,20 +656,23 @@ static void nfs_direct_write_reschedule(struct nfs_direct_req *dreq) | |||
| 586 | LIST_HEAD(reqs); | 656 | LIST_HEAD(reqs); |
| 587 | struct nfs_commit_info cinfo; | 657 | struct nfs_commit_info cinfo; |
| 588 | LIST_HEAD(failed); | 658 | LIST_HEAD(failed); |
| 659 | int i; | ||
| 589 | 660 | ||
| 590 | nfs_init_cinfo_from_dreq(&cinfo, dreq); | 661 | nfs_init_cinfo_from_dreq(&cinfo, dreq); |
| 591 | pnfs_recover_commit_reqs(dreq->inode, &reqs, &cinfo); | 662 | nfs_direct_write_scan_commit_list(dreq->inode, &reqs, &cinfo); |
| 592 | spin_lock(cinfo.lock); | ||
| 593 | nfs_scan_commit_list(&cinfo.mds->list, &reqs, &cinfo, 0); | ||
| 594 | spin_unlock(cinfo.lock); | ||
| 595 | 663 | ||
| 596 | dreq->count = 0; | 664 | dreq->count = 0; |
| 665 | for (i = 0; i < dreq->mirror_count; i++) | ||
| 666 | dreq->mirrors[i].count = 0; | ||
| 597 | get_dreq(dreq); | 667 | get_dreq(dreq); |
| 598 | 668 | ||
| 599 | nfs_pageio_init_write(&desc, dreq->inode, FLUSH_STABLE, false, | 669 | nfs_pageio_init_write(&desc, dreq->inode, FLUSH_STABLE, false, |
| 600 | &nfs_direct_write_completion_ops); | 670 | &nfs_direct_write_completion_ops); |
| 601 | desc.pg_dreq = dreq; | 671 | desc.pg_dreq = dreq; |
| 602 | 672 | ||
| 673 | req = nfs_list_entry(reqs.next); | ||
| 674 | nfs_direct_setup_mirroring(dreq, &desc, req); | ||
| 675 | |||
| 603 | list_for_each_entry_safe(req, tmp, &reqs, wb_list) { | 676 | list_for_each_entry_safe(req, tmp, &reqs, wb_list) { |
| 604 | if (!nfs_pageio_add_request(&desc, req)) { | 677 | if (!nfs_pageio_add_request(&desc, req)) { |
| 605 | nfs_list_remove_request(req); | 678 | nfs_list_remove_request(req); |
| @@ -646,7 +719,7 @@ static void nfs_direct_commit_complete(struct nfs_commit_data *data) | |||
| 646 | nfs_list_remove_request(req); | 719 | nfs_list_remove_request(req); |
| 647 | if (dreq->flags == NFS_ODIRECT_RESCHED_WRITES) { | 720 | if (dreq->flags == NFS_ODIRECT_RESCHED_WRITES) { |
| 648 | /* Note the rewrite will go through mds */ | 721 | /* Note the rewrite will go through mds */ |
| 649 | nfs_mark_request_commit(req, NULL, &cinfo); | 722 | nfs_mark_request_commit(req, NULL, &cinfo, 0); |
| 650 | } else | 723 | } else |
| 651 | nfs_release_request(req); | 724 | nfs_release_request(req); |
| 652 | nfs_unlock_and_release_request(req); | 725 | nfs_unlock_and_release_request(req); |
| @@ -721,7 +794,7 @@ static void nfs_direct_write_completion(struct nfs_pgio_header *hdr) | |||
| 721 | dreq->error = hdr->error; | 794 | dreq->error = hdr->error; |
| 722 | } | 795 | } |
| 723 | if (dreq->error == 0) { | 796 | if (dreq->error == 0) { |
| 724 | dreq->count += hdr->good_bytes; | 797 | nfs_direct_good_bytes(dreq, hdr); |
| 725 | if (nfs_write_need_commit(hdr)) { | 798 | if (nfs_write_need_commit(hdr)) { |
| 726 | if (dreq->flags == NFS_ODIRECT_RESCHED_WRITES) | 799 | if (dreq->flags == NFS_ODIRECT_RESCHED_WRITES) |
| 727 | request_commit = true; | 800 | request_commit = true; |
| @@ -745,7 +818,8 @@ static void nfs_direct_write_completion(struct nfs_pgio_header *hdr) | |||
| 745 | nfs_list_remove_request(req); | 818 | nfs_list_remove_request(req); |
| 746 | if (request_commit) { | 819 | if (request_commit) { |
| 747 | kref_get(&req->wb_kref); | 820 | kref_get(&req->wb_kref); |
| 748 | nfs_mark_request_commit(req, hdr->lseg, &cinfo); | 821 | nfs_mark_request_commit(req, hdr->lseg, &cinfo, |
| 822 | hdr->ds_commit_idx); | ||
| 749 | } | 823 | } |
| 750 | nfs_unlock_and_release_request(req); | 824 | nfs_unlock_and_release_request(req); |
| 751 | } | 825 | } |
| @@ -826,6 +900,9 @@ static ssize_t nfs_direct_write_schedule_iovec(struct nfs_direct_req *dreq, | |||
| 826 | result = PTR_ERR(req); | 900 | result = PTR_ERR(req); |
| 827 | break; | 901 | break; |
| 828 | } | 902 | } |
| 903 | |||
| 904 | nfs_direct_setup_mirroring(dreq, &desc, req); | ||
| 905 | |||
| 829 | nfs_lock_request(req); | 906 | nfs_lock_request(req); |
| 830 | req->wb_index = pos >> PAGE_SHIFT; | 907 | req->wb_index = pos >> PAGE_SHIFT; |
| 831 | req->wb_offset = pos & ~PAGE_MASK; | 908 | req->wb_offset = pos & ~PAGE_MASK; |
| @@ -934,6 +1011,7 @@ ssize_t nfs_file_direct_write(struct kiocb *iocb, struct iov_iter *iter, | |||
| 934 | 1011 | ||
| 935 | dreq->inode = inode; | 1012 | dreq->inode = inode; |
| 936 | dreq->bytes_left = count; | 1013 | dreq->bytes_left = count; |
| 1014 | dreq->io_start = pos; | ||
| 937 | dreq->ctx = get_nfs_open_context(nfs_file_open_context(iocb->ki_filp)); | 1015 | dreq->ctx = get_nfs_open_context(nfs_file_open_context(iocb->ki_filp)); |
| 938 | l_ctx = nfs_get_lock_context(dreq->ctx); | 1016 | l_ctx = nfs_get_lock_context(dreq->ctx); |
| 939 | if (IS_ERR(l_ctx)) { | 1017 | if (IS_ERR(l_ctx)) { |
diff --git a/fs/nfs/filelayout/filelayout.c b/fs/nfs/filelayout/filelayout.c index 7afb52f6a25a..3c9769441f36 100644 --- a/fs/nfs/filelayout/filelayout.c +++ b/fs/nfs/filelayout/filelayout.c | |||
| @@ -118,13 +118,6 @@ static void filelayout_reset_read(struct nfs_pgio_header *hdr) | |||
| 118 | } | 118 | } |
| 119 | } | 119 | } |
| 120 | 120 | ||
| 121 | static void filelayout_fenceme(struct inode *inode, struct pnfs_layout_hdr *lo) | ||
| 122 | { | ||
| 123 | if (!test_and_clear_bit(NFS_LAYOUT_RETURN, &lo->plh_flags)) | ||
| 124 | return; | ||
| 125 | pnfs_return_layout(inode); | ||
| 126 | } | ||
| 127 | |||
| 128 | static int filelayout_async_handle_error(struct rpc_task *task, | 121 | static int filelayout_async_handle_error(struct rpc_task *task, |
| 129 | struct nfs4_state *state, | 122 | struct nfs4_state *state, |
| 130 | struct nfs_client *clp, | 123 | struct nfs_client *clp, |
| @@ -207,7 +200,7 @@ static int filelayout_async_handle_error(struct rpc_task *task, | |||
| 207 | dprintk("%s DS connection error %d\n", __func__, | 200 | dprintk("%s DS connection error %d\n", __func__, |
| 208 | task->tk_status); | 201 | task->tk_status); |
| 209 | nfs4_mark_deviceid_unavailable(devid); | 202 | nfs4_mark_deviceid_unavailable(devid); |
| 210 | set_bit(NFS_LAYOUT_RETURN, &lo->plh_flags); | 203 | pnfs_error_mark_layout_for_return(inode, lseg); |
| 211 | rpc_wake_up(&tbl->slot_tbl_waitq); | 204 | rpc_wake_up(&tbl->slot_tbl_waitq); |
| 212 | /* fall through */ | 205 | /* fall through */ |
| 213 | default: | 206 | default: |
| @@ -339,16 +332,6 @@ static void filelayout_read_count_stats(struct rpc_task *task, void *data) | |||
| 339 | rpc_count_iostats(task, NFS_SERVER(hdr->inode)->client->cl_metrics); | 332 | rpc_count_iostats(task, NFS_SERVER(hdr->inode)->client->cl_metrics); |
| 340 | } | 333 | } |
| 341 | 334 | ||
| 342 | static void filelayout_read_release(void *data) | ||
| 343 | { | ||
| 344 | struct nfs_pgio_header *hdr = data; | ||
| 345 | struct pnfs_layout_hdr *lo = hdr->lseg->pls_layout; | ||
| 346 | |||
| 347 | filelayout_fenceme(lo->plh_inode, lo); | ||
| 348 | nfs_put_client(hdr->ds_clp); | ||
| 349 | hdr->mds_ops->rpc_release(data); | ||
| 350 | } | ||
| 351 | |||
| 352 | static int filelayout_write_done_cb(struct rpc_task *task, | 335 | static int filelayout_write_done_cb(struct rpc_task *task, |
| 353 | struct nfs_pgio_header *hdr) | 336 | struct nfs_pgio_header *hdr) |
| 354 | { | 337 | { |
| @@ -371,17 +354,6 @@ static int filelayout_write_done_cb(struct rpc_task *task, | |||
| 371 | return 0; | 354 | return 0; |
| 372 | } | 355 | } |
| 373 | 356 | ||
| 374 | /* Fake up some data that will cause nfs_commit_release to retry the writes. */ | ||
| 375 | static void prepare_to_resend_writes(struct nfs_commit_data *data) | ||
| 376 | { | ||
| 377 | struct nfs_page *first = nfs_list_entry(data->pages.next); | ||
| 378 | |||
| 379 | data->task.tk_status = 0; | ||
| 380 | memcpy(&data->verf.verifier, &first->wb_verf, | ||
| 381 | sizeof(data->verf.verifier)); | ||
| 382 | data->verf.verifier.data[0]++; /* ensure verifier mismatch */ | ||
| 383 | } | ||
| 384 | |||
| 385 | static int filelayout_commit_done_cb(struct rpc_task *task, | 357 | static int filelayout_commit_done_cb(struct rpc_task *task, |
| 386 | struct nfs_commit_data *data) | 358 | struct nfs_commit_data *data) |
| 387 | { | 359 | { |
| @@ -393,7 +365,7 @@ static int filelayout_commit_done_cb(struct rpc_task *task, | |||
| 393 | 365 | ||
| 394 | switch (err) { | 366 | switch (err) { |
| 395 | case -NFS4ERR_RESET_TO_MDS: | 367 | case -NFS4ERR_RESET_TO_MDS: |
| 396 | prepare_to_resend_writes(data); | 368 | pnfs_generic_prepare_to_resend_writes(data); |
| 397 | return -EAGAIN; | 369 | return -EAGAIN; |
| 398 | case -EAGAIN: | 370 | case -EAGAIN: |
| 399 | rpc_restart_call_prepare(task); | 371 | rpc_restart_call_prepare(task); |
| @@ -451,16 +423,6 @@ static void filelayout_write_count_stats(struct rpc_task *task, void *data) | |||
| 451 | rpc_count_iostats(task, NFS_SERVER(hdr->inode)->client->cl_metrics); | 423 | rpc_count_iostats(task, NFS_SERVER(hdr->inode)->client->cl_metrics); |
| 452 | } | 424 | } |
| 453 | 425 | ||
| 454 | static void filelayout_write_release(void *data) | ||
| 455 | { | ||
| 456 | struct nfs_pgio_header *hdr = data; | ||
| 457 | struct pnfs_layout_hdr *lo = hdr->lseg->pls_layout; | ||
| 458 | |||
| 459 | filelayout_fenceme(lo->plh_inode, lo); | ||
| 460 | nfs_put_client(hdr->ds_clp); | ||
| 461 | hdr->mds_ops->rpc_release(data); | ||
| 462 | } | ||
| 463 | |||
| 464 | static void filelayout_commit_prepare(struct rpc_task *task, void *data) | 426 | static void filelayout_commit_prepare(struct rpc_task *task, void *data) |
| 465 | { | 427 | { |
| 466 | struct nfs_commit_data *wdata = data; | 428 | struct nfs_commit_data *wdata = data; |
| @@ -471,14 +433,6 @@ static void filelayout_commit_prepare(struct rpc_task *task, void *data) | |||
| 471 | task); | 433 | task); |
| 472 | } | 434 | } |
| 473 | 435 | ||
| 474 | static void filelayout_write_commit_done(struct rpc_task *task, void *data) | ||
| 475 | { | ||
| 476 | struct nfs_commit_data *wdata = data; | ||
| 477 | |||
| 478 | /* Note this may cause RPC to be resent */ | ||
| 479 | wdata->mds_ops->rpc_call_done(task, data); | ||
| 480 | } | ||
| 481 | |||
| 482 | static void filelayout_commit_count_stats(struct rpc_task *task, void *data) | 436 | static void filelayout_commit_count_stats(struct rpc_task *task, void *data) |
| 483 | { | 437 | { |
| 484 | struct nfs_commit_data *cdata = data; | 438 | struct nfs_commit_data *cdata = data; |
| @@ -486,35 +440,25 @@ static void filelayout_commit_count_stats(struct rpc_task *task, void *data) | |||
| 486 | rpc_count_iostats(task, NFS_SERVER(cdata->inode)->client->cl_metrics); | 440 | rpc_count_iostats(task, NFS_SERVER(cdata->inode)->client->cl_metrics); |
| 487 | } | 441 | } |
| 488 | 442 | ||
| 489 | static void filelayout_commit_release(void *calldata) | ||
| 490 | { | ||
| 491 | struct nfs_commit_data *data = calldata; | ||
| 492 | |||
| 493 | data->completion_ops->completion(data); | ||
| 494 | pnfs_put_lseg(data->lseg); | ||
| 495 | nfs_put_client(data->ds_clp); | ||
| 496 | nfs_commitdata_release(data); | ||
| 497 | } | ||
| 498 | |||
| 499 | static const struct rpc_call_ops filelayout_read_call_ops = { | 443 | static const struct rpc_call_ops filelayout_read_call_ops = { |
| 500 | .rpc_call_prepare = filelayout_read_prepare, | 444 | .rpc_call_prepare = filelayout_read_prepare, |
| 501 | .rpc_call_done = filelayout_read_call_done, | 445 | .rpc_call_done = filelayout_read_call_done, |
| 502 | .rpc_count_stats = filelayout_read_count_stats, | 446 | .rpc_count_stats = filelayout_read_count_stats, |
| 503 | .rpc_release = filelayout_read_release, | 447 | .rpc_release = pnfs_generic_rw_release, |
| 504 | }; | 448 | }; |
| 505 | 449 | ||
| 506 | static const struct rpc_call_ops filelayout_write_call_ops = { | 450 | static const struct rpc_call_ops filelayout_write_call_ops = { |
| 507 | .rpc_call_prepare = filelayout_write_prepare, | 451 | .rpc_call_prepare = filelayout_write_prepare, |
| 508 | .rpc_call_done = filelayout_write_call_done, | 452 | .rpc_call_done = filelayout_write_call_done, |
| 509 | .rpc_count_stats = filelayout_write_count_stats, | 453 | .rpc_count_stats = filelayout_write_count_stats, |
| 510 | .rpc_release = filelayout_write_release, | 454 | .rpc_release = pnfs_generic_rw_release, |
| 511 | }; | 455 | }; |
| 512 | 456 | ||
| 513 | static const struct rpc_call_ops filelayout_commit_call_ops = { | 457 | static const struct rpc_call_ops filelayout_commit_call_ops = { |
| 514 | .rpc_call_prepare = filelayout_commit_prepare, | 458 | .rpc_call_prepare = filelayout_commit_prepare, |
| 515 | .rpc_call_done = filelayout_write_commit_done, | 459 | .rpc_call_done = pnfs_generic_write_commit_done, |
| 516 | .rpc_count_stats = filelayout_commit_count_stats, | 460 | .rpc_count_stats = filelayout_commit_count_stats, |
| 517 | .rpc_release = filelayout_commit_release, | 461 | .rpc_release = pnfs_generic_commit_release, |
| 518 | }; | 462 | }; |
| 519 | 463 | ||
| 520 | static enum pnfs_try_status | 464 | static enum pnfs_try_status |
| @@ -548,7 +492,7 @@ filelayout_read_pagelist(struct nfs_pgio_header *hdr) | |||
| 548 | /* No multipath support. Use first DS */ | 492 | /* No multipath support. Use first DS */ |
| 549 | atomic_inc(&ds->ds_clp->cl_count); | 493 | atomic_inc(&ds->ds_clp->cl_count); |
| 550 | hdr->ds_clp = ds->ds_clp; | 494 | hdr->ds_clp = ds->ds_clp; |
| 551 | hdr->ds_idx = idx; | 495 | hdr->ds_commit_idx = idx; |
| 552 | fh = nfs4_fl_select_ds_fh(lseg, j); | 496 | fh = nfs4_fl_select_ds_fh(lseg, j); |
| 553 | if (fh) | 497 | if (fh) |
| 554 | hdr->args.fh = fh; | 498 | hdr->args.fh = fh; |
| @@ -557,8 +501,9 @@ filelayout_read_pagelist(struct nfs_pgio_header *hdr) | |||
| 557 | hdr->mds_offset = offset; | 501 | hdr->mds_offset = offset; |
| 558 | 502 | ||
| 559 | /* Perform an asynchronous read to ds */ | 503 | /* Perform an asynchronous read to ds */ |
| 560 | nfs_initiate_pgio(ds_clnt, hdr, | 504 | nfs_initiate_pgio(ds_clnt, hdr, hdr->cred, |
| 561 | &filelayout_read_call_ops, 0, RPC_TASK_SOFTCONN); | 505 | NFS_PROTO(hdr->inode), &filelayout_read_call_ops, |
| 506 | 0, RPC_TASK_SOFTCONN); | ||
| 562 | return PNFS_ATTEMPTED; | 507 | return PNFS_ATTEMPTED; |
| 563 | } | 508 | } |
| 564 | 509 | ||
| @@ -591,16 +536,16 @@ filelayout_write_pagelist(struct nfs_pgio_header *hdr, int sync) | |||
| 591 | hdr->pgio_done_cb = filelayout_write_done_cb; | 536 | hdr->pgio_done_cb = filelayout_write_done_cb; |
| 592 | atomic_inc(&ds->ds_clp->cl_count); | 537 | atomic_inc(&ds->ds_clp->cl_count); |
| 593 | hdr->ds_clp = ds->ds_clp; | 538 | hdr->ds_clp = ds->ds_clp; |
| 594 | hdr->ds_idx = idx; | 539 | hdr->ds_commit_idx = idx; |
| 595 | fh = nfs4_fl_select_ds_fh(lseg, j); | 540 | fh = nfs4_fl_select_ds_fh(lseg, j); |
| 596 | if (fh) | 541 | if (fh) |
| 597 | hdr->args.fh = fh; | 542 | hdr->args.fh = fh; |
| 598 | hdr->args.offset = filelayout_get_dserver_offset(lseg, offset); | 543 | hdr->args.offset = filelayout_get_dserver_offset(lseg, offset); |
| 599 | 544 | ||
| 600 | /* Perform an asynchronous write */ | 545 | /* Perform an asynchronous write */ |
| 601 | nfs_initiate_pgio(ds_clnt, hdr, | 546 | nfs_initiate_pgio(ds_clnt, hdr, hdr->cred, |
| 602 | &filelayout_write_call_ops, sync, | 547 | NFS_PROTO(hdr->inode), &filelayout_write_call_ops, |
| 603 | RPC_TASK_SOFTCONN); | 548 | sync, RPC_TASK_SOFTCONN); |
| 604 | return PNFS_ATTEMPTED; | 549 | return PNFS_ATTEMPTED; |
| 605 | } | 550 | } |
| 606 | 551 | ||
| @@ -988,12 +933,14 @@ static const struct nfs_pageio_ops filelayout_pg_read_ops = { | |||
| 988 | .pg_init = filelayout_pg_init_read, | 933 | .pg_init = filelayout_pg_init_read, |
| 989 | .pg_test = filelayout_pg_test, | 934 | .pg_test = filelayout_pg_test, |
| 990 | .pg_doio = pnfs_generic_pg_readpages, | 935 | .pg_doio = pnfs_generic_pg_readpages, |
| 936 | .pg_cleanup = pnfs_generic_pg_cleanup, | ||
| 991 | }; | 937 | }; |
| 992 | 938 | ||
| 993 | static const struct nfs_pageio_ops filelayout_pg_write_ops = { | 939 | static const struct nfs_pageio_ops filelayout_pg_write_ops = { |
| 994 | .pg_init = filelayout_pg_init_write, | 940 | .pg_init = filelayout_pg_init_write, |
| 995 | .pg_test = filelayout_pg_test, | 941 | .pg_test = filelayout_pg_test, |
| 996 | .pg_doio = pnfs_generic_pg_writepages, | 942 | .pg_doio = pnfs_generic_pg_writepages, |
| 943 | .pg_cleanup = pnfs_generic_pg_cleanup, | ||
| 997 | }; | 944 | }; |
| 998 | 945 | ||
| 999 | static u32 select_bucket_index(struct nfs4_filelayout_segment *fl, u32 j) | 946 | static u32 select_bucket_index(struct nfs4_filelayout_segment *fl, u32 j) |
| @@ -1004,37 +951,11 @@ static u32 select_bucket_index(struct nfs4_filelayout_segment *fl, u32 j) | |||
| 1004 | return j; | 951 | return j; |
| 1005 | } | 952 | } |
| 1006 | 953 | ||
| 1007 | /* The generic layer is about to remove the req from the commit list. | ||
| 1008 | * If this will make the bucket empty, it will need to put the lseg reference. | ||
| 1009 | * Note this is must be called holding the inode (/cinfo) lock | ||
| 1010 | */ | ||
| 1011 | static void | ||
| 1012 | filelayout_clear_request_commit(struct nfs_page *req, | ||
| 1013 | struct nfs_commit_info *cinfo) | ||
| 1014 | { | ||
| 1015 | struct pnfs_layout_segment *freeme = NULL; | ||
| 1016 | |||
| 1017 | if (!test_and_clear_bit(PG_COMMIT_TO_DS, &req->wb_flags)) | ||
| 1018 | goto out; | ||
| 1019 | cinfo->ds->nwritten--; | ||
| 1020 | if (list_is_singular(&req->wb_list)) { | ||
| 1021 | struct pnfs_commit_bucket *bucket; | ||
| 1022 | |||
| 1023 | bucket = list_first_entry(&req->wb_list, | ||
| 1024 | struct pnfs_commit_bucket, | ||
| 1025 | written); | ||
| 1026 | freeme = bucket->wlseg; | ||
| 1027 | bucket->wlseg = NULL; | ||
| 1028 | } | ||
| 1029 | out: | ||
| 1030 | nfs_request_remove_commit_list(req, cinfo); | ||
| 1031 | pnfs_put_lseg_locked(freeme); | ||
| 1032 | } | ||
| 1033 | |||
| 1034 | static void | 954 | static void |
| 1035 | filelayout_mark_request_commit(struct nfs_page *req, | 955 | filelayout_mark_request_commit(struct nfs_page *req, |
| 1036 | struct pnfs_layout_segment *lseg, | 956 | struct pnfs_layout_segment *lseg, |
| 1037 | struct nfs_commit_info *cinfo) | 957 | struct nfs_commit_info *cinfo, |
| 958 | u32 ds_commit_idx) | ||
| 1038 | 959 | ||
| 1039 | { | 960 | { |
| 1040 | struct nfs4_filelayout_segment *fl = FILELAYOUT_LSEG(lseg); | 961 | struct nfs4_filelayout_segment *fl = FILELAYOUT_LSEG(lseg); |
| @@ -1064,7 +985,7 @@ filelayout_mark_request_commit(struct nfs_page *req, | |||
| 1064 | * is normally transferred to the COMMIT call and released | 985 | * is normally transferred to the COMMIT call and released |
| 1065 | * there. It could also be released if the last req is pulled | 986 | * there. It could also be released if the last req is pulled |
| 1066 | * off due to a rewrite, in which case it will be done in | 987 | * off due to a rewrite, in which case it will be done in |
| 1067 | * filelayout_clear_request_commit | 988 | * pnfs_generic_clear_request_commit |
| 1068 | */ | 989 | */ |
| 1069 | buckets[i].wlseg = pnfs_get_lseg(lseg); | 990 | buckets[i].wlseg = pnfs_get_lseg(lseg); |
| 1070 | } | 991 | } |
| @@ -1138,101 +1059,15 @@ static int filelayout_initiate_commit(struct nfs_commit_data *data, int how) | |||
| 1138 | fh = select_ds_fh_from_commit(lseg, data->ds_commit_index); | 1059 | fh = select_ds_fh_from_commit(lseg, data->ds_commit_index); |
| 1139 | if (fh) | 1060 | if (fh) |
| 1140 | data->args.fh = fh; | 1061 | data->args.fh = fh; |
| 1141 | return nfs_initiate_commit(ds_clnt, data, | 1062 | return nfs_initiate_commit(ds_clnt, data, NFS_PROTO(data->inode), |
| 1142 | &filelayout_commit_call_ops, how, | 1063 | &filelayout_commit_call_ops, how, |
| 1143 | RPC_TASK_SOFTCONN); | 1064 | RPC_TASK_SOFTCONN); |
| 1144 | out_err: | 1065 | out_err: |
| 1145 | prepare_to_resend_writes(data); | 1066 | pnfs_generic_prepare_to_resend_writes(data); |
| 1146 | filelayout_commit_release(data); | 1067 | pnfs_generic_commit_release(data); |
| 1147 | return -EAGAIN; | 1068 | return -EAGAIN; |
| 1148 | } | 1069 | } |
| 1149 | 1070 | ||
| 1150 | static int | ||
| 1151 | transfer_commit_list(struct list_head *src, struct list_head *dst, | ||
| 1152 | struct nfs_commit_info *cinfo, int max) | ||
| 1153 | { | ||
| 1154 | struct nfs_page *req, *tmp; | ||
| 1155 | int ret = 0; | ||
| 1156 | |||
| 1157 | list_for_each_entry_safe(req, tmp, src, wb_list) { | ||
| 1158 | if (!nfs_lock_request(req)) | ||
| 1159 | continue; | ||
| 1160 | kref_get(&req->wb_kref); | ||
| 1161 | if (cond_resched_lock(cinfo->lock)) | ||
| 1162 | list_safe_reset_next(req, tmp, wb_list); | ||
| 1163 | nfs_request_remove_commit_list(req, cinfo); | ||
| 1164 | clear_bit(PG_COMMIT_TO_DS, &req->wb_flags); | ||
| 1165 | nfs_list_add_request(req, dst); | ||
| 1166 | ret++; | ||
| 1167 | if ((ret == max) && !cinfo->dreq) | ||
| 1168 | break; | ||
| 1169 | } | ||
| 1170 | return ret; | ||
| 1171 | } | ||
| 1172 | |||
| 1173 | /* Note called with cinfo->lock held. */ | ||
| 1174 | static int | ||
| 1175 | filelayout_scan_ds_commit_list(struct pnfs_commit_bucket *bucket, | ||
| 1176 | struct nfs_commit_info *cinfo, | ||
| 1177 | int max) | ||
| 1178 | { | ||
| 1179 | struct list_head *src = &bucket->written; | ||
| 1180 | struct list_head *dst = &bucket->committing; | ||
| 1181 | int ret; | ||
| 1182 | |||
| 1183 | ret = transfer_commit_list(src, dst, cinfo, max); | ||
| 1184 | if (ret) { | ||
| 1185 | cinfo->ds->nwritten -= ret; | ||
| 1186 | cinfo->ds->ncommitting += ret; | ||
| 1187 | bucket->clseg = bucket->wlseg; | ||
| 1188 | if (list_empty(src)) | ||
| 1189 | bucket->wlseg = NULL; | ||
| 1190 | else | ||
| 1191 | pnfs_get_lseg(bucket->clseg); | ||
| 1192 | } | ||
| 1193 | return ret; | ||
| 1194 | } | ||
| 1195 | |||
| 1196 | /* Move reqs from written to committing lists, returning count of number moved. | ||
| 1197 | * Note called with cinfo->lock held. | ||
| 1198 | */ | ||
| 1199 | static int filelayout_scan_commit_lists(struct nfs_commit_info *cinfo, | ||
| 1200 | int max) | ||
| 1201 | { | ||
| 1202 | int i, rv = 0, cnt; | ||
| 1203 | |||
| 1204 | for (i = 0; i < cinfo->ds->nbuckets && max != 0; i++) { | ||
| 1205 | cnt = filelayout_scan_ds_commit_list(&cinfo->ds->buckets[i], | ||
| 1206 | cinfo, max); | ||
| 1207 | max -= cnt; | ||
| 1208 | rv += cnt; | ||
| 1209 | } | ||
| 1210 | return rv; | ||
| 1211 | } | ||
| 1212 | |||
| 1213 | /* Pull everything off the committing lists and dump into @dst */ | ||
| 1214 | static void filelayout_recover_commit_reqs(struct list_head *dst, | ||
| 1215 | struct nfs_commit_info *cinfo) | ||
| 1216 | { | ||
| 1217 | struct pnfs_commit_bucket *b; | ||
| 1218 | struct pnfs_layout_segment *freeme; | ||
| 1219 | int i; | ||
| 1220 | |||
| 1221 | restart: | ||
| 1222 | spin_lock(cinfo->lock); | ||
| 1223 | for (i = 0, b = cinfo->ds->buckets; i < cinfo->ds->nbuckets; i++, b++) { | ||
| 1224 | if (transfer_commit_list(&b->written, dst, cinfo, 0)) { | ||
| 1225 | freeme = b->wlseg; | ||
| 1226 | b->wlseg = NULL; | ||
| 1227 | spin_unlock(cinfo->lock); | ||
| 1228 | pnfs_put_lseg(freeme); | ||
| 1229 | goto restart; | ||
| 1230 | } | ||
| 1231 | } | ||
| 1232 | cinfo->ds->nwritten = 0; | ||
| 1233 | spin_unlock(cinfo->lock); | ||
| 1234 | } | ||
| 1235 | |||
| 1236 | /* filelayout_search_commit_reqs - Search lists in @cinfo for the head reqest | 1071 | /* filelayout_search_commit_reqs - Search lists in @cinfo for the head reqest |
| 1237 | * for @page | 1072 | * for @page |
| 1238 | * @cinfo - commit info for current inode | 1073 | * @cinfo - commit info for current inode |
| @@ -1263,108 +1098,14 @@ filelayout_search_commit_reqs(struct nfs_commit_info *cinfo, struct page *page) | |||
| 1263 | return NULL; | 1098 | return NULL; |
| 1264 | } | 1099 | } |
| 1265 | 1100 | ||
| 1266 | static void filelayout_retry_commit(struct nfs_commit_info *cinfo, int idx) | ||
| 1267 | { | ||
| 1268 | struct pnfs_ds_commit_info *fl_cinfo = cinfo->ds; | ||
| 1269 | struct pnfs_commit_bucket *bucket; | ||
| 1270 | struct pnfs_layout_segment *freeme; | ||
| 1271 | int i; | ||
| 1272 | |||
| 1273 | for (i = idx; i < fl_cinfo->nbuckets; i++) { | ||
| 1274 | bucket = &fl_cinfo->buckets[i]; | ||
| 1275 | if (list_empty(&bucket->committing)) | ||
| 1276 | continue; | ||
| 1277 | nfs_retry_commit(&bucket->committing, bucket->clseg, cinfo); | ||
| 1278 | spin_lock(cinfo->lock); | ||
| 1279 | freeme = bucket->clseg; | ||
| 1280 | bucket->clseg = NULL; | ||
| 1281 | spin_unlock(cinfo->lock); | ||
| 1282 | pnfs_put_lseg(freeme); | ||
| 1283 | } | ||
| 1284 | } | ||
| 1285 | |||
| 1286 | static unsigned int | ||
| 1287 | alloc_ds_commits(struct nfs_commit_info *cinfo, struct list_head *list) | ||
| 1288 | { | ||
| 1289 | struct pnfs_ds_commit_info *fl_cinfo; | ||
| 1290 | struct pnfs_commit_bucket *bucket; | ||
| 1291 | struct nfs_commit_data *data; | ||
| 1292 | int i; | ||
| 1293 | unsigned int nreq = 0; | ||
| 1294 | |||
| 1295 | fl_cinfo = cinfo->ds; | ||
| 1296 | bucket = fl_cinfo->buckets; | ||
| 1297 | for (i = 0; i < fl_cinfo->nbuckets; i++, bucket++) { | ||
| 1298 | if (list_empty(&bucket->committing)) | ||
| 1299 | continue; | ||
| 1300 | data = nfs_commitdata_alloc(); | ||
| 1301 | if (!data) | ||
| 1302 | break; | ||
| 1303 | data->ds_commit_index = i; | ||
| 1304 | spin_lock(cinfo->lock); | ||
| 1305 | data->lseg = bucket->clseg; | ||
| 1306 | bucket->clseg = NULL; | ||
| 1307 | spin_unlock(cinfo->lock); | ||
| 1308 | list_add(&data->pages, list); | ||
| 1309 | nreq++; | ||
| 1310 | } | ||
| 1311 | |||
| 1312 | /* Clean up on error */ | ||
| 1313 | filelayout_retry_commit(cinfo, i); | ||
| 1314 | /* Caller will clean up entries put on list */ | ||
| 1315 | return nreq; | ||
| 1316 | } | ||
| 1317 | |||
| 1318 | /* This follows nfs_commit_list pretty closely */ | ||
| 1319 | static int | 1101 | static int |
| 1320 | filelayout_commit_pagelist(struct inode *inode, struct list_head *mds_pages, | 1102 | filelayout_commit_pagelist(struct inode *inode, struct list_head *mds_pages, |
| 1321 | int how, struct nfs_commit_info *cinfo) | 1103 | int how, struct nfs_commit_info *cinfo) |
| 1322 | { | 1104 | { |
| 1323 | struct nfs_commit_data *data, *tmp; | 1105 | return pnfs_generic_commit_pagelist(inode, mds_pages, how, cinfo, |
| 1324 | LIST_HEAD(list); | 1106 | filelayout_initiate_commit); |
| 1325 | unsigned int nreq = 0; | ||
| 1326 | |||
| 1327 | if (!list_empty(mds_pages)) { | ||
| 1328 | data = nfs_commitdata_alloc(); | ||
| 1329 | if (data != NULL) { | ||
| 1330 | data->lseg = NULL; | ||
| 1331 | list_add(&data->pages, &list); | ||
| 1332 | nreq++; | ||
| 1333 | } else { | ||
| 1334 | nfs_retry_commit(mds_pages, NULL, cinfo); | ||
| 1335 | filelayout_retry_commit(cinfo, 0); | ||
| 1336 | cinfo->completion_ops->error_cleanup(NFS_I(inode)); | ||
| 1337 | return -ENOMEM; | ||
| 1338 | } | ||
| 1339 | } | ||
| 1340 | |||
| 1341 | nreq += alloc_ds_commits(cinfo, &list); | ||
| 1342 | |||
| 1343 | if (nreq == 0) { | ||
| 1344 | cinfo->completion_ops->error_cleanup(NFS_I(inode)); | ||
| 1345 | goto out; | ||
| 1346 | } | ||
| 1347 | |||
| 1348 | atomic_add(nreq, &cinfo->mds->rpcs_out); | ||
| 1349 | |||
| 1350 | list_for_each_entry_safe(data, tmp, &list, pages) { | ||
| 1351 | list_del_init(&data->pages); | ||
| 1352 | if (!data->lseg) { | ||
| 1353 | nfs_init_commit(data, mds_pages, NULL, cinfo); | ||
| 1354 | nfs_initiate_commit(NFS_CLIENT(inode), data, | ||
| 1355 | data->mds_ops, how, 0); | ||
| 1356 | } else { | ||
| 1357 | struct pnfs_commit_bucket *buckets; | ||
| 1358 | |||
| 1359 | buckets = cinfo->ds->buckets; | ||
| 1360 | nfs_init_commit(data, &buckets[data->ds_commit_index].committing, data->lseg, cinfo); | ||
| 1361 | filelayout_initiate_commit(data, how); | ||
| 1362 | } | ||
| 1363 | } | ||
| 1364 | out: | ||
| 1365 | cinfo->ds->ncommitting = 0; | ||
| 1366 | return PNFS_ATTEMPTED; | ||
| 1367 | } | 1107 | } |
| 1108 | |||
| 1368 | static struct nfs4_deviceid_node * | 1109 | static struct nfs4_deviceid_node * |
| 1369 | filelayout_alloc_deviceid_node(struct nfs_server *server, | 1110 | filelayout_alloc_deviceid_node(struct nfs_server *server, |
| 1370 | struct pnfs_device *pdev, gfp_t gfp_flags) | 1111 | struct pnfs_device *pdev, gfp_t gfp_flags) |
| @@ -1421,9 +1162,9 @@ static struct pnfs_layoutdriver_type filelayout_type = { | |||
| 1421 | .pg_write_ops = &filelayout_pg_write_ops, | 1162 | .pg_write_ops = &filelayout_pg_write_ops, |
| 1422 | .get_ds_info = &filelayout_get_ds_info, | 1163 | .get_ds_info = &filelayout_get_ds_info, |
| 1423 | .mark_request_commit = filelayout_mark_request_commit, | 1164 | .mark_request_commit = filelayout_mark_request_commit, |
| 1424 | .clear_request_commit = filelayout_clear_request_commit, | 1165 | .clear_request_commit = pnfs_generic_clear_request_commit, |
| 1425 | .scan_commit_lists = filelayout_scan_commit_lists, | 1166 | .scan_commit_lists = pnfs_generic_scan_commit_lists, |
| 1426 | .recover_commit_reqs = filelayout_recover_commit_reqs, | 1167 | .recover_commit_reqs = pnfs_generic_recover_commit_reqs, |
| 1427 | .search_commit_reqs = filelayout_search_commit_reqs, | 1168 | .search_commit_reqs = filelayout_search_commit_reqs, |
| 1428 | .commit_pagelist = filelayout_commit_pagelist, | 1169 | .commit_pagelist = filelayout_commit_pagelist, |
| 1429 | .read_pagelist = filelayout_read_pagelist, | 1170 | .read_pagelist = filelayout_read_pagelist, |
diff --git a/fs/nfs/filelayout/filelayout.h b/fs/nfs/filelayout/filelayout.h index 7c9f800c49d7..2896cb833a11 100644 --- a/fs/nfs/filelayout/filelayout.h +++ b/fs/nfs/filelayout/filelayout.h | |||
| @@ -33,13 +33,6 @@ | |||
| 33 | #include "../pnfs.h" | 33 | #include "../pnfs.h" |
| 34 | 34 | ||
| 35 | /* | 35 | /* |
| 36 | * Default data server connection timeout and retrans vaules. | ||
| 37 | * Set by module paramters dataserver_timeo and dataserver_retrans. | ||
| 38 | */ | ||
| 39 | #define NFS4_DEF_DS_TIMEO 600 /* in tenths of a second */ | ||
| 40 | #define NFS4_DEF_DS_RETRANS 5 | ||
| 41 | |||
| 42 | /* | ||
| 43 | * Field testing shows we need to support up to 4096 stripe indices. | 36 | * Field testing shows we need to support up to 4096 stripe indices. |
| 44 | * We store each index as a u8 (u32 on the wire) to keep the memory footprint | 37 | * We store each index as a u8 (u32 on the wire) to keep the memory footprint |
| 45 | * reasonable. This in turn means we support a maximum of 256 | 38 | * reasonable. This in turn means we support a maximum of 256 |
| @@ -48,32 +41,11 @@ | |||
| 48 | #define NFS4_PNFS_MAX_STRIPE_CNT 4096 | 41 | #define NFS4_PNFS_MAX_STRIPE_CNT 4096 |
| 49 | #define NFS4_PNFS_MAX_MULTI_CNT 256 /* 256 fit into a u8 stripe_index */ | 42 | #define NFS4_PNFS_MAX_MULTI_CNT 256 /* 256 fit into a u8 stripe_index */ |
| 50 | 43 | ||
| 51 | /* error codes for internal use */ | ||
| 52 | #define NFS4ERR_RESET_TO_MDS 12001 | ||
| 53 | |||
| 54 | enum stripetype4 { | 44 | enum stripetype4 { |
| 55 | STRIPE_SPARSE = 1, | 45 | STRIPE_SPARSE = 1, |
| 56 | STRIPE_DENSE = 2 | 46 | STRIPE_DENSE = 2 |
| 57 | }; | 47 | }; |
| 58 | 48 | ||
| 59 | /* Individual ip address */ | ||
| 60 | struct nfs4_pnfs_ds_addr { | ||
| 61 | struct sockaddr_storage da_addr; | ||
| 62 | size_t da_addrlen; | ||
| 63 | struct list_head da_node; /* nfs4_pnfs_dev_hlist dev_dslist */ | ||
| 64 | char *da_remotestr; /* human readable addr+port */ | ||
| 65 | }; | ||
| 66 | |||
| 67 | struct nfs4_pnfs_ds { | ||
| 68 | struct list_head ds_node; /* nfs4_pnfs_dev_hlist dev_dslist */ | ||
| 69 | char *ds_remotestr; /* comma sep list of addrs */ | ||
| 70 | struct list_head ds_addrs; | ||
| 71 | struct nfs_client *ds_clp; | ||
| 72 | atomic_t ds_count; | ||
| 73 | unsigned long ds_state; | ||
| 74 | #define NFS4DS_CONNECTING 0 /* ds is establishing connection */ | ||
| 75 | }; | ||
| 76 | |||
| 77 | struct nfs4_file_layout_dsaddr { | 49 | struct nfs4_file_layout_dsaddr { |
| 78 | struct nfs4_deviceid_node id_node; | 50 | struct nfs4_deviceid_node id_node; |
| 79 | u32 stripe_count; | 51 | u32 stripe_count; |
| @@ -119,17 +91,6 @@ FILELAYOUT_DEVID_NODE(struct pnfs_layout_segment *lseg) | |||
| 119 | return &FILELAYOUT_LSEG(lseg)->dsaddr->id_node; | 91 | return &FILELAYOUT_LSEG(lseg)->dsaddr->id_node; |
| 120 | } | 92 | } |
| 121 | 93 | ||
| 122 | static inline void | ||
| 123 | filelayout_mark_devid_invalid(struct nfs4_deviceid_node *node) | ||
| 124 | { | ||
| 125 | u32 *p = (u32 *)&node->deviceid; | ||
| 126 | |||
| 127 | printk(KERN_WARNING "NFS: Deviceid [%x%x%x%x] marked out of use.\n", | ||
| 128 | p[0], p[1], p[2], p[3]); | ||
| 129 | |||
| 130 | set_bit(NFS_DEVICEID_INVALID, &node->flags); | ||
| 131 | } | ||
| 132 | |||
| 133 | static inline bool | 94 | static inline bool |
| 134 | filelayout_test_devid_invalid(struct nfs4_deviceid_node *node) | 95 | filelayout_test_devid_invalid(struct nfs4_deviceid_node *node) |
| 135 | { | 96 | { |
| @@ -142,7 +103,6 @@ filelayout_test_devid_unavailable(struct nfs4_deviceid_node *node); | |||
| 142 | extern struct nfs_fh * | 103 | extern struct nfs_fh * |
| 143 | nfs4_fl_select_ds_fh(struct pnfs_layout_segment *lseg, u32 j); | 104 | nfs4_fl_select_ds_fh(struct pnfs_layout_segment *lseg, u32 j); |
| 144 | 105 | ||
| 145 | extern void print_ds(struct nfs4_pnfs_ds *ds); | ||
| 146 | u32 nfs4_fl_calc_j_index(struct pnfs_layout_segment *lseg, loff_t offset); | 106 | u32 nfs4_fl_calc_j_index(struct pnfs_layout_segment *lseg, loff_t offset); |
| 147 | u32 nfs4_fl_calc_ds_index(struct pnfs_layout_segment *lseg, u32 j); | 107 | u32 nfs4_fl_calc_ds_index(struct pnfs_layout_segment *lseg, u32 j); |
| 148 | struct nfs4_pnfs_ds *nfs4_fl_prepare_ds(struct pnfs_layout_segment *lseg, | 108 | struct nfs4_pnfs_ds *nfs4_fl_prepare_ds(struct pnfs_layout_segment *lseg, |
diff --git a/fs/nfs/filelayout/filelayoutdev.c b/fs/nfs/filelayout/filelayoutdev.c index bfecac781f19..4f372e224603 100644 --- a/fs/nfs/filelayout/filelayoutdev.c +++ b/fs/nfs/filelayout/filelayoutdev.c | |||
| @@ -31,7 +31,6 @@ | |||
| 31 | #include <linux/nfs_fs.h> | 31 | #include <linux/nfs_fs.h> |
| 32 | #include <linux/vmalloc.h> | 32 | #include <linux/vmalloc.h> |
| 33 | #include <linux/module.h> | 33 | #include <linux/module.h> |
| 34 | #include <linux/sunrpc/addr.h> | ||
| 35 | 34 | ||
| 36 | #include "../internal.h" | 35 | #include "../internal.h" |
| 37 | #include "../nfs4session.h" | 36 | #include "../nfs4session.h" |
| @@ -42,183 +41,6 @@ | |||
| 42 | static unsigned int dataserver_timeo = NFS4_DEF_DS_TIMEO; | 41 | static unsigned int dataserver_timeo = NFS4_DEF_DS_TIMEO; |
| 43 | static unsigned int dataserver_retrans = NFS4_DEF_DS_RETRANS; | 42 | static unsigned int dataserver_retrans = NFS4_DEF_DS_RETRANS; |
| 44 | 43 | ||
| 45 | /* | ||
| 46 | * Data server cache | ||
| 47 | * | ||
| 48 | * Data servers can be mapped to different device ids. | ||
| 49 | * nfs4_pnfs_ds reference counting | ||
| 50 | * - set to 1 on allocation | ||
| 51 | * - incremented when a device id maps a data server already in the cache. | ||
| 52 | * - decremented when deviceid is removed from the cache. | ||
| 53 | */ | ||
| 54 | static DEFINE_SPINLOCK(nfs4_ds_cache_lock); | ||
| 55 | static LIST_HEAD(nfs4_data_server_cache); | ||
| 56 | |||
| 57 | /* Debug routines */ | ||
| 58 | void | ||
| 59 | print_ds(struct nfs4_pnfs_ds *ds) | ||
| 60 | { | ||
| 61 | if (ds == NULL) { | ||
| 62 | printk("%s NULL device\n", __func__); | ||
| 63 | return; | ||
| 64 | } | ||
| 65 | printk(" ds %s\n" | ||
| 66 | " ref count %d\n" | ||
| 67 | " client %p\n" | ||
| 68 | " cl_exchange_flags %x\n", | ||
| 69 | ds->ds_remotestr, | ||
| 70 | atomic_read(&ds->ds_count), ds->ds_clp, | ||
| 71 | ds->ds_clp ? ds->ds_clp->cl_exchange_flags : 0); | ||
| 72 | } | ||
| 73 | |||
| 74 | static bool | ||
| 75 | same_sockaddr(struct sockaddr *addr1, struct sockaddr *addr2) | ||
| 76 | { | ||
| 77 | struct sockaddr_in *a, *b; | ||
| 78 | struct sockaddr_in6 *a6, *b6; | ||
| 79 | |||
| 80 | if (addr1->sa_family != addr2->sa_family) | ||
| 81 | return false; | ||
| 82 | |||
| 83 | switch (addr1->sa_family) { | ||
| 84 | case AF_INET: | ||
| 85 | a = (struct sockaddr_in *)addr1; | ||
| 86 | b = (struct sockaddr_in *)addr2; | ||
| 87 | |||
| 88 | if (a->sin_addr.s_addr == b->sin_addr.s_addr && | ||
| 89 | a->sin_port == b->sin_port) | ||
| 90 | return true; | ||
| 91 | break; | ||
| 92 | |||
| 93 | case AF_INET6: | ||
| 94 | a6 = (struct sockaddr_in6 *)addr1; | ||
| 95 | b6 = (struct sockaddr_in6 *)addr2; | ||
| 96 | |||
| 97 | /* LINKLOCAL addresses must have matching scope_id */ | ||
| 98 | if (ipv6_addr_src_scope(&a6->sin6_addr) == | ||
| 99 | IPV6_ADDR_SCOPE_LINKLOCAL && | ||
| 100 | a6->sin6_scope_id != b6->sin6_scope_id) | ||
| 101 | return false; | ||
| 102 | |||
| 103 | if (ipv6_addr_equal(&a6->sin6_addr, &b6->sin6_addr) && | ||
| 104 | a6->sin6_port == b6->sin6_port) | ||
| 105 | return true; | ||
| 106 | break; | ||
| 107 | |||
| 108 | default: | ||
| 109 | dprintk("%s: unhandled address family: %u\n", | ||
| 110 | __func__, addr1->sa_family); | ||
| 111 | return false; | ||
| 112 | } | ||
| 113 | |||
| 114 | return false; | ||
| 115 | } | ||
| 116 | |||
| 117 | static bool | ||
| 118 | _same_data_server_addrs_locked(const struct list_head *dsaddrs1, | ||
| 119 | const struct list_head *dsaddrs2) | ||
| 120 | { | ||
| 121 | struct nfs4_pnfs_ds_addr *da1, *da2; | ||
| 122 | |||
| 123 | /* step through both lists, comparing as we go */ | ||
| 124 | for (da1 = list_first_entry(dsaddrs1, typeof(*da1), da_node), | ||
| 125 | da2 = list_first_entry(dsaddrs2, typeof(*da2), da_node); | ||
| 126 | da1 != NULL && da2 != NULL; | ||
| 127 | da1 = list_entry(da1->da_node.next, typeof(*da1), da_node), | ||
| 128 | da2 = list_entry(da2->da_node.next, typeof(*da2), da_node)) { | ||
| 129 | if (!same_sockaddr((struct sockaddr *)&da1->da_addr, | ||
| 130 | (struct sockaddr *)&da2->da_addr)) | ||
| 131 | return false; | ||
| 132 | } | ||
| 133 | if (da1 == NULL && da2 == NULL) | ||
| 134 | return true; | ||
| 135 | |||
| 136 | return false; | ||
| 137 | } | ||
| 138 | |||
| 139 | /* | ||
| 140 | * Lookup DS by addresses. nfs4_ds_cache_lock is held | ||
| 141 | */ | ||
| 142 | static struct nfs4_pnfs_ds * | ||
| 143 | _data_server_lookup_locked(const struct list_head *dsaddrs) | ||
| 144 | { | ||
| 145 | struct nfs4_pnfs_ds *ds; | ||
| 146 | |||
| 147 | list_for_each_entry(ds, &nfs4_data_server_cache, ds_node) | ||
| 148 | if (_same_data_server_addrs_locked(&ds->ds_addrs, dsaddrs)) | ||
| 149 | return ds; | ||
| 150 | return NULL; | ||
| 151 | } | ||
| 152 | |||
| 153 | /* | ||
| 154 | * Create an rpc connection to the nfs4_pnfs_ds data server | ||
| 155 | * Currently only supports IPv4 and IPv6 addresses | ||
| 156 | */ | ||
| 157 | static int | ||
| 158 | nfs4_ds_connect(struct nfs_server *mds_srv, struct nfs4_pnfs_ds *ds) | ||
| 159 | { | ||
| 160 | struct nfs_client *clp = ERR_PTR(-EIO); | ||
| 161 | struct nfs4_pnfs_ds_addr *da; | ||
| 162 | int status = 0; | ||
| 163 | |||
| 164 | dprintk("--> %s DS %s au_flavor %d\n", __func__, ds->ds_remotestr, | ||
| 165 | mds_srv->nfs_client->cl_rpcclient->cl_auth->au_flavor); | ||
| 166 | |||
| 167 | list_for_each_entry(da, &ds->ds_addrs, da_node) { | ||
| 168 | dprintk("%s: DS %s: trying address %s\n", | ||
| 169 | __func__, ds->ds_remotestr, da->da_remotestr); | ||
| 170 | |||
| 171 | clp = nfs4_set_ds_client(mds_srv->nfs_client, | ||
| 172 | (struct sockaddr *)&da->da_addr, | ||
| 173 | da->da_addrlen, IPPROTO_TCP, | ||
| 174 | dataserver_timeo, dataserver_retrans); | ||
| 175 | if (!IS_ERR(clp)) | ||
| 176 | break; | ||
| 177 | } | ||
| 178 | |||
| 179 | if (IS_ERR(clp)) { | ||
| 180 | status = PTR_ERR(clp); | ||
| 181 | goto out; | ||
| 182 | } | ||
| 183 | |||
| 184 | status = nfs4_init_ds_session(clp, mds_srv->nfs_client->cl_lease_time); | ||
| 185 | if (status) | ||
| 186 | goto out_put; | ||
| 187 | |||
| 188 | smp_wmb(); | ||
| 189 | ds->ds_clp = clp; | ||
| 190 | dprintk("%s [new] addr: %s\n", __func__, ds->ds_remotestr); | ||
| 191 | out: | ||
| 192 | return status; | ||
| 193 | out_put: | ||
| 194 | nfs_put_client(clp); | ||
| 195 | goto out; | ||
| 196 | } | ||
| 197 | |||
| 198 | static void | ||
| 199 | destroy_ds(struct nfs4_pnfs_ds *ds) | ||
| 200 | { | ||
| 201 | struct nfs4_pnfs_ds_addr *da; | ||
| 202 | |||
| 203 | dprintk("--> %s\n", __func__); | ||
| 204 | ifdebug(FACILITY) | ||
| 205 | print_ds(ds); | ||
| 206 | |||
| 207 | nfs_put_client(ds->ds_clp); | ||
| 208 | |||
| 209 | while (!list_empty(&ds->ds_addrs)) { | ||
| 210 | da = list_first_entry(&ds->ds_addrs, | ||
| 211 | struct nfs4_pnfs_ds_addr, | ||
| 212 | da_node); | ||
| 213 | list_del_init(&da->da_node); | ||
| 214 | kfree(da->da_remotestr); | ||
| 215 | kfree(da); | ||
| 216 | } | ||
| 217 | |||
| 218 | kfree(ds->ds_remotestr); | ||
| 219 | kfree(ds); | ||
| 220 | } | ||
| 221 | |||
| 222 | void | 44 | void |
| 223 | nfs4_fl_free_deviceid(struct nfs4_file_layout_dsaddr *dsaddr) | 45 | nfs4_fl_free_deviceid(struct nfs4_file_layout_dsaddr *dsaddr) |
| 224 | { | 46 | { |
| @@ -229,259 +51,13 @@ nfs4_fl_free_deviceid(struct nfs4_file_layout_dsaddr *dsaddr) | |||
| 229 | 51 | ||
| 230 | for (i = 0; i < dsaddr->ds_num; i++) { | 52 | for (i = 0; i < dsaddr->ds_num; i++) { |
| 231 | ds = dsaddr->ds_list[i]; | 53 | ds = dsaddr->ds_list[i]; |
| 232 | if (ds != NULL) { | 54 | if (ds != NULL) |
| 233 | if (atomic_dec_and_lock(&ds->ds_count, | 55 | nfs4_pnfs_ds_put(ds); |
| 234 | &nfs4_ds_cache_lock)) { | ||
| 235 | list_del_init(&ds->ds_node); | ||
| 236 | spin_unlock(&nfs4_ds_cache_lock); | ||
| 237 | destroy_ds(ds); | ||
| 238 | } | ||
| 239 | } | ||
| 240 | } | 56 | } |
| 241 | kfree(dsaddr->stripe_indices); | 57 | kfree(dsaddr->stripe_indices); |
| 242 | kfree(dsaddr); | 58 | kfree(dsaddr); |
| 243 | } | 59 | } |
| 244 | 60 | ||
| 245 | /* | ||
| 246 | * Create a string with a human readable address and port to avoid | ||
| 247 | * complicated setup around many dprinks. | ||
| 248 | */ | ||
| 249 | static char * | ||
| 250 | nfs4_pnfs_remotestr(struct list_head *dsaddrs, gfp_t gfp_flags) | ||
| 251 | { | ||
| 252 | struct nfs4_pnfs_ds_addr *da; | ||
| 253 | char *remotestr; | ||
| 254 | size_t len; | ||
| 255 | char *p; | ||
| 256 | |||
| 257 | len = 3; /* '{', '}' and eol */ | ||
| 258 | list_for_each_entry(da, dsaddrs, da_node) { | ||
| 259 | len += strlen(da->da_remotestr) + 1; /* string plus comma */ | ||
| 260 | } | ||
| 261 | |||
| 262 | remotestr = kzalloc(len, gfp_flags); | ||
| 263 | if (!remotestr) | ||
| 264 | return NULL; | ||
| 265 | |||
| 266 | p = remotestr; | ||
| 267 | *(p++) = '{'; | ||
| 268 | len--; | ||
| 269 | list_for_each_entry(da, dsaddrs, da_node) { | ||
| 270 | size_t ll = strlen(da->da_remotestr); | ||
| 271 | |||
| 272 | if (ll > len) | ||
| 273 | goto out_err; | ||
| 274 | |||
| 275 | memcpy(p, da->da_remotestr, ll); | ||
| 276 | p += ll; | ||
| 277 | len -= ll; | ||
| 278 | |||
| 279 | if (len < 1) | ||
| 280 | goto out_err; | ||
| 281 | (*p++) = ','; | ||
| 282 | len--; | ||
| 283 | } | ||
| 284 | if (len < 2) | ||
| 285 | goto out_err; | ||
| 286 | *(p++) = '}'; | ||
| 287 | *p = '\0'; | ||
| 288 | return remotestr; | ||
| 289 | out_err: | ||
| 290 | kfree(remotestr); | ||
| 291 | return NULL; | ||
| 292 | } | ||
| 293 | |||
| 294 | static struct nfs4_pnfs_ds * | ||
| 295 | nfs4_pnfs_ds_add(struct list_head *dsaddrs, gfp_t gfp_flags) | ||
| 296 | { | ||
| 297 | struct nfs4_pnfs_ds *tmp_ds, *ds = NULL; | ||
| 298 | char *remotestr; | ||
| 299 | |||
| 300 | if (list_empty(dsaddrs)) { | ||
| 301 | dprintk("%s: no addresses defined\n", __func__); | ||
| 302 | goto out; | ||
| 303 | } | ||
| 304 | |||
| 305 | ds = kzalloc(sizeof(*ds), gfp_flags); | ||
| 306 | if (!ds) | ||
| 307 | goto out; | ||
| 308 | |||
| 309 | /* this is only used for debugging, so it's ok if its NULL */ | ||
| 310 | remotestr = nfs4_pnfs_remotestr(dsaddrs, gfp_flags); | ||
| 311 | |||
| 312 | spin_lock(&nfs4_ds_cache_lock); | ||
| 313 | tmp_ds = _data_server_lookup_locked(dsaddrs); | ||
| 314 | if (tmp_ds == NULL) { | ||
| 315 | INIT_LIST_HEAD(&ds->ds_addrs); | ||
| 316 | list_splice_init(dsaddrs, &ds->ds_addrs); | ||
| 317 | ds->ds_remotestr = remotestr; | ||
| 318 | atomic_set(&ds->ds_count, 1); | ||
| 319 | INIT_LIST_HEAD(&ds->ds_node); | ||
| 320 | ds->ds_clp = NULL; | ||
| 321 | list_add(&ds->ds_node, &nfs4_data_server_cache); | ||
| 322 | dprintk("%s add new data server %s\n", __func__, | ||
| 323 | ds->ds_remotestr); | ||
| 324 | } else { | ||
| 325 | kfree(remotestr); | ||
| 326 | kfree(ds); | ||
| 327 | atomic_inc(&tmp_ds->ds_count); | ||
| 328 | dprintk("%s data server %s found, inc'ed ds_count to %d\n", | ||
| 329 | __func__, tmp_ds->ds_remotestr, | ||
| 330 | atomic_read(&tmp_ds->ds_count)); | ||
| 331 | ds = tmp_ds; | ||
| 332 | } | ||
| 333 | spin_unlock(&nfs4_ds_cache_lock); | ||
| 334 | out: | ||
| 335 | return ds; | ||
| 336 | } | ||
| 337 | |||
| 338 | /* | ||
| 339 | * Currently only supports ipv4, ipv6 and one multi-path address. | ||
| 340 | */ | ||
| 341 | static struct nfs4_pnfs_ds_addr * | ||
| 342 | decode_ds_addr(struct net *net, struct xdr_stream *streamp, gfp_t gfp_flags) | ||
| 343 | { | ||
| 344 | struct nfs4_pnfs_ds_addr *da = NULL; | ||
| 345 | char *buf, *portstr; | ||
| 346 | __be16 port; | ||
| 347 | int nlen, rlen; | ||
| 348 | int tmp[2]; | ||
| 349 | __be32 *p; | ||
| 350 | char *netid, *match_netid; | ||
| 351 | size_t len, match_netid_len; | ||
| 352 | char *startsep = ""; | ||
| 353 | char *endsep = ""; | ||
| 354 | |||
| 355 | |||
| 356 | /* r_netid */ | ||
| 357 | p = xdr_inline_decode(streamp, 4); | ||
| 358 | if (unlikely(!p)) | ||
| 359 | goto out_err; | ||
| 360 | nlen = be32_to_cpup(p++); | ||
| 361 | |||
| 362 | p = xdr_inline_decode(streamp, nlen); | ||
| 363 | if (unlikely(!p)) | ||
| 364 | goto out_err; | ||
| 365 | |||
| 366 | netid = kmalloc(nlen+1, gfp_flags); | ||
| 367 | if (unlikely(!netid)) | ||
| 368 | goto out_err; | ||
| 369 | |||
| 370 | netid[nlen] = '\0'; | ||
| 371 | memcpy(netid, p, nlen); | ||
| 372 | |||
| 373 | /* r_addr: ip/ip6addr with port in dec octets - see RFC 5665 */ | ||
| 374 | p = xdr_inline_decode(streamp, 4); | ||
| 375 | if (unlikely(!p)) | ||
| 376 | goto out_free_netid; | ||
| 377 | rlen = be32_to_cpup(p); | ||
| 378 | |||
| 379 | p = xdr_inline_decode(streamp, rlen); | ||
| 380 | if (unlikely(!p)) | ||
| 381 | goto out_free_netid; | ||
| 382 | |||
| 383 | /* port is ".ABC.DEF", 8 chars max */ | ||
| 384 | if (rlen > INET6_ADDRSTRLEN + IPV6_SCOPE_ID_LEN + 8) { | ||
| 385 | dprintk("%s: Invalid address, length %d\n", __func__, | ||
| 386 | rlen); | ||
| 387 | goto out_free_netid; | ||
| 388 | } | ||
| 389 | buf = kmalloc(rlen + 1, gfp_flags); | ||
| 390 | if (!buf) { | ||
| 391 | dprintk("%s: Not enough memory\n", __func__); | ||
| 392 | goto out_free_netid; | ||
| 393 | } | ||
| 394 | buf[rlen] = '\0'; | ||
| 395 | memcpy(buf, p, rlen); | ||
| 396 | |||
| 397 | /* replace port '.' with '-' */ | ||
| 398 | portstr = strrchr(buf, '.'); | ||
| 399 | if (!portstr) { | ||
| 400 | dprintk("%s: Failed finding expected dot in port\n", | ||
| 401 | __func__); | ||
| 402 | goto out_free_buf; | ||
| 403 | } | ||
| 404 | *portstr = '-'; | ||
| 405 | |||
| 406 | /* find '.' between address and port */ | ||
| 407 | portstr = strrchr(buf, '.'); | ||
| 408 | if (!portstr) { | ||
| 409 | dprintk("%s: Failed finding expected dot between address and " | ||
| 410 | "port\n", __func__); | ||
| 411 | goto out_free_buf; | ||
| 412 | } | ||
| 413 | *portstr = '\0'; | ||
| 414 | |||
| 415 | da = kzalloc(sizeof(*da), gfp_flags); | ||
| 416 | if (unlikely(!da)) | ||
| 417 | goto out_free_buf; | ||
| 418 | |||
| 419 | INIT_LIST_HEAD(&da->da_node); | ||
| 420 | |||
| 421 | if (!rpc_pton(net, buf, portstr-buf, (struct sockaddr *)&da->da_addr, | ||
| 422 | sizeof(da->da_addr))) { | ||
| 423 | dprintk("%s: error parsing address %s\n", __func__, buf); | ||
| 424 | goto out_free_da; | ||
| 425 | } | ||
| 426 | |||
| 427 | portstr++; | ||
| 428 | sscanf(portstr, "%d-%d", &tmp[0], &tmp[1]); | ||
| 429 | port = htons((tmp[0] << 8) | (tmp[1])); | ||
| 430 | |||
| 431 | switch (da->da_addr.ss_family) { | ||
| 432 | case AF_INET: | ||
| 433 | ((struct sockaddr_in *)&da->da_addr)->sin_port = port; | ||
| 434 | da->da_addrlen = sizeof(struct sockaddr_in); | ||
| 435 | match_netid = "tcp"; | ||
| 436 | match_netid_len = 3; | ||
| 437 | break; | ||
| 438 | |||
| 439 | case AF_INET6: | ||
| 440 | ((struct sockaddr_in6 *)&da->da_addr)->sin6_port = port; | ||
| 441 | da->da_addrlen = sizeof(struct sockaddr_in6); | ||
| 442 | match_netid = "tcp6"; | ||
| 443 | match_netid_len = 4; | ||
| 444 | startsep = "["; | ||
| 445 | endsep = "]"; | ||
| 446 | break; | ||
| 447 | |||
| 448 | default: | ||
| 449 | dprintk("%s: unsupported address family: %u\n", | ||
| 450 | __func__, da->da_addr.ss_family); | ||
| 451 | goto out_free_da; | ||
| 452 | } | ||
| 453 | |||
| 454 | if (nlen != match_netid_len || strncmp(netid, match_netid, nlen)) { | ||
| 455 | dprintk("%s: ERROR: r_netid \"%s\" != \"%s\"\n", | ||
| 456 | __func__, netid, match_netid); | ||
| 457 | goto out_free_da; | ||
| 458 | } | ||
| 459 | |||
| 460 | /* save human readable address */ | ||
| 461 | len = strlen(startsep) + strlen(buf) + strlen(endsep) + 7; | ||
| 462 | da->da_remotestr = kzalloc(len, gfp_flags); | ||
| 463 | |||
| 464 | /* NULL is ok, only used for dprintk */ | ||
| 465 | if (da->da_remotestr) | ||
| 466 | snprintf(da->da_remotestr, len, "%s%s%s:%u", startsep, | ||
| 467 | buf, endsep, ntohs(port)); | ||
| 468 | |||
| 469 | dprintk("%s: Parsed DS addr %s\n", __func__, da->da_remotestr); | ||
| 470 | kfree(buf); | ||
| 471 | kfree(netid); | ||
| 472 | return da; | ||
| 473 | |||
| 474 | out_free_da: | ||
| 475 | kfree(da); | ||
| 476 | out_free_buf: | ||
| 477 | dprintk("%s: Error parsing DS addr: %s\n", __func__, buf); | ||
| 478 | kfree(buf); | ||
| 479 | out_free_netid: | ||
| 480 | kfree(netid); | ||
| 481 | out_err: | ||
| 482 | return NULL; | ||
| 483 | } | ||
| 484 | |||
| 485 | /* Decode opaque device data and return the result */ | 61 | /* Decode opaque device data and return the result */ |
| 486 | struct nfs4_file_layout_dsaddr * | 62 | struct nfs4_file_layout_dsaddr * |
| 487 | nfs4_fl_alloc_deviceid_node(struct nfs_server *server, struct pnfs_device *pdev, | 63 | nfs4_fl_alloc_deviceid_node(struct nfs_server *server, struct pnfs_device *pdev, |
| @@ -584,8 +160,8 @@ nfs4_fl_alloc_deviceid_node(struct nfs_server *server, struct pnfs_device *pdev, | |||
| 584 | 160 | ||
| 585 | mp_count = be32_to_cpup(p); /* multipath count */ | 161 | mp_count = be32_to_cpup(p); /* multipath count */ |
| 586 | for (j = 0; j < mp_count; j++) { | 162 | for (j = 0; j < mp_count; j++) { |
| 587 | da = decode_ds_addr(server->nfs_client->cl_net, | 163 | da = nfs4_decode_mp_ds_addr(server->nfs_client->cl_net, |
| 588 | &stream, gfp_flags); | 164 | &stream, gfp_flags); |
| 589 | if (da) | 165 | if (da) |
| 590 | list_add_tail(&da->da_node, &dsaddrs); | 166 | list_add_tail(&da->da_node, &dsaddrs); |
| 591 | } | 167 | } |
| @@ -681,22 +257,7 @@ nfs4_fl_select_ds_fh(struct pnfs_layout_segment *lseg, u32 j) | |||
| 681 | return flseg->fh_array[i]; | 257 | return flseg->fh_array[i]; |
| 682 | } | 258 | } |
| 683 | 259 | ||
| 684 | static void nfs4_wait_ds_connect(struct nfs4_pnfs_ds *ds) | 260 | /* Upon return, either ds is connected, or ds is NULL */ |
| 685 | { | ||
| 686 | might_sleep(); | ||
| 687 | wait_on_bit_action(&ds->ds_state, NFS4DS_CONNECTING, | ||
| 688 | nfs_wait_bit_killable, TASK_KILLABLE); | ||
| 689 | } | ||
| 690 | |||
| 691 | static void nfs4_clear_ds_conn_bit(struct nfs4_pnfs_ds *ds) | ||
| 692 | { | ||
| 693 | smp_mb__before_atomic(); | ||
| 694 | clear_bit(NFS4DS_CONNECTING, &ds->ds_state); | ||
| 695 | smp_mb__after_atomic(); | ||
| 696 | wake_up_bit(&ds->ds_state, NFS4DS_CONNECTING); | ||
| 697 | } | ||
| 698 | |||
| 699 | |||
| 700 | struct nfs4_pnfs_ds * | 261 | struct nfs4_pnfs_ds * |
| 701 | nfs4_fl_prepare_ds(struct pnfs_layout_segment *lseg, u32 ds_idx) | 262 | nfs4_fl_prepare_ds(struct pnfs_layout_segment *lseg, u32 ds_idx) |
| 702 | { | 263 | { |
| @@ -704,29 +265,23 @@ nfs4_fl_prepare_ds(struct pnfs_layout_segment *lseg, u32 ds_idx) | |||
| 704 | struct nfs4_pnfs_ds *ds = dsaddr->ds_list[ds_idx]; | 265 | struct nfs4_pnfs_ds *ds = dsaddr->ds_list[ds_idx]; |
| 705 | struct nfs4_deviceid_node *devid = FILELAYOUT_DEVID_NODE(lseg); | 266 | struct nfs4_deviceid_node *devid = FILELAYOUT_DEVID_NODE(lseg); |
| 706 | struct nfs4_pnfs_ds *ret = ds; | 267 | struct nfs4_pnfs_ds *ret = ds; |
| 268 | struct nfs_server *s = NFS_SERVER(lseg->pls_layout->plh_inode); | ||
| 707 | 269 | ||
| 708 | if (ds == NULL) { | 270 | if (ds == NULL) { |
| 709 | printk(KERN_ERR "NFS: %s: No data server for offset index %d\n", | 271 | printk(KERN_ERR "NFS: %s: No data server for offset index %d\n", |
| 710 | __func__, ds_idx); | 272 | __func__, ds_idx); |
| 711 | filelayout_mark_devid_invalid(devid); | 273 | pnfs_generic_mark_devid_invalid(devid); |
| 712 | goto out; | 274 | goto out; |
| 713 | } | 275 | } |
| 714 | smp_rmb(); | 276 | smp_rmb(); |
| 715 | if (ds->ds_clp) | 277 | if (ds->ds_clp) |
| 716 | goto out_test_devid; | 278 | goto out_test_devid; |
| 717 | 279 | ||
| 718 | if (test_and_set_bit(NFS4DS_CONNECTING, &ds->ds_state) == 0) { | 280 | nfs4_pnfs_ds_connect(s, ds, devid, dataserver_timeo, |
| 719 | struct nfs_server *s = NFS_SERVER(lseg->pls_layout->plh_inode); | 281 | dataserver_retrans, 4, |
| 720 | int err; | 282 | s->nfs_client->cl_minorversion, |
| 721 | 283 | s->nfs_client->cl_rpcclient->cl_auth->au_flavor); | |
| 722 | err = nfs4_ds_connect(s, ds); | 284 | |
| 723 | if (err) | ||
| 724 | nfs4_mark_deviceid_unavailable(devid); | ||
| 725 | nfs4_clear_ds_conn_bit(ds); | ||
| 726 | } else { | ||
| 727 | /* Either ds is connected, or ds is NULL */ | ||
| 728 | nfs4_wait_ds_connect(ds); | ||
| 729 | } | ||
| 730 | out_test_devid: | 285 | out_test_devid: |
| 731 | if (filelayout_test_devid_unavailable(devid)) | 286 | if (filelayout_test_devid_unavailable(devid)) |
| 732 | ret = NULL; | 287 | ret = NULL; |
diff --git a/fs/nfs/flexfilelayout/Makefile b/fs/nfs/flexfilelayout/Makefile new file mode 100644 index 000000000000..1d2c9f6bbcd4 --- /dev/null +++ b/fs/nfs/flexfilelayout/Makefile | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | # | ||
| 2 | # Makefile for the pNFS Flexfile Layout Driver kernel module | ||
| 3 | # | ||
| 4 | obj-$(CONFIG_PNFS_FLEXFILE_LAYOUT) += nfs_layout_flexfiles.o | ||
| 5 | nfs_layout_flexfiles-y := flexfilelayout.o flexfilelayoutdev.o | ||
diff --git a/fs/nfs/flexfilelayout/flexfilelayout.c b/fs/nfs/flexfilelayout/flexfilelayout.c new file mode 100644 index 000000000000..f29fb7d7e8f8 --- /dev/null +++ b/fs/nfs/flexfilelayout/flexfilelayout.c | |||
| @@ -0,0 +1,1574 @@ | |||
| 1 | /* | ||
| 2 | * Module for pnfs flexfile layout driver. | ||
| 3 | * | ||
| 4 | * Copyright (c) 2014, Primary Data, Inc. All rights reserved. | ||
| 5 | * | ||
| 6 | * Tao Peng <bergwolf@primarydata.com> | ||
| 7 | */ | ||
| 8 | |||
| 9 | #include <linux/nfs_fs.h> | ||
| 10 | #include <linux/nfs_page.h> | ||
| 11 | #include <linux/module.h> | ||
| 12 | |||
| 13 | #include <linux/sunrpc/metrics.h> | ||
| 14 | #include <linux/nfs_idmap.h> | ||
| 15 | |||
| 16 | #include "flexfilelayout.h" | ||
| 17 | #include "../nfs4session.h" | ||
| 18 | #include "../internal.h" | ||
| 19 | #include "../delegation.h" | ||
| 20 | #include "../nfs4trace.h" | ||
| 21 | #include "../iostat.h" | ||
| 22 | #include "../nfs.h" | ||
| 23 | |||
| 24 | #define NFSDBG_FACILITY NFSDBG_PNFS_LD | ||
| 25 | |||
| 26 | #define FF_LAYOUT_POLL_RETRY_MAX (15*HZ) | ||
| 27 | |||
| 28 | static struct pnfs_layout_hdr * | ||
| 29 | ff_layout_alloc_layout_hdr(struct inode *inode, gfp_t gfp_flags) | ||
| 30 | { | ||
| 31 | struct nfs4_flexfile_layout *ffl; | ||
| 32 | |||
| 33 | ffl = kzalloc(sizeof(*ffl), gfp_flags); | ||
| 34 | if (ffl) { | ||
| 35 | INIT_LIST_HEAD(&ffl->error_list); | ||
| 36 | return &ffl->generic_hdr; | ||
| 37 | } else | ||
| 38 | return NULL; | ||
| 39 | } | ||
| 40 | |||
| 41 | static void | ||
| 42 | ff_layout_free_layout_hdr(struct pnfs_layout_hdr *lo) | ||
| 43 | { | ||
| 44 | struct nfs4_ff_layout_ds_err *err, *n; | ||
| 45 | |||
| 46 | list_for_each_entry_safe(err, n, &FF_LAYOUT_FROM_HDR(lo)->error_list, | ||
| 47 | list) { | ||
| 48 | list_del(&err->list); | ||
| 49 | kfree(err); | ||
| 50 | } | ||
| 51 | kfree(FF_LAYOUT_FROM_HDR(lo)); | ||
| 52 | } | ||
| 53 | |||
| 54 | static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) | ||
| 55 | { | ||
| 56 | __be32 *p; | ||
| 57 | |||
| 58 | p = xdr_inline_decode(xdr, NFS4_STATEID_SIZE); | ||
| 59 | if (unlikely(p == NULL)) | ||
| 60 | return -ENOBUFS; | ||
| 61 | memcpy(stateid, p, NFS4_STATEID_SIZE); | ||
| 62 | dprintk("%s: stateid id= [%x%x%x%x]\n", __func__, | ||
| 63 | p[0], p[1], p[2], p[3]); | ||
| 64 | return 0; | ||
| 65 | } | ||
| 66 | |||
| 67 | static int decode_deviceid(struct xdr_stream *xdr, struct nfs4_deviceid *devid) | ||
| 68 | { | ||
| 69 | __be32 *p; | ||
| 70 | |||
| 71 | p = xdr_inline_decode(xdr, NFS4_DEVICEID4_SIZE); | ||
| 72 | if (unlikely(!p)) | ||
| 73 | return -ENOBUFS; | ||
| 74 | memcpy(devid, p, NFS4_DEVICEID4_SIZE); | ||
| 75 | nfs4_print_deviceid(devid); | ||
| 76 | return 0; | ||
| 77 | } | ||
| 78 | |||
| 79 | static int decode_nfs_fh(struct xdr_stream *xdr, struct nfs_fh *fh) | ||
| 80 | { | ||
| 81 | __be32 *p; | ||
| 82 | |||
| 83 | p = xdr_inline_decode(xdr, 4); | ||
| 84 | if (unlikely(!p)) | ||
| 85 | return -ENOBUFS; | ||
| 86 | fh->size = be32_to_cpup(p++); | ||
| 87 | if (fh->size > sizeof(struct nfs_fh)) { | ||
| 88 | printk(KERN_ERR "NFS flexfiles: Too big fh received %d\n", | ||
| 89 | fh->size); | ||
| 90 | return -EOVERFLOW; | ||
| 91 | } | ||
| 92 | /* fh.data */ | ||
| 93 | p = xdr_inline_decode(xdr, fh->size); | ||
| 94 | if (unlikely(!p)) | ||
| 95 | return -ENOBUFS; | ||
| 96 | memcpy(&fh->data, p, fh->size); | ||
| 97 | dprintk("%s: fh len %d\n", __func__, fh->size); | ||
| 98 | |||
| 99 | return 0; | ||
| 100 | } | ||
| 101 | |||
| 102 | /* | ||
| 103 | * Currently only stringified uids and gids are accepted. | ||
| 104 | * I.e., kerberos is not supported to the DSes, so no pricipals. | ||
| 105 | * | ||
| 106 | * That means that one common function will suffice, but when | ||
| 107 | * principals are added, this should be split to accomodate | ||
| 108 | * calls to both nfs_map_name_to_uid() and nfs_map_group_to_gid(). | ||
| 109 | */ | ||
| 110 | static int | ||
| 111 | decode_name(struct xdr_stream *xdr, u32 *id) | ||
| 112 | { | ||
| 113 | __be32 *p; | ||
| 114 | int len; | ||
| 115 | |||
| 116 | /* opaque_length(4)*/ | ||
| 117 | p = xdr_inline_decode(xdr, 4); | ||
| 118 | if (unlikely(!p)) | ||
| 119 | return -ENOBUFS; | ||
| 120 | len = be32_to_cpup(p++); | ||
| 121 | if (len < 0) | ||
| 122 | return -EINVAL; | ||
| 123 | |||
| 124 | dprintk("%s: len %u\n", __func__, len); | ||
| 125 | |||
| 126 | /* opaque body */ | ||
| 127 | p = xdr_inline_decode(xdr, len); | ||
| 128 | if (unlikely(!p)) | ||
| 129 | return -ENOBUFS; | ||
| 130 | |||
| 131 | if (!nfs_map_string_to_numeric((char *)p, len, id)) | ||
| 132 | return -EINVAL; | ||
| 133 | |||
| 134 | return 0; | ||
| 135 | } | ||
| 136 | |||
| 137 | static void ff_layout_free_mirror_array(struct nfs4_ff_layout_segment *fls) | ||
| 138 | { | ||
| 139 | int i; | ||
| 140 | |||
| 141 | if (fls->mirror_array) { | ||
| 142 | for (i = 0; i < fls->mirror_array_cnt; i++) { | ||
| 143 | /* normally mirror_ds is freed in | ||
| 144 | * .free_deviceid_node but we still do it here | ||
| 145 | * for .alloc_lseg error path */ | ||
| 146 | if (fls->mirror_array[i]) { | ||
| 147 | kfree(fls->mirror_array[i]->fh_versions); | ||
| 148 | nfs4_ff_layout_put_deviceid(fls->mirror_array[i]->mirror_ds); | ||
| 149 | kfree(fls->mirror_array[i]); | ||
| 150 | } | ||
| 151 | } | ||
| 152 | kfree(fls->mirror_array); | ||
| 153 | fls->mirror_array = NULL; | ||
| 154 | } | ||
| 155 | } | ||
| 156 | |||
| 157 | static int ff_layout_check_layout(struct nfs4_layoutget_res *lgr) | ||
| 158 | { | ||
| 159 | int ret = 0; | ||
| 160 | |||
| 161 | dprintk("--> %s\n", __func__); | ||
| 162 | |||
| 163 | /* FIXME: remove this check when layout segment support is added */ | ||
| 164 | if (lgr->range.offset != 0 || | ||
| 165 | lgr->range.length != NFS4_MAX_UINT64) { | ||
| 166 | dprintk("%s Only whole file layouts supported. Use MDS i/o\n", | ||
| 167 | __func__); | ||
| 168 | ret = -EINVAL; | ||
| 169 | } | ||
| 170 | |||
| 171 | dprintk("--> %s returns %d\n", __func__, ret); | ||
| 172 | return ret; | ||
| 173 | } | ||
| 174 | |||
| 175 | static void _ff_layout_free_lseg(struct nfs4_ff_layout_segment *fls) | ||
| 176 | { | ||
| 177 | if (fls) { | ||
| 178 | ff_layout_free_mirror_array(fls); | ||
| 179 | kfree(fls); | ||
| 180 | } | ||
| 181 | } | ||
| 182 | |||
| 183 | static void ff_layout_sort_mirrors(struct nfs4_ff_layout_segment *fls) | ||
| 184 | { | ||
| 185 | struct nfs4_ff_layout_mirror *tmp; | ||
| 186 | int i, j; | ||
| 187 | |||
| 188 | for (i = 0; i < fls->mirror_array_cnt - 1; i++) { | ||
| 189 | for (j = i + 1; j < fls->mirror_array_cnt; j++) | ||
| 190 | if (fls->mirror_array[i]->efficiency < | ||
| 191 | fls->mirror_array[j]->efficiency) { | ||
| 192 | tmp = fls->mirror_array[i]; | ||
| 193 | fls->mirror_array[i] = fls->mirror_array[j]; | ||
| 194 | fls->mirror_array[j] = tmp; | ||
| 195 | } | ||
| 196 | } | ||
| 197 | } | ||
| 198 | |||
| 199 | static struct pnfs_layout_segment * | ||
| 200 | ff_layout_alloc_lseg(struct pnfs_layout_hdr *lh, | ||
| 201 | struct nfs4_layoutget_res *lgr, | ||
| 202 | gfp_t gfp_flags) | ||
| 203 | { | ||
| 204 | struct pnfs_layout_segment *ret; | ||
| 205 | struct nfs4_ff_layout_segment *fls = NULL; | ||
| 206 | struct xdr_stream stream; | ||
| 207 | struct xdr_buf buf; | ||
| 208 | struct page *scratch; | ||
| 209 | u64 stripe_unit; | ||
| 210 | u32 mirror_array_cnt; | ||
| 211 | __be32 *p; | ||
| 212 | int i, rc; | ||
| 213 | |||
| 214 | dprintk("--> %s\n", __func__); | ||
| 215 | scratch = alloc_page(gfp_flags); | ||
| 216 | if (!scratch) | ||
| 217 | return ERR_PTR(-ENOMEM); | ||
| 218 | |||
| 219 | xdr_init_decode_pages(&stream, &buf, lgr->layoutp->pages, | ||
| 220 | lgr->layoutp->len); | ||
| 221 | xdr_set_scratch_buffer(&stream, page_address(scratch), PAGE_SIZE); | ||
| 222 | |||
| 223 | /* stripe unit and mirror_array_cnt */ | ||
| 224 | rc = -EIO; | ||
| 225 | p = xdr_inline_decode(&stream, 8 + 4); | ||
| 226 | if (!p) | ||
| 227 | goto out_err_free; | ||
| 228 | |||
| 229 | p = xdr_decode_hyper(p, &stripe_unit); | ||
| 230 | mirror_array_cnt = be32_to_cpup(p++); | ||
| 231 | dprintk("%s: stripe_unit=%llu mirror_array_cnt=%u\n", __func__, | ||
| 232 | stripe_unit, mirror_array_cnt); | ||
| 233 | |||
| 234 | if (mirror_array_cnt > NFS4_FLEXFILE_LAYOUT_MAX_MIRROR_CNT || | ||
| 235 | mirror_array_cnt == 0) | ||
| 236 | goto out_err_free; | ||
| 237 | |||
| 238 | rc = -ENOMEM; | ||
| 239 | fls = kzalloc(sizeof(*fls), gfp_flags); | ||
| 240 | if (!fls) | ||
| 241 | goto out_err_free; | ||
| 242 | |||
| 243 | fls->mirror_array_cnt = mirror_array_cnt; | ||
| 244 | fls->stripe_unit = stripe_unit; | ||
| 245 | fls->mirror_array = kcalloc(fls->mirror_array_cnt, | ||
| 246 | sizeof(fls->mirror_array[0]), gfp_flags); | ||
| 247 | if (fls->mirror_array == NULL) | ||
| 248 | goto out_err_free; | ||
| 249 | |||
| 250 | for (i = 0; i < fls->mirror_array_cnt; i++) { | ||
| 251 | struct nfs4_deviceid devid; | ||
| 252 | struct nfs4_deviceid_node *idnode; | ||
| 253 | u32 ds_count; | ||
| 254 | u32 fh_count; | ||
| 255 | int j; | ||
| 256 | |||
| 257 | rc = -EIO; | ||
| 258 | p = xdr_inline_decode(&stream, 4); | ||
| 259 | if (!p) | ||
| 260 | goto out_err_free; | ||
| 261 | ds_count = be32_to_cpup(p); | ||
| 262 | |||
| 263 | /* FIXME: allow for striping? */ | ||
| 264 | if (ds_count != 1) | ||
| 265 | goto out_err_free; | ||
| 266 | |||
| 267 | fls->mirror_array[i] = | ||
| 268 | kzalloc(sizeof(struct nfs4_ff_layout_mirror), | ||
| 269 | gfp_flags); | ||
| 270 | if (fls->mirror_array[i] == NULL) { | ||
| 271 | rc = -ENOMEM; | ||
| 272 | goto out_err_free; | ||
| 273 | } | ||
| 274 | |||
| 275 | spin_lock_init(&fls->mirror_array[i]->lock); | ||
| 276 | fls->mirror_array[i]->ds_count = ds_count; | ||
| 277 | |||
| 278 | /* deviceid */ | ||
| 279 | rc = decode_deviceid(&stream, &devid); | ||
| 280 | if (rc) | ||
| 281 | goto out_err_free; | ||
| 282 | |||
| 283 | idnode = nfs4_find_get_deviceid(NFS_SERVER(lh->plh_inode), | ||
| 284 | &devid, lh->plh_lc_cred, | ||
| 285 | gfp_flags); | ||
| 286 | /* | ||
| 287 | * upon success, mirror_ds is allocated by previous | ||
| 288 | * getdeviceinfo, or newly by .alloc_deviceid_node | ||
| 289 | * nfs4_find_get_deviceid failure is indeed getdeviceinfo falure | ||
| 290 | */ | ||
| 291 | if (idnode) | ||
| 292 | fls->mirror_array[i]->mirror_ds = | ||
| 293 | FF_LAYOUT_MIRROR_DS(idnode); | ||
| 294 | else | ||
| 295 | goto out_err_free; | ||
| 296 | |||
| 297 | /* efficiency */ | ||
| 298 | rc = -EIO; | ||
| 299 | p = xdr_inline_decode(&stream, 4); | ||
| 300 | if (!p) | ||
| 301 | goto out_err_free; | ||
| 302 | fls->mirror_array[i]->efficiency = be32_to_cpup(p); | ||
| 303 | |||
| 304 | /* stateid */ | ||
| 305 | rc = decode_stateid(&stream, &fls->mirror_array[i]->stateid); | ||
| 306 | if (rc) | ||
| 307 | goto out_err_free; | ||
| 308 | |||
| 309 | /* fh */ | ||
| 310 | p = xdr_inline_decode(&stream, 4); | ||
| 311 | if (!p) | ||
| 312 | goto out_err_free; | ||
| 313 | fh_count = be32_to_cpup(p); | ||
| 314 | |||
| 315 | fls->mirror_array[i]->fh_versions = | ||
| 316 | kzalloc(fh_count * sizeof(struct nfs_fh), | ||
| 317 | gfp_flags); | ||
| 318 | if (fls->mirror_array[i]->fh_versions == NULL) { | ||
| 319 | rc = -ENOMEM; | ||
| 320 | goto out_err_free; | ||
| 321 | } | ||
| 322 | |||
| 323 | for (j = 0; j < fh_count; j++) { | ||
| 324 | rc = decode_nfs_fh(&stream, | ||
| 325 | &fls->mirror_array[i]->fh_versions[j]); | ||
| 326 | if (rc) | ||
| 327 | goto out_err_free; | ||
| 328 | } | ||
| 329 | |||
| 330 | fls->mirror_array[i]->fh_versions_cnt = fh_count; | ||
| 331 | |||
| 332 | /* user */ | ||
| 333 | rc = decode_name(&stream, &fls->mirror_array[i]->uid); | ||
| 334 | if (rc) | ||
| 335 | goto out_err_free; | ||
| 336 | |||
| 337 | /* group */ | ||
| 338 | rc = decode_name(&stream, &fls->mirror_array[i]->gid); | ||
| 339 | if (rc) | ||
| 340 | goto out_err_free; | ||
| 341 | |||
| 342 | dprintk("%s: uid %d gid %d\n", __func__, | ||
| 343 | fls->mirror_array[i]->uid, | ||
| 344 | fls->mirror_array[i]->gid); | ||
| 345 | } | ||
| 346 | |||
| 347 | ff_layout_sort_mirrors(fls); | ||
| 348 | rc = ff_layout_check_layout(lgr); | ||
| 349 | if (rc) | ||
| 350 | goto out_err_free; | ||
| 351 | |||
| 352 | ret = &fls->generic_hdr; | ||
| 353 | dprintk("<-- %s (success)\n", __func__); | ||
| 354 | out_free_page: | ||
| 355 | __free_page(scratch); | ||
| 356 | return ret; | ||
| 357 | out_err_free: | ||
| 358 | _ff_layout_free_lseg(fls); | ||
| 359 | ret = ERR_PTR(rc); | ||
| 360 | dprintk("<-- %s (%d)\n", __func__, rc); | ||
| 361 | goto out_free_page; | ||
| 362 | } | ||
| 363 | |||
| 364 | static bool ff_layout_has_rw_segments(struct pnfs_layout_hdr *layout) | ||
| 365 | { | ||
| 366 | struct pnfs_layout_segment *lseg; | ||
| 367 | |||
| 368 | list_for_each_entry(lseg, &layout->plh_segs, pls_list) | ||
| 369 | if (lseg->pls_range.iomode == IOMODE_RW) | ||
| 370 | return true; | ||
| 371 | |||
| 372 | return false; | ||
| 373 | } | ||
| 374 | |||
| 375 | static void | ||
| 376 | ff_layout_free_lseg(struct pnfs_layout_segment *lseg) | ||
| 377 | { | ||
| 378 | struct nfs4_ff_layout_segment *fls = FF_LAYOUT_LSEG(lseg); | ||
| 379 | int i; | ||
| 380 | |||
| 381 | dprintk("--> %s\n", __func__); | ||
| 382 | |||
| 383 | for (i = 0; i < fls->mirror_array_cnt; i++) { | ||
| 384 | if (fls->mirror_array[i]) { | ||
| 385 | nfs4_ff_layout_put_deviceid(fls->mirror_array[i]->mirror_ds); | ||
| 386 | fls->mirror_array[i]->mirror_ds = NULL; | ||
| 387 | if (fls->mirror_array[i]->cred) { | ||
| 388 | put_rpccred(fls->mirror_array[i]->cred); | ||
| 389 | fls->mirror_array[i]->cred = NULL; | ||
| 390 | } | ||
| 391 | } | ||
| 392 | } | ||
| 393 | |||
| 394 | if (lseg->pls_range.iomode == IOMODE_RW) { | ||
| 395 | struct nfs4_flexfile_layout *ffl; | ||
| 396 | struct inode *inode; | ||
| 397 | |||
| 398 | ffl = FF_LAYOUT_FROM_HDR(lseg->pls_layout); | ||
| 399 | inode = ffl->generic_hdr.plh_inode; | ||
| 400 | spin_lock(&inode->i_lock); | ||
| 401 | if (!ff_layout_has_rw_segments(lseg->pls_layout)) { | ||
| 402 | ffl->commit_info.nbuckets = 0; | ||
| 403 | kfree(ffl->commit_info.buckets); | ||
| 404 | ffl->commit_info.buckets = NULL; | ||
| 405 | } | ||
| 406 | spin_unlock(&inode->i_lock); | ||
| 407 | } | ||
| 408 | _ff_layout_free_lseg(fls); | ||
| 409 | } | ||
| 410 | |||
| 411 | /* Return 1 until we have multiple lsegs support */ | ||
| 412 | static int | ||
| 413 | ff_layout_get_lseg_count(struct nfs4_ff_layout_segment *fls) | ||
| 414 | { | ||
| 415 | return 1; | ||
| 416 | } | ||
| 417 | |||
| 418 | static int | ||
| 419 | ff_layout_alloc_commit_info(struct pnfs_layout_segment *lseg, | ||
| 420 | struct nfs_commit_info *cinfo, | ||
| 421 | gfp_t gfp_flags) | ||
| 422 | { | ||
| 423 | struct nfs4_ff_layout_segment *fls = FF_LAYOUT_LSEG(lseg); | ||
| 424 | struct pnfs_commit_bucket *buckets; | ||
| 425 | int size; | ||
| 426 | |||
| 427 | if (cinfo->ds->nbuckets != 0) { | ||
| 428 | /* This assumes there is only one RW lseg per file. | ||
| 429 | * To support multiple lseg per file, we need to | ||
| 430 | * change struct pnfs_commit_bucket to allow dynamic | ||
| 431 | * increasing nbuckets. | ||
| 432 | */ | ||
| 433 | return 0; | ||
| 434 | } | ||
| 435 | |||
| 436 | size = ff_layout_get_lseg_count(fls) * FF_LAYOUT_MIRROR_COUNT(lseg); | ||
| 437 | |||
| 438 | buckets = kcalloc(size, sizeof(struct pnfs_commit_bucket), | ||
| 439 | gfp_flags); | ||
| 440 | if (!buckets) | ||
| 441 | return -ENOMEM; | ||
| 442 | else { | ||
| 443 | int i; | ||
| 444 | |||
| 445 | spin_lock(cinfo->lock); | ||
| 446 | if (cinfo->ds->nbuckets != 0) | ||
| 447 | kfree(buckets); | ||
| 448 | else { | ||
| 449 | cinfo->ds->buckets = buckets; | ||
| 450 | cinfo->ds->nbuckets = size; | ||
| 451 | for (i = 0; i < size; i++) { | ||
| 452 | INIT_LIST_HEAD(&buckets[i].written); | ||
| 453 | INIT_LIST_HEAD(&buckets[i].committing); | ||
| 454 | /* mark direct verifier as unset */ | ||
| 455 | buckets[i].direct_verf.committed = | ||
| 456 | NFS_INVALID_STABLE_HOW; | ||
| 457 | } | ||
| 458 | } | ||
| 459 | spin_unlock(cinfo->lock); | ||
| 460 | return 0; | ||
| 461 | } | ||
| 462 | } | ||
| 463 | |||
| 464 | static struct nfs4_pnfs_ds * | ||
| 465 | ff_layout_choose_best_ds_for_read(struct nfs_pageio_descriptor *pgio, | ||
| 466 | int *best_idx) | ||
| 467 | { | ||
| 468 | struct nfs4_ff_layout_segment *fls; | ||
| 469 | struct nfs4_pnfs_ds *ds; | ||
| 470 | int idx; | ||
| 471 | |||
| 472 | fls = FF_LAYOUT_LSEG(pgio->pg_lseg); | ||
| 473 | /* mirrors are sorted by efficiency */ | ||
| 474 | for (idx = 0; idx < fls->mirror_array_cnt; idx++) { | ||
| 475 | ds = nfs4_ff_layout_prepare_ds(pgio->pg_lseg, idx, false); | ||
| 476 | if (ds) { | ||
| 477 | *best_idx = idx; | ||
| 478 | return ds; | ||
| 479 | } | ||
| 480 | } | ||
| 481 | |||
| 482 | return NULL; | ||
| 483 | } | ||
| 484 | |||
| 485 | static void | ||
| 486 | ff_layout_pg_init_read(struct nfs_pageio_descriptor *pgio, | ||
| 487 | struct nfs_page *req) | ||
| 488 | { | ||
| 489 | struct nfs_pgio_mirror *pgm; | ||
| 490 | struct nfs4_ff_layout_mirror *mirror; | ||
| 491 | struct nfs4_pnfs_ds *ds; | ||
| 492 | int ds_idx; | ||
| 493 | |||
| 494 | /* Use full layout for now */ | ||
| 495 | if (!pgio->pg_lseg) | ||
| 496 | pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode, | ||
| 497 | req->wb_context, | ||
| 498 | 0, | ||
| 499 | NFS4_MAX_UINT64, | ||
| 500 | IOMODE_READ, | ||
| 501 | GFP_KERNEL); | ||
| 502 | /* If no lseg, fall back to read through mds */ | ||
| 503 | if (pgio->pg_lseg == NULL) | ||
| 504 | goto out_mds; | ||
| 505 | |||
| 506 | ds = ff_layout_choose_best_ds_for_read(pgio, &ds_idx); | ||
| 507 | if (!ds) | ||
| 508 | goto out_mds; | ||
| 509 | mirror = FF_LAYOUT_COMP(pgio->pg_lseg, ds_idx); | ||
| 510 | |||
| 511 | pgio->pg_mirror_idx = ds_idx; | ||
| 512 | |||
| 513 | /* read always uses only one mirror - idx 0 for pgio layer */ | ||
| 514 | pgm = &pgio->pg_mirrors[0]; | ||
| 515 | pgm->pg_bsize = mirror->mirror_ds->ds_versions[0].rsize; | ||
| 516 | |||
| 517 | return; | ||
| 518 | out_mds: | ||
| 519 | pnfs_put_lseg(pgio->pg_lseg); | ||
| 520 | pgio->pg_lseg = NULL; | ||
| 521 | nfs_pageio_reset_read_mds(pgio); | ||
| 522 | } | ||
| 523 | |||
| 524 | static void | ||
| 525 | ff_layout_pg_init_write(struct nfs_pageio_descriptor *pgio, | ||
| 526 | struct nfs_page *req) | ||
| 527 | { | ||
| 528 | struct nfs4_ff_layout_mirror *mirror; | ||
| 529 | struct nfs_pgio_mirror *pgm; | ||
| 530 | struct nfs_commit_info cinfo; | ||
| 531 | struct nfs4_pnfs_ds *ds; | ||
| 532 | int i; | ||
| 533 | int status; | ||
| 534 | |||
| 535 | if (!pgio->pg_lseg) | ||
| 536 | pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode, | ||
| 537 | req->wb_context, | ||
| 538 | 0, | ||
| 539 | NFS4_MAX_UINT64, | ||
| 540 | IOMODE_RW, | ||
| 541 | GFP_NOFS); | ||
| 542 | /* If no lseg, fall back to write through mds */ | ||
| 543 | if (pgio->pg_lseg == NULL) | ||
| 544 | goto out_mds; | ||
| 545 | |||
| 546 | nfs_init_cinfo(&cinfo, pgio->pg_inode, pgio->pg_dreq); | ||
| 547 | status = ff_layout_alloc_commit_info(pgio->pg_lseg, &cinfo, GFP_NOFS); | ||
| 548 | if (status < 0) | ||
| 549 | goto out_mds; | ||
| 550 | |||
| 551 | /* Use a direct mapping of ds_idx to pgio mirror_idx */ | ||
| 552 | if (WARN_ON_ONCE(pgio->pg_mirror_count != | ||
| 553 | FF_LAYOUT_MIRROR_COUNT(pgio->pg_lseg))) | ||
| 554 | goto out_mds; | ||
| 555 | |||
| 556 | for (i = 0; i < pgio->pg_mirror_count; i++) { | ||
| 557 | ds = nfs4_ff_layout_prepare_ds(pgio->pg_lseg, i, true); | ||
| 558 | if (!ds) | ||
| 559 | goto out_mds; | ||
| 560 | pgm = &pgio->pg_mirrors[i]; | ||
| 561 | mirror = FF_LAYOUT_COMP(pgio->pg_lseg, i); | ||
| 562 | pgm->pg_bsize = mirror->mirror_ds->ds_versions[0].wsize; | ||
| 563 | } | ||
| 564 | |||
| 565 | return; | ||
| 566 | |||
| 567 | out_mds: | ||
| 568 | pnfs_put_lseg(pgio->pg_lseg); | ||
| 569 | pgio->pg_lseg = NULL; | ||
| 570 | nfs_pageio_reset_write_mds(pgio); | ||
| 571 | } | ||
| 572 | |||
| 573 | static unsigned int | ||
| 574 | ff_layout_pg_get_mirror_count_write(struct nfs_pageio_descriptor *pgio, | ||
| 575 | struct nfs_page *req) | ||
| 576 | { | ||
| 577 | if (!pgio->pg_lseg) | ||
| 578 | pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode, | ||
| 579 | req->wb_context, | ||
| 580 | 0, | ||
| 581 | NFS4_MAX_UINT64, | ||
| 582 | IOMODE_RW, | ||
| 583 | GFP_NOFS); | ||
| 584 | if (pgio->pg_lseg) | ||
| 585 | return FF_LAYOUT_MIRROR_COUNT(pgio->pg_lseg); | ||
| 586 | |||
| 587 | /* no lseg means that pnfs is not in use, so no mirroring here */ | ||
| 588 | pnfs_put_lseg(pgio->pg_lseg); | ||
| 589 | pgio->pg_lseg = NULL; | ||
| 590 | nfs_pageio_reset_write_mds(pgio); | ||
| 591 | return 1; | ||
| 592 | } | ||
| 593 | |||
| 594 | static const struct nfs_pageio_ops ff_layout_pg_read_ops = { | ||
| 595 | .pg_init = ff_layout_pg_init_read, | ||
| 596 | .pg_test = pnfs_generic_pg_test, | ||
| 597 | .pg_doio = pnfs_generic_pg_readpages, | ||
| 598 | .pg_cleanup = pnfs_generic_pg_cleanup, | ||
| 599 | }; | ||
| 600 | |||
| 601 | static const struct nfs_pageio_ops ff_layout_pg_write_ops = { | ||
| 602 | .pg_init = ff_layout_pg_init_write, | ||
| 603 | .pg_test = pnfs_generic_pg_test, | ||
| 604 | .pg_doio = pnfs_generic_pg_writepages, | ||
| 605 | .pg_get_mirror_count = ff_layout_pg_get_mirror_count_write, | ||
| 606 | .pg_cleanup = pnfs_generic_pg_cleanup, | ||
| 607 | }; | ||
| 608 | |||
| 609 | static void ff_layout_reset_write(struct nfs_pgio_header *hdr, bool retry_pnfs) | ||
| 610 | { | ||
| 611 | struct rpc_task *task = &hdr->task; | ||
| 612 | |||
| 613 | pnfs_layoutcommit_inode(hdr->inode, false); | ||
| 614 | |||
| 615 | if (retry_pnfs) { | ||
| 616 | dprintk("%s Reset task %5u for i/o through pNFS " | ||
| 617 | "(req %s/%llu, %u bytes @ offset %llu)\n", __func__, | ||
| 618 | hdr->task.tk_pid, | ||
| 619 | hdr->inode->i_sb->s_id, | ||
| 620 | (unsigned long long)NFS_FILEID(hdr->inode), | ||
| 621 | hdr->args.count, | ||
| 622 | (unsigned long long)hdr->args.offset); | ||
| 623 | |||
| 624 | if (!hdr->dreq) { | ||
| 625 | struct nfs_open_context *ctx; | ||
| 626 | |||
| 627 | ctx = nfs_list_entry(hdr->pages.next)->wb_context; | ||
| 628 | set_bit(NFS_CONTEXT_RESEND_WRITES, &ctx->flags); | ||
| 629 | hdr->completion_ops->error_cleanup(&hdr->pages); | ||
| 630 | } else { | ||
| 631 | nfs_direct_set_resched_writes(hdr->dreq); | ||
| 632 | /* fake unstable write to let common nfs resend pages */ | ||
| 633 | hdr->verf.committed = NFS_UNSTABLE; | ||
| 634 | hdr->good_bytes = 0; | ||
| 635 | } | ||
| 636 | return; | ||
| 637 | } | ||
| 638 | |||
| 639 | if (!test_and_set_bit(NFS_IOHDR_REDO, &hdr->flags)) { | ||
| 640 | dprintk("%s Reset task %5u for i/o through MDS " | ||
| 641 | "(req %s/%llu, %u bytes @ offset %llu)\n", __func__, | ||
| 642 | hdr->task.tk_pid, | ||
| 643 | hdr->inode->i_sb->s_id, | ||
| 644 | (unsigned long long)NFS_FILEID(hdr->inode), | ||
| 645 | hdr->args.count, | ||
| 646 | (unsigned long long)hdr->args.offset); | ||
| 647 | |||
| 648 | task->tk_status = pnfs_write_done_resend_to_mds(hdr); | ||
| 649 | } | ||
| 650 | } | ||
| 651 | |||
| 652 | static void ff_layout_reset_read(struct nfs_pgio_header *hdr) | ||
| 653 | { | ||
| 654 | struct rpc_task *task = &hdr->task; | ||
| 655 | |||
| 656 | pnfs_layoutcommit_inode(hdr->inode, false); | ||
| 657 | |||
| 658 | if (!test_and_set_bit(NFS_IOHDR_REDO, &hdr->flags)) { | ||
| 659 | dprintk("%s Reset task %5u for i/o through MDS " | ||
| 660 | "(req %s/%llu, %u bytes @ offset %llu)\n", __func__, | ||
| 661 | hdr->task.tk_pid, | ||
| 662 | hdr->inode->i_sb->s_id, | ||
| 663 | (unsigned long long)NFS_FILEID(hdr->inode), | ||
| 664 | hdr->args.count, | ||
| 665 | (unsigned long long)hdr->args.offset); | ||
| 666 | |||
| 667 | task->tk_status = pnfs_read_done_resend_to_mds(hdr); | ||
| 668 | } | ||
| 669 | } | ||
| 670 | |||
| 671 | static int ff_layout_async_handle_error_v4(struct rpc_task *task, | ||
| 672 | struct nfs4_state *state, | ||
| 673 | struct nfs_client *clp, | ||
| 674 | struct pnfs_layout_segment *lseg, | ||
| 675 | int idx) | ||
| 676 | { | ||
| 677 | struct pnfs_layout_hdr *lo = lseg->pls_layout; | ||
| 678 | struct inode *inode = lo->plh_inode; | ||
| 679 | struct nfs_server *mds_server = NFS_SERVER(inode); | ||
| 680 | |||
| 681 | struct nfs4_deviceid_node *devid = FF_LAYOUT_DEVID_NODE(lseg, idx); | ||
| 682 | struct nfs_client *mds_client = mds_server->nfs_client; | ||
| 683 | struct nfs4_slot_table *tbl = &clp->cl_session->fc_slot_table; | ||
| 684 | |||
| 685 | if (task->tk_status >= 0) | ||
| 686 | return 0; | ||
| 687 | |||
| 688 | switch (task->tk_status) { | ||
| 689 | /* MDS state errors */ | ||
| 690 | case -NFS4ERR_DELEG_REVOKED: | ||
| 691 | case -NFS4ERR_ADMIN_REVOKED: | ||
| 692 | case -NFS4ERR_BAD_STATEID: | ||
| 693 | if (state == NULL) | ||
| 694 | break; | ||
| 695 | nfs_remove_bad_delegation(state->inode); | ||
| 696 | case -NFS4ERR_OPENMODE: | ||
| 697 | if (state == NULL) | ||
| 698 | break; | ||
| 699 | if (nfs4_schedule_stateid_recovery(mds_server, state) < 0) | ||
| 700 | goto out_bad_stateid; | ||
| 701 | goto wait_on_recovery; | ||
| 702 | case -NFS4ERR_EXPIRED: | ||
| 703 | if (state != NULL) { | ||
| 704 | if (nfs4_schedule_stateid_recovery(mds_server, state) < 0) | ||
| 705 | goto out_bad_stateid; | ||
| 706 | } | ||
| 707 | nfs4_schedule_lease_recovery(mds_client); | ||
| 708 | goto wait_on_recovery; | ||
| 709 | /* DS session errors */ | ||
| 710 | case -NFS4ERR_BADSESSION: | ||
| 711 | case -NFS4ERR_BADSLOT: | ||
| 712 | case -NFS4ERR_BAD_HIGH_SLOT: | ||
| 713 | case -NFS4ERR_DEADSESSION: | ||
| 714 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: | ||
| 715 | case -NFS4ERR_SEQ_FALSE_RETRY: | ||
| 716 | case -NFS4ERR_SEQ_MISORDERED: | ||
| 717 | dprintk("%s ERROR %d, Reset session. Exchangeid " | ||
| 718 | "flags 0x%x\n", __func__, task->tk_status, | ||
| 719 | clp->cl_exchange_flags); | ||
| 720 | nfs4_schedule_session_recovery(clp->cl_session, task->tk_status); | ||
| 721 | break; | ||
| 722 | case -NFS4ERR_DELAY: | ||
| 723 | case -NFS4ERR_GRACE: | ||
| 724 | rpc_delay(task, FF_LAYOUT_POLL_RETRY_MAX); | ||
| 725 | break; | ||
| 726 | case -NFS4ERR_RETRY_UNCACHED_REP: | ||
| 727 | break; | ||
| 728 | /* Invalidate Layout errors */ | ||
| 729 | case -NFS4ERR_PNFS_NO_LAYOUT: | ||
| 730 | case -ESTALE: /* mapped NFS4ERR_STALE */ | ||
| 731 | case -EBADHANDLE: /* mapped NFS4ERR_BADHANDLE */ | ||
| 732 | case -EISDIR: /* mapped NFS4ERR_ISDIR */ | ||
| 733 | case -NFS4ERR_FHEXPIRED: | ||
| 734 | case -NFS4ERR_WRONG_TYPE: | ||
| 735 | dprintk("%s Invalid layout error %d\n", __func__, | ||
| 736 | task->tk_status); | ||
| 737 | /* | ||
| 738 | * Destroy layout so new i/o will get a new layout. | ||
| 739 | * Layout will not be destroyed until all current lseg | ||
| 740 | * references are put. Mark layout as invalid to resend failed | ||
| 741 | * i/o and all i/o waiting on the slot table to the MDS until | ||
| 742 | * layout is destroyed and a new valid layout is obtained. | ||
| 743 | */ | ||
| 744 | pnfs_destroy_layout(NFS_I(inode)); | ||
| 745 | rpc_wake_up(&tbl->slot_tbl_waitq); | ||
| 746 | goto reset; | ||
| 747 | /* RPC connection errors */ | ||
| 748 | case -ECONNREFUSED: | ||
| 749 | case -EHOSTDOWN: | ||
| 750 | case -EHOSTUNREACH: | ||
| 751 | case -ENETUNREACH: | ||
| 752 | case -EIO: | ||
| 753 | case -ETIMEDOUT: | ||
| 754 | case -EPIPE: | ||
| 755 | dprintk("%s DS connection error %d\n", __func__, | ||
| 756 | task->tk_status); | ||
| 757 | nfs4_mark_deviceid_unavailable(devid); | ||
| 758 | rpc_wake_up(&tbl->slot_tbl_waitq); | ||
| 759 | /* fall through */ | ||
| 760 | default: | ||
| 761 | if (ff_layout_has_available_ds(lseg)) | ||
| 762 | return -NFS4ERR_RESET_TO_PNFS; | ||
| 763 | reset: | ||
| 764 | dprintk("%s Retry through MDS. Error %d\n", __func__, | ||
| 765 | task->tk_status); | ||
| 766 | return -NFS4ERR_RESET_TO_MDS; | ||
| 767 | } | ||
| 768 | out: | ||
| 769 | task->tk_status = 0; | ||
| 770 | return -EAGAIN; | ||
| 771 | out_bad_stateid: | ||
| 772 | task->tk_status = -EIO; | ||
| 773 | return 0; | ||
| 774 | wait_on_recovery: | ||
| 775 | rpc_sleep_on(&mds_client->cl_rpcwaitq, task, NULL); | ||
| 776 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &mds_client->cl_state) == 0) | ||
| 777 | rpc_wake_up_queued_task(&mds_client->cl_rpcwaitq, task); | ||
| 778 | goto out; | ||
| 779 | } | ||
| 780 | |||
| 781 | /* Retry all errors through either pNFS or MDS except for -EJUKEBOX */ | ||
| 782 | static int ff_layout_async_handle_error_v3(struct rpc_task *task, | ||
| 783 | struct pnfs_layout_segment *lseg, | ||
| 784 | int idx) | ||
| 785 | { | ||
| 786 | struct nfs4_deviceid_node *devid = FF_LAYOUT_DEVID_NODE(lseg, idx); | ||
| 787 | |||
| 788 | if (task->tk_status >= 0) | ||
| 789 | return 0; | ||
| 790 | |||
| 791 | if (task->tk_status != -EJUKEBOX) { | ||
| 792 | dprintk("%s DS connection error %d\n", __func__, | ||
| 793 | task->tk_status); | ||
| 794 | nfs4_mark_deviceid_unavailable(devid); | ||
| 795 | if (ff_layout_has_available_ds(lseg)) | ||
| 796 | return -NFS4ERR_RESET_TO_PNFS; | ||
| 797 | else | ||
| 798 | return -NFS4ERR_RESET_TO_MDS; | ||
| 799 | } | ||
| 800 | |||
| 801 | if (task->tk_status == -EJUKEBOX) | ||
| 802 | nfs_inc_stats(lseg->pls_layout->plh_inode, NFSIOS_DELAY); | ||
| 803 | task->tk_status = 0; | ||
| 804 | rpc_restart_call(task); | ||
| 805 | rpc_delay(task, NFS_JUKEBOX_RETRY_TIME); | ||
| 806 | return -EAGAIN; | ||
| 807 | } | ||
| 808 | |||
| 809 | static int ff_layout_async_handle_error(struct rpc_task *task, | ||
| 810 | struct nfs4_state *state, | ||
| 811 | struct nfs_client *clp, | ||
| 812 | struct pnfs_layout_segment *lseg, | ||
| 813 | int idx) | ||
| 814 | { | ||
| 815 | int vers = clp->cl_nfs_mod->rpc_vers->number; | ||
| 816 | |||
| 817 | switch (vers) { | ||
| 818 | case 3: | ||
| 819 | return ff_layout_async_handle_error_v3(task, lseg, idx); | ||
| 820 | case 4: | ||
| 821 | return ff_layout_async_handle_error_v4(task, state, clp, | ||
| 822 | lseg, idx); | ||
| 823 | default: | ||
| 824 | /* should never happen */ | ||
| 825 | WARN_ON_ONCE(1); | ||
| 826 | return 0; | ||
| 827 | } | ||
| 828 | } | ||
| 829 | |||
| 830 | static void ff_layout_io_track_ds_error(struct pnfs_layout_segment *lseg, | ||
| 831 | int idx, u64 offset, u64 length, | ||
| 832 | u32 status, int opnum) | ||
| 833 | { | ||
| 834 | struct nfs4_ff_layout_mirror *mirror; | ||
| 835 | int err; | ||
| 836 | |||
| 837 | mirror = FF_LAYOUT_COMP(lseg, idx); | ||
| 838 | err = ff_layout_track_ds_error(FF_LAYOUT_FROM_HDR(lseg->pls_layout), | ||
| 839 | mirror, offset, length, status, opnum, | ||
| 840 | GFP_NOIO); | ||
| 841 | dprintk("%s: err %d op %d status %u\n", __func__, err, opnum, status); | ||
| 842 | } | ||
| 843 | |||
| 844 | /* NFS_PROTO call done callback routines */ | ||
| 845 | |||
| 846 | static int ff_layout_read_done_cb(struct rpc_task *task, | ||
| 847 | struct nfs_pgio_header *hdr) | ||
| 848 | { | ||
| 849 | struct inode *inode; | ||
| 850 | int err; | ||
| 851 | |||
| 852 | trace_nfs4_pnfs_read(hdr, task->tk_status); | ||
| 853 | if (task->tk_status == -ETIMEDOUT && !hdr->res.op_status) | ||
| 854 | hdr->res.op_status = NFS4ERR_NXIO; | ||
| 855 | if (task->tk_status < 0 && hdr->res.op_status) | ||
| 856 | ff_layout_io_track_ds_error(hdr->lseg, hdr->pgio_mirror_idx, | ||
| 857 | hdr->args.offset, hdr->args.count, | ||
| 858 | hdr->res.op_status, OP_READ); | ||
| 859 | err = ff_layout_async_handle_error(task, hdr->args.context->state, | ||
| 860 | hdr->ds_clp, hdr->lseg, | ||
| 861 | hdr->pgio_mirror_idx); | ||
| 862 | |||
| 863 | switch (err) { | ||
| 864 | case -NFS4ERR_RESET_TO_PNFS: | ||
| 865 | set_bit(NFS_LAYOUT_RETURN_BEFORE_CLOSE, | ||
| 866 | &hdr->lseg->pls_layout->plh_flags); | ||
| 867 | pnfs_read_resend_pnfs(hdr); | ||
| 868 | return task->tk_status; | ||
| 869 | case -NFS4ERR_RESET_TO_MDS: | ||
| 870 | inode = hdr->lseg->pls_layout->plh_inode; | ||
| 871 | pnfs_error_mark_layout_for_return(inode, hdr->lseg); | ||
| 872 | ff_layout_reset_read(hdr); | ||
| 873 | return task->tk_status; | ||
| 874 | case -EAGAIN: | ||
| 875 | rpc_restart_call_prepare(task); | ||
| 876 | return -EAGAIN; | ||
| 877 | } | ||
| 878 | |||
| 879 | return 0; | ||
| 880 | } | ||
| 881 | |||
| 882 | /* | ||
| 883 | * We reference the rpc_cred of the first WRITE that triggers the need for | ||
| 884 | * a LAYOUTCOMMIT, and use it to send the layoutcommit compound. | ||
| 885 | * rfc5661 is not clear about which credential should be used. | ||
| 886 | * | ||
| 887 | * Flexlayout client should treat DS replied FILE_SYNC as DATA_SYNC, so | ||
| 888 | * to follow http://www.rfc-editor.org/errata_search.php?rfc=5661&eid=2751 | ||
| 889 | * we always send layoutcommit after DS writes. | ||
| 890 | */ | ||
| 891 | static void | ||
| 892 | ff_layout_set_layoutcommit(struct nfs_pgio_header *hdr) | ||
| 893 | { | ||
| 894 | pnfs_set_layoutcommit(hdr); | ||
| 895 | dprintk("%s inode %lu pls_end_pos %lu\n", __func__, hdr->inode->i_ino, | ||
| 896 | (unsigned long) NFS_I(hdr->inode)->layout->plh_lwb); | ||
| 897 | } | ||
| 898 | |||
| 899 | static bool | ||
| 900 | ff_layout_reset_to_mds(struct pnfs_layout_segment *lseg, int idx) | ||
| 901 | { | ||
| 902 | /* No mirroring for now */ | ||
| 903 | struct nfs4_deviceid_node *node = FF_LAYOUT_DEVID_NODE(lseg, idx); | ||
| 904 | |||
| 905 | return ff_layout_test_devid_unavailable(node); | ||
| 906 | } | ||
| 907 | |||
| 908 | static int ff_layout_read_prepare_common(struct rpc_task *task, | ||
| 909 | struct nfs_pgio_header *hdr) | ||
| 910 | { | ||
| 911 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) { | ||
| 912 | rpc_exit(task, -EIO); | ||
| 913 | return -EIO; | ||
| 914 | } | ||
| 915 | if (ff_layout_reset_to_mds(hdr->lseg, hdr->pgio_mirror_idx)) { | ||
| 916 | dprintk("%s task %u reset io to MDS\n", __func__, task->tk_pid); | ||
| 917 | if (ff_layout_has_available_ds(hdr->lseg)) | ||
| 918 | pnfs_read_resend_pnfs(hdr); | ||
| 919 | else | ||
| 920 | ff_layout_reset_read(hdr); | ||
| 921 | rpc_exit(task, 0); | ||
| 922 | return -EAGAIN; | ||
| 923 | } | ||
| 924 | hdr->pgio_done_cb = ff_layout_read_done_cb; | ||
| 925 | |||
| 926 | return 0; | ||
| 927 | } | ||
| 928 | |||
| 929 | /* | ||
| 930 | * Call ops for the async read/write cases | ||
| 931 | * In the case of dense layouts, the offset needs to be reset to its | ||
| 932 | * original value. | ||
| 933 | */ | ||
| 934 | static void ff_layout_read_prepare_v3(struct rpc_task *task, void *data) | ||
| 935 | { | ||
| 936 | struct nfs_pgio_header *hdr = data; | ||
| 937 | |||
| 938 | if (ff_layout_read_prepare_common(task, hdr)) | ||
| 939 | return; | ||
| 940 | |||
| 941 | rpc_call_start(task); | ||
| 942 | } | ||
| 943 | |||
| 944 | static int ff_layout_setup_sequence(struct nfs_client *ds_clp, | ||
| 945 | struct nfs4_sequence_args *args, | ||
| 946 | struct nfs4_sequence_res *res, | ||
| 947 | struct rpc_task *task) | ||
| 948 | { | ||
| 949 | if (ds_clp->cl_session) | ||
| 950 | return nfs41_setup_sequence(ds_clp->cl_session, | ||
| 951 | args, | ||
| 952 | res, | ||
| 953 | task); | ||
| 954 | return nfs40_setup_sequence(ds_clp->cl_slot_tbl, | ||
| 955 | args, | ||
| 956 | res, | ||
| 957 | task); | ||
| 958 | } | ||
| 959 | |||
| 960 | static void ff_layout_read_prepare_v4(struct rpc_task *task, void *data) | ||
| 961 | { | ||
| 962 | struct nfs_pgio_header *hdr = data; | ||
| 963 | |||
| 964 | if (ff_layout_read_prepare_common(task, hdr)) | ||
| 965 | return; | ||
| 966 | |||
| 967 | if (ff_layout_setup_sequence(hdr->ds_clp, | ||
| 968 | &hdr->args.seq_args, | ||
| 969 | &hdr->res.seq_res, | ||
| 970 | task)) | ||
| 971 | return; | ||
| 972 | |||
| 973 | if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context, | ||
| 974 | hdr->args.lock_context, FMODE_READ) == -EIO) | ||
| 975 | rpc_exit(task, -EIO); /* lost lock, terminate I/O */ | ||
| 976 | } | ||
| 977 | |||
| 978 | static void ff_layout_read_call_done(struct rpc_task *task, void *data) | ||
| 979 | { | ||
| 980 | struct nfs_pgio_header *hdr = data; | ||
| 981 | |||
| 982 | dprintk("--> %s task->tk_status %d\n", __func__, task->tk_status); | ||
| 983 | |||
| 984 | if (test_bit(NFS_IOHDR_REDO, &hdr->flags) && | ||
| 985 | task->tk_status == 0) { | ||
| 986 | nfs4_sequence_done(task, &hdr->res.seq_res); | ||
| 987 | return; | ||
| 988 | } | ||
| 989 | |||
| 990 | /* Note this may cause RPC to be resent */ | ||
| 991 | hdr->mds_ops->rpc_call_done(task, hdr); | ||
| 992 | } | ||
| 993 | |||
| 994 | static void ff_layout_read_count_stats(struct rpc_task *task, void *data) | ||
| 995 | { | ||
| 996 | struct nfs_pgio_header *hdr = data; | ||
| 997 | |||
| 998 | rpc_count_iostats_metrics(task, | ||
| 999 | &NFS_CLIENT(hdr->inode)->cl_metrics[NFSPROC4_CLNT_READ]); | ||
| 1000 | } | ||
| 1001 | |||
| 1002 | static int ff_layout_write_done_cb(struct rpc_task *task, | ||
| 1003 | struct nfs_pgio_header *hdr) | ||
| 1004 | { | ||
| 1005 | struct inode *inode; | ||
| 1006 | int err; | ||
| 1007 | |||
| 1008 | trace_nfs4_pnfs_write(hdr, task->tk_status); | ||
| 1009 | if (task->tk_status == -ETIMEDOUT && !hdr->res.op_status) | ||
| 1010 | hdr->res.op_status = NFS4ERR_NXIO; | ||
| 1011 | if (task->tk_status < 0 && hdr->res.op_status) | ||
| 1012 | ff_layout_io_track_ds_error(hdr->lseg, hdr->pgio_mirror_idx, | ||
| 1013 | hdr->args.offset, hdr->args.count, | ||
| 1014 | hdr->res.op_status, OP_WRITE); | ||
| 1015 | err = ff_layout_async_handle_error(task, hdr->args.context->state, | ||
| 1016 | hdr->ds_clp, hdr->lseg, | ||
| 1017 | hdr->pgio_mirror_idx); | ||
| 1018 | |||
| 1019 | switch (err) { | ||
| 1020 | case -NFS4ERR_RESET_TO_PNFS: | ||
| 1021 | case -NFS4ERR_RESET_TO_MDS: | ||
| 1022 | inode = hdr->lseg->pls_layout->plh_inode; | ||
| 1023 | pnfs_error_mark_layout_for_return(inode, hdr->lseg); | ||
| 1024 | if (err == -NFS4ERR_RESET_TO_PNFS) { | ||
| 1025 | pnfs_set_retry_layoutget(hdr->lseg->pls_layout); | ||
| 1026 | ff_layout_reset_write(hdr, true); | ||
| 1027 | } else { | ||
| 1028 | pnfs_clear_retry_layoutget(hdr->lseg->pls_layout); | ||
| 1029 | ff_layout_reset_write(hdr, false); | ||
| 1030 | } | ||
| 1031 | return task->tk_status; | ||
| 1032 | case -EAGAIN: | ||
| 1033 | rpc_restart_call_prepare(task); | ||
| 1034 | return -EAGAIN; | ||
| 1035 | } | ||
| 1036 | |||
| 1037 | if (hdr->res.verf->committed == NFS_FILE_SYNC || | ||
| 1038 | hdr->res.verf->committed == NFS_DATA_SYNC) | ||
| 1039 | ff_layout_set_layoutcommit(hdr); | ||
| 1040 | |||
| 1041 | return 0; | ||
| 1042 | } | ||
| 1043 | |||
| 1044 | static int ff_layout_commit_done_cb(struct rpc_task *task, | ||
| 1045 | struct nfs_commit_data *data) | ||
| 1046 | { | ||
| 1047 | struct inode *inode; | ||
| 1048 | int err; | ||
| 1049 | |||
| 1050 | trace_nfs4_pnfs_commit_ds(data, task->tk_status); | ||
| 1051 | if (task->tk_status == -ETIMEDOUT && !data->res.op_status) | ||
| 1052 | data->res.op_status = NFS4ERR_NXIO; | ||
| 1053 | if (task->tk_status < 0 && data->res.op_status) | ||
| 1054 | ff_layout_io_track_ds_error(data->lseg, data->ds_commit_index, | ||
| 1055 | data->args.offset, data->args.count, | ||
| 1056 | data->res.op_status, OP_COMMIT); | ||
| 1057 | err = ff_layout_async_handle_error(task, NULL, data->ds_clp, | ||
| 1058 | data->lseg, data->ds_commit_index); | ||
| 1059 | |||
| 1060 | switch (err) { | ||
| 1061 | case -NFS4ERR_RESET_TO_PNFS: | ||
| 1062 | case -NFS4ERR_RESET_TO_MDS: | ||
| 1063 | inode = data->lseg->pls_layout->plh_inode; | ||
| 1064 | pnfs_error_mark_layout_for_return(inode, data->lseg); | ||
| 1065 | if (err == -NFS4ERR_RESET_TO_PNFS) | ||
| 1066 | pnfs_set_retry_layoutget(data->lseg->pls_layout); | ||
| 1067 | else | ||
| 1068 | pnfs_clear_retry_layoutget(data->lseg->pls_layout); | ||
| 1069 | pnfs_generic_prepare_to_resend_writes(data); | ||
| 1070 | return -EAGAIN; | ||
| 1071 | case -EAGAIN: | ||
| 1072 | rpc_restart_call_prepare(task); | ||
| 1073 | return -EAGAIN; | ||
| 1074 | } | ||
| 1075 | |||
| 1076 | if (data->verf.committed == NFS_UNSTABLE) | ||
| 1077 | pnfs_commit_set_layoutcommit(data); | ||
| 1078 | |||
| 1079 | return 0; | ||
| 1080 | } | ||
| 1081 | |||
| 1082 | static int ff_layout_write_prepare_common(struct rpc_task *task, | ||
| 1083 | struct nfs_pgio_header *hdr) | ||
| 1084 | { | ||
| 1085 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) { | ||
| 1086 | rpc_exit(task, -EIO); | ||
| 1087 | return -EIO; | ||
| 1088 | } | ||
| 1089 | |||
| 1090 | if (ff_layout_reset_to_mds(hdr->lseg, hdr->pgio_mirror_idx)) { | ||
| 1091 | bool retry_pnfs; | ||
| 1092 | |||
| 1093 | retry_pnfs = ff_layout_has_available_ds(hdr->lseg); | ||
| 1094 | dprintk("%s task %u reset io to %s\n", __func__, | ||
| 1095 | task->tk_pid, retry_pnfs ? "pNFS" : "MDS"); | ||
| 1096 | ff_layout_reset_write(hdr, retry_pnfs); | ||
| 1097 | rpc_exit(task, 0); | ||
| 1098 | return -EAGAIN; | ||
| 1099 | } | ||
| 1100 | |||
| 1101 | return 0; | ||
| 1102 | } | ||
| 1103 | |||
| 1104 | static void ff_layout_write_prepare_v3(struct rpc_task *task, void *data) | ||
| 1105 | { | ||
| 1106 | struct nfs_pgio_header *hdr = data; | ||
| 1107 | |||
| 1108 | if (ff_layout_write_prepare_common(task, hdr)) | ||
| 1109 | return; | ||
| 1110 | |||
| 1111 | rpc_call_start(task); | ||
| 1112 | } | ||
| 1113 | |||
| 1114 | static void ff_layout_write_prepare_v4(struct rpc_task *task, void *data) | ||
| 1115 | { | ||
| 1116 | struct nfs_pgio_header *hdr = data; | ||
| 1117 | |||
| 1118 | if (ff_layout_write_prepare_common(task, hdr)) | ||
| 1119 | return; | ||
| 1120 | |||
| 1121 | if (ff_layout_setup_sequence(hdr->ds_clp, | ||
| 1122 | &hdr->args.seq_args, | ||
| 1123 | &hdr->res.seq_res, | ||
| 1124 | task)) | ||
| 1125 | return; | ||
| 1126 | |||
| 1127 | if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context, | ||
| 1128 | hdr->args.lock_context, FMODE_WRITE) == -EIO) | ||
| 1129 | rpc_exit(task, -EIO); /* lost lock, terminate I/O */ | ||
| 1130 | } | ||
| 1131 | |||
| 1132 | static void ff_layout_write_call_done(struct rpc_task *task, void *data) | ||
| 1133 | { | ||
| 1134 | struct nfs_pgio_header *hdr = data; | ||
| 1135 | |||
| 1136 | if (test_bit(NFS_IOHDR_REDO, &hdr->flags) && | ||
| 1137 | task->tk_status == 0) { | ||
| 1138 | nfs4_sequence_done(task, &hdr->res.seq_res); | ||
| 1139 | return; | ||
| 1140 | } | ||
| 1141 | |||
| 1142 | /* Note this may cause RPC to be resent */ | ||
| 1143 | hdr->mds_ops->rpc_call_done(task, hdr); | ||
| 1144 | } | ||
| 1145 | |||
| 1146 | static void ff_layout_write_count_stats(struct rpc_task *task, void *data) | ||
| 1147 | { | ||
| 1148 | struct nfs_pgio_header *hdr = data; | ||
| 1149 | |||
| 1150 | rpc_count_iostats_metrics(task, | ||
| 1151 | &NFS_CLIENT(hdr->inode)->cl_metrics[NFSPROC4_CLNT_WRITE]); | ||
| 1152 | } | ||
| 1153 | |||
| 1154 | static void ff_layout_commit_prepare_v3(struct rpc_task *task, void *data) | ||
| 1155 | { | ||
| 1156 | rpc_call_start(task); | ||
| 1157 | } | ||
| 1158 | |||
| 1159 | static void ff_layout_commit_prepare_v4(struct rpc_task *task, void *data) | ||
| 1160 | { | ||
| 1161 | struct nfs_commit_data *wdata = data; | ||
| 1162 | |||
| 1163 | ff_layout_setup_sequence(wdata->ds_clp, | ||
| 1164 | &wdata->args.seq_args, | ||
| 1165 | &wdata->res.seq_res, | ||
| 1166 | task); | ||
| 1167 | } | ||
| 1168 | |||
| 1169 | static void ff_layout_commit_count_stats(struct rpc_task *task, void *data) | ||
| 1170 | { | ||
| 1171 | struct nfs_commit_data *cdata = data; | ||
| 1172 | |||
| 1173 | rpc_count_iostats_metrics(task, | ||
| 1174 | &NFS_CLIENT(cdata->inode)->cl_metrics[NFSPROC4_CLNT_COMMIT]); | ||
| 1175 | } | ||
| 1176 | |||
| 1177 | static const struct rpc_call_ops ff_layout_read_call_ops_v3 = { | ||
| 1178 | .rpc_call_prepare = ff_layout_read_prepare_v3, | ||
| 1179 | .rpc_call_done = ff_layout_read_call_done, | ||
| 1180 | .rpc_count_stats = ff_layout_read_count_stats, | ||
| 1181 | .rpc_release = pnfs_generic_rw_release, | ||
| 1182 | }; | ||
| 1183 | |||
| 1184 | static const struct rpc_call_ops ff_layout_read_call_ops_v4 = { | ||
| 1185 | .rpc_call_prepare = ff_layout_read_prepare_v4, | ||
| 1186 | .rpc_call_done = ff_layout_read_call_done, | ||
| 1187 | .rpc_count_stats = ff_layout_read_count_stats, | ||
| 1188 | .rpc_release = pnfs_generic_rw_release, | ||
| 1189 | }; | ||
| 1190 | |||
| 1191 | static const struct rpc_call_ops ff_layout_write_call_ops_v3 = { | ||
| 1192 | .rpc_call_prepare = ff_layout_write_prepare_v3, | ||
| 1193 | .rpc_call_done = ff_layout_write_call_done, | ||
| 1194 | .rpc_count_stats = ff_layout_write_count_stats, | ||
| 1195 | .rpc_release = pnfs_generic_rw_release, | ||
| 1196 | }; | ||
| 1197 | |||
| 1198 | static const struct rpc_call_ops ff_layout_write_call_ops_v4 = { | ||
| 1199 | .rpc_call_prepare = ff_layout_write_prepare_v4, | ||
| 1200 | .rpc_call_done = ff_layout_write_call_done, | ||
| 1201 | .rpc_count_stats = ff_layout_write_count_stats, | ||
| 1202 | .rpc_release = pnfs_generic_rw_release, | ||
| 1203 | }; | ||
| 1204 | |||
| 1205 | static const struct rpc_call_ops ff_layout_commit_call_ops_v3 = { | ||
| 1206 | .rpc_call_prepare = ff_layout_commit_prepare_v3, | ||
| 1207 | .rpc_call_done = pnfs_generic_write_commit_done, | ||
| 1208 | .rpc_count_stats = ff_layout_commit_count_stats, | ||
| 1209 | .rpc_release = pnfs_generic_commit_release, | ||
| 1210 | }; | ||
| 1211 | |||
| 1212 | static const struct rpc_call_ops ff_layout_commit_call_ops_v4 = { | ||
| 1213 | .rpc_call_prepare = ff_layout_commit_prepare_v4, | ||
| 1214 | .rpc_call_done = pnfs_generic_write_commit_done, | ||
| 1215 | .rpc_count_stats = ff_layout_commit_count_stats, | ||
| 1216 | .rpc_release = pnfs_generic_commit_release, | ||
| 1217 | }; | ||
| 1218 | |||
| 1219 | static enum pnfs_try_status | ||
| 1220 | ff_layout_read_pagelist(struct nfs_pgio_header *hdr) | ||
| 1221 | { | ||
| 1222 | struct pnfs_layout_segment *lseg = hdr->lseg; | ||
| 1223 | struct nfs4_pnfs_ds *ds; | ||
| 1224 | struct rpc_clnt *ds_clnt; | ||
| 1225 | struct rpc_cred *ds_cred; | ||
| 1226 | loff_t offset = hdr->args.offset; | ||
| 1227 | u32 idx = hdr->pgio_mirror_idx; | ||
| 1228 | int vers; | ||
| 1229 | struct nfs_fh *fh; | ||
| 1230 | |||
| 1231 | dprintk("--> %s ino %lu pgbase %u req %Zu@%llu\n", | ||
| 1232 | __func__, hdr->inode->i_ino, | ||
| 1233 | hdr->args.pgbase, (size_t)hdr->args.count, offset); | ||
| 1234 | |||
| 1235 | ds = nfs4_ff_layout_prepare_ds(lseg, idx, false); | ||
| 1236 | if (!ds) | ||
| 1237 | goto out_failed; | ||
| 1238 | |||
| 1239 | ds_clnt = nfs4_ff_find_or_create_ds_client(lseg, idx, ds->ds_clp, | ||
| 1240 | hdr->inode); | ||
| 1241 | if (IS_ERR(ds_clnt)) | ||
| 1242 | goto out_failed; | ||
| 1243 | |||
| 1244 | ds_cred = ff_layout_get_ds_cred(lseg, idx, hdr->cred); | ||
| 1245 | if (IS_ERR(ds_cred)) | ||
| 1246 | goto out_failed; | ||
| 1247 | |||
| 1248 | vers = nfs4_ff_layout_ds_version(lseg, idx); | ||
| 1249 | |||
| 1250 | dprintk("%s USE DS: %s cl_count %d vers %d\n", __func__, | ||
| 1251 | ds->ds_remotestr, atomic_read(&ds->ds_clp->cl_count), vers); | ||
| 1252 | |||
| 1253 | atomic_inc(&ds->ds_clp->cl_count); | ||
| 1254 | hdr->ds_clp = ds->ds_clp; | ||
| 1255 | fh = nfs4_ff_layout_select_ds_fh(lseg, idx); | ||
| 1256 | if (fh) | ||
| 1257 | hdr->args.fh = fh; | ||
| 1258 | |||
| 1259 | /* | ||
| 1260 | * Note that if we ever decide to split across DSes, | ||
| 1261 | * then we may need to handle dense-like offsets. | ||
| 1262 | */ | ||
| 1263 | hdr->args.offset = offset; | ||
| 1264 | hdr->mds_offset = offset; | ||
| 1265 | |||
| 1266 | /* Perform an asynchronous read to ds */ | ||
| 1267 | nfs_initiate_pgio(ds_clnt, hdr, ds_cred, ds->ds_clp->rpc_ops, | ||
| 1268 | vers == 3 ? &ff_layout_read_call_ops_v3 : | ||
| 1269 | &ff_layout_read_call_ops_v4, | ||
| 1270 | 0, RPC_TASK_SOFTCONN); | ||
| 1271 | |||
| 1272 | return PNFS_ATTEMPTED; | ||
| 1273 | |||
| 1274 | out_failed: | ||
| 1275 | if (ff_layout_has_available_ds(lseg)) | ||
| 1276 | return PNFS_TRY_AGAIN; | ||
| 1277 | return PNFS_NOT_ATTEMPTED; | ||
| 1278 | } | ||
| 1279 | |||
| 1280 | /* Perform async writes. */ | ||
| 1281 | static enum pnfs_try_status | ||
| 1282 | ff_layout_write_pagelist(struct nfs_pgio_header *hdr, int sync) | ||
| 1283 | { | ||
| 1284 | struct pnfs_layout_segment *lseg = hdr->lseg; | ||
| 1285 | struct nfs4_pnfs_ds *ds; | ||
| 1286 | struct rpc_clnt *ds_clnt; | ||
| 1287 | struct rpc_cred *ds_cred; | ||
| 1288 | loff_t offset = hdr->args.offset; | ||
| 1289 | int vers; | ||
| 1290 | struct nfs_fh *fh; | ||
| 1291 | int idx = hdr->pgio_mirror_idx; | ||
| 1292 | |||
| 1293 | ds = nfs4_ff_layout_prepare_ds(lseg, idx, true); | ||
| 1294 | if (!ds) | ||
| 1295 | return PNFS_NOT_ATTEMPTED; | ||
| 1296 | |||
| 1297 | ds_clnt = nfs4_ff_find_or_create_ds_client(lseg, idx, ds->ds_clp, | ||
| 1298 | hdr->inode); | ||
| 1299 | if (IS_ERR(ds_clnt)) | ||
| 1300 | return PNFS_NOT_ATTEMPTED; | ||
| 1301 | |||
| 1302 | ds_cred = ff_layout_get_ds_cred(lseg, idx, hdr->cred); | ||
| 1303 | if (IS_ERR(ds_cred)) | ||
| 1304 | return PNFS_NOT_ATTEMPTED; | ||
| 1305 | |||
| 1306 | vers = nfs4_ff_layout_ds_version(lseg, idx); | ||
| 1307 | |||
| 1308 | dprintk("%s ino %lu sync %d req %Zu@%llu DS: %s cl_count %d vers %d\n", | ||
| 1309 | __func__, hdr->inode->i_ino, sync, (size_t) hdr->args.count, | ||
| 1310 | offset, ds->ds_remotestr, atomic_read(&ds->ds_clp->cl_count), | ||
| 1311 | vers); | ||
| 1312 | |||
| 1313 | hdr->pgio_done_cb = ff_layout_write_done_cb; | ||
| 1314 | atomic_inc(&ds->ds_clp->cl_count); | ||
| 1315 | hdr->ds_clp = ds->ds_clp; | ||
| 1316 | hdr->ds_commit_idx = idx; | ||
| 1317 | fh = nfs4_ff_layout_select_ds_fh(lseg, idx); | ||
| 1318 | if (fh) | ||
| 1319 | hdr->args.fh = fh; | ||
| 1320 | |||
| 1321 | /* | ||
| 1322 | * Note that if we ever decide to split across DSes, | ||
| 1323 | * then we may need to handle dense-like offsets. | ||
| 1324 | */ | ||
| 1325 | hdr->args.offset = offset; | ||
| 1326 | |||
| 1327 | /* Perform an asynchronous write */ | ||
| 1328 | nfs_initiate_pgio(ds_clnt, hdr, ds_cred, ds->ds_clp->rpc_ops, | ||
| 1329 | vers == 3 ? &ff_layout_write_call_ops_v3 : | ||
| 1330 | &ff_layout_write_call_ops_v4, | ||
| 1331 | sync, RPC_TASK_SOFTCONN); | ||
| 1332 | return PNFS_ATTEMPTED; | ||
| 1333 | } | ||
| 1334 | |||
| 1335 | static void | ||
| 1336 | ff_layout_mark_request_commit(struct nfs_page *req, | ||
| 1337 | struct pnfs_layout_segment *lseg, | ||
| 1338 | struct nfs_commit_info *cinfo, | ||
| 1339 | u32 ds_commit_idx) | ||
| 1340 | { | ||
| 1341 | struct list_head *list; | ||
| 1342 | struct pnfs_commit_bucket *buckets; | ||
| 1343 | |||
| 1344 | spin_lock(cinfo->lock); | ||
| 1345 | buckets = cinfo->ds->buckets; | ||
| 1346 | list = &buckets[ds_commit_idx].written; | ||
| 1347 | if (list_empty(list)) { | ||
| 1348 | /* Non-empty buckets hold a reference on the lseg. That ref | ||
| 1349 | * is normally transferred to the COMMIT call and released | ||
| 1350 | * there. It could also be released if the last req is pulled | ||
| 1351 | * off due to a rewrite, in which case it will be done in | ||
| 1352 | * pnfs_common_clear_request_commit | ||
| 1353 | */ | ||
| 1354 | WARN_ON_ONCE(buckets[ds_commit_idx].wlseg != NULL); | ||
| 1355 | buckets[ds_commit_idx].wlseg = pnfs_get_lseg(lseg); | ||
| 1356 | } | ||
| 1357 | set_bit(PG_COMMIT_TO_DS, &req->wb_flags); | ||
| 1358 | cinfo->ds->nwritten++; | ||
| 1359 | |||
| 1360 | /* nfs_request_add_commit_list(). We need to add req to list without | ||
| 1361 | * dropping cinfo lock. | ||
| 1362 | */ | ||
| 1363 | set_bit(PG_CLEAN, &(req)->wb_flags); | ||
| 1364 | nfs_list_add_request(req, list); | ||
| 1365 | cinfo->mds->ncommit++; | ||
| 1366 | spin_unlock(cinfo->lock); | ||
| 1367 | if (!cinfo->dreq) { | ||
| 1368 | inc_zone_page_state(req->wb_page, NR_UNSTABLE_NFS); | ||
| 1369 | inc_bdi_stat(page_file_mapping(req->wb_page)->backing_dev_info, | ||
| 1370 | BDI_RECLAIMABLE); | ||
| 1371 | __mark_inode_dirty(req->wb_context->dentry->d_inode, | ||
| 1372 | I_DIRTY_DATASYNC); | ||
| 1373 | } | ||
| 1374 | } | ||
| 1375 | |||
| 1376 | static u32 calc_ds_index_from_commit(struct pnfs_layout_segment *lseg, u32 i) | ||
| 1377 | { | ||
| 1378 | return i; | ||
| 1379 | } | ||
| 1380 | |||
| 1381 | static struct nfs_fh * | ||
| 1382 | select_ds_fh_from_commit(struct pnfs_layout_segment *lseg, u32 i) | ||
| 1383 | { | ||
| 1384 | struct nfs4_ff_layout_segment *flseg = FF_LAYOUT_LSEG(lseg); | ||
| 1385 | |||
| 1386 | /* FIXME: Assume that there is only one NFS version available | ||
| 1387 | * for the DS. | ||
| 1388 | */ | ||
| 1389 | return &flseg->mirror_array[i]->fh_versions[0]; | ||
| 1390 | } | ||
| 1391 | |||
| 1392 | static int ff_layout_initiate_commit(struct nfs_commit_data *data, int how) | ||
| 1393 | { | ||
| 1394 | struct pnfs_layout_segment *lseg = data->lseg; | ||
| 1395 | struct nfs4_pnfs_ds *ds; | ||
| 1396 | struct rpc_clnt *ds_clnt; | ||
| 1397 | struct rpc_cred *ds_cred; | ||
| 1398 | u32 idx; | ||
| 1399 | int vers; | ||
| 1400 | struct nfs_fh *fh; | ||
| 1401 | |||
| 1402 | idx = calc_ds_index_from_commit(lseg, data->ds_commit_index); | ||
| 1403 | ds = nfs4_ff_layout_prepare_ds(lseg, idx, true); | ||
| 1404 | if (!ds) | ||
| 1405 | goto out_err; | ||
| 1406 | |||
| 1407 | ds_clnt = nfs4_ff_find_or_create_ds_client(lseg, idx, ds->ds_clp, | ||
| 1408 | data->inode); | ||
| 1409 | if (IS_ERR(ds_clnt)) | ||
| 1410 | goto out_err; | ||
| 1411 | |||
| 1412 | ds_cred = ff_layout_get_ds_cred(lseg, idx, data->cred); | ||
| 1413 | if (IS_ERR(ds_cred)) | ||
| 1414 | goto out_err; | ||
| 1415 | |||
| 1416 | vers = nfs4_ff_layout_ds_version(lseg, idx); | ||
| 1417 | |||
| 1418 | dprintk("%s ino %lu, how %d cl_count %d vers %d\n", __func__, | ||
| 1419 | data->inode->i_ino, how, atomic_read(&ds->ds_clp->cl_count), | ||
| 1420 | vers); | ||
| 1421 | data->commit_done_cb = ff_layout_commit_done_cb; | ||
| 1422 | data->cred = ds_cred; | ||
| 1423 | atomic_inc(&ds->ds_clp->cl_count); | ||
| 1424 | data->ds_clp = ds->ds_clp; | ||
| 1425 | fh = select_ds_fh_from_commit(lseg, data->ds_commit_index); | ||
| 1426 | if (fh) | ||
| 1427 | data->args.fh = fh; | ||
| 1428 | return nfs_initiate_commit(ds_clnt, data, ds->ds_clp->rpc_ops, | ||
| 1429 | vers == 3 ? &ff_layout_commit_call_ops_v3 : | ||
| 1430 | &ff_layout_commit_call_ops_v4, | ||
| 1431 | how, RPC_TASK_SOFTCONN); | ||
| 1432 | out_err: | ||
| 1433 | pnfs_generic_prepare_to_resend_writes(data); | ||
| 1434 | pnfs_generic_commit_release(data); | ||
| 1435 | return -EAGAIN; | ||
| 1436 | } | ||
| 1437 | |||
| 1438 | static int | ||
| 1439 | ff_layout_commit_pagelist(struct inode *inode, struct list_head *mds_pages, | ||
| 1440 | int how, struct nfs_commit_info *cinfo) | ||
| 1441 | { | ||
| 1442 | return pnfs_generic_commit_pagelist(inode, mds_pages, how, cinfo, | ||
| 1443 | ff_layout_initiate_commit); | ||
| 1444 | } | ||
| 1445 | |||
| 1446 | static struct pnfs_ds_commit_info * | ||
| 1447 | ff_layout_get_ds_info(struct inode *inode) | ||
| 1448 | { | ||
| 1449 | struct pnfs_layout_hdr *layout = NFS_I(inode)->layout; | ||
| 1450 | |||
| 1451 | if (layout == NULL) | ||
| 1452 | return NULL; | ||
| 1453 | |||
| 1454 | return &FF_LAYOUT_FROM_HDR(layout)->commit_info; | ||
| 1455 | } | ||
| 1456 | |||
| 1457 | static void | ||
| 1458 | ff_layout_free_deveiceid_node(struct nfs4_deviceid_node *d) | ||
| 1459 | { | ||
| 1460 | nfs4_ff_layout_free_deviceid(container_of(d, struct nfs4_ff_layout_ds, | ||
| 1461 | id_node)); | ||
| 1462 | } | ||
| 1463 | |||
| 1464 | static int ff_layout_encode_ioerr(struct nfs4_flexfile_layout *flo, | ||
| 1465 | struct xdr_stream *xdr, | ||
| 1466 | const struct nfs4_layoutreturn_args *args) | ||
| 1467 | { | ||
| 1468 | struct pnfs_layout_hdr *hdr = &flo->generic_hdr; | ||
| 1469 | __be32 *start; | ||
| 1470 | int count = 0, ret = 0; | ||
| 1471 | |||
| 1472 | start = xdr_reserve_space(xdr, 4); | ||
| 1473 | if (unlikely(!start)) | ||
| 1474 | return -E2BIG; | ||
| 1475 | |||
| 1476 | /* This assume we always return _ALL_ layouts */ | ||
| 1477 | spin_lock(&hdr->plh_inode->i_lock); | ||
| 1478 | ret = ff_layout_encode_ds_ioerr(flo, xdr, &count, &args->range); | ||
| 1479 | spin_unlock(&hdr->plh_inode->i_lock); | ||
| 1480 | |||
| 1481 | *start = cpu_to_be32(count); | ||
| 1482 | |||
| 1483 | return ret; | ||
| 1484 | } | ||
| 1485 | |||
| 1486 | /* report nothing for now */ | ||
| 1487 | static void ff_layout_encode_iostats(struct nfs4_flexfile_layout *flo, | ||
| 1488 | struct xdr_stream *xdr, | ||
| 1489 | const struct nfs4_layoutreturn_args *args) | ||
| 1490 | { | ||
| 1491 | __be32 *p; | ||
| 1492 | |||
| 1493 | p = xdr_reserve_space(xdr, 4); | ||
| 1494 | if (likely(p)) | ||
| 1495 | *p = cpu_to_be32(0); | ||
| 1496 | } | ||
| 1497 | |||
| 1498 | static struct nfs4_deviceid_node * | ||
| 1499 | ff_layout_alloc_deviceid_node(struct nfs_server *server, | ||
| 1500 | struct pnfs_device *pdev, gfp_t gfp_flags) | ||
| 1501 | { | ||
| 1502 | struct nfs4_ff_layout_ds *dsaddr; | ||
| 1503 | |||
| 1504 | dsaddr = nfs4_ff_alloc_deviceid_node(server, pdev, gfp_flags); | ||
| 1505 | if (!dsaddr) | ||
| 1506 | return NULL; | ||
| 1507 | return &dsaddr->id_node; | ||
| 1508 | } | ||
| 1509 | |||
| 1510 | static void | ||
| 1511 | ff_layout_encode_layoutreturn(struct pnfs_layout_hdr *lo, | ||
| 1512 | struct xdr_stream *xdr, | ||
| 1513 | const struct nfs4_layoutreturn_args *args) | ||
| 1514 | { | ||
| 1515 | struct nfs4_flexfile_layout *flo = FF_LAYOUT_FROM_HDR(lo); | ||
| 1516 | __be32 *start; | ||
| 1517 | |||
| 1518 | dprintk("%s: Begin\n", __func__); | ||
| 1519 | start = xdr_reserve_space(xdr, 4); | ||
| 1520 | BUG_ON(!start); | ||
| 1521 | |||
| 1522 | if (ff_layout_encode_ioerr(flo, xdr, args)) | ||
| 1523 | goto out; | ||
| 1524 | |||
| 1525 | ff_layout_encode_iostats(flo, xdr, args); | ||
| 1526 | out: | ||
| 1527 | *start = cpu_to_be32((xdr->p - start - 1) * 4); | ||
| 1528 | dprintk("%s: Return\n", __func__); | ||
| 1529 | } | ||
| 1530 | |||
| 1531 | static struct pnfs_layoutdriver_type flexfilelayout_type = { | ||
| 1532 | .id = LAYOUT_FLEX_FILES, | ||
| 1533 | .name = "LAYOUT_FLEX_FILES", | ||
| 1534 | .owner = THIS_MODULE, | ||
| 1535 | .alloc_layout_hdr = ff_layout_alloc_layout_hdr, | ||
| 1536 | .free_layout_hdr = ff_layout_free_layout_hdr, | ||
| 1537 | .alloc_lseg = ff_layout_alloc_lseg, | ||
| 1538 | .free_lseg = ff_layout_free_lseg, | ||
| 1539 | .pg_read_ops = &ff_layout_pg_read_ops, | ||
| 1540 | .pg_write_ops = &ff_layout_pg_write_ops, | ||
| 1541 | .get_ds_info = ff_layout_get_ds_info, | ||
| 1542 | .free_deviceid_node = ff_layout_free_deveiceid_node, | ||
| 1543 | .mark_request_commit = ff_layout_mark_request_commit, | ||
| 1544 | .clear_request_commit = pnfs_generic_clear_request_commit, | ||
| 1545 | .scan_commit_lists = pnfs_generic_scan_commit_lists, | ||
| 1546 | .recover_commit_reqs = pnfs_generic_recover_commit_reqs, | ||
| 1547 | .commit_pagelist = ff_layout_commit_pagelist, | ||
| 1548 | .read_pagelist = ff_layout_read_pagelist, | ||
| 1549 | .write_pagelist = ff_layout_write_pagelist, | ||
| 1550 | .alloc_deviceid_node = ff_layout_alloc_deviceid_node, | ||
| 1551 | .encode_layoutreturn = ff_layout_encode_layoutreturn, | ||
| 1552 | }; | ||
| 1553 | |||
| 1554 | static int __init nfs4flexfilelayout_init(void) | ||
| 1555 | { | ||
| 1556 | printk(KERN_INFO "%s: NFSv4 Flexfile Layout Driver Registering...\n", | ||
| 1557 | __func__); | ||
| 1558 | return pnfs_register_layoutdriver(&flexfilelayout_type); | ||
| 1559 | } | ||
| 1560 | |||
| 1561 | static void __exit nfs4flexfilelayout_exit(void) | ||
| 1562 | { | ||
| 1563 | printk(KERN_INFO "%s: NFSv4 Flexfile Layout Driver Unregistering...\n", | ||
| 1564 | __func__); | ||
| 1565 | pnfs_unregister_layoutdriver(&flexfilelayout_type); | ||
| 1566 | } | ||
| 1567 | |||
| 1568 | MODULE_ALIAS("nfs-layouttype4-4"); | ||
| 1569 | |||
| 1570 | MODULE_LICENSE("GPL"); | ||
| 1571 | MODULE_DESCRIPTION("The NFSv4 flexfile layout driver"); | ||
| 1572 | |||
| 1573 | module_init(nfs4flexfilelayout_init); | ||
| 1574 | module_exit(nfs4flexfilelayout_exit); | ||
diff --git a/fs/nfs/flexfilelayout/flexfilelayout.h b/fs/nfs/flexfilelayout/flexfilelayout.h new file mode 100644 index 000000000000..070f20445b2d --- /dev/null +++ b/fs/nfs/flexfilelayout/flexfilelayout.h | |||
| @@ -0,0 +1,155 @@ | |||
| 1 | /* | ||
| 2 | * NFSv4 flexfile layout driver data structures. | ||
| 3 | * | ||
| 4 | * Copyright (c) 2014, Primary Data, Inc. All rights reserved. | ||
| 5 | * | ||
| 6 | * Tao Peng <bergwolf@primarydata.com> | ||
| 7 | */ | ||
| 8 | |||
| 9 | #ifndef FS_NFS_NFS4FLEXFILELAYOUT_H | ||
| 10 | #define FS_NFS_NFS4FLEXFILELAYOUT_H | ||
| 11 | |||
| 12 | #include "../pnfs.h" | ||
| 13 | |||
| 14 | /* XXX: Let's filter out insanely large mirror count for now to avoid oom | ||
| 15 | * due to network error etc. */ | ||
| 16 | #define NFS4_FLEXFILE_LAYOUT_MAX_MIRROR_CNT 4096 | ||
| 17 | |||
| 18 | struct nfs4_ff_ds_version { | ||
| 19 | u32 version; | ||
| 20 | u32 minor_version; | ||
| 21 | u32 rsize; | ||
| 22 | u32 wsize; | ||
| 23 | bool tightly_coupled; | ||
| 24 | }; | ||
| 25 | |||
| 26 | /* chained in global deviceid hlist */ | ||
| 27 | struct nfs4_ff_layout_ds { | ||
| 28 | struct nfs4_deviceid_node id_node; | ||
| 29 | u32 ds_versions_cnt; | ||
| 30 | struct nfs4_ff_ds_version *ds_versions; | ||
| 31 | struct nfs4_pnfs_ds *ds; | ||
| 32 | }; | ||
| 33 | |||
| 34 | struct nfs4_ff_layout_ds_err { | ||
| 35 | struct list_head list; /* linked in mirror error_list */ | ||
| 36 | u64 offset; | ||
| 37 | u64 length; | ||
| 38 | int status; | ||
| 39 | enum nfs_opnum4 opnum; | ||
| 40 | nfs4_stateid stateid; | ||
| 41 | struct nfs4_deviceid deviceid; | ||
| 42 | }; | ||
| 43 | |||
| 44 | struct nfs4_ff_layout_mirror { | ||
| 45 | u32 ds_count; | ||
| 46 | u32 efficiency; | ||
| 47 | struct nfs4_ff_layout_ds *mirror_ds; | ||
| 48 | u32 fh_versions_cnt; | ||
| 49 | struct nfs_fh *fh_versions; | ||
| 50 | nfs4_stateid stateid; | ||
| 51 | struct nfs4_string user_name; | ||
| 52 | struct nfs4_string group_name; | ||
| 53 | u32 uid; | ||
| 54 | u32 gid; | ||
| 55 | struct rpc_cred *cred; | ||
| 56 | spinlock_t lock; | ||
| 57 | }; | ||
| 58 | |||
| 59 | struct nfs4_ff_layout_segment { | ||
| 60 | struct pnfs_layout_segment generic_hdr; | ||
| 61 | u64 stripe_unit; | ||
| 62 | u32 mirror_array_cnt; | ||
| 63 | struct nfs4_ff_layout_mirror **mirror_array; | ||
| 64 | }; | ||
| 65 | |||
| 66 | struct nfs4_flexfile_layout { | ||
| 67 | struct pnfs_layout_hdr generic_hdr; | ||
| 68 | struct pnfs_ds_commit_info commit_info; | ||
| 69 | struct list_head error_list; /* nfs4_ff_layout_ds_err */ | ||
| 70 | }; | ||
| 71 | |||
| 72 | static inline struct nfs4_flexfile_layout * | ||
| 73 | FF_LAYOUT_FROM_HDR(struct pnfs_layout_hdr *lo) | ||
| 74 | { | ||
| 75 | return container_of(lo, struct nfs4_flexfile_layout, generic_hdr); | ||
| 76 | } | ||
| 77 | |||
| 78 | static inline struct nfs4_ff_layout_segment * | ||
| 79 | FF_LAYOUT_LSEG(struct pnfs_layout_segment *lseg) | ||
| 80 | { | ||
| 81 | return container_of(lseg, | ||
| 82 | struct nfs4_ff_layout_segment, | ||
| 83 | generic_hdr); | ||
| 84 | } | ||
| 85 | |||
| 86 | static inline struct nfs4_deviceid_node * | ||
| 87 | FF_LAYOUT_DEVID_NODE(struct pnfs_layout_segment *lseg, u32 idx) | ||
| 88 | { | ||
| 89 | if (idx >= FF_LAYOUT_LSEG(lseg)->mirror_array_cnt || | ||
| 90 | FF_LAYOUT_LSEG(lseg)->mirror_array[idx] == NULL || | ||
| 91 | FF_LAYOUT_LSEG(lseg)->mirror_array[idx]->mirror_ds == NULL) | ||
| 92 | return NULL; | ||
| 93 | return &FF_LAYOUT_LSEG(lseg)->mirror_array[idx]->mirror_ds->id_node; | ||
| 94 | } | ||
| 95 | |||
| 96 | static inline struct nfs4_ff_layout_ds * | ||
| 97 | FF_LAYOUT_MIRROR_DS(struct nfs4_deviceid_node *node) | ||
| 98 | { | ||
| 99 | return container_of(node, struct nfs4_ff_layout_ds, id_node); | ||
| 100 | } | ||
| 101 | |||
| 102 | static inline struct nfs4_ff_layout_mirror * | ||
| 103 | FF_LAYOUT_COMP(struct pnfs_layout_segment *lseg, u32 idx) | ||
| 104 | { | ||
| 105 | if (idx >= FF_LAYOUT_LSEG(lseg)->mirror_array_cnt) | ||
| 106 | return NULL; | ||
| 107 | return FF_LAYOUT_LSEG(lseg)->mirror_array[idx]; | ||
| 108 | } | ||
| 109 | |||
| 110 | static inline u32 | ||
| 111 | FF_LAYOUT_MIRROR_COUNT(struct pnfs_layout_segment *lseg) | ||
| 112 | { | ||
| 113 | return FF_LAYOUT_LSEG(lseg)->mirror_array_cnt; | ||
| 114 | } | ||
| 115 | |||
| 116 | static inline bool | ||
| 117 | ff_layout_test_devid_unavailable(struct nfs4_deviceid_node *node) | ||
| 118 | { | ||
| 119 | return nfs4_test_deviceid_unavailable(node); | ||
| 120 | } | ||
| 121 | |||
| 122 | static inline int | ||
| 123 | nfs4_ff_layout_ds_version(struct pnfs_layout_segment *lseg, u32 ds_idx) | ||
| 124 | { | ||
| 125 | return FF_LAYOUT_COMP(lseg, ds_idx)->mirror_ds->ds_versions[0].version; | ||
| 126 | } | ||
| 127 | |||
| 128 | struct nfs4_ff_layout_ds * | ||
| 129 | nfs4_ff_alloc_deviceid_node(struct nfs_server *server, struct pnfs_device *pdev, | ||
| 130 | gfp_t gfp_flags); | ||
| 131 | void nfs4_ff_layout_put_deviceid(struct nfs4_ff_layout_ds *mirror_ds); | ||
| 132 | void nfs4_ff_layout_free_deviceid(struct nfs4_ff_layout_ds *mirror_ds); | ||
| 133 | int ff_layout_track_ds_error(struct nfs4_flexfile_layout *flo, | ||
| 134 | struct nfs4_ff_layout_mirror *mirror, u64 offset, | ||
| 135 | u64 length, int status, enum nfs_opnum4 opnum, | ||
| 136 | gfp_t gfp_flags); | ||
| 137 | int ff_layout_encode_ds_ioerr(struct nfs4_flexfile_layout *flo, | ||
| 138 | struct xdr_stream *xdr, int *count, | ||
| 139 | const struct pnfs_layout_range *range); | ||
| 140 | struct nfs_fh * | ||
| 141 | nfs4_ff_layout_select_ds_fh(struct pnfs_layout_segment *lseg, u32 mirror_idx); | ||
| 142 | |||
| 143 | struct nfs4_pnfs_ds * | ||
| 144 | nfs4_ff_layout_prepare_ds(struct pnfs_layout_segment *lseg, u32 ds_idx, | ||
| 145 | bool fail_return); | ||
| 146 | |||
| 147 | struct rpc_clnt * | ||
| 148 | nfs4_ff_find_or_create_ds_client(struct pnfs_layout_segment *lseg, | ||
| 149 | u32 ds_idx, | ||
| 150 | struct nfs_client *ds_clp, | ||
| 151 | struct inode *inode); | ||
| 152 | struct rpc_cred *ff_layout_get_ds_cred(struct pnfs_layout_segment *lseg, | ||
| 153 | u32 ds_idx, struct rpc_cred *mdscred); | ||
| 154 | bool ff_layout_has_available_ds(struct pnfs_layout_segment *lseg); | ||
| 155 | #endif /* FS_NFS_NFS4FLEXFILELAYOUT_H */ | ||
diff --git a/fs/nfs/flexfilelayout/flexfilelayoutdev.c b/fs/nfs/flexfilelayout/flexfilelayoutdev.c new file mode 100644 index 000000000000..3bbb16b3066f --- /dev/null +++ b/fs/nfs/flexfilelayout/flexfilelayoutdev.c | |||
| @@ -0,0 +1,552 @@ | |||
| 1 | /* | ||
| 2 | * Device operations for the pnfs nfs4 file layout driver. | ||
| 3 | * | ||
| 4 | * Copyright (c) 2014, Primary Data, Inc. All rights reserved. | ||
| 5 | * | ||
| 6 | * Tao Peng <bergwolf@primarydata.com> | ||
| 7 | */ | ||
| 8 | |||
| 9 | #include <linux/nfs_fs.h> | ||
| 10 | #include <linux/vmalloc.h> | ||
| 11 | #include <linux/module.h> | ||
| 12 | #include <linux/sunrpc/addr.h> | ||
| 13 | |||
| 14 | #include "../internal.h" | ||
| 15 | #include "../nfs4session.h" | ||
| 16 | #include "flexfilelayout.h" | ||
| 17 | |||
| 18 | #define NFSDBG_FACILITY NFSDBG_PNFS_LD | ||
| 19 | |||
| 20 | static unsigned int dataserver_timeo = NFS4_DEF_DS_TIMEO; | ||
| 21 | static unsigned int dataserver_retrans = NFS4_DEF_DS_RETRANS; | ||
| 22 | |||
| 23 | void nfs4_ff_layout_put_deviceid(struct nfs4_ff_layout_ds *mirror_ds) | ||
| 24 | { | ||
| 25 | if (mirror_ds) | ||
| 26 | nfs4_put_deviceid_node(&mirror_ds->id_node); | ||
| 27 | } | ||
| 28 | |||
| 29 | void nfs4_ff_layout_free_deviceid(struct nfs4_ff_layout_ds *mirror_ds) | ||
| 30 | { | ||
| 31 | nfs4_print_deviceid(&mirror_ds->id_node.deviceid); | ||
| 32 | nfs4_pnfs_ds_put(mirror_ds->ds); | ||
| 33 | kfree(mirror_ds); | ||
| 34 | } | ||
| 35 | |||
| 36 | /* Decode opaque device data and construct new_ds using it */ | ||
| 37 | struct nfs4_ff_layout_ds * | ||
| 38 | nfs4_ff_alloc_deviceid_node(struct nfs_server *server, struct pnfs_device *pdev, | ||
| 39 | gfp_t gfp_flags) | ||
| 40 | { | ||
| 41 | struct xdr_stream stream; | ||
| 42 | struct xdr_buf buf; | ||
| 43 | struct page *scratch; | ||
| 44 | struct list_head dsaddrs; | ||
| 45 | struct nfs4_pnfs_ds_addr *da; | ||
| 46 | struct nfs4_ff_layout_ds *new_ds = NULL; | ||
| 47 | struct nfs4_ff_ds_version *ds_versions = NULL; | ||
| 48 | u32 mp_count; | ||
| 49 | u32 version_count; | ||
| 50 | __be32 *p; | ||
| 51 | int i, ret = -ENOMEM; | ||
| 52 | |||
| 53 | /* set up xdr stream */ | ||
| 54 | scratch = alloc_page(gfp_flags); | ||
| 55 | if (!scratch) | ||
| 56 | goto out_err; | ||
| 57 | |||
| 58 | new_ds = kzalloc(sizeof(struct nfs4_ff_layout_ds), gfp_flags); | ||
| 59 | if (!new_ds) | ||
| 60 | goto out_scratch; | ||
| 61 | |||
| 62 | nfs4_init_deviceid_node(&new_ds->id_node, | ||
| 63 | server, | ||
| 64 | &pdev->dev_id); | ||
| 65 | INIT_LIST_HEAD(&dsaddrs); | ||
| 66 | |||
| 67 | xdr_init_decode_pages(&stream, &buf, pdev->pages, pdev->pglen); | ||
| 68 | xdr_set_scratch_buffer(&stream, page_address(scratch), PAGE_SIZE); | ||
| 69 | |||
| 70 | /* multipath count */ | ||
| 71 | p = xdr_inline_decode(&stream, 4); | ||
| 72 | if (unlikely(!p)) | ||
| 73 | goto out_err_drain_dsaddrs; | ||
| 74 | mp_count = be32_to_cpup(p); | ||
| 75 | dprintk("%s: multipath ds count %d\n", __func__, mp_count); | ||
| 76 | |||
| 77 | for (i = 0; i < mp_count; i++) { | ||
| 78 | /* multipath ds */ | ||
| 79 | da = nfs4_decode_mp_ds_addr(server->nfs_client->cl_net, | ||
| 80 | &stream, gfp_flags); | ||
| 81 | if (da) | ||
| 82 | list_add_tail(&da->da_node, &dsaddrs); | ||
| 83 | } | ||
| 84 | if (list_empty(&dsaddrs)) { | ||
| 85 | dprintk("%s: no suitable DS addresses found\n", | ||
| 86 | __func__); | ||
| 87 | ret = -ENOMEDIUM; | ||
| 88 | goto out_err_drain_dsaddrs; | ||
| 89 | } | ||
| 90 | |||
| 91 | /* version count */ | ||
| 92 | p = xdr_inline_decode(&stream, 4); | ||
| 93 | if (unlikely(!p)) | ||
| 94 | goto out_err_drain_dsaddrs; | ||
| 95 | version_count = be32_to_cpup(p); | ||
| 96 | dprintk("%s: version count %d\n", __func__, version_count); | ||
| 97 | |||
| 98 | ds_versions = kzalloc(version_count * sizeof(struct nfs4_ff_ds_version), | ||
| 99 | gfp_flags); | ||
| 100 | if (!ds_versions) | ||
| 101 | goto out_scratch; | ||
| 102 | |||
| 103 | for (i = 0; i < version_count; i++) { | ||
| 104 | /* 20 = version(4) + minor_version(4) + rsize(4) + wsize(4) + | ||
| 105 | * tightly_coupled(4) */ | ||
| 106 | p = xdr_inline_decode(&stream, 20); | ||
| 107 | if (unlikely(!p)) | ||
| 108 | goto out_err_drain_dsaddrs; | ||
| 109 | ds_versions[i].version = be32_to_cpup(p++); | ||
| 110 | ds_versions[i].minor_version = be32_to_cpup(p++); | ||
| 111 | ds_versions[i].rsize = nfs_block_size(be32_to_cpup(p++), NULL); | ||
| 112 | ds_versions[i].wsize = nfs_block_size(be32_to_cpup(p++), NULL); | ||
| 113 | ds_versions[i].tightly_coupled = be32_to_cpup(p); | ||
| 114 | |||
| 115 | if (ds_versions[i].rsize > NFS_MAX_FILE_IO_SIZE) | ||
| 116 | ds_versions[i].rsize = NFS_MAX_FILE_IO_SIZE; | ||
| 117 | if (ds_versions[i].wsize > NFS_MAX_FILE_IO_SIZE) | ||
| 118 | ds_versions[i].wsize = NFS_MAX_FILE_IO_SIZE; | ||
| 119 | |||
| 120 | if (ds_versions[i].version != 3 || ds_versions[i].minor_version != 0) { | ||
| 121 | dprintk("%s: [%d] unsupported ds version %d-%d\n", __func__, | ||
| 122 | i, ds_versions[i].version, | ||
| 123 | ds_versions[i].minor_version); | ||
| 124 | ret = -EPROTONOSUPPORT; | ||
| 125 | goto out_err_drain_dsaddrs; | ||
| 126 | } | ||
| 127 | |||
| 128 | dprintk("%s: [%d] vers %u minor_ver %u rsize %u wsize %u coupled %d\n", | ||
| 129 | __func__, i, ds_versions[i].version, | ||
| 130 | ds_versions[i].minor_version, | ||
| 131 | ds_versions[i].rsize, | ||
| 132 | ds_versions[i].wsize, | ||
| 133 | ds_versions[i].tightly_coupled); | ||
| 134 | } | ||
| 135 | |||
| 136 | new_ds->ds_versions = ds_versions; | ||
| 137 | new_ds->ds_versions_cnt = version_count; | ||
| 138 | |||
| 139 | new_ds->ds = nfs4_pnfs_ds_add(&dsaddrs, gfp_flags); | ||
| 140 | if (!new_ds->ds) | ||
| 141 | goto out_err_drain_dsaddrs; | ||
| 142 | |||
| 143 | /* If DS was already in cache, free ds addrs */ | ||
| 144 | while (!list_empty(&dsaddrs)) { | ||
| 145 | da = list_first_entry(&dsaddrs, | ||
| 146 | struct nfs4_pnfs_ds_addr, | ||
| 147 | da_node); | ||
| 148 | list_del_init(&da->da_node); | ||
| 149 | kfree(da->da_remotestr); | ||
| 150 | kfree(da); | ||
| 151 | } | ||
| 152 | |||
| 153 | __free_page(scratch); | ||
| 154 | return new_ds; | ||
| 155 | |||
| 156 | out_err_drain_dsaddrs: | ||
| 157 | while (!list_empty(&dsaddrs)) { | ||
| 158 | da = list_first_entry(&dsaddrs, struct nfs4_pnfs_ds_addr, | ||
| 159 | da_node); | ||
| 160 | list_del_init(&da->da_node); | ||
| 161 | kfree(da->da_remotestr); | ||
| 162 | kfree(da); | ||
| 163 | } | ||
| 164 | |||
| 165 | kfree(ds_versions); | ||
| 166 | out_scratch: | ||
| 167 | __free_page(scratch); | ||
| 168 | out_err: | ||
| 169 | kfree(new_ds); | ||
| 170 | |||
| 171 | dprintk("%s ERROR: returning %d\n", __func__, ret); | ||
| 172 | return NULL; | ||
| 173 | } | ||
| 174 | |||
| 175 | static u64 | ||
| 176 | end_offset(u64 start, u64 len) | ||
| 177 | { | ||
| 178 | u64 end; | ||
| 179 | |||
| 180 | end = start + len; | ||
| 181 | return end >= start ? end : NFS4_MAX_UINT64; | ||
| 182 | } | ||
| 183 | |||
| 184 | static void extend_ds_error(struct nfs4_ff_layout_ds_err *err, | ||
| 185 | u64 offset, u64 length) | ||
| 186 | { | ||
| 187 | u64 end; | ||
| 188 | |||
| 189 | end = max_t(u64, end_offset(err->offset, err->length), | ||
| 190 | end_offset(offset, length)); | ||
| 191 | err->offset = min_t(u64, err->offset, offset); | ||
| 192 | err->length = end - err->offset; | ||
| 193 | } | ||
| 194 | |||
| 195 | static bool ds_error_can_merge(struct nfs4_ff_layout_ds_err *err, u64 offset, | ||
| 196 | u64 length, int status, enum nfs_opnum4 opnum, | ||
| 197 | nfs4_stateid *stateid, | ||
| 198 | struct nfs4_deviceid *deviceid) | ||
| 199 | { | ||
| 200 | return err->status == status && err->opnum == opnum && | ||
| 201 | nfs4_stateid_match(&err->stateid, stateid) && | ||
| 202 | !memcmp(&err->deviceid, deviceid, sizeof(*deviceid)) && | ||
| 203 | end_offset(err->offset, err->length) >= offset && | ||
| 204 | err->offset <= end_offset(offset, length); | ||
| 205 | } | ||
| 206 | |||
| 207 | static bool merge_ds_error(struct nfs4_ff_layout_ds_err *old, | ||
| 208 | struct nfs4_ff_layout_ds_err *new) | ||
| 209 | { | ||
| 210 | if (!ds_error_can_merge(old, new->offset, new->length, new->status, | ||
| 211 | new->opnum, &new->stateid, &new->deviceid)) | ||
| 212 | return false; | ||
| 213 | |||
| 214 | extend_ds_error(old, new->offset, new->length); | ||
| 215 | return true; | ||
| 216 | } | ||
| 217 | |||
| 218 | static bool | ||
| 219 | ff_layout_add_ds_error_locked(struct nfs4_flexfile_layout *flo, | ||
| 220 | struct nfs4_ff_layout_ds_err *dserr) | ||
| 221 | { | ||
| 222 | struct nfs4_ff_layout_ds_err *err; | ||
| 223 | |||
| 224 | list_for_each_entry(err, &flo->error_list, list) { | ||
| 225 | if (merge_ds_error(err, dserr)) { | ||
| 226 | return true; | ||
| 227 | } | ||
| 228 | } | ||
| 229 | |||
| 230 | list_add(&dserr->list, &flo->error_list); | ||
| 231 | return false; | ||
| 232 | } | ||
| 233 | |||
| 234 | static bool | ||
| 235 | ff_layout_update_ds_error(struct nfs4_flexfile_layout *flo, u64 offset, | ||
| 236 | u64 length, int status, enum nfs_opnum4 opnum, | ||
| 237 | nfs4_stateid *stateid, struct nfs4_deviceid *deviceid) | ||
| 238 | { | ||
| 239 | bool found = false; | ||
| 240 | struct nfs4_ff_layout_ds_err *err; | ||
| 241 | |||
| 242 | list_for_each_entry(err, &flo->error_list, list) { | ||
| 243 | if (ds_error_can_merge(err, offset, length, status, opnum, | ||
| 244 | stateid, deviceid)) { | ||
| 245 | found = true; | ||
| 246 | extend_ds_error(err, offset, length); | ||
| 247 | break; | ||
| 248 | } | ||
| 249 | } | ||
| 250 | |||
| 251 | return found; | ||
| 252 | } | ||
| 253 | |||
| 254 | int ff_layout_track_ds_error(struct nfs4_flexfile_layout *flo, | ||
| 255 | struct nfs4_ff_layout_mirror *mirror, u64 offset, | ||
| 256 | u64 length, int status, enum nfs_opnum4 opnum, | ||
| 257 | gfp_t gfp_flags) | ||
| 258 | { | ||
| 259 | struct nfs4_ff_layout_ds_err *dserr; | ||
| 260 | bool needfree; | ||
| 261 | |||
| 262 | if (status == 0) | ||
| 263 | return 0; | ||
| 264 | |||
| 265 | if (mirror->mirror_ds == NULL) | ||
| 266 | return -EINVAL; | ||
| 267 | |||
| 268 | spin_lock(&flo->generic_hdr.plh_inode->i_lock); | ||
| 269 | if (ff_layout_update_ds_error(flo, offset, length, status, opnum, | ||
| 270 | &mirror->stateid, | ||
| 271 | &mirror->mirror_ds->id_node.deviceid)) { | ||
| 272 | spin_unlock(&flo->generic_hdr.plh_inode->i_lock); | ||
| 273 | return 0; | ||
| 274 | } | ||
| 275 | spin_unlock(&flo->generic_hdr.plh_inode->i_lock); | ||
| 276 | dserr = kmalloc(sizeof(*dserr), gfp_flags); | ||
| 277 | if (!dserr) | ||
| 278 | return -ENOMEM; | ||
| 279 | |||
| 280 | INIT_LIST_HEAD(&dserr->list); | ||
| 281 | dserr->offset = offset; | ||
| 282 | dserr->length = length; | ||
| 283 | dserr->status = status; | ||
| 284 | dserr->opnum = opnum; | ||
| 285 | nfs4_stateid_copy(&dserr->stateid, &mirror->stateid); | ||
| 286 | memcpy(&dserr->deviceid, &mirror->mirror_ds->id_node.deviceid, | ||
| 287 | NFS4_DEVICEID4_SIZE); | ||
| 288 | |||
| 289 | spin_lock(&flo->generic_hdr.plh_inode->i_lock); | ||
| 290 | needfree = ff_layout_add_ds_error_locked(flo, dserr); | ||
| 291 | spin_unlock(&flo->generic_hdr.plh_inode->i_lock); | ||
| 292 | if (needfree) | ||
| 293 | kfree(dserr); | ||
| 294 | |||
| 295 | return 0; | ||
| 296 | } | ||
| 297 | |||
| 298 | /* currently we only support AUTH_NONE and AUTH_SYS */ | ||
| 299 | static rpc_authflavor_t | ||
| 300 | nfs4_ff_layout_choose_authflavor(struct nfs4_ff_layout_mirror *mirror) | ||
| 301 | { | ||
| 302 | if (mirror->uid == (u32)-1) | ||
| 303 | return RPC_AUTH_NULL; | ||
| 304 | return RPC_AUTH_UNIX; | ||
| 305 | } | ||
| 306 | |||
| 307 | /* fetch cred for NFSv3 DS */ | ||
| 308 | static int ff_layout_update_mirror_cred(struct nfs4_ff_layout_mirror *mirror, | ||
| 309 | struct nfs4_pnfs_ds *ds) | ||
| 310 | { | ||
| 311 | if (ds->ds_clp && !mirror->cred && | ||
| 312 | mirror->mirror_ds->ds_versions[0].version == 3) { | ||
| 313 | struct rpc_auth *auth = ds->ds_clp->cl_rpcclient->cl_auth; | ||
| 314 | struct rpc_cred *cred; | ||
| 315 | struct auth_cred acred = { | ||
| 316 | .uid = make_kuid(&init_user_ns, mirror->uid), | ||
| 317 | .gid = make_kgid(&init_user_ns, mirror->gid), | ||
| 318 | }; | ||
| 319 | |||
| 320 | /* AUTH_NULL ignores acred */ | ||
| 321 | cred = auth->au_ops->lookup_cred(auth, &acred, 0); | ||
| 322 | if (IS_ERR(cred)) { | ||
| 323 | dprintk("%s: lookup_cred failed with %ld\n", | ||
| 324 | __func__, PTR_ERR(cred)); | ||
| 325 | return PTR_ERR(cred); | ||
| 326 | } else { | ||
| 327 | mirror->cred = cred; | ||
| 328 | } | ||
| 329 | } | ||
| 330 | return 0; | ||
| 331 | } | ||
| 332 | |||
| 333 | struct nfs_fh * | ||
| 334 | nfs4_ff_layout_select_ds_fh(struct pnfs_layout_segment *lseg, u32 mirror_idx) | ||
| 335 | { | ||
| 336 | struct nfs4_ff_layout_mirror *mirror = FF_LAYOUT_COMP(lseg, mirror_idx); | ||
| 337 | struct nfs_fh *fh = NULL; | ||
| 338 | struct nfs4_deviceid_node *devid; | ||
| 339 | |||
| 340 | if (mirror == NULL || mirror->mirror_ds == NULL || | ||
| 341 | mirror->mirror_ds->ds == NULL) { | ||
| 342 | printk(KERN_ERR "NFS: %s: No data server for mirror offset index %d\n", | ||
| 343 | __func__, mirror_idx); | ||
| 344 | if (mirror && mirror->mirror_ds) { | ||
| 345 | devid = &mirror->mirror_ds->id_node; | ||
| 346 | pnfs_generic_mark_devid_invalid(devid); | ||
| 347 | } | ||
| 348 | goto out; | ||
| 349 | } | ||
| 350 | |||
| 351 | /* FIXME: For now assume there is only 1 version available for the DS */ | ||
| 352 | fh = &mirror->fh_versions[0]; | ||
| 353 | out: | ||
| 354 | return fh; | ||
| 355 | } | ||
| 356 | |||
| 357 | /* Upon return, either ds is connected, or ds is NULL */ | ||
| 358 | struct nfs4_pnfs_ds * | ||
| 359 | nfs4_ff_layout_prepare_ds(struct pnfs_layout_segment *lseg, u32 ds_idx, | ||
| 360 | bool fail_return) | ||
| 361 | { | ||
| 362 | struct nfs4_ff_layout_mirror *mirror = FF_LAYOUT_COMP(lseg, ds_idx); | ||
| 363 | struct nfs4_pnfs_ds *ds = NULL; | ||
| 364 | struct nfs4_deviceid_node *devid; | ||
| 365 | struct inode *ino = lseg->pls_layout->plh_inode; | ||
| 366 | struct nfs_server *s = NFS_SERVER(ino); | ||
| 367 | unsigned int max_payload; | ||
| 368 | rpc_authflavor_t flavor; | ||
| 369 | |||
| 370 | if (mirror == NULL || mirror->mirror_ds == NULL || | ||
| 371 | mirror->mirror_ds->ds == NULL) { | ||
| 372 | printk(KERN_ERR "NFS: %s: No data server for offset index %d\n", | ||
| 373 | __func__, ds_idx); | ||
| 374 | if (mirror && mirror->mirror_ds) { | ||
| 375 | devid = &mirror->mirror_ds->id_node; | ||
| 376 | pnfs_generic_mark_devid_invalid(devid); | ||
| 377 | } | ||
| 378 | goto out; | ||
| 379 | } | ||
| 380 | |||
| 381 | devid = &mirror->mirror_ds->id_node; | ||
| 382 | if (ff_layout_test_devid_unavailable(devid)) | ||
| 383 | goto out; | ||
| 384 | |||
| 385 | ds = mirror->mirror_ds->ds; | ||
| 386 | /* matching smp_wmb() in _nfs4_pnfs_v3/4_ds_connect */ | ||
| 387 | smp_rmb(); | ||
| 388 | if (ds->ds_clp) | ||
| 389 | goto out; | ||
| 390 | |||
| 391 | flavor = nfs4_ff_layout_choose_authflavor(mirror); | ||
| 392 | |||
| 393 | /* FIXME: For now we assume the server sent only one version of NFS | ||
| 394 | * to use for the DS. | ||
| 395 | */ | ||
| 396 | nfs4_pnfs_ds_connect(s, ds, devid, dataserver_timeo, | ||
| 397 | dataserver_retrans, | ||
| 398 | mirror->mirror_ds->ds_versions[0].version, | ||
| 399 | mirror->mirror_ds->ds_versions[0].minor_version, | ||
| 400 | flavor); | ||
| 401 | |||
| 402 | /* connect success, check rsize/wsize limit */ | ||
| 403 | if (ds->ds_clp) { | ||
| 404 | max_payload = | ||
| 405 | nfs_block_size(rpc_max_payload(ds->ds_clp->cl_rpcclient), | ||
| 406 | NULL); | ||
| 407 | if (mirror->mirror_ds->ds_versions[0].rsize > max_payload) | ||
| 408 | mirror->mirror_ds->ds_versions[0].rsize = max_payload; | ||
| 409 | if (mirror->mirror_ds->ds_versions[0].wsize > max_payload) | ||
| 410 | mirror->mirror_ds->ds_versions[0].wsize = max_payload; | ||
| 411 | } else { | ||
| 412 | ff_layout_track_ds_error(FF_LAYOUT_FROM_HDR(lseg->pls_layout), | ||
| 413 | mirror, lseg->pls_range.offset, | ||
| 414 | lseg->pls_range.length, NFS4ERR_NXIO, | ||
| 415 | OP_ILLEGAL, GFP_NOIO); | ||
| 416 | if (fail_return) { | ||
| 417 | pnfs_error_mark_layout_for_return(ino, lseg); | ||
| 418 | if (ff_layout_has_available_ds(lseg)) | ||
| 419 | pnfs_set_retry_layoutget(lseg->pls_layout); | ||
| 420 | else | ||
| 421 | pnfs_clear_retry_layoutget(lseg->pls_layout); | ||
| 422 | |||
| 423 | } else { | ||
| 424 | if (ff_layout_has_available_ds(lseg)) | ||
| 425 | set_bit(NFS_LAYOUT_RETURN_BEFORE_CLOSE, | ||
| 426 | &lseg->pls_layout->plh_flags); | ||
| 427 | else { | ||
| 428 | pnfs_error_mark_layout_for_return(ino, lseg); | ||
| 429 | pnfs_clear_retry_layoutget(lseg->pls_layout); | ||
| 430 | } | ||
| 431 | } | ||
| 432 | } | ||
| 433 | |||
| 434 | if (ff_layout_update_mirror_cred(mirror, ds)) | ||
| 435 | ds = NULL; | ||
| 436 | out: | ||
| 437 | return ds; | ||
| 438 | } | ||
| 439 | |||
| 440 | struct rpc_cred * | ||
| 441 | ff_layout_get_ds_cred(struct pnfs_layout_segment *lseg, u32 ds_idx, | ||
| 442 | struct rpc_cred *mdscred) | ||
| 443 | { | ||
| 444 | struct nfs4_ff_layout_mirror *mirror = FF_LAYOUT_COMP(lseg, ds_idx); | ||
| 445 | struct rpc_cred *cred = ERR_PTR(-EINVAL); | ||
| 446 | |||
| 447 | if (!nfs4_ff_layout_prepare_ds(lseg, ds_idx, true)) | ||
| 448 | goto out; | ||
| 449 | |||
| 450 | if (mirror && mirror->cred) | ||
| 451 | cred = mirror->cred; | ||
| 452 | else | ||
| 453 | cred = mdscred; | ||
| 454 | out: | ||
| 455 | return cred; | ||
| 456 | } | ||
| 457 | |||
| 458 | /** | ||
| 459 | * Find or create a DS rpc client with th MDS server rpc client auth flavor | ||
| 460 | * in the nfs_client cl_ds_clients list. | ||
| 461 | */ | ||
| 462 | struct rpc_clnt * | ||
| 463 | nfs4_ff_find_or_create_ds_client(struct pnfs_layout_segment *lseg, u32 ds_idx, | ||
| 464 | struct nfs_client *ds_clp, struct inode *inode) | ||
| 465 | { | ||
| 466 | struct nfs4_ff_layout_mirror *mirror = FF_LAYOUT_COMP(lseg, ds_idx); | ||
| 467 | |||
| 468 | switch (mirror->mirror_ds->ds_versions[0].version) { | ||
| 469 | case 3: | ||
| 470 | /* For NFSv3 DS, flavor is set when creating DS connections */ | ||
| 471 | return ds_clp->cl_rpcclient; | ||
| 472 | case 4: | ||
| 473 | return nfs4_find_or_create_ds_client(ds_clp, inode); | ||
| 474 | default: | ||
| 475 | BUG(); | ||
| 476 | } | ||
| 477 | } | ||
| 478 | |||
| 479 | static bool is_range_intersecting(u64 offset1, u64 length1, | ||
| 480 | u64 offset2, u64 length2) | ||
| 481 | { | ||
| 482 | u64 end1 = end_offset(offset1, length1); | ||
| 483 | u64 end2 = end_offset(offset2, length2); | ||
| 484 | |||
| 485 | return (end1 == NFS4_MAX_UINT64 || end1 > offset2) && | ||
| 486 | (end2 == NFS4_MAX_UINT64 || end2 > offset1); | ||
| 487 | } | ||
| 488 | |||
| 489 | /* called with inode i_lock held */ | ||
| 490 | int ff_layout_encode_ds_ioerr(struct nfs4_flexfile_layout *flo, | ||
| 491 | struct xdr_stream *xdr, int *count, | ||
| 492 | const struct pnfs_layout_range *range) | ||
| 493 | { | ||
| 494 | struct nfs4_ff_layout_ds_err *err, *n; | ||
| 495 | __be32 *p; | ||
| 496 | |||
| 497 | list_for_each_entry_safe(err, n, &flo->error_list, list) { | ||
| 498 | if (!is_range_intersecting(err->offset, err->length, | ||
| 499 | range->offset, range->length)) | ||
| 500 | continue; | ||
| 501 | /* offset(8) + length(8) + stateid(NFS4_STATEID_SIZE) | ||
| 502 | * + deviceid(NFS4_DEVICEID4_SIZE) + status(4) + opnum(4) | ||
| 503 | */ | ||
| 504 | p = xdr_reserve_space(xdr, | ||
| 505 | 24 + NFS4_STATEID_SIZE + NFS4_DEVICEID4_SIZE); | ||
| 506 | if (unlikely(!p)) | ||
| 507 | return -ENOBUFS; | ||
| 508 | p = xdr_encode_hyper(p, err->offset); | ||
| 509 | p = xdr_encode_hyper(p, err->length); | ||
| 510 | p = xdr_encode_opaque_fixed(p, &err->stateid, | ||
| 511 | NFS4_STATEID_SIZE); | ||
| 512 | p = xdr_encode_opaque_fixed(p, &err->deviceid, | ||
| 513 | NFS4_DEVICEID4_SIZE); | ||
| 514 | *p++ = cpu_to_be32(err->status); | ||
| 515 | *p++ = cpu_to_be32(err->opnum); | ||
| 516 | *count += 1; | ||
| 517 | list_del(&err->list); | ||
| 518 | kfree(err); | ||
| 519 | dprintk("%s: offset %llu length %llu status %d op %d count %d\n", | ||
| 520 | __func__, err->offset, err->length, err->status, | ||
| 521 | err->opnum, *count); | ||
| 522 | } | ||
| 523 | |||
| 524 | return 0; | ||
| 525 | } | ||
| 526 | |||
| 527 | bool ff_layout_has_available_ds(struct pnfs_layout_segment *lseg) | ||
| 528 | { | ||
| 529 | struct nfs4_ff_layout_mirror *mirror; | ||
| 530 | struct nfs4_deviceid_node *devid; | ||
| 531 | int idx; | ||
| 532 | |||
| 533 | for (idx = 0; idx < FF_LAYOUT_MIRROR_COUNT(lseg); idx++) { | ||
| 534 | mirror = FF_LAYOUT_COMP(lseg, idx); | ||
| 535 | if (mirror && mirror->mirror_ds) { | ||
| 536 | devid = &mirror->mirror_ds->id_node; | ||
| 537 | if (!ff_layout_test_devid_unavailable(devid)) | ||
| 538 | return true; | ||
| 539 | } | ||
| 540 | } | ||
| 541 | |||
| 542 | return false; | ||
| 543 | } | ||
| 544 | |||
| 545 | module_param(dataserver_retrans, uint, 0644); | ||
| 546 | MODULE_PARM_DESC(dataserver_retrans, "The number of times the NFSv4.1 client " | ||
| 547 | "retries a request before it attempts further " | ||
| 548 | " recovery action."); | ||
| 549 | module_param(dataserver_timeo, uint, 0644); | ||
| 550 | MODULE_PARM_DESC(dataserver_timeo, "The time (in tenths of a second) the " | ||
| 551 | "NFSv4.1 client waits for a response from a " | ||
| 552 | " data server before it retries an NFS request."); | ||
diff --git a/fs/nfs/idmap.c b/fs/nfs/idmap.c index 2f5db844c172..857e2a99acc8 100644 --- a/fs/nfs/idmap.c +++ b/fs/nfs/idmap.c | |||
| @@ -152,7 +152,7 @@ void nfs_fattr_map_and_free_names(struct nfs_server *server, struct nfs_fattr *f | |||
| 152 | nfs_fattr_free_group_name(fattr); | 152 | nfs_fattr_free_group_name(fattr); |
| 153 | } | 153 | } |
| 154 | 154 | ||
| 155 | static int nfs_map_string_to_numeric(const char *name, size_t namelen, __u32 *res) | 155 | int nfs_map_string_to_numeric(const char *name, size_t namelen, __u32 *res) |
| 156 | { | 156 | { |
| 157 | unsigned long val; | 157 | unsigned long val; |
| 158 | char buf[16]; | 158 | char buf[16]; |
| @@ -166,6 +166,7 @@ static int nfs_map_string_to_numeric(const char *name, size_t namelen, __u32 *re | |||
| 166 | *res = val; | 166 | *res = val; |
| 167 | return 1; | 167 | return 1; |
| 168 | } | 168 | } |
| 169 | EXPORT_SYMBOL_GPL(nfs_map_string_to_numeric); | ||
| 169 | 170 | ||
| 170 | static int nfs_map_numeric_to_string(__u32 id, char *buf, size_t buflen) | 171 | static int nfs_map_numeric_to_string(__u32 id, char *buf, size_t buflen) |
| 171 | { | 172 | { |
diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h index b6f34bfa6fe8..a98cf2006179 100644 --- a/fs/nfs/internal.h +++ b/fs/nfs/internal.h | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | #include <linux/mount.h> | 6 | #include <linux/mount.h> |
| 7 | #include <linux/security.h> | 7 | #include <linux/security.h> |
| 8 | #include <linux/crc32.h> | 8 | #include <linux/crc32.h> |
| 9 | #include <linux/nfs_page.h> | ||
| 9 | 10 | ||
| 10 | #define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS) | 11 | #define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS) |
| 11 | 12 | ||
| @@ -187,9 +188,15 @@ extern struct nfs_client *nfs4_set_ds_client(struct nfs_client* mds_clp, | |||
| 187 | const struct sockaddr *ds_addr, | 188 | const struct sockaddr *ds_addr, |
| 188 | int ds_addrlen, int ds_proto, | 189 | int ds_addrlen, int ds_proto, |
| 189 | unsigned int ds_timeo, | 190 | unsigned int ds_timeo, |
| 190 | unsigned int ds_retrans); | 191 | unsigned int ds_retrans, |
| 192 | u32 minor_version, | ||
| 193 | rpc_authflavor_t au_flavor); | ||
| 191 | extern struct rpc_clnt *nfs4_find_or_create_ds_client(struct nfs_client *, | 194 | extern struct rpc_clnt *nfs4_find_or_create_ds_client(struct nfs_client *, |
| 192 | struct inode *); | 195 | struct inode *); |
| 196 | extern struct nfs_client *nfs3_set_ds_client(struct nfs_client *mds_clp, | ||
| 197 | const struct sockaddr *ds_addr, int ds_addrlen, | ||
| 198 | int ds_proto, unsigned int ds_timeo, | ||
| 199 | unsigned int ds_retrans, rpc_authflavor_t au_flavor); | ||
| 193 | #ifdef CONFIG_PROC_FS | 200 | #ifdef CONFIG_PROC_FS |
| 194 | extern int __init nfs_fs_proc_init(void); | 201 | extern int __init nfs_fs_proc_init(void); |
| 195 | extern void nfs_fs_proc_exit(void); | 202 | extern void nfs_fs_proc_exit(void); |
| @@ -242,9 +249,12 @@ struct nfs_pgio_header *nfs_pgio_header_alloc(const struct nfs_rw_ops *); | |||
| 242 | void nfs_pgio_header_free(struct nfs_pgio_header *); | 249 | void nfs_pgio_header_free(struct nfs_pgio_header *); |
| 243 | void nfs_pgio_data_destroy(struct nfs_pgio_header *); | 250 | void nfs_pgio_data_destroy(struct nfs_pgio_header *); |
| 244 | int nfs_generic_pgio(struct nfs_pageio_descriptor *, struct nfs_pgio_header *); | 251 | int nfs_generic_pgio(struct nfs_pageio_descriptor *, struct nfs_pgio_header *); |
| 245 | int nfs_initiate_pgio(struct rpc_clnt *, struct nfs_pgio_header *, | 252 | int nfs_initiate_pgio(struct rpc_clnt *clnt, struct nfs_pgio_header *hdr, |
| 246 | const struct rpc_call_ops *, int, int); | 253 | struct rpc_cred *cred, const struct nfs_rpc_ops *rpc_ops, |
| 254 | const struct rpc_call_ops *call_ops, int how, int flags); | ||
| 247 | void nfs_free_request(struct nfs_page *req); | 255 | void nfs_free_request(struct nfs_page *req); |
| 256 | struct nfs_pgio_mirror * | ||
| 257 | nfs_pgio_current_mirror(struct nfs_pageio_descriptor *desc); | ||
| 248 | 258 | ||
| 249 | static inline void nfs_iocounter_init(struct nfs_io_counter *c) | 259 | static inline void nfs_iocounter_init(struct nfs_io_counter *c) |
| 250 | { | 260 | { |
| @@ -252,6 +262,12 @@ static inline void nfs_iocounter_init(struct nfs_io_counter *c) | |||
| 252 | atomic_set(&c->io_count, 0); | 262 | atomic_set(&c->io_count, 0); |
| 253 | } | 263 | } |
| 254 | 264 | ||
| 265 | static inline bool nfs_pgio_has_mirroring(struct nfs_pageio_descriptor *desc) | ||
| 266 | { | ||
| 267 | WARN_ON_ONCE(desc->pg_mirror_count < 1); | ||
| 268 | return desc->pg_mirror_count > 1; | ||
| 269 | } | ||
| 270 | |||
| 255 | /* nfs2xdr.c */ | 271 | /* nfs2xdr.c */ |
| 256 | extern struct rpc_procinfo nfs_procedures[]; | 272 | extern struct rpc_procinfo nfs_procedures[]; |
| 257 | extern int nfs2_decode_dirent(struct xdr_stream *, | 273 | extern int nfs2_decode_dirent(struct xdr_stream *, |
| @@ -427,6 +443,7 @@ extern void nfs_write_prepare(struct rpc_task *task, void *calldata); | |||
| 427 | extern void nfs_commit_prepare(struct rpc_task *task, void *calldata); | 443 | extern void nfs_commit_prepare(struct rpc_task *task, void *calldata); |
| 428 | extern int nfs_initiate_commit(struct rpc_clnt *clnt, | 444 | extern int nfs_initiate_commit(struct rpc_clnt *clnt, |
| 429 | struct nfs_commit_data *data, | 445 | struct nfs_commit_data *data, |
| 446 | const struct nfs_rpc_ops *nfs_ops, | ||
| 430 | const struct rpc_call_ops *call_ops, | 447 | const struct rpc_call_ops *call_ops, |
| 431 | int how, int flags); | 448 | int how, int flags); |
| 432 | extern void nfs_init_commit(struct nfs_commit_data *data, | 449 | extern void nfs_init_commit(struct nfs_commit_data *data, |
| @@ -440,13 +457,15 @@ int nfs_scan_commit(struct inode *inode, struct list_head *dst, | |||
| 440 | struct nfs_commit_info *cinfo); | 457 | struct nfs_commit_info *cinfo); |
| 441 | void nfs_mark_request_commit(struct nfs_page *req, | 458 | void nfs_mark_request_commit(struct nfs_page *req, |
| 442 | struct pnfs_layout_segment *lseg, | 459 | struct pnfs_layout_segment *lseg, |
| 443 | struct nfs_commit_info *cinfo); | 460 | struct nfs_commit_info *cinfo, |
| 461 | u32 ds_commit_idx); | ||
| 444 | int nfs_write_need_commit(struct nfs_pgio_header *); | 462 | int nfs_write_need_commit(struct nfs_pgio_header *); |
| 445 | int nfs_generic_commit_list(struct inode *inode, struct list_head *head, | 463 | int nfs_generic_commit_list(struct inode *inode, struct list_head *head, |
| 446 | int how, struct nfs_commit_info *cinfo); | 464 | int how, struct nfs_commit_info *cinfo); |
| 447 | void nfs_retry_commit(struct list_head *page_list, | 465 | void nfs_retry_commit(struct list_head *page_list, |
| 448 | struct pnfs_layout_segment *lseg, | 466 | struct pnfs_layout_segment *lseg, |
| 449 | struct nfs_commit_info *cinfo); | 467 | struct nfs_commit_info *cinfo, |
| 468 | u32 ds_commit_idx); | ||
| 450 | void nfs_commitdata_release(struct nfs_commit_data *data); | 469 | void nfs_commitdata_release(struct nfs_commit_data *data); |
| 451 | void nfs_request_add_commit_list(struct nfs_page *req, struct list_head *dst, | 470 | void nfs_request_add_commit_list(struct nfs_page *req, struct list_head *dst, |
| 452 | struct nfs_commit_info *cinfo); | 471 | struct nfs_commit_info *cinfo); |
| @@ -457,6 +476,7 @@ void nfs_init_cinfo(struct nfs_commit_info *cinfo, | |||
| 457 | struct nfs_direct_req *dreq); | 476 | struct nfs_direct_req *dreq); |
| 458 | int nfs_key_timeout_notify(struct file *filp, struct inode *inode); | 477 | int nfs_key_timeout_notify(struct file *filp, struct inode *inode); |
| 459 | bool nfs_ctx_key_to_expire(struct nfs_open_context *ctx); | 478 | bool nfs_ctx_key_to_expire(struct nfs_open_context *ctx); |
| 479 | void nfs_pageio_stop_mirroring(struct nfs_pageio_descriptor *pgio); | ||
| 460 | 480 | ||
| 461 | #ifdef CONFIG_MIGRATION | 481 | #ifdef CONFIG_MIGRATION |
| 462 | extern int nfs_migrate_page(struct address_space *, | 482 | extern int nfs_migrate_page(struct address_space *, |
| @@ -480,6 +500,7 @@ static inline void nfs_inode_dio_wait(struct inode *inode) | |||
| 480 | inode_dio_wait(inode); | 500 | inode_dio_wait(inode); |
| 481 | } | 501 | } |
| 482 | extern ssize_t nfs_dreq_bytes_left(struct nfs_direct_req *dreq); | 502 | extern ssize_t nfs_dreq_bytes_left(struct nfs_direct_req *dreq); |
| 503 | extern void nfs_direct_set_resched_writes(struct nfs_direct_req *dreq); | ||
| 483 | 504 | ||
| 484 | /* nfs4proc.c */ | 505 | /* nfs4proc.c */ |
| 485 | extern void __nfs4_read_done_cb(struct nfs_pgio_header *); | 506 | extern void __nfs4_read_done_cb(struct nfs_pgio_header *); |
diff --git a/fs/nfs/nfs2xdr.c b/fs/nfs/nfs2xdr.c index 5f61b83f4a1c..b4e03ed8599d 100644 --- a/fs/nfs/nfs2xdr.c +++ b/fs/nfs/nfs2xdr.c | |||
| @@ -481,7 +481,8 @@ out_overflow: | |||
| 481 | * void; | 481 | * void; |
| 482 | * }; | 482 | * }; |
| 483 | */ | 483 | */ |
| 484 | static int decode_attrstat(struct xdr_stream *xdr, struct nfs_fattr *result) | 484 | static int decode_attrstat(struct xdr_stream *xdr, struct nfs_fattr *result, |
| 485 | __u32 *op_status) | ||
| 485 | { | 486 | { |
| 486 | enum nfs_stat status; | 487 | enum nfs_stat status; |
| 487 | int error; | 488 | int error; |
| @@ -489,6 +490,8 @@ static int decode_attrstat(struct xdr_stream *xdr, struct nfs_fattr *result) | |||
| 489 | error = decode_stat(xdr, &status); | 490 | error = decode_stat(xdr, &status); |
| 490 | if (unlikely(error)) | 491 | if (unlikely(error)) |
| 491 | goto out; | 492 | goto out; |
| 493 | if (op_status) | ||
| 494 | *op_status = status; | ||
| 492 | if (status != NFS_OK) | 495 | if (status != NFS_OK) |
| 493 | goto out_default; | 496 | goto out_default; |
| 494 | error = decode_fattr(xdr, result); | 497 | error = decode_fattr(xdr, result); |
| @@ -808,7 +811,7 @@ out_default: | |||
| 808 | static int nfs2_xdr_dec_attrstat(struct rpc_rqst *req, struct xdr_stream *xdr, | 811 | static int nfs2_xdr_dec_attrstat(struct rpc_rqst *req, struct xdr_stream *xdr, |
| 809 | struct nfs_fattr *result) | 812 | struct nfs_fattr *result) |
| 810 | { | 813 | { |
| 811 | return decode_attrstat(xdr, result); | 814 | return decode_attrstat(xdr, result, NULL); |
| 812 | } | 815 | } |
| 813 | 816 | ||
| 814 | static int nfs2_xdr_dec_diropres(struct rpc_rqst *req, struct xdr_stream *xdr, | 817 | static int nfs2_xdr_dec_diropres(struct rpc_rqst *req, struct xdr_stream *xdr, |
| @@ -865,6 +868,7 @@ static int nfs2_xdr_dec_readres(struct rpc_rqst *req, struct xdr_stream *xdr, | |||
| 865 | error = decode_stat(xdr, &status); | 868 | error = decode_stat(xdr, &status); |
| 866 | if (unlikely(error)) | 869 | if (unlikely(error)) |
| 867 | goto out; | 870 | goto out; |
| 871 | result->op_status = status; | ||
| 868 | if (status != NFS_OK) | 872 | if (status != NFS_OK) |
| 869 | goto out_default; | 873 | goto out_default; |
| 870 | error = decode_fattr(xdr, result->fattr); | 874 | error = decode_fattr(xdr, result->fattr); |
| @@ -882,7 +886,7 @@ static int nfs2_xdr_dec_writeres(struct rpc_rqst *req, struct xdr_stream *xdr, | |||
| 882 | { | 886 | { |
| 883 | /* All NFSv2 writes are "file sync" writes */ | 887 | /* All NFSv2 writes are "file sync" writes */ |
| 884 | result->verf->committed = NFS_FILE_SYNC; | 888 | result->verf->committed = NFS_FILE_SYNC; |
| 885 | return decode_attrstat(xdr, result->fattr); | 889 | return decode_attrstat(xdr, result->fattr, &result->op_status); |
| 886 | } | 890 | } |
| 887 | 891 | ||
| 888 | /** | 892 | /** |
diff --git a/fs/nfs/nfs3_fs.h b/fs/nfs/nfs3_fs.h index 333ae4068506..e134d6548ab7 100644 --- a/fs/nfs/nfs3_fs.h +++ b/fs/nfs/nfs3_fs.h | |||
| @@ -30,5 +30,7 @@ struct nfs_server *nfs3_create_server(struct nfs_mount_info *, struct nfs_subver | |||
| 30 | struct nfs_server *nfs3_clone_server(struct nfs_server *, struct nfs_fh *, | 30 | struct nfs_server *nfs3_clone_server(struct nfs_server *, struct nfs_fh *, |
| 31 | struct nfs_fattr *, rpc_authflavor_t); | 31 | struct nfs_fattr *, rpc_authflavor_t); |
| 32 | 32 | ||
| 33 | /* nfs3super.c */ | ||
| 34 | extern struct nfs_subversion nfs_v3; | ||
| 33 | 35 | ||
| 34 | #endif /* __LINUX_FS_NFS_NFS3_FS_H */ | 36 | #endif /* __LINUX_FS_NFS_NFS3_FS_H */ |
diff --git a/fs/nfs/nfs3client.c b/fs/nfs/nfs3client.c index 8c1b437c5403..9e9fa347a948 100644 --- a/fs/nfs/nfs3client.c +++ b/fs/nfs/nfs3client.c | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | #include <linux/nfs_fs.h> | 1 | #include <linux/nfs_fs.h> |
| 2 | #include <linux/nfs_mount.h> | 2 | #include <linux/nfs_mount.h> |
| 3 | #include <linux/sunrpc/addr.h> | ||
| 3 | #include "internal.h" | 4 | #include "internal.h" |
| 4 | #include "nfs3_fs.h" | 5 | #include "nfs3_fs.h" |
| 5 | 6 | ||
| @@ -64,3 +65,43 @@ struct nfs_server *nfs3_clone_server(struct nfs_server *source, | |||
| 64 | nfs_init_server_aclclient(server); | 65 | nfs_init_server_aclclient(server); |
| 65 | return server; | 66 | return server; |
| 66 | } | 67 | } |
| 68 | |||
| 69 | /* | ||
| 70 | * Set up a pNFS Data Server client over NFSv3. | ||
| 71 | * | ||
| 72 | * Return any existing nfs_client that matches server address,port,version | ||
| 73 | * and minorversion. | ||
| 74 | * | ||
| 75 | * For a new nfs_client, use a soft mount (default), a low retrans and a | ||
| 76 | * low timeout interval so that if a connection is lost, we retry through | ||
| 77 | * the MDS. | ||
| 78 | */ | ||
| 79 | struct nfs_client *nfs3_set_ds_client(struct nfs_client *mds_clp, | ||
| 80 | const struct sockaddr *ds_addr, int ds_addrlen, | ||
| 81 | int ds_proto, unsigned int ds_timeo, unsigned int ds_retrans, | ||
| 82 | rpc_authflavor_t au_flavor) | ||
| 83 | { | ||
| 84 | struct nfs_client_initdata cl_init = { | ||
| 85 | .addr = ds_addr, | ||
| 86 | .addrlen = ds_addrlen, | ||
| 87 | .nfs_mod = &nfs_v3, | ||
| 88 | .proto = ds_proto, | ||
| 89 | .net = mds_clp->cl_net, | ||
| 90 | }; | ||
| 91 | struct rpc_timeout ds_timeout; | ||
| 92 | struct nfs_client *clp; | ||
| 93 | char buf[INET6_ADDRSTRLEN + 1]; | ||
| 94 | |||
| 95 | /* fake a hostname because lockd wants it */ | ||
| 96 | if (rpc_ntop(ds_addr, buf, sizeof(buf)) <= 0) | ||
| 97 | return ERR_PTR(-EINVAL); | ||
| 98 | cl_init.hostname = buf; | ||
| 99 | |||
| 100 | /* Use the MDS nfs_client cl_ipaddr. */ | ||
| 101 | nfs_init_timeout_values(&ds_timeout, ds_proto, ds_timeo, ds_retrans); | ||
| 102 | clp = nfs_get_client(&cl_init, &ds_timeout, mds_clp->cl_ipaddr, | ||
| 103 | au_flavor); | ||
| 104 | |||
| 105 | return clp; | ||
| 106 | } | ||
| 107 | EXPORT_SYMBOL_GPL(nfs3_set_ds_client); | ||
diff --git a/fs/nfs/nfs3proc.c b/fs/nfs/nfs3proc.c index 524f9f837408..78e557c3ab87 100644 --- a/fs/nfs/nfs3proc.c +++ b/fs/nfs/nfs3proc.c | |||
| @@ -800,6 +800,9 @@ static int nfs3_read_done(struct rpc_task *task, struct nfs_pgio_header *hdr) | |||
| 800 | { | 800 | { |
| 801 | struct inode *inode = hdr->inode; | 801 | struct inode *inode = hdr->inode; |
| 802 | 802 | ||
| 803 | if (hdr->pgio_done_cb != NULL) | ||
| 804 | return hdr->pgio_done_cb(task, hdr); | ||
| 805 | |||
| 803 | if (nfs3_async_handle_jukebox(task, inode)) | 806 | if (nfs3_async_handle_jukebox(task, inode)) |
| 804 | return -EAGAIN; | 807 | return -EAGAIN; |
| 805 | 808 | ||
| @@ -825,6 +828,9 @@ static int nfs3_write_done(struct rpc_task *task, struct nfs_pgio_header *hdr) | |||
| 825 | { | 828 | { |
| 826 | struct inode *inode = hdr->inode; | 829 | struct inode *inode = hdr->inode; |
| 827 | 830 | ||
| 831 | if (hdr->pgio_done_cb != NULL) | ||
| 832 | return hdr->pgio_done_cb(task, hdr); | ||
| 833 | |||
| 828 | if (nfs3_async_handle_jukebox(task, inode)) | 834 | if (nfs3_async_handle_jukebox(task, inode)) |
| 829 | return -EAGAIN; | 835 | return -EAGAIN; |
| 830 | if (task->tk_status >= 0) | 836 | if (task->tk_status >= 0) |
| @@ -845,6 +851,9 @@ static void nfs3_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commi | |||
| 845 | 851 | ||
| 846 | static int nfs3_commit_done(struct rpc_task *task, struct nfs_commit_data *data) | 852 | static int nfs3_commit_done(struct rpc_task *task, struct nfs_commit_data *data) |
| 847 | { | 853 | { |
| 854 | if (data->commit_done_cb != NULL) | ||
| 855 | return data->commit_done_cb(task, data); | ||
| 856 | |||
| 848 | if (nfs3_async_handle_jukebox(task, data->inode)) | 857 | if (nfs3_async_handle_jukebox(task, data->inode)) |
| 849 | return -EAGAIN; | 858 | return -EAGAIN; |
| 850 | nfs_refresh_inode(data->inode, data->res.fattr); | 859 | nfs_refresh_inode(data->inode, data->res.fattr); |
diff --git a/fs/nfs/nfs3super.c b/fs/nfs/nfs3super.c index 6af29c2da352..5c4394e4656b 100644 --- a/fs/nfs/nfs3super.c +++ b/fs/nfs/nfs3super.c | |||
| @@ -7,7 +7,7 @@ | |||
| 7 | #include "nfs3_fs.h" | 7 | #include "nfs3_fs.h" |
| 8 | #include "nfs.h" | 8 | #include "nfs.h" |
| 9 | 9 | ||
| 10 | static struct nfs_subversion nfs_v3 = { | 10 | struct nfs_subversion nfs_v3 = { |
| 11 | .owner = THIS_MODULE, | 11 | .owner = THIS_MODULE, |
| 12 | .nfs_fs = &nfs_fs_type, | 12 | .nfs_fs = &nfs_fs_type, |
| 13 | .rpc_vers = &nfs_version3, | 13 | .rpc_vers = &nfs_version3, |
diff --git a/fs/nfs/nfs3xdr.c b/fs/nfs/nfs3xdr.c index 8f4cbe7f4aa8..2a932fdc57cb 100644 --- a/fs/nfs/nfs3xdr.c +++ b/fs/nfs/nfs3xdr.c | |||
| @@ -1636,6 +1636,7 @@ static int nfs3_xdr_dec_read3res(struct rpc_rqst *req, struct xdr_stream *xdr, | |||
| 1636 | error = decode_post_op_attr(xdr, result->fattr); | 1636 | error = decode_post_op_attr(xdr, result->fattr); |
| 1637 | if (unlikely(error)) | 1637 | if (unlikely(error)) |
| 1638 | goto out; | 1638 | goto out; |
| 1639 | result->op_status = status; | ||
| 1639 | if (status != NFS3_OK) | 1640 | if (status != NFS3_OK) |
| 1640 | goto out_status; | 1641 | goto out_status; |
| 1641 | error = decode_read3resok(xdr, result); | 1642 | error = decode_read3resok(xdr, result); |
| @@ -1708,6 +1709,7 @@ static int nfs3_xdr_dec_write3res(struct rpc_rqst *req, struct xdr_stream *xdr, | |||
| 1708 | error = decode_wcc_data(xdr, result->fattr); | 1709 | error = decode_wcc_data(xdr, result->fattr); |
| 1709 | if (unlikely(error)) | 1710 | if (unlikely(error)) |
| 1710 | goto out; | 1711 | goto out; |
| 1712 | result->op_status = status; | ||
| 1711 | if (status != NFS3_OK) | 1713 | if (status != NFS3_OK) |
| 1712 | goto out_status; | 1714 | goto out_status; |
| 1713 | error = decode_write3resok(xdr, result); | 1715 | error = decode_write3resok(xdr, result); |
| @@ -2323,6 +2325,7 @@ static int nfs3_xdr_dec_commit3res(struct rpc_rqst *req, | |||
| 2323 | error = decode_wcc_data(xdr, result->fattr); | 2325 | error = decode_wcc_data(xdr, result->fattr); |
| 2324 | if (unlikely(error)) | 2326 | if (unlikely(error)) |
| 2325 | goto out; | 2327 | goto out; |
| 2328 | result->op_status = status; | ||
| 2326 | if (status != NFS3_OK) | 2329 | if (status != NFS3_OK) |
| 2327 | goto out_status; | 2330 | goto out_status; |
| 2328 | error = decode_writeverf3(xdr, &result->verf->verifier); | 2331 | error = decode_writeverf3(xdr, &result->verf->verifier); |
diff --git a/fs/nfs/nfs4_fs.h b/fs/nfs/nfs4_fs.h index e57290a66b76..fdef424b0cd3 100644 --- a/fs/nfs/nfs4_fs.h +++ b/fs/nfs/nfs4_fs.h | |||
| @@ -446,6 +446,12 @@ extern void nfs_increment_open_seqid(int status, struct nfs_seqid *seqid); | |||
| 446 | extern void nfs_increment_lock_seqid(int status, struct nfs_seqid *seqid); | 446 | extern void nfs_increment_lock_seqid(int status, struct nfs_seqid *seqid); |
| 447 | extern void nfs_release_seqid(struct nfs_seqid *seqid); | 447 | extern void nfs_release_seqid(struct nfs_seqid *seqid); |
| 448 | extern void nfs_free_seqid(struct nfs_seqid *seqid); | 448 | extern void nfs_free_seqid(struct nfs_seqid *seqid); |
| 449 | extern int nfs40_setup_sequence(struct nfs4_slot_table *tbl, | ||
| 450 | struct nfs4_sequence_args *args, | ||
| 451 | struct nfs4_sequence_res *res, | ||
| 452 | struct rpc_task *task); | ||
| 453 | extern int nfs4_sequence_done(struct rpc_task *task, | ||
| 454 | struct nfs4_sequence_res *res); | ||
| 449 | 455 | ||
| 450 | extern void nfs4_free_lock_state(struct nfs_server *server, struct nfs4_lock_state *lsp); | 456 | extern void nfs4_free_lock_state(struct nfs_server *server, struct nfs4_lock_state *lsp); |
| 451 | 457 | ||
diff --git a/fs/nfs/nfs4client.c b/fs/nfs/nfs4client.c index 706ad10b8186..8646af9b11d2 100644 --- a/fs/nfs/nfs4client.c +++ b/fs/nfs/nfs4client.c | |||
| @@ -849,14 +849,15 @@ error: | |||
| 849 | */ | 849 | */ |
| 850 | struct nfs_client *nfs4_set_ds_client(struct nfs_client* mds_clp, | 850 | struct nfs_client *nfs4_set_ds_client(struct nfs_client* mds_clp, |
| 851 | const struct sockaddr *ds_addr, int ds_addrlen, | 851 | const struct sockaddr *ds_addr, int ds_addrlen, |
| 852 | int ds_proto, unsigned int ds_timeo, unsigned int ds_retrans) | 852 | int ds_proto, unsigned int ds_timeo, unsigned int ds_retrans, |
| 853 | u32 minor_version, rpc_authflavor_t au_flavor) | ||
| 853 | { | 854 | { |
| 854 | struct nfs_client_initdata cl_init = { | 855 | struct nfs_client_initdata cl_init = { |
| 855 | .addr = ds_addr, | 856 | .addr = ds_addr, |
| 856 | .addrlen = ds_addrlen, | 857 | .addrlen = ds_addrlen, |
| 857 | .nfs_mod = &nfs_v4, | 858 | .nfs_mod = &nfs_v4, |
| 858 | .proto = ds_proto, | 859 | .proto = ds_proto, |
| 859 | .minorversion = mds_clp->cl_minorversion, | 860 | .minorversion = minor_version, |
| 860 | .net = mds_clp->cl_net, | 861 | .net = mds_clp->cl_net, |
| 861 | }; | 862 | }; |
| 862 | struct rpc_timeout ds_timeout; | 863 | struct rpc_timeout ds_timeout; |
| @@ -874,7 +875,7 @@ struct nfs_client *nfs4_set_ds_client(struct nfs_client* mds_clp, | |||
| 874 | */ | 875 | */ |
| 875 | nfs_init_timeout_values(&ds_timeout, ds_proto, ds_timeo, ds_retrans); | 876 | nfs_init_timeout_values(&ds_timeout, ds_proto, ds_timeo, ds_retrans); |
| 876 | clp = nfs_get_client(&cl_init, &ds_timeout, mds_clp->cl_ipaddr, | 877 | clp = nfs_get_client(&cl_init, &ds_timeout, mds_clp->cl_ipaddr, |
| 877 | mds_clp->cl_rpcclient->cl_auth->au_flavor); | 878 | au_flavor); |
| 878 | 879 | ||
| 879 | dprintk("<-- %s %p\n", __func__, clp); | 880 | dprintk("<-- %s %p\n", __func__, clp); |
| 880 | return clp; | 881 | return clp; |
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index 0f75b9276726..6e1c9b2d92c5 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c | |||
| @@ -495,12 +495,11 @@ static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args) | |||
| 495 | args->sa_privileged = 1; | 495 | args->sa_privileged = 1; |
| 496 | } | 496 | } |
| 497 | 497 | ||
| 498 | static int nfs40_setup_sequence(const struct nfs_server *server, | 498 | int nfs40_setup_sequence(struct nfs4_slot_table *tbl, |
| 499 | struct nfs4_sequence_args *args, | 499 | struct nfs4_sequence_args *args, |
| 500 | struct nfs4_sequence_res *res, | 500 | struct nfs4_sequence_res *res, |
| 501 | struct rpc_task *task) | 501 | struct rpc_task *task) |
| 502 | { | 502 | { |
| 503 | struct nfs4_slot_table *tbl = server->nfs_client->cl_slot_tbl; | ||
| 504 | struct nfs4_slot *slot; | 503 | struct nfs4_slot *slot; |
| 505 | 504 | ||
| 506 | /* slot already allocated? */ | 505 | /* slot already allocated? */ |
| @@ -535,6 +534,7 @@ out_sleep: | |||
| 535 | spin_unlock(&tbl->slot_tbl_lock); | 534 | spin_unlock(&tbl->slot_tbl_lock); |
| 536 | return -EAGAIN; | 535 | return -EAGAIN; |
| 537 | } | 536 | } |
| 537 | EXPORT_SYMBOL_GPL(nfs40_setup_sequence); | ||
| 538 | 538 | ||
| 539 | static int nfs40_sequence_done(struct rpc_task *task, | 539 | static int nfs40_sequence_done(struct rpc_task *task, |
| 540 | struct nfs4_sequence_res *res) | 540 | struct nfs4_sequence_res *res) |
| @@ -694,8 +694,7 @@ out_retry: | |||
| 694 | } | 694 | } |
| 695 | EXPORT_SYMBOL_GPL(nfs41_sequence_done); | 695 | EXPORT_SYMBOL_GPL(nfs41_sequence_done); |
| 696 | 696 | ||
| 697 | static int nfs4_sequence_done(struct rpc_task *task, | 697 | int nfs4_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res) |
| 698 | struct nfs4_sequence_res *res) | ||
| 699 | { | 698 | { |
| 700 | if (res->sr_slot == NULL) | 699 | if (res->sr_slot == NULL) |
| 701 | return 1; | 700 | return 1; |
| @@ -703,6 +702,7 @@ static int nfs4_sequence_done(struct rpc_task *task, | |||
| 703 | return nfs40_sequence_done(task, res); | 702 | return nfs40_sequence_done(task, res); |
| 704 | return nfs41_sequence_done(task, res); | 703 | return nfs41_sequence_done(task, res); |
| 705 | } | 704 | } |
| 705 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); | ||
| 706 | 706 | ||
| 707 | int nfs41_setup_sequence(struct nfs4_session *session, | 707 | int nfs41_setup_sequence(struct nfs4_session *session, |
| 708 | struct nfs4_sequence_args *args, | 708 | struct nfs4_sequence_args *args, |
| @@ -777,7 +777,8 @@ static int nfs4_setup_sequence(const struct nfs_server *server, | |||
| 777 | int ret = 0; | 777 | int ret = 0; |
| 778 | 778 | ||
| 779 | if (!session) | 779 | if (!session) |
| 780 | return nfs40_setup_sequence(server, args, res, task); | 780 | return nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 781 | args, res, task); | ||
| 781 | 782 | ||
| 782 | dprintk("--> %s clp %p session %p sr_slot %u\n", | 783 | dprintk("--> %s clp %p session %p sr_slot %u\n", |
| 783 | __func__, session->clp, session, res->sr_slot ? | 784 | __func__, session->clp, session, res->sr_slot ? |
| @@ -818,14 +819,16 @@ static int nfs4_setup_sequence(const struct nfs_server *server, | |||
| 818 | struct nfs4_sequence_res *res, | 819 | struct nfs4_sequence_res *res, |
| 819 | struct rpc_task *task) | 820 | struct rpc_task *task) |
| 820 | { | 821 | { |
| 821 | return nfs40_setup_sequence(server, args, res, task); | 822 | return nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 823 | args, res, task); | ||
| 822 | } | 824 | } |
| 823 | 825 | ||
| 824 | static int nfs4_sequence_done(struct rpc_task *task, | 826 | int nfs4_sequence_done(struct rpc_task *task, |
| 825 | struct nfs4_sequence_res *res) | 827 | struct nfs4_sequence_res *res) |
| 826 | { | 828 | { |
| 827 | return nfs40_sequence_done(task, res); | 829 | return nfs40_sequence_done(task, res); |
| 828 | } | 830 | } |
| 831 | EXPORT_SYMBOL_GPL(nfs4_sequence_done); | ||
| 829 | 832 | ||
| 830 | #endif /* !CONFIG_NFS_V4_1 */ | 833 | #endif /* !CONFIG_NFS_V4_1 */ |
| 831 | 834 | ||
| @@ -1712,8 +1715,8 @@ static void nfs4_open_confirm_prepare(struct rpc_task *task, void *calldata) | |||
| 1712 | { | 1715 | { |
| 1713 | struct nfs4_opendata *data = calldata; | 1716 | struct nfs4_opendata *data = calldata; |
| 1714 | 1717 | ||
| 1715 | nfs40_setup_sequence(data->o_arg.server, &data->c_arg.seq_args, | 1718 | nfs40_setup_sequence(data->o_arg.server->nfs_client->cl_slot_tbl, |
| 1716 | &data->c_res.seq_res, task); | 1719 | &data->c_arg.seq_args, &data->c_res.seq_res, task); |
| 1717 | } | 1720 | } |
| 1718 | 1721 | ||
| 1719 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) | 1722 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| @@ -5994,8 +5997,8 @@ static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata | |||
| 5994 | { | 5997 | { |
| 5995 | struct nfs_release_lockowner_data *data = calldata; | 5998 | struct nfs_release_lockowner_data *data = calldata; |
| 5996 | struct nfs_server *server = data->server; | 5999 | struct nfs_server *server = data->server; |
| 5997 | nfs40_setup_sequence(server, &data->args.seq_args, | 6000 | nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 5998 | &data->res.seq_res, task); | 6001 | &data->args.seq_args, &data->res.seq_res, task); |
| 5999 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; | 6002 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 6000 | data->timestamp = jiffies; | 6003 | data->timestamp = jiffies; |
| 6001 | } | 6004 | } |
| @@ -7557,6 +7560,7 @@ nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) | |||
| 7557 | return; | 7560 | return; |
| 7558 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, | 7561 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 7559 | NFS_I(lgp->args.inode)->layout, | 7562 | NFS_I(lgp->args.inode)->layout, |
| 7563 | &lgp->args.range, | ||
| 7560 | lgp->args.ctx->state)) { | 7564 | lgp->args.ctx->state)) { |
| 7561 | rpc_exit(task, NFS4_OK); | 7565 | rpc_exit(task, NFS4_OK); |
| 7562 | } | 7566 | } |
| @@ -7812,6 +7816,9 @@ static void nfs4_layoutreturn_release(void *calldata) | |||
| 7812 | spin_lock(&lo->plh_inode->i_lock); | 7816 | spin_lock(&lo->plh_inode->i_lock); |
| 7813 | if (lrp->res.lrs_present) | 7817 | if (lrp->res.lrs_present) |
| 7814 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); | 7818 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
| 7819 | pnfs_clear_layoutreturn_waitbit(lo); | ||
| 7820 | clear_bit(NFS_LAYOUT_RETURN_BEFORE_CLOSE, &lo->plh_flags); | ||
| 7821 | rpc_wake_up(&NFS_SERVER(lo->plh_inode)->roc_rpcwaitq); | ||
| 7815 | lo->plh_block_lgets--; | 7822 | lo->plh_block_lgets--; |
| 7816 | spin_unlock(&lo->plh_inode->i_lock); | 7823 | spin_unlock(&lo->plh_inode->i_lock); |
| 7817 | pnfs_put_layout_hdr(lrp->args.layout); | 7824 | pnfs_put_layout_hdr(lrp->args.layout); |
| @@ -7825,7 +7832,7 @@ static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { | |||
| 7825 | .rpc_release = nfs4_layoutreturn_release, | 7832 | .rpc_release = nfs4_layoutreturn_release, |
| 7826 | }; | 7833 | }; |
| 7827 | 7834 | ||
| 7828 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp) | 7835 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, bool sync) |
| 7829 | { | 7836 | { |
| 7830 | struct rpc_task *task; | 7837 | struct rpc_task *task; |
| 7831 | struct rpc_message msg = { | 7838 | struct rpc_message msg = { |
| @@ -7839,16 +7846,23 @@ int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp) | |||
| 7839 | .rpc_message = &msg, | 7846 | .rpc_message = &msg, |
| 7840 | .callback_ops = &nfs4_layoutreturn_call_ops, | 7847 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 7841 | .callback_data = lrp, | 7848 | .callback_data = lrp, |
| 7849 | .flags = RPC_TASK_ASYNC, | ||
| 7842 | }; | 7850 | }; |
| 7843 | int status; | 7851 | int status = 0; |
| 7844 | 7852 | ||
| 7845 | dprintk("--> %s\n", __func__); | 7853 | dprintk("--> %s\n", __func__); |
| 7846 | nfs4_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); | 7854 | nfs4_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
| 7847 | task = rpc_run_task(&task_setup_data); | 7855 | task = rpc_run_task(&task_setup_data); |
| 7848 | if (IS_ERR(task)) | 7856 | if (IS_ERR(task)) |
| 7849 | return PTR_ERR(task); | 7857 | return PTR_ERR(task); |
| 7858 | if (sync == false) | ||
| 7859 | goto out; | ||
| 7860 | status = nfs4_wait_for_completion_rpc_task(task); | ||
| 7861 | if (status != 0) | ||
| 7862 | goto out; | ||
| 7850 | status = task->tk_status; | 7863 | status = task->tk_status; |
| 7851 | trace_nfs4_layoutreturn(lrp->args.inode, status); | 7864 | trace_nfs4_layoutreturn(lrp->args.inode, status); |
| 7865 | out: | ||
| 7852 | dprintk("<-- %s status=%d\n", __func__, status); | 7866 | dprintk("<-- %s status=%d\n", __func__, status); |
| 7853 | rpc_put_task(task); | 7867 | rpc_put_task(task); |
| 7854 | return status; | 7868 | return status; |
diff --git a/fs/nfs/nfs4super.c b/fs/nfs/nfs4super.c index 6f340f02f2ba..48cea3c30e5d 100644 --- a/fs/nfs/nfs4super.c +++ b/fs/nfs/nfs4super.c | |||
| @@ -346,6 +346,9 @@ out: | |||
| 346 | 346 | ||
| 347 | static void __exit exit_nfs_v4(void) | 347 | static void __exit exit_nfs_v4(void) |
| 348 | { | 348 | { |
| 349 | /* Not called in the _init(), conditionally loaded */ | ||
| 350 | nfs4_pnfs_v3_ds_connect_unload(); | ||
| 351 | |||
| 349 | unregister_nfs_version(&nfs_v4); | 352 | unregister_nfs_version(&nfs_v4); |
| 350 | nfs4_unregister_sysctl(); | 353 | nfs4_unregister_sysctl(); |
| 351 | nfs_idmap_quit(); | 354 | nfs_idmap_quit(); |
diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c index 41253393171f..a2329d69502b 100644 --- a/fs/nfs/nfs4xdr.c +++ b/fs/nfs/nfs4xdr.c | |||
| @@ -2011,11 +2011,11 @@ encode_layoutreturn(struct xdr_stream *xdr, | |||
| 2011 | p = reserve_space(xdr, 16); | 2011 | p = reserve_space(xdr, 16); |
| 2012 | *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */ | 2012 | *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */ |
| 2013 | *p++ = cpu_to_be32(args->layout_type); | 2013 | *p++ = cpu_to_be32(args->layout_type); |
| 2014 | *p++ = cpu_to_be32(IOMODE_ANY); | 2014 | *p++ = cpu_to_be32(args->range.iomode); |
| 2015 | *p = cpu_to_be32(RETURN_FILE); | 2015 | *p = cpu_to_be32(RETURN_FILE); |
| 2016 | p = reserve_space(xdr, 16); | 2016 | p = reserve_space(xdr, 16); |
| 2017 | p = xdr_encode_hyper(p, 0); | 2017 | p = xdr_encode_hyper(p, args->range.offset); |
| 2018 | p = xdr_encode_hyper(p, NFS4_MAX_UINT64); | 2018 | p = xdr_encode_hyper(p, args->range.length); |
| 2019 | spin_lock(&args->inode->i_lock); | 2019 | spin_lock(&args->inode->i_lock); |
| 2020 | encode_nfs4_stateid(xdr, &args->stateid); | 2020 | encode_nfs4_stateid(xdr, &args->stateid); |
| 2021 | spin_unlock(&args->inode->i_lock); | 2021 | spin_unlock(&args->inode->i_lock); |
| @@ -6566,6 +6566,7 @@ static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr, | |||
| 6566 | int status; | 6566 | int status; |
| 6567 | 6567 | ||
| 6568 | status = decode_compound_hdr(xdr, &hdr); | 6568 | status = decode_compound_hdr(xdr, &hdr); |
| 6569 | res->op_status = hdr.status; | ||
| 6569 | if (status) | 6570 | if (status) |
| 6570 | goto out; | 6571 | goto out; |
| 6571 | status = decode_sequence(xdr, &res->seq_res, rqstp); | 6572 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
| @@ -6591,6 +6592,7 @@ static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr, | |||
| 6591 | int status; | 6592 | int status; |
| 6592 | 6593 | ||
| 6593 | status = decode_compound_hdr(xdr, &hdr); | 6594 | status = decode_compound_hdr(xdr, &hdr); |
| 6595 | res->op_status = hdr.status; | ||
| 6594 | if (status) | 6596 | if (status) |
| 6595 | goto out; | 6597 | goto out; |
| 6596 | status = decode_sequence(xdr, &res->seq_res, rqstp); | 6598 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
| @@ -6620,6 +6622,7 @@ static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr, | |||
| 6620 | int status; | 6622 | int status; |
| 6621 | 6623 | ||
| 6622 | status = decode_compound_hdr(xdr, &hdr); | 6624 | status = decode_compound_hdr(xdr, &hdr); |
| 6625 | res->op_status = hdr.status; | ||
| 6623 | if (status) | 6626 | if (status) |
| 6624 | goto out; | 6627 | goto out; |
| 6625 | status = decode_sequence(xdr, &res->seq_res, rqstp); | 6628 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
diff --git a/fs/nfs/objlayout/objio_osd.c b/fs/nfs/objlayout/objio_osd.c index 9e5bc42180e4..24e1d7403c0b 100644 --- a/fs/nfs/objlayout/objio_osd.c +++ b/fs/nfs/objlayout/objio_osd.c | |||
| @@ -537,11 +537,12 @@ int objio_write_pagelist(struct nfs_pgio_header *hdr, int how) | |||
| 537 | static size_t objio_pg_test(struct nfs_pageio_descriptor *pgio, | 537 | static size_t objio_pg_test(struct nfs_pageio_descriptor *pgio, |
| 538 | struct nfs_page *prev, struct nfs_page *req) | 538 | struct nfs_page *prev, struct nfs_page *req) |
| 539 | { | 539 | { |
| 540 | struct nfs_pgio_mirror *mirror = nfs_pgio_current_mirror(pgio); | ||
| 540 | unsigned int size; | 541 | unsigned int size; |
| 541 | 542 | ||
| 542 | size = pnfs_generic_pg_test(pgio, prev, req); | 543 | size = pnfs_generic_pg_test(pgio, prev, req); |
| 543 | 544 | ||
| 544 | if (!size || pgio->pg_count + req->wb_bytes > | 545 | if (!size || mirror->pg_count + req->wb_bytes > |
| 545 | (unsigned long)pgio->pg_layout_private) | 546 | (unsigned long)pgio->pg_layout_private) |
| 546 | return 0; | 547 | return 0; |
| 547 | 548 | ||
| @@ -607,12 +608,14 @@ static const struct nfs_pageio_ops objio_pg_read_ops = { | |||
| 607 | .pg_init = objio_init_read, | 608 | .pg_init = objio_init_read, |
| 608 | .pg_test = objio_pg_test, | 609 | .pg_test = objio_pg_test, |
| 609 | .pg_doio = pnfs_generic_pg_readpages, | 610 | .pg_doio = pnfs_generic_pg_readpages, |
| 611 | .pg_cleanup = pnfs_generic_pg_cleanup, | ||
| 610 | }; | 612 | }; |
| 611 | 613 | ||
| 612 | static const struct nfs_pageio_ops objio_pg_write_ops = { | 614 | static const struct nfs_pageio_ops objio_pg_write_ops = { |
| 613 | .pg_init = objio_init_write, | 615 | .pg_init = objio_init_write, |
| 614 | .pg_test = objio_pg_test, | 616 | .pg_test = objio_pg_test, |
| 615 | .pg_doio = pnfs_generic_pg_writepages, | 617 | .pg_doio = pnfs_generic_pg_writepages, |
| 618 | .pg_cleanup = pnfs_generic_pg_cleanup, | ||
| 616 | }; | 619 | }; |
| 617 | 620 | ||
| 618 | static struct pnfs_layoutdriver_type objlayout_type = { | 621 | static struct pnfs_layoutdriver_type objlayout_type = { |
diff --git a/fs/nfs/pagelist.c b/fs/nfs/pagelist.c index 2b5e769beb16..960c99f75d3f 100644 --- a/fs/nfs/pagelist.c +++ b/fs/nfs/pagelist.c | |||
| @@ -42,21 +42,35 @@ static bool nfs_pgarray_set(struct nfs_page_array *p, unsigned int pagecount) | |||
| 42 | return p->pagevec != NULL; | 42 | return p->pagevec != NULL; |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | struct nfs_pgio_mirror * | ||
| 46 | nfs_pgio_current_mirror(struct nfs_pageio_descriptor *desc) | ||
| 47 | { | ||
| 48 | return nfs_pgio_has_mirroring(desc) ? | ||
| 49 | &desc->pg_mirrors[desc->pg_mirror_idx] : | ||
| 50 | &desc->pg_mirrors[0]; | ||
| 51 | } | ||
| 52 | EXPORT_SYMBOL_GPL(nfs_pgio_current_mirror); | ||
| 53 | |||
| 45 | void nfs_pgheader_init(struct nfs_pageio_descriptor *desc, | 54 | void nfs_pgheader_init(struct nfs_pageio_descriptor *desc, |
| 46 | struct nfs_pgio_header *hdr, | 55 | struct nfs_pgio_header *hdr, |
| 47 | void (*release)(struct nfs_pgio_header *hdr)) | 56 | void (*release)(struct nfs_pgio_header *hdr)) |
| 48 | { | 57 | { |
| 49 | hdr->req = nfs_list_entry(desc->pg_list.next); | 58 | struct nfs_pgio_mirror *mirror = nfs_pgio_current_mirror(desc); |
| 59 | |||
| 60 | |||
| 61 | hdr->req = nfs_list_entry(mirror->pg_list.next); | ||
| 50 | hdr->inode = desc->pg_inode; | 62 | hdr->inode = desc->pg_inode; |
| 51 | hdr->cred = hdr->req->wb_context->cred; | 63 | hdr->cred = hdr->req->wb_context->cred; |
| 52 | hdr->io_start = req_offset(hdr->req); | 64 | hdr->io_start = req_offset(hdr->req); |
| 53 | hdr->good_bytes = desc->pg_count; | 65 | hdr->good_bytes = mirror->pg_count; |
| 54 | hdr->dreq = desc->pg_dreq; | 66 | hdr->dreq = desc->pg_dreq; |
| 55 | hdr->layout_private = desc->pg_layout_private; | 67 | hdr->layout_private = desc->pg_layout_private; |
| 56 | hdr->release = release; | 68 | hdr->release = release; |
| 57 | hdr->completion_ops = desc->pg_completion_ops; | 69 | hdr->completion_ops = desc->pg_completion_ops; |
| 58 | if (hdr->completion_ops->init_hdr) | 70 | if (hdr->completion_ops->init_hdr) |
| 59 | hdr->completion_ops->init_hdr(hdr); | 71 | hdr->completion_ops->init_hdr(hdr); |
| 72 | |||
| 73 | hdr->pgio_mirror_idx = desc->pg_mirror_idx; | ||
| 60 | } | 74 | } |
| 61 | EXPORT_SYMBOL_GPL(nfs_pgheader_init); | 75 | EXPORT_SYMBOL_GPL(nfs_pgheader_init); |
| 62 | 76 | ||
| @@ -480,7 +494,10 @@ nfs_wait_on_request(struct nfs_page *req) | |||
| 480 | size_t nfs_generic_pg_test(struct nfs_pageio_descriptor *desc, | 494 | size_t nfs_generic_pg_test(struct nfs_pageio_descriptor *desc, |
| 481 | struct nfs_page *prev, struct nfs_page *req) | 495 | struct nfs_page *prev, struct nfs_page *req) |
| 482 | { | 496 | { |
| 483 | if (desc->pg_count > desc->pg_bsize) { | 497 | struct nfs_pgio_mirror *mirror = nfs_pgio_current_mirror(desc); |
| 498 | |||
| 499 | |||
| 500 | if (mirror->pg_count > mirror->pg_bsize) { | ||
| 484 | /* should never happen */ | 501 | /* should never happen */ |
| 485 | WARN_ON_ONCE(1); | 502 | WARN_ON_ONCE(1); |
| 486 | return 0; | 503 | return 0; |
| @@ -490,11 +507,11 @@ size_t nfs_generic_pg_test(struct nfs_pageio_descriptor *desc, | |||
| 490 | * Limit the request size so that we can still allocate a page array | 507 | * Limit the request size so that we can still allocate a page array |
| 491 | * for it without upsetting the slab allocator. | 508 | * for it without upsetting the slab allocator. |
| 492 | */ | 509 | */ |
| 493 | if (((desc->pg_count + req->wb_bytes) >> PAGE_SHIFT) * | 510 | if (((mirror->pg_count + req->wb_bytes) >> PAGE_SHIFT) * |
| 494 | sizeof(struct page) > PAGE_SIZE) | 511 | sizeof(struct page) > PAGE_SIZE) |
| 495 | return 0; | 512 | return 0; |
| 496 | 513 | ||
| 497 | return min(desc->pg_bsize - desc->pg_count, (size_t)req->wb_bytes); | 514 | return min(mirror->pg_bsize - mirror->pg_count, (size_t)req->wb_bytes); |
| 498 | } | 515 | } |
| 499 | EXPORT_SYMBOL_GPL(nfs_generic_pg_test); | 516 | EXPORT_SYMBOL_GPL(nfs_generic_pg_test); |
| 500 | 517 | ||
| @@ -597,13 +614,14 @@ static void nfs_pgio_prepare(struct rpc_task *task, void *calldata) | |||
| 597 | } | 614 | } |
| 598 | 615 | ||
| 599 | int nfs_initiate_pgio(struct rpc_clnt *clnt, struct nfs_pgio_header *hdr, | 616 | int nfs_initiate_pgio(struct rpc_clnt *clnt, struct nfs_pgio_header *hdr, |
| 617 | struct rpc_cred *cred, const struct nfs_rpc_ops *rpc_ops, | ||
| 600 | const struct rpc_call_ops *call_ops, int how, int flags) | 618 | const struct rpc_call_ops *call_ops, int how, int flags) |
| 601 | { | 619 | { |
| 602 | struct rpc_task *task; | 620 | struct rpc_task *task; |
| 603 | struct rpc_message msg = { | 621 | struct rpc_message msg = { |
| 604 | .rpc_argp = &hdr->args, | 622 | .rpc_argp = &hdr->args, |
| 605 | .rpc_resp = &hdr->res, | 623 | .rpc_resp = &hdr->res, |
| 606 | .rpc_cred = hdr->cred, | 624 | .rpc_cred = cred, |
| 607 | }; | 625 | }; |
| 608 | struct rpc_task_setup task_setup_data = { | 626 | struct rpc_task_setup task_setup_data = { |
| 609 | .rpc_client = clnt, | 627 | .rpc_client = clnt, |
| @@ -616,7 +634,7 @@ int nfs_initiate_pgio(struct rpc_clnt *clnt, struct nfs_pgio_header *hdr, | |||
| 616 | }; | 634 | }; |
| 617 | int ret = 0; | 635 | int ret = 0; |
| 618 | 636 | ||
| 619 | hdr->rw_ops->rw_initiate(hdr, &msg, &task_setup_data, how); | 637 | hdr->rw_ops->rw_initiate(hdr, &msg, rpc_ops, &task_setup_data, how); |
| 620 | 638 | ||
| 621 | dprintk("NFS: %5u initiated pgio call " | 639 | dprintk("NFS: %5u initiated pgio call " |
| 622 | "(req %s/%llu, %u bytes @ offset %llu)\n", | 640 | "(req %s/%llu, %u bytes @ offset %llu)\n", |
| @@ -650,10 +668,18 @@ EXPORT_SYMBOL_GPL(nfs_initiate_pgio); | |||
| 650 | static int nfs_pgio_error(struct nfs_pageio_descriptor *desc, | 668 | static int nfs_pgio_error(struct nfs_pageio_descriptor *desc, |
| 651 | struct nfs_pgio_header *hdr) | 669 | struct nfs_pgio_header *hdr) |
| 652 | { | 670 | { |
| 671 | struct nfs_pgio_mirror *mirror; | ||
| 672 | u32 midx; | ||
| 673 | |||
| 653 | set_bit(NFS_IOHDR_REDO, &hdr->flags); | 674 | set_bit(NFS_IOHDR_REDO, &hdr->flags); |
| 654 | nfs_pgio_data_destroy(hdr); | 675 | nfs_pgio_data_destroy(hdr); |
| 655 | hdr->completion_ops->completion(hdr); | 676 | hdr->completion_ops->completion(hdr); |
| 656 | desc->pg_completion_ops->error_cleanup(&desc->pg_list); | 677 | /* TODO: Make sure it's right to clean up all mirrors here |
| 678 | * and not just hdr->pgio_mirror_idx */ | ||
| 679 | for (midx = 0; midx < desc->pg_mirror_count; midx++) { | ||
| 680 | mirror = &desc->pg_mirrors[midx]; | ||
| 681 | desc->pg_completion_ops->error_cleanup(&mirror->pg_list); | ||
| 682 | } | ||
| 657 | return -ENOMEM; | 683 | return -ENOMEM; |
| 658 | } | 684 | } |
| 659 | 685 | ||
| @@ -670,6 +696,17 @@ static void nfs_pgio_release(void *calldata) | |||
| 670 | hdr->completion_ops->completion(hdr); | 696 | hdr->completion_ops->completion(hdr); |
| 671 | } | 697 | } |
| 672 | 698 | ||
| 699 | static void nfs_pageio_mirror_init(struct nfs_pgio_mirror *mirror, | ||
| 700 | unsigned int bsize) | ||
| 701 | { | ||
| 702 | INIT_LIST_HEAD(&mirror->pg_list); | ||
| 703 | mirror->pg_bytes_written = 0; | ||
| 704 | mirror->pg_count = 0; | ||
| 705 | mirror->pg_bsize = bsize; | ||
| 706 | mirror->pg_base = 0; | ||
| 707 | mirror->pg_recoalesce = 0; | ||
| 708 | } | ||
| 709 | |||
| 673 | /** | 710 | /** |
| 674 | * nfs_pageio_init - initialise a page io descriptor | 711 | * nfs_pageio_init - initialise a page io descriptor |
| 675 | * @desc: pointer to descriptor | 712 | * @desc: pointer to descriptor |
| @@ -686,13 +723,10 @@ void nfs_pageio_init(struct nfs_pageio_descriptor *desc, | |||
| 686 | size_t bsize, | 723 | size_t bsize, |
| 687 | int io_flags) | 724 | int io_flags) |
| 688 | { | 725 | { |
| 689 | INIT_LIST_HEAD(&desc->pg_list); | 726 | struct nfs_pgio_mirror *new; |
| 690 | desc->pg_bytes_written = 0; | 727 | int i; |
| 691 | desc->pg_count = 0; | 728 | |
| 692 | desc->pg_bsize = bsize; | ||
| 693 | desc->pg_base = 0; | ||
| 694 | desc->pg_moreio = 0; | 729 | desc->pg_moreio = 0; |
| 695 | desc->pg_recoalesce = 0; | ||
| 696 | desc->pg_inode = inode; | 730 | desc->pg_inode = inode; |
| 697 | desc->pg_ops = pg_ops; | 731 | desc->pg_ops = pg_ops; |
| 698 | desc->pg_completion_ops = compl_ops; | 732 | desc->pg_completion_ops = compl_ops; |
| @@ -702,6 +736,26 @@ void nfs_pageio_init(struct nfs_pageio_descriptor *desc, | |||
| 702 | desc->pg_lseg = NULL; | 736 | desc->pg_lseg = NULL; |
| 703 | desc->pg_dreq = NULL; | 737 | desc->pg_dreq = NULL; |
| 704 | desc->pg_layout_private = NULL; | 738 | desc->pg_layout_private = NULL; |
| 739 | desc->pg_bsize = bsize; | ||
| 740 | |||
| 741 | desc->pg_mirror_count = 1; | ||
| 742 | desc->pg_mirror_idx = 0; | ||
| 743 | |||
| 744 | if (pg_ops->pg_get_mirror_count) { | ||
| 745 | /* until we have a request, we don't have an lseg and no | ||
| 746 | * idea how many mirrors there will be */ | ||
| 747 | new = kcalloc(NFS_PAGEIO_DESCRIPTOR_MIRROR_MAX, | ||
| 748 | sizeof(struct nfs_pgio_mirror), GFP_KERNEL); | ||
| 749 | desc->pg_mirrors_dynamic = new; | ||
| 750 | desc->pg_mirrors = new; | ||
| 751 | |||
| 752 | for (i = 0; i < NFS_PAGEIO_DESCRIPTOR_MIRROR_MAX; i++) | ||
| 753 | nfs_pageio_mirror_init(&desc->pg_mirrors[i], bsize); | ||
| 754 | } else { | ||
| 755 | desc->pg_mirrors_dynamic = NULL; | ||
| 756 | desc->pg_mirrors = desc->pg_mirrors_static; | ||
| 757 | nfs_pageio_mirror_init(&desc->pg_mirrors[0], bsize); | ||
| 758 | } | ||
| 705 | } | 759 | } |
| 706 | EXPORT_SYMBOL_GPL(nfs_pageio_init); | 760 | EXPORT_SYMBOL_GPL(nfs_pageio_init); |
| 707 | 761 | ||
| @@ -737,14 +791,16 @@ static void nfs_pgio_result(struct rpc_task *task, void *calldata) | |||
| 737 | int nfs_generic_pgio(struct nfs_pageio_descriptor *desc, | 791 | int nfs_generic_pgio(struct nfs_pageio_descriptor *desc, |
| 738 | struct nfs_pgio_header *hdr) | 792 | struct nfs_pgio_header *hdr) |
| 739 | { | 793 | { |
| 794 | struct nfs_pgio_mirror *mirror = nfs_pgio_current_mirror(desc); | ||
| 795 | |||
| 740 | struct nfs_page *req; | 796 | struct nfs_page *req; |
| 741 | struct page **pages, | 797 | struct page **pages, |
| 742 | *last_page; | 798 | *last_page; |
| 743 | struct list_head *head = &desc->pg_list; | 799 | struct list_head *head = &mirror->pg_list; |
| 744 | struct nfs_commit_info cinfo; | 800 | struct nfs_commit_info cinfo; |
| 745 | unsigned int pagecount, pageused; | 801 | unsigned int pagecount, pageused; |
| 746 | 802 | ||
| 747 | pagecount = nfs_page_array_len(desc->pg_base, desc->pg_count); | 803 | pagecount = nfs_page_array_len(mirror->pg_base, mirror->pg_count); |
| 748 | if (!nfs_pgarray_set(&hdr->page_array, pagecount)) | 804 | if (!nfs_pgarray_set(&hdr->page_array, pagecount)) |
| 749 | return nfs_pgio_error(desc, hdr); | 805 | return nfs_pgio_error(desc, hdr); |
| 750 | 806 | ||
| @@ -772,7 +828,7 @@ int nfs_generic_pgio(struct nfs_pageio_descriptor *desc, | |||
| 772 | desc->pg_ioflags &= ~FLUSH_COND_STABLE; | 828 | desc->pg_ioflags &= ~FLUSH_COND_STABLE; |
| 773 | 829 | ||
| 774 | /* Set up the argument struct */ | 830 | /* Set up the argument struct */ |
| 775 | nfs_pgio_rpcsetup(hdr, desc->pg_count, 0, desc->pg_ioflags, &cinfo); | 831 | nfs_pgio_rpcsetup(hdr, mirror->pg_count, 0, desc->pg_ioflags, &cinfo); |
| 776 | desc->pg_rpc_callops = &nfs_pgio_common_ops; | 832 | desc->pg_rpc_callops = &nfs_pgio_common_ops; |
| 777 | return 0; | 833 | return 0; |
| 778 | } | 834 | } |
| @@ -780,23 +836,74 @@ EXPORT_SYMBOL_GPL(nfs_generic_pgio); | |||
| 780 | 836 | ||
| 781 | static int nfs_generic_pg_pgios(struct nfs_pageio_descriptor *desc) | 837 | static int nfs_generic_pg_pgios(struct nfs_pageio_descriptor *desc) |
| 782 | { | 838 | { |
| 839 | struct nfs_pgio_mirror *mirror; | ||
| 783 | struct nfs_pgio_header *hdr; | 840 | struct nfs_pgio_header *hdr; |
| 784 | int ret; | 841 | int ret; |
| 785 | 842 | ||
| 843 | mirror = nfs_pgio_current_mirror(desc); | ||
| 844 | |||
| 786 | hdr = nfs_pgio_header_alloc(desc->pg_rw_ops); | 845 | hdr = nfs_pgio_header_alloc(desc->pg_rw_ops); |
| 787 | if (!hdr) { | 846 | if (!hdr) { |
| 788 | desc->pg_completion_ops->error_cleanup(&desc->pg_list); | 847 | /* TODO: make sure this is right with mirroring - or |
| 848 | * should it back out all mirrors? */ | ||
| 849 | desc->pg_completion_ops->error_cleanup(&mirror->pg_list); | ||
| 789 | return -ENOMEM; | 850 | return -ENOMEM; |
| 790 | } | 851 | } |
| 791 | nfs_pgheader_init(desc, hdr, nfs_pgio_header_free); | 852 | nfs_pgheader_init(desc, hdr, nfs_pgio_header_free); |
| 792 | ret = nfs_generic_pgio(desc, hdr); | 853 | ret = nfs_generic_pgio(desc, hdr); |
| 793 | if (ret == 0) | 854 | if (ret == 0) |
| 794 | ret = nfs_initiate_pgio(NFS_CLIENT(hdr->inode), | 855 | ret = nfs_initiate_pgio(NFS_CLIENT(hdr->inode), |
| 795 | hdr, desc->pg_rpc_callops, | 856 | hdr, |
| 857 | hdr->cred, | ||
| 858 | NFS_PROTO(hdr->inode), | ||
| 859 | desc->pg_rpc_callops, | ||
| 796 | desc->pg_ioflags, 0); | 860 | desc->pg_ioflags, 0); |
| 797 | return ret; | 861 | return ret; |
| 798 | } | 862 | } |
| 799 | 863 | ||
| 864 | /* | ||
| 865 | * nfs_pageio_setup_mirroring - determine if mirroring is to be used | ||
| 866 | * by calling the pg_get_mirror_count op | ||
| 867 | */ | ||
| 868 | static int nfs_pageio_setup_mirroring(struct nfs_pageio_descriptor *pgio, | ||
| 869 | struct nfs_page *req) | ||
| 870 | { | ||
| 871 | int mirror_count = 1; | ||
| 872 | |||
| 873 | if (!pgio->pg_ops->pg_get_mirror_count) | ||
| 874 | return 0; | ||
| 875 | |||
| 876 | mirror_count = pgio->pg_ops->pg_get_mirror_count(pgio, req); | ||
| 877 | |||
| 878 | if (!mirror_count || mirror_count > NFS_PAGEIO_DESCRIPTOR_MIRROR_MAX) | ||
| 879 | return -EINVAL; | ||
| 880 | |||
| 881 | if (WARN_ON_ONCE(!pgio->pg_mirrors_dynamic)) | ||
| 882 | return -EINVAL; | ||
| 883 | |||
| 884 | pgio->pg_mirror_count = mirror_count; | ||
| 885 | |||
| 886 | return 0; | ||
| 887 | } | ||
| 888 | |||
| 889 | /* | ||
| 890 | * nfs_pageio_stop_mirroring - stop using mirroring (set mirror count to 1) | ||
| 891 | */ | ||
| 892 | void nfs_pageio_stop_mirroring(struct nfs_pageio_descriptor *pgio) | ||
| 893 | { | ||
| 894 | pgio->pg_mirror_count = 1; | ||
| 895 | pgio->pg_mirror_idx = 0; | ||
| 896 | } | ||
| 897 | |||
| 898 | static void nfs_pageio_cleanup_mirroring(struct nfs_pageio_descriptor *pgio) | ||
| 899 | { | ||
| 900 | pgio->pg_mirror_count = 1; | ||
| 901 | pgio->pg_mirror_idx = 0; | ||
| 902 | pgio->pg_mirrors = pgio->pg_mirrors_static; | ||
| 903 | kfree(pgio->pg_mirrors_dynamic); | ||
| 904 | pgio->pg_mirrors_dynamic = NULL; | ||
| 905 | } | ||
| 906 | |||
| 800 | static bool nfs_match_open_context(const struct nfs_open_context *ctx1, | 907 | static bool nfs_match_open_context(const struct nfs_open_context *ctx1, |
| 801 | const struct nfs_open_context *ctx2) | 908 | const struct nfs_open_context *ctx2) |
| 802 | { | 909 | { |
| @@ -863,19 +970,22 @@ static bool nfs_can_coalesce_requests(struct nfs_page *prev, | |||
| 863 | static int nfs_pageio_do_add_request(struct nfs_pageio_descriptor *desc, | 970 | static int nfs_pageio_do_add_request(struct nfs_pageio_descriptor *desc, |
| 864 | struct nfs_page *req) | 971 | struct nfs_page *req) |
| 865 | { | 972 | { |
| 973 | struct nfs_pgio_mirror *mirror = nfs_pgio_current_mirror(desc); | ||
| 974 | |||
| 866 | struct nfs_page *prev = NULL; | 975 | struct nfs_page *prev = NULL; |
| 867 | if (desc->pg_count != 0) { | 976 | |
| 868 | prev = nfs_list_entry(desc->pg_list.prev); | 977 | if (mirror->pg_count != 0) { |
| 978 | prev = nfs_list_entry(mirror->pg_list.prev); | ||
| 869 | } else { | 979 | } else { |
| 870 | if (desc->pg_ops->pg_init) | 980 | if (desc->pg_ops->pg_init) |
| 871 | desc->pg_ops->pg_init(desc, req); | 981 | desc->pg_ops->pg_init(desc, req); |
| 872 | desc->pg_base = req->wb_pgbase; | 982 | mirror->pg_base = req->wb_pgbase; |
| 873 | } | 983 | } |
| 874 | if (!nfs_can_coalesce_requests(prev, req, desc)) | 984 | if (!nfs_can_coalesce_requests(prev, req, desc)) |
| 875 | return 0; | 985 | return 0; |
| 876 | nfs_list_remove_request(req); | 986 | nfs_list_remove_request(req); |
| 877 | nfs_list_add_request(req, &desc->pg_list); | 987 | nfs_list_add_request(req, &mirror->pg_list); |
| 878 | desc->pg_count += req->wb_bytes; | 988 | mirror->pg_count += req->wb_bytes; |
| 879 | return 1; | 989 | return 1; |
| 880 | } | 990 | } |
| 881 | 991 | ||
| @@ -884,16 +994,19 @@ static int nfs_pageio_do_add_request(struct nfs_pageio_descriptor *desc, | |||
| 884 | */ | 994 | */ |
| 885 | static void nfs_pageio_doio(struct nfs_pageio_descriptor *desc) | 995 | static void nfs_pageio_doio(struct nfs_pageio_descriptor *desc) |
| 886 | { | 996 | { |
| 887 | if (!list_empty(&desc->pg_list)) { | 997 | struct nfs_pgio_mirror *mirror = nfs_pgio_current_mirror(desc); |
| 998 | |||
| 999 | |||
| 1000 | if (!list_empty(&mirror->pg_list)) { | ||
| 888 | int error = desc->pg_ops->pg_doio(desc); | 1001 | int error = desc->pg_ops->pg_doio(desc); |
| 889 | if (error < 0) | 1002 | if (error < 0) |
| 890 | desc->pg_error = error; | 1003 | desc->pg_error = error; |
| 891 | else | 1004 | else |
| 892 | desc->pg_bytes_written += desc->pg_count; | 1005 | mirror->pg_bytes_written += mirror->pg_count; |
| 893 | } | 1006 | } |
| 894 | if (list_empty(&desc->pg_list)) { | 1007 | if (list_empty(&mirror->pg_list)) { |
| 895 | desc->pg_count = 0; | 1008 | mirror->pg_count = 0; |
| 896 | desc->pg_base = 0; | 1009 | mirror->pg_base = 0; |
| 897 | } | 1010 | } |
| 898 | } | 1011 | } |
| 899 | 1012 | ||
| @@ -911,6 +1024,8 @@ static void nfs_pageio_doio(struct nfs_pageio_descriptor *desc) | |||
| 911 | static int __nfs_pageio_add_request(struct nfs_pageio_descriptor *desc, | 1024 | static int __nfs_pageio_add_request(struct nfs_pageio_descriptor *desc, |
| 912 | struct nfs_page *req) | 1025 | struct nfs_page *req) |
| 913 | { | 1026 | { |
| 1027 | struct nfs_pgio_mirror *mirror = nfs_pgio_current_mirror(desc); | ||
| 1028 | |||
| 914 | struct nfs_page *subreq; | 1029 | struct nfs_page *subreq; |
| 915 | unsigned int bytes_left = 0; | 1030 | unsigned int bytes_left = 0; |
| 916 | unsigned int offset, pgbase; | 1031 | unsigned int offset, pgbase; |
| @@ -934,7 +1049,7 @@ static int __nfs_pageio_add_request(struct nfs_pageio_descriptor *desc, | |||
| 934 | nfs_pageio_doio(desc); | 1049 | nfs_pageio_doio(desc); |
| 935 | if (desc->pg_error < 0) | 1050 | if (desc->pg_error < 0) |
| 936 | return 0; | 1051 | return 0; |
| 937 | if (desc->pg_recoalesce) | 1052 | if (mirror->pg_recoalesce) |
| 938 | return 0; | 1053 | return 0; |
| 939 | /* retry add_request for this subreq */ | 1054 | /* retry add_request for this subreq */ |
| 940 | nfs_page_group_lock(req, false); | 1055 | nfs_page_group_lock(req, false); |
| @@ -972,14 +1087,16 @@ err_ptr: | |||
| 972 | 1087 | ||
| 973 | static int nfs_do_recoalesce(struct nfs_pageio_descriptor *desc) | 1088 | static int nfs_do_recoalesce(struct nfs_pageio_descriptor *desc) |
| 974 | { | 1089 | { |
| 1090 | struct nfs_pgio_mirror *mirror = nfs_pgio_current_mirror(desc); | ||
| 975 | LIST_HEAD(head); | 1091 | LIST_HEAD(head); |
| 976 | 1092 | ||
| 977 | do { | 1093 | do { |
| 978 | list_splice_init(&desc->pg_list, &head); | 1094 | list_splice_init(&mirror->pg_list, &head); |
| 979 | desc->pg_bytes_written -= desc->pg_count; | 1095 | mirror->pg_bytes_written -= mirror->pg_count; |
| 980 | desc->pg_count = 0; | 1096 | mirror->pg_count = 0; |
| 981 | desc->pg_base = 0; | 1097 | mirror->pg_base = 0; |
| 982 | desc->pg_recoalesce = 0; | 1098 | mirror->pg_recoalesce = 0; |
| 1099 | |||
| 983 | desc->pg_moreio = 0; | 1100 | desc->pg_moreio = 0; |
| 984 | 1101 | ||
| 985 | while (!list_empty(&head)) { | 1102 | while (!list_empty(&head)) { |
| @@ -993,11 +1110,11 @@ static int nfs_do_recoalesce(struct nfs_pageio_descriptor *desc) | |||
| 993 | return 0; | 1110 | return 0; |
| 994 | break; | 1111 | break; |
| 995 | } | 1112 | } |
| 996 | } while (desc->pg_recoalesce); | 1113 | } while (mirror->pg_recoalesce); |
| 997 | return 1; | 1114 | return 1; |
| 998 | } | 1115 | } |
| 999 | 1116 | ||
| 1000 | int nfs_pageio_add_request(struct nfs_pageio_descriptor *desc, | 1117 | static int nfs_pageio_add_request_mirror(struct nfs_pageio_descriptor *desc, |
| 1001 | struct nfs_page *req) | 1118 | struct nfs_page *req) |
| 1002 | { | 1119 | { |
| 1003 | int ret; | 1120 | int ret; |
| @@ -1010,9 +1127,80 @@ int nfs_pageio_add_request(struct nfs_pageio_descriptor *desc, | |||
| 1010 | break; | 1127 | break; |
| 1011 | ret = nfs_do_recoalesce(desc); | 1128 | ret = nfs_do_recoalesce(desc); |
| 1012 | } while (ret); | 1129 | } while (ret); |
| 1130 | |||
| 1013 | return ret; | 1131 | return ret; |
| 1014 | } | 1132 | } |
| 1015 | 1133 | ||
| 1134 | int nfs_pageio_add_request(struct nfs_pageio_descriptor *desc, | ||
| 1135 | struct nfs_page *req) | ||
| 1136 | { | ||
| 1137 | u32 midx; | ||
| 1138 | unsigned int pgbase, offset, bytes; | ||
| 1139 | struct nfs_page *dupreq, *lastreq; | ||
| 1140 | |||
| 1141 | pgbase = req->wb_pgbase; | ||
| 1142 | offset = req->wb_offset; | ||
| 1143 | bytes = req->wb_bytes; | ||
| 1144 | |||
| 1145 | nfs_pageio_setup_mirroring(desc, req); | ||
| 1146 | |||
| 1147 | for (midx = 0; midx < desc->pg_mirror_count; midx++) { | ||
| 1148 | if (midx) { | ||
| 1149 | nfs_page_group_lock(req, false); | ||
| 1150 | |||
| 1151 | /* find the last request */ | ||
| 1152 | for (lastreq = req->wb_head; | ||
| 1153 | lastreq->wb_this_page != req->wb_head; | ||
| 1154 | lastreq = lastreq->wb_this_page) | ||
| 1155 | ; | ||
| 1156 | |||
| 1157 | dupreq = nfs_create_request(req->wb_context, | ||
| 1158 | req->wb_page, lastreq, pgbase, bytes); | ||
| 1159 | |||
| 1160 | if (IS_ERR(dupreq)) { | ||
| 1161 | nfs_page_group_unlock(req); | ||
| 1162 | return 0; | ||
| 1163 | } | ||
| 1164 | |||
| 1165 | nfs_lock_request(dupreq); | ||
| 1166 | nfs_page_group_unlock(req); | ||
| 1167 | dupreq->wb_offset = offset; | ||
| 1168 | dupreq->wb_index = req->wb_index; | ||
| 1169 | } else | ||
| 1170 | dupreq = req; | ||
| 1171 | |||
| 1172 | if (nfs_pgio_has_mirroring(desc)) | ||
| 1173 | desc->pg_mirror_idx = midx; | ||
| 1174 | if (!nfs_pageio_add_request_mirror(desc, dupreq)) | ||
| 1175 | return 0; | ||
| 1176 | } | ||
| 1177 | |||
| 1178 | return 1; | ||
| 1179 | } | ||
| 1180 | |||
| 1181 | /* | ||
| 1182 | * nfs_pageio_complete_mirror - Complete I/O on the current mirror of an | ||
| 1183 | * nfs_pageio_descriptor | ||
| 1184 | * @desc: pointer to io descriptor | ||
| 1185 | */ | ||
| 1186 | static void nfs_pageio_complete_mirror(struct nfs_pageio_descriptor *desc, | ||
| 1187 | u32 mirror_idx) | ||
| 1188 | { | ||
| 1189 | struct nfs_pgio_mirror *mirror = &desc->pg_mirrors[mirror_idx]; | ||
| 1190 | u32 restore_idx = desc->pg_mirror_idx; | ||
| 1191 | |||
| 1192 | if (nfs_pgio_has_mirroring(desc)) | ||
| 1193 | desc->pg_mirror_idx = mirror_idx; | ||
| 1194 | for (;;) { | ||
| 1195 | nfs_pageio_doio(desc); | ||
| 1196 | if (!mirror->pg_recoalesce) | ||
| 1197 | break; | ||
| 1198 | if (!nfs_do_recoalesce(desc)) | ||
| 1199 | break; | ||
| 1200 | } | ||
| 1201 | desc->pg_mirror_idx = restore_idx; | ||
| 1202 | } | ||
| 1203 | |||
| 1016 | /* | 1204 | /* |
| 1017 | * nfs_pageio_resend - Transfer requests to new descriptor and resend | 1205 | * nfs_pageio_resend - Transfer requests to new descriptor and resend |
| 1018 | * @hdr - the pgio header to move request from | 1206 | * @hdr - the pgio header to move request from |
| @@ -1046,18 +1234,19 @@ int nfs_pageio_resend(struct nfs_pageio_descriptor *desc, | |||
| 1046 | EXPORT_SYMBOL_GPL(nfs_pageio_resend); | 1234 | EXPORT_SYMBOL_GPL(nfs_pageio_resend); |
| 1047 | 1235 | ||
| 1048 | /** | 1236 | /** |
| 1049 | * nfs_pageio_complete - Complete I/O on an nfs_pageio_descriptor | 1237 | * nfs_pageio_complete - Complete I/O then cleanup an nfs_pageio_descriptor |
| 1050 | * @desc: pointer to io descriptor | 1238 | * @desc: pointer to io descriptor |
| 1051 | */ | 1239 | */ |
| 1052 | void nfs_pageio_complete(struct nfs_pageio_descriptor *desc) | 1240 | void nfs_pageio_complete(struct nfs_pageio_descriptor *desc) |
| 1053 | { | 1241 | { |
| 1054 | for (;;) { | 1242 | u32 midx; |
| 1055 | nfs_pageio_doio(desc); | 1243 | |
| 1056 | if (!desc->pg_recoalesce) | 1244 | for (midx = 0; midx < desc->pg_mirror_count; midx++) |
| 1057 | break; | 1245 | nfs_pageio_complete_mirror(desc, midx); |
| 1058 | if (!nfs_do_recoalesce(desc)) | 1246 | |
| 1059 | break; | 1247 | if (desc->pg_ops->pg_cleanup) |
| 1060 | } | 1248 | desc->pg_ops->pg_cleanup(desc); |
| 1249 | nfs_pageio_cleanup_mirroring(desc); | ||
| 1061 | } | 1250 | } |
| 1062 | 1251 | ||
| 1063 | /** | 1252 | /** |
| @@ -1073,10 +1262,17 @@ void nfs_pageio_complete(struct nfs_pageio_descriptor *desc) | |||
| 1073 | */ | 1262 | */ |
| 1074 | void nfs_pageio_cond_complete(struct nfs_pageio_descriptor *desc, pgoff_t index) | 1263 | void nfs_pageio_cond_complete(struct nfs_pageio_descriptor *desc, pgoff_t index) |
| 1075 | { | 1264 | { |
| 1076 | if (!list_empty(&desc->pg_list)) { | 1265 | struct nfs_pgio_mirror *mirror; |
| 1077 | struct nfs_page *prev = nfs_list_entry(desc->pg_list.prev); | 1266 | struct nfs_page *prev; |
| 1078 | if (index != prev->wb_index + 1) | 1267 | u32 midx; |
| 1079 | nfs_pageio_complete(desc); | 1268 | |
| 1269 | for (midx = 0; midx < desc->pg_mirror_count; midx++) { | ||
| 1270 | mirror = &desc->pg_mirrors[midx]; | ||
| 1271 | if (!list_empty(&mirror->pg_list)) { | ||
| 1272 | prev = nfs_list_entry(mirror->pg_list.prev); | ||
| 1273 | if (index != prev->wb_index + 1) | ||
| 1274 | nfs_pageio_complete_mirror(desc, midx); | ||
| 1275 | } | ||
| 1080 | } | 1276 | } |
| 1081 | } | 1277 | } |
| 1082 | 1278 | ||
diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c index 4d69076a6028..703501d3ed19 100644 --- a/fs/nfs/pnfs.c +++ b/fs/nfs/pnfs.c | |||
| @@ -51,6 +51,10 @@ static DEFINE_SPINLOCK(pnfs_spinlock); | |||
| 51 | */ | 51 | */ |
| 52 | static LIST_HEAD(pnfs_modules_tbl); | 52 | static LIST_HEAD(pnfs_modules_tbl); |
| 53 | 53 | ||
| 54 | static int | ||
| 55 | pnfs_send_layoutreturn(struct pnfs_layout_hdr *lo, nfs4_stateid stateid, | ||
| 56 | enum pnfs_iomode iomode, bool sync); | ||
| 57 | |||
| 54 | /* Return the registered pnfs layout driver module matching given id */ | 58 | /* Return the registered pnfs layout driver module matching given id */ |
| 55 | static struct pnfs_layoutdriver_type * | 59 | static struct pnfs_layoutdriver_type * |
| 56 | find_pnfs_driver_locked(u32 id) | 60 | find_pnfs_driver_locked(u32 id) |
| @@ -239,6 +243,8 @@ pnfs_put_layout_hdr(struct pnfs_layout_hdr *lo) | |||
| 239 | struct inode *inode = lo->plh_inode; | 243 | struct inode *inode = lo->plh_inode; |
| 240 | 244 | ||
| 241 | if (atomic_dec_and_lock(&lo->plh_refcount, &inode->i_lock)) { | 245 | if (atomic_dec_and_lock(&lo->plh_refcount, &inode->i_lock)) { |
| 246 | if (!list_empty(&lo->plh_segs)) | ||
| 247 | WARN_ONCE(1, "NFS: BUG unfreed layout segments.\n"); | ||
| 242 | pnfs_detach_layout_hdr(lo); | 248 | pnfs_detach_layout_hdr(lo); |
| 243 | spin_unlock(&inode->i_lock); | 249 | spin_unlock(&inode->i_lock); |
| 244 | pnfs_free_layout_hdr(lo); | 250 | pnfs_free_layout_hdr(lo); |
| @@ -338,6 +344,65 @@ pnfs_layout_remove_lseg(struct pnfs_layout_hdr *lo, | |||
| 338 | rpc_wake_up(&NFS_SERVER(inode)->roc_rpcwaitq); | 344 | rpc_wake_up(&NFS_SERVER(inode)->roc_rpcwaitq); |
| 339 | } | 345 | } |
| 340 | 346 | ||
| 347 | /* Return true if layoutreturn is needed */ | ||
| 348 | static bool | ||
| 349 | pnfs_layout_need_return(struct pnfs_layout_hdr *lo, | ||
| 350 | struct pnfs_layout_segment *lseg) | ||
| 351 | { | ||
| 352 | struct pnfs_layout_segment *s; | ||
| 353 | |||
| 354 | if (!test_bit(NFS_LSEG_LAYOUTRETURN, &lseg->pls_flags)) | ||
| 355 | return false; | ||
| 356 | |||
| 357 | list_for_each_entry(s, &lo->plh_segs, pls_list) | ||
| 358 | if (s != lseg && test_bit(NFS_LSEG_LAYOUTRETURN, &s->pls_flags)) | ||
| 359 | return false; | ||
| 360 | |||
| 361 | return true; | ||
| 362 | } | ||
| 363 | |||
| 364 | static void pnfs_layoutreturn_free_lseg(struct work_struct *work) | ||
| 365 | { | ||
| 366 | struct pnfs_layout_segment *lseg; | ||
| 367 | struct pnfs_layout_hdr *lo; | ||
| 368 | struct inode *inode; | ||
| 369 | |||
| 370 | lseg = container_of(work, struct pnfs_layout_segment, pls_work); | ||
| 371 | WARN_ON(atomic_read(&lseg->pls_refcount)); | ||
| 372 | lo = lseg->pls_layout; | ||
| 373 | inode = lo->plh_inode; | ||
| 374 | |||
| 375 | spin_lock(&inode->i_lock); | ||
| 376 | if (pnfs_layout_need_return(lo, lseg)) { | ||
| 377 | nfs4_stateid stateid; | ||
| 378 | enum pnfs_iomode iomode; | ||
| 379 | |||
| 380 | stateid = lo->plh_stateid; | ||
| 381 | iomode = lo->plh_return_iomode; | ||
| 382 | /* decreased in pnfs_send_layoutreturn() */ | ||
| 383 | lo->plh_block_lgets++; | ||
| 384 | lo->plh_return_iomode = 0; | ||
| 385 | spin_unlock(&inode->i_lock); | ||
| 386 | |||
| 387 | pnfs_send_layoutreturn(lo, stateid, iomode, true); | ||
| 388 | spin_lock(&inode->i_lock); | ||
| 389 | } else | ||
| 390 | /* match pnfs_get_layout_hdr #2 in pnfs_put_lseg */ | ||
| 391 | pnfs_put_layout_hdr(lo); | ||
| 392 | pnfs_layout_remove_lseg(lo, lseg); | ||
| 393 | spin_unlock(&inode->i_lock); | ||
| 394 | pnfs_free_lseg(lseg); | ||
| 395 | /* match pnfs_get_layout_hdr #1 in pnfs_put_lseg */ | ||
| 396 | pnfs_put_layout_hdr(lo); | ||
| 397 | } | ||
| 398 | |||
| 399 | static void | ||
| 400 | pnfs_layoutreturn_free_lseg_async(struct pnfs_layout_segment *lseg) | ||
| 401 | { | ||
| 402 | INIT_WORK(&lseg->pls_work, pnfs_layoutreturn_free_lseg); | ||
| 403 | queue_work(nfsiod_workqueue, &lseg->pls_work); | ||
| 404 | } | ||
| 405 | |||
| 341 | void | 406 | void |
| 342 | pnfs_put_lseg(struct pnfs_layout_segment *lseg) | 407 | pnfs_put_lseg(struct pnfs_layout_segment *lseg) |
| 343 | { | 408 | { |
| @@ -354,10 +419,17 @@ pnfs_put_lseg(struct pnfs_layout_segment *lseg) | |||
| 354 | inode = lo->plh_inode; | 419 | inode = lo->plh_inode; |
| 355 | if (atomic_dec_and_lock(&lseg->pls_refcount, &inode->i_lock)) { | 420 | if (atomic_dec_and_lock(&lseg->pls_refcount, &inode->i_lock)) { |
| 356 | pnfs_get_layout_hdr(lo); | 421 | pnfs_get_layout_hdr(lo); |
| 357 | pnfs_layout_remove_lseg(lo, lseg); | 422 | if (pnfs_layout_need_return(lo, lseg)) { |
| 358 | spin_unlock(&inode->i_lock); | 423 | spin_unlock(&inode->i_lock); |
| 359 | pnfs_free_lseg(lseg); | 424 | /* hdr reference dropped in nfs4_layoutreturn_release */ |
| 360 | pnfs_put_layout_hdr(lo); | 425 | pnfs_get_layout_hdr(lo); |
| 426 | pnfs_layoutreturn_free_lseg_async(lseg); | ||
| 427 | } else { | ||
| 428 | pnfs_layout_remove_lseg(lo, lseg); | ||
| 429 | spin_unlock(&inode->i_lock); | ||
| 430 | pnfs_free_lseg(lseg); | ||
| 431 | pnfs_put_layout_hdr(lo); | ||
| 432 | } | ||
| 361 | } | 433 | } |
| 362 | } | 434 | } |
| 363 | EXPORT_SYMBOL_GPL(pnfs_put_lseg); | 435 | EXPORT_SYMBOL_GPL(pnfs_put_lseg); |
| @@ -544,6 +616,7 @@ pnfs_destroy_layout(struct nfs_inode *nfsi) | |||
| 544 | pnfs_get_layout_hdr(lo); | 616 | pnfs_get_layout_hdr(lo); |
| 545 | pnfs_layout_clear_fail_bit(lo, NFS_LAYOUT_RO_FAILED); | 617 | pnfs_layout_clear_fail_bit(lo, NFS_LAYOUT_RO_FAILED); |
| 546 | pnfs_layout_clear_fail_bit(lo, NFS_LAYOUT_RW_FAILED); | 618 | pnfs_layout_clear_fail_bit(lo, NFS_LAYOUT_RW_FAILED); |
| 619 | pnfs_clear_retry_layoutget(lo); | ||
| 547 | spin_unlock(&nfsi->vfs_inode.i_lock); | 620 | spin_unlock(&nfsi->vfs_inode.i_lock); |
| 548 | pnfs_free_lseg_list(&tmp_list); | 621 | pnfs_free_lseg_list(&tmp_list); |
| 549 | pnfs_put_layout_hdr(lo); | 622 | pnfs_put_layout_hdr(lo); |
| @@ -741,25 +814,37 @@ pnfs_layout_stateid_blocked(const struct pnfs_layout_hdr *lo, | |||
| 741 | return !pnfs_seqid_is_newer(seqid, lo->plh_barrier); | 814 | return !pnfs_seqid_is_newer(seqid, lo->plh_barrier); |
| 742 | } | 815 | } |
| 743 | 816 | ||
| 817 | static bool | ||
| 818 | pnfs_layout_returning(const struct pnfs_layout_hdr *lo, | ||
| 819 | struct pnfs_layout_range *range) | ||
| 820 | { | ||
| 821 | return test_bit(NFS_LAYOUT_RETURN, &lo->plh_flags) && | ||
| 822 | (lo->plh_return_iomode == IOMODE_ANY || | ||
| 823 | lo->plh_return_iomode == range->iomode); | ||
| 824 | } | ||
| 825 | |||
| 744 | /* lget is set to 1 if called from inside send_layoutget call chain */ | 826 | /* lget is set to 1 if called from inside send_layoutget call chain */ |
| 745 | static bool | 827 | static bool |
| 746 | pnfs_layoutgets_blocked(const struct pnfs_layout_hdr *lo, int lget) | 828 | pnfs_layoutgets_blocked(const struct pnfs_layout_hdr *lo, |
| 829 | struct pnfs_layout_range *range, int lget) | ||
| 747 | { | 830 | { |
| 748 | return lo->plh_block_lgets || | 831 | return lo->plh_block_lgets || |
| 749 | test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags) || | 832 | test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags) || |
| 750 | (list_empty(&lo->plh_segs) && | 833 | (list_empty(&lo->plh_segs) && |
| 751 | (atomic_read(&lo->plh_outstanding) > lget)); | 834 | (atomic_read(&lo->plh_outstanding) > lget)) || |
| 835 | pnfs_layout_returning(lo, range); | ||
| 752 | } | 836 | } |
| 753 | 837 | ||
| 754 | int | 838 | int |
| 755 | pnfs_choose_layoutget_stateid(nfs4_stateid *dst, struct pnfs_layout_hdr *lo, | 839 | pnfs_choose_layoutget_stateid(nfs4_stateid *dst, struct pnfs_layout_hdr *lo, |
| 840 | struct pnfs_layout_range *range, | ||
| 756 | struct nfs4_state *open_state) | 841 | struct nfs4_state *open_state) |
| 757 | { | 842 | { |
| 758 | int status = 0; | 843 | int status = 0; |
| 759 | 844 | ||
| 760 | dprintk("--> %s\n", __func__); | 845 | dprintk("--> %s\n", __func__); |
| 761 | spin_lock(&lo->plh_inode->i_lock); | 846 | spin_lock(&lo->plh_inode->i_lock); |
| 762 | if (pnfs_layoutgets_blocked(lo, 1)) { | 847 | if (pnfs_layoutgets_blocked(lo, range, 1)) { |
| 763 | status = -EAGAIN; | 848 | status = -EAGAIN; |
| 764 | } else if (!nfs4_valid_open_stateid(open_state)) { | 849 | } else if (!nfs4_valid_open_stateid(open_state)) { |
| 765 | status = -EBADF; | 850 | status = -EBADF; |
| @@ -826,7 +911,9 @@ send_layoutget(struct pnfs_layout_hdr *lo, | |||
| 826 | pnfs_layout_io_set_failed(lo, range->iomode); | 911 | pnfs_layout_io_set_failed(lo, range->iomode); |
| 827 | } | 912 | } |
| 828 | return NULL; | 913 | return NULL; |
| 829 | } | 914 | } else |
| 915 | pnfs_layout_clear_fail_bit(lo, | ||
| 916 | pnfs_iomode_to_fail_bit(range->iomode)); | ||
| 830 | 917 | ||
| 831 | return lseg; | 918 | return lseg; |
| 832 | } | 919 | } |
| @@ -846,6 +933,49 @@ static void pnfs_clear_layoutcommit(struct inode *inode, | |||
| 846 | } | 933 | } |
| 847 | } | 934 | } |
| 848 | 935 | ||
| 936 | void pnfs_clear_layoutreturn_waitbit(struct pnfs_layout_hdr *lo) | ||
| 937 | { | ||
| 938 | clear_bit_unlock(NFS_LAYOUT_RETURN, &lo->plh_flags); | ||
| 939 | smp_mb__after_atomic(); | ||
| 940 | wake_up_bit(&lo->plh_flags, NFS_LAYOUT_RETURN); | ||
| 941 | } | ||
| 942 | |||
| 943 | static int | ||
| 944 | pnfs_send_layoutreturn(struct pnfs_layout_hdr *lo, nfs4_stateid stateid, | ||
| 945 | enum pnfs_iomode iomode, bool sync) | ||
| 946 | { | ||
| 947 | struct inode *ino = lo->plh_inode; | ||
| 948 | struct nfs4_layoutreturn *lrp; | ||
| 949 | int status = 0; | ||
| 950 | |||
| 951 | lrp = kzalloc(sizeof(*lrp), GFP_KERNEL); | ||
| 952 | if (unlikely(lrp == NULL)) { | ||
| 953 | status = -ENOMEM; | ||
| 954 | spin_lock(&ino->i_lock); | ||
| 955 | lo->plh_block_lgets--; | ||
| 956 | pnfs_clear_layoutreturn_waitbit(lo); | ||
| 957 | rpc_wake_up(&NFS_SERVER(ino)->roc_rpcwaitq); | ||
| 958 | spin_unlock(&ino->i_lock); | ||
| 959 | pnfs_put_layout_hdr(lo); | ||
| 960 | goto out; | ||
| 961 | } | ||
| 962 | |||
| 963 | lrp->args.stateid = stateid; | ||
| 964 | lrp->args.layout_type = NFS_SERVER(ino)->pnfs_curr_ld->id; | ||
| 965 | lrp->args.inode = ino; | ||
| 966 | lrp->args.range.iomode = iomode; | ||
| 967 | lrp->args.range.offset = 0; | ||
| 968 | lrp->args.range.length = NFS4_MAX_UINT64; | ||
| 969 | lrp->args.layout = lo; | ||
| 970 | lrp->clp = NFS_SERVER(ino)->nfs_client; | ||
| 971 | lrp->cred = lo->plh_lc_cred; | ||
| 972 | |||
| 973 | status = nfs4_proc_layoutreturn(lrp, sync); | ||
| 974 | out: | ||
| 975 | dprintk("<-- %s status: %d\n", __func__, status); | ||
| 976 | return status; | ||
| 977 | } | ||
| 978 | |||
| 849 | /* | 979 | /* |
| 850 | * Initiates a LAYOUTRETURN(FILE), and removes the pnfs_layout_hdr | 980 | * Initiates a LAYOUTRETURN(FILE), and removes the pnfs_layout_hdr |
| 851 | * when the layout segment list is empty. | 981 | * when the layout segment list is empty. |
| @@ -860,7 +990,6 @@ _pnfs_return_layout(struct inode *ino) | |||
| 860 | struct pnfs_layout_hdr *lo = NULL; | 990 | struct pnfs_layout_hdr *lo = NULL; |
| 861 | struct nfs_inode *nfsi = NFS_I(ino); | 991 | struct nfs_inode *nfsi = NFS_I(ino); |
| 862 | LIST_HEAD(tmp_list); | 992 | LIST_HEAD(tmp_list); |
| 863 | struct nfs4_layoutreturn *lrp; | ||
| 864 | nfs4_stateid stateid; | 993 | nfs4_stateid stateid; |
| 865 | int status = 0, empty; | 994 | int status = 0, empty; |
| 866 | 995 | ||
| @@ -902,24 +1031,7 @@ _pnfs_return_layout(struct inode *ino) | |||
| 902 | spin_unlock(&ino->i_lock); | 1031 | spin_unlock(&ino->i_lock); |
| 903 | pnfs_free_lseg_list(&tmp_list); | 1032 | pnfs_free_lseg_list(&tmp_list); |
| 904 | 1033 | ||
| 905 | lrp = kzalloc(sizeof(*lrp), GFP_KERNEL); | 1034 | status = pnfs_send_layoutreturn(lo, stateid, IOMODE_ANY, true); |
| 906 | if (unlikely(lrp == NULL)) { | ||
| 907 | status = -ENOMEM; | ||
| 908 | spin_lock(&ino->i_lock); | ||
| 909 | lo->plh_block_lgets--; | ||
| 910 | spin_unlock(&ino->i_lock); | ||
| 911 | pnfs_put_layout_hdr(lo); | ||
| 912 | goto out; | ||
| 913 | } | ||
| 914 | |||
| 915 | lrp->args.stateid = stateid; | ||
| 916 | lrp->args.layout_type = NFS_SERVER(ino)->pnfs_curr_ld->id; | ||
| 917 | lrp->args.inode = ino; | ||
| 918 | lrp->args.layout = lo; | ||
| 919 | lrp->clp = NFS_SERVER(ino)->nfs_client; | ||
| 920 | lrp->cred = lo->plh_lc_cred; | ||
| 921 | |||
| 922 | status = nfs4_proc_layoutreturn(lrp); | ||
| 923 | out: | 1035 | out: |
| 924 | dprintk("<-- %s status: %d\n", __func__, status); | 1036 | dprintk("<-- %s status: %d\n", __func__, status); |
| 925 | return status; | 1037 | return status; |
| @@ -960,8 +1072,9 @@ bool pnfs_roc(struct inode *ino) | |||
| 960 | struct nfs4_state *state; | 1072 | struct nfs4_state *state; |
| 961 | struct pnfs_layout_hdr *lo; | 1073 | struct pnfs_layout_hdr *lo; |
| 962 | struct pnfs_layout_segment *lseg, *tmp; | 1074 | struct pnfs_layout_segment *lseg, *tmp; |
| 1075 | nfs4_stateid stateid; | ||
| 963 | LIST_HEAD(tmp_list); | 1076 | LIST_HEAD(tmp_list); |
| 964 | bool found = false; | 1077 | bool found = false, layoutreturn = false; |
| 965 | 1078 | ||
| 966 | spin_lock(&ino->i_lock); | 1079 | spin_lock(&ino->i_lock); |
| 967 | lo = nfsi->layout; | 1080 | lo = nfsi->layout; |
| @@ -980,6 +1093,8 @@ bool pnfs_roc(struct inode *ino) | |||
| 980 | goto out_noroc; | 1093 | goto out_noroc; |
| 981 | } | 1094 | } |
| 982 | 1095 | ||
| 1096 | goto out_noroc; | ||
| 1097 | pnfs_clear_retry_layoutget(lo); | ||
| 983 | list_for_each_entry_safe(lseg, tmp, &lo->plh_segs, pls_list) | 1098 | list_for_each_entry_safe(lseg, tmp, &lo->plh_segs, pls_list) |
| 984 | if (test_bit(NFS_LSEG_ROC, &lseg->pls_flags)) { | 1099 | if (test_bit(NFS_LSEG_ROC, &lseg->pls_flags)) { |
| 985 | mark_lseg_invalid(lseg, &tmp_list); | 1100 | mark_lseg_invalid(lseg, &tmp_list); |
| @@ -994,7 +1109,19 @@ bool pnfs_roc(struct inode *ino) | |||
| 994 | return true; | 1109 | return true; |
| 995 | 1110 | ||
| 996 | out_noroc: | 1111 | out_noroc: |
| 1112 | if (lo) { | ||
| 1113 | stateid = lo->plh_stateid; | ||
| 1114 | layoutreturn = | ||
| 1115 | test_and_clear_bit(NFS_LAYOUT_RETURN_BEFORE_CLOSE, | ||
| 1116 | &lo->plh_flags); | ||
| 1117 | if (layoutreturn) { | ||
| 1118 | lo->plh_block_lgets++; | ||
| 1119 | pnfs_get_layout_hdr(lo); | ||
| 1120 | } | ||
| 1121 | } | ||
| 997 | spin_unlock(&ino->i_lock); | 1122 | spin_unlock(&ino->i_lock); |
| 1123 | if (layoutreturn) | ||
| 1124 | pnfs_send_layoutreturn(lo, stateid, IOMODE_ANY, true); | ||
| 998 | return false; | 1125 | return false; |
| 999 | } | 1126 | } |
| 1000 | 1127 | ||
| @@ -1029,8 +1156,9 @@ bool pnfs_roc_drain(struct inode *ino, u32 *barrier, struct rpc_task *task) | |||
| 1029 | struct nfs_inode *nfsi = NFS_I(ino); | 1156 | struct nfs_inode *nfsi = NFS_I(ino); |
| 1030 | struct pnfs_layout_hdr *lo; | 1157 | struct pnfs_layout_hdr *lo; |
| 1031 | struct pnfs_layout_segment *lseg; | 1158 | struct pnfs_layout_segment *lseg; |
| 1159 | nfs4_stateid stateid; | ||
| 1032 | u32 current_seqid; | 1160 | u32 current_seqid; |
| 1033 | bool found = false; | 1161 | bool found = false, layoutreturn = false; |
| 1034 | 1162 | ||
| 1035 | spin_lock(&ino->i_lock); | 1163 | spin_lock(&ino->i_lock); |
| 1036 | list_for_each_entry(lseg, &nfsi->layout->plh_segs, pls_list) | 1164 | list_for_each_entry(lseg, &nfsi->layout->plh_segs, pls_list) |
| @@ -1047,7 +1175,21 @@ bool pnfs_roc_drain(struct inode *ino, u32 *barrier, struct rpc_task *task) | |||
| 1047 | */ | 1175 | */ |
| 1048 | *barrier = current_seqid + atomic_read(&lo->plh_outstanding); | 1176 | *barrier = current_seqid + atomic_read(&lo->plh_outstanding); |
| 1049 | out: | 1177 | out: |
| 1178 | if (!found) { | ||
| 1179 | stateid = lo->plh_stateid; | ||
| 1180 | layoutreturn = | ||
| 1181 | test_and_clear_bit(NFS_LAYOUT_RETURN_BEFORE_CLOSE, | ||
| 1182 | &lo->plh_flags); | ||
| 1183 | if (layoutreturn) { | ||
| 1184 | lo->plh_block_lgets++; | ||
| 1185 | pnfs_get_layout_hdr(lo); | ||
| 1186 | } | ||
| 1187 | } | ||
| 1050 | spin_unlock(&ino->i_lock); | 1188 | spin_unlock(&ino->i_lock); |
| 1189 | if (layoutreturn) { | ||
| 1190 | rpc_sleep_on(&NFS_SERVER(ino)->roc_rpcwaitq, task, NULL); | ||
| 1191 | pnfs_send_layoutreturn(lo, stateid, IOMODE_ANY, false); | ||
| 1192 | } | ||
| 1051 | return found; | 1193 | return found; |
| 1052 | } | 1194 | } |
| 1053 | 1195 | ||
| @@ -1194,6 +1336,7 @@ pnfs_find_lseg(struct pnfs_layout_hdr *lo, | |||
| 1194 | 1336 | ||
| 1195 | list_for_each_entry(lseg, &lo->plh_segs, pls_list) { | 1337 | list_for_each_entry(lseg, &lo->plh_segs, pls_list) { |
| 1196 | if (test_bit(NFS_LSEG_VALID, &lseg->pls_flags) && | 1338 | if (test_bit(NFS_LSEG_VALID, &lseg->pls_flags) && |
| 1339 | !test_bit(NFS_LSEG_LAYOUTRETURN, &lseg->pls_flags) && | ||
| 1197 | pnfs_lseg_range_match(&lseg->pls_range, range)) { | 1340 | pnfs_lseg_range_match(&lseg->pls_range, range)) { |
| 1198 | ret = pnfs_get_lseg(lseg); | 1341 | ret = pnfs_get_lseg(lseg); |
| 1199 | break; | 1342 | break; |
| @@ -1282,6 +1425,35 @@ static bool pnfs_within_mdsthreshold(struct nfs_open_context *ctx, | |||
| 1282 | return ret; | 1425 | return ret; |
| 1283 | } | 1426 | } |
| 1284 | 1427 | ||
| 1428 | /* stop waiting if someone clears NFS_LAYOUT_RETRY_LAYOUTGET bit. */ | ||
| 1429 | static int pnfs_layoutget_retry_bit_wait(struct wait_bit_key *key) | ||
| 1430 | { | ||
| 1431 | if (!test_bit(NFS_LAYOUT_RETRY_LAYOUTGET, key->flags)) | ||
| 1432 | return 1; | ||
| 1433 | return nfs_wait_bit_killable(key); | ||
| 1434 | } | ||
| 1435 | |||
| 1436 | static bool pnfs_prepare_to_retry_layoutget(struct pnfs_layout_hdr *lo) | ||
| 1437 | { | ||
| 1438 | /* | ||
| 1439 | * send layoutcommit as it can hold up layoutreturn due to lseg | ||
| 1440 | * reference | ||
| 1441 | */ | ||
| 1442 | pnfs_layoutcommit_inode(lo->plh_inode, false); | ||
| 1443 | return !wait_on_bit_action(&lo->plh_flags, NFS_LAYOUT_RETURN, | ||
| 1444 | pnfs_layoutget_retry_bit_wait, | ||
| 1445 | TASK_UNINTERRUPTIBLE); | ||
| 1446 | } | ||
| 1447 | |||
| 1448 | static void pnfs_clear_first_layoutget(struct pnfs_layout_hdr *lo) | ||
| 1449 | { | ||
| 1450 | unsigned long *bitlock = &lo->plh_flags; | ||
| 1451 | |||
| 1452 | clear_bit_unlock(NFS_LAYOUT_FIRST_LAYOUTGET, bitlock); | ||
| 1453 | smp_mb__after_atomic(); | ||
| 1454 | wake_up_bit(bitlock, NFS_LAYOUT_FIRST_LAYOUTGET); | ||
| 1455 | } | ||
| 1456 | |||
| 1285 | /* | 1457 | /* |
| 1286 | * Layout segment is retreived from the server if not cached. | 1458 | * Layout segment is retreived from the server if not cached. |
| 1287 | * The appropriate layout segment is referenced and returned to the caller. | 1459 | * The appropriate layout segment is referenced and returned to the caller. |
| @@ -1312,6 +1484,8 @@ pnfs_update_layout(struct inode *ino, | |||
| 1312 | if (pnfs_within_mdsthreshold(ctx, ino, iomode)) | 1484 | if (pnfs_within_mdsthreshold(ctx, ino, iomode)) |
| 1313 | goto out; | 1485 | goto out; |
| 1314 | 1486 | ||
| 1487 | lookup_again: | ||
| 1488 | first = false; | ||
| 1315 | spin_lock(&ino->i_lock); | 1489 | spin_lock(&ino->i_lock); |
| 1316 | lo = pnfs_find_alloc_layout(ino, ctx, gfp_flags); | 1490 | lo = pnfs_find_alloc_layout(ino, ctx, gfp_flags); |
| 1317 | if (lo == NULL) { | 1491 | if (lo == NULL) { |
| @@ -1326,27 +1500,62 @@ pnfs_update_layout(struct inode *ino, | |||
| 1326 | } | 1500 | } |
| 1327 | 1501 | ||
| 1328 | /* if LAYOUTGET already failed once we don't try again */ | 1502 | /* if LAYOUTGET already failed once we don't try again */ |
| 1329 | if (pnfs_layout_io_test_failed(lo, iomode)) | 1503 | if (pnfs_layout_io_test_failed(lo, iomode) && |
| 1504 | !pnfs_should_retry_layoutget(lo)) | ||
| 1330 | goto out_unlock; | 1505 | goto out_unlock; |
| 1331 | 1506 | ||
| 1332 | /* Check to see if the layout for the given range already exists */ | 1507 | first = list_empty(&lo->plh_segs); |
| 1333 | lseg = pnfs_find_lseg(lo, &arg); | 1508 | if (first) { |
| 1334 | if (lseg) | 1509 | /* The first layoutget for the file. Need to serialize per |
| 1335 | goto out_unlock; | 1510 | * RFC 5661 Errata 3208. |
| 1511 | */ | ||
| 1512 | if (test_and_set_bit(NFS_LAYOUT_FIRST_LAYOUTGET, | ||
| 1513 | &lo->plh_flags)) { | ||
| 1514 | spin_unlock(&ino->i_lock); | ||
| 1515 | wait_on_bit(&lo->plh_flags, NFS_LAYOUT_FIRST_LAYOUTGET, | ||
| 1516 | TASK_UNINTERRUPTIBLE); | ||
| 1517 | pnfs_put_layout_hdr(lo); | ||
| 1518 | goto lookup_again; | ||
| 1519 | } | ||
| 1520 | } else { | ||
| 1521 | /* Check to see if the layout for the given range | ||
| 1522 | * already exists | ||
| 1523 | */ | ||
| 1524 | lseg = pnfs_find_lseg(lo, &arg); | ||
| 1525 | if (lseg) | ||
| 1526 | goto out_unlock; | ||
| 1527 | } | ||
| 1336 | 1528 | ||
| 1337 | if (pnfs_layoutgets_blocked(lo, 0)) | 1529 | /* |
| 1530 | * Because we free lsegs before sending LAYOUTRETURN, we need to wait | ||
| 1531 | * for LAYOUTRETURN even if first is true. | ||
| 1532 | */ | ||
| 1533 | if (!lseg && pnfs_should_retry_layoutget(lo) && | ||
| 1534 | test_bit(NFS_LAYOUT_RETURN, &lo->plh_flags)) { | ||
| 1535 | spin_unlock(&ino->i_lock); | ||
| 1536 | dprintk("%s wait for layoutreturn\n", __func__); | ||
| 1537 | if (pnfs_prepare_to_retry_layoutget(lo)) { | ||
| 1538 | if (first) | ||
| 1539 | pnfs_clear_first_layoutget(lo); | ||
| 1540 | pnfs_put_layout_hdr(lo); | ||
| 1541 | dprintk("%s retrying\n", __func__); | ||
| 1542 | goto lookup_again; | ||
| 1543 | } | ||
| 1544 | goto out_put_layout_hdr; | ||
| 1545 | } | ||
| 1546 | |||
| 1547 | if (pnfs_layoutgets_blocked(lo, &arg, 0)) | ||
| 1338 | goto out_unlock; | 1548 | goto out_unlock; |
| 1339 | atomic_inc(&lo->plh_outstanding); | 1549 | atomic_inc(&lo->plh_outstanding); |
| 1340 | |||
| 1341 | first = list_empty(&lo->plh_layouts) ? true : false; | ||
| 1342 | spin_unlock(&ino->i_lock); | 1550 | spin_unlock(&ino->i_lock); |
| 1343 | 1551 | ||
| 1344 | if (first) { | 1552 | if (list_empty(&lo->plh_layouts)) { |
| 1345 | /* The lo must be on the clp list if there is any | 1553 | /* The lo must be on the clp list if there is any |
| 1346 | * chance of a CB_LAYOUTRECALL(FILE) coming in. | 1554 | * chance of a CB_LAYOUTRECALL(FILE) coming in. |
| 1347 | */ | 1555 | */ |
| 1348 | spin_lock(&clp->cl_lock); | 1556 | spin_lock(&clp->cl_lock); |
| 1349 | list_add_tail(&lo->plh_layouts, &server->layouts); | 1557 | if (list_empty(&lo->plh_layouts)) |
| 1558 | list_add_tail(&lo->plh_layouts, &server->layouts); | ||
| 1350 | spin_unlock(&clp->cl_lock); | 1559 | spin_unlock(&clp->cl_lock); |
| 1351 | } | 1560 | } |
| 1352 | 1561 | ||
| @@ -1359,8 +1568,11 @@ pnfs_update_layout(struct inode *ino, | |||
| 1359 | arg.length = PAGE_CACHE_ALIGN(arg.length); | 1568 | arg.length = PAGE_CACHE_ALIGN(arg.length); |
| 1360 | 1569 | ||
| 1361 | lseg = send_layoutget(lo, ctx, &arg, gfp_flags); | 1570 | lseg = send_layoutget(lo, ctx, &arg, gfp_flags); |
| 1571 | pnfs_clear_retry_layoutget(lo); | ||
| 1362 | atomic_dec(&lo->plh_outstanding); | 1572 | atomic_dec(&lo->plh_outstanding); |
| 1363 | out_put_layout_hdr: | 1573 | out_put_layout_hdr: |
| 1574 | if (first) | ||
| 1575 | pnfs_clear_first_layoutget(lo); | ||
| 1364 | pnfs_put_layout_hdr(lo); | 1576 | pnfs_put_layout_hdr(lo); |
| 1365 | out: | 1577 | out: |
| 1366 | dprintk("%s: inode %s/%llu pNFS layout segment %s for " | 1578 | dprintk("%s: inode %s/%llu pNFS layout segment %s for " |
| @@ -1409,7 +1621,7 @@ pnfs_layout_process(struct nfs4_layoutget *lgp) | |||
| 1409 | goto out_forget_reply; | 1621 | goto out_forget_reply; |
| 1410 | } | 1622 | } |
| 1411 | 1623 | ||
| 1412 | if (pnfs_layoutgets_blocked(lo, 1)) { | 1624 | if (pnfs_layoutgets_blocked(lo, &lgp->args.range, 1)) { |
| 1413 | dprintk("%s forget reply due to state\n", __func__); | 1625 | dprintk("%s forget reply due to state\n", __func__); |
| 1414 | goto out_forget_reply; | 1626 | goto out_forget_reply; |
| 1415 | } | 1627 | } |
| @@ -1456,24 +1668,79 @@ out_forget_reply: | |||
| 1456 | goto out; | 1668 | goto out; |
| 1457 | } | 1669 | } |
| 1458 | 1670 | ||
| 1671 | static void | ||
| 1672 | pnfs_mark_matching_lsegs_return(struct pnfs_layout_hdr *lo, | ||
| 1673 | struct list_head *tmp_list, | ||
| 1674 | struct pnfs_layout_range *return_range) | ||
| 1675 | { | ||
| 1676 | struct pnfs_layout_segment *lseg, *next; | ||
| 1677 | |||
| 1678 | dprintk("%s:Begin lo %p\n", __func__, lo); | ||
| 1679 | |||
| 1680 | if (list_empty(&lo->plh_segs)) | ||
| 1681 | return; | ||
| 1682 | |||
| 1683 | list_for_each_entry_safe(lseg, next, &lo->plh_segs, pls_list) | ||
| 1684 | if (should_free_lseg(&lseg->pls_range, return_range)) { | ||
| 1685 | dprintk("%s: marking lseg %p iomode %d " | ||
| 1686 | "offset %llu length %llu\n", __func__, | ||
| 1687 | lseg, lseg->pls_range.iomode, | ||
| 1688 | lseg->pls_range.offset, | ||
| 1689 | lseg->pls_range.length); | ||
| 1690 | set_bit(NFS_LSEG_LAYOUTRETURN, &lseg->pls_flags); | ||
| 1691 | mark_lseg_invalid(lseg, tmp_list); | ||
| 1692 | } | ||
| 1693 | } | ||
| 1694 | |||
| 1695 | void pnfs_error_mark_layout_for_return(struct inode *inode, | ||
| 1696 | struct pnfs_layout_segment *lseg) | ||
| 1697 | { | ||
| 1698 | struct pnfs_layout_hdr *lo = NFS_I(inode)->layout; | ||
| 1699 | int iomode = pnfs_iomode_to_fail_bit(lseg->pls_range.iomode); | ||
| 1700 | struct pnfs_layout_range range = { | ||
| 1701 | .iomode = lseg->pls_range.iomode, | ||
| 1702 | .offset = 0, | ||
| 1703 | .length = NFS4_MAX_UINT64, | ||
| 1704 | }; | ||
| 1705 | LIST_HEAD(free_me); | ||
| 1706 | |||
| 1707 | spin_lock(&inode->i_lock); | ||
| 1708 | /* set failure bit so that pnfs path will be retried later */ | ||
| 1709 | pnfs_layout_set_fail_bit(lo, iomode); | ||
| 1710 | set_bit(NFS_LAYOUT_RETURN, &lo->plh_flags); | ||
| 1711 | if (lo->plh_return_iomode == 0) | ||
| 1712 | lo->plh_return_iomode = range.iomode; | ||
| 1713 | else if (lo->plh_return_iomode != range.iomode) | ||
| 1714 | lo->plh_return_iomode = IOMODE_ANY; | ||
| 1715 | /* | ||
| 1716 | * mark all matching lsegs so that we are sure to have no live | ||
| 1717 | * segments at hand when sending layoutreturn. See pnfs_put_lseg() | ||
| 1718 | * for how it works. | ||
| 1719 | */ | ||
| 1720 | pnfs_mark_matching_lsegs_return(lo, &free_me, &range); | ||
| 1721 | spin_unlock(&inode->i_lock); | ||
| 1722 | pnfs_free_lseg_list(&free_me); | ||
| 1723 | } | ||
| 1724 | EXPORT_SYMBOL_GPL(pnfs_error_mark_layout_for_return); | ||
| 1725 | |||
| 1459 | void | 1726 | void |
| 1460 | pnfs_generic_pg_init_read(struct nfs_pageio_descriptor *pgio, struct nfs_page *req) | 1727 | pnfs_generic_pg_init_read(struct nfs_pageio_descriptor *pgio, struct nfs_page *req) |
| 1461 | { | 1728 | { |
| 1462 | u64 rd_size = req->wb_bytes; | 1729 | u64 rd_size = req->wb_bytes; |
| 1463 | 1730 | ||
| 1464 | WARN_ON_ONCE(pgio->pg_lseg != NULL); | 1731 | if (pgio->pg_lseg == NULL) { |
| 1465 | 1732 | if (pgio->pg_dreq == NULL) | |
| 1466 | if (pgio->pg_dreq == NULL) | 1733 | rd_size = i_size_read(pgio->pg_inode) - req_offset(req); |
| 1467 | rd_size = i_size_read(pgio->pg_inode) - req_offset(req); | 1734 | else |
| 1468 | else | 1735 | rd_size = nfs_dreq_bytes_left(pgio->pg_dreq); |
| 1469 | rd_size = nfs_dreq_bytes_left(pgio->pg_dreq); | 1736 | |
| 1470 | 1737 | pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode, | |
| 1471 | pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode, | 1738 | req->wb_context, |
| 1472 | req->wb_context, | 1739 | req_offset(req), |
| 1473 | req_offset(req), | 1740 | rd_size, |
| 1474 | rd_size, | 1741 | IOMODE_READ, |
| 1475 | IOMODE_READ, | 1742 | GFP_KERNEL); |
| 1476 | GFP_KERNEL); | 1743 | } |
| 1477 | /* If no lseg, fall back to read through mds */ | 1744 | /* If no lseg, fall back to read through mds */ |
| 1478 | if (pgio->pg_lseg == NULL) | 1745 | if (pgio->pg_lseg == NULL) |
| 1479 | nfs_pageio_reset_read_mds(pgio); | 1746 | nfs_pageio_reset_read_mds(pgio); |
| @@ -1485,27 +1752,36 @@ void | |||
| 1485 | pnfs_generic_pg_init_write(struct nfs_pageio_descriptor *pgio, | 1752 | pnfs_generic_pg_init_write(struct nfs_pageio_descriptor *pgio, |
| 1486 | struct nfs_page *req, u64 wb_size) | 1753 | struct nfs_page *req, u64 wb_size) |
| 1487 | { | 1754 | { |
| 1488 | WARN_ON_ONCE(pgio->pg_lseg != NULL); | 1755 | if (pgio->pg_lseg == NULL) |
| 1489 | 1756 | pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode, | |
| 1490 | pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode, | 1757 | req->wb_context, |
| 1491 | req->wb_context, | 1758 | req_offset(req), |
| 1492 | req_offset(req), | 1759 | wb_size, |
| 1493 | wb_size, | 1760 | IOMODE_RW, |
| 1494 | IOMODE_RW, | 1761 | GFP_NOFS); |
| 1495 | GFP_NOFS); | ||
| 1496 | /* If no lseg, fall back to write through mds */ | 1762 | /* If no lseg, fall back to write through mds */ |
| 1497 | if (pgio->pg_lseg == NULL) | 1763 | if (pgio->pg_lseg == NULL) |
| 1498 | nfs_pageio_reset_write_mds(pgio); | 1764 | nfs_pageio_reset_write_mds(pgio); |
| 1499 | } | 1765 | } |
| 1500 | EXPORT_SYMBOL_GPL(pnfs_generic_pg_init_write); | 1766 | EXPORT_SYMBOL_GPL(pnfs_generic_pg_init_write); |
| 1501 | 1767 | ||
| 1768 | void | ||
| 1769 | pnfs_generic_pg_cleanup(struct nfs_pageio_descriptor *desc) | ||
| 1770 | { | ||
| 1771 | if (desc->pg_lseg) { | ||
| 1772 | pnfs_put_lseg(desc->pg_lseg); | ||
| 1773 | desc->pg_lseg = NULL; | ||
| 1774 | } | ||
| 1775 | } | ||
| 1776 | EXPORT_SYMBOL_GPL(pnfs_generic_pg_cleanup); | ||
| 1777 | |||
| 1502 | /* | 1778 | /* |
| 1503 | * Return 0 if @req cannot be coalesced into @pgio, otherwise return the number | 1779 | * Return 0 if @req cannot be coalesced into @pgio, otherwise return the number |
| 1504 | * of bytes (maximum @req->wb_bytes) that can be coalesced. | 1780 | * of bytes (maximum @req->wb_bytes) that can be coalesced. |
| 1505 | */ | 1781 | */ |
| 1506 | size_t | 1782 | size_t |
| 1507 | pnfs_generic_pg_test(struct nfs_pageio_descriptor *pgio, struct nfs_page *prev, | 1783 | pnfs_generic_pg_test(struct nfs_pageio_descriptor *pgio, |
| 1508 | struct nfs_page *req) | 1784 | struct nfs_page *prev, struct nfs_page *req) |
| 1509 | { | 1785 | { |
| 1510 | unsigned int size; | 1786 | unsigned int size; |
| 1511 | u64 seg_end, req_start, seg_left; | 1787 | u64 seg_end, req_start, seg_left; |
| @@ -1529,10 +1805,16 @@ pnfs_generic_pg_test(struct nfs_pageio_descriptor *pgio, struct nfs_page *prev, | |||
| 1529 | seg_end = end_offset(pgio->pg_lseg->pls_range.offset, | 1805 | seg_end = end_offset(pgio->pg_lseg->pls_range.offset, |
| 1530 | pgio->pg_lseg->pls_range.length); | 1806 | pgio->pg_lseg->pls_range.length); |
| 1531 | req_start = req_offset(req); | 1807 | req_start = req_offset(req); |
| 1532 | WARN_ON_ONCE(req_start > seg_end); | 1808 | WARN_ON_ONCE(req_start >= seg_end); |
| 1533 | /* start of request is past the last byte of this segment */ | 1809 | /* start of request is past the last byte of this segment */ |
| 1534 | if (req_start >= seg_end) | 1810 | if (req_start >= seg_end) { |
| 1811 | /* reference the new lseg */ | ||
| 1812 | if (pgio->pg_ops->pg_cleanup) | ||
| 1813 | pgio->pg_ops->pg_cleanup(pgio); | ||
| 1814 | if (pgio->pg_ops->pg_init) | ||
| 1815 | pgio->pg_ops->pg_init(pgio, req); | ||
| 1535 | return 0; | 1816 | return 0; |
| 1817 | } | ||
| 1536 | 1818 | ||
| 1537 | /* adjust 'size' iff there are fewer bytes left in the | 1819 | /* adjust 'size' iff there are fewer bytes left in the |
| 1538 | * segment than what nfs_generic_pg_test returned */ | 1820 | * segment than what nfs_generic_pg_test returned */ |
| @@ -1587,10 +1869,12 @@ static void | |||
| 1587 | pnfs_write_through_mds(struct nfs_pageio_descriptor *desc, | 1869 | pnfs_write_through_mds(struct nfs_pageio_descriptor *desc, |
| 1588 | struct nfs_pgio_header *hdr) | 1870 | struct nfs_pgio_header *hdr) |
| 1589 | { | 1871 | { |
| 1872 | struct nfs_pgio_mirror *mirror = nfs_pgio_current_mirror(desc); | ||
| 1873 | |||
| 1590 | if (!test_and_set_bit(NFS_IOHDR_REDO, &hdr->flags)) { | 1874 | if (!test_and_set_bit(NFS_IOHDR_REDO, &hdr->flags)) { |
| 1591 | list_splice_tail_init(&hdr->pages, &desc->pg_list); | 1875 | list_splice_tail_init(&hdr->pages, &mirror->pg_list); |
| 1592 | nfs_pageio_reset_write_mds(desc); | 1876 | nfs_pageio_reset_write_mds(desc); |
| 1593 | desc->pg_recoalesce = 1; | 1877 | mirror->pg_recoalesce = 1; |
| 1594 | } | 1878 | } |
| 1595 | nfs_pgio_data_destroy(hdr); | 1879 | nfs_pgio_data_destroy(hdr); |
| 1596 | } | 1880 | } |
| @@ -1624,11 +1908,9 @@ pnfs_do_write(struct nfs_pageio_descriptor *desc, | |||
| 1624 | struct pnfs_layout_segment *lseg = desc->pg_lseg; | 1908 | struct pnfs_layout_segment *lseg = desc->pg_lseg; |
| 1625 | enum pnfs_try_status trypnfs; | 1909 | enum pnfs_try_status trypnfs; |
| 1626 | 1910 | ||
| 1627 | desc->pg_lseg = NULL; | ||
| 1628 | trypnfs = pnfs_try_to_write_data(hdr, call_ops, lseg, how); | 1911 | trypnfs = pnfs_try_to_write_data(hdr, call_ops, lseg, how); |
| 1629 | if (trypnfs == PNFS_NOT_ATTEMPTED) | 1912 | if (trypnfs == PNFS_NOT_ATTEMPTED) |
| 1630 | pnfs_write_through_mds(desc, hdr); | 1913 | pnfs_write_through_mds(desc, hdr); |
| 1631 | pnfs_put_lseg(lseg); | ||
| 1632 | } | 1914 | } |
| 1633 | 1915 | ||
| 1634 | static void pnfs_writehdr_free(struct nfs_pgio_header *hdr) | 1916 | static void pnfs_writehdr_free(struct nfs_pgio_header *hdr) |
| @@ -1641,24 +1923,23 @@ EXPORT_SYMBOL_GPL(pnfs_writehdr_free); | |||
| 1641 | int | 1923 | int |
| 1642 | pnfs_generic_pg_writepages(struct nfs_pageio_descriptor *desc) | 1924 | pnfs_generic_pg_writepages(struct nfs_pageio_descriptor *desc) |
| 1643 | { | 1925 | { |
| 1926 | struct nfs_pgio_mirror *mirror = nfs_pgio_current_mirror(desc); | ||
| 1927 | |||
| 1644 | struct nfs_pgio_header *hdr; | 1928 | struct nfs_pgio_header *hdr; |
| 1645 | int ret; | 1929 | int ret; |
| 1646 | 1930 | ||
| 1647 | hdr = nfs_pgio_header_alloc(desc->pg_rw_ops); | 1931 | hdr = nfs_pgio_header_alloc(desc->pg_rw_ops); |
| 1648 | if (!hdr) { | 1932 | if (!hdr) { |
| 1649 | desc->pg_completion_ops->error_cleanup(&desc->pg_list); | 1933 | desc->pg_completion_ops->error_cleanup(&mirror->pg_list); |
| 1650 | pnfs_put_lseg(desc->pg_lseg); | ||
| 1651 | desc->pg_lseg = NULL; | ||
| 1652 | return -ENOMEM; | 1934 | return -ENOMEM; |
| 1653 | } | 1935 | } |
| 1654 | nfs_pgheader_init(desc, hdr, pnfs_writehdr_free); | 1936 | nfs_pgheader_init(desc, hdr, pnfs_writehdr_free); |
| 1937 | |||
| 1655 | hdr->lseg = pnfs_get_lseg(desc->pg_lseg); | 1938 | hdr->lseg = pnfs_get_lseg(desc->pg_lseg); |
| 1656 | ret = nfs_generic_pgio(desc, hdr); | 1939 | ret = nfs_generic_pgio(desc, hdr); |
| 1657 | if (ret != 0) { | 1940 | if (!ret) |
| 1658 | pnfs_put_lseg(desc->pg_lseg); | ||
| 1659 | desc->pg_lseg = NULL; | ||
| 1660 | } else | ||
| 1661 | pnfs_do_write(desc, hdr, desc->pg_ioflags); | 1941 | pnfs_do_write(desc, hdr, desc->pg_ioflags); |
| 1942 | |||
| 1662 | return ret; | 1943 | return ret; |
| 1663 | } | 1944 | } |
| 1664 | EXPORT_SYMBOL_GPL(pnfs_generic_pg_writepages); | 1945 | EXPORT_SYMBOL_GPL(pnfs_generic_pg_writepages); |
| @@ -1703,10 +1984,12 @@ static void | |||
| 1703 | pnfs_read_through_mds(struct nfs_pageio_descriptor *desc, | 1984 | pnfs_read_through_mds(struct nfs_pageio_descriptor *desc, |
| 1704 | struct nfs_pgio_header *hdr) | 1985 | struct nfs_pgio_header *hdr) |
| 1705 | { | 1986 | { |
| 1987 | struct nfs_pgio_mirror *mirror = nfs_pgio_current_mirror(desc); | ||
| 1988 | |||
| 1706 | if (!test_and_set_bit(NFS_IOHDR_REDO, &hdr->flags)) { | 1989 | if (!test_and_set_bit(NFS_IOHDR_REDO, &hdr->flags)) { |
| 1707 | list_splice_tail_init(&hdr->pages, &desc->pg_list); | 1990 | list_splice_tail_init(&hdr->pages, &mirror->pg_list); |
| 1708 | nfs_pageio_reset_read_mds(desc); | 1991 | nfs_pageio_reset_read_mds(desc); |
| 1709 | desc->pg_recoalesce = 1; | 1992 | mirror->pg_recoalesce = 1; |
| 1710 | } | 1993 | } |
| 1711 | nfs_pgio_data_destroy(hdr); | 1994 | nfs_pgio_data_destroy(hdr); |
| 1712 | } | 1995 | } |
| @@ -1735,18 +2018,29 @@ pnfs_try_to_read_data(struct nfs_pgio_header *hdr, | |||
| 1735 | return trypnfs; | 2018 | return trypnfs; |
| 1736 | } | 2019 | } |
| 1737 | 2020 | ||
| 2021 | /* Resend all requests through pnfs. */ | ||
| 2022 | int pnfs_read_resend_pnfs(struct nfs_pgio_header *hdr) | ||
| 2023 | { | ||
| 2024 | struct nfs_pageio_descriptor pgio; | ||
| 2025 | |||
| 2026 | nfs_pageio_init_read(&pgio, hdr->inode, false, hdr->completion_ops); | ||
| 2027 | return nfs_pageio_resend(&pgio, hdr); | ||
| 2028 | } | ||
| 2029 | EXPORT_SYMBOL_GPL(pnfs_read_resend_pnfs); | ||
| 2030 | |||
| 1738 | static void | 2031 | static void |
| 1739 | pnfs_do_read(struct nfs_pageio_descriptor *desc, struct nfs_pgio_header *hdr) | 2032 | pnfs_do_read(struct nfs_pageio_descriptor *desc, struct nfs_pgio_header *hdr) |
| 1740 | { | 2033 | { |
| 1741 | const struct rpc_call_ops *call_ops = desc->pg_rpc_callops; | 2034 | const struct rpc_call_ops *call_ops = desc->pg_rpc_callops; |
| 1742 | struct pnfs_layout_segment *lseg = desc->pg_lseg; | 2035 | struct pnfs_layout_segment *lseg = desc->pg_lseg; |
| 1743 | enum pnfs_try_status trypnfs; | 2036 | enum pnfs_try_status trypnfs; |
| 2037 | int err = 0; | ||
| 1744 | 2038 | ||
| 1745 | desc->pg_lseg = NULL; | ||
| 1746 | trypnfs = pnfs_try_to_read_data(hdr, call_ops, lseg); | 2039 | trypnfs = pnfs_try_to_read_data(hdr, call_ops, lseg); |
| 1747 | if (trypnfs == PNFS_NOT_ATTEMPTED) | 2040 | if (trypnfs == PNFS_TRY_AGAIN) |
| 2041 | err = pnfs_read_resend_pnfs(hdr); | ||
| 2042 | if (trypnfs == PNFS_NOT_ATTEMPTED || err) | ||
| 1748 | pnfs_read_through_mds(desc, hdr); | 2043 | pnfs_read_through_mds(desc, hdr); |
| 1749 | pnfs_put_lseg(lseg); | ||
| 1750 | } | 2044 | } |
| 1751 | 2045 | ||
| 1752 | static void pnfs_readhdr_free(struct nfs_pgio_header *hdr) | 2046 | static void pnfs_readhdr_free(struct nfs_pgio_header *hdr) |
| @@ -1759,24 +2053,20 @@ EXPORT_SYMBOL_GPL(pnfs_readhdr_free); | |||
| 1759 | int | 2053 | int |
| 1760 | pnfs_generic_pg_readpages(struct nfs_pageio_descriptor *desc) | 2054 | pnfs_generic_pg_readpages(struct nfs_pageio_descriptor *desc) |
| 1761 | { | 2055 | { |
| 2056 | struct nfs_pgio_mirror *mirror = nfs_pgio_current_mirror(desc); | ||
| 2057 | |||
| 1762 | struct nfs_pgio_header *hdr; | 2058 | struct nfs_pgio_header *hdr; |
| 1763 | int ret; | 2059 | int ret; |
| 1764 | 2060 | ||
| 1765 | hdr = nfs_pgio_header_alloc(desc->pg_rw_ops); | 2061 | hdr = nfs_pgio_header_alloc(desc->pg_rw_ops); |
| 1766 | if (!hdr) { | 2062 | if (!hdr) { |
| 1767 | desc->pg_completion_ops->error_cleanup(&desc->pg_list); | 2063 | desc->pg_completion_ops->error_cleanup(&mirror->pg_list); |
| 1768 | ret = -ENOMEM; | 2064 | return -ENOMEM; |
| 1769 | pnfs_put_lseg(desc->pg_lseg); | ||
| 1770 | desc->pg_lseg = NULL; | ||
| 1771 | return ret; | ||
| 1772 | } | 2065 | } |
| 1773 | nfs_pgheader_init(desc, hdr, pnfs_readhdr_free); | 2066 | nfs_pgheader_init(desc, hdr, pnfs_readhdr_free); |
| 1774 | hdr->lseg = pnfs_get_lseg(desc->pg_lseg); | 2067 | hdr->lseg = pnfs_get_lseg(desc->pg_lseg); |
| 1775 | ret = nfs_generic_pgio(desc, hdr); | 2068 | ret = nfs_generic_pgio(desc, hdr); |
| 1776 | if (ret != 0) { | 2069 | if (!ret) |
| 1777 | pnfs_put_lseg(desc->pg_lseg); | ||
| 1778 | desc->pg_lseg = NULL; | ||
| 1779 | } else | ||
| 1780 | pnfs_do_read(desc, hdr); | 2070 | pnfs_do_read(desc, hdr); |
| 1781 | return ret; | 2071 | return ret; |
| 1782 | } | 2072 | } |
| @@ -1982,6 +2272,7 @@ clear_layoutcommitting: | |||
| 1982 | pnfs_clear_layoutcommitting(inode); | 2272 | pnfs_clear_layoutcommitting(inode); |
| 1983 | goto out; | 2273 | goto out; |
| 1984 | } | 2274 | } |
| 2275 | EXPORT_SYMBOL_GPL(pnfs_layoutcommit_inode); | ||
| 1985 | 2276 | ||
| 1986 | struct nfs4_threshold *pnfs_mdsthreshold_alloc(void) | 2277 | struct nfs4_threshold *pnfs_mdsthreshold_alloc(void) |
| 1987 | { | 2278 | { |
diff --git a/fs/nfs/pnfs.h b/fs/nfs/pnfs.h index a98d8fd9637f..797cd6253adf 100644 --- a/fs/nfs/pnfs.h +++ b/fs/nfs/pnfs.h | |||
| @@ -38,6 +38,25 @@ enum { | |||
| 38 | NFS_LSEG_VALID = 0, /* cleared when lseg is recalled/returned */ | 38 | NFS_LSEG_VALID = 0, /* cleared when lseg is recalled/returned */ |
| 39 | NFS_LSEG_ROC, /* roc bit received from server */ | 39 | NFS_LSEG_ROC, /* roc bit received from server */ |
| 40 | NFS_LSEG_LAYOUTCOMMIT, /* layoutcommit bit set for layoutcommit */ | 40 | NFS_LSEG_LAYOUTCOMMIT, /* layoutcommit bit set for layoutcommit */ |
| 41 | NFS_LSEG_LAYOUTRETURN, /* layoutreturn bit set for layoutreturn */ | ||
| 42 | }; | ||
| 43 | |||
| 44 | /* Individual ip address */ | ||
| 45 | struct nfs4_pnfs_ds_addr { | ||
| 46 | struct sockaddr_storage da_addr; | ||
| 47 | size_t da_addrlen; | ||
| 48 | struct list_head da_node; /* nfs4_pnfs_dev_hlist dev_dslist */ | ||
| 49 | char *da_remotestr; /* human readable addr+port */ | ||
| 50 | }; | ||
| 51 | |||
| 52 | struct nfs4_pnfs_ds { | ||
| 53 | struct list_head ds_node; /* nfs4_pnfs_dev_hlist dev_dslist */ | ||
| 54 | char *ds_remotestr; /* comma sep list of addrs */ | ||
| 55 | struct list_head ds_addrs; | ||
| 56 | struct nfs_client *ds_clp; | ||
| 57 | atomic_t ds_count; | ||
| 58 | unsigned long ds_state; | ||
| 59 | #define NFS4DS_CONNECTING 0 /* ds is establishing connection */ | ||
| 41 | }; | 60 | }; |
| 42 | 61 | ||
| 43 | struct pnfs_layout_segment { | 62 | struct pnfs_layout_segment { |
| @@ -53,19 +72,34 @@ struct pnfs_layout_segment { | |||
| 53 | enum pnfs_try_status { | 72 | enum pnfs_try_status { |
| 54 | PNFS_ATTEMPTED = 0, | 73 | PNFS_ATTEMPTED = 0, |
| 55 | PNFS_NOT_ATTEMPTED = 1, | 74 | PNFS_NOT_ATTEMPTED = 1, |
| 75 | PNFS_TRY_AGAIN = 2, | ||
| 56 | }; | 76 | }; |
| 57 | 77 | ||
| 58 | #ifdef CONFIG_NFS_V4_1 | 78 | #ifdef CONFIG_NFS_V4_1 |
| 59 | 79 | ||
| 60 | #define LAYOUT_NFSV4_1_MODULE_PREFIX "nfs-layouttype4" | 80 | #define LAYOUT_NFSV4_1_MODULE_PREFIX "nfs-layouttype4" |
| 61 | 81 | ||
| 82 | /* | ||
| 83 | * Default data server connection timeout and retrans vaules. | ||
| 84 | * Set by module parameters dataserver_timeo and dataserver_retrans. | ||
| 85 | */ | ||
| 86 | #define NFS4_DEF_DS_TIMEO 600 /* in tenths of a second */ | ||
| 87 | #define NFS4_DEF_DS_RETRANS 5 | ||
| 88 | |||
| 89 | /* error codes for internal use */ | ||
| 90 | #define NFS4ERR_RESET_TO_MDS 12001 | ||
| 91 | #define NFS4ERR_RESET_TO_PNFS 12002 | ||
| 92 | |||
| 62 | enum { | 93 | enum { |
| 63 | NFS_LAYOUT_RO_FAILED = 0, /* get ro layout failed stop trying */ | 94 | NFS_LAYOUT_RO_FAILED = 0, /* get ro layout failed stop trying */ |
| 64 | NFS_LAYOUT_RW_FAILED, /* get rw layout failed stop trying */ | 95 | NFS_LAYOUT_RW_FAILED, /* get rw layout failed stop trying */ |
| 65 | NFS_LAYOUT_BULK_RECALL, /* bulk recall affecting layout */ | 96 | NFS_LAYOUT_BULK_RECALL, /* bulk recall affecting layout */ |
| 66 | NFS_LAYOUT_ROC, /* some lseg had roc bit set */ | 97 | NFS_LAYOUT_ROC, /* some lseg had roc bit set */ |
| 67 | NFS_LAYOUT_RETURN, /* Return this layout ASAP */ | 98 | NFS_LAYOUT_RETURN, /* Return this layout ASAP */ |
| 99 | NFS_LAYOUT_RETURN_BEFORE_CLOSE, /* Return this layout before close */ | ||
| 68 | NFS_LAYOUT_INVALID_STID, /* layout stateid id is invalid */ | 100 | NFS_LAYOUT_INVALID_STID, /* layout stateid id is invalid */ |
| 101 | NFS_LAYOUT_FIRST_LAYOUTGET, /* Serialize first layoutget */ | ||
| 102 | NFS_LAYOUT_RETRY_LAYOUTGET, /* Retry layoutget */ | ||
| 69 | }; | 103 | }; |
| 70 | 104 | ||
| 71 | enum layoutdriver_policy_flags { | 105 | enum layoutdriver_policy_flags { |
| @@ -106,7 +140,8 @@ struct pnfs_layoutdriver_type { | |||
| 106 | struct pnfs_ds_commit_info *(*get_ds_info) (struct inode *inode); | 140 | struct pnfs_ds_commit_info *(*get_ds_info) (struct inode *inode); |
| 107 | void (*mark_request_commit) (struct nfs_page *req, | 141 | void (*mark_request_commit) (struct nfs_page *req, |
| 108 | struct pnfs_layout_segment *lseg, | 142 | struct pnfs_layout_segment *lseg, |
| 109 | struct nfs_commit_info *cinfo); | 143 | struct nfs_commit_info *cinfo, |
| 144 | u32 ds_commit_idx); | ||
| 110 | void (*clear_request_commit) (struct nfs_page *req, | 145 | void (*clear_request_commit) (struct nfs_page *req, |
| 111 | struct nfs_commit_info *cinfo); | 146 | struct nfs_commit_info *cinfo); |
| 112 | int (*scan_commit_lists) (struct nfs_commit_info *cinfo, | 147 | int (*scan_commit_lists) (struct nfs_commit_info *cinfo, |
| @@ -154,6 +189,7 @@ struct pnfs_layout_hdr { | |||
| 154 | u32 plh_barrier; /* ignore lower seqids */ | 189 | u32 plh_barrier; /* ignore lower seqids */ |
| 155 | unsigned long plh_retry_timestamp; | 190 | unsigned long plh_retry_timestamp; |
| 156 | unsigned long plh_flags; | 191 | unsigned long plh_flags; |
| 192 | enum pnfs_iomode plh_return_iomode; | ||
| 157 | loff_t plh_lwb; /* last write byte for layoutcommit */ | 193 | loff_t plh_lwb; /* last write byte for layoutcommit */ |
| 158 | struct rpc_cred *plh_lc_cred; /* layoutcommit cred */ | 194 | struct rpc_cred *plh_lc_cred; /* layoutcommit cred */ |
| 159 | struct inode *plh_inode; | 195 | struct inode *plh_inode; |
| @@ -185,7 +221,7 @@ extern int nfs4_proc_getdeviceinfo(struct nfs_server *server, | |||
| 185 | struct pnfs_device *dev, | 221 | struct pnfs_device *dev, |
| 186 | struct rpc_cred *cred); | 222 | struct rpc_cred *cred); |
| 187 | extern struct pnfs_layout_segment* nfs4_proc_layoutget(struct nfs4_layoutget *lgp, gfp_t gfp_flags); | 223 | extern struct pnfs_layout_segment* nfs4_proc_layoutget(struct nfs4_layoutget *lgp, gfp_t gfp_flags); |
| 188 | extern int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp); | 224 | extern int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, bool sync); |
| 189 | 225 | ||
| 190 | /* pnfs.c */ | 226 | /* pnfs.c */ |
| 191 | void pnfs_get_layout_hdr(struct pnfs_layout_hdr *lo); | 227 | void pnfs_get_layout_hdr(struct pnfs_layout_hdr *lo); |
| @@ -198,6 +234,7 @@ void pnfs_generic_pg_init_read(struct nfs_pageio_descriptor *, struct nfs_page * | |||
| 198 | int pnfs_generic_pg_readpages(struct nfs_pageio_descriptor *desc); | 234 | int pnfs_generic_pg_readpages(struct nfs_pageio_descriptor *desc); |
| 199 | void pnfs_generic_pg_init_write(struct nfs_pageio_descriptor *pgio, | 235 | void pnfs_generic_pg_init_write(struct nfs_pageio_descriptor *pgio, |
| 200 | struct nfs_page *req, u64 wb_size); | 236 | struct nfs_page *req, u64 wb_size); |
| 237 | void pnfs_generic_pg_cleanup(struct nfs_pageio_descriptor *); | ||
| 201 | int pnfs_generic_pg_writepages(struct nfs_pageio_descriptor *desc); | 238 | int pnfs_generic_pg_writepages(struct nfs_pageio_descriptor *desc); |
| 202 | size_t pnfs_generic_pg_test(struct nfs_pageio_descriptor *pgio, | 239 | size_t pnfs_generic_pg_test(struct nfs_pageio_descriptor *pgio, |
| 203 | struct nfs_page *prev, struct nfs_page *req); | 240 | struct nfs_page *prev, struct nfs_page *req); |
| @@ -217,6 +254,7 @@ void pnfs_set_layout_stateid(struct pnfs_layout_hdr *lo, | |||
| 217 | bool update_barrier); | 254 | bool update_barrier); |
| 218 | int pnfs_choose_layoutget_stateid(nfs4_stateid *dst, | 255 | int pnfs_choose_layoutget_stateid(nfs4_stateid *dst, |
| 219 | struct pnfs_layout_hdr *lo, | 256 | struct pnfs_layout_hdr *lo, |
| 257 | struct pnfs_layout_range *range, | ||
| 220 | struct nfs4_state *open_state); | 258 | struct nfs4_state *open_state); |
| 221 | int pnfs_mark_matching_lsegs_invalid(struct pnfs_layout_hdr *lo, | 259 | int pnfs_mark_matching_lsegs_invalid(struct pnfs_layout_hdr *lo, |
| 222 | struct list_head *tmp_list, | 260 | struct list_head *tmp_list, |
| @@ -233,17 +271,21 @@ int _pnfs_return_layout(struct inode *); | |||
| 233 | int pnfs_commit_and_return_layout(struct inode *); | 271 | int pnfs_commit_and_return_layout(struct inode *); |
| 234 | void pnfs_ld_write_done(struct nfs_pgio_header *); | 272 | void pnfs_ld_write_done(struct nfs_pgio_header *); |
| 235 | void pnfs_ld_read_done(struct nfs_pgio_header *); | 273 | void pnfs_ld_read_done(struct nfs_pgio_header *); |
| 274 | int pnfs_read_resend_pnfs(struct nfs_pgio_header *); | ||
| 236 | struct pnfs_layout_segment *pnfs_update_layout(struct inode *ino, | 275 | struct pnfs_layout_segment *pnfs_update_layout(struct inode *ino, |
| 237 | struct nfs_open_context *ctx, | 276 | struct nfs_open_context *ctx, |
| 238 | loff_t pos, | 277 | loff_t pos, |
| 239 | u64 count, | 278 | u64 count, |
| 240 | enum pnfs_iomode iomode, | 279 | enum pnfs_iomode iomode, |
| 241 | gfp_t gfp_flags); | 280 | gfp_t gfp_flags); |
| 281 | void pnfs_clear_layoutreturn_waitbit(struct pnfs_layout_hdr *lo); | ||
| 242 | 282 | ||
| 243 | void nfs4_deviceid_mark_client_invalid(struct nfs_client *clp); | 283 | void nfs4_deviceid_mark_client_invalid(struct nfs_client *clp); |
| 244 | int pnfs_read_done_resend_to_mds(struct nfs_pgio_header *); | 284 | int pnfs_read_done_resend_to_mds(struct nfs_pgio_header *); |
| 245 | int pnfs_write_done_resend_to_mds(struct nfs_pgio_header *); | 285 | int pnfs_write_done_resend_to_mds(struct nfs_pgio_header *); |
| 246 | struct nfs4_threshold *pnfs_mdsthreshold_alloc(void); | 286 | struct nfs4_threshold *pnfs_mdsthreshold_alloc(void); |
| 287 | void pnfs_error_mark_layout_for_return(struct inode *inode, | ||
| 288 | struct pnfs_layout_segment *lseg); | ||
| 247 | 289 | ||
| 248 | /* nfs4_deviceid_flags */ | 290 | /* nfs4_deviceid_flags */ |
| 249 | enum { | 291 | enum { |
| @@ -275,6 +317,34 @@ void nfs4_mark_deviceid_unavailable(struct nfs4_deviceid_node *node); | |||
| 275 | bool nfs4_test_deviceid_unavailable(struct nfs4_deviceid_node *node); | 317 | bool nfs4_test_deviceid_unavailable(struct nfs4_deviceid_node *node); |
| 276 | void nfs4_deviceid_purge_client(const struct nfs_client *); | 318 | void nfs4_deviceid_purge_client(const struct nfs_client *); |
| 277 | 319 | ||
| 320 | /* pnfs_nfs.c */ | ||
| 321 | void pnfs_generic_clear_request_commit(struct nfs_page *req, | ||
| 322 | struct nfs_commit_info *cinfo); | ||
| 323 | void pnfs_generic_commit_release(void *calldata); | ||
| 324 | void pnfs_generic_prepare_to_resend_writes(struct nfs_commit_data *data); | ||
| 325 | void pnfs_generic_rw_release(void *data); | ||
| 326 | void pnfs_generic_recover_commit_reqs(struct list_head *dst, | ||
| 327 | struct nfs_commit_info *cinfo); | ||
| 328 | int pnfs_generic_commit_pagelist(struct inode *inode, | ||
| 329 | struct list_head *mds_pages, | ||
| 330 | int how, | ||
| 331 | struct nfs_commit_info *cinfo, | ||
| 332 | int (*initiate_commit)(struct nfs_commit_data *data, | ||
| 333 | int how)); | ||
| 334 | int pnfs_generic_scan_commit_lists(struct nfs_commit_info *cinfo, int max); | ||
| 335 | void pnfs_generic_write_commit_done(struct rpc_task *task, void *data); | ||
| 336 | void nfs4_pnfs_ds_put(struct nfs4_pnfs_ds *ds); | ||
| 337 | struct nfs4_pnfs_ds *nfs4_pnfs_ds_add(struct list_head *dsaddrs, | ||
| 338 | gfp_t gfp_flags); | ||
| 339 | void nfs4_pnfs_v3_ds_connect_unload(void); | ||
| 340 | void nfs4_pnfs_ds_connect(struct nfs_server *mds_srv, struct nfs4_pnfs_ds *ds, | ||
| 341 | struct nfs4_deviceid_node *devid, unsigned int timeo, | ||
| 342 | unsigned int retrans, u32 version, u32 minor_version, | ||
| 343 | rpc_authflavor_t au_flavor); | ||
| 344 | struct nfs4_pnfs_ds_addr *nfs4_decode_mp_ds_addr(struct net *net, | ||
| 345 | struct xdr_stream *xdr, | ||
| 346 | gfp_t gfp_flags); | ||
| 347 | |||
| 278 | static inline bool nfs_have_layout(struct inode *inode) | 348 | static inline bool nfs_have_layout(struct inode *inode) |
| 279 | { | 349 | { |
| 280 | return NFS_I(inode)->layout != NULL; | 350 | return NFS_I(inode)->layout != NULL; |
| @@ -287,6 +357,26 @@ nfs4_get_deviceid(struct nfs4_deviceid_node *d) | |||
| 287 | return d; | 357 | return d; |
| 288 | } | 358 | } |
| 289 | 359 | ||
| 360 | static inline void pnfs_set_retry_layoutget(struct pnfs_layout_hdr *lo) | ||
| 361 | { | ||
| 362 | if (!test_and_set_bit(NFS_LAYOUT_RETRY_LAYOUTGET, &lo->plh_flags)) | ||
| 363 | atomic_inc(&lo->plh_refcount); | ||
| 364 | } | ||
| 365 | |||
| 366 | static inline void pnfs_clear_retry_layoutget(struct pnfs_layout_hdr *lo) | ||
| 367 | { | ||
| 368 | if (test_and_clear_bit(NFS_LAYOUT_RETRY_LAYOUTGET, &lo->plh_flags)) { | ||
| 369 | atomic_dec(&lo->plh_refcount); | ||
| 370 | /* wake up waiters for LAYOUTRETURN as that is not needed */ | ||
| 371 | wake_up_bit(&lo->plh_flags, NFS_LAYOUT_RETURN); | ||
| 372 | } | ||
| 373 | } | ||
| 374 | |||
| 375 | static inline bool pnfs_should_retry_layoutget(struct pnfs_layout_hdr *lo) | ||
| 376 | { | ||
| 377 | return test_bit(NFS_LAYOUT_RETRY_LAYOUTGET, &lo->plh_flags); | ||
| 378 | } | ||
| 379 | |||
| 290 | static inline struct pnfs_layout_segment * | 380 | static inline struct pnfs_layout_segment * |
| 291 | pnfs_get_lseg(struct pnfs_layout_segment *lseg) | 381 | pnfs_get_lseg(struct pnfs_layout_segment *lseg) |
| 292 | { | 382 | { |
| @@ -322,16 +412,22 @@ pnfs_get_ds_info(struct inode *inode) | |||
| 322 | return ld->get_ds_info(inode); | 412 | return ld->get_ds_info(inode); |
| 323 | } | 413 | } |
| 324 | 414 | ||
| 415 | static inline void | ||
| 416 | pnfs_generic_mark_devid_invalid(struct nfs4_deviceid_node *node) | ||
| 417 | { | ||
| 418 | set_bit(NFS_DEVICEID_INVALID, &node->flags); | ||
| 419 | } | ||
| 420 | |||
| 325 | static inline bool | 421 | static inline bool |
| 326 | pnfs_mark_request_commit(struct nfs_page *req, struct pnfs_layout_segment *lseg, | 422 | pnfs_mark_request_commit(struct nfs_page *req, struct pnfs_layout_segment *lseg, |
| 327 | struct nfs_commit_info *cinfo) | 423 | struct nfs_commit_info *cinfo, u32 ds_commit_idx) |
| 328 | { | 424 | { |
| 329 | struct inode *inode = req->wb_context->dentry->d_inode; | 425 | struct inode *inode = req->wb_context->dentry->d_inode; |
| 330 | struct pnfs_layoutdriver_type *ld = NFS_SERVER(inode)->pnfs_curr_ld; | 426 | struct pnfs_layoutdriver_type *ld = NFS_SERVER(inode)->pnfs_curr_ld; |
| 331 | 427 | ||
| 332 | if (lseg == NULL || ld->mark_request_commit == NULL) | 428 | if (lseg == NULL || ld->mark_request_commit == NULL) |
| 333 | return false; | 429 | return false; |
| 334 | ld->mark_request_commit(req, lseg, cinfo); | 430 | ld->mark_request_commit(req, lseg, cinfo, ds_commit_idx); |
| 335 | return true; | 431 | return true; |
| 336 | } | 432 | } |
| 337 | 433 | ||
| @@ -357,15 +453,6 @@ pnfs_scan_commit_lists(struct inode *inode, struct nfs_commit_info *cinfo, | |||
| 357 | return NFS_SERVER(inode)->pnfs_curr_ld->scan_commit_lists(cinfo, max); | 453 | return NFS_SERVER(inode)->pnfs_curr_ld->scan_commit_lists(cinfo, max); |
| 358 | } | 454 | } |
| 359 | 455 | ||
| 360 | static inline void | ||
| 361 | pnfs_recover_commit_reqs(struct inode *inode, struct list_head *list, | ||
| 362 | struct nfs_commit_info *cinfo) | ||
| 363 | { | ||
| 364 | if (cinfo->ds == NULL || cinfo->ds->nwritten == 0) | ||
| 365 | return; | ||
| 366 | NFS_SERVER(inode)->pnfs_curr_ld->recover_commit_reqs(list, cinfo); | ||
| 367 | } | ||
| 368 | |||
| 369 | static inline struct nfs_page * | 456 | static inline struct nfs_page * |
| 370 | pnfs_search_commit_reqs(struct inode *inode, struct nfs_commit_info *cinfo, | 457 | pnfs_search_commit_reqs(struct inode *inode, struct nfs_commit_info *cinfo, |
| 371 | struct page *page) | 458 | struct page *page) |
| @@ -523,7 +610,7 @@ pnfs_get_ds_info(struct inode *inode) | |||
| 523 | 610 | ||
| 524 | static inline bool | 611 | static inline bool |
| 525 | pnfs_mark_request_commit(struct nfs_page *req, struct pnfs_layout_segment *lseg, | 612 | pnfs_mark_request_commit(struct nfs_page *req, struct pnfs_layout_segment *lseg, |
| 526 | struct nfs_commit_info *cinfo) | 613 | struct nfs_commit_info *cinfo, u32 ds_commit_idx) |
| 527 | { | 614 | { |
| 528 | return false; | 615 | return false; |
| 529 | } | 616 | } |
| @@ -541,12 +628,6 @@ pnfs_scan_commit_lists(struct inode *inode, struct nfs_commit_info *cinfo, | |||
| 541 | return 0; | 628 | return 0; |
| 542 | } | 629 | } |
| 543 | 630 | ||
| 544 | static inline void | ||
| 545 | pnfs_recover_commit_reqs(struct inode *inode, struct list_head *list, | ||
| 546 | struct nfs_commit_info *cinfo) | ||
| 547 | { | ||
| 548 | } | ||
| 549 | |||
| 550 | static inline struct nfs_page * | 631 | static inline struct nfs_page * |
| 551 | pnfs_search_commit_reqs(struct inode *inode, struct nfs_commit_info *cinfo, | 632 | pnfs_search_commit_reqs(struct inode *inode, struct nfs_commit_info *cinfo, |
| 552 | struct page *page) | 633 | struct page *page) |
| @@ -578,6 +659,10 @@ static inline struct nfs4_threshold *pnfs_mdsthreshold_alloc(void) | |||
| 578 | return NULL; | 659 | return NULL; |
| 579 | } | 660 | } |
| 580 | 661 | ||
| 662 | static inline void nfs4_pnfs_v3_ds_connect_unload(void) | ||
| 663 | { | ||
| 664 | } | ||
| 665 | |||
| 581 | #endif /* CONFIG_NFS_V4_1 */ | 666 | #endif /* CONFIG_NFS_V4_1 */ |
| 582 | 667 | ||
| 583 | #endif /* FS_NFS_PNFS_H */ | 668 | #endif /* FS_NFS_PNFS_H */ |
diff --git a/fs/nfs/pnfs_nfs.c b/fs/nfs/pnfs_nfs.c new file mode 100644 index 000000000000..fdc4f6562bb7 --- /dev/null +++ b/fs/nfs/pnfs_nfs.c | |||
| @@ -0,0 +1,840 @@ | |||
| 1 | /* | ||
| 2 | * Common NFS I/O operations for the pnfs file based | ||
| 3 | * layout drivers. | ||
| 4 | * | ||
| 5 | * Copyright (c) 2014, Primary Data, Inc. All rights reserved. | ||
| 6 | * | ||
| 7 | * Tom Haynes <loghyr@primarydata.com> | ||
| 8 | */ | ||
| 9 | |||
| 10 | #include <linux/nfs_fs.h> | ||
| 11 | #include <linux/nfs_page.h> | ||
| 12 | #include <linux/sunrpc/addr.h> | ||
| 13 | #include <linux/module.h> | ||
| 14 | |||
| 15 | #include "nfs4session.h" | ||
| 16 | #include "internal.h" | ||
| 17 | #include "pnfs.h" | ||
| 18 | |||
| 19 | #define NFSDBG_FACILITY NFSDBG_PNFS | ||
| 20 | |||
| 21 | void pnfs_generic_rw_release(void *data) | ||
| 22 | { | ||
| 23 | struct nfs_pgio_header *hdr = data; | ||
| 24 | |||
| 25 | nfs_put_client(hdr->ds_clp); | ||
| 26 | hdr->mds_ops->rpc_release(data); | ||
| 27 | } | ||
| 28 | EXPORT_SYMBOL_GPL(pnfs_generic_rw_release); | ||
| 29 | |||
| 30 | /* Fake up some data that will cause nfs_commit_release to retry the writes. */ | ||
| 31 | void pnfs_generic_prepare_to_resend_writes(struct nfs_commit_data *data) | ||
| 32 | { | ||
| 33 | struct nfs_page *first = nfs_list_entry(data->pages.next); | ||
| 34 | |||
| 35 | data->task.tk_status = 0; | ||
| 36 | memcpy(&data->verf.verifier, &first->wb_verf, | ||
| 37 | sizeof(data->verf.verifier)); | ||
| 38 | data->verf.verifier.data[0]++; /* ensure verifier mismatch */ | ||
| 39 | } | ||
| 40 | EXPORT_SYMBOL_GPL(pnfs_generic_prepare_to_resend_writes); | ||
| 41 | |||
| 42 | void pnfs_generic_write_commit_done(struct rpc_task *task, void *data) | ||
| 43 | { | ||
| 44 | struct nfs_commit_data *wdata = data; | ||
| 45 | |||
| 46 | /* Note this may cause RPC to be resent */ | ||
| 47 | wdata->mds_ops->rpc_call_done(task, data); | ||
| 48 | } | ||
| 49 | EXPORT_SYMBOL_GPL(pnfs_generic_write_commit_done); | ||
| 50 | |||
| 51 | void pnfs_generic_commit_release(void *calldata) | ||
| 52 | { | ||
| 53 | struct nfs_commit_data *data = calldata; | ||
| 54 | |||
| 55 | data->completion_ops->completion(data); | ||
| 56 | pnfs_put_lseg(data->lseg); | ||
| 57 | nfs_put_client(data->ds_clp); | ||
| 58 | nfs_commitdata_release(data); | ||
| 59 | } | ||
| 60 | EXPORT_SYMBOL_GPL(pnfs_generic_commit_release); | ||
| 61 | |||
| 62 | /* The generic layer is about to remove the req from the commit list. | ||
| 63 | * If this will make the bucket empty, it will need to put the lseg reference. | ||
| 64 | * Note this must be called holding the inode (/cinfo) lock | ||
| 65 | */ | ||
| 66 | void | ||
| 67 | pnfs_generic_clear_request_commit(struct nfs_page *req, | ||
| 68 | struct nfs_commit_info *cinfo) | ||
| 69 | { | ||
| 70 | struct pnfs_layout_segment *freeme = NULL; | ||
| 71 | |||
| 72 | if (!test_and_clear_bit(PG_COMMIT_TO_DS, &req->wb_flags)) | ||
| 73 | goto out; | ||
| 74 | cinfo->ds->nwritten--; | ||
| 75 | if (list_is_singular(&req->wb_list)) { | ||
| 76 | struct pnfs_commit_bucket *bucket; | ||
| 77 | |||
| 78 | bucket = list_first_entry(&req->wb_list, | ||
| 79 | struct pnfs_commit_bucket, | ||
| 80 | written); | ||
| 81 | freeme = bucket->wlseg; | ||
| 82 | bucket->wlseg = NULL; | ||
| 83 | } | ||
| 84 | out: | ||
| 85 | nfs_request_remove_commit_list(req, cinfo); | ||
| 86 | pnfs_put_lseg_locked(freeme); | ||
| 87 | } | ||
| 88 | EXPORT_SYMBOL_GPL(pnfs_generic_clear_request_commit); | ||
| 89 | |||
| 90 | static int | ||
| 91 | pnfs_generic_transfer_commit_list(struct list_head *src, struct list_head *dst, | ||
| 92 | struct nfs_commit_info *cinfo, int max) | ||
| 93 | { | ||
| 94 | struct nfs_page *req, *tmp; | ||
| 95 | int ret = 0; | ||
| 96 | |||
| 97 | list_for_each_entry_safe(req, tmp, src, wb_list) { | ||
| 98 | if (!nfs_lock_request(req)) | ||
| 99 | continue; | ||
| 100 | kref_get(&req->wb_kref); | ||
| 101 | if (cond_resched_lock(cinfo->lock)) | ||
| 102 | list_safe_reset_next(req, tmp, wb_list); | ||
| 103 | nfs_request_remove_commit_list(req, cinfo); | ||
| 104 | clear_bit(PG_COMMIT_TO_DS, &req->wb_flags); | ||
| 105 | nfs_list_add_request(req, dst); | ||
| 106 | ret++; | ||
| 107 | if ((ret == max) && !cinfo->dreq) | ||
| 108 | break; | ||
| 109 | } | ||
| 110 | return ret; | ||
| 111 | } | ||
| 112 | |||
| 113 | static int | ||
| 114 | pnfs_generic_scan_ds_commit_list(struct pnfs_commit_bucket *bucket, | ||
| 115 | struct nfs_commit_info *cinfo, | ||
| 116 | int max) | ||
| 117 | { | ||
| 118 | struct list_head *src = &bucket->written; | ||
| 119 | struct list_head *dst = &bucket->committing; | ||
| 120 | int ret; | ||
| 121 | |||
| 122 | lockdep_assert_held(cinfo->lock); | ||
| 123 | ret = pnfs_generic_transfer_commit_list(src, dst, cinfo, max); | ||
| 124 | if (ret) { | ||
| 125 | cinfo->ds->nwritten -= ret; | ||
| 126 | cinfo->ds->ncommitting += ret; | ||
| 127 | bucket->clseg = bucket->wlseg; | ||
| 128 | if (list_empty(src)) | ||
| 129 | bucket->wlseg = NULL; | ||
| 130 | else | ||
| 131 | pnfs_get_lseg(bucket->clseg); | ||
| 132 | } | ||
| 133 | return ret; | ||
| 134 | } | ||
| 135 | |||
| 136 | /* Move reqs from written to committing lists, returning count | ||
| 137 | * of number moved. | ||
| 138 | */ | ||
| 139 | int pnfs_generic_scan_commit_lists(struct nfs_commit_info *cinfo, | ||
| 140 | int max) | ||
| 141 | { | ||
| 142 | int i, rv = 0, cnt; | ||
| 143 | |||
| 144 | lockdep_assert_held(cinfo->lock); | ||
| 145 | for (i = 0; i < cinfo->ds->nbuckets && max != 0; i++) { | ||
| 146 | cnt = pnfs_generic_scan_ds_commit_list(&cinfo->ds->buckets[i], | ||
| 147 | cinfo, max); | ||
| 148 | max -= cnt; | ||
| 149 | rv += cnt; | ||
| 150 | } | ||
| 151 | return rv; | ||
| 152 | } | ||
| 153 | EXPORT_SYMBOL_GPL(pnfs_generic_scan_commit_lists); | ||
| 154 | |||
| 155 | /* Pull everything off the committing lists and dump into @dst. */ | ||
| 156 | void pnfs_generic_recover_commit_reqs(struct list_head *dst, | ||
| 157 | struct nfs_commit_info *cinfo) | ||
| 158 | { | ||
| 159 | struct pnfs_commit_bucket *b; | ||
| 160 | struct pnfs_layout_segment *freeme; | ||
| 161 | int i; | ||
| 162 | |||
| 163 | lockdep_assert_held(cinfo->lock); | ||
| 164 | restart: | ||
| 165 | for (i = 0, b = cinfo->ds->buckets; i < cinfo->ds->nbuckets; i++, b++) { | ||
| 166 | if (pnfs_generic_transfer_commit_list(&b->written, dst, | ||
| 167 | cinfo, 0)) { | ||
| 168 | freeme = b->wlseg; | ||
| 169 | b->wlseg = NULL; | ||
| 170 | spin_unlock(cinfo->lock); | ||
| 171 | pnfs_put_lseg(freeme); | ||
| 172 | spin_lock(cinfo->lock); | ||
| 173 | goto restart; | ||
| 174 | } | ||
| 175 | } | ||
| 176 | cinfo->ds->nwritten = 0; | ||
| 177 | } | ||
| 178 | EXPORT_SYMBOL_GPL(pnfs_generic_recover_commit_reqs); | ||
| 179 | |||
| 180 | static void pnfs_generic_retry_commit(struct nfs_commit_info *cinfo, int idx) | ||
| 181 | { | ||
| 182 | struct pnfs_ds_commit_info *fl_cinfo = cinfo->ds; | ||
| 183 | struct pnfs_commit_bucket *bucket; | ||
| 184 | struct pnfs_layout_segment *freeme; | ||
| 185 | int i; | ||
| 186 | |||
| 187 | for (i = idx; i < fl_cinfo->nbuckets; i++) { | ||
| 188 | bucket = &fl_cinfo->buckets[i]; | ||
| 189 | if (list_empty(&bucket->committing)) | ||
| 190 | continue; | ||
| 191 | nfs_retry_commit(&bucket->committing, bucket->clseg, cinfo, i); | ||
| 192 | spin_lock(cinfo->lock); | ||
| 193 | freeme = bucket->clseg; | ||
| 194 | bucket->clseg = NULL; | ||
| 195 | spin_unlock(cinfo->lock); | ||
| 196 | pnfs_put_lseg(freeme); | ||
| 197 | } | ||
| 198 | } | ||
| 199 | |||
| 200 | static unsigned int | ||
| 201 | pnfs_generic_alloc_ds_commits(struct nfs_commit_info *cinfo, | ||
| 202 | struct list_head *list) | ||
| 203 | { | ||
| 204 | struct pnfs_ds_commit_info *fl_cinfo; | ||
| 205 | struct pnfs_commit_bucket *bucket; | ||
| 206 | struct nfs_commit_data *data; | ||
| 207 | int i; | ||
| 208 | unsigned int nreq = 0; | ||
| 209 | |||
| 210 | fl_cinfo = cinfo->ds; | ||
| 211 | bucket = fl_cinfo->buckets; | ||
| 212 | for (i = 0; i < fl_cinfo->nbuckets; i++, bucket++) { | ||
| 213 | if (list_empty(&bucket->committing)) | ||
| 214 | continue; | ||
| 215 | data = nfs_commitdata_alloc(); | ||
| 216 | if (!data) | ||
| 217 | break; | ||
| 218 | data->ds_commit_index = i; | ||
| 219 | spin_lock(cinfo->lock); | ||
| 220 | data->lseg = bucket->clseg; | ||
| 221 | bucket->clseg = NULL; | ||
| 222 | spin_unlock(cinfo->lock); | ||
| 223 | list_add(&data->pages, list); | ||
| 224 | nreq++; | ||
| 225 | } | ||
| 226 | |||
| 227 | /* Clean up on error */ | ||
| 228 | pnfs_generic_retry_commit(cinfo, i); | ||
| 229 | return nreq; | ||
| 230 | } | ||
| 231 | |||
| 232 | /* This follows nfs_commit_list pretty closely */ | ||
| 233 | int | ||
| 234 | pnfs_generic_commit_pagelist(struct inode *inode, struct list_head *mds_pages, | ||
| 235 | int how, struct nfs_commit_info *cinfo, | ||
| 236 | int (*initiate_commit)(struct nfs_commit_data *data, | ||
| 237 | int how)) | ||
| 238 | { | ||
| 239 | struct nfs_commit_data *data, *tmp; | ||
| 240 | LIST_HEAD(list); | ||
| 241 | unsigned int nreq = 0; | ||
| 242 | |||
| 243 | if (!list_empty(mds_pages)) { | ||
| 244 | data = nfs_commitdata_alloc(); | ||
| 245 | if (data != NULL) { | ||
| 246 | data->lseg = NULL; | ||
| 247 | list_add(&data->pages, &list); | ||
| 248 | nreq++; | ||
| 249 | } else { | ||
| 250 | nfs_retry_commit(mds_pages, NULL, cinfo, 0); | ||
| 251 | pnfs_generic_retry_commit(cinfo, 0); | ||
| 252 | cinfo->completion_ops->error_cleanup(NFS_I(inode)); | ||
| 253 | return -ENOMEM; | ||
| 254 | } | ||
| 255 | } | ||
| 256 | |||
| 257 | nreq += pnfs_generic_alloc_ds_commits(cinfo, &list); | ||
| 258 | |||
| 259 | if (nreq == 0) { | ||
| 260 | cinfo->completion_ops->error_cleanup(NFS_I(inode)); | ||
| 261 | goto out; | ||
| 262 | } | ||
| 263 | |||
| 264 | atomic_add(nreq, &cinfo->mds->rpcs_out); | ||
| 265 | |||
| 266 | list_for_each_entry_safe(data, tmp, &list, pages) { | ||
| 267 | list_del_init(&data->pages); | ||
| 268 | if (!data->lseg) { | ||
| 269 | nfs_init_commit(data, mds_pages, NULL, cinfo); | ||
| 270 | nfs_initiate_commit(NFS_CLIENT(inode), data, | ||
| 271 | NFS_PROTO(data->inode), | ||
| 272 | data->mds_ops, how, 0); | ||
| 273 | } else { | ||
| 274 | struct pnfs_commit_bucket *buckets; | ||
| 275 | |||
| 276 | buckets = cinfo->ds->buckets; | ||
| 277 | nfs_init_commit(data, | ||
| 278 | &buckets[data->ds_commit_index].committing, | ||
| 279 | data->lseg, | ||
| 280 | cinfo); | ||
| 281 | initiate_commit(data, how); | ||
| 282 | } | ||
| 283 | } | ||
| 284 | out: | ||
| 285 | cinfo->ds->ncommitting = 0; | ||
| 286 | return PNFS_ATTEMPTED; | ||
| 287 | } | ||
| 288 | EXPORT_SYMBOL_GPL(pnfs_generic_commit_pagelist); | ||
| 289 | |||
| 290 | /* | ||
| 291 | * Data server cache | ||
| 292 | * | ||
| 293 | * Data servers can be mapped to different device ids. | ||
| 294 | * nfs4_pnfs_ds reference counting | ||
| 295 | * - set to 1 on allocation | ||
| 296 | * - incremented when a device id maps a data server already in the cache. | ||
| 297 | * - decremented when deviceid is removed from the cache. | ||
| 298 | */ | ||
| 299 | static DEFINE_SPINLOCK(nfs4_ds_cache_lock); | ||
| 300 | static LIST_HEAD(nfs4_data_server_cache); | ||
| 301 | |||
| 302 | /* Debug routines */ | ||
| 303 | static void | ||
| 304 | print_ds(struct nfs4_pnfs_ds *ds) | ||
| 305 | { | ||
| 306 | if (ds == NULL) { | ||
| 307 | printk(KERN_WARNING "%s NULL device\n", __func__); | ||
| 308 | return; | ||
| 309 | } | ||
| 310 | printk(KERN_WARNING " ds %s\n" | ||
| 311 | " ref count %d\n" | ||
| 312 | " client %p\n" | ||
| 313 | " cl_exchange_flags %x\n", | ||
| 314 | ds->ds_remotestr, | ||
| 315 | atomic_read(&ds->ds_count), ds->ds_clp, | ||
| 316 | ds->ds_clp ? ds->ds_clp->cl_exchange_flags : 0); | ||
| 317 | } | ||
| 318 | |||
| 319 | static bool | ||
| 320 | same_sockaddr(struct sockaddr *addr1, struct sockaddr *addr2) | ||
| 321 | { | ||
| 322 | struct sockaddr_in *a, *b; | ||
| 323 | struct sockaddr_in6 *a6, *b6; | ||
| 324 | |||
| 325 | if (addr1->sa_family != addr2->sa_family) | ||
| 326 | return false; | ||
| 327 | |||
| 328 | switch (addr1->sa_family) { | ||
| 329 | case AF_INET: | ||
| 330 | a = (struct sockaddr_in *)addr1; | ||
| 331 | b = (struct sockaddr_in *)addr2; | ||
| 332 | |||
| 333 | if (a->sin_addr.s_addr == b->sin_addr.s_addr && | ||
| 334 | a->sin_port == b->sin_port) | ||
| 335 | return true; | ||
| 336 | break; | ||
| 337 | |||
| 338 | case AF_INET6: | ||
| 339 | a6 = (struct sockaddr_in6 *)addr1; | ||
| 340 | b6 = (struct sockaddr_in6 *)addr2; | ||
| 341 | |||
| 342 | /* LINKLOCAL addresses must have matching scope_id */ | ||
| 343 | if (ipv6_addr_src_scope(&a6->sin6_addr) == | ||
| 344 | IPV6_ADDR_SCOPE_LINKLOCAL && | ||
| 345 | a6->sin6_scope_id != b6->sin6_scope_id) | ||
| 346 | return false; | ||
| 347 | |||
| 348 | if (ipv6_addr_equal(&a6->sin6_addr, &b6->sin6_addr) && | ||
| 349 | a6->sin6_port == b6->sin6_port) | ||
| 350 | return true; | ||
| 351 | break; | ||
| 352 | |||
| 353 | default: | ||
| 354 | dprintk("%s: unhandled address family: %u\n", | ||
| 355 | __func__, addr1->sa_family); | ||
| 356 | return false; | ||
| 357 | } | ||
| 358 | |||
| 359 | return false; | ||
| 360 | } | ||
| 361 | |||
| 362 | static bool | ||
| 363 | _same_data_server_addrs_locked(const struct list_head *dsaddrs1, | ||
| 364 | const struct list_head *dsaddrs2) | ||
| 365 | { | ||
| 366 | struct nfs4_pnfs_ds_addr *da1, *da2; | ||
| 367 | |||
| 368 | /* step through both lists, comparing as we go */ | ||
| 369 | for (da1 = list_first_entry(dsaddrs1, typeof(*da1), da_node), | ||
| 370 | da2 = list_first_entry(dsaddrs2, typeof(*da2), da_node); | ||
| 371 | da1 != NULL && da2 != NULL; | ||
| 372 | da1 = list_entry(da1->da_node.next, typeof(*da1), da_node), | ||
| 373 | da2 = list_entry(da2->da_node.next, typeof(*da2), da_node)) { | ||
| 374 | if (!same_sockaddr((struct sockaddr *)&da1->da_addr, | ||
| 375 | (struct sockaddr *)&da2->da_addr)) | ||
| 376 | return false; | ||
| 377 | } | ||
| 378 | if (da1 == NULL && da2 == NULL) | ||
| 379 | return true; | ||
| 380 | |||
| 381 | return false; | ||
| 382 | } | ||
| 383 | |||
| 384 | /* | ||
| 385 | * Lookup DS by addresses. nfs4_ds_cache_lock is held | ||
| 386 | */ | ||
| 387 | static struct nfs4_pnfs_ds * | ||
| 388 | _data_server_lookup_locked(const struct list_head *dsaddrs) | ||
| 389 | { | ||
| 390 | struct nfs4_pnfs_ds *ds; | ||
| 391 | |||
| 392 | list_for_each_entry(ds, &nfs4_data_server_cache, ds_node) | ||
| 393 | if (_same_data_server_addrs_locked(&ds->ds_addrs, dsaddrs)) | ||
| 394 | return ds; | ||
| 395 | return NULL; | ||
| 396 | } | ||
| 397 | |||
| 398 | static void destroy_ds(struct nfs4_pnfs_ds *ds) | ||
| 399 | { | ||
| 400 | struct nfs4_pnfs_ds_addr *da; | ||
| 401 | |||
| 402 | dprintk("--> %s\n", __func__); | ||
| 403 | ifdebug(FACILITY) | ||
| 404 | print_ds(ds); | ||
| 405 | |||
| 406 | nfs_put_client(ds->ds_clp); | ||
| 407 | |||
| 408 | while (!list_empty(&ds->ds_addrs)) { | ||
| 409 | da = list_first_entry(&ds->ds_addrs, | ||
| 410 | struct nfs4_pnfs_ds_addr, | ||
| 411 | da_node); | ||
| 412 | list_del_init(&da->da_node); | ||
| 413 | kfree(da->da_remotestr); | ||
| 414 | kfree(da); | ||
| 415 | } | ||
| 416 | |||
| 417 | kfree(ds->ds_remotestr); | ||
| 418 | kfree(ds); | ||
| 419 | } | ||
| 420 | |||
| 421 | void nfs4_pnfs_ds_put(struct nfs4_pnfs_ds *ds) | ||
| 422 | { | ||
| 423 | if (atomic_dec_and_lock(&ds->ds_count, | ||
| 424 | &nfs4_ds_cache_lock)) { | ||
| 425 | list_del_init(&ds->ds_node); | ||
| 426 | spin_unlock(&nfs4_ds_cache_lock); | ||
| 427 | destroy_ds(ds); | ||
| 428 | } | ||
| 429 | } | ||
| 430 | EXPORT_SYMBOL_GPL(nfs4_pnfs_ds_put); | ||
| 431 | |||
| 432 | /* | ||
| 433 | * Create a string with a human readable address and port to avoid | ||
| 434 | * complicated setup around many dprinks. | ||
| 435 | */ | ||
| 436 | static char * | ||
| 437 | nfs4_pnfs_remotestr(struct list_head *dsaddrs, gfp_t gfp_flags) | ||
| 438 | { | ||
| 439 | struct nfs4_pnfs_ds_addr *da; | ||
| 440 | char *remotestr; | ||
| 441 | size_t len; | ||
| 442 | char *p; | ||
| 443 | |||
| 444 | len = 3; /* '{', '}' and eol */ | ||
| 445 | list_for_each_entry(da, dsaddrs, da_node) { | ||
| 446 | len += strlen(da->da_remotestr) + 1; /* string plus comma */ | ||
| 447 | } | ||
| 448 | |||
| 449 | remotestr = kzalloc(len, gfp_flags); | ||
| 450 | if (!remotestr) | ||
| 451 | return NULL; | ||
| 452 | |||
| 453 | p = remotestr; | ||
| 454 | *(p++) = '{'; | ||
| 455 | len--; | ||
| 456 | list_for_each_entry(da, dsaddrs, da_node) { | ||
| 457 | size_t ll = strlen(da->da_remotestr); | ||
| 458 | |||
| 459 | if (ll > len) | ||
| 460 | goto out_err; | ||
| 461 | |||
| 462 | memcpy(p, da->da_remotestr, ll); | ||
| 463 | p += ll; | ||
| 464 | len -= ll; | ||
| 465 | |||
| 466 | if (len < 1) | ||
| 467 | goto out_err; | ||
| 468 | (*p++) = ','; | ||
| 469 | len--; | ||
| 470 | } | ||
| 471 | if (len < 2) | ||
| 472 | goto out_err; | ||
| 473 | *(p++) = '}'; | ||
| 474 | *p = '\0'; | ||
| 475 | return remotestr; | ||
| 476 | out_err: | ||
| 477 | kfree(remotestr); | ||
| 478 | return NULL; | ||
| 479 | } | ||
| 480 | |||
| 481 | /* | ||
| 482 | * Given a list of multipath struct nfs4_pnfs_ds_addr, add it to ds cache if | ||
| 483 | * uncached and return cached struct nfs4_pnfs_ds. | ||
| 484 | */ | ||
| 485 | struct nfs4_pnfs_ds * | ||
| 486 | nfs4_pnfs_ds_add(struct list_head *dsaddrs, gfp_t gfp_flags) | ||
| 487 | { | ||
| 488 | struct nfs4_pnfs_ds *tmp_ds, *ds = NULL; | ||
| 489 | char *remotestr; | ||
| 490 | |||
| 491 | if (list_empty(dsaddrs)) { | ||
| 492 | dprintk("%s: no addresses defined\n", __func__); | ||
| 493 | goto out; | ||
| 494 | } | ||
| 495 | |||
| 496 | ds = kzalloc(sizeof(*ds), gfp_flags); | ||
| 497 | if (!ds) | ||
| 498 | goto out; | ||
| 499 | |||
| 500 | /* this is only used for debugging, so it's ok if its NULL */ | ||
| 501 | remotestr = nfs4_pnfs_remotestr(dsaddrs, gfp_flags); | ||
| 502 | |||
| 503 | spin_lock(&nfs4_ds_cache_lock); | ||
| 504 | tmp_ds = _data_server_lookup_locked(dsaddrs); | ||
| 505 | if (tmp_ds == NULL) { | ||
| 506 | INIT_LIST_HEAD(&ds->ds_addrs); | ||
| 507 | list_splice_init(dsaddrs, &ds->ds_addrs); | ||
| 508 | ds->ds_remotestr = remotestr; | ||
| 509 | atomic_set(&ds->ds_count, 1); | ||
| 510 | INIT_LIST_HEAD(&ds->ds_node); | ||
| 511 | ds->ds_clp = NULL; | ||
| 512 | list_add(&ds->ds_node, &nfs4_data_server_cache); | ||
| 513 | dprintk("%s add new data server %s\n", __func__, | ||
| 514 | ds->ds_remotestr); | ||
| 515 | } else { | ||
| 516 | kfree(remotestr); | ||
| 517 | kfree(ds); | ||
| 518 | atomic_inc(&tmp_ds->ds_count); | ||
| 519 | dprintk("%s data server %s found, inc'ed ds_count to %d\n", | ||
| 520 | __func__, tmp_ds->ds_remotestr, | ||
| 521 | atomic_read(&tmp_ds->ds_count)); | ||
| 522 | ds = tmp_ds; | ||
| 523 | } | ||
| 524 | spin_unlock(&nfs4_ds_cache_lock); | ||
| 525 | out: | ||
| 526 | return ds; | ||
| 527 | } | ||
| 528 | EXPORT_SYMBOL_GPL(nfs4_pnfs_ds_add); | ||
| 529 | |||
| 530 | static void nfs4_wait_ds_connect(struct nfs4_pnfs_ds *ds) | ||
| 531 | { | ||
| 532 | might_sleep(); | ||
| 533 | wait_on_bit(&ds->ds_state, NFS4DS_CONNECTING, | ||
| 534 | TASK_KILLABLE); | ||
| 535 | } | ||
| 536 | |||
| 537 | static void nfs4_clear_ds_conn_bit(struct nfs4_pnfs_ds *ds) | ||
| 538 | { | ||
| 539 | smp_mb__before_atomic(); | ||
| 540 | clear_bit(NFS4DS_CONNECTING, &ds->ds_state); | ||
| 541 | smp_mb__after_atomic(); | ||
| 542 | wake_up_bit(&ds->ds_state, NFS4DS_CONNECTING); | ||
| 543 | } | ||
| 544 | |||
| 545 | static struct nfs_client *(*get_v3_ds_connect)( | ||
| 546 | struct nfs_client *mds_clp, | ||
| 547 | const struct sockaddr *ds_addr, | ||
| 548 | int ds_addrlen, | ||
| 549 | int ds_proto, | ||
| 550 | unsigned int ds_timeo, | ||
| 551 | unsigned int ds_retrans, | ||
| 552 | rpc_authflavor_t au_flavor); | ||
| 553 | |||
| 554 | static bool load_v3_ds_connect(void) | ||
| 555 | { | ||
| 556 | if (!get_v3_ds_connect) { | ||
| 557 | get_v3_ds_connect = symbol_request(nfs3_set_ds_client); | ||
| 558 | WARN_ON_ONCE(!get_v3_ds_connect); | ||
| 559 | } | ||
| 560 | |||
| 561 | return(get_v3_ds_connect != NULL); | ||
| 562 | } | ||
| 563 | |||
| 564 | void __exit nfs4_pnfs_v3_ds_connect_unload(void) | ||
| 565 | { | ||
| 566 | if (get_v3_ds_connect) { | ||
| 567 | symbol_put(nfs3_set_ds_client); | ||
| 568 | get_v3_ds_connect = NULL; | ||
| 569 | } | ||
| 570 | } | ||
| 571 | EXPORT_SYMBOL_GPL(nfs4_pnfs_v3_ds_connect_unload); | ||
| 572 | |||
| 573 | static int _nfs4_pnfs_v3_ds_connect(struct nfs_server *mds_srv, | ||
| 574 | struct nfs4_pnfs_ds *ds, | ||
| 575 | unsigned int timeo, | ||
| 576 | unsigned int retrans, | ||
| 577 | rpc_authflavor_t au_flavor) | ||
| 578 | { | ||
| 579 | struct nfs_client *clp = ERR_PTR(-EIO); | ||
| 580 | struct nfs4_pnfs_ds_addr *da; | ||
| 581 | int status = 0; | ||
| 582 | |||
| 583 | dprintk("--> %s DS %s au_flavor %d\n", __func__, | ||
| 584 | ds->ds_remotestr, au_flavor); | ||
| 585 | |||
| 586 | if (!load_v3_ds_connect()) | ||
| 587 | goto out; | ||
| 588 | |||
| 589 | list_for_each_entry(da, &ds->ds_addrs, da_node) { | ||
| 590 | dprintk("%s: DS %s: trying address %s\n", | ||
| 591 | __func__, ds->ds_remotestr, da->da_remotestr); | ||
| 592 | |||
| 593 | clp = get_v3_ds_connect(mds_srv->nfs_client, | ||
| 594 | (struct sockaddr *)&da->da_addr, | ||
| 595 | da->da_addrlen, IPPROTO_TCP, | ||
| 596 | timeo, retrans, au_flavor); | ||
| 597 | if (!IS_ERR(clp)) | ||
| 598 | break; | ||
| 599 | } | ||
| 600 | |||
| 601 | if (IS_ERR(clp)) { | ||
| 602 | status = PTR_ERR(clp); | ||
| 603 | goto out; | ||
| 604 | } | ||
| 605 | |||
| 606 | smp_wmb(); | ||
| 607 | ds->ds_clp = clp; | ||
| 608 | dprintk("%s [new] addr: %s\n", __func__, ds->ds_remotestr); | ||
| 609 | out: | ||
| 610 | return status; | ||
| 611 | } | ||
| 612 | |||
| 613 | static int _nfs4_pnfs_v4_ds_connect(struct nfs_server *mds_srv, | ||
| 614 | struct nfs4_pnfs_ds *ds, | ||
| 615 | unsigned int timeo, | ||
| 616 | unsigned int retrans, | ||
| 617 | u32 minor_version, | ||
| 618 | rpc_authflavor_t au_flavor) | ||
| 619 | { | ||
| 620 | struct nfs_client *clp = ERR_PTR(-EIO); | ||
| 621 | struct nfs4_pnfs_ds_addr *da; | ||
| 622 | int status = 0; | ||
| 623 | |||
| 624 | dprintk("--> %s DS %s au_flavor %d\n", __func__, ds->ds_remotestr, | ||
| 625 | au_flavor); | ||
| 626 | |||
| 627 | list_for_each_entry(da, &ds->ds_addrs, da_node) { | ||
| 628 | dprintk("%s: DS %s: trying address %s\n", | ||
| 629 | __func__, ds->ds_remotestr, da->da_remotestr); | ||
| 630 | |||
| 631 | clp = nfs4_set_ds_client(mds_srv->nfs_client, | ||
| 632 | (struct sockaddr *)&da->da_addr, | ||
| 633 | da->da_addrlen, IPPROTO_TCP, | ||
| 634 | timeo, retrans, minor_version, | ||
| 635 | au_flavor); | ||
| 636 | if (!IS_ERR(clp)) | ||
| 637 | break; | ||
| 638 | } | ||
| 639 | |||
| 640 | if (IS_ERR(clp)) { | ||
| 641 | status = PTR_ERR(clp); | ||
| 642 | goto out; | ||
| 643 | } | ||
| 644 | |||
| 645 | status = nfs4_init_ds_session(clp, mds_srv->nfs_client->cl_lease_time); | ||
| 646 | if (status) | ||
| 647 | goto out_put; | ||
| 648 | |||
| 649 | smp_wmb(); | ||
| 650 | ds->ds_clp = clp; | ||
| 651 | dprintk("%s [new] addr: %s\n", __func__, ds->ds_remotestr); | ||
| 652 | out: | ||
| 653 | return status; | ||
| 654 | out_put: | ||
| 655 | nfs_put_client(clp); | ||
| 656 | goto out; | ||
| 657 | } | ||
| 658 | |||
| 659 | /* | ||
| 660 | * Create an rpc connection to the nfs4_pnfs_ds data server. | ||
| 661 | * Currently only supports IPv4 and IPv6 addresses. | ||
| 662 | * If connection fails, make devid unavailable. | ||
| 663 | */ | ||
| 664 | void nfs4_pnfs_ds_connect(struct nfs_server *mds_srv, struct nfs4_pnfs_ds *ds, | ||
| 665 | struct nfs4_deviceid_node *devid, unsigned int timeo, | ||
| 666 | unsigned int retrans, u32 version, | ||
| 667 | u32 minor_version, rpc_authflavor_t au_flavor) | ||
| 668 | { | ||
| 669 | if (test_and_set_bit(NFS4DS_CONNECTING, &ds->ds_state) == 0) { | ||
| 670 | int err = 0; | ||
| 671 | |||
| 672 | if (version == 3) { | ||
| 673 | err = _nfs4_pnfs_v3_ds_connect(mds_srv, ds, timeo, | ||
| 674 | retrans, au_flavor); | ||
| 675 | } else if (version == 4) { | ||
| 676 | err = _nfs4_pnfs_v4_ds_connect(mds_srv, ds, timeo, | ||
| 677 | retrans, minor_version, | ||
| 678 | au_flavor); | ||
| 679 | } else { | ||
| 680 | dprintk("%s: unsupported DS version %d\n", __func__, | ||
| 681 | version); | ||
| 682 | err = -EPROTONOSUPPORT; | ||
| 683 | } | ||
| 684 | |||
| 685 | if (err) | ||
| 686 | nfs4_mark_deviceid_unavailable(devid); | ||
| 687 | nfs4_clear_ds_conn_bit(ds); | ||
| 688 | } else { | ||
| 689 | nfs4_wait_ds_connect(ds); | ||
| 690 | } | ||
| 691 | } | ||
| 692 | EXPORT_SYMBOL_GPL(nfs4_pnfs_ds_connect); | ||
| 693 | |||
| 694 | /* | ||
| 695 | * Currently only supports ipv4, ipv6 and one multi-path address. | ||
| 696 | */ | ||
| 697 | struct nfs4_pnfs_ds_addr * | ||
| 698 | nfs4_decode_mp_ds_addr(struct net *net, struct xdr_stream *xdr, gfp_t gfp_flags) | ||
| 699 | { | ||
| 700 | struct nfs4_pnfs_ds_addr *da = NULL; | ||
| 701 | char *buf, *portstr; | ||
| 702 | __be16 port; | ||
| 703 | int nlen, rlen; | ||
| 704 | int tmp[2]; | ||
| 705 | __be32 *p; | ||
| 706 | char *netid, *match_netid; | ||
| 707 | size_t len, match_netid_len; | ||
| 708 | char *startsep = ""; | ||
| 709 | char *endsep = ""; | ||
| 710 | |||
| 711 | |||
| 712 | /* r_netid */ | ||
| 713 | p = xdr_inline_decode(xdr, 4); | ||
| 714 | if (unlikely(!p)) | ||
| 715 | goto out_err; | ||
| 716 | nlen = be32_to_cpup(p++); | ||
| 717 | |||
| 718 | p = xdr_inline_decode(xdr, nlen); | ||
| 719 | if (unlikely(!p)) | ||
| 720 | goto out_err; | ||
| 721 | |||
| 722 | netid = kmalloc(nlen+1, gfp_flags); | ||
| 723 | if (unlikely(!netid)) | ||
| 724 | goto out_err; | ||
| 725 | |||
| 726 | netid[nlen] = '\0'; | ||
| 727 | memcpy(netid, p, nlen); | ||
| 728 | |||
| 729 | /* r_addr: ip/ip6addr with port in dec octets - see RFC 5665 */ | ||
| 730 | p = xdr_inline_decode(xdr, 4); | ||
| 731 | if (unlikely(!p)) | ||
| 732 | goto out_free_netid; | ||
| 733 | rlen = be32_to_cpup(p); | ||
| 734 | |||
| 735 | p = xdr_inline_decode(xdr, rlen); | ||
| 736 | if (unlikely(!p)) | ||
| 737 | goto out_free_netid; | ||
| 738 | |||
| 739 | /* port is ".ABC.DEF", 8 chars max */ | ||
| 740 | if (rlen > INET6_ADDRSTRLEN + IPV6_SCOPE_ID_LEN + 8) { | ||
| 741 | dprintk("%s: Invalid address, length %d\n", __func__, | ||
| 742 | rlen); | ||
| 743 | goto out_free_netid; | ||
| 744 | } | ||
| 745 | buf = kmalloc(rlen + 1, gfp_flags); | ||
| 746 | if (!buf) { | ||
| 747 | dprintk("%s: Not enough memory\n", __func__); | ||
| 748 | goto out_free_netid; | ||
| 749 | } | ||
| 750 | buf[rlen] = '\0'; | ||
| 751 | memcpy(buf, p, rlen); | ||
| 752 | |||
| 753 | /* replace port '.' with '-' */ | ||
| 754 | portstr = strrchr(buf, '.'); | ||
| 755 | if (!portstr) { | ||
| 756 | dprintk("%s: Failed finding expected dot in port\n", | ||
| 757 | __func__); | ||
| 758 | goto out_free_buf; | ||
| 759 | } | ||
| 760 | *portstr = '-'; | ||
| 761 | |||
| 762 | /* find '.' between address and port */ | ||
| 763 | portstr = strrchr(buf, '.'); | ||
| 764 | if (!portstr) { | ||
| 765 | dprintk("%s: Failed finding expected dot between address and " | ||
| 766 | "port\n", __func__); | ||
| 767 | goto out_free_buf; | ||
| 768 | } | ||
| 769 | *portstr = '\0'; | ||
| 770 | |||
| 771 | da = kzalloc(sizeof(*da), gfp_flags); | ||
| 772 | if (unlikely(!da)) | ||
| 773 | goto out_free_buf; | ||
| 774 | |||
| 775 | INIT_LIST_HEAD(&da->da_node); | ||
| 776 | |||
| 777 | if (!rpc_pton(net, buf, portstr-buf, (struct sockaddr *)&da->da_addr, | ||
| 778 | sizeof(da->da_addr))) { | ||
| 779 | dprintk("%s: error parsing address %s\n", __func__, buf); | ||
| 780 | goto out_free_da; | ||
| 781 | } | ||
| 782 | |||
| 783 | portstr++; | ||
| 784 | sscanf(portstr, "%d-%d", &tmp[0], &tmp[1]); | ||
| 785 | port = htons((tmp[0] << 8) | (tmp[1])); | ||
| 786 | |||
| 787 | switch (da->da_addr.ss_family) { | ||
| 788 | case AF_INET: | ||
| 789 | ((struct sockaddr_in *)&da->da_addr)->sin_port = port; | ||
| 790 | da->da_addrlen = sizeof(struct sockaddr_in); | ||
| 791 | match_netid = "tcp"; | ||
| 792 | match_netid_len = 3; | ||
| 793 | break; | ||
| 794 | |||
| 795 | case AF_INET6: | ||
| 796 | ((struct sockaddr_in6 *)&da->da_addr)->sin6_port = port; | ||
| 797 | da->da_addrlen = sizeof(struct sockaddr_in6); | ||
| 798 | match_netid = "tcp6"; | ||
| 799 | match_netid_len = 4; | ||
| 800 | startsep = "["; | ||
| 801 | endsep = "]"; | ||
| 802 | break; | ||
| 803 | |||
| 804 | default: | ||
| 805 | dprintk("%s: unsupported address family: %u\n", | ||
| 806 | __func__, da->da_addr.ss_family); | ||
| 807 | goto out_free_da; | ||
| 808 | } | ||
| 809 | |||
| 810 | if (nlen != match_netid_len || strncmp(netid, match_netid, nlen)) { | ||
| 811 | dprintk("%s: ERROR: r_netid \"%s\" != \"%s\"\n", | ||
| 812 | __func__, netid, match_netid); | ||
| 813 | goto out_free_da; | ||
| 814 | } | ||
| 815 | |||
| 816 | /* save human readable address */ | ||
| 817 | len = strlen(startsep) + strlen(buf) + strlen(endsep) + 7; | ||
| 818 | da->da_remotestr = kzalloc(len, gfp_flags); | ||
| 819 | |||
| 820 | /* NULL is ok, only used for dprintk */ | ||
| 821 | if (da->da_remotestr) | ||
| 822 | snprintf(da->da_remotestr, len, "%s%s%s:%u", startsep, | ||
| 823 | buf, endsep, ntohs(port)); | ||
| 824 | |||
| 825 | dprintk("%s: Parsed DS addr %s\n", __func__, da->da_remotestr); | ||
| 826 | kfree(buf); | ||
| 827 | kfree(netid); | ||
| 828 | return da; | ||
| 829 | |||
| 830 | out_free_da: | ||
| 831 | kfree(da); | ||
| 832 | out_free_buf: | ||
| 833 | dprintk("%s: Error parsing DS addr: %s\n", __func__, buf); | ||
| 834 | kfree(buf); | ||
| 835 | out_free_netid: | ||
| 836 | kfree(netid); | ||
| 837 | out_err: | ||
| 838 | return NULL; | ||
| 839 | } | ||
| 840 | EXPORT_SYMBOL_GPL(nfs4_decode_mp_ds_addr); | ||
diff --git a/fs/nfs/read.c b/fs/nfs/read.c index c91a4799c562..568ecf0a880f 100644 --- a/fs/nfs/read.c +++ b/fs/nfs/read.c | |||
| @@ -70,8 +70,15 @@ EXPORT_SYMBOL_GPL(nfs_pageio_init_read); | |||
| 70 | 70 | ||
| 71 | void nfs_pageio_reset_read_mds(struct nfs_pageio_descriptor *pgio) | 71 | void nfs_pageio_reset_read_mds(struct nfs_pageio_descriptor *pgio) |
| 72 | { | 72 | { |
| 73 | struct nfs_pgio_mirror *mirror; | ||
| 74 | |||
| 73 | pgio->pg_ops = &nfs_pgio_rw_ops; | 75 | pgio->pg_ops = &nfs_pgio_rw_ops; |
| 74 | pgio->pg_bsize = NFS_SERVER(pgio->pg_inode)->rsize; | 76 | |
| 77 | /* read path should never have more than one mirror */ | ||
| 78 | WARN_ON_ONCE(pgio->pg_mirror_count != 1); | ||
| 79 | |||
| 80 | mirror = &pgio->pg_mirrors[0]; | ||
| 81 | mirror->pg_bsize = NFS_SERVER(pgio->pg_inode)->rsize; | ||
| 75 | } | 82 | } |
| 76 | EXPORT_SYMBOL_GPL(nfs_pageio_reset_read_mds); | 83 | EXPORT_SYMBOL_GPL(nfs_pageio_reset_read_mds); |
| 77 | 84 | ||
| @@ -81,6 +88,7 @@ int nfs_readpage_async(struct nfs_open_context *ctx, struct inode *inode, | |||
| 81 | struct nfs_page *new; | 88 | struct nfs_page *new; |
| 82 | unsigned int len; | 89 | unsigned int len; |
| 83 | struct nfs_pageio_descriptor pgio; | 90 | struct nfs_pageio_descriptor pgio; |
| 91 | struct nfs_pgio_mirror *pgm; | ||
| 84 | 92 | ||
| 85 | len = nfs_page_length(page); | 93 | len = nfs_page_length(page); |
| 86 | if (len == 0) | 94 | if (len == 0) |
| @@ -97,7 +105,13 @@ int nfs_readpage_async(struct nfs_open_context *ctx, struct inode *inode, | |||
| 97 | &nfs_async_read_completion_ops); | 105 | &nfs_async_read_completion_ops); |
| 98 | nfs_pageio_add_request(&pgio, new); | 106 | nfs_pageio_add_request(&pgio, new); |
| 99 | nfs_pageio_complete(&pgio); | 107 | nfs_pageio_complete(&pgio); |
| 100 | NFS_I(inode)->read_io += pgio.pg_bytes_written; | 108 | |
| 109 | /* It doesn't make sense to do mirrored reads! */ | ||
| 110 | WARN_ON_ONCE(pgio.pg_mirror_count != 1); | ||
| 111 | |||
| 112 | pgm = &pgio.pg_mirrors[0]; | ||
| 113 | NFS_I(inode)->read_io += pgm->pg_bytes_written; | ||
| 114 | |||
| 101 | return 0; | 115 | return 0; |
| 102 | } | 116 | } |
| 103 | 117 | ||
| @@ -168,13 +182,14 @@ out: | |||
| 168 | 182 | ||
| 169 | static void nfs_initiate_read(struct nfs_pgio_header *hdr, | 183 | static void nfs_initiate_read(struct nfs_pgio_header *hdr, |
| 170 | struct rpc_message *msg, | 184 | struct rpc_message *msg, |
| 185 | const struct nfs_rpc_ops *rpc_ops, | ||
| 171 | struct rpc_task_setup *task_setup_data, int how) | 186 | struct rpc_task_setup *task_setup_data, int how) |
| 172 | { | 187 | { |
| 173 | struct inode *inode = hdr->inode; | 188 | struct inode *inode = hdr->inode; |
| 174 | int swap_flags = IS_SWAPFILE(inode) ? NFS_RPC_SWAPFLAGS : 0; | 189 | int swap_flags = IS_SWAPFILE(inode) ? NFS_RPC_SWAPFLAGS : 0; |
| 175 | 190 | ||
| 176 | task_setup_data->flags |= swap_flags; | 191 | task_setup_data->flags |= swap_flags; |
| 177 | NFS_PROTO(inode)->read_setup(hdr, msg); | 192 | rpc_ops->read_setup(hdr, msg); |
| 178 | } | 193 | } |
| 179 | 194 | ||
| 180 | static void | 195 | static void |
| @@ -351,6 +366,7 @@ int nfs_readpages(struct file *filp, struct address_space *mapping, | |||
| 351 | struct list_head *pages, unsigned nr_pages) | 366 | struct list_head *pages, unsigned nr_pages) |
| 352 | { | 367 | { |
| 353 | struct nfs_pageio_descriptor pgio; | 368 | struct nfs_pageio_descriptor pgio; |
| 369 | struct nfs_pgio_mirror *pgm; | ||
| 354 | struct nfs_readdesc desc = { | 370 | struct nfs_readdesc desc = { |
| 355 | .pgio = &pgio, | 371 | .pgio = &pgio, |
| 356 | }; | 372 | }; |
| @@ -386,10 +402,15 @@ int nfs_readpages(struct file *filp, struct address_space *mapping, | |||
| 386 | &nfs_async_read_completion_ops); | 402 | &nfs_async_read_completion_ops); |
| 387 | 403 | ||
| 388 | ret = read_cache_pages(mapping, pages, readpage_async_filler, &desc); | 404 | ret = read_cache_pages(mapping, pages, readpage_async_filler, &desc); |
| 389 | |||
| 390 | nfs_pageio_complete(&pgio); | 405 | nfs_pageio_complete(&pgio); |
| 391 | NFS_I(inode)->read_io += pgio.pg_bytes_written; | 406 | |
| 392 | npages = (pgio.pg_bytes_written + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; | 407 | /* It doesn't make sense to do mirrored reads! */ |
| 408 | WARN_ON_ONCE(pgio.pg_mirror_count != 1); | ||
| 409 | |||
| 410 | pgm = &pgio.pg_mirrors[0]; | ||
| 411 | NFS_I(inode)->read_io += pgm->pg_bytes_written; | ||
| 412 | npages = (pgm->pg_bytes_written + PAGE_CACHE_SIZE - 1) >> | ||
| 413 | PAGE_CACHE_SHIFT; | ||
| 393 | nfs_add_stats(inode, NFSIOS_READPAGES, npages); | 414 | nfs_add_stats(inode, NFSIOS_READPAGES, npages); |
| 394 | read_complete: | 415 | read_complete: |
| 395 | put_nfs_open_context(desc.ctx); | 416 | put_nfs_open_context(desc.ctx); |
diff --git a/fs/nfs/write.c b/fs/nfs/write.c index af3af685a9e3..ceacfeeb28c2 100644 --- a/fs/nfs/write.c +++ b/fs/nfs/write.c | |||
| @@ -473,13 +473,18 @@ try_again: | |||
| 473 | do { | 473 | do { |
| 474 | /* | 474 | /* |
| 475 | * Subrequests are always contiguous, non overlapping | 475 | * Subrequests are always contiguous, non overlapping |
| 476 | * and in order. If not, it's a programming error. | 476 | * and in order - but may be repeated (mirrored writes). |
| 477 | */ | 477 | */ |
| 478 | WARN_ON_ONCE(subreq->wb_offset != | 478 | if (subreq->wb_offset == (head->wb_offset + total_bytes)) { |
| 479 | (head->wb_offset + total_bytes)); | 479 | /* keep track of how many bytes this group covers */ |
| 480 | 480 | total_bytes += subreq->wb_bytes; | |
| 481 | /* keep track of how many bytes this group covers */ | 481 | } else if (WARN_ON_ONCE(subreq->wb_offset < head->wb_offset || |
| 482 | total_bytes += subreq->wb_bytes; | 482 | ((subreq->wb_offset + subreq->wb_bytes) > |
| 483 | (head->wb_offset + total_bytes)))) { | ||
| 484 | nfs_page_group_unlock(head); | ||
| 485 | spin_unlock(&inode->i_lock); | ||
| 486 | return ERR_PTR(-EIO); | ||
| 487 | } | ||
| 483 | 488 | ||
| 484 | if (!nfs_lock_request(subreq)) { | 489 | if (!nfs_lock_request(subreq)) { |
| 485 | /* releases page group bit lock and | 490 | /* releases page group bit lock and |
| @@ -842,9 +847,9 @@ EXPORT_SYMBOL_GPL(nfs_init_cinfo); | |||
| 842 | */ | 847 | */ |
| 843 | void | 848 | void |
| 844 | nfs_mark_request_commit(struct nfs_page *req, struct pnfs_layout_segment *lseg, | 849 | nfs_mark_request_commit(struct nfs_page *req, struct pnfs_layout_segment *lseg, |
| 845 | struct nfs_commit_info *cinfo) | 850 | struct nfs_commit_info *cinfo, u32 ds_commit_idx) |
| 846 | { | 851 | { |
| 847 | if (pnfs_mark_request_commit(req, lseg, cinfo)) | 852 | if (pnfs_mark_request_commit(req, lseg, cinfo, ds_commit_idx)) |
| 848 | return; | 853 | return; |
| 849 | nfs_request_add_commit_list(req, &cinfo->mds->list, cinfo); | 854 | nfs_request_add_commit_list(req, &cinfo->mds->list, cinfo); |
| 850 | } | 855 | } |
| @@ -900,7 +905,8 @@ static void nfs_write_completion(struct nfs_pgio_header *hdr) | |||
| 900 | } | 905 | } |
| 901 | if (nfs_write_need_commit(hdr)) { | 906 | if (nfs_write_need_commit(hdr)) { |
| 902 | memcpy(&req->wb_verf, &hdr->verf.verifier, sizeof(req->wb_verf)); | 907 | memcpy(&req->wb_verf, &hdr->verf.verifier, sizeof(req->wb_verf)); |
| 903 | nfs_mark_request_commit(req, hdr->lseg, &cinfo); | 908 | nfs_mark_request_commit(req, hdr->lseg, &cinfo, |
| 909 | hdr->pgio_mirror_idx); | ||
| 904 | goto next; | 910 | goto next; |
| 905 | } | 911 | } |
| 906 | remove_req: | 912 | remove_req: |
| @@ -1240,15 +1246,15 @@ static int flush_task_priority(int how) | |||
| 1240 | 1246 | ||
| 1241 | static void nfs_initiate_write(struct nfs_pgio_header *hdr, | 1247 | static void nfs_initiate_write(struct nfs_pgio_header *hdr, |
| 1242 | struct rpc_message *msg, | 1248 | struct rpc_message *msg, |
| 1249 | const struct nfs_rpc_ops *rpc_ops, | ||
| 1243 | struct rpc_task_setup *task_setup_data, int how) | 1250 | struct rpc_task_setup *task_setup_data, int how) |
| 1244 | { | 1251 | { |
| 1245 | struct inode *inode = hdr->inode; | ||
| 1246 | int priority = flush_task_priority(how); | 1252 | int priority = flush_task_priority(how); |
| 1247 | 1253 | ||
| 1248 | task_setup_data->priority = priority; | 1254 | task_setup_data->priority = priority; |
| 1249 | NFS_PROTO(inode)->write_setup(hdr, msg); | 1255 | rpc_ops->write_setup(hdr, msg); |
| 1250 | 1256 | ||
| 1251 | nfs4_state_protect_write(NFS_SERVER(inode)->nfs_client, | 1257 | nfs4_state_protect_write(NFS_SERVER(hdr->inode)->nfs_client, |
| 1252 | &task_setup_data->rpc_client, msg, hdr); | 1258 | &task_setup_data->rpc_client, msg, hdr); |
| 1253 | } | 1259 | } |
| 1254 | 1260 | ||
| @@ -1298,8 +1304,14 @@ EXPORT_SYMBOL_GPL(nfs_pageio_init_write); | |||
| 1298 | 1304 | ||
| 1299 | void nfs_pageio_reset_write_mds(struct nfs_pageio_descriptor *pgio) | 1305 | void nfs_pageio_reset_write_mds(struct nfs_pageio_descriptor *pgio) |
| 1300 | { | 1306 | { |
| 1307 | struct nfs_pgio_mirror *mirror; | ||
| 1308 | |||
| 1301 | pgio->pg_ops = &nfs_pgio_rw_ops; | 1309 | pgio->pg_ops = &nfs_pgio_rw_ops; |
| 1302 | pgio->pg_bsize = NFS_SERVER(pgio->pg_inode)->wsize; | 1310 | |
| 1311 | nfs_pageio_stop_mirroring(pgio); | ||
| 1312 | |||
| 1313 | mirror = &pgio->pg_mirrors[0]; | ||
| 1314 | mirror->pg_bsize = NFS_SERVER(pgio->pg_inode)->wsize; | ||
| 1303 | } | 1315 | } |
| 1304 | EXPORT_SYMBOL_GPL(nfs_pageio_reset_write_mds); | 1316 | EXPORT_SYMBOL_GPL(nfs_pageio_reset_write_mds); |
| 1305 | 1317 | ||
| @@ -1465,6 +1477,7 @@ void nfs_commitdata_release(struct nfs_commit_data *data) | |||
| 1465 | EXPORT_SYMBOL_GPL(nfs_commitdata_release); | 1477 | EXPORT_SYMBOL_GPL(nfs_commitdata_release); |
| 1466 | 1478 | ||
| 1467 | int nfs_initiate_commit(struct rpc_clnt *clnt, struct nfs_commit_data *data, | 1479 | int nfs_initiate_commit(struct rpc_clnt *clnt, struct nfs_commit_data *data, |
| 1480 | const struct nfs_rpc_ops *nfs_ops, | ||
| 1468 | const struct rpc_call_ops *call_ops, | 1481 | const struct rpc_call_ops *call_ops, |
| 1469 | int how, int flags) | 1482 | int how, int flags) |
| 1470 | { | 1483 | { |
| @@ -1486,7 +1499,7 @@ int nfs_initiate_commit(struct rpc_clnt *clnt, struct nfs_commit_data *data, | |||
| 1486 | .priority = priority, | 1499 | .priority = priority, |
| 1487 | }; | 1500 | }; |
| 1488 | /* Set up the initial task struct. */ | 1501 | /* Set up the initial task struct. */ |
| 1489 | NFS_PROTO(data->inode)->commit_setup(data, &msg); | 1502 | nfs_ops->commit_setup(data, &msg); |
| 1490 | 1503 | ||
| 1491 | dprintk("NFS: %5u initiated commit call\n", data->task.tk_pid); | 1504 | dprintk("NFS: %5u initiated commit call\n", data->task.tk_pid); |
| 1492 | 1505 | ||
| @@ -1554,14 +1567,15 @@ EXPORT_SYMBOL_GPL(nfs_init_commit); | |||
| 1554 | 1567 | ||
| 1555 | void nfs_retry_commit(struct list_head *page_list, | 1568 | void nfs_retry_commit(struct list_head *page_list, |
| 1556 | struct pnfs_layout_segment *lseg, | 1569 | struct pnfs_layout_segment *lseg, |
| 1557 | struct nfs_commit_info *cinfo) | 1570 | struct nfs_commit_info *cinfo, |
| 1571 | u32 ds_commit_idx) | ||
| 1558 | { | 1572 | { |
| 1559 | struct nfs_page *req; | 1573 | struct nfs_page *req; |
| 1560 | 1574 | ||
| 1561 | while (!list_empty(page_list)) { | 1575 | while (!list_empty(page_list)) { |
| 1562 | req = nfs_list_entry(page_list->next); | 1576 | req = nfs_list_entry(page_list->next); |
| 1563 | nfs_list_remove_request(req); | 1577 | nfs_list_remove_request(req); |
| 1564 | nfs_mark_request_commit(req, lseg, cinfo); | 1578 | nfs_mark_request_commit(req, lseg, cinfo, ds_commit_idx); |
| 1565 | if (!cinfo->dreq) { | 1579 | if (!cinfo->dreq) { |
| 1566 | dec_zone_page_state(req->wb_page, NR_UNSTABLE_NFS); | 1580 | dec_zone_page_state(req->wb_page, NR_UNSTABLE_NFS); |
| 1567 | dec_bdi_stat(page_file_mapping(req->wb_page)->backing_dev_info, | 1581 | dec_bdi_stat(page_file_mapping(req->wb_page)->backing_dev_info, |
| @@ -1589,10 +1603,10 @@ nfs_commit_list(struct inode *inode, struct list_head *head, int how, | |||
| 1589 | /* Set up the argument struct */ | 1603 | /* Set up the argument struct */ |
| 1590 | nfs_init_commit(data, head, NULL, cinfo); | 1604 | nfs_init_commit(data, head, NULL, cinfo); |
| 1591 | atomic_inc(&cinfo->mds->rpcs_out); | 1605 | atomic_inc(&cinfo->mds->rpcs_out); |
| 1592 | return nfs_initiate_commit(NFS_CLIENT(inode), data, data->mds_ops, | 1606 | return nfs_initiate_commit(NFS_CLIENT(inode), data, NFS_PROTO(inode), |
| 1593 | how, 0); | 1607 | data->mds_ops, how, 0); |
| 1594 | out_bad: | 1608 | out_bad: |
| 1595 | nfs_retry_commit(head, NULL, cinfo); | 1609 | nfs_retry_commit(head, NULL, cinfo, 0); |
| 1596 | cinfo->completion_ops->error_cleanup(NFS_I(inode)); | 1610 | cinfo->completion_ops->error_cleanup(NFS_I(inode)); |
| 1597 | return -ENOMEM; | 1611 | return -ENOMEM; |
| 1598 | } | 1612 | } |
diff --git a/include/linux/nfs4.h b/include/linux/nfs4.h index 022b761dbf0a..de7c91ca427e 100644 --- a/include/linux/nfs4.h +++ b/include/linux/nfs4.h | |||
| @@ -516,6 +516,7 @@ enum pnfs_layouttype { | |||
| 516 | LAYOUT_NFSV4_1_FILES = 1, | 516 | LAYOUT_NFSV4_1_FILES = 1, |
| 517 | LAYOUT_OSD2_OBJECTS = 2, | 517 | LAYOUT_OSD2_OBJECTS = 2, |
| 518 | LAYOUT_BLOCK_VOLUME = 3, | 518 | LAYOUT_BLOCK_VOLUME = 3, |
| 519 | LAYOUT_FLEX_FILES = 4, | ||
| 519 | }; | 520 | }; |
| 520 | 521 | ||
| 521 | /* used for both layout return and recall */ | 522 | /* used for both layout return and recall */ |
diff --git a/include/linux/nfs_fs_sb.h b/include/linux/nfs_fs_sb.h index ddea982355f3..5e1273d4de14 100644 --- a/include/linux/nfs_fs_sb.h +++ b/include/linux/nfs_fs_sb.h | |||
| @@ -77,10 +77,6 @@ struct nfs_client { | |||
| 77 | /* Client owner identifier */ | 77 | /* Client owner identifier */ |
| 78 | const char * cl_owner_id; | 78 | const char * cl_owner_id; |
| 79 | 79 | ||
| 80 | /* Our own IP address, as a null-terminated string. | ||
| 81 | * This is used to generate the mv0 callback address. | ||
| 82 | */ | ||
| 83 | char cl_ipaddr[48]; | ||
| 84 | u32 cl_cb_ident; /* v4.0 callback identifier */ | 80 | u32 cl_cb_ident; /* v4.0 callback identifier */ |
| 85 | const struct nfs4_minor_version_ops *cl_mvops; | 81 | const struct nfs4_minor_version_ops *cl_mvops; |
| 86 | unsigned long cl_mig_gen; | 82 | unsigned long cl_mig_gen; |
| @@ -108,6 +104,11 @@ struct nfs_client { | |||
| 108 | #define NFS_SP4_MACH_CRED_COMMIT 6 /* COMMIT */ | 104 | #define NFS_SP4_MACH_CRED_COMMIT 6 /* COMMIT */ |
| 109 | #endif /* CONFIG_NFS_V4 */ | 105 | #endif /* CONFIG_NFS_V4 */ |
| 110 | 106 | ||
| 107 | /* Our own IP address, as a null-terminated string. | ||
| 108 | * This is used to generate the mv0 callback address. | ||
| 109 | */ | ||
| 110 | char cl_ipaddr[48]; | ||
| 111 | |||
| 111 | #ifdef CONFIG_NFS_FSCACHE | 112 | #ifdef CONFIG_NFS_FSCACHE |
| 112 | struct fscache_cookie *fscache; /* client index cache cookie */ | 113 | struct fscache_cookie *fscache; /* client index cache cookie */ |
| 113 | #endif | 114 | #endif |
diff --git a/include/linux/nfs_idmap.h b/include/linux/nfs_idmap.h index 0f4b79da6584..333844e38f66 100644 --- a/include/linux/nfs_idmap.h +++ b/include/linux/nfs_idmap.h | |||
| @@ -73,5 +73,7 @@ int nfs_map_group_to_gid(const struct nfs_server *, const char *, size_t, kgid_t | |||
| 73 | int nfs_map_uid_to_name(const struct nfs_server *, kuid_t, char *, size_t); | 73 | int nfs_map_uid_to_name(const struct nfs_server *, kuid_t, char *, size_t); |
| 74 | int nfs_map_gid_to_group(const struct nfs_server *, kgid_t, char *, size_t); | 74 | int nfs_map_gid_to_group(const struct nfs_server *, kgid_t, char *, size_t); |
| 75 | 75 | ||
| 76 | int nfs_map_string_to_numeric(const char *name, size_t namelen, __u32 *res); | ||
| 77 | |||
| 76 | extern unsigned int nfs_idmap_cache_timeout; | 78 | extern unsigned int nfs_idmap_cache_timeout; |
| 77 | #endif /* NFS_IDMAP_H */ | 79 | #endif /* NFS_IDMAP_H */ |
diff --git a/include/linux/nfs_page.h b/include/linux/nfs_page.h index 6c3e06ee2fb7..3eb072dbce83 100644 --- a/include/linux/nfs_page.h +++ b/include/linux/nfs_page.h | |||
| @@ -58,6 +58,9 @@ struct nfs_pageio_ops { | |||
| 58 | size_t (*pg_test)(struct nfs_pageio_descriptor *, struct nfs_page *, | 58 | size_t (*pg_test)(struct nfs_pageio_descriptor *, struct nfs_page *, |
| 59 | struct nfs_page *); | 59 | struct nfs_page *); |
| 60 | int (*pg_doio)(struct nfs_pageio_descriptor *); | 60 | int (*pg_doio)(struct nfs_pageio_descriptor *); |
| 61 | unsigned int (*pg_get_mirror_count)(struct nfs_pageio_descriptor *, | ||
| 62 | struct nfs_page *); | ||
| 63 | void (*pg_cleanup)(struct nfs_pageio_descriptor *); | ||
| 61 | }; | 64 | }; |
| 62 | 65 | ||
| 63 | struct nfs_rw_ops { | 66 | struct nfs_rw_ops { |
| @@ -69,18 +72,21 @@ struct nfs_rw_ops { | |||
| 69 | struct inode *); | 72 | struct inode *); |
| 70 | void (*rw_result)(struct rpc_task *, struct nfs_pgio_header *); | 73 | void (*rw_result)(struct rpc_task *, struct nfs_pgio_header *); |
| 71 | void (*rw_initiate)(struct nfs_pgio_header *, struct rpc_message *, | 74 | void (*rw_initiate)(struct nfs_pgio_header *, struct rpc_message *, |
| 75 | const struct nfs_rpc_ops *, | ||
| 72 | struct rpc_task_setup *, int); | 76 | struct rpc_task_setup *, int); |
| 73 | }; | 77 | }; |
| 74 | 78 | ||
| 75 | struct nfs_pageio_descriptor { | 79 | struct nfs_pgio_mirror { |
| 76 | struct list_head pg_list; | 80 | struct list_head pg_list; |
| 77 | unsigned long pg_bytes_written; | 81 | unsigned long pg_bytes_written; |
| 78 | size_t pg_count; | 82 | size_t pg_count; |
| 79 | size_t pg_bsize; | 83 | size_t pg_bsize; |
| 80 | unsigned int pg_base; | 84 | unsigned int pg_base; |
| 81 | unsigned char pg_moreio : 1, | 85 | unsigned char pg_recoalesce : 1; |
| 82 | pg_recoalesce : 1; | 86 | }; |
| 83 | 87 | ||
| 88 | struct nfs_pageio_descriptor { | ||
| 89 | unsigned char pg_moreio : 1; | ||
| 84 | struct inode *pg_inode; | 90 | struct inode *pg_inode; |
| 85 | const struct nfs_pageio_ops *pg_ops; | 91 | const struct nfs_pageio_ops *pg_ops; |
| 86 | const struct nfs_rw_ops *pg_rw_ops; | 92 | const struct nfs_rw_ops *pg_rw_ops; |
| @@ -91,8 +97,18 @@ struct nfs_pageio_descriptor { | |||
| 91 | struct pnfs_layout_segment *pg_lseg; | 97 | struct pnfs_layout_segment *pg_lseg; |
| 92 | struct nfs_direct_req *pg_dreq; | 98 | struct nfs_direct_req *pg_dreq; |
| 93 | void *pg_layout_private; | 99 | void *pg_layout_private; |
| 100 | unsigned int pg_bsize; /* default bsize for mirrors */ | ||
| 101 | |||
| 102 | u32 pg_mirror_count; | ||
| 103 | struct nfs_pgio_mirror *pg_mirrors; | ||
| 104 | struct nfs_pgio_mirror pg_mirrors_static[1]; | ||
| 105 | struct nfs_pgio_mirror *pg_mirrors_dynamic; | ||
| 106 | u32 pg_mirror_idx; /* current mirror */ | ||
| 94 | }; | 107 | }; |
| 95 | 108 | ||
| 109 | /* arbitrarily selected limit to number of mirrors */ | ||
| 110 | #define NFS_PAGEIO_DESCRIPTOR_MIRROR_MAX 16 | ||
| 111 | |||
| 96 | #define NFS_WBACK_BUSY(req) (test_bit(PG_BUSY,&(req)->wb_flags)) | 112 | #define NFS_WBACK_BUSY(req) (test_bit(PG_BUSY,&(req)->wb_flags)) |
| 97 | 113 | ||
| 98 | extern struct nfs_page *nfs_create_request(struct nfs_open_context *ctx, | 114 | extern struct nfs_page *nfs_create_request(struct nfs_open_context *ctx, |
diff --git a/include/linux/nfs_xdr.h b/include/linux/nfs_xdr.h index e5c3b620a609..81401125ab2d 100644 --- a/include/linux/nfs_xdr.h +++ b/include/linux/nfs_xdr.h | |||
| @@ -293,6 +293,7 @@ struct nfs4_layoutreturn_args { | |||
| 293 | struct nfs4_sequence_args seq_args; | 293 | struct nfs4_sequence_args seq_args; |
| 294 | struct pnfs_layout_hdr *layout; | 294 | struct pnfs_layout_hdr *layout; |
| 295 | struct inode *inode; | 295 | struct inode *inode; |
| 296 | struct pnfs_layout_range range; | ||
| 296 | nfs4_stateid stateid; | 297 | nfs4_stateid stateid; |
| 297 | __u32 layout_type; | 298 | __u32 layout_type; |
| 298 | }; | 299 | }; |
| @@ -514,6 +515,7 @@ struct nfs_pgio_res { | |||
| 514 | struct nfs4_sequence_res seq_res; | 515 | struct nfs4_sequence_res seq_res; |
| 515 | struct nfs_fattr * fattr; | 516 | struct nfs_fattr * fattr; |
| 516 | __u32 count; | 517 | __u32 count; |
| 518 | __u32 op_status; | ||
| 517 | int eof; /* used by read */ | 519 | int eof; /* used by read */ |
| 518 | struct nfs_writeverf * verf; /* used by write */ | 520 | struct nfs_writeverf * verf; /* used by write */ |
| 519 | const struct nfs_server *server; /* used by write */ | 521 | const struct nfs_server *server; /* used by write */ |
| @@ -533,6 +535,7 @@ struct nfs_commitargs { | |||
| 533 | 535 | ||
| 534 | struct nfs_commitres { | 536 | struct nfs_commitres { |
| 535 | struct nfs4_sequence_res seq_res; | 537 | struct nfs4_sequence_res seq_res; |
| 538 | __u32 op_status; | ||
| 536 | struct nfs_fattr *fattr; | 539 | struct nfs_fattr *fattr; |
| 537 | struct nfs_writeverf *verf; | 540 | struct nfs_writeverf *verf; |
| 538 | const struct nfs_server *server; | 541 | const struct nfs_server *server; |
| @@ -1326,7 +1329,8 @@ struct nfs_pgio_header { | |||
| 1326 | __u64 mds_offset; /* Filelayout dense stripe */ | 1329 | __u64 mds_offset; /* Filelayout dense stripe */ |
| 1327 | struct nfs_page_array page_array; | 1330 | struct nfs_page_array page_array; |
| 1328 | struct nfs_client *ds_clp; /* pNFS data server */ | 1331 | struct nfs_client *ds_clp; /* pNFS data server */ |
| 1329 | int ds_idx; /* ds index if ds_clp is set */ | 1332 | int ds_commit_idx; /* ds index if ds_clp is set */ |
| 1333 | int pgio_mirror_idx;/* mirror index in pgio layer */ | ||
| 1330 | }; | 1334 | }; |
| 1331 | 1335 | ||
| 1332 | struct nfs_mds_commit_info { | 1336 | struct nfs_mds_commit_info { |
diff --git a/include/linux/sunrpc/metrics.h b/include/linux/sunrpc/metrics.h index eecb5a71e6c0..7e61a17030a4 100644 --- a/include/linux/sunrpc/metrics.h +++ b/include/linux/sunrpc/metrics.h | |||
| @@ -79,6 +79,8 @@ struct rpc_clnt; | |||
| 79 | struct rpc_iostats * rpc_alloc_iostats(struct rpc_clnt *); | 79 | struct rpc_iostats * rpc_alloc_iostats(struct rpc_clnt *); |
| 80 | void rpc_count_iostats(const struct rpc_task *, | 80 | void rpc_count_iostats(const struct rpc_task *, |
| 81 | struct rpc_iostats *); | 81 | struct rpc_iostats *); |
| 82 | void rpc_count_iostats_metrics(const struct rpc_task *, | ||
| 83 | struct rpc_iostats *); | ||
| 82 | void rpc_print_iostats(struct seq_file *, struct rpc_clnt *); | 84 | void rpc_print_iostats(struct seq_file *, struct rpc_clnt *); |
| 83 | void rpc_free_iostats(struct rpc_iostats *); | 85 | void rpc_free_iostats(struct rpc_iostats *); |
| 84 | 86 | ||
| @@ -87,6 +89,8 @@ void rpc_free_iostats(struct rpc_iostats *); | |||
| 87 | static inline struct rpc_iostats *rpc_alloc_iostats(struct rpc_clnt *clnt) { return NULL; } | 89 | static inline struct rpc_iostats *rpc_alloc_iostats(struct rpc_clnt *clnt) { return NULL; } |
| 88 | static inline void rpc_count_iostats(const struct rpc_task *task, | 90 | static inline void rpc_count_iostats(const struct rpc_task *task, |
| 89 | struct rpc_iostats *stats) {} | 91 | struct rpc_iostats *stats) {} |
| 92 | static inline void rpc_count_iostats_metrics(const struct rpc_task *, | ||
| 93 | struct rpc_iostats *) {} | ||
| 90 | static inline void rpc_print_iostats(struct seq_file *seq, struct rpc_clnt *clnt) {} | 94 | static inline void rpc_print_iostats(struct seq_file *seq, struct rpc_clnt *clnt) {} |
| 91 | static inline void rpc_free_iostats(struct rpc_iostats *stats) {} | 95 | static inline void rpc_free_iostats(struct rpc_iostats *stats) {} |
| 92 | 96 | ||
diff --git a/net/sunrpc/stats.c b/net/sunrpc/stats.c index 9711a155bc50..2ecb994314c1 100644 --- a/net/sunrpc/stats.c +++ b/net/sunrpc/stats.c | |||
| @@ -140,22 +140,20 @@ void rpc_free_iostats(struct rpc_iostats *stats) | |||
| 140 | EXPORT_SYMBOL_GPL(rpc_free_iostats); | 140 | EXPORT_SYMBOL_GPL(rpc_free_iostats); |
| 141 | 141 | ||
| 142 | /** | 142 | /** |
| 143 | * rpc_count_iostats - tally up per-task stats | 143 | * rpc_count_iostats_metrics - tally up per-task stats |
| 144 | * @task: completed rpc_task | 144 | * @task: completed rpc_task |
| 145 | * @stats: array of stat structures | 145 | * @op_metrics: stat structure for OP that will accumulate stats from @task |
| 146 | */ | 146 | */ |
| 147 | void rpc_count_iostats(const struct rpc_task *task, struct rpc_iostats *stats) | 147 | void rpc_count_iostats_metrics(const struct rpc_task *task, |
| 148 | struct rpc_iostats *op_metrics) | ||
| 148 | { | 149 | { |
| 149 | struct rpc_rqst *req = task->tk_rqstp; | 150 | struct rpc_rqst *req = task->tk_rqstp; |
| 150 | struct rpc_iostats *op_metrics; | ||
| 151 | ktime_t delta, now; | 151 | ktime_t delta, now; |
| 152 | 152 | ||
| 153 | if (!stats || !req) | 153 | if (!op_metrics || !req) |
| 154 | return; | 154 | return; |
| 155 | 155 | ||
| 156 | now = ktime_get(); | 156 | now = ktime_get(); |
| 157 | op_metrics = &stats[task->tk_msg.rpc_proc->p_statidx]; | ||
| 158 | |||
| 159 | spin_lock(&op_metrics->om_lock); | 157 | spin_lock(&op_metrics->om_lock); |
| 160 | 158 | ||
| 161 | op_metrics->om_ops++; | 159 | op_metrics->om_ops++; |
| @@ -175,6 +173,20 @@ void rpc_count_iostats(const struct rpc_task *task, struct rpc_iostats *stats) | |||
| 175 | 173 | ||
| 176 | spin_unlock(&op_metrics->om_lock); | 174 | spin_unlock(&op_metrics->om_lock); |
| 177 | } | 175 | } |
| 176 | EXPORT_SYMBOL_GPL(rpc_count_iostats_metrics); | ||
| 177 | |||
| 178 | /** | ||
| 179 | * rpc_count_iostats - tally up per-task stats | ||
| 180 | * @task: completed rpc_task | ||
| 181 | * @stats: array of stat structures | ||
| 182 | * | ||
| 183 | * Uses the statidx from @task | ||
| 184 | */ | ||
| 185 | void rpc_count_iostats(const struct rpc_task *task, struct rpc_iostats *stats) | ||
| 186 | { | ||
| 187 | rpc_count_iostats_metrics(task, | ||
| 188 | &stats[task->tk_msg.rpc_proc->p_statidx]); | ||
| 189 | } | ||
| 178 | EXPORT_SYMBOL_GPL(rpc_count_iostats); | 190 | EXPORT_SYMBOL_GPL(rpc_count_iostats); |
| 179 | 191 | ||
| 180 | static void _print_name(struct seq_file *seq, unsigned int op, | 192 | static void _print_name(struct seq_file *seq, unsigned int op, |
