diff options
Diffstat (limited to 'fs/nfs')
38 files changed, 4682 insertions, 1283 deletions
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/callback.c b/fs/nfs/callback.c index b8fb3a4ef649..351be9205bf8 100644 --- a/fs/nfs/callback.c +++ b/fs/nfs/callback.c | |||
| @@ -128,22 +128,24 @@ nfs41_callback_svc(void *vrqstp) | |||
| 128 | if (try_to_freeze()) | 128 | if (try_to_freeze()) |
| 129 | continue; | 129 | continue; |
| 130 | 130 | ||
| 131 | prepare_to_wait(&serv->sv_cb_waitq, &wq, TASK_INTERRUPTIBLE); | 131 | prepare_to_wait(&serv->sv_cb_waitq, &wq, TASK_UNINTERRUPTIBLE); |
| 132 | spin_lock_bh(&serv->sv_cb_lock); | 132 | spin_lock_bh(&serv->sv_cb_lock); |
| 133 | if (!list_empty(&serv->sv_cb_list)) { | 133 | if (!list_empty(&serv->sv_cb_list)) { |
| 134 | req = list_first_entry(&serv->sv_cb_list, | 134 | req = list_first_entry(&serv->sv_cb_list, |
| 135 | struct rpc_rqst, rq_bc_list); | 135 | struct rpc_rqst, rq_bc_list); |
| 136 | list_del(&req->rq_bc_list); | 136 | list_del(&req->rq_bc_list); |
| 137 | spin_unlock_bh(&serv->sv_cb_lock); | 137 | spin_unlock_bh(&serv->sv_cb_lock); |
| 138 | finish_wait(&serv->sv_cb_waitq, &wq); | ||
| 138 | dprintk("Invoking bc_svc_process()\n"); | 139 | dprintk("Invoking bc_svc_process()\n"); |
| 139 | error = bc_svc_process(serv, req, rqstp); | 140 | error = bc_svc_process(serv, req, rqstp); |
| 140 | dprintk("bc_svc_process() returned w/ error code= %d\n", | 141 | dprintk("bc_svc_process() returned w/ error code= %d\n", |
| 141 | error); | 142 | error); |
| 142 | } else { | 143 | } else { |
| 143 | spin_unlock_bh(&serv->sv_cb_lock); | 144 | spin_unlock_bh(&serv->sv_cb_lock); |
| 144 | schedule(); | 145 | /* schedule_timeout to game the hung task watchdog */ |
| 146 | schedule_timeout(60 * HZ); | ||
| 147 | finish_wait(&serv->sv_cb_waitq, &wq); | ||
| 145 | } | 148 | } |
| 146 | finish_wait(&serv->sv_cb_waitq, &wq); | ||
| 147 | } | 149 | } |
| 148 | return 0; | 150 | return 0; |
| 149 | } | 151 | } |
diff --git a/fs/nfs/delegation.c b/fs/nfs/delegation.c index 7f3f60641344..da5433230bb1 100644 --- a/fs/nfs/delegation.c +++ b/fs/nfs/delegation.c | |||
| @@ -85,25 +85,30 @@ static int nfs_delegation_claim_locks(struct nfs_open_context *ctx, struct nfs4_ | |||
| 85 | { | 85 | { |
| 86 | struct inode *inode = state->inode; | 86 | struct inode *inode = state->inode; |
| 87 | struct file_lock *fl; | 87 | struct file_lock *fl; |
| 88 | struct file_lock_context *flctx = inode->i_flctx; | ||
| 89 | struct list_head *list; | ||
| 88 | int status = 0; | 90 | int status = 0; |
| 89 | 91 | ||
| 90 | if (inode->i_flock == NULL) | 92 | if (flctx == NULL) |
| 91 | goto out; | 93 | goto out; |
| 92 | 94 | ||
| 93 | /* Protect inode->i_flock using the i_lock */ | 95 | list = &flctx->flc_posix; |
| 94 | spin_lock(&inode->i_lock); | 96 | spin_lock(&flctx->flc_lock); |
| 95 | for (fl = inode->i_flock; fl != NULL; fl = fl->fl_next) { | 97 | restart: |
| 96 | if (!(fl->fl_flags & (FL_POSIX|FL_FLOCK))) | 98 | list_for_each_entry(fl, list, fl_list) { |
| 97 | continue; | ||
| 98 | if (nfs_file_open_context(fl->fl_file) != ctx) | 99 | if (nfs_file_open_context(fl->fl_file) != ctx) |
| 99 | continue; | 100 | continue; |
| 100 | spin_unlock(&inode->i_lock); | 101 | spin_unlock(&flctx->flc_lock); |
| 101 | status = nfs4_lock_delegation_recall(fl, state, stateid); | 102 | status = nfs4_lock_delegation_recall(fl, state, stateid); |
| 102 | if (status < 0) | 103 | if (status < 0) |
| 103 | goto out; | 104 | goto out; |
| 104 | spin_lock(&inode->i_lock); | 105 | spin_lock(&flctx->flc_lock); |
| 105 | } | 106 | } |
| 106 | spin_unlock(&inode->i_lock); | 107 | if (list == &flctx->flc_posix) { |
| 108 | list = &flctx->flc_flock; | ||
| 109 | goto restart; | ||
| 110 | } | ||
| 111 | spin_unlock(&flctx->flc_lock); | ||
| 107 | out: | 112 | out: |
| 108 | return status; | 113 | return status; |
| 109 | } | 114 | } |
| @@ -301,6 +306,17 @@ nfs_inode_detach_delegation(struct inode *inode) | |||
| 301 | return nfs_detach_delegation(nfsi, delegation, server); | 306 | return nfs_detach_delegation(nfsi, delegation, server); |
| 302 | } | 307 | } |
| 303 | 308 | ||
| 309 | static void | ||
| 310 | nfs_update_inplace_delegation(struct nfs_delegation *delegation, | ||
| 311 | const struct nfs_delegation *update) | ||
| 312 | { | ||
| 313 | if (nfs4_stateid_is_newer(&update->stateid, &delegation->stateid)) { | ||
| 314 | delegation->stateid.seqid = update->stateid.seqid; | ||
| 315 | smp_wmb(); | ||
| 316 | delegation->type = update->type; | ||
| 317 | } | ||
| 318 | } | ||
| 319 | |||
| 304 | /** | 320 | /** |
| 305 | * nfs_inode_set_delegation - set up a delegation on an inode | 321 | * nfs_inode_set_delegation - set up a delegation on an inode |
| 306 | * @inode: inode to which delegation applies | 322 | * @inode: inode to which delegation applies |
| @@ -334,9 +350,12 @@ int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred, struct | |||
| 334 | old_delegation = rcu_dereference_protected(nfsi->delegation, | 350 | old_delegation = rcu_dereference_protected(nfsi->delegation, |
| 335 | lockdep_is_held(&clp->cl_lock)); | 351 | lockdep_is_held(&clp->cl_lock)); |
| 336 | if (old_delegation != NULL) { | 352 | if (old_delegation != NULL) { |
| 337 | if (nfs4_stateid_match(&delegation->stateid, | 353 | /* Is this an update of the existing delegation? */ |
| 338 | &old_delegation->stateid) && | 354 | if (nfs4_stateid_match_other(&old_delegation->stateid, |
| 339 | delegation->type == old_delegation->type) { | 355 | &delegation->stateid)) { |
| 356 | nfs_update_inplace_delegation(old_delegation, | ||
| 357 | delegation); | ||
| 358 | nfsi->delegation_state = old_delegation->type; | ||
| 340 | goto out; | 359 | goto out; |
| 341 | } | 360 | } |
| 342 | /* | 361 | /* |
diff --git a/fs/nfs/direct.c b/fs/nfs/direct.c index 10bf07280f4a..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 | ||
| @@ -212,6 +253,12 @@ static int nfs_direct_cmp_commit_data_verf(struct nfs_direct_req *dreq, | |||
| 212 | */ | 253 | */ |
| 213 | ssize_t nfs_direct_IO(int rw, struct kiocb *iocb, struct iov_iter *iter, loff_t pos) | 254 | ssize_t nfs_direct_IO(int rw, struct kiocb *iocb, struct iov_iter *iter, loff_t pos) |
| 214 | { | 255 | { |
| 256 | struct inode *inode = iocb->ki_filp->f_mapping->host; | ||
| 257 | |||
| 258 | /* we only support swap file calling nfs_direct_IO */ | ||
| 259 | if (!IS_SWAPFILE(inode)) | ||
| 260 | return 0; | ||
| 261 | |||
| 215 | #ifndef CONFIG_NFS_SWAP | 262 | #ifndef CONFIG_NFS_SWAP |
| 216 | dprintk("NFS: nfs_direct_IO (%pD) off/no(%Ld/%lu) EINVAL\n", | 263 | dprintk("NFS: nfs_direct_IO (%pD) off/no(%Ld/%lu) EINVAL\n", |
| 217 | iocb->ki_filp, (long long) pos, iter->nr_segs); | 264 | iocb->ki_filp, (long long) pos, iter->nr_segs); |
| @@ -243,6 +290,18 @@ void nfs_init_cinfo_from_dreq(struct nfs_commit_info *cinfo, | |||
| 243 | cinfo->completion_ops = &nfs_direct_commit_completion_ops; | 290 | cinfo->completion_ops = &nfs_direct_commit_completion_ops; |
| 244 | } | 291 | } |
| 245 | 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 | |||
| 246 | static inline struct nfs_direct_req *nfs_direct_req_alloc(void) | 305 | static inline struct nfs_direct_req *nfs_direct_req_alloc(void) |
| 247 | { | 306 | { |
| 248 | struct nfs_direct_req *dreq; | 307 | struct nfs_direct_req *dreq; |
| @@ -257,6 +316,7 @@ static inline struct nfs_direct_req *nfs_direct_req_alloc(void) | |||
| 257 | INIT_LIST_HEAD(&dreq->mds_cinfo.list); | 316 | INIT_LIST_HEAD(&dreq->mds_cinfo.list); |
| 258 | dreq->verf.committed = NFS_INVALID_STABLE_HOW; /* not set yet */ | 317 | dreq->verf.committed = NFS_INVALID_STABLE_HOW; /* not set yet */ |
| 259 | INIT_WORK(&dreq->work, nfs_direct_write_schedule_work); | 318 | INIT_WORK(&dreq->work, nfs_direct_write_schedule_work); |
| 319 | dreq->mirror_count = 1; | ||
| 260 | spin_lock_init(&dreq->lock); | 320 | spin_lock_init(&dreq->lock); |
| 261 | 321 | ||
| 262 | return dreq; | 322 | return dreq; |
| @@ -363,7 +423,8 @@ static void nfs_direct_read_completion(struct nfs_pgio_header *hdr) | |||
| 363 | 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)) |
| 364 | dreq->error = hdr->error; | 424 | dreq->error = hdr->error; |
| 365 | else | 425 | else |
| 366 | dreq->count += hdr->good_bytes; | 426 | nfs_direct_good_bytes(dreq, hdr); |
| 427 | |||
| 367 | spin_unlock(&dreq->lock); | 428 | spin_unlock(&dreq->lock); |
| 368 | 429 | ||
| 369 | while (!list_empty(&hdr->pages)) { | 430 | while (!list_empty(&hdr->pages)) { |
| @@ -541,6 +602,7 @@ ssize_t nfs_file_direct_read(struct kiocb *iocb, struct iov_iter *iter, | |||
| 541 | 602 | ||
| 542 | dreq->inode = inode; | 603 | dreq->inode = inode; |
| 543 | dreq->bytes_left = count; | 604 | dreq->bytes_left = count; |
| 605 | dreq->io_start = pos; | ||
| 544 | 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)); |
| 545 | l_ctx = nfs_get_lock_context(dreq->ctx); | 607 | l_ctx = nfs_get_lock_context(dreq->ctx); |
| 546 | if (IS_ERR(l_ctx)) { | 608 | if (IS_ERR(l_ctx)) { |
| @@ -573,6 +635,20 @@ out: | |||
| 573 | return result; | 635 | return result; |
| 574 | } | 636 | } |
| 575 | 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 | |||
| 576 | static void nfs_direct_write_reschedule(struct nfs_direct_req *dreq) | 652 | static void nfs_direct_write_reschedule(struct nfs_direct_req *dreq) |
| 577 | { | 653 | { |
| 578 | struct nfs_pageio_descriptor desc; | 654 | struct nfs_pageio_descriptor desc; |
| @@ -580,20 +656,23 @@ static void nfs_direct_write_reschedule(struct nfs_direct_req *dreq) | |||
| 580 | LIST_HEAD(reqs); | 656 | LIST_HEAD(reqs); |
| 581 | struct nfs_commit_info cinfo; | 657 | struct nfs_commit_info cinfo; |
| 582 | LIST_HEAD(failed); | 658 | LIST_HEAD(failed); |
| 659 | int i; | ||
| 583 | 660 | ||
| 584 | nfs_init_cinfo_from_dreq(&cinfo, dreq); | 661 | nfs_init_cinfo_from_dreq(&cinfo, dreq); |
| 585 | pnfs_recover_commit_reqs(dreq->inode, &reqs, &cinfo); | 662 | nfs_direct_write_scan_commit_list(dreq->inode, &reqs, &cinfo); |
| 586 | spin_lock(cinfo.lock); | ||
| 587 | nfs_scan_commit_list(&cinfo.mds->list, &reqs, &cinfo, 0); | ||
| 588 | spin_unlock(cinfo.lock); | ||
| 589 | 663 | ||
| 590 | dreq->count = 0; | 664 | dreq->count = 0; |
| 665 | for (i = 0; i < dreq->mirror_count; i++) | ||
| 666 | dreq->mirrors[i].count = 0; | ||
| 591 | get_dreq(dreq); | 667 | get_dreq(dreq); |
| 592 | 668 | ||
| 593 | nfs_pageio_init_write(&desc, dreq->inode, FLUSH_STABLE, false, | 669 | nfs_pageio_init_write(&desc, dreq->inode, FLUSH_STABLE, false, |
| 594 | &nfs_direct_write_completion_ops); | 670 | &nfs_direct_write_completion_ops); |
| 595 | desc.pg_dreq = dreq; | 671 | desc.pg_dreq = dreq; |
| 596 | 672 | ||
| 673 | req = nfs_list_entry(reqs.next); | ||
| 674 | nfs_direct_setup_mirroring(dreq, &desc, req); | ||
| 675 | |||
| 597 | list_for_each_entry_safe(req, tmp, &reqs, wb_list) { | 676 | list_for_each_entry_safe(req, tmp, &reqs, wb_list) { |
| 598 | if (!nfs_pageio_add_request(&desc, req)) { | 677 | if (!nfs_pageio_add_request(&desc, req)) { |
| 599 | nfs_list_remove_request(req); | 678 | nfs_list_remove_request(req); |
| @@ -640,7 +719,7 @@ static void nfs_direct_commit_complete(struct nfs_commit_data *data) | |||
| 640 | nfs_list_remove_request(req); | 719 | nfs_list_remove_request(req); |
| 641 | if (dreq->flags == NFS_ODIRECT_RESCHED_WRITES) { | 720 | if (dreq->flags == NFS_ODIRECT_RESCHED_WRITES) { |
| 642 | /* Note the rewrite will go through mds */ | 721 | /* Note the rewrite will go through mds */ |
| 643 | nfs_mark_request_commit(req, NULL, &cinfo); | 722 | nfs_mark_request_commit(req, NULL, &cinfo, 0); |
| 644 | } else | 723 | } else |
| 645 | nfs_release_request(req); | 724 | nfs_release_request(req); |
| 646 | nfs_unlock_and_release_request(req); | 725 | nfs_unlock_and_release_request(req); |
| @@ -715,7 +794,7 @@ static void nfs_direct_write_completion(struct nfs_pgio_header *hdr) | |||
| 715 | dreq->error = hdr->error; | 794 | dreq->error = hdr->error; |
| 716 | } | 795 | } |
| 717 | if (dreq->error == 0) { | 796 | if (dreq->error == 0) { |
| 718 | dreq->count += hdr->good_bytes; | 797 | nfs_direct_good_bytes(dreq, hdr); |
| 719 | if (nfs_write_need_commit(hdr)) { | 798 | if (nfs_write_need_commit(hdr)) { |
| 720 | if (dreq->flags == NFS_ODIRECT_RESCHED_WRITES) | 799 | if (dreq->flags == NFS_ODIRECT_RESCHED_WRITES) |
| 721 | request_commit = true; | 800 | request_commit = true; |
| @@ -739,7 +818,8 @@ static void nfs_direct_write_completion(struct nfs_pgio_header *hdr) | |||
| 739 | nfs_list_remove_request(req); | 818 | nfs_list_remove_request(req); |
| 740 | if (request_commit) { | 819 | if (request_commit) { |
| 741 | kref_get(&req->wb_kref); | 820 | kref_get(&req->wb_kref); |
| 742 | nfs_mark_request_commit(req, hdr->lseg, &cinfo); | 821 | nfs_mark_request_commit(req, hdr->lseg, &cinfo, |
| 822 | hdr->ds_commit_idx); | ||
| 743 | } | 823 | } |
| 744 | nfs_unlock_and_release_request(req); | 824 | nfs_unlock_and_release_request(req); |
| 745 | } | 825 | } |
| @@ -820,6 +900,9 @@ static ssize_t nfs_direct_write_schedule_iovec(struct nfs_direct_req *dreq, | |||
| 820 | result = PTR_ERR(req); | 900 | result = PTR_ERR(req); |
| 821 | break; | 901 | break; |
| 822 | } | 902 | } |
| 903 | |||
| 904 | nfs_direct_setup_mirroring(dreq, &desc, req); | ||
| 905 | |||
| 823 | nfs_lock_request(req); | 906 | nfs_lock_request(req); |
| 824 | req->wb_index = pos >> PAGE_SHIFT; | 907 | req->wb_index = pos >> PAGE_SHIFT; |
| 825 | req->wb_offset = pos & ~PAGE_MASK; | 908 | req->wb_offset = pos & ~PAGE_MASK; |
| @@ -928,6 +1011,7 @@ ssize_t nfs_file_direct_write(struct kiocb *iocb, struct iov_iter *iter, | |||
| 928 | 1011 | ||
| 929 | dreq->inode = inode; | 1012 | dreq->inode = inode; |
| 930 | dreq->bytes_left = count; | 1013 | dreq->bytes_left = count; |
| 1014 | dreq->io_start = pos; | ||
| 931 | 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)); |
| 932 | l_ctx = nfs_get_lock_context(dreq->ctx); | 1016 | l_ctx = nfs_get_lock_context(dreq->ctx); |
| 933 | if (IS_ERR(l_ctx)) { | 1017 | if (IS_ERR(l_ctx)) { |
diff --git a/fs/nfs/file.c b/fs/nfs/file.c index 2ab6f00dba5b..94712fc781fa 100644 --- a/fs/nfs/file.c +++ b/fs/nfs/file.c | |||
| @@ -646,7 +646,6 @@ static const struct vm_operations_struct nfs_file_vm_ops = { | |||
| 646 | .fault = filemap_fault, | 646 | .fault = filemap_fault, |
| 647 | .map_pages = filemap_map_pages, | 647 | .map_pages = filemap_map_pages, |
| 648 | .page_mkwrite = nfs_vm_page_mkwrite, | 648 | .page_mkwrite = nfs_vm_page_mkwrite, |
| 649 | .remap_pages = generic_file_remap_pages, | ||
| 650 | }; | 649 | }; |
| 651 | 650 | ||
| 652 | static int nfs_need_sync_write(struct file *filp, struct inode *inode) | 651 | static int nfs_need_sync_write(struct file *filp, struct inode *inode) |
diff --git a/fs/nfs/filelayout/filelayout.c b/fs/nfs/filelayout/filelayout.c index 7afb52f6a25a..7ae1c263c5cf 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 | } |
| @@ -1081,7 +1002,7 @@ mds_commit: | |||
| 1081 | spin_unlock(cinfo->lock); | 1002 | spin_unlock(cinfo->lock); |
| 1082 | if (!cinfo->dreq) { | 1003 | if (!cinfo->dreq) { |
| 1083 | inc_zone_page_state(req->wb_page, NR_UNSTABLE_NFS); | 1004 | inc_zone_page_state(req->wb_page, NR_UNSTABLE_NFS); |
| 1084 | inc_bdi_stat(page_file_mapping(req->wb_page)->backing_dev_info, | 1005 | inc_bdi_stat(inode_to_bdi(page_file_mapping(req->wb_page)->host), |
| 1085 | BDI_RECLAIMABLE); | 1006 | BDI_RECLAIMABLE); |
| 1086 | __mark_inode_dirty(req->wb_context->dentry->d_inode, | 1007 | __mark_inode_dirty(req->wb_context->dentry->d_inode, |
| 1087 | I_DIRTY_DATASYNC); | 1008 | I_DIRTY_DATASYNC); |
| @@ -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..c22ecaa86c1c --- /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(inode_to_bdi(page_file_mapping(req->wb_page)->host), | ||
| 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..e2c01f204a95 --- /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 | dprintk("%s: offset %llu length %llu status %d op %d count %d\n", | ||
| 519 | __func__, err->offset, err->length, err->status, | ||
| 520 | err->opnum, *count); | ||
| 521 | kfree(err); | ||
| 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/inode.c b/fs/nfs/inode.c index 4bffe637ea32..e4f0dcef8f54 100644 --- a/fs/nfs/inode.c +++ b/fs/nfs/inode.c | |||
| @@ -352,8 +352,9 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr, st | |||
| 352 | 352 | ||
| 353 | nfs_attr_check_mountpoint(sb, fattr); | 353 | nfs_attr_check_mountpoint(sb, fattr); |
| 354 | 354 | ||
| 355 | if (((fattr->valid & NFS_ATTR_FATTR_FILEID) == 0) && | 355 | if (nfs_attr_use_mounted_on_fileid(fattr)) |
| 356 | !nfs_attr_use_mounted_on_fileid(fattr)) | 356 | fattr->fileid = fattr->mounted_on_fileid; |
| 357 | else if ((fattr->valid & NFS_ATTR_FATTR_FILEID) == 0) | ||
| 357 | goto out_no_inode; | 358 | goto out_no_inode; |
| 358 | if ((fattr->valid & NFS_ATTR_FATTR_TYPE) == 0) | 359 | if ((fattr->valid & NFS_ATTR_FATTR_TYPE) == 0) |
| 359 | goto out_no_inode; | 360 | goto out_no_inode; |
| @@ -387,7 +388,6 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr, st | |||
| 387 | if (S_ISREG(inode->i_mode)) { | 388 | if (S_ISREG(inode->i_mode)) { |
| 388 | inode->i_fop = NFS_SB(sb)->nfs_client->rpc_ops->file_ops; | 389 | inode->i_fop = NFS_SB(sb)->nfs_client->rpc_ops->file_ops; |
| 389 | inode->i_data.a_ops = &nfs_file_aops; | 390 | inode->i_data.a_ops = &nfs_file_aops; |
| 390 | inode->i_data.backing_dev_info = &NFS_SB(sb)->backing_dev_info; | ||
| 391 | } else if (S_ISDIR(inode->i_mode)) { | 391 | } else if (S_ISDIR(inode->i_mode)) { |
| 392 | inode->i_op = NFS_SB(sb)->nfs_client->rpc_ops->dir_inode_ops; | 392 | inode->i_op = NFS_SB(sb)->nfs_client->rpc_ops->dir_inode_ops; |
| 393 | inode->i_fop = &nfs_dir_operations; | 393 | inode->i_fop = &nfs_dir_operations; |
| @@ -506,10 +506,15 @@ nfs_setattr(struct dentry *dentry, struct iattr *attr) | |||
| 506 | attr->ia_valid &= ~ATTR_MODE; | 506 | attr->ia_valid &= ~ATTR_MODE; |
| 507 | 507 | ||
| 508 | if (attr->ia_valid & ATTR_SIZE) { | 508 | if (attr->ia_valid & ATTR_SIZE) { |
| 509 | loff_t i_size; | ||
| 510 | |||
| 509 | BUG_ON(!S_ISREG(inode->i_mode)); | 511 | BUG_ON(!S_ISREG(inode->i_mode)); |
| 510 | 512 | ||
| 511 | if (attr->ia_size == i_size_read(inode)) | 513 | i_size = i_size_read(inode); |
| 514 | if (attr->ia_size == i_size) | ||
| 512 | attr->ia_valid &= ~ATTR_SIZE; | 515 | attr->ia_valid &= ~ATTR_SIZE; |
| 516 | else if (attr->ia_size < i_size && IS_SWAPFILE(inode)) | ||
| 517 | return -ETXTBSY; | ||
| 513 | } | 518 | } |
| 514 | 519 | ||
| 515 | /* Optimization: if the end result is no change, don't RPC */ | 520 | /* Optimization: if the end result is no change, don't RPC */ |
diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h index efaa31c70fbe..212b8c883d22 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 | ||
| @@ -31,8 +32,6 @@ static inline int nfs_attr_use_mounted_on_fileid(struct nfs_fattr *fattr) | |||
| 31 | (((fattr->valid & NFS_ATTR_FATTR_MOUNTPOINT) == 0) && | 32 | (((fattr->valid & NFS_ATTR_FATTR_MOUNTPOINT) == 0) && |
| 32 | ((fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL) == 0))) | 33 | ((fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL) == 0))) |
| 33 | return 0; | 34 | return 0; |
| 34 | |||
| 35 | fattr->fileid = fattr->mounted_on_fileid; | ||
| 36 | return 1; | 35 | return 1; |
| 37 | } | 36 | } |
| 38 | 37 | ||
| @@ -189,9 +188,15 @@ extern struct nfs_client *nfs4_set_ds_client(struct nfs_client* mds_clp, | |||
| 189 | const struct sockaddr *ds_addr, | 188 | const struct sockaddr *ds_addr, |
| 190 | int ds_addrlen, int ds_proto, | 189 | int ds_addrlen, int ds_proto, |
| 191 | unsigned int ds_timeo, | 190 | unsigned int ds_timeo, |
| 192 | unsigned int ds_retrans); | 191 | unsigned int ds_retrans, |
| 192 | u32 minor_version, | ||
| 193 | rpc_authflavor_t au_flavor); | ||
| 193 | 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 *, |
| 194 | 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); | ||
| 195 | #ifdef CONFIG_PROC_FS | 200 | #ifdef CONFIG_PROC_FS |
| 196 | extern int __init nfs_fs_proc_init(void); | 201 | extern int __init nfs_fs_proc_init(void); |
| 197 | extern void nfs_fs_proc_exit(void); | 202 | extern void nfs_fs_proc_exit(void); |
| @@ -244,9 +249,12 @@ struct nfs_pgio_header *nfs_pgio_header_alloc(const struct nfs_rw_ops *); | |||
| 244 | void nfs_pgio_header_free(struct nfs_pgio_header *); | 249 | void nfs_pgio_header_free(struct nfs_pgio_header *); |
| 245 | void nfs_pgio_data_destroy(struct nfs_pgio_header *); | 250 | void nfs_pgio_data_destroy(struct nfs_pgio_header *); |
| 246 | 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 *); |
| 247 | 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, |
| 248 | 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); | ||
| 249 | 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); | ||
| 250 | 258 | ||
| 251 | static inline void nfs_iocounter_init(struct nfs_io_counter *c) | 259 | static inline void nfs_iocounter_init(struct nfs_io_counter *c) |
| 252 | { | 260 | { |
| @@ -254,6 +262,12 @@ static inline void nfs_iocounter_init(struct nfs_io_counter *c) | |||
| 254 | atomic_set(&c->io_count, 0); | 262 | atomic_set(&c->io_count, 0); |
| 255 | } | 263 | } |
| 256 | 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 | |||
| 257 | /* nfs2xdr.c */ | 271 | /* nfs2xdr.c */ |
| 258 | extern struct rpc_procinfo nfs_procedures[]; | 272 | extern struct rpc_procinfo nfs_procedures[]; |
| 259 | extern int nfs2_decode_dirent(struct xdr_stream *, | 273 | extern int nfs2_decode_dirent(struct xdr_stream *, |
| @@ -377,7 +391,7 @@ extern struct rpc_stat nfs_rpcstat; | |||
| 377 | 391 | ||
| 378 | extern int __init register_nfs_fs(void); | 392 | extern int __init register_nfs_fs(void); |
| 379 | extern void __exit unregister_nfs_fs(void); | 393 | extern void __exit unregister_nfs_fs(void); |
| 380 | extern void nfs_sb_active(struct super_block *sb); | 394 | extern bool nfs_sb_active(struct super_block *sb); |
| 381 | extern void nfs_sb_deactive(struct super_block *sb); | 395 | extern void nfs_sb_deactive(struct super_block *sb); |
| 382 | 396 | ||
| 383 | /* namespace.c */ | 397 | /* namespace.c */ |
| @@ -416,7 +430,6 @@ int nfs_show_options(struct seq_file *, struct dentry *); | |||
| 416 | int nfs_show_devname(struct seq_file *, struct dentry *); | 430 | int nfs_show_devname(struct seq_file *, struct dentry *); |
| 417 | int nfs_show_path(struct seq_file *, struct dentry *); | 431 | int nfs_show_path(struct seq_file *, struct dentry *); |
| 418 | int nfs_show_stats(struct seq_file *, struct dentry *); | 432 | int nfs_show_stats(struct seq_file *, struct dentry *); |
| 419 | void nfs_put_super(struct super_block *); | ||
| 420 | int nfs_remount(struct super_block *sb, int *flags, char *raw_data); | 433 | int nfs_remount(struct super_block *sb, int *flags, char *raw_data); |
| 421 | 434 | ||
| 422 | /* write.c */ | 435 | /* write.c */ |
| @@ -429,6 +442,7 @@ extern void nfs_write_prepare(struct rpc_task *task, void *calldata); | |||
| 429 | extern void nfs_commit_prepare(struct rpc_task *task, void *calldata); | 442 | extern void nfs_commit_prepare(struct rpc_task *task, void *calldata); |
| 430 | extern int nfs_initiate_commit(struct rpc_clnt *clnt, | 443 | extern int nfs_initiate_commit(struct rpc_clnt *clnt, |
| 431 | struct nfs_commit_data *data, | 444 | struct nfs_commit_data *data, |
| 445 | const struct nfs_rpc_ops *nfs_ops, | ||
| 432 | const struct rpc_call_ops *call_ops, | 446 | const struct rpc_call_ops *call_ops, |
| 433 | int how, int flags); | 447 | int how, int flags); |
| 434 | extern void nfs_init_commit(struct nfs_commit_data *data, | 448 | extern void nfs_init_commit(struct nfs_commit_data *data, |
| @@ -442,13 +456,15 @@ int nfs_scan_commit(struct inode *inode, struct list_head *dst, | |||
| 442 | struct nfs_commit_info *cinfo); | 456 | struct nfs_commit_info *cinfo); |
| 443 | void nfs_mark_request_commit(struct nfs_page *req, | 457 | void nfs_mark_request_commit(struct nfs_page *req, |
| 444 | struct pnfs_layout_segment *lseg, | 458 | struct pnfs_layout_segment *lseg, |
| 445 | struct nfs_commit_info *cinfo); | 459 | struct nfs_commit_info *cinfo, |
| 460 | u32 ds_commit_idx); | ||
| 446 | int nfs_write_need_commit(struct nfs_pgio_header *); | 461 | int nfs_write_need_commit(struct nfs_pgio_header *); |
| 447 | int nfs_generic_commit_list(struct inode *inode, struct list_head *head, | 462 | int nfs_generic_commit_list(struct inode *inode, struct list_head *head, |
| 448 | int how, struct nfs_commit_info *cinfo); | 463 | int how, struct nfs_commit_info *cinfo); |
| 449 | void nfs_retry_commit(struct list_head *page_list, | 464 | void nfs_retry_commit(struct list_head *page_list, |
| 450 | struct pnfs_layout_segment *lseg, | 465 | struct pnfs_layout_segment *lseg, |
| 451 | struct nfs_commit_info *cinfo); | 466 | struct nfs_commit_info *cinfo, |
| 467 | u32 ds_commit_idx); | ||
| 452 | void nfs_commitdata_release(struct nfs_commit_data *data); | 468 | void nfs_commitdata_release(struct nfs_commit_data *data); |
| 453 | void nfs_request_add_commit_list(struct nfs_page *req, struct list_head *dst, | 469 | void nfs_request_add_commit_list(struct nfs_page *req, struct list_head *dst, |
| 454 | struct nfs_commit_info *cinfo); | 470 | struct nfs_commit_info *cinfo); |
| @@ -459,6 +475,7 @@ void nfs_init_cinfo(struct nfs_commit_info *cinfo, | |||
| 459 | struct nfs_direct_req *dreq); | 475 | struct nfs_direct_req *dreq); |
| 460 | int nfs_key_timeout_notify(struct file *filp, struct inode *inode); | 476 | int nfs_key_timeout_notify(struct file *filp, struct inode *inode); |
| 461 | bool nfs_ctx_key_to_expire(struct nfs_open_context *ctx); | 477 | bool nfs_ctx_key_to_expire(struct nfs_open_context *ctx); |
| 478 | void nfs_pageio_stop_mirroring(struct nfs_pageio_descriptor *pgio); | ||
| 462 | 479 | ||
| 463 | #ifdef CONFIG_MIGRATION | 480 | #ifdef CONFIG_MIGRATION |
| 464 | extern int nfs_migrate_page(struct address_space *, | 481 | extern int nfs_migrate_page(struct address_space *, |
| @@ -482,6 +499,7 @@ static inline void nfs_inode_dio_wait(struct inode *inode) | |||
| 482 | inode_dio_wait(inode); | 499 | inode_dio_wait(inode); |
| 483 | } | 500 | } |
| 484 | extern ssize_t nfs_dreq_bytes_left(struct nfs_direct_req *dreq); | 501 | extern ssize_t nfs_dreq_bytes_left(struct nfs_direct_req *dreq); |
| 502 | extern void nfs_direct_set_resched_writes(struct nfs_direct_req *dreq); | ||
| 485 | 503 | ||
| 486 | /* nfs4proc.c */ | 504 | /* nfs4proc.c */ |
| 487 | extern void __nfs4_read_done_cb(struct nfs_pgio_header *); | 505 | extern void __nfs4_read_done_cb(struct nfs_pgio_header *); |
| @@ -495,6 +513,26 @@ extern int nfs41_walk_client_list(struct nfs_client *clp, | |||
| 495 | struct nfs_client **result, | 513 | struct nfs_client **result, |
| 496 | struct rpc_cred *cred); | 514 | struct rpc_cred *cred); |
| 497 | 515 | ||
| 516 | static inline struct inode *nfs_igrab_and_active(struct inode *inode) | ||
| 517 | { | ||
| 518 | inode = igrab(inode); | ||
| 519 | if (inode != NULL && !nfs_sb_active(inode->i_sb)) { | ||
| 520 | iput(inode); | ||
| 521 | inode = NULL; | ||
| 522 | } | ||
| 523 | return inode; | ||
| 524 | } | ||
| 525 | |||
| 526 | static inline void nfs_iput_and_deactive(struct inode *inode) | ||
| 527 | { | ||
| 528 | if (inode != NULL) { | ||
| 529 | struct super_block *sb = inode->i_sb; | ||
| 530 | |||
| 531 | iput(inode); | ||
| 532 | nfs_sb_deactive(sb); | ||
| 533 | } | ||
| 534 | } | ||
| 535 | |||
| 498 | /* | 536 | /* |
| 499 | * Determine the device name as a string | 537 | * Determine the device name as a string |
| 500 | */ | 538 | */ |
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 a08178764cf9..fdef424b0cd3 100644 --- a/fs/nfs/nfs4_fs.h +++ b/fs/nfs/nfs4_fs.h | |||
| @@ -44,6 +44,7 @@ enum nfs4_client_state { | |||
| 44 | #define NFS4_RENEW_TIMEOUT 0x01 | 44 | #define NFS4_RENEW_TIMEOUT 0x01 |
| 45 | #define NFS4_RENEW_DELEGATION_CB 0x02 | 45 | #define NFS4_RENEW_DELEGATION_CB 0x02 |
| 46 | 46 | ||
| 47 | struct nfs_seqid_counter; | ||
| 47 | struct nfs4_minor_version_ops { | 48 | struct nfs4_minor_version_ops { |
| 48 | u32 minor_version; | 49 | u32 minor_version; |
| 49 | unsigned init_caps; | 50 | unsigned init_caps; |
| @@ -56,6 +57,8 @@ struct nfs4_minor_version_ops { | |||
| 56 | struct nfs_fsinfo *); | 57 | struct nfs_fsinfo *); |
| 57 | void (*free_lock_state)(struct nfs_server *, | 58 | void (*free_lock_state)(struct nfs_server *, |
| 58 | struct nfs4_lock_state *); | 59 | struct nfs4_lock_state *); |
| 60 | struct nfs_seqid * | ||
| 61 | (*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); | ||
| 59 | const struct rpc_call_ops *call_sync_ops; | 62 | const struct rpc_call_ops *call_sync_ops; |
| 60 | const struct nfs4_state_recovery_ops *reboot_recovery_ops; | 63 | const struct nfs4_state_recovery_ops *reboot_recovery_ops; |
| 61 | const struct nfs4_state_recovery_ops *nograce_recovery_ops; | 64 | const struct nfs4_state_recovery_ops *nograce_recovery_ops; |
| @@ -443,6 +446,12 @@ extern void nfs_increment_open_seqid(int status, struct nfs_seqid *seqid); | |||
| 443 | 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); |
| 444 | extern void nfs_release_seqid(struct nfs_seqid *seqid); | 447 | extern void nfs_release_seqid(struct nfs_seqid *seqid); |
| 445 | 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); | ||
| 446 | 455 | ||
| 447 | 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); |
| 448 | 457 | ||
diff --git a/fs/nfs/nfs4client.c b/fs/nfs/nfs4client.c index 03311259b0c4..8646af9b11d2 100644 --- a/fs/nfs/nfs4client.c +++ b/fs/nfs/nfs4client.c | |||
| @@ -228,6 +228,7 @@ static void nfs4_shutdown_client(struct nfs_client *clp) | |||
| 228 | kfree(clp->cl_serverowner); | 228 | kfree(clp->cl_serverowner); |
| 229 | kfree(clp->cl_serverscope); | 229 | kfree(clp->cl_serverscope); |
| 230 | kfree(clp->cl_implid); | 230 | kfree(clp->cl_implid); |
| 231 | kfree(clp->cl_owner_id); | ||
| 231 | } | 232 | } |
| 232 | 233 | ||
| 233 | void nfs4_free_client(struct nfs_client *clp) | 234 | void nfs4_free_client(struct nfs_client *clp) |
| @@ -452,6 +453,14 @@ static void nfs4_swap_callback_idents(struct nfs_client *keep, | |||
| 452 | spin_unlock(&nn->nfs_client_lock); | 453 | spin_unlock(&nn->nfs_client_lock); |
| 453 | } | 454 | } |
| 454 | 455 | ||
| 456 | static bool nfs4_match_client_owner_id(const struct nfs_client *clp1, | ||
| 457 | const struct nfs_client *clp2) | ||
| 458 | { | ||
| 459 | if (clp1->cl_owner_id == NULL || clp2->cl_owner_id == NULL) | ||
| 460 | return true; | ||
| 461 | return strcmp(clp1->cl_owner_id, clp2->cl_owner_id) == 0; | ||
| 462 | } | ||
| 463 | |||
| 455 | /** | 464 | /** |
| 456 | * nfs40_walk_client_list - Find server that recognizes a client ID | 465 | * nfs40_walk_client_list - Find server that recognizes a client ID |
| 457 | * | 466 | * |
| @@ -483,9 +492,6 @@ int nfs40_walk_client_list(struct nfs_client *new, | |||
| 483 | if (pos->rpc_ops != new->rpc_ops) | 492 | if (pos->rpc_ops != new->rpc_ops) |
| 484 | continue; | 493 | continue; |
| 485 | 494 | ||
| 486 | if (pos->cl_proto != new->cl_proto) | ||
| 487 | continue; | ||
| 488 | |||
| 489 | if (pos->cl_minorversion != new->cl_minorversion) | 495 | if (pos->cl_minorversion != new->cl_minorversion) |
| 490 | continue; | 496 | continue; |
| 491 | 497 | ||
| @@ -510,6 +516,9 @@ int nfs40_walk_client_list(struct nfs_client *new, | |||
| 510 | if (pos->cl_clientid != new->cl_clientid) | 516 | if (pos->cl_clientid != new->cl_clientid) |
| 511 | continue; | 517 | continue; |
| 512 | 518 | ||
| 519 | if (!nfs4_match_client_owner_id(pos, new)) | ||
| 520 | continue; | ||
| 521 | |||
| 513 | atomic_inc(&pos->cl_count); | 522 | atomic_inc(&pos->cl_count); |
| 514 | spin_unlock(&nn->nfs_client_lock); | 523 | spin_unlock(&nn->nfs_client_lock); |
| 515 | 524 | ||
| @@ -566,20 +575,14 @@ static bool nfs4_match_clientids(struct nfs_client *a, struct nfs_client *b) | |||
| 566 | } | 575 | } |
| 567 | 576 | ||
| 568 | /* | 577 | /* |
| 569 | * Returns true if the server owners match | 578 | * Returns true if the server major ids match |
| 570 | */ | 579 | */ |
| 571 | static bool | 580 | static bool |
| 572 | nfs4_match_serverowners(struct nfs_client *a, struct nfs_client *b) | 581 | nfs4_check_clientid_trunking(struct nfs_client *a, struct nfs_client *b) |
| 573 | { | 582 | { |
| 574 | struct nfs41_server_owner *o1 = a->cl_serverowner; | 583 | struct nfs41_server_owner *o1 = a->cl_serverowner; |
| 575 | struct nfs41_server_owner *o2 = b->cl_serverowner; | 584 | struct nfs41_server_owner *o2 = b->cl_serverowner; |
| 576 | 585 | ||
| 577 | if (o1->minor_id != o2->minor_id) { | ||
| 578 | dprintk("NFS: --> %s server owner minor IDs do not match\n", | ||
| 579 | __func__); | ||
| 580 | return false; | ||
| 581 | } | ||
| 582 | |||
| 583 | if (o1->major_id_sz != o2->major_id_sz) | 586 | if (o1->major_id_sz != o2->major_id_sz) |
| 584 | goto out_major_mismatch; | 587 | goto out_major_mismatch; |
| 585 | if (memcmp(o1->major_id, o2->major_id, o1->major_id_sz) != 0) | 588 | if (memcmp(o1->major_id, o2->major_id, o1->major_id_sz) != 0) |
| @@ -621,9 +624,6 @@ int nfs41_walk_client_list(struct nfs_client *new, | |||
| 621 | if (pos->rpc_ops != new->rpc_ops) | 624 | if (pos->rpc_ops != new->rpc_ops) |
| 622 | continue; | 625 | continue; |
| 623 | 626 | ||
| 624 | if (pos->cl_proto != new->cl_proto) | ||
| 625 | continue; | ||
| 626 | |||
| 627 | if (pos->cl_minorversion != new->cl_minorversion) | 627 | if (pos->cl_minorversion != new->cl_minorversion) |
| 628 | continue; | 628 | continue; |
| 629 | 629 | ||
| @@ -639,7 +639,7 @@ int nfs41_walk_client_list(struct nfs_client *new, | |||
| 639 | prev = pos; | 639 | prev = pos; |
| 640 | 640 | ||
| 641 | status = nfs_wait_client_init_complete(pos); | 641 | status = nfs_wait_client_init_complete(pos); |
| 642 | if (status == 0) { | 642 | if (pos->cl_cons_state == NFS_CS_SESSION_INITING) { |
| 643 | nfs4_schedule_lease_recovery(pos); | 643 | nfs4_schedule_lease_recovery(pos); |
| 644 | status = nfs4_wait_clnt_recover(pos); | 644 | status = nfs4_wait_clnt_recover(pos); |
| 645 | } | 645 | } |
| @@ -654,7 +654,19 @@ int nfs41_walk_client_list(struct nfs_client *new, | |||
| 654 | if (!nfs4_match_clientids(pos, new)) | 654 | if (!nfs4_match_clientids(pos, new)) |
| 655 | continue; | 655 | continue; |
| 656 | 656 | ||
| 657 | if (!nfs4_match_serverowners(pos, new)) | 657 | /* |
| 658 | * Note that session trunking is just a special subcase of | ||
| 659 | * client id trunking. In either case, we want to fall back | ||
| 660 | * to using the existing nfs_client. | ||
| 661 | */ | ||
| 662 | if (!nfs4_check_clientid_trunking(pos, new)) | ||
| 663 | continue; | ||
| 664 | |||
| 665 | /* Unlike NFSv4.0, we know that NFSv4.1 always uses the | ||
| 666 | * uniform string, however someone might switch the | ||
| 667 | * uniquifier string on us. | ||
| 668 | */ | ||
| 669 | if (!nfs4_match_client_owner_id(pos, new)) | ||
| 658 | continue; | 670 | continue; |
| 659 | 671 | ||
| 660 | atomic_inc(&pos->cl_count); | 672 | atomic_inc(&pos->cl_count); |
| @@ -837,14 +849,15 @@ error: | |||
| 837 | */ | 849 | */ |
| 838 | 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, |
| 839 | const struct sockaddr *ds_addr, int ds_addrlen, | 851 | const struct sockaddr *ds_addr, int ds_addrlen, |
| 840 | 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) | ||
| 841 | { | 854 | { |
| 842 | struct nfs_client_initdata cl_init = { | 855 | struct nfs_client_initdata cl_init = { |
| 843 | .addr = ds_addr, | 856 | .addr = ds_addr, |
| 844 | .addrlen = ds_addrlen, | 857 | .addrlen = ds_addrlen, |
| 845 | .nfs_mod = &nfs_v4, | 858 | .nfs_mod = &nfs_v4, |
| 846 | .proto = ds_proto, | 859 | .proto = ds_proto, |
| 847 | .minorversion = mds_clp->cl_minorversion, | 860 | .minorversion = minor_version, |
| 848 | .net = mds_clp->cl_net, | 861 | .net = mds_clp->cl_net, |
| 849 | }; | 862 | }; |
| 850 | struct rpc_timeout ds_timeout; | 863 | struct rpc_timeout ds_timeout; |
| @@ -862,7 +875,7 @@ struct nfs_client *nfs4_set_ds_client(struct nfs_client* mds_clp, | |||
| 862 | */ | 875 | */ |
| 863 | 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); |
| 864 | 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, |
| 865 | mds_clp->cl_rpcclient->cl_auth->au_flavor); | 878 | au_flavor); |
| 866 | 879 | ||
| 867 | dprintk("<-- %s %p\n", __func__, clp); | 880 | dprintk("<-- %s %p\n", __func__, clp); |
| 868 | return clp; | 881 | return clp; |
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index e7f8d5ff2581..2e7c9f7a6f7c 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 | ||
| @@ -937,6 +940,31 @@ static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server, | |||
| 937 | return true; | 940 | return true; |
| 938 | } | 941 | } |
| 939 | 942 | ||
| 943 | static u32 | ||
| 944 | nfs4_map_atomic_open_share(struct nfs_server *server, | ||
| 945 | fmode_t fmode, int openflags) | ||
| 946 | { | ||
| 947 | u32 res = 0; | ||
| 948 | |||
| 949 | switch (fmode & (FMODE_READ | FMODE_WRITE)) { | ||
| 950 | case FMODE_READ: | ||
| 951 | res = NFS4_SHARE_ACCESS_READ; | ||
| 952 | break; | ||
| 953 | case FMODE_WRITE: | ||
| 954 | res = NFS4_SHARE_ACCESS_WRITE; | ||
| 955 | break; | ||
| 956 | case FMODE_READ|FMODE_WRITE: | ||
| 957 | res = NFS4_SHARE_ACCESS_BOTH; | ||
| 958 | } | ||
| 959 | if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1)) | ||
| 960 | goto out; | ||
| 961 | /* Want no delegation if we're using O_DIRECT */ | ||
| 962 | if (openflags & O_DIRECT) | ||
| 963 | res |= NFS4_SHARE_WANT_NO_DELEG; | ||
| 964 | out: | ||
| 965 | return res; | ||
| 966 | } | ||
| 967 | |||
| 940 | static enum open_claim_type4 | 968 | static enum open_claim_type4 |
| 941 | nfs4_map_atomic_open_claim(struct nfs_server *server, | 969 | nfs4_map_atomic_open_claim(struct nfs_server *server, |
| 942 | enum open_claim_type4 claim) | 970 | enum open_claim_type4 claim) |
| @@ -977,6 +1005,7 @@ static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, | |||
| 977 | struct dentry *parent = dget_parent(dentry); | 1005 | struct dentry *parent = dget_parent(dentry); |
| 978 | struct inode *dir = parent->d_inode; | 1006 | struct inode *dir = parent->d_inode; |
| 979 | struct nfs_server *server = NFS_SERVER(dir); | 1007 | struct nfs_server *server = NFS_SERVER(dir); |
| 1008 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); | ||
| 980 | struct nfs4_opendata *p; | 1009 | struct nfs4_opendata *p; |
| 981 | 1010 | ||
| 982 | p = kzalloc(sizeof(*p), gfp_mask); | 1011 | p = kzalloc(sizeof(*p), gfp_mask); |
| @@ -987,8 +1016,9 @@ static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, | |||
| 987 | if (IS_ERR(p->f_label)) | 1016 | if (IS_ERR(p->f_label)) |
| 988 | goto err_free_p; | 1017 | goto err_free_p; |
| 989 | 1018 | ||
| 990 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask); | 1019 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 991 | if (p->o_arg.seqid == NULL) | 1020 | p->o_arg.seqid = alloc_seqid(&sp->so_seqid, gfp_mask); |
| 1021 | if (IS_ERR(p->o_arg.seqid)) | ||
| 992 | goto err_free_label; | 1022 | goto err_free_label; |
| 993 | nfs_sb_active(dentry->d_sb); | 1023 | nfs_sb_active(dentry->d_sb); |
| 994 | p->dentry = dget(dentry); | 1024 | p->dentry = dget(dentry); |
| @@ -997,6 +1027,8 @@ static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, | |||
| 997 | atomic_inc(&sp->so_count); | 1027 | atomic_inc(&sp->so_count); |
| 998 | p->o_arg.open_flags = flags; | 1028 | p->o_arg.open_flags = flags; |
| 999 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); | 1029 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
| 1030 | p->o_arg.share_access = nfs4_map_atomic_open_share(server, | ||
| 1031 | fmode, flags); | ||
| 1000 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS | 1032 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 1001 | * will return permission denied for all bits until close */ | 1033 | * will return permission denied for all bits until close */ |
| 1002 | if (!(flags & O_EXCL)) { | 1034 | if (!(flags & O_EXCL)) { |
| @@ -1117,8 +1149,6 @@ static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) | |||
| 1117 | return 0; | 1149 | return 0; |
| 1118 | if ((delegation->type & fmode) != fmode) | 1150 | if ((delegation->type & fmode) != fmode) |
| 1119 | return 0; | 1151 | return 0; |
| 1120 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) | ||
| 1121 | return 0; | ||
| 1122 | if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) | 1152 | if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) |
| 1123 | return 0; | 1153 | return 0; |
| 1124 | nfs_mark_delegation_referenced(delegation); | 1154 | nfs_mark_delegation_referenced(delegation); |
| @@ -1169,6 +1199,16 @@ static bool nfs_need_update_open_stateid(struct nfs4_state *state, | |||
| 1169 | return false; | 1199 | return false; |
| 1170 | } | 1200 | } |
| 1171 | 1201 | ||
| 1202 | static void nfs_resync_open_stateid_locked(struct nfs4_state *state) | ||
| 1203 | { | ||
| 1204 | if (state->n_wronly) | ||
| 1205 | set_bit(NFS_O_WRONLY_STATE, &state->flags); | ||
| 1206 | if (state->n_rdonly) | ||
| 1207 | set_bit(NFS_O_RDONLY_STATE, &state->flags); | ||
| 1208 | if (state->n_rdwr) | ||
| 1209 | set_bit(NFS_O_RDWR_STATE, &state->flags); | ||
| 1210 | } | ||
| 1211 | |||
| 1172 | static void nfs_clear_open_stateid_locked(struct nfs4_state *state, | 1212 | static void nfs_clear_open_stateid_locked(struct nfs4_state *state, |
| 1173 | nfs4_stateid *stateid, fmode_t fmode) | 1213 | nfs4_stateid *stateid, fmode_t fmode) |
| 1174 | { | 1214 | { |
| @@ -1187,8 +1227,12 @@ static void nfs_clear_open_stateid_locked(struct nfs4_state *state, | |||
| 1187 | } | 1227 | } |
| 1188 | if (stateid == NULL) | 1228 | if (stateid == NULL) |
| 1189 | return; | 1229 | return; |
| 1190 | if (!nfs_need_update_open_stateid(state, stateid)) | 1230 | /* Handle races with OPEN */ |
| 1231 | if (!nfs4_stateid_match_other(stateid, &state->open_stateid) || | ||
| 1232 | !nfs4_stateid_is_newer(stateid, &state->open_stateid)) { | ||
| 1233 | nfs_resync_open_stateid_locked(state); | ||
| 1191 | return; | 1234 | return; |
| 1235 | } | ||
| 1192 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) | 1236 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1193 | nfs4_stateid_copy(&state->stateid, stateid); | 1237 | nfs4_stateid_copy(&state->stateid, stateid); |
| 1194 | nfs4_stateid_copy(&state->open_stateid, stateid); | 1238 | nfs4_stateid_copy(&state->open_stateid, stateid); |
| @@ -1283,6 +1327,23 @@ no_delegation: | |||
| 1283 | return ret; | 1327 | return ret; |
| 1284 | } | 1328 | } |
| 1285 | 1329 | ||
| 1330 | static bool nfs4_update_lock_stateid(struct nfs4_lock_state *lsp, | ||
| 1331 | const nfs4_stateid *stateid) | ||
| 1332 | { | ||
| 1333 | struct nfs4_state *state = lsp->ls_state; | ||
| 1334 | bool ret = false; | ||
| 1335 | |||
| 1336 | spin_lock(&state->state_lock); | ||
| 1337 | if (!nfs4_stateid_match_other(stateid, &lsp->ls_stateid)) | ||
| 1338 | goto out_noupdate; | ||
| 1339 | if (!nfs4_stateid_is_newer(stateid, &lsp->ls_stateid)) | ||
| 1340 | goto out_noupdate; | ||
| 1341 | nfs4_stateid_copy(&lsp->ls_stateid, stateid); | ||
| 1342 | ret = true; | ||
| 1343 | out_noupdate: | ||
| 1344 | spin_unlock(&state->state_lock); | ||
| 1345 | return ret; | ||
| 1346 | } | ||
| 1286 | 1347 | ||
| 1287 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) | 1348 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
| 1288 | { | 1349 | { |
| @@ -1681,8 +1742,8 @@ static void nfs4_open_confirm_prepare(struct rpc_task *task, void *calldata) | |||
| 1681 | { | 1742 | { |
| 1682 | struct nfs4_opendata *data = calldata; | 1743 | struct nfs4_opendata *data = calldata; |
| 1683 | 1744 | ||
| 1684 | nfs40_setup_sequence(data->o_arg.server, &data->c_arg.seq_args, | 1745 | nfs40_setup_sequence(data->o_arg.server->nfs_client->cl_slot_tbl, |
| 1685 | &data->c_res.seq_res, task); | 1746 | &data->c_arg.seq_args, &data->c_res.seq_res, task); |
| 1686 | } | 1747 | } |
| 1687 | 1748 | ||
| 1688 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) | 1749 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| @@ -2589,6 +2650,11 @@ static void nfs4_close_done(struct rpc_task *task, void *data) | |||
| 2589 | case -NFS4ERR_OLD_STATEID: | 2650 | case -NFS4ERR_OLD_STATEID: |
| 2590 | case -NFS4ERR_BAD_STATEID: | 2651 | case -NFS4ERR_BAD_STATEID: |
| 2591 | case -NFS4ERR_EXPIRED: | 2652 | case -NFS4ERR_EXPIRED: |
| 2653 | if (!nfs4_stateid_match(&calldata->arg.stateid, | ||
| 2654 | &state->stateid)) { | ||
| 2655 | rpc_restart_call_prepare(task); | ||
| 2656 | goto out_release; | ||
| 2657 | } | ||
| 2592 | if (calldata->arg.fmode == 0) | 2658 | if (calldata->arg.fmode == 0) |
| 2593 | break; | 2659 | break; |
| 2594 | default: | 2660 | default: |
| @@ -2621,6 +2687,7 @@ static void nfs4_close_prepare(struct rpc_task *task, void *data) | |||
| 2621 | is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); | 2687 | is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2622 | is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); | 2688 | is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2623 | is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); | 2689 | is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2690 | nfs4_stateid_copy(&calldata->arg.stateid, &state->stateid); | ||
| 2624 | /* Calculate the change in open mode */ | 2691 | /* Calculate the change in open mode */ |
| 2625 | calldata->arg.fmode = 0; | 2692 | calldata->arg.fmode = 0; |
| 2626 | if (state->n_rdwr == 0) { | 2693 | if (state->n_rdwr == 0) { |
| @@ -2655,6 +2722,9 @@ static void nfs4_close_prepare(struct rpc_task *task, void *data) | |||
| 2655 | goto out_wait; | 2722 | goto out_wait; |
| 2656 | } | 2723 | } |
| 2657 | } | 2724 | } |
| 2725 | calldata->arg.share_access = | ||
| 2726 | nfs4_map_atomic_open_share(NFS_SERVER(inode), | ||
| 2727 | calldata->arg.fmode, 0); | ||
| 2658 | 2728 | ||
| 2659 | nfs_fattr_init(calldata->res.fattr); | 2729 | nfs_fattr_init(calldata->res.fattr); |
| 2660 | calldata->timestamp = jiffies; | 2730 | calldata->timestamp = jiffies; |
| @@ -2677,45 +2747,10 @@ static const struct rpc_call_ops nfs4_close_ops = { | |||
| 2677 | .rpc_release = nfs4_free_closedata, | 2747 | .rpc_release = nfs4_free_closedata, |
| 2678 | }; | 2748 | }; |
| 2679 | 2749 | ||
| 2680 | static bool nfs4_state_has_opener(struct nfs4_state *state) | ||
| 2681 | { | ||
| 2682 | /* first check existing openers */ | ||
| 2683 | if (test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 && | ||
| 2684 | state->n_rdonly != 0) | ||
| 2685 | return true; | ||
| 2686 | |||
| 2687 | if (test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 && | ||
| 2688 | state->n_wronly != 0) | ||
| 2689 | return true; | ||
| 2690 | |||
| 2691 | if (test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 && | ||
| 2692 | state->n_rdwr != 0) | ||
| 2693 | return true; | ||
| 2694 | |||
| 2695 | return false; | ||
| 2696 | } | ||
| 2697 | |||
| 2698 | static bool nfs4_roc(struct inode *inode) | 2750 | static bool nfs4_roc(struct inode *inode) |
| 2699 | { | 2751 | { |
| 2700 | struct nfs_inode *nfsi = NFS_I(inode); | 2752 | if (!nfs_have_layout(inode)) |
| 2701 | struct nfs_open_context *ctx; | ||
| 2702 | struct nfs4_state *state; | ||
| 2703 | |||
| 2704 | spin_lock(&inode->i_lock); | ||
| 2705 | list_for_each_entry(ctx, &nfsi->open_files, list) { | ||
| 2706 | state = ctx->state; | ||
| 2707 | if (state == NULL) | ||
| 2708 | continue; | ||
| 2709 | if (nfs4_state_has_opener(state)) { | ||
| 2710 | spin_unlock(&inode->i_lock); | ||
| 2711 | return false; | ||
| 2712 | } | ||
| 2713 | } | ||
| 2714 | spin_unlock(&inode->i_lock); | ||
| 2715 | |||
| 2716 | if (nfs4_check_delegation(inode, FMODE_READ)) | ||
| 2717 | return false; | 2753 | return false; |
| 2718 | |||
| 2719 | return pnfs_roc(inode); | 2754 | return pnfs_roc(inode); |
| 2720 | } | 2755 | } |
| 2721 | 2756 | ||
| @@ -2733,6 +2768,7 @@ static bool nfs4_roc(struct inode *inode) | |||
| 2733 | int nfs4_do_close(struct nfs4_state *state, gfp_t gfp_mask, int wait) | 2768 | int nfs4_do_close(struct nfs4_state *state, gfp_t gfp_mask, int wait) |
| 2734 | { | 2769 | { |
| 2735 | struct nfs_server *server = NFS_SERVER(state->inode); | 2770 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 2771 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); | ||
| 2736 | struct nfs4_closedata *calldata; | 2772 | struct nfs4_closedata *calldata; |
| 2737 | struct nfs4_state_owner *sp = state->owner; | 2773 | struct nfs4_state_owner *sp = state->owner; |
| 2738 | struct rpc_task *task; | 2774 | struct rpc_task *task; |
| @@ -2759,10 +2795,10 @@ int nfs4_do_close(struct nfs4_state *state, gfp_t gfp_mask, int wait) | |||
| 2759 | calldata->inode = state->inode; | 2795 | calldata->inode = state->inode; |
| 2760 | calldata->state = state; | 2796 | calldata->state = state; |
| 2761 | calldata->arg.fh = NFS_FH(state->inode); | 2797 | calldata->arg.fh = NFS_FH(state->inode); |
| 2762 | calldata->arg.stateid = &state->open_stateid; | ||
| 2763 | /* Serialization for the sequence id */ | 2798 | /* Serialization for the sequence id */ |
| 2764 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); | 2799 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 2765 | if (calldata->arg.seqid == NULL) | 2800 | calldata->arg.seqid = alloc_seqid(&state->owner->so_seqid, gfp_mask); |
| 2801 | if (IS_ERR(calldata->arg.seqid)) | ||
| 2766 | goto out_free_calldata; | 2802 | goto out_free_calldata; |
| 2767 | calldata->arg.fmode = 0; | 2803 | calldata->arg.fmode = 0; |
| 2768 | calldata->arg.bitmask = server->cache_consistency_bitmask; | 2804 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
| @@ -4917,11 +4953,14 @@ static void nfs4_init_boot_verifier(const struct nfs_client *clp, | |||
| 4917 | } | 4953 | } |
| 4918 | 4954 | ||
| 4919 | static unsigned int | 4955 | static unsigned int |
| 4920 | nfs4_init_nonuniform_client_string(const struct nfs_client *clp, | 4956 | nfs4_init_nonuniform_client_string(struct nfs_client *clp, |
| 4921 | char *buf, size_t len) | 4957 | char *buf, size_t len) |
| 4922 | { | 4958 | { |
| 4923 | unsigned int result; | 4959 | unsigned int result; |
| 4924 | 4960 | ||
| 4961 | if (clp->cl_owner_id != NULL) | ||
| 4962 | return strlcpy(buf, clp->cl_owner_id, len); | ||
| 4963 | |||
| 4925 | rcu_read_lock(); | 4964 | rcu_read_lock(); |
| 4926 | result = scnprintf(buf, len, "Linux NFSv4.0 %s/%s %s", | 4965 | result = scnprintf(buf, len, "Linux NFSv4.0 %s/%s %s", |
| 4927 | clp->cl_ipaddr, | 4966 | clp->cl_ipaddr, |
| @@ -4930,24 +4969,32 @@ nfs4_init_nonuniform_client_string(const struct nfs_client *clp, | |||
| 4930 | rpc_peeraddr2str(clp->cl_rpcclient, | 4969 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4931 | RPC_DISPLAY_PROTO)); | 4970 | RPC_DISPLAY_PROTO)); |
| 4932 | rcu_read_unlock(); | 4971 | rcu_read_unlock(); |
| 4972 | clp->cl_owner_id = kstrdup(buf, GFP_KERNEL); | ||
| 4933 | return result; | 4973 | return result; |
| 4934 | } | 4974 | } |
| 4935 | 4975 | ||
| 4936 | static unsigned int | 4976 | static unsigned int |
| 4937 | nfs4_init_uniform_client_string(const struct nfs_client *clp, | 4977 | nfs4_init_uniform_client_string(struct nfs_client *clp, |
| 4938 | char *buf, size_t len) | 4978 | char *buf, size_t len) |
| 4939 | { | 4979 | { |
| 4940 | const char *nodename = clp->cl_rpcclient->cl_nodename; | 4980 | const char *nodename = clp->cl_rpcclient->cl_nodename; |
| 4981 | unsigned int result; | ||
| 4982 | |||
| 4983 | if (clp->cl_owner_id != NULL) | ||
| 4984 | return strlcpy(buf, clp->cl_owner_id, len); | ||
| 4941 | 4985 | ||
| 4942 | if (nfs4_client_id_uniquifier[0] != '\0') | 4986 | if (nfs4_client_id_uniquifier[0] != '\0') |
| 4943 | return scnprintf(buf, len, "Linux NFSv%u.%u %s/%s", | 4987 | result = scnprintf(buf, len, "Linux NFSv%u.%u %s/%s", |
| 4944 | clp->rpc_ops->version, | 4988 | clp->rpc_ops->version, |
| 4945 | clp->cl_minorversion, | 4989 | clp->cl_minorversion, |
| 4946 | nfs4_client_id_uniquifier, | 4990 | nfs4_client_id_uniquifier, |
| 4947 | nodename); | 4991 | nodename); |
| 4948 | return scnprintf(buf, len, "Linux NFSv%u.%u %s", | 4992 | else |
| 4993 | result = scnprintf(buf, len, "Linux NFSv%u.%u %s", | ||
| 4949 | clp->rpc_ops->version, clp->cl_minorversion, | 4994 | clp->rpc_ops->version, clp->cl_minorversion, |
| 4950 | nodename); | 4995 | nodename); |
| 4996 | clp->cl_owner_id = kstrdup(buf, GFP_KERNEL); | ||
| 4997 | return result; | ||
| 4951 | } | 4998 | } |
| 4952 | 4999 | ||
| 4953 | /* | 5000 | /* |
| @@ -5128,9 +5175,13 @@ static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) | |||
| 5128 | static void nfs4_delegreturn_release(void *calldata) | 5175 | static void nfs4_delegreturn_release(void *calldata) |
| 5129 | { | 5176 | { |
| 5130 | struct nfs4_delegreturndata *data = calldata; | 5177 | struct nfs4_delegreturndata *data = calldata; |
| 5178 | struct inode *inode = data->inode; | ||
| 5131 | 5179 | ||
| 5132 | if (data->roc) | 5180 | if (inode) { |
| 5133 | pnfs_roc_release(data->inode); | 5181 | if (data->roc) |
| 5182 | pnfs_roc_release(inode); | ||
| 5183 | nfs_iput_and_deactive(inode); | ||
| 5184 | } | ||
| 5134 | kfree(calldata); | 5185 | kfree(calldata); |
| 5135 | } | 5186 | } |
| 5136 | 5187 | ||
| @@ -5187,9 +5238,9 @@ static int _nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, co | |||
| 5187 | nfs_fattr_init(data->res.fattr); | 5238 | nfs_fattr_init(data->res.fattr); |
| 5188 | data->timestamp = jiffies; | 5239 | data->timestamp = jiffies; |
| 5189 | data->rpc_status = 0; | 5240 | data->rpc_status = 0; |
| 5190 | data->inode = inode; | 5241 | data->inode = nfs_igrab_and_active(inode); |
| 5191 | data->roc = list_empty(&NFS_I(inode)->open_files) ? | 5242 | if (data->inode) |
| 5192 | pnfs_roc(inode) : false; | 5243 | data->roc = nfs4_roc(inode); |
| 5193 | 5244 | ||
| 5194 | task_setup_data.callback_data = data; | 5245 | task_setup_data.callback_data = data; |
| 5195 | msg.rpc_argp = &data->args; | 5246 | msg.rpc_argp = &data->args; |
| @@ -5344,7 +5395,6 @@ static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, | |||
| 5344 | p->arg.fl = &p->fl; | 5395 | p->arg.fl = &p->fl; |
| 5345 | p->arg.seqid = seqid; | 5396 | p->arg.seqid = seqid; |
| 5346 | p->res.seqid = seqid; | 5397 | p->res.seqid = seqid; |
| 5347 | p->arg.stateid = &lsp->ls_stateid; | ||
| 5348 | p->lsp = lsp; | 5398 | p->lsp = lsp; |
| 5349 | atomic_inc(&lsp->ls_count); | 5399 | atomic_inc(&lsp->ls_count); |
| 5350 | /* Ensure we don't close file until we're done freeing locks! */ | 5400 | /* Ensure we don't close file until we're done freeing locks! */ |
| @@ -5371,14 +5421,18 @@ static void nfs4_locku_done(struct rpc_task *task, void *data) | |||
| 5371 | return; | 5421 | return; |
| 5372 | switch (task->tk_status) { | 5422 | switch (task->tk_status) { |
| 5373 | case 0: | 5423 | case 0: |
| 5374 | nfs4_stateid_copy(&calldata->lsp->ls_stateid, | ||
| 5375 | &calldata->res.stateid); | ||
| 5376 | renew_lease(calldata->server, calldata->timestamp); | 5424 | renew_lease(calldata->server, calldata->timestamp); |
| 5377 | break; | 5425 | do_vfs_lock(calldata->fl.fl_file, &calldata->fl); |
| 5426 | if (nfs4_update_lock_stateid(calldata->lsp, | ||
| 5427 | &calldata->res.stateid)) | ||
| 5428 | break; | ||
| 5378 | case -NFS4ERR_BAD_STATEID: | 5429 | case -NFS4ERR_BAD_STATEID: |
| 5379 | case -NFS4ERR_OLD_STATEID: | 5430 | case -NFS4ERR_OLD_STATEID: |
| 5380 | case -NFS4ERR_STALE_STATEID: | 5431 | case -NFS4ERR_STALE_STATEID: |
| 5381 | case -NFS4ERR_EXPIRED: | 5432 | case -NFS4ERR_EXPIRED: |
| 5433 | if (!nfs4_stateid_match(&calldata->arg.stateid, | ||
| 5434 | &calldata->lsp->ls_stateid)) | ||
| 5435 | rpc_restart_call_prepare(task); | ||
| 5382 | break; | 5436 | break; |
| 5383 | default: | 5437 | default: |
| 5384 | if (nfs4_async_handle_error(task, calldata->server, | 5438 | if (nfs4_async_handle_error(task, calldata->server, |
| @@ -5394,6 +5448,7 @@ static void nfs4_locku_prepare(struct rpc_task *task, void *data) | |||
| 5394 | 5448 | ||
| 5395 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) | 5449 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
| 5396 | goto out_wait; | 5450 | goto out_wait; |
| 5451 | nfs4_stateid_copy(&calldata->arg.stateid, &calldata->lsp->ls_stateid); | ||
| 5397 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { | 5452 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
| 5398 | /* Note: exit _without_ running nfs4_locku_done */ | 5453 | /* Note: exit _without_ running nfs4_locku_done */ |
| 5399 | goto out_no_action; | 5454 | goto out_no_action; |
| @@ -5464,6 +5519,7 @@ static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock * | |||
| 5464 | struct nfs_seqid *seqid; | 5519 | struct nfs_seqid *seqid; |
| 5465 | struct nfs4_lock_state *lsp; | 5520 | struct nfs4_lock_state *lsp; |
| 5466 | struct rpc_task *task; | 5521 | struct rpc_task *task; |
| 5522 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); | ||
| 5467 | int status = 0; | 5523 | int status = 0; |
| 5468 | unsigned char fl_flags = request->fl_flags; | 5524 | unsigned char fl_flags = request->fl_flags; |
| 5469 | 5525 | ||
| @@ -5487,9 +5543,10 @@ static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock * | |||
| 5487 | lsp = request->fl_u.nfs4_fl.owner; | 5543 | lsp = request->fl_u.nfs4_fl.owner; |
| 5488 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) | 5544 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0) |
| 5489 | goto out; | 5545 | goto out; |
| 5490 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); | 5546 | alloc_seqid = NFS_SERVER(inode)->nfs_client->cl_mvops->alloc_seqid; |
| 5547 | seqid = alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); | ||
| 5491 | status = -ENOMEM; | 5548 | status = -ENOMEM; |
| 5492 | if (seqid == NULL) | 5549 | if (IS_ERR(seqid)) |
| 5493 | goto out; | 5550 | goto out; |
| 5494 | task = nfs4_do_unlck(request, nfs_file_open_context(request->fl_file), lsp, seqid); | 5551 | task = nfs4_do_unlck(request, nfs_file_open_context(request->fl_file), lsp, seqid); |
| 5495 | status = PTR_ERR(task); | 5552 | status = PTR_ERR(task); |
| @@ -5522,6 +5579,7 @@ static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, | |||
| 5522 | struct nfs4_lockdata *p; | 5579 | struct nfs4_lockdata *p; |
| 5523 | struct inode *inode = lsp->ls_state->inode; | 5580 | struct inode *inode = lsp->ls_state->inode; |
| 5524 | struct nfs_server *server = NFS_SERVER(inode); | 5581 | struct nfs_server *server = NFS_SERVER(inode); |
| 5582 | struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t); | ||
| 5525 | 5583 | ||
| 5526 | p = kzalloc(sizeof(*p), gfp_mask); | 5584 | p = kzalloc(sizeof(*p), gfp_mask); |
| 5527 | if (p == NULL) | 5585 | if (p == NULL) |
| @@ -5530,12 +5588,12 @@ static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, | |||
| 5530 | p->arg.fh = NFS_FH(inode); | 5588 | p->arg.fh = NFS_FH(inode); |
| 5531 | p->arg.fl = &p->fl; | 5589 | p->arg.fl = &p->fl; |
| 5532 | p->arg.open_seqid = nfs_alloc_seqid(&lsp->ls_state->owner->so_seqid, gfp_mask); | 5590 | p->arg.open_seqid = nfs_alloc_seqid(&lsp->ls_state->owner->so_seqid, gfp_mask); |
| 5533 | if (p->arg.open_seqid == NULL) | 5591 | if (IS_ERR(p->arg.open_seqid)) |
| 5534 | goto out_free; | 5592 | goto out_free; |
| 5535 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); | 5593 | alloc_seqid = server->nfs_client->cl_mvops->alloc_seqid; |
| 5536 | if (p->arg.lock_seqid == NULL) | 5594 | p->arg.lock_seqid = alloc_seqid(&lsp->ls_seqid, gfp_mask); |
| 5595 | if (IS_ERR(p->arg.lock_seqid)) | ||
| 5537 | goto out_free_seqid; | 5596 | goto out_free_seqid; |
| 5538 | p->arg.lock_stateid = &lsp->ls_stateid; | ||
| 5539 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; | 5597 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 5540 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; | 5598 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
| 5541 | p->arg.lock_owner.s_dev = server->s_dev; | 5599 | p->arg.lock_owner.s_dev = server->s_dev; |
| @@ -5562,15 +5620,19 @@ static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) | |||
| 5562 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) | 5620 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
| 5563 | goto out_wait; | 5621 | goto out_wait; |
| 5564 | /* Do we need to do an open_to_lock_owner? */ | 5622 | /* Do we need to do an open_to_lock_owner? */ |
| 5565 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { | 5623 | if (!test_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags)) { |
| 5566 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { | 5624 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) { |
| 5567 | goto out_release_lock_seqid; | 5625 | goto out_release_lock_seqid; |
| 5568 | } | 5626 | } |
| 5569 | data->arg.open_stateid = &state->open_stateid; | 5627 | nfs4_stateid_copy(&data->arg.open_stateid, |
| 5628 | &state->open_stateid); | ||
| 5570 | data->arg.new_lock_owner = 1; | 5629 | data->arg.new_lock_owner = 1; |
| 5571 | data->res.open_seqid = data->arg.open_seqid; | 5630 | data->res.open_seqid = data->arg.open_seqid; |
| 5572 | } else | 5631 | } else { |
| 5573 | data->arg.new_lock_owner = 0; | 5632 | data->arg.new_lock_owner = 0; |
| 5633 | nfs4_stateid_copy(&data->arg.lock_stateid, | ||
| 5634 | &data->lsp->ls_stateid); | ||
| 5635 | } | ||
| 5574 | if (!nfs4_valid_open_stateid(state)) { | 5636 | if (!nfs4_valid_open_stateid(state)) { |
| 5575 | data->rpc_status = -EBADF; | 5637 | data->rpc_status = -EBADF; |
| 5576 | task->tk_action = NULL; | 5638 | task->tk_action = NULL; |
| @@ -5594,6 +5656,7 @@ out_wait: | |||
| 5594 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) | 5656 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 5595 | { | 5657 | { |
| 5596 | struct nfs4_lockdata *data = calldata; | 5658 | struct nfs4_lockdata *data = calldata; |
| 5659 | struct nfs4_lock_state *lsp = data->lsp; | ||
| 5597 | 5660 | ||
| 5598 | dprintk("%s: begin!\n", __func__); | 5661 | dprintk("%s: begin!\n", __func__); |
| 5599 | 5662 | ||
| @@ -5601,18 +5664,36 @@ static void nfs4_lock_done(struct rpc_task *task, void *calldata) | |||
| 5601 | return; | 5664 | return; |
| 5602 | 5665 | ||
| 5603 | data->rpc_status = task->tk_status; | 5666 | data->rpc_status = task->tk_status; |
| 5604 | if (data->arg.new_lock_owner != 0) { | 5667 | switch (task->tk_status) { |
| 5605 | if (data->rpc_status == 0) | 5668 | case 0: |
| 5606 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); | 5669 | renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), |
| 5607 | else | 5670 | data->timestamp); |
| 5608 | goto out; | 5671 | if (data->arg.new_lock) { |
| 5609 | } | 5672 | data->fl.fl_flags &= ~(FL_SLEEP | FL_ACCESS); |
| 5610 | if (data->rpc_status == 0) { | 5673 | if (do_vfs_lock(data->fl.fl_file, &data->fl) < 0) { |
| 5611 | nfs4_stateid_copy(&data->lsp->ls_stateid, &data->res.stateid); | 5674 | rpc_restart_call_prepare(task); |
| 5612 | set_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags); | 5675 | break; |
| 5613 | renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp); | 5676 | } |
| 5677 | } | ||
| 5678 | if (data->arg.new_lock_owner != 0) { | ||
| 5679 | nfs_confirm_seqid(&lsp->ls_seqid, 0); | ||
| 5680 | nfs4_stateid_copy(&lsp->ls_stateid, &data->res.stateid); | ||
| 5681 | set_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); | ||
| 5682 | } else if (!nfs4_update_lock_stateid(lsp, &data->res.stateid)) | ||
| 5683 | rpc_restart_call_prepare(task); | ||
| 5684 | break; | ||
| 5685 | case -NFS4ERR_BAD_STATEID: | ||
| 5686 | case -NFS4ERR_OLD_STATEID: | ||
| 5687 | case -NFS4ERR_STALE_STATEID: | ||
| 5688 | case -NFS4ERR_EXPIRED: | ||
| 5689 | if (data->arg.new_lock_owner != 0) { | ||
| 5690 | if (!nfs4_stateid_match(&data->arg.open_stateid, | ||
| 5691 | &lsp->ls_state->open_stateid)) | ||
| 5692 | rpc_restart_call_prepare(task); | ||
| 5693 | } else if (!nfs4_stateid_match(&data->arg.lock_stateid, | ||
| 5694 | &lsp->ls_stateid)) | ||
| 5695 | rpc_restart_call_prepare(task); | ||
| 5614 | } | 5696 | } |
| 5615 | out: | ||
| 5616 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); | 5697 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
| 5617 | } | 5698 | } |
| 5618 | 5699 | ||
| @@ -5693,7 +5774,8 @@ static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *f | |||
| 5693 | if (recovery_type == NFS_LOCK_RECLAIM) | 5774 | if (recovery_type == NFS_LOCK_RECLAIM) |
| 5694 | data->arg.reclaim = NFS_LOCK_RECLAIM; | 5775 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
| 5695 | nfs4_set_sequence_privileged(&data->arg.seq_args); | 5776 | nfs4_set_sequence_privileged(&data->arg.seq_args); |
| 5696 | } | 5777 | } else |
| 5778 | data->arg.new_lock = 1; | ||
| 5697 | task = rpc_run_task(&task_setup_data); | 5779 | task = rpc_run_task(&task_setup_data); |
| 5698 | if (IS_ERR(task)) | 5780 | if (IS_ERR(task)) |
| 5699 | return PTR_ERR(task); | 5781 | return PTR_ERR(task); |
| @@ -5817,10 +5899,8 @@ static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *reques | |||
| 5817 | 5899 | ||
| 5818 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) | 5900 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 5819 | { | 5901 | { |
| 5820 | struct nfs4_state_owner *sp = state->owner; | ||
| 5821 | struct nfs_inode *nfsi = NFS_I(state->inode); | 5902 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 5822 | unsigned char fl_flags = request->fl_flags; | 5903 | unsigned char fl_flags = request->fl_flags; |
| 5823 | unsigned int seq; | ||
| 5824 | int status = -ENOLCK; | 5904 | int status = -ENOLCK; |
| 5825 | 5905 | ||
| 5826 | if ((fl_flags & FL_POSIX) && | 5906 | if ((fl_flags & FL_POSIX) && |
| @@ -5840,25 +5920,11 @@ static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock | |||
| 5840 | /* ...but avoid races with delegation recall... */ | 5920 | /* ...but avoid races with delegation recall... */ |
| 5841 | request->fl_flags = fl_flags & ~FL_SLEEP; | 5921 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 5842 | status = do_vfs_lock(request->fl_file, request); | 5922 | status = do_vfs_lock(request->fl_file, request); |
| 5843 | goto out_unlock; | 5923 | up_read(&nfsi->rwsem); |
| 5844 | } | ||
| 5845 | seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); | ||
| 5846 | up_read(&nfsi->rwsem); | ||
| 5847 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); | ||
| 5848 | if (status != 0) | ||
| 5849 | goto out; | 5924 | goto out; |
| 5850 | down_read(&nfsi->rwsem); | ||
| 5851 | if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) { | ||
| 5852 | status = -NFS4ERR_DELAY; | ||
| 5853 | goto out_unlock; | ||
| 5854 | } | 5925 | } |
| 5855 | /* Note: we always want to sleep here! */ | ||
| 5856 | request->fl_flags = fl_flags | FL_SLEEP; | ||
| 5857 | if (do_vfs_lock(request->fl_file, request) < 0) | ||
| 5858 | printk(KERN_WARNING "NFS: %s: VFS is out of sync with lock " | ||
| 5859 | "manager!\n", __func__); | ||
| 5860 | out_unlock: | ||
| 5861 | up_read(&nfsi->rwsem); | 5926 | up_read(&nfsi->rwsem); |
| 5927 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); | ||
| 5862 | out: | 5928 | out: |
| 5863 | request->fl_flags = fl_flags; | 5929 | request->fl_flags = fl_flags; |
| 5864 | return status; | 5930 | return status; |
| @@ -5965,8 +6031,8 @@ static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata | |||
| 5965 | { | 6031 | { |
| 5966 | struct nfs_release_lockowner_data *data = calldata; | 6032 | struct nfs_release_lockowner_data *data = calldata; |
| 5967 | struct nfs_server *server = data->server; | 6033 | struct nfs_server *server = data->server; |
| 5968 | nfs40_setup_sequence(server, &data->args.seq_args, | 6034 | nfs40_setup_sequence(server->nfs_client->cl_slot_tbl, |
| 5969 | &data->res.seq_res, task); | 6035 | &data->args.seq_args, &data->res.seq_res, task); |
| 5970 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; | 6036 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 5971 | data->timestamp = jiffies; | 6037 | data->timestamp = jiffies; |
| 5972 | } | 6038 | } |
| @@ -7528,6 +7594,7 @@ nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) | |||
| 7528 | return; | 7594 | return; |
| 7529 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, | 7595 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 7530 | NFS_I(lgp->args.inode)->layout, | 7596 | NFS_I(lgp->args.inode)->layout, |
| 7597 | &lgp->args.range, | ||
| 7531 | lgp->args.ctx->state)) { | 7598 | lgp->args.ctx->state)) { |
| 7532 | rpc_exit(task, NFS4_OK); | 7599 | rpc_exit(task, NFS4_OK); |
| 7533 | } | 7600 | } |
| @@ -7783,9 +7850,13 @@ static void nfs4_layoutreturn_release(void *calldata) | |||
| 7783 | spin_lock(&lo->plh_inode->i_lock); | 7850 | spin_lock(&lo->plh_inode->i_lock); |
| 7784 | if (lrp->res.lrs_present) | 7851 | if (lrp->res.lrs_present) |
| 7785 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); | 7852 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
| 7853 | pnfs_clear_layoutreturn_waitbit(lo); | ||
| 7854 | clear_bit(NFS_LAYOUT_RETURN_BEFORE_CLOSE, &lo->plh_flags); | ||
| 7855 | rpc_wake_up(&NFS_SERVER(lo->plh_inode)->roc_rpcwaitq); | ||
| 7786 | lo->plh_block_lgets--; | 7856 | lo->plh_block_lgets--; |
| 7787 | spin_unlock(&lo->plh_inode->i_lock); | 7857 | spin_unlock(&lo->plh_inode->i_lock); |
| 7788 | pnfs_put_layout_hdr(lrp->args.layout); | 7858 | pnfs_put_layout_hdr(lrp->args.layout); |
| 7859 | nfs_iput_and_deactive(lrp->inode); | ||
| 7789 | kfree(calldata); | 7860 | kfree(calldata); |
| 7790 | dprintk("<-- %s\n", __func__); | 7861 | dprintk("<-- %s\n", __func__); |
| 7791 | } | 7862 | } |
| @@ -7796,7 +7867,7 @@ static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { | |||
| 7796 | .rpc_release = nfs4_layoutreturn_release, | 7867 | .rpc_release = nfs4_layoutreturn_release, |
| 7797 | }; | 7868 | }; |
| 7798 | 7869 | ||
| 7799 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp) | 7870 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp, bool sync) |
| 7800 | { | 7871 | { |
| 7801 | struct rpc_task *task; | 7872 | struct rpc_task *task; |
| 7802 | struct rpc_message msg = { | 7873 | struct rpc_message msg = { |
| @@ -7811,14 +7882,23 @@ int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp) | |||
| 7811 | .callback_ops = &nfs4_layoutreturn_call_ops, | 7882 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 7812 | .callback_data = lrp, | 7883 | .callback_data = lrp, |
| 7813 | }; | 7884 | }; |
| 7814 | int status; | 7885 | int status = 0; |
| 7815 | 7886 | ||
| 7816 | dprintk("--> %s\n", __func__); | 7887 | dprintk("--> %s\n", __func__); |
| 7888 | if (!sync) { | ||
| 7889 | lrp->inode = nfs_igrab_and_active(lrp->args.inode); | ||
| 7890 | if (!lrp->inode) { | ||
| 7891 | nfs4_layoutreturn_release(lrp); | ||
| 7892 | return -EAGAIN; | ||
| 7893 | } | ||
| 7894 | task_setup_data.flags |= RPC_TASK_ASYNC; | ||
| 7895 | } | ||
| 7817 | nfs4_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); | 7896 | nfs4_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
| 7818 | task = rpc_run_task(&task_setup_data); | 7897 | task = rpc_run_task(&task_setup_data); |
| 7819 | if (IS_ERR(task)) | 7898 | if (IS_ERR(task)) |
| 7820 | return PTR_ERR(task); | 7899 | return PTR_ERR(task); |
| 7821 | status = task->tk_status; | 7900 | if (sync) |
| 7901 | status = task->tk_status; | ||
| 7822 | trace_nfs4_layoutreturn(lrp->args.inode, status); | 7902 | trace_nfs4_layoutreturn(lrp->args.inode, status); |
| 7823 | dprintk("<-- %s status=%d\n", __func__, status); | 7903 | dprintk("<-- %s status=%d\n", __func__, status); |
| 7824 | rpc_put_task(task); | 7904 | rpc_put_task(task); |
| @@ -7912,6 +7992,7 @@ static void nfs4_layoutcommit_release(void *calldata) | |||
| 7912 | nfs_post_op_update_inode_force_wcc(data->args.inode, | 7992 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 7913 | data->res.fattr); | 7993 | data->res.fattr); |
| 7914 | put_rpccred(data->cred); | 7994 | put_rpccred(data->cred); |
| 7995 | nfs_iput_and_deactive(data->inode); | ||
| 7915 | kfree(data); | 7996 | kfree(data); |
| 7916 | } | 7997 | } |
| 7917 | 7998 | ||
| @@ -7936,7 +8017,6 @@ nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) | |||
| 7936 | .rpc_message = &msg, | 8017 | .rpc_message = &msg, |
| 7937 | .callback_ops = &nfs4_layoutcommit_ops, | 8018 | .callback_ops = &nfs4_layoutcommit_ops, |
| 7938 | .callback_data = data, | 8019 | .callback_data = data, |
| 7939 | .flags = RPC_TASK_ASYNC, | ||
| 7940 | }; | 8020 | }; |
| 7941 | struct rpc_task *task; | 8021 | struct rpc_task *task; |
| 7942 | int status = 0; | 8022 | int status = 0; |
| @@ -7947,18 +8027,21 @@ nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) | |||
| 7947 | data->args.lastbytewritten, | 8027 | data->args.lastbytewritten, |
| 7948 | data->args.inode->i_ino); | 8028 | data->args.inode->i_ino); |
| 7949 | 8029 | ||
| 8030 | if (!sync) { | ||
| 8031 | data->inode = nfs_igrab_and_active(data->args.inode); | ||
| 8032 | if (data->inode == NULL) { | ||
| 8033 | nfs4_layoutcommit_release(data); | ||
| 8034 | return -EAGAIN; | ||
| 8035 | } | ||
| 8036 | task_setup_data.flags = RPC_TASK_ASYNC; | ||
| 8037 | } | ||
| 7950 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); | 8038 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
| 7951 | task = rpc_run_task(&task_setup_data); | 8039 | task = rpc_run_task(&task_setup_data); |
| 7952 | if (IS_ERR(task)) | 8040 | if (IS_ERR(task)) |
| 7953 | return PTR_ERR(task); | 8041 | return PTR_ERR(task); |
| 7954 | if (sync == false) | 8042 | if (sync) |
| 7955 | goto out; | 8043 | status = task->tk_status; |
| 7956 | status = nfs4_wait_for_completion_rpc_task(task); | ||
| 7957 | if (status != 0) | ||
| 7958 | goto out; | ||
| 7959 | status = task->tk_status; | ||
| 7960 | trace_nfs4_layoutcommit(data->args.inode, status); | 8044 | trace_nfs4_layoutcommit(data->args.inode, status); |
| 7961 | out: | ||
| 7962 | dprintk("%s: status %d\n", __func__, status); | 8045 | dprintk("%s: status %d\n", __func__, status); |
| 7963 | rpc_put_task(task); | 8046 | rpc_put_task(task); |
| 7964 | return status; | 8047 | return status; |
| @@ -8386,6 +8469,7 @@ static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { | |||
| 8386 | .match_stateid = nfs4_match_stateid, | 8469 | .match_stateid = nfs4_match_stateid, |
| 8387 | .find_root_sec = nfs4_find_root_sec, | 8470 | .find_root_sec = nfs4_find_root_sec, |
| 8388 | .free_lock_state = nfs4_release_lockowner, | 8471 | .free_lock_state = nfs4_release_lockowner, |
| 8472 | .alloc_seqid = nfs_alloc_seqid, | ||
| 8389 | .call_sync_ops = &nfs40_call_sync_ops, | 8473 | .call_sync_ops = &nfs40_call_sync_ops, |
| 8390 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, | 8474 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 8391 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, | 8475 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| @@ -8394,6 +8478,12 @@ static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { | |||
| 8394 | }; | 8478 | }; |
| 8395 | 8479 | ||
| 8396 | #if defined(CONFIG_NFS_V4_1) | 8480 | #if defined(CONFIG_NFS_V4_1) |
| 8481 | static struct nfs_seqid * | ||
| 8482 | nfs_alloc_no_seqid(struct nfs_seqid_counter *arg1, gfp_t arg2) | ||
| 8483 | { | ||
| 8484 | return NULL; | ||
| 8485 | } | ||
| 8486 | |||
| 8397 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { | 8487 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 8398 | .minor_version = 1, | 8488 | .minor_version = 1, |
| 8399 | .init_caps = NFS_CAP_READDIRPLUS | 8489 | .init_caps = NFS_CAP_READDIRPLUS |
| @@ -8407,6 +8497,7 @@ static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { | |||
| 8407 | .match_stateid = nfs41_match_stateid, | 8497 | .match_stateid = nfs41_match_stateid, |
| 8408 | .find_root_sec = nfs41_find_root_sec, | 8498 | .find_root_sec = nfs41_find_root_sec, |
| 8409 | .free_lock_state = nfs41_free_lock_state, | 8499 | .free_lock_state = nfs41_free_lock_state, |
| 8500 | .alloc_seqid = nfs_alloc_no_seqid, | ||
| 8410 | .call_sync_ops = &nfs41_call_sync_ops, | 8501 | .call_sync_ops = &nfs41_call_sync_ops, |
| 8411 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, | 8502 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 8412 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, | 8503 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| @@ -8433,6 +8524,7 @@ static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = { | |||
| 8433 | .find_root_sec = nfs41_find_root_sec, | 8524 | .find_root_sec = nfs41_find_root_sec, |
| 8434 | .free_lock_state = nfs41_free_lock_state, | 8525 | .free_lock_state = nfs41_free_lock_state, |
| 8435 | .call_sync_ops = &nfs41_call_sync_ops, | 8526 | .call_sync_ops = &nfs41_call_sync_ops, |
| 8527 | .alloc_seqid = nfs_alloc_no_seqid, | ||
| 8436 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, | 8528 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 8437 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, | 8529 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 8438 | .state_renewal_ops = &nfs41_state_renewal_ops, | 8530 | .state_renewal_ops = &nfs41_state_renewal_ops, |
diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c index 5194933ed419..5ad908e9ce9c 100644 --- a/fs/nfs/nfs4state.c +++ b/fs/nfs/nfs4state.c | |||
| @@ -1003,11 +1003,11 @@ struct nfs_seqid *nfs_alloc_seqid(struct nfs_seqid_counter *counter, gfp_t gfp_m | |||
| 1003 | struct nfs_seqid *new; | 1003 | struct nfs_seqid *new; |
| 1004 | 1004 | ||
| 1005 | new = kmalloc(sizeof(*new), gfp_mask); | 1005 | new = kmalloc(sizeof(*new), gfp_mask); |
| 1006 | if (new != NULL) { | 1006 | if (new == NULL) |
| 1007 | new->sequence = counter; | 1007 | return ERR_PTR(-ENOMEM); |
| 1008 | INIT_LIST_HEAD(&new->list); | 1008 | new->sequence = counter; |
| 1009 | new->task = NULL; | 1009 | INIT_LIST_HEAD(&new->list); |
| 1010 | } | 1010 | new->task = NULL; |
| 1011 | return new; | 1011 | return new; |
| 1012 | } | 1012 | } |
| 1013 | 1013 | ||
| @@ -1015,7 +1015,7 @@ void nfs_release_seqid(struct nfs_seqid *seqid) | |||
| 1015 | { | 1015 | { |
| 1016 | struct nfs_seqid_counter *sequence; | 1016 | struct nfs_seqid_counter *sequence; |
| 1017 | 1017 | ||
| 1018 | if (list_empty(&seqid->list)) | 1018 | if (seqid == NULL || list_empty(&seqid->list)) |
| 1019 | return; | 1019 | return; |
| 1020 | sequence = seqid->sequence; | 1020 | sequence = seqid->sequence; |
| 1021 | spin_lock(&sequence->lock); | 1021 | spin_lock(&sequence->lock); |
| @@ -1071,13 +1071,15 @@ static void nfs_increment_seqid(int status, struct nfs_seqid *seqid) | |||
| 1071 | 1071 | ||
| 1072 | void nfs_increment_open_seqid(int status, struct nfs_seqid *seqid) | 1072 | void nfs_increment_open_seqid(int status, struct nfs_seqid *seqid) |
| 1073 | { | 1073 | { |
| 1074 | struct nfs4_state_owner *sp = container_of(seqid->sequence, | 1074 | struct nfs4_state_owner *sp; |
| 1075 | struct nfs4_state_owner, so_seqid); | 1075 | |
| 1076 | struct nfs_server *server = sp->so_server; | 1076 | if (seqid == NULL) |
| 1077 | return; | ||
| 1077 | 1078 | ||
| 1079 | sp = container_of(seqid->sequence, struct nfs4_state_owner, so_seqid); | ||
| 1078 | if (status == -NFS4ERR_BAD_SEQID) | 1080 | if (status == -NFS4ERR_BAD_SEQID) |
| 1079 | nfs4_drop_state_owner(sp); | 1081 | nfs4_drop_state_owner(sp); |
| 1080 | if (!nfs4_has_session(server->nfs_client)) | 1082 | if (!nfs4_has_session(sp->so_server->nfs_client)) |
| 1081 | nfs_increment_seqid(status, seqid); | 1083 | nfs_increment_seqid(status, seqid); |
| 1082 | } | 1084 | } |
| 1083 | 1085 | ||
| @@ -1088,14 +1090,18 @@ void nfs_increment_open_seqid(int status, struct nfs_seqid *seqid) | |||
| 1088 | */ | 1090 | */ |
| 1089 | void nfs_increment_lock_seqid(int status, struct nfs_seqid *seqid) | 1091 | void nfs_increment_lock_seqid(int status, struct nfs_seqid *seqid) |
| 1090 | { | 1092 | { |
| 1091 | nfs_increment_seqid(status, seqid); | 1093 | if (seqid != NULL) |
| 1094 | nfs_increment_seqid(status, seqid); | ||
| 1092 | } | 1095 | } |
| 1093 | 1096 | ||
| 1094 | int nfs_wait_on_sequence(struct nfs_seqid *seqid, struct rpc_task *task) | 1097 | int nfs_wait_on_sequence(struct nfs_seqid *seqid, struct rpc_task *task) |
| 1095 | { | 1098 | { |
| 1096 | struct nfs_seqid_counter *sequence = seqid->sequence; | 1099 | struct nfs_seqid_counter *sequence; |
| 1097 | int status = 0; | 1100 | int status = 0; |
| 1098 | 1101 | ||
| 1102 | if (seqid == NULL) | ||
| 1103 | goto out; | ||
| 1104 | sequence = seqid->sequence; | ||
| 1099 | spin_lock(&sequence->lock); | 1105 | spin_lock(&sequence->lock); |
| 1100 | seqid->task = task; | 1106 | seqid->task = task; |
| 1101 | if (list_empty(&seqid->list)) | 1107 | if (list_empty(&seqid->list)) |
| @@ -1106,6 +1112,7 @@ int nfs_wait_on_sequence(struct nfs_seqid *seqid, struct rpc_task *task) | |||
| 1106 | status = -EAGAIN; | 1112 | status = -EAGAIN; |
| 1107 | unlock: | 1113 | unlock: |
| 1108 | spin_unlock(&sequence->lock); | 1114 | spin_unlock(&sequence->lock); |
| 1115 | out: | ||
| 1109 | return status; | 1116 | return status; |
| 1110 | } | 1117 | } |
| 1111 | 1118 | ||
| @@ -1366,49 +1373,55 @@ static int nfs4_reclaim_locks(struct nfs4_state *state, const struct nfs4_state_ | |||
| 1366 | struct nfs_inode *nfsi = NFS_I(inode); | 1373 | struct nfs_inode *nfsi = NFS_I(inode); |
| 1367 | struct file_lock *fl; | 1374 | struct file_lock *fl; |
| 1368 | int status = 0; | 1375 | int status = 0; |
| 1376 | struct file_lock_context *flctx = inode->i_flctx; | ||
| 1377 | struct list_head *list; | ||
| 1369 | 1378 | ||
| 1370 | if (inode->i_flock == NULL) | 1379 | if (flctx == NULL) |
| 1371 | return 0; | 1380 | return 0; |
| 1372 | 1381 | ||
| 1382 | list = &flctx->flc_posix; | ||
| 1383 | |||
| 1373 | /* Guard against delegation returns and new lock/unlock calls */ | 1384 | /* Guard against delegation returns and new lock/unlock calls */ |
| 1374 | down_write(&nfsi->rwsem); | 1385 | down_write(&nfsi->rwsem); |
| 1375 | /* Protect inode->i_flock using the BKL */ | 1386 | spin_lock(&flctx->flc_lock); |
| 1376 | spin_lock(&inode->i_lock); | 1387 | restart: |
| 1377 | for (fl = inode->i_flock; fl != NULL; fl = fl->fl_next) { | 1388 | list_for_each_entry(fl, list, fl_list) { |
| 1378 | if (!(fl->fl_flags & (FL_POSIX|FL_FLOCK))) | ||
| 1379 | continue; | ||
| 1380 | if (nfs_file_open_context(fl->fl_file)->state != state) | 1389 | if (nfs_file_open_context(fl->fl_file)->state != state) |
| 1381 | continue; | 1390 | continue; |
| 1382 | spin_unlock(&inode->i_lock); | 1391 | spin_unlock(&flctx->flc_lock); |
| 1383 | status = ops->recover_lock(state, fl); | 1392 | status = ops->recover_lock(state, fl); |
| 1384 | switch (status) { | 1393 | switch (status) { |
| 1385 | case 0: | 1394 | case 0: |
| 1386 | break; | 1395 | break; |
| 1387 | case -ESTALE: | 1396 | case -ESTALE: |
| 1388 | case -NFS4ERR_ADMIN_REVOKED: | 1397 | case -NFS4ERR_ADMIN_REVOKED: |
| 1389 | case -NFS4ERR_STALE_STATEID: | 1398 | case -NFS4ERR_STALE_STATEID: |
| 1390 | case -NFS4ERR_BAD_STATEID: | 1399 | case -NFS4ERR_BAD_STATEID: |
| 1391 | case -NFS4ERR_EXPIRED: | 1400 | case -NFS4ERR_EXPIRED: |
| 1392 | case -NFS4ERR_NO_GRACE: | 1401 | case -NFS4ERR_NO_GRACE: |
| 1393 | case -NFS4ERR_STALE_CLIENTID: | 1402 | case -NFS4ERR_STALE_CLIENTID: |
| 1394 | case -NFS4ERR_BADSESSION: | 1403 | case -NFS4ERR_BADSESSION: |
| 1395 | case -NFS4ERR_BADSLOT: | 1404 | case -NFS4ERR_BADSLOT: |
| 1396 | case -NFS4ERR_BAD_HIGH_SLOT: | 1405 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1397 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: | 1406 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1398 | goto out; | 1407 | goto out; |
| 1399 | default: | 1408 | default: |
| 1400 | printk(KERN_ERR "NFS: %s: unhandled error %d\n", | 1409 | pr_err("NFS: %s: unhandled error %d\n", |
| 1401 | __func__, status); | 1410 | __func__, status); |
| 1402 | case -ENOMEM: | 1411 | case -ENOMEM: |
| 1403 | case -NFS4ERR_DENIED: | 1412 | case -NFS4ERR_DENIED: |
| 1404 | case -NFS4ERR_RECLAIM_BAD: | 1413 | case -NFS4ERR_RECLAIM_BAD: |
| 1405 | case -NFS4ERR_RECLAIM_CONFLICT: | 1414 | case -NFS4ERR_RECLAIM_CONFLICT: |
| 1406 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ | 1415 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 1407 | status = 0; | 1416 | status = 0; |
| 1408 | } | 1417 | } |
| 1409 | spin_lock(&inode->i_lock); | 1418 | spin_lock(&flctx->flc_lock); |
| 1410 | } | 1419 | } |
| 1411 | spin_unlock(&inode->i_lock); | 1420 | if (list == &flctx->flc_posix) { |
| 1421 | list = &flctx->flc_flock; | ||
| 1422 | goto restart; | ||
| 1423 | } | ||
| 1424 | spin_unlock(&flctx->flc_lock); | ||
| 1412 | out: | 1425 | out: |
| 1413 | up_write(&nfsi->rwsem); | 1426 | up_write(&nfsi->rwsem); |
| 1414 | return status; | 1427 | return status; |
diff --git a/fs/nfs/nfs4super.c b/fs/nfs/nfs4super.c index 6f340f02f2ba..75090feeafad 100644 --- a/fs/nfs/nfs4super.c +++ b/fs/nfs/nfs4super.c | |||
| @@ -53,7 +53,6 @@ static const struct super_operations nfs4_sops = { | |||
| 53 | .destroy_inode = nfs_destroy_inode, | 53 | .destroy_inode = nfs_destroy_inode, |
| 54 | .write_inode = nfs4_write_inode, | 54 | .write_inode = nfs4_write_inode, |
| 55 | .drop_inode = nfs_drop_inode, | 55 | .drop_inode = nfs_drop_inode, |
| 56 | .put_super = nfs_put_super, | ||
| 57 | .statfs = nfs_statfs, | 56 | .statfs = nfs_statfs, |
| 58 | .evict_inode = nfs4_evict_inode, | 57 | .evict_inode = nfs4_evict_inode, |
| 59 | .umount_begin = nfs_umount_begin, | 58 | .umount_begin = nfs_umount_begin, |
| @@ -346,6 +345,9 @@ out: | |||
| 346 | 345 | ||
| 347 | static void __exit exit_nfs_v4(void) | 346 | static void __exit exit_nfs_v4(void) |
| 348 | { | 347 | { |
| 348 | /* Not called in the _init(), conditionally loaded */ | ||
| 349 | nfs4_pnfs_v3_ds_connect_unload(); | ||
| 350 | |||
| 349 | unregister_nfs_version(&nfs_v4); | 351 | unregister_nfs_version(&nfs_v4); |
| 350 | nfs4_unregister_sysctl(); | 352 | nfs4_unregister_sysctl(); |
| 351 | nfs_idmap_quit(); | 353 | nfs_idmap_quit(); |
diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c index cb4376b78ed9..e23a0a664e12 100644 --- a/fs/nfs/nfs4xdr.c +++ b/fs/nfs/nfs4xdr.c | |||
| @@ -946,7 +946,10 @@ static void encode_uint64(struct xdr_stream *xdr, u64 n) | |||
| 946 | static void encode_nfs4_seqid(struct xdr_stream *xdr, | 946 | static void encode_nfs4_seqid(struct xdr_stream *xdr, |
| 947 | const struct nfs_seqid *seqid) | 947 | const struct nfs_seqid *seqid) |
| 948 | { | 948 | { |
| 949 | encode_uint32(xdr, seqid->sequence->counter); | 949 | if (seqid != NULL) |
| 950 | encode_uint32(xdr, seqid->sequence->counter); | ||
| 951 | else | ||
| 952 | encode_uint32(xdr, 0); | ||
| 950 | } | 953 | } |
| 951 | 954 | ||
| 952 | static void encode_compound_hdr(struct xdr_stream *xdr, | 955 | static void encode_compound_hdr(struct xdr_stream *xdr, |
| @@ -1125,7 +1128,7 @@ static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg | |||
| 1125 | { | 1128 | { |
| 1126 | encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr); | 1129 | encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr); |
| 1127 | encode_nfs4_seqid(xdr, arg->seqid); | 1130 | encode_nfs4_seqid(xdr, arg->seqid); |
| 1128 | encode_nfs4_stateid(xdr, arg->stateid); | 1131 | encode_nfs4_stateid(xdr, &arg->stateid); |
| 1129 | } | 1132 | } |
| 1130 | 1133 | ||
| 1131 | static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr) | 1134 | static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr) |
| @@ -1301,12 +1304,12 @@ static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args | |||
| 1301 | *p = cpu_to_be32(args->new_lock_owner); | 1304 | *p = cpu_to_be32(args->new_lock_owner); |
| 1302 | if (args->new_lock_owner){ | 1305 | if (args->new_lock_owner){ |
| 1303 | encode_nfs4_seqid(xdr, args->open_seqid); | 1306 | encode_nfs4_seqid(xdr, args->open_seqid); |
| 1304 | encode_nfs4_stateid(xdr, args->open_stateid); | 1307 | encode_nfs4_stateid(xdr, &args->open_stateid); |
| 1305 | encode_nfs4_seqid(xdr, args->lock_seqid); | 1308 | encode_nfs4_seqid(xdr, args->lock_seqid); |
| 1306 | encode_lockowner(xdr, &args->lock_owner); | 1309 | encode_lockowner(xdr, &args->lock_owner); |
| 1307 | } | 1310 | } |
| 1308 | else { | 1311 | else { |
| 1309 | encode_nfs4_stateid(xdr, args->lock_stateid); | 1312 | encode_nfs4_stateid(xdr, &args->lock_stateid); |
| 1310 | encode_nfs4_seqid(xdr, args->lock_seqid); | 1313 | encode_nfs4_seqid(xdr, args->lock_seqid); |
| 1311 | } | 1314 | } |
| 1312 | } | 1315 | } |
| @@ -1330,7 +1333,7 @@ static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *ar | |||
| 1330 | encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr); | 1333 | encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr); |
| 1331 | encode_uint32(xdr, nfs4_lock_type(args->fl, 0)); | 1334 | encode_uint32(xdr, nfs4_lock_type(args->fl, 0)); |
| 1332 | encode_nfs4_seqid(xdr, args->seqid); | 1335 | encode_nfs4_seqid(xdr, args->seqid); |
| 1333 | encode_nfs4_stateid(xdr, args->stateid); | 1336 | encode_nfs4_stateid(xdr, &args->stateid); |
| 1334 | p = reserve_space(xdr, 16); | 1337 | p = reserve_space(xdr, 16); |
| 1335 | p = xdr_encode_hyper(p, args->fl->fl_start); | 1338 | p = xdr_encode_hyper(p, args->fl->fl_start); |
| 1336 | xdr_encode_hyper(p, nfs4_lock_length(args->fl)); | 1339 | xdr_encode_hyper(p, nfs4_lock_length(args->fl)); |
| @@ -1348,24 +1351,12 @@ static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struc | |||
| 1348 | encode_string(xdr, name->len, name->name); | 1351 | encode_string(xdr, name->len, name->name); |
| 1349 | } | 1352 | } |
| 1350 | 1353 | ||
| 1351 | static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode) | 1354 | static void encode_share_access(struct xdr_stream *xdr, u32 share_access) |
| 1352 | { | 1355 | { |
| 1353 | __be32 *p; | 1356 | __be32 *p; |
| 1354 | 1357 | ||
| 1355 | p = reserve_space(xdr, 8); | 1358 | p = reserve_space(xdr, 8); |
| 1356 | switch (fmode & (FMODE_READ|FMODE_WRITE)) { | 1359 | *p++ = cpu_to_be32(share_access); |
| 1357 | case FMODE_READ: | ||
| 1358 | *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ); | ||
| 1359 | break; | ||
| 1360 | case FMODE_WRITE: | ||
| 1361 | *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE); | ||
| 1362 | break; | ||
| 1363 | case FMODE_READ|FMODE_WRITE: | ||
| 1364 | *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH); | ||
| 1365 | break; | ||
| 1366 | default: | ||
| 1367 | *p++ = cpu_to_be32(0); | ||
| 1368 | } | ||
| 1369 | *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */ | 1360 | *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */ |
| 1370 | } | 1361 | } |
| 1371 | 1362 | ||
| @@ -1377,7 +1368,7 @@ static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_opena | |||
| 1377 | * owner 4 = 32 | 1368 | * owner 4 = 32 |
| 1378 | */ | 1369 | */ |
| 1379 | encode_nfs4_seqid(xdr, arg->seqid); | 1370 | encode_nfs4_seqid(xdr, arg->seqid); |
| 1380 | encode_share_access(xdr, arg->fmode); | 1371 | encode_share_access(xdr, arg->share_access); |
| 1381 | p = reserve_space(xdr, 36); | 1372 | p = reserve_space(xdr, 36); |
| 1382 | p = xdr_encode_hyper(p, arg->clientid); | 1373 | p = xdr_encode_hyper(p, arg->clientid); |
| 1383 | *p++ = cpu_to_be32(24); | 1374 | *p++ = cpu_to_be32(24); |
| @@ -1530,9 +1521,9 @@ static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_co | |||
| 1530 | static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr) | 1521 | static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr) |
| 1531 | { | 1522 | { |
| 1532 | encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr); | 1523 | encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr); |
| 1533 | encode_nfs4_stateid(xdr, arg->stateid); | 1524 | encode_nfs4_stateid(xdr, &arg->stateid); |
| 1534 | encode_nfs4_seqid(xdr, arg->seqid); | 1525 | encode_nfs4_seqid(xdr, arg->seqid); |
| 1535 | encode_share_access(xdr, arg->fmode); | 1526 | encode_share_access(xdr, arg->share_access); |
| 1536 | } | 1527 | } |
| 1537 | 1528 | ||
| 1538 | static void | 1529 | static void |
| @@ -1801,9 +1792,8 @@ static void encode_create_session(struct xdr_stream *xdr, | |||
| 1801 | struct compound_hdr *hdr) | 1792 | struct compound_hdr *hdr) |
| 1802 | { | 1793 | { |
| 1803 | __be32 *p; | 1794 | __be32 *p; |
| 1804 | char machine_name[NFS4_MAX_MACHINE_NAME_LEN]; | ||
| 1805 | uint32_t len; | ||
| 1806 | struct nfs_client *clp = args->client; | 1795 | struct nfs_client *clp = args->client; |
| 1796 | struct rpc_clnt *clnt = clp->cl_rpcclient; | ||
| 1807 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); | 1797 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
| 1808 | u32 max_resp_sz_cached; | 1798 | u32 max_resp_sz_cached; |
| 1809 | 1799 | ||
| @@ -1814,11 +1804,8 @@ static void encode_create_session(struct xdr_stream *xdr, | |||
| 1814 | max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE + | 1804 | max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE + |
| 1815 | RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT; | 1805 | RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT; |
| 1816 | 1806 | ||
| 1817 | len = scnprintf(machine_name, sizeof(machine_name), "%s", | ||
| 1818 | clp->cl_ipaddr); | ||
| 1819 | |||
| 1820 | encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr); | 1807 | encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr); |
| 1821 | p = reserve_space(xdr, 16 + 2*28 + 20 + len + 12); | 1808 | p = reserve_space(xdr, 16 + 2*28 + 20 + clnt->cl_nodelen + 12); |
| 1822 | p = xdr_encode_hyper(p, clp->cl_clientid); | 1809 | p = xdr_encode_hyper(p, clp->cl_clientid); |
| 1823 | *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */ | 1810 | *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */ |
| 1824 | *p++ = cpu_to_be32(args->flags); /*flags */ | 1811 | *p++ = cpu_to_be32(args->flags); /*flags */ |
| @@ -1847,7 +1834,7 @@ static void encode_create_session(struct xdr_stream *xdr, | |||
| 1847 | 1834 | ||
| 1848 | /* authsys_parms rfc1831 */ | 1835 | /* authsys_parms rfc1831 */ |
| 1849 | *p++ = cpu_to_be32(nn->boot_time.tv_nsec); /* stamp */ | 1836 | *p++ = cpu_to_be32(nn->boot_time.tv_nsec); /* stamp */ |
| 1850 | p = xdr_encode_opaque(p, machine_name, len); | 1837 | p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen); |
| 1851 | *p++ = cpu_to_be32(0); /* UID */ | 1838 | *p++ = cpu_to_be32(0); /* UID */ |
| 1852 | *p++ = cpu_to_be32(0); /* GID */ | 1839 | *p++ = cpu_to_be32(0); /* GID */ |
| 1853 | *p = cpu_to_be32(0); /* No more gids */ | 1840 | *p = cpu_to_be32(0); /* No more gids */ |
| @@ -2012,11 +1999,11 @@ encode_layoutreturn(struct xdr_stream *xdr, | |||
| 2012 | p = reserve_space(xdr, 16); | 1999 | p = reserve_space(xdr, 16); |
| 2013 | *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */ | 2000 | *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */ |
| 2014 | *p++ = cpu_to_be32(args->layout_type); | 2001 | *p++ = cpu_to_be32(args->layout_type); |
| 2015 | *p++ = cpu_to_be32(IOMODE_ANY); | 2002 | *p++ = cpu_to_be32(args->range.iomode); |
| 2016 | *p = cpu_to_be32(RETURN_FILE); | 2003 | *p = cpu_to_be32(RETURN_FILE); |
| 2017 | p = reserve_space(xdr, 16); | 2004 | p = reserve_space(xdr, 16); |
| 2018 | p = xdr_encode_hyper(p, 0); | 2005 | p = xdr_encode_hyper(p, args->range.offset); |
| 2019 | p = xdr_encode_hyper(p, NFS4_MAX_UINT64); | 2006 | p = xdr_encode_hyper(p, args->range.length); |
| 2020 | spin_lock(&args->inode->i_lock); | 2007 | spin_lock(&args->inode->i_lock); |
| 2021 | encode_nfs4_stateid(xdr, &args->stateid); | 2008 | encode_nfs4_stateid(xdr, &args->stateid); |
| 2022 | spin_unlock(&args->inode->i_lock); | 2009 | spin_unlock(&args->inode->i_lock); |
| @@ -4936,20 +4923,13 @@ out_overflow: | |||
| 4936 | return -EIO; | 4923 | return -EIO; |
| 4937 | } | 4924 | } |
| 4938 | 4925 | ||
| 4939 | static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res) | 4926 | static int decode_rw_delegation(struct xdr_stream *xdr, |
| 4927 | uint32_t delegation_type, | ||
| 4928 | struct nfs_openres *res) | ||
| 4940 | { | 4929 | { |
| 4941 | __be32 *p; | 4930 | __be32 *p; |
| 4942 | uint32_t delegation_type; | ||
| 4943 | int status; | 4931 | int status; |
| 4944 | 4932 | ||
| 4945 | p = xdr_inline_decode(xdr, 4); | ||
| 4946 | if (unlikely(!p)) | ||
| 4947 | goto out_overflow; | ||
| 4948 | delegation_type = be32_to_cpup(p); | ||
| 4949 | if (delegation_type == NFS4_OPEN_DELEGATE_NONE) { | ||
| 4950 | res->delegation_type = 0; | ||
| 4951 | return 0; | ||
| 4952 | } | ||
| 4953 | status = decode_stateid(xdr, &res->delegation); | 4933 | status = decode_stateid(xdr, &res->delegation); |
| 4954 | if (unlikely(status)) | 4934 | if (unlikely(status)) |
| 4955 | return status; | 4935 | return status; |
| @@ -4973,6 +4953,52 @@ out_overflow: | |||
| 4973 | return -EIO; | 4953 | return -EIO; |
| 4974 | } | 4954 | } |
| 4975 | 4955 | ||
| 4956 | static int decode_no_delegation(struct xdr_stream *xdr, struct nfs_openres *res) | ||
| 4957 | { | ||
| 4958 | __be32 *p; | ||
| 4959 | uint32_t why_no_delegation; | ||
| 4960 | |||
| 4961 | p = xdr_inline_decode(xdr, 4); | ||
| 4962 | if (unlikely(!p)) | ||
| 4963 | goto out_overflow; | ||
| 4964 | why_no_delegation = be32_to_cpup(p); | ||
| 4965 | switch (why_no_delegation) { | ||
| 4966 | case WND4_CONTENTION: | ||
| 4967 | case WND4_RESOURCE: | ||
| 4968 | xdr_inline_decode(xdr, 4); | ||
| 4969 | /* Ignore for now */ | ||
| 4970 | } | ||
| 4971 | return 0; | ||
| 4972 | out_overflow: | ||
| 4973 | print_overflow_msg(__func__, xdr); | ||
| 4974 | return -EIO; | ||
| 4975 | } | ||
| 4976 | |||
| 4977 | static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res) | ||
| 4978 | { | ||
| 4979 | __be32 *p; | ||
| 4980 | uint32_t delegation_type; | ||
| 4981 | |||
| 4982 | p = xdr_inline_decode(xdr, 4); | ||
| 4983 | if (unlikely(!p)) | ||
| 4984 | goto out_overflow; | ||
| 4985 | delegation_type = be32_to_cpup(p); | ||
| 4986 | res->delegation_type = 0; | ||
| 4987 | switch (delegation_type) { | ||
| 4988 | case NFS4_OPEN_DELEGATE_NONE: | ||
| 4989 | return 0; | ||
| 4990 | case NFS4_OPEN_DELEGATE_READ: | ||
| 4991 | case NFS4_OPEN_DELEGATE_WRITE: | ||
| 4992 | return decode_rw_delegation(xdr, delegation_type, res); | ||
| 4993 | case NFS4_OPEN_DELEGATE_NONE_EXT: | ||
| 4994 | return decode_no_delegation(xdr, res); | ||
| 4995 | } | ||
| 4996 | return -EIO; | ||
| 4997 | out_overflow: | ||
| 4998 | print_overflow_msg(__func__, xdr); | ||
| 4999 | return -EIO; | ||
| 5000 | } | ||
| 5001 | |||
| 4976 | static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res) | 5002 | static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res) |
| 4977 | { | 5003 | { |
| 4978 | __be32 *p; | 5004 | __be32 *p; |
| @@ -6567,6 +6593,7 @@ static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr, | |||
| 6567 | int status; | 6593 | int status; |
| 6568 | 6594 | ||
| 6569 | status = decode_compound_hdr(xdr, &hdr); | 6595 | status = decode_compound_hdr(xdr, &hdr); |
| 6596 | res->op_status = hdr.status; | ||
| 6570 | if (status) | 6597 | if (status) |
| 6571 | goto out; | 6598 | goto out; |
| 6572 | status = decode_sequence(xdr, &res->seq_res, rqstp); | 6599 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
| @@ -6592,6 +6619,7 @@ static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr, | |||
| 6592 | int status; | 6619 | int status; |
| 6593 | 6620 | ||
| 6594 | status = decode_compound_hdr(xdr, &hdr); | 6621 | status = decode_compound_hdr(xdr, &hdr); |
| 6622 | res->op_status = hdr.status; | ||
| 6595 | if (status) | 6623 | if (status) |
| 6596 | goto out; | 6624 | goto out; |
| 6597 | status = decode_sequence(xdr, &res->seq_res, rqstp); | 6625 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
| @@ -6621,6 +6649,7 @@ static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr, | |||
| 6621 | int status; | 6649 | int status; |
| 6622 | 6650 | ||
| 6623 | status = decode_compound_hdr(xdr, &hdr); | 6651 | status = decode_compound_hdr(xdr, &hdr); |
| 6652 | res->op_status = hdr.status; | ||
| 6624 | if (status) | 6653 | if (status) |
| 6625 | goto out; | 6654 | goto out; |
| 6626 | status = decode_sequence(xdr, &res->seq_res, rqstp); | 6655 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
diff --git a/fs/nfs/nfsroot.c b/fs/nfs/nfsroot.c index cd3c910d2d12..9bc9f04fb7f6 100644 --- a/fs/nfs/nfsroot.c +++ b/fs/nfs/nfsroot.c | |||
| @@ -261,11 +261,11 @@ static int __init root_nfs_data(char *cmdline) | |||
| 261 | */ | 261 | */ |
| 262 | len = snprintf(nfs_export_path, sizeof(nfs_export_path), | 262 | len = snprintf(nfs_export_path, sizeof(nfs_export_path), |
| 263 | tmp, utsname()->nodename); | 263 | tmp, utsname()->nodename); |
| 264 | if (len > (int)sizeof(nfs_export_path)) | 264 | if (len >= (int)sizeof(nfs_export_path)) |
| 265 | goto out_devnametoolong; | 265 | goto out_devnametoolong; |
| 266 | len = snprintf(nfs_root_device, sizeof(nfs_root_device), | 266 | len = snprintf(nfs_root_device, sizeof(nfs_root_device), |
| 267 | "%pI4:%s", &servaddr, nfs_export_path); | 267 | "%pI4:%s", &servaddr, nfs_export_path); |
| 268 | if (len > (int)sizeof(nfs_root_device)) | 268 | if (len >= (int)sizeof(nfs_root_device)) |
| 269 | goto out_devnametoolong; | 269 | goto out_devnametoolong; |
| 270 | 270 | ||
| 271 | retval = 0; | 271 | retval = 0; |
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..d57190a0d533 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 | { |
| @@ -826,11 +933,15 @@ static bool nfs_can_coalesce_requests(struct nfs_page *prev, | |||
| 826 | struct nfs_pageio_descriptor *pgio) | 933 | struct nfs_pageio_descriptor *pgio) |
| 827 | { | 934 | { |
| 828 | size_t size; | 935 | size_t size; |
| 936 | struct file_lock_context *flctx; | ||
| 829 | 937 | ||
| 830 | if (prev) { | 938 | if (prev) { |
| 831 | if (!nfs_match_open_context(req->wb_context, prev->wb_context)) | 939 | if (!nfs_match_open_context(req->wb_context, prev->wb_context)) |
| 832 | return false; | 940 | return false; |
| 833 | if (req->wb_context->dentry->d_inode->i_flock != NULL && | 941 | flctx = req->wb_context->dentry->d_inode->i_flctx; |
| 942 | if (flctx != NULL && | ||
| 943 | !(list_empty_careful(&flctx->flc_posix) && | ||
| 944 | list_empty_careful(&flctx->flc_flock)) && | ||
| 834 | !nfs_match_lock_context(req->wb_lock_context, | 945 | !nfs_match_lock_context(req->wb_lock_context, |
| 835 | prev->wb_lock_context)) | 946 | prev->wb_lock_context)) |
| 836 | return false; | 947 | return false; |
| @@ -863,19 +974,22 @@ static bool nfs_can_coalesce_requests(struct nfs_page *prev, | |||
| 863 | static int nfs_pageio_do_add_request(struct nfs_pageio_descriptor *desc, | 974 | static int nfs_pageio_do_add_request(struct nfs_pageio_descriptor *desc, |
| 864 | struct nfs_page *req) | 975 | struct nfs_page *req) |
| 865 | { | 976 | { |
| 977 | struct nfs_pgio_mirror *mirror = nfs_pgio_current_mirror(desc); | ||
| 978 | |||
| 866 | struct nfs_page *prev = NULL; | 979 | struct nfs_page *prev = NULL; |
| 867 | if (desc->pg_count != 0) { | 980 | |
| 868 | prev = nfs_list_entry(desc->pg_list.prev); | 981 | if (mirror->pg_count != 0) { |
| 982 | prev = nfs_list_entry(mirror->pg_list.prev); | ||
| 869 | } else { | 983 | } else { |
| 870 | if (desc->pg_ops->pg_init) | 984 | if (desc->pg_ops->pg_init) |
| 871 | desc->pg_ops->pg_init(desc, req); | 985 | desc->pg_ops->pg_init(desc, req); |
| 872 | desc->pg_base = req->wb_pgbase; | 986 | mirror->pg_base = req->wb_pgbase; |
| 873 | } | 987 | } |
| 874 | if (!nfs_can_coalesce_requests(prev, req, desc)) | 988 | if (!nfs_can_coalesce_requests(prev, req, desc)) |
| 875 | return 0; | 989 | return 0; |
| 876 | nfs_list_remove_request(req); | 990 | nfs_list_remove_request(req); |
| 877 | nfs_list_add_request(req, &desc->pg_list); | 991 | nfs_list_add_request(req, &mirror->pg_list); |
| 878 | desc->pg_count += req->wb_bytes; | 992 | mirror->pg_count += req->wb_bytes; |
| 879 | return 1; | 993 | return 1; |
| 880 | } | 994 | } |
| 881 | 995 | ||
| @@ -884,16 +998,19 @@ static int nfs_pageio_do_add_request(struct nfs_pageio_descriptor *desc, | |||
| 884 | */ | 998 | */ |
| 885 | static void nfs_pageio_doio(struct nfs_pageio_descriptor *desc) | 999 | static void nfs_pageio_doio(struct nfs_pageio_descriptor *desc) |
| 886 | { | 1000 | { |
| 887 | if (!list_empty(&desc->pg_list)) { | 1001 | struct nfs_pgio_mirror *mirror = nfs_pgio_current_mirror(desc); |
| 1002 | |||
| 1003 | |||
| 1004 | if (!list_empty(&mirror->pg_list)) { | ||
| 888 | int error = desc->pg_ops->pg_doio(desc); | 1005 | int error = desc->pg_ops->pg_doio(desc); |
| 889 | if (error < 0) | 1006 | if (error < 0) |
| 890 | desc->pg_error = error; | 1007 | desc->pg_error = error; |
| 891 | else | 1008 | else |
| 892 | desc->pg_bytes_written += desc->pg_count; | 1009 | mirror->pg_bytes_written += mirror->pg_count; |
| 893 | } | 1010 | } |
| 894 | if (list_empty(&desc->pg_list)) { | 1011 | if (list_empty(&mirror->pg_list)) { |
| 895 | desc->pg_count = 0; | 1012 | mirror->pg_count = 0; |
| 896 | desc->pg_base = 0; | 1013 | mirror->pg_base = 0; |
| 897 | } | 1014 | } |
| 898 | } | 1015 | } |
| 899 | 1016 | ||
| @@ -911,6 +1028,8 @@ static void nfs_pageio_doio(struct nfs_pageio_descriptor *desc) | |||
| 911 | static int __nfs_pageio_add_request(struct nfs_pageio_descriptor *desc, | 1028 | static int __nfs_pageio_add_request(struct nfs_pageio_descriptor *desc, |
| 912 | struct nfs_page *req) | 1029 | struct nfs_page *req) |
| 913 | { | 1030 | { |
| 1031 | struct nfs_pgio_mirror *mirror = nfs_pgio_current_mirror(desc); | ||
| 1032 | |||
| 914 | struct nfs_page *subreq; | 1033 | struct nfs_page *subreq; |
| 915 | unsigned int bytes_left = 0; | 1034 | unsigned int bytes_left = 0; |
| 916 | unsigned int offset, pgbase; | 1035 | unsigned int offset, pgbase; |
| @@ -934,7 +1053,7 @@ static int __nfs_pageio_add_request(struct nfs_pageio_descriptor *desc, | |||
| 934 | nfs_pageio_doio(desc); | 1053 | nfs_pageio_doio(desc); |
| 935 | if (desc->pg_error < 0) | 1054 | if (desc->pg_error < 0) |
| 936 | return 0; | 1055 | return 0; |
| 937 | if (desc->pg_recoalesce) | 1056 | if (mirror->pg_recoalesce) |
| 938 | return 0; | 1057 | return 0; |
| 939 | /* retry add_request for this subreq */ | 1058 | /* retry add_request for this subreq */ |
| 940 | nfs_page_group_lock(req, false); | 1059 | nfs_page_group_lock(req, false); |
| @@ -972,14 +1091,16 @@ err_ptr: | |||
| 972 | 1091 | ||
| 973 | static int nfs_do_recoalesce(struct nfs_pageio_descriptor *desc) | 1092 | static int nfs_do_recoalesce(struct nfs_pageio_descriptor *desc) |
| 974 | { | 1093 | { |
| 1094 | struct nfs_pgio_mirror *mirror = nfs_pgio_current_mirror(desc); | ||
| 975 | LIST_HEAD(head); | 1095 | LIST_HEAD(head); |
| 976 | 1096 | ||
| 977 | do { | 1097 | do { |
| 978 | list_splice_init(&desc->pg_list, &head); | 1098 | list_splice_init(&mirror->pg_list, &head); |
| 979 | desc->pg_bytes_written -= desc->pg_count; | 1099 | mirror->pg_bytes_written -= mirror->pg_count; |
| 980 | desc->pg_count = 0; | 1100 | mirror->pg_count = 0; |
| 981 | desc->pg_base = 0; | 1101 | mirror->pg_base = 0; |
| 982 | desc->pg_recoalesce = 0; | 1102 | mirror->pg_recoalesce = 0; |
| 1103 | |||
| 983 | desc->pg_moreio = 0; | 1104 | desc->pg_moreio = 0; |
| 984 | 1105 | ||
| 985 | while (!list_empty(&head)) { | 1106 | while (!list_empty(&head)) { |
| @@ -993,11 +1114,11 @@ static int nfs_do_recoalesce(struct nfs_pageio_descriptor *desc) | |||
| 993 | return 0; | 1114 | return 0; |
| 994 | break; | 1115 | break; |
| 995 | } | 1116 | } |
| 996 | } while (desc->pg_recoalesce); | 1117 | } while (mirror->pg_recoalesce); |
| 997 | return 1; | 1118 | return 1; |
| 998 | } | 1119 | } |
| 999 | 1120 | ||
| 1000 | int nfs_pageio_add_request(struct nfs_pageio_descriptor *desc, | 1121 | static int nfs_pageio_add_request_mirror(struct nfs_pageio_descriptor *desc, |
| 1001 | struct nfs_page *req) | 1122 | struct nfs_page *req) |
| 1002 | { | 1123 | { |
| 1003 | int ret; | 1124 | int ret; |
| @@ -1010,9 +1131,80 @@ int nfs_pageio_add_request(struct nfs_pageio_descriptor *desc, | |||
| 1010 | break; | 1131 | break; |
| 1011 | ret = nfs_do_recoalesce(desc); | 1132 | ret = nfs_do_recoalesce(desc); |
| 1012 | } while (ret); | 1133 | } while (ret); |
| 1134 | |||
| 1013 | return ret; | 1135 | return ret; |
| 1014 | } | 1136 | } |
| 1015 | 1137 | ||
| 1138 | int nfs_pageio_add_request(struct nfs_pageio_descriptor *desc, | ||
| 1139 | struct nfs_page *req) | ||
| 1140 | { | ||
| 1141 | u32 midx; | ||
| 1142 | unsigned int pgbase, offset, bytes; | ||
| 1143 | struct nfs_page *dupreq, *lastreq; | ||
| 1144 | |||
| 1145 | pgbase = req->wb_pgbase; | ||
| 1146 | offset = req->wb_offset; | ||
| 1147 | bytes = req->wb_bytes; | ||
| 1148 | |||
| 1149 | nfs_pageio_setup_mirroring(desc, req); | ||
| 1150 | |||
| 1151 | for (midx = 0; midx < desc->pg_mirror_count; midx++) { | ||
| 1152 | if (midx) { | ||
| 1153 | nfs_page_group_lock(req, false); | ||
| 1154 | |||
| 1155 | /* find the last request */ | ||
| 1156 | for (lastreq = req->wb_head; | ||
| 1157 | lastreq->wb_this_page != req->wb_head; | ||
| 1158 | lastreq = lastreq->wb_this_page) | ||
| 1159 | ; | ||
| 1160 | |||
| 1161 | dupreq = nfs_create_request(req->wb_context, | ||
| 1162 | req->wb_page, lastreq, pgbase, bytes); | ||
| 1163 | |||
| 1164 | if (IS_ERR(dupreq)) { | ||
| 1165 | nfs_page_group_unlock(req); | ||
| 1166 | return 0; | ||
| 1167 | } | ||
| 1168 | |||
| 1169 | nfs_lock_request(dupreq); | ||
| 1170 | nfs_page_group_unlock(req); | ||
| 1171 | dupreq->wb_offset = offset; | ||
| 1172 | dupreq->wb_index = req->wb_index; | ||
| 1173 | } else | ||
| 1174 | dupreq = req; | ||
| 1175 | |||
| 1176 | if (nfs_pgio_has_mirroring(desc)) | ||
| 1177 | desc->pg_mirror_idx = midx; | ||
| 1178 | if (!nfs_pageio_add_request_mirror(desc, dupreq)) | ||
| 1179 | return 0; | ||
| 1180 | } | ||
| 1181 | |||
| 1182 | return 1; | ||
| 1183 | } | ||
| 1184 | |||
| 1185 | /* | ||
| 1186 | * nfs_pageio_complete_mirror - Complete I/O on the current mirror of an | ||
| 1187 | * nfs_pageio_descriptor | ||
| 1188 | * @desc: pointer to io descriptor | ||
| 1189 | */ | ||
| 1190 | static void nfs_pageio_complete_mirror(struct nfs_pageio_descriptor *desc, | ||
| 1191 | u32 mirror_idx) | ||
| 1192 | { | ||
| 1193 | struct nfs_pgio_mirror *mirror = &desc->pg_mirrors[mirror_idx]; | ||
| 1194 | u32 restore_idx = desc->pg_mirror_idx; | ||
| 1195 | |||
| 1196 | if (nfs_pgio_has_mirroring(desc)) | ||
| 1197 | desc->pg_mirror_idx = mirror_idx; | ||
| 1198 | for (;;) { | ||
| 1199 | nfs_pageio_doio(desc); | ||
| 1200 | if (!mirror->pg_recoalesce) | ||
| 1201 | break; | ||
| 1202 | if (!nfs_do_recoalesce(desc)) | ||
| 1203 | break; | ||
| 1204 | } | ||
| 1205 | desc->pg_mirror_idx = restore_idx; | ||
| 1206 | } | ||
| 1207 | |||
| 1016 | /* | 1208 | /* |
| 1017 | * nfs_pageio_resend - Transfer requests to new descriptor and resend | 1209 | * nfs_pageio_resend - Transfer requests to new descriptor and resend |
| 1018 | * @hdr - the pgio header to move request from | 1210 | * @hdr - the pgio header to move request from |
| @@ -1046,18 +1238,19 @@ int nfs_pageio_resend(struct nfs_pageio_descriptor *desc, | |||
| 1046 | EXPORT_SYMBOL_GPL(nfs_pageio_resend); | 1238 | EXPORT_SYMBOL_GPL(nfs_pageio_resend); |
| 1047 | 1239 | ||
| 1048 | /** | 1240 | /** |
| 1049 | * nfs_pageio_complete - Complete I/O on an nfs_pageio_descriptor | 1241 | * nfs_pageio_complete - Complete I/O then cleanup an nfs_pageio_descriptor |
| 1050 | * @desc: pointer to io descriptor | 1242 | * @desc: pointer to io descriptor |
| 1051 | */ | 1243 | */ |
| 1052 | void nfs_pageio_complete(struct nfs_pageio_descriptor *desc) | 1244 | void nfs_pageio_complete(struct nfs_pageio_descriptor *desc) |
| 1053 | { | 1245 | { |
| 1054 | for (;;) { | 1246 | u32 midx; |
| 1055 | nfs_pageio_doio(desc); | 1247 | |
| 1056 | if (!desc->pg_recoalesce) | 1248 | for (midx = 0; midx < desc->pg_mirror_count; midx++) |
| 1057 | break; | 1249 | nfs_pageio_complete_mirror(desc, midx); |
| 1058 | if (!nfs_do_recoalesce(desc)) | 1250 | |
| 1059 | break; | 1251 | if (desc->pg_ops->pg_cleanup) |
| 1060 | } | 1252 | desc->pg_ops->pg_cleanup(desc); |
| 1253 | nfs_pageio_cleanup_mirroring(desc); | ||
| 1061 | } | 1254 | } |
| 1062 | 1255 | ||
| 1063 | /** | 1256 | /** |
| @@ -1073,10 +1266,17 @@ void nfs_pageio_complete(struct nfs_pageio_descriptor *desc) | |||
| 1073 | */ | 1266 | */ |
| 1074 | void nfs_pageio_cond_complete(struct nfs_pageio_descriptor *desc, pgoff_t index) | 1267 | void nfs_pageio_cond_complete(struct nfs_pageio_descriptor *desc, pgoff_t index) |
| 1075 | { | 1268 | { |
| 1076 | if (!list_empty(&desc->pg_list)) { | 1269 | struct nfs_pgio_mirror *mirror; |
| 1077 | struct nfs_page *prev = nfs_list_entry(desc->pg_list.prev); | 1270 | struct nfs_page *prev; |
| 1078 | if (index != prev->wb_index + 1) | 1271 | u32 midx; |
| 1079 | nfs_pageio_complete(desc); | 1272 | |
| 1273 | for (midx = 0; midx < desc->pg_mirror_count; midx++) { | ||
| 1274 | mirror = &desc->pg_mirrors[midx]; | ||
| 1275 | if (!list_empty(&mirror->pg_list)) { | ||
| 1276 | prev = nfs_list_entry(mirror->pg_list.prev); | ||
| 1277 | if (index != prev->wb_index + 1) | ||
| 1278 | nfs_pageio_complete_mirror(desc, midx); | ||
| 1279 | } | ||
| 1080 | } | 1280 | } |
| 1081 | } | 1281 | } |
| 1082 | 1282 | ||
diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c index 0a5dda4d85c2..4f802b02fbb9 100644 --- a/fs/nfs/pnfs.c +++ b/fs/nfs/pnfs.c | |||
| @@ -34,6 +34,7 @@ | |||
| 34 | #include "pnfs.h" | 34 | #include "pnfs.h" |
| 35 | #include "iostat.h" | 35 | #include "iostat.h" |
| 36 | #include "nfs4trace.h" | 36 | #include "nfs4trace.h" |
| 37 | #include "delegation.h" | ||
| 37 | 38 | ||
| 38 | #define NFSDBG_FACILITY NFSDBG_PNFS | 39 | #define NFSDBG_FACILITY NFSDBG_PNFS |
| 39 | #define PNFS_LAYOUTGET_RETRY_TIMEOUT (120*HZ) | 40 | #define PNFS_LAYOUTGET_RETRY_TIMEOUT (120*HZ) |
| @@ -50,6 +51,10 @@ static DEFINE_SPINLOCK(pnfs_spinlock); | |||
| 50 | */ | 51 | */ |
| 51 | static LIST_HEAD(pnfs_modules_tbl); | 52 | static LIST_HEAD(pnfs_modules_tbl); |
| 52 | 53 | ||
| 54 | static int | ||
| 55 | pnfs_send_layoutreturn(struct pnfs_layout_hdr *lo, nfs4_stateid stateid, | ||
| 56 | enum pnfs_iomode iomode, bool sync); | ||
| 57 | |||
| 53 | /* Return the registered pnfs layout driver module matching given id */ | 58 | /* Return the registered pnfs layout driver module matching given id */ |
| 54 | static struct pnfs_layoutdriver_type * | 59 | static struct pnfs_layoutdriver_type * |
| 55 | find_pnfs_driver_locked(u32 id) | 60 | find_pnfs_driver_locked(u32 id) |
| @@ -238,6 +243,8 @@ pnfs_put_layout_hdr(struct pnfs_layout_hdr *lo) | |||
| 238 | struct inode *inode = lo->plh_inode; | 243 | struct inode *inode = lo->plh_inode; |
| 239 | 244 | ||
| 240 | 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"); | ||
| 241 | pnfs_detach_layout_hdr(lo); | 248 | pnfs_detach_layout_hdr(lo); |
| 242 | spin_unlock(&inode->i_lock); | 249 | spin_unlock(&inode->i_lock); |
| 243 | pnfs_free_layout_hdr(lo); | 250 | pnfs_free_layout_hdr(lo); |
| @@ -337,6 +344,48 @@ pnfs_layout_remove_lseg(struct pnfs_layout_hdr *lo, | |||
| 337 | rpc_wake_up(&NFS_SERVER(inode)->roc_rpcwaitq); | 344 | rpc_wake_up(&NFS_SERVER(inode)->roc_rpcwaitq); |
| 338 | } | 345 | } |
| 339 | 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_before_put_lseg(struct pnfs_layout_segment *lseg, | ||
| 365 | struct pnfs_layout_hdr *lo, struct inode *inode) | ||
| 366 | { | ||
| 367 | lo = lseg->pls_layout; | ||
| 368 | inode = lo->plh_inode; | ||
| 369 | |||
| 370 | spin_lock(&inode->i_lock); | ||
| 371 | if (pnfs_layout_need_return(lo, lseg)) { | ||
| 372 | nfs4_stateid stateid; | ||
| 373 | enum pnfs_iomode iomode; | ||
| 374 | |||
| 375 | stateid = lo->plh_stateid; | ||
| 376 | iomode = lo->plh_return_iomode; | ||
| 377 | /* decreased in pnfs_send_layoutreturn() */ | ||
| 378 | lo->plh_block_lgets++; | ||
| 379 | lo->plh_return_iomode = 0; | ||
| 380 | spin_unlock(&inode->i_lock); | ||
| 381 | pnfs_get_layout_hdr(lo); | ||
| 382 | |||
| 383 | /* Send an async layoutreturn so we dont deadlock */ | ||
| 384 | pnfs_send_layoutreturn(lo, stateid, iomode, false); | ||
| 385 | } else | ||
| 386 | spin_unlock(&inode->i_lock); | ||
| 387 | } | ||
| 388 | |||
| 340 | void | 389 | void |
| 341 | pnfs_put_lseg(struct pnfs_layout_segment *lseg) | 390 | pnfs_put_lseg(struct pnfs_layout_segment *lseg) |
| 342 | { | 391 | { |
| @@ -349,8 +398,17 @@ pnfs_put_lseg(struct pnfs_layout_segment *lseg) | |||
| 349 | dprintk("%s: lseg %p ref %d valid %d\n", __func__, lseg, | 398 | dprintk("%s: lseg %p ref %d valid %d\n", __func__, lseg, |
| 350 | atomic_read(&lseg->pls_refcount), | 399 | atomic_read(&lseg->pls_refcount), |
| 351 | test_bit(NFS_LSEG_VALID, &lseg->pls_flags)); | 400 | test_bit(NFS_LSEG_VALID, &lseg->pls_flags)); |
| 401 | |||
| 402 | /* Handle the case where refcount != 1 */ | ||
| 403 | if (atomic_add_unless(&lseg->pls_refcount, -1, 1)) | ||
| 404 | return; | ||
| 405 | |||
| 352 | lo = lseg->pls_layout; | 406 | lo = lseg->pls_layout; |
| 353 | inode = lo->plh_inode; | 407 | inode = lo->plh_inode; |
| 408 | /* Do we need a layoutreturn? */ | ||
| 409 | if (test_bit(NFS_LSEG_LAYOUTRETURN, &lseg->pls_flags)) | ||
| 410 | pnfs_layoutreturn_before_put_lseg(lseg, lo, inode); | ||
| 411 | |||
| 354 | if (atomic_dec_and_lock(&lseg->pls_refcount, &inode->i_lock)) { | 412 | if (atomic_dec_and_lock(&lseg->pls_refcount, &inode->i_lock)) { |
| 355 | pnfs_get_layout_hdr(lo); | 413 | pnfs_get_layout_hdr(lo); |
| 356 | pnfs_layout_remove_lseg(lo, lseg); | 414 | pnfs_layout_remove_lseg(lo, lseg); |
| @@ -543,6 +601,7 @@ pnfs_destroy_layout(struct nfs_inode *nfsi) | |||
| 543 | pnfs_get_layout_hdr(lo); | 601 | pnfs_get_layout_hdr(lo); |
| 544 | pnfs_layout_clear_fail_bit(lo, NFS_LAYOUT_RO_FAILED); | 602 | pnfs_layout_clear_fail_bit(lo, NFS_LAYOUT_RO_FAILED); |
| 545 | pnfs_layout_clear_fail_bit(lo, NFS_LAYOUT_RW_FAILED); | 603 | pnfs_layout_clear_fail_bit(lo, NFS_LAYOUT_RW_FAILED); |
| 604 | pnfs_clear_retry_layoutget(lo); | ||
| 546 | spin_unlock(&nfsi->vfs_inode.i_lock); | 605 | spin_unlock(&nfsi->vfs_inode.i_lock); |
| 547 | pnfs_free_lseg_list(&tmp_list); | 606 | pnfs_free_lseg_list(&tmp_list); |
| 548 | pnfs_put_layout_hdr(lo); | 607 | pnfs_put_layout_hdr(lo); |
| @@ -740,25 +799,37 @@ pnfs_layout_stateid_blocked(const struct pnfs_layout_hdr *lo, | |||
| 740 | return !pnfs_seqid_is_newer(seqid, lo->plh_barrier); | 799 | return !pnfs_seqid_is_newer(seqid, lo->plh_barrier); |
| 741 | } | 800 | } |
| 742 | 801 | ||
| 802 | static bool | ||
| 803 | pnfs_layout_returning(const struct pnfs_layout_hdr *lo, | ||
| 804 | struct pnfs_layout_range *range) | ||
| 805 | { | ||
| 806 | return test_bit(NFS_LAYOUT_RETURN, &lo->plh_flags) && | ||
| 807 | (lo->plh_return_iomode == IOMODE_ANY || | ||
| 808 | lo->plh_return_iomode == range->iomode); | ||
| 809 | } | ||
| 810 | |||
| 743 | /* lget is set to 1 if called from inside send_layoutget call chain */ | 811 | /* lget is set to 1 if called from inside send_layoutget call chain */ |
| 744 | static bool | 812 | static bool |
| 745 | pnfs_layoutgets_blocked(const struct pnfs_layout_hdr *lo, int lget) | 813 | pnfs_layoutgets_blocked(const struct pnfs_layout_hdr *lo, |
| 814 | struct pnfs_layout_range *range, int lget) | ||
| 746 | { | 815 | { |
| 747 | return lo->plh_block_lgets || | 816 | return lo->plh_block_lgets || |
| 748 | test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags) || | 817 | test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags) || |
| 749 | (list_empty(&lo->plh_segs) && | 818 | (list_empty(&lo->plh_segs) && |
| 750 | (atomic_read(&lo->plh_outstanding) > lget)); | 819 | (atomic_read(&lo->plh_outstanding) > lget)) || |
| 820 | pnfs_layout_returning(lo, range); | ||
| 751 | } | 821 | } |
| 752 | 822 | ||
| 753 | int | 823 | int |
| 754 | pnfs_choose_layoutget_stateid(nfs4_stateid *dst, struct pnfs_layout_hdr *lo, | 824 | pnfs_choose_layoutget_stateid(nfs4_stateid *dst, struct pnfs_layout_hdr *lo, |
| 825 | struct pnfs_layout_range *range, | ||
| 755 | struct nfs4_state *open_state) | 826 | struct nfs4_state *open_state) |
| 756 | { | 827 | { |
| 757 | int status = 0; | 828 | int status = 0; |
| 758 | 829 | ||
| 759 | dprintk("--> %s\n", __func__); | 830 | dprintk("--> %s\n", __func__); |
| 760 | spin_lock(&lo->plh_inode->i_lock); | 831 | spin_lock(&lo->plh_inode->i_lock); |
| 761 | if (pnfs_layoutgets_blocked(lo, 1)) { | 832 | if (pnfs_layoutgets_blocked(lo, range, 1)) { |
| 762 | status = -EAGAIN; | 833 | status = -EAGAIN; |
| 763 | } else if (!nfs4_valid_open_stateid(open_state)) { | 834 | } else if (!nfs4_valid_open_stateid(open_state)) { |
| 764 | status = -EBADF; | 835 | status = -EBADF; |
| @@ -825,7 +896,9 @@ send_layoutget(struct pnfs_layout_hdr *lo, | |||
| 825 | pnfs_layout_io_set_failed(lo, range->iomode); | 896 | pnfs_layout_io_set_failed(lo, range->iomode); |
| 826 | } | 897 | } |
| 827 | return NULL; | 898 | return NULL; |
| 828 | } | 899 | } else |
| 900 | pnfs_layout_clear_fail_bit(lo, | ||
| 901 | pnfs_iomode_to_fail_bit(range->iomode)); | ||
| 829 | 902 | ||
| 830 | return lseg; | 903 | return lseg; |
| 831 | } | 904 | } |
| @@ -845,6 +918,49 @@ static void pnfs_clear_layoutcommit(struct inode *inode, | |||
| 845 | } | 918 | } |
| 846 | } | 919 | } |
| 847 | 920 | ||
| 921 | void pnfs_clear_layoutreturn_waitbit(struct pnfs_layout_hdr *lo) | ||
| 922 | { | ||
| 923 | clear_bit_unlock(NFS_LAYOUT_RETURN, &lo->plh_flags); | ||
| 924 | smp_mb__after_atomic(); | ||
| 925 | wake_up_bit(&lo->plh_flags, NFS_LAYOUT_RETURN); | ||
| 926 | } | ||
| 927 | |||
| 928 | static int | ||
| 929 | pnfs_send_layoutreturn(struct pnfs_layout_hdr *lo, nfs4_stateid stateid, | ||
| 930 | enum pnfs_iomode iomode, bool sync) | ||
| 931 | { | ||
| 932 | struct inode *ino = lo->plh_inode; | ||
| 933 | struct nfs4_layoutreturn *lrp; | ||
| 934 | int status = 0; | ||
| 935 | |||
| 936 | lrp = kzalloc(sizeof(*lrp), GFP_NOFS); | ||
| 937 | if (unlikely(lrp == NULL)) { | ||
| 938 | status = -ENOMEM; | ||
| 939 | spin_lock(&ino->i_lock); | ||
| 940 | lo->plh_block_lgets--; | ||
| 941 | pnfs_clear_layoutreturn_waitbit(lo); | ||
| 942 | rpc_wake_up(&NFS_SERVER(ino)->roc_rpcwaitq); | ||
| 943 | spin_unlock(&ino->i_lock); | ||
| 944 | pnfs_put_layout_hdr(lo); | ||
| 945 | goto out; | ||
| 946 | } | ||
| 947 | |||
| 948 | lrp->args.stateid = stateid; | ||
| 949 | lrp->args.layout_type = NFS_SERVER(ino)->pnfs_curr_ld->id; | ||
| 950 | lrp->args.inode = ino; | ||
| 951 | lrp->args.range.iomode = iomode; | ||
| 952 | lrp->args.range.offset = 0; | ||
| 953 | lrp->args.range.length = NFS4_MAX_UINT64; | ||
| 954 | lrp->args.layout = lo; | ||
| 955 | lrp->clp = NFS_SERVER(ino)->nfs_client; | ||
| 956 | lrp->cred = lo->plh_lc_cred; | ||
| 957 | |||
| 958 | status = nfs4_proc_layoutreturn(lrp, sync); | ||
| 959 | out: | ||
| 960 | dprintk("<-- %s status: %d\n", __func__, status); | ||
| 961 | return status; | ||
| 962 | } | ||
| 963 | |||
| 848 | /* | 964 | /* |
| 849 | * Initiates a LAYOUTRETURN(FILE), and removes the pnfs_layout_hdr | 965 | * Initiates a LAYOUTRETURN(FILE), and removes the pnfs_layout_hdr |
| 850 | * when the layout segment list is empty. | 966 | * when the layout segment list is empty. |
| @@ -859,7 +975,6 @@ _pnfs_return_layout(struct inode *ino) | |||
| 859 | struct pnfs_layout_hdr *lo = NULL; | 975 | struct pnfs_layout_hdr *lo = NULL; |
| 860 | struct nfs_inode *nfsi = NFS_I(ino); | 976 | struct nfs_inode *nfsi = NFS_I(ino); |
| 861 | LIST_HEAD(tmp_list); | 977 | LIST_HEAD(tmp_list); |
| 862 | struct nfs4_layoutreturn *lrp; | ||
| 863 | nfs4_stateid stateid; | 978 | nfs4_stateid stateid; |
| 864 | int status = 0, empty; | 979 | int status = 0, empty; |
| 865 | 980 | ||
| @@ -901,24 +1016,7 @@ _pnfs_return_layout(struct inode *ino) | |||
| 901 | spin_unlock(&ino->i_lock); | 1016 | spin_unlock(&ino->i_lock); |
| 902 | pnfs_free_lseg_list(&tmp_list); | 1017 | pnfs_free_lseg_list(&tmp_list); |
| 903 | 1018 | ||
| 904 | lrp = kzalloc(sizeof(*lrp), GFP_KERNEL); | 1019 | status = pnfs_send_layoutreturn(lo, stateid, IOMODE_ANY, true); |
| 905 | if (unlikely(lrp == NULL)) { | ||
| 906 | status = -ENOMEM; | ||
| 907 | spin_lock(&ino->i_lock); | ||
| 908 | lo->plh_block_lgets--; | ||
| 909 | spin_unlock(&ino->i_lock); | ||
| 910 | pnfs_put_layout_hdr(lo); | ||
| 911 | goto out; | ||
| 912 | } | ||
| 913 | |||
| 914 | lrp->args.stateid = stateid; | ||
| 915 | lrp->args.layout_type = NFS_SERVER(ino)->pnfs_curr_ld->id; | ||
| 916 | lrp->args.inode = ino; | ||
| 917 | lrp->args.layout = lo; | ||
| 918 | lrp->clp = NFS_SERVER(ino)->nfs_client; | ||
| 919 | lrp->cred = lo->plh_lc_cred; | ||
| 920 | |||
| 921 | status = nfs4_proc_layoutreturn(lrp); | ||
| 922 | out: | 1020 | out: |
| 923 | dprintk("<-- %s status: %d\n", __func__, status); | 1021 | dprintk("<-- %s status: %d\n", __func__, status); |
| 924 | return status; | 1022 | return status; |
| @@ -954,31 +1052,60 @@ pnfs_commit_and_return_layout(struct inode *inode) | |||
| 954 | 1052 | ||
| 955 | bool pnfs_roc(struct inode *ino) | 1053 | bool pnfs_roc(struct inode *ino) |
| 956 | { | 1054 | { |
| 1055 | struct nfs_inode *nfsi = NFS_I(ino); | ||
| 1056 | struct nfs_open_context *ctx; | ||
| 1057 | struct nfs4_state *state; | ||
| 957 | struct pnfs_layout_hdr *lo; | 1058 | struct pnfs_layout_hdr *lo; |
| 958 | struct pnfs_layout_segment *lseg, *tmp; | 1059 | struct pnfs_layout_segment *lseg, *tmp; |
| 1060 | nfs4_stateid stateid; | ||
| 959 | LIST_HEAD(tmp_list); | 1061 | LIST_HEAD(tmp_list); |
| 960 | bool found = false; | 1062 | bool found = false, layoutreturn = false; |
| 961 | 1063 | ||
| 962 | spin_lock(&ino->i_lock); | 1064 | spin_lock(&ino->i_lock); |
| 963 | lo = NFS_I(ino)->layout; | 1065 | lo = nfsi->layout; |
| 964 | if (!lo || !test_and_clear_bit(NFS_LAYOUT_ROC, &lo->plh_flags) || | 1066 | if (!lo || !test_and_clear_bit(NFS_LAYOUT_ROC, &lo->plh_flags) || |
| 965 | test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags)) | 1067 | test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags)) |
| 966 | goto out_nolayout; | 1068 | goto out_noroc; |
| 1069 | |||
| 1070 | /* Don't return layout if we hold a delegation */ | ||
| 1071 | if (nfs4_check_delegation(ino, FMODE_READ)) | ||
| 1072 | goto out_noroc; | ||
| 1073 | |||
| 1074 | list_for_each_entry(ctx, &nfsi->open_files, list) { | ||
| 1075 | state = ctx->state; | ||
| 1076 | /* Don't return layout if there is open file state */ | ||
| 1077 | if (state != NULL && state->state != 0) | ||
| 1078 | goto out_noroc; | ||
| 1079 | } | ||
| 1080 | |||
| 1081 | pnfs_clear_retry_layoutget(lo); | ||
| 967 | list_for_each_entry_safe(lseg, tmp, &lo->plh_segs, pls_list) | 1082 | list_for_each_entry_safe(lseg, tmp, &lo->plh_segs, pls_list) |
| 968 | if (test_bit(NFS_LSEG_ROC, &lseg->pls_flags)) { | 1083 | if (test_bit(NFS_LSEG_ROC, &lseg->pls_flags)) { |
| 969 | mark_lseg_invalid(lseg, &tmp_list); | 1084 | mark_lseg_invalid(lseg, &tmp_list); |
| 970 | found = true; | 1085 | found = true; |
| 971 | } | 1086 | } |
| 972 | if (!found) | 1087 | if (!found) |
| 973 | goto out_nolayout; | 1088 | goto out_noroc; |
| 974 | lo->plh_block_lgets++; | 1089 | lo->plh_block_lgets++; |
| 975 | pnfs_get_layout_hdr(lo); /* matched in pnfs_roc_release */ | 1090 | pnfs_get_layout_hdr(lo); /* matched in pnfs_roc_release */ |
| 976 | spin_unlock(&ino->i_lock); | 1091 | spin_unlock(&ino->i_lock); |
| 977 | pnfs_free_lseg_list(&tmp_list); | 1092 | pnfs_free_lseg_list(&tmp_list); |
| 978 | return true; | 1093 | return true; |
| 979 | 1094 | ||
| 980 | out_nolayout: | 1095 | out_noroc: |
| 1096 | if (lo) { | ||
| 1097 | stateid = lo->plh_stateid; | ||
| 1098 | layoutreturn = | ||
| 1099 | test_and_clear_bit(NFS_LAYOUT_RETURN_BEFORE_CLOSE, | ||
| 1100 | &lo->plh_flags); | ||
| 1101 | if (layoutreturn) { | ||
| 1102 | lo->plh_block_lgets++; | ||
| 1103 | pnfs_get_layout_hdr(lo); | ||
| 1104 | } | ||
| 1105 | } | ||
| 981 | spin_unlock(&ino->i_lock); | 1106 | spin_unlock(&ino->i_lock); |
| 1107 | if (layoutreturn) | ||
| 1108 | pnfs_send_layoutreturn(lo, stateid, IOMODE_ANY, true); | ||
| 982 | return false; | 1109 | return false; |
| 983 | } | 1110 | } |
| 984 | 1111 | ||
| @@ -1013,8 +1140,9 @@ bool pnfs_roc_drain(struct inode *ino, u32 *barrier, struct rpc_task *task) | |||
| 1013 | struct nfs_inode *nfsi = NFS_I(ino); | 1140 | struct nfs_inode *nfsi = NFS_I(ino); |
| 1014 | struct pnfs_layout_hdr *lo; | 1141 | struct pnfs_layout_hdr *lo; |
| 1015 | struct pnfs_layout_segment *lseg; | 1142 | struct pnfs_layout_segment *lseg; |
| 1143 | nfs4_stateid stateid; | ||
| 1016 | u32 current_seqid; | 1144 | u32 current_seqid; |
| 1017 | bool found = false; | 1145 | bool found = false, layoutreturn = false; |
| 1018 | 1146 | ||
| 1019 | spin_lock(&ino->i_lock); | 1147 | spin_lock(&ino->i_lock); |
| 1020 | list_for_each_entry(lseg, &nfsi->layout->plh_segs, pls_list) | 1148 | list_for_each_entry(lseg, &nfsi->layout->plh_segs, pls_list) |
| @@ -1031,7 +1159,21 @@ bool pnfs_roc_drain(struct inode *ino, u32 *barrier, struct rpc_task *task) | |||
| 1031 | */ | 1159 | */ |
| 1032 | *barrier = current_seqid + atomic_read(&lo->plh_outstanding); | 1160 | *barrier = current_seqid + atomic_read(&lo->plh_outstanding); |
| 1033 | out: | 1161 | out: |
| 1162 | if (!found) { | ||
| 1163 | stateid = lo->plh_stateid; | ||
| 1164 | layoutreturn = | ||
| 1165 | test_and_clear_bit(NFS_LAYOUT_RETURN_BEFORE_CLOSE, | ||
| 1166 | &lo->plh_flags); | ||
| 1167 | if (layoutreturn) { | ||
| 1168 | lo->plh_block_lgets++; | ||
| 1169 | pnfs_get_layout_hdr(lo); | ||
| 1170 | } | ||
| 1171 | } | ||
| 1034 | spin_unlock(&ino->i_lock); | 1172 | spin_unlock(&ino->i_lock); |
| 1173 | if (layoutreturn) { | ||
| 1174 | rpc_sleep_on(&NFS_SERVER(ino)->roc_rpcwaitq, task, NULL); | ||
| 1175 | pnfs_send_layoutreturn(lo, stateid, IOMODE_ANY, false); | ||
| 1176 | } | ||
| 1035 | return found; | 1177 | return found; |
| 1036 | } | 1178 | } |
| 1037 | 1179 | ||
| @@ -1178,6 +1320,7 @@ pnfs_find_lseg(struct pnfs_layout_hdr *lo, | |||
| 1178 | 1320 | ||
| 1179 | list_for_each_entry(lseg, &lo->plh_segs, pls_list) { | 1321 | list_for_each_entry(lseg, &lo->plh_segs, pls_list) { |
| 1180 | if (test_bit(NFS_LSEG_VALID, &lseg->pls_flags) && | 1322 | if (test_bit(NFS_LSEG_VALID, &lseg->pls_flags) && |
| 1323 | !test_bit(NFS_LSEG_LAYOUTRETURN, &lseg->pls_flags) && | ||
| 1181 | pnfs_lseg_range_match(&lseg->pls_range, range)) { | 1324 | pnfs_lseg_range_match(&lseg->pls_range, range)) { |
| 1182 | ret = pnfs_get_lseg(lseg); | 1325 | ret = pnfs_get_lseg(lseg); |
| 1183 | break; | 1326 | break; |
| @@ -1266,6 +1409,35 @@ static bool pnfs_within_mdsthreshold(struct nfs_open_context *ctx, | |||
| 1266 | return ret; | 1409 | return ret; |
| 1267 | } | 1410 | } |
| 1268 | 1411 | ||
| 1412 | /* stop waiting if someone clears NFS_LAYOUT_RETRY_LAYOUTGET bit. */ | ||
| 1413 | static int pnfs_layoutget_retry_bit_wait(struct wait_bit_key *key) | ||
| 1414 | { | ||
| 1415 | if (!test_bit(NFS_LAYOUT_RETRY_LAYOUTGET, key->flags)) | ||
| 1416 | return 1; | ||
| 1417 | return nfs_wait_bit_killable(key); | ||
| 1418 | } | ||
| 1419 | |||
| 1420 | static bool pnfs_prepare_to_retry_layoutget(struct pnfs_layout_hdr *lo) | ||
| 1421 | { | ||
| 1422 | /* | ||
| 1423 | * send layoutcommit as it can hold up layoutreturn due to lseg | ||
| 1424 | * reference | ||
| 1425 | */ | ||
| 1426 | pnfs_layoutcommit_inode(lo->plh_inode, false); | ||
| 1427 | return !wait_on_bit_action(&lo->plh_flags, NFS_LAYOUT_RETURN, | ||
| 1428 | pnfs_layoutget_retry_bit_wait, | ||
| 1429 | TASK_UNINTERRUPTIBLE); | ||
| 1430 | } | ||
| 1431 | |||
| 1432 | static void pnfs_clear_first_layoutget(struct pnfs_layout_hdr *lo) | ||
| 1433 | { | ||
| 1434 | unsigned long *bitlock = &lo->plh_flags; | ||
| 1435 | |||
| 1436 | clear_bit_unlock(NFS_LAYOUT_FIRST_LAYOUTGET, bitlock); | ||
| 1437 | smp_mb__after_atomic(); | ||
| 1438 | wake_up_bit(bitlock, NFS_LAYOUT_FIRST_LAYOUTGET); | ||
| 1439 | } | ||
| 1440 | |||
| 1269 | /* | 1441 | /* |
| 1270 | * Layout segment is retreived from the server if not cached. | 1442 | * Layout segment is retreived from the server if not cached. |
| 1271 | * The appropriate layout segment is referenced and returned to the caller. | 1443 | * The appropriate layout segment is referenced and returned to the caller. |
| @@ -1296,6 +1468,8 @@ pnfs_update_layout(struct inode *ino, | |||
| 1296 | if (pnfs_within_mdsthreshold(ctx, ino, iomode)) | 1468 | if (pnfs_within_mdsthreshold(ctx, ino, iomode)) |
| 1297 | goto out; | 1469 | goto out; |
| 1298 | 1470 | ||
| 1471 | lookup_again: | ||
| 1472 | first = false; | ||
| 1299 | spin_lock(&ino->i_lock); | 1473 | spin_lock(&ino->i_lock); |
| 1300 | lo = pnfs_find_alloc_layout(ino, ctx, gfp_flags); | 1474 | lo = pnfs_find_alloc_layout(ino, ctx, gfp_flags); |
| 1301 | if (lo == NULL) { | 1475 | if (lo == NULL) { |
| @@ -1310,27 +1484,62 @@ pnfs_update_layout(struct inode *ino, | |||
| 1310 | } | 1484 | } |
| 1311 | 1485 | ||
| 1312 | /* if LAYOUTGET already failed once we don't try again */ | 1486 | /* if LAYOUTGET already failed once we don't try again */ |
| 1313 | if (pnfs_layout_io_test_failed(lo, iomode)) | 1487 | if (pnfs_layout_io_test_failed(lo, iomode) && |
| 1488 | !pnfs_should_retry_layoutget(lo)) | ||
| 1314 | goto out_unlock; | 1489 | goto out_unlock; |
| 1315 | 1490 | ||
| 1316 | /* Check to see if the layout for the given range already exists */ | 1491 | first = list_empty(&lo->plh_segs); |
| 1317 | lseg = pnfs_find_lseg(lo, &arg); | 1492 | if (first) { |
| 1318 | if (lseg) | 1493 | /* The first layoutget for the file. Need to serialize per |
| 1319 | goto out_unlock; | 1494 | * RFC 5661 Errata 3208. |
| 1495 | */ | ||
| 1496 | if (test_and_set_bit(NFS_LAYOUT_FIRST_LAYOUTGET, | ||
| 1497 | &lo->plh_flags)) { | ||
| 1498 | spin_unlock(&ino->i_lock); | ||
| 1499 | wait_on_bit(&lo->plh_flags, NFS_LAYOUT_FIRST_LAYOUTGET, | ||
| 1500 | TASK_UNINTERRUPTIBLE); | ||
| 1501 | pnfs_put_layout_hdr(lo); | ||
| 1502 | goto lookup_again; | ||
| 1503 | } | ||
| 1504 | } else { | ||
| 1505 | /* Check to see if the layout for the given range | ||
| 1506 | * already exists | ||
| 1507 | */ | ||
| 1508 | lseg = pnfs_find_lseg(lo, &arg); | ||
| 1509 | if (lseg) | ||
| 1510 | goto out_unlock; | ||
| 1511 | } | ||
| 1512 | |||
| 1513 | /* | ||
| 1514 | * Because we free lsegs before sending LAYOUTRETURN, we need to wait | ||
| 1515 | * for LAYOUTRETURN even if first is true. | ||
| 1516 | */ | ||
| 1517 | if (!lseg && pnfs_should_retry_layoutget(lo) && | ||
| 1518 | test_bit(NFS_LAYOUT_RETURN, &lo->plh_flags)) { | ||
| 1519 | spin_unlock(&ino->i_lock); | ||
| 1520 | dprintk("%s wait for layoutreturn\n", __func__); | ||
| 1521 | if (pnfs_prepare_to_retry_layoutget(lo)) { | ||
| 1522 | if (first) | ||
| 1523 | pnfs_clear_first_layoutget(lo); | ||
| 1524 | pnfs_put_layout_hdr(lo); | ||
| 1525 | dprintk("%s retrying\n", __func__); | ||
| 1526 | goto lookup_again; | ||
| 1527 | } | ||
| 1528 | goto out_put_layout_hdr; | ||
| 1529 | } | ||
| 1320 | 1530 | ||
| 1321 | if (pnfs_layoutgets_blocked(lo, 0)) | 1531 | if (pnfs_layoutgets_blocked(lo, &arg, 0)) |
| 1322 | goto out_unlock; | 1532 | goto out_unlock; |
| 1323 | atomic_inc(&lo->plh_outstanding); | 1533 | atomic_inc(&lo->plh_outstanding); |
| 1324 | |||
| 1325 | first = list_empty(&lo->plh_layouts) ? true : false; | ||
| 1326 | spin_unlock(&ino->i_lock); | 1534 | spin_unlock(&ino->i_lock); |
| 1327 | 1535 | ||
| 1328 | if (first) { | 1536 | if (list_empty(&lo->plh_layouts)) { |
| 1329 | /* The lo must be on the clp list if there is any | 1537 | /* The lo must be on the clp list if there is any |
| 1330 | * chance of a CB_LAYOUTRECALL(FILE) coming in. | 1538 | * chance of a CB_LAYOUTRECALL(FILE) coming in. |
| 1331 | */ | 1539 | */ |
| 1332 | spin_lock(&clp->cl_lock); | 1540 | spin_lock(&clp->cl_lock); |
| 1333 | list_add_tail(&lo->plh_layouts, &server->layouts); | 1541 | if (list_empty(&lo->plh_layouts)) |
| 1542 | list_add_tail(&lo->plh_layouts, &server->layouts); | ||
| 1334 | spin_unlock(&clp->cl_lock); | 1543 | spin_unlock(&clp->cl_lock); |
| 1335 | } | 1544 | } |
| 1336 | 1545 | ||
| @@ -1343,8 +1552,11 @@ pnfs_update_layout(struct inode *ino, | |||
| 1343 | arg.length = PAGE_CACHE_ALIGN(arg.length); | 1552 | arg.length = PAGE_CACHE_ALIGN(arg.length); |
| 1344 | 1553 | ||
| 1345 | lseg = send_layoutget(lo, ctx, &arg, gfp_flags); | 1554 | lseg = send_layoutget(lo, ctx, &arg, gfp_flags); |
| 1555 | pnfs_clear_retry_layoutget(lo); | ||
| 1346 | atomic_dec(&lo->plh_outstanding); | 1556 | atomic_dec(&lo->plh_outstanding); |
| 1347 | out_put_layout_hdr: | 1557 | out_put_layout_hdr: |
| 1558 | if (first) | ||
| 1559 | pnfs_clear_first_layoutget(lo); | ||
| 1348 | pnfs_put_layout_hdr(lo); | 1560 | pnfs_put_layout_hdr(lo); |
| 1349 | out: | 1561 | out: |
| 1350 | dprintk("%s: inode %s/%llu pNFS layout segment %s for " | 1562 | dprintk("%s: inode %s/%llu pNFS layout segment %s for " |
| @@ -1393,7 +1605,7 @@ pnfs_layout_process(struct nfs4_layoutget *lgp) | |||
| 1393 | goto out_forget_reply; | 1605 | goto out_forget_reply; |
| 1394 | } | 1606 | } |
| 1395 | 1607 | ||
| 1396 | if (pnfs_layoutgets_blocked(lo, 1)) { | 1608 | if (pnfs_layoutgets_blocked(lo, &lgp->args.range, 1)) { |
| 1397 | dprintk("%s forget reply due to state\n", __func__); | 1609 | dprintk("%s forget reply due to state\n", __func__); |
| 1398 | goto out_forget_reply; | 1610 | goto out_forget_reply; |
| 1399 | } | 1611 | } |
| @@ -1440,24 +1652,79 @@ out_forget_reply: | |||
| 1440 | goto out; | 1652 | goto out; |
| 1441 | } | 1653 | } |
| 1442 | 1654 | ||
| 1655 | static void | ||
| 1656 | pnfs_mark_matching_lsegs_return(struct pnfs_layout_hdr *lo, | ||
| 1657 | struct list_head *tmp_list, | ||
| 1658 | struct pnfs_layout_range *return_range) | ||
| 1659 | { | ||
| 1660 | struct pnfs_layout_segment *lseg, *next; | ||
| 1661 | |||
| 1662 | dprintk("%s:Begin lo %p\n", __func__, lo); | ||
| 1663 | |||
| 1664 | if (list_empty(&lo->plh_segs)) | ||
| 1665 | return; | ||
| 1666 | |||
| 1667 | list_for_each_entry_safe(lseg, next, &lo->plh_segs, pls_list) | ||
| 1668 | if (should_free_lseg(&lseg->pls_range, return_range)) { | ||
| 1669 | dprintk("%s: marking lseg %p iomode %d " | ||
| 1670 | "offset %llu length %llu\n", __func__, | ||
| 1671 | lseg, lseg->pls_range.iomode, | ||
| 1672 | lseg->pls_range.offset, | ||
| 1673 | lseg->pls_range.length); | ||
| 1674 | set_bit(NFS_LSEG_LAYOUTRETURN, &lseg->pls_flags); | ||
| 1675 | mark_lseg_invalid(lseg, tmp_list); | ||
| 1676 | } | ||
| 1677 | } | ||
| 1678 | |||
| 1679 | void pnfs_error_mark_layout_for_return(struct inode *inode, | ||
| 1680 | struct pnfs_layout_segment *lseg) | ||
| 1681 | { | ||
| 1682 | struct pnfs_layout_hdr *lo = NFS_I(inode)->layout; | ||
| 1683 | int iomode = pnfs_iomode_to_fail_bit(lseg->pls_range.iomode); | ||
| 1684 | struct pnfs_layout_range range = { | ||
| 1685 | .iomode = lseg->pls_range.iomode, | ||
| 1686 | .offset = 0, | ||
| 1687 | .length = NFS4_MAX_UINT64, | ||
| 1688 | }; | ||
| 1689 | LIST_HEAD(free_me); | ||
| 1690 | |||
| 1691 | spin_lock(&inode->i_lock); | ||
| 1692 | /* set failure bit so that pnfs path will be retried later */ | ||
| 1693 | pnfs_layout_set_fail_bit(lo, iomode); | ||
| 1694 | set_bit(NFS_LAYOUT_RETURN, &lo->plh_flags); | ||
| 1695 | if (lo->plh_return_iomode == 0) | ||
| 1696 | lo->plh_return_iomode = range.iomode; | ||
| 1697 | else if (lo->plh_return_iomode != range.iomode) | ||
| 1698 | lo->plh_return_iomode = IOMODE_ANY; | ||
| 1699 | /* | ||
| 1700 | * mark all matching lsegs so that we are sure to have no live | ||
| 1701 | * segments at hand when sending layoutreturn. See pnfs_put_lseg() | ||
| 1702 | * for how it works. | ||
| 1703 | */ | ||
| 1704 | pnfs_mark_matching_lsegs_return(lo, &free_me, &range); | ||
| 1705 | spin_unlock(&inode->i_lock); | ||
| 1706 | pnfs_free_lseg_list(&free_me); | ||
| 1707 | } | ||
| 1708 | EXPORT_SYMBOL_GPL(pnfs_error_mark_layout_for_return); | ||
| 1709 | |||
| 1443 | void | 1710 | void |
| 1444 | pnfs_generic_pg_init_read(struct nfs_pageio_descriptor *pgio, struct nfs_page *req) | 1711 | pnfs_generic_pg_init_read(struct nfs_pageio_descriptor *pgio, struct nfs_page *req) |
| 1445 | { | 1712 | { |
| 1446 | u64 rd_size = req->wb_bytes; | 1713 | u64 rd_size = req->wb_bytes; |
| 1447 | 1714 | ||
| 1448 | WARN_ON_ONCE(pgio->pg_lseg != NULL); | 1715 | if (pgio->pg_lseg == NULL) { |
| 1449 | 1716 | if (pgio->pg_dreq == NULL) | |
| 1450 | if (pgio->pg_dreq == NULL) | 1717 | rd_size = i_size_read(pgio->pg_inode) - req_offset(req); |
| 1451 | rd_size = i_size_read(pgio->pg_inode) - req_offset(req); | 1718 | else |
| 1452 | else | 1719 | rd_size = nfs_dreq_bytes_left(pgio->pg_dreq); |
| 1453 | rd_size = nfs_dreq_bytes_left(pgio->pg_dreq); | 1720 | |
| 1454 | 1721 | pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode, | |
| 1455 | pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode, | 1722 | req->wb_context, |
| 1456 | req->wb_context, | 1723 | req_offset(req), |
| 1457 | req_offset(req), | 1724 | rd_size, |
| 1458 | rd_size, | 1725 | IOMODE_READ, |
| 1459 | IOMODE_READ, | 1726 | GFP_KERNEL); |
| 1460 | GFP_KERNEL); | 1727 | } |
| 1461 | /* If no lseg, fall back to read through mds */ | 1728 | /* If no lseg, fall back to read through mds */ |
| 1462 | if (pgio->pg_lseg == NULL) | 1729 | if (pgio->pg_lseg == NULL) |
| 1463 | nfs_pageio_reset_read_mds(pgio); | 1730 | nfs_pageio_reset_read_mds(pgio); |
| @@ -1469,27 +1736,36 @@ void | |||
| 1469 | pnfs_generic_pg_init_write(struct nfs_pageio_descriptor *pgio, | 1736 | pnfs_generic_pg_init_write(struct nfs_pageio_descriptor *pgio, |
| 1470 | struct nfs_page *req, u64 wb_size) | 1737 | struct nfs_page *req, u64 wb_size) |
| 1471 | { | 1738 | { |
| 1472 | WARN_ON_ONCE(pgio->pg_lseg != NULL); | 1739 | if (pgio->pg_lseg == NULL) |
| 1473 | 1740 | pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode, | |
| 1474 | pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode, | 1741 | req->wb_context, |
| 1475 | req->wb_context, | 1742 | req_offset(req), |
| 1476 | req_offset(req), | 1743 | wb_size, |
| 1477 | wb_size, | 1744 | IOMODE_RW, |
| 1478 | IOMODE_RW, | 1745 | GFP_NOFS); |
| 1479 | GFP_NOFS); | ||
| 1480 | /* If no lseg, fall back to write through mds */ | 1746 | /* If no lseg, fall back to write through mds */ |
| 1481 | if (pgio->pg_lseg == NULL) | 1747 | if (pgio->pg_lseg == NULL) |
| 1482 | nfs_pageio_reset_write_mds(pgio); | 1748 | nfs_pageio_reset_write_mds(pgio); |
| 1483 | } | 1749 | } |
| 1484 | EXPORT_SYMBOL_GPL(pnfs_generic_pg_init_write); | 1750 | EXPORT_SYMBOL_GPL(pnfs_generic_pg_init_write); |
| 1485 | 1751 | ||
| 1752 | void | ||
| 1753 | pnfs_generic_pg_cleanup(struct nfs_pageio_descriptor *desc) | ||
| 1754 | { | ||
| 1755 | if (desc->pg_lseg) { | ||
| 1756 | pnfs_put_lseg(desc->pg_lseg); | ||
| 1757 | desc->pg_lseg = NULL; | ||
| 1758 | } | ||
| 1759 | } | ||
| 1760 | EXPORT_SYMBOL_GPL(pnfs_generic_pg_cleanup); | ||
| 1761 | |||
| 1486 | /* | 1762 | /* |
| 1487 | * Return 0 if @req cannot be coalesced into @pgio, otherwise return the number | 1763 | * Return 0 if @req cannot be coalesced into @pgio, otherwise return the number |
| 1488 | * of bytes (maximum @req->wb_bytes) that can be coalesced. | 1764 | * of bytes (maximum @req->wb_bytes) that can be coalesced. |
| 1489 | */ | 1765 | */ |
| 1490 | size_t | 1766 | size_t |
| 1491 | pnfs_generic_pg_test(struct nfs_pageio_descriptor *pgio, struct nfs_page *prev, | 1767 | pnfs_generic_pg_test(struct nfs_pageio_descriptor *pgio, |
| 1492 | struct nfs_page *req) | 1768 | struct nfs_page *prev, struct nfs_page *req) |
| 1493 | { | 1769 | { |
| 1494 | unsigned int size; | 1770 | unsigned int size; |
| 1495 | u64 seg_end, req_start, seg_left; | 1771 | u64 seg_end, req_start, seg_left; |
| @@ -1513,10 +1789,16 @@ pnfs_generic_pg_test(struct nfs_pageio_descriptor *pgio, struct nfs_page *prev, | |||
| 1513 | seg_end = end_offset(pgio->pg_lseg->pls_range.offset, | 1789 | seg_end = end_offset(pgio->pg_lseg->pls_range.offset, |
| 1514 | pgio->pg_lseg->pls_range.length); | 1790 | pgio->pg_lseg->pls_range.length); |
| 1515 | req_start = req_offset(req); | 1791 | req_start = req_offset(req); |
| 1516 | WARN_ON_ONCE(req_start > seg_end); | 1792 | WARN_ON_ONCE(req_start >= seg_end); |
| 1517 | /* start of request is past the last byte of this segment */ | 1793 | /* start of request is past the last byte of this segment */ |
| 1518 | if (req_start >= seg_end) | 1794 | if (req_start >= seg_end) { |
| 1795 | /* reference the new lseg */ | ||
| 1796 | if (pgio->pg_ops->pg_cleanup) | ||
| 1797 | pgio->pg_ops->pg_cleanup(pgio); | ||
| 1798 | if (pgio->pg_ops->pg_init) | ||
| 1799 | pgio->pg_ops->pg_init(pgio, req); | ||
| 1519 | return 0; | 1800 | return 0; |
| 1801 | } | ||
| 1520 | 1802 | ||
| 1521 | /* adjust 'size' iff there are fewer bytes left in the | 1803 | /* adjust 'size' iff there are fewer bytes left in the |
| 1522 | * segment than what nfs_generic_pg_test returned */ | 1804 | * segment than what nfs_generic_pg_test returned */ |
| @@ -1571,10 +1853,12 @@ static void | |||
| 1571 | pnfs_write_through_mds(struct nfs_pageio_descriptor *desc, | 1853 | pnfs_write_through_mds(struct nfs_pageio_descriptor *desc, |
| 1572 | struct nfs_pgio_header *hdr) | 1854 | struct nfs_pgio_header *hdr) |
| 1573 | { | 1855 | { |
| 1856 | struct nfs_pgio_mirror *mirror = nfs_pgio_current_mirror(desc); | ||
| 1857 | |||
| 1574 | if (!test_and_set_bit(NFS_IOHDR_REDO, &hdr->flags)) { | 1858 | if (!test_and_set_bit(NFS_IOHDR_REDO, &hdr->flags)) { |
| 1575 | list_splice_tail_init(&hdr->pages, &desc->pg_list); | 1859 | list_splice_tail_init(&hdr->pages, &mirror->pg_list); |
| 1576 | nfs_pageio_reset_write_mds(desc); | 1860 | nfs_pageio_reset_write_mds(desc); |
| 1577 | desc->pg_recoalesce = 1; | 1861 | mirror->pg_recoalesce = 1; |
| 1578 | } | 1862 | } |
| 1579 | nfs_pgio_data_destroy(hdr); | 1863 | nfs_pgio_data_destroy(hdr); |
| 1580 | } | 1864 | } |
| @@ -1608,11 +1892,9 @@ pnfs_do_write(struct nfs_pageio_descriptor *desc, | |||
| 1608 | struct pnfs_layout_segment *lseg = desc->pg_lseg; | 1892 | struct pnfs_layout_segment *lseg = desc->pg_lseg; |
| 1609 | enum pnfs_try_status trypnfs; | 1893 | enum pnfs_try_status trypnfs; |
| 1610 | 1894 | ||
| 1611 | desc->pg_lseg = NULL; | ||
| 1612 | trypnfs = pnfs_try_to_write_data(hdr, call_ops, lseg, how); | 1895 | trypnfs = pnfs_try_to_write_data(hdr, call_ops, lseg, how); |
| 1613 | if (trypnfs == PNFS_NOT_ATTEMPTED) | 1896 | if (trypnfs == PNFS_NOT_ATTEMPTED) |
| 1614 | pnfs_write_through_mds(desc, hdr); | 1897 | pnfs_write_through_mds(desc, hdr); |
| 1615 | pnfs_put_lseg(lseg); | ||
| 1616 | } | 1898 | } |
| 1617 | 1899 | ||
| 1618 | static void pnfs_writehdr_free(struct nfs_pgio_header *hdr) | 1900 | static void pnfs_writehdr_free(struct nfs_pgio_header *hdr) |
| @@ -1625,24 +1907,23 @@ EXPORT_SYMBOL_GPL(pnfs_writehdr_free); | |||
| 1625 | int | 1907 | int |
| 1626 | pnfs_generic_pg_writepages(struct nfs_pageio_descriptor *desc) | 1908 | pnfs_generic_pg_writepages(struct nfs_pageio_descriptor *desc) |
| 1627 | { | 1909 | { |
| 1910 | struct nfs_pgio_mirror *mirror = nfs_pgio_current_mirror(desc); | ||
| 1911 | |||
| 1628 | struct nfs_pgio_header *hdr; | 1912 | struct nfs_pgio_header *hdr; |
| 1629 | int ret; | 1913 | int ret; |
| 1630 | 1914 | ||
| 1631 | hdr = nfs_pgio_header_alloc(desc->pg_rw_ops); | 1915 | hdr = nfs_pgio_header_alloc(desc->pg_rw_ops); |
| 1632 | if (!hdr) { | 1916 | if (!hdr) { |
| 1633 | desc->pg_completion_ops->error_cleanup(&desc->pg_list); | 1917 | desc->pg_completion_ops->error_cleanup(&mirror->pg_list); |
| 1634 | pnfs_put_lseg(desc->pg_lseg); | ||
| 1635 | desc->pg_lseg = NULL; | ||
| 1636 | return -ENOMEM; | 1918 | return -ENOMEM; |
| 1637 | } | 1919 | } |
| 1638 | nfs_pgheader_init(desc, hdr, pnfs_writehdr_free); | 1920 | nfs_pgheader_init(desc, hdr, pnfs_writehdr_free); |
| 1921 | |||
| 1639 | hdr->lseg = pnfs_get_lseg(desc->pg_lseg); | 1922 | hdr->lseg = pnfs_get_lseg(desc->pg_lseg); |
| 1640 | ret = nfs_generic_pgio(desc, hdr); | 1923 | ret = nfs_generic_pgio(desc, hdr); |
| 1641 | if (ret != 0) { | 1924 | if (!ret) |
| 1642 | pnfs_put_lseg(desc->pg_lseg); | ||
| 1643 | desc->pg_lseg = NULL; | ||
| 1644 | } else | ||
| 1645 | pnfs_do_write(desc, hdr, desc->pg_ioflags); | 1925 | pnfs_do_write(desc, hdr, desc->pg_ioflags); |
| 1926 | |||
| 1646 | return ret; | 1927 | return ret; |
| 1647 | } | 1928 | } |
| 1648 | EXPORT_SYMBOL_GPL(pnfs_generic_pg_writepages); | 1929 | EXPORT_SYMBOL_GPL(pnfs_generic_pg_writepages); |
| @@ -1687,10 +1968,12 @@ static void | |||
| 1687 | pnfs_read_through_mds(struct nfs_pageio_descriptor *desc, | 1968 | pnfs_read_through_mds(struct nfs_pageio_descriptor *desc, |
| 1688 | struct nfs_pgio_header *hdr) | 1969 | struct nfs_pgio_header *hdr) |
| 1689 | { | 1970 | { |
| 1971 | struct nfs_pgio_mirror *mirror = nfs_pgio_current_mirror(desc); | ||
| 1972 | |||
| 1690 | if (!test_and_set_bit(NFS_IOHDR_REDO, &hdr->flags)) { | 1973 | if (!test_and_set_bit(NFS_IOHDR_REDO, &hdr->flags)) { |
| 1691 | list_splice_tail_init(&hdr->pages, &desc->pg_list); | 1974 | list_splice_tail_init(&hdr->pages, &mirror->pg_list); |
| 1692 | nfs_pageio_reset_read_mds(desc); | 1975 | nfs_pageio_reset_read_mds(desc); |
| 1693 | desc->pg_recoalesce = 1; | 1976 | mirror->pg_recoalesce = 1; |
| 1694 | } | 1977 | } |
| 1695 | nfs_pgio_data_destroy(hdr); | 1978 | nfs_pgio_data_destroy(hdr); |
| 1696 | } | 1979 | } |
| @@ -1719,18 +2002,29 @@ pnfs_try_to_read_data(struct nfs_pgio_header *hdr, | |||
| 1719 | return trypnfs; | 2002 | return trypnfs; |
| 1720 | } | 2003 | } |
| 1721 | 2004 | ||
| 2005 | /* Resend all requests through pnfs. */ | ||
| 2006 | int pnfs_read_resend_pnfs(struct nfs_pgio_header *hdr) | ||
| 2007 | { | ||
| 2008 | struct nfs_pageio_descriptor pgio; | ||
| 2009 | |||
| 2010 | nfs_pageio_init_read(&pgio, hdr->inode, false, hdr->completion_ops); | ||
| 2011 | return nfs_pageio_resend(&pgio, hdr); | ||
| 2012 | } | ||
| 2013 | EXPORT_SYMBOL_GPL(pnfs_read_resend_pnfs); | ||
| 2014 | |||
| 1722 | static void | 2015 | static void |
| 1723 | pnfs_do_read(struct nfs_pageio_descriptor *desc, struct nfs_pgio_header *hdr) | 2016 | pnfs_do_read(struct nfs_pageio_descriptor *desc, struct nfs_pgio_header *hdr) |
| 1724 | { | 2017 | { |
| 1725 | const struct rpc_call_ops *call_ops = desc->pg_rpc_callops; | 2018 | const struct rpc_call_ops *call_ops = desc->pg_rpc_callops; |
| 1726 | struct pnfs_layout_segment *lseg = desc->pg_lseg; | 2019 | struct pnfs_layout_segment *lseg = desc->pg_lseg; |
| 1727 | enum pnfs_try_status trypnfs; | 2020 | enum pnfs_try_status trypnfs; |
| 2021 | int err = 0; | ||
| 1728 | 2022 | ||
| 1729 | desc->pg_lseg = NULL; | ||
| 1730 | trypnfs = pnfs_try_to_read_data(hdr, call_ops, lseg); | 2023 | trypnfs = pnfs_try_to_read_data(hdr, call_ops, lseg); |
| 1731 | if (trypnfs == PNFS_NOT_ATTEMPTED) | 2024 | if (trypnfs == PNFS_TRY_AGAIN) |
| 2025 | err = pnfs_read_resend_pnfs(hdr); | ||
| 2026 | if (trypnfs == PNFS_NOT_ATTEMPTED || err) | ||
| 1732 | pnfs_read_through_mds(desc, hdr); | 2027 | pnfs_read_through_mds(desc, hdr); |
| 1733 | pnfs_put_lseg(lseg); | ||
| 1734 | } | 2028 | } |
| 1735 | 2029 | ||
| 1736 | static void pnfs_readhdr_free(struct nfs_pgio_header *hdr) | 2030 | static void pnfs_readhdr_free(struct nfs_pgio_header *hdr) |
| @@ -1743,24 +2037,20 @@ EXPORT_SYMBOL_GPL(pnfs_readhdr_free); | |||
| 1743 | int | 2037 | int |
| 1744 | pnfs_generic_pg_readpages(struct nfs_pageio_descriptor *desc) | 2038 | pnfs_generic_pg_readpages(struct nfs_pageio_descriptor *desc) |
| 1745 | { | 2039 | { |
| 2040 | struct nfs_pgio_mirror *mirror = nfs_pgio_current_mirror(desc); | ||
| 2041 | |||
| 1746 | struct nfs_pgio_header *hdr; | 2042 | struct nfs_pgio_header *hdr; |
| 1747 | int ret; | 2043 | int ret; |
| 1748 | 2044 | ||
| 1749 | hdr = nfs_pgio_header_alloc(desc->pg_rw_ops); | 2045 | hdr = nfs_pgio_header_alloc(desc->pg_rw_ops); |
| 1750 | if (!hdr) { | 2046 | if (!hdr) { |
| 1751 | desc->pg_completion_ops->error_cleanup(&desc->pg_list); | 2047 | desc->pg_completion_ops->error_cleanup(&mirror->pg_list); |
| 1752 | ret = -ENOMEM; | 2048 | return -ENOMEM; |
| 1753 | pnfs_put_lseg(desc->pg_lseg); | ||
| 1754 | desc->pg_lseg = NULL; | ||
| 1755 | return ret; | ||
| 1756 | } | 2049 | } |
| 1757 | nfs_pgheader_init(desc, hdr, pnfs_readhdr_free); | 2050 | nfs_pgheader_init(desc, hdr, pnfs_readhdr_free); |
| 1758 | hdr->lseg = pnfs_get_lseg(desc->pg_lseg); | 2051 | hdr->lseg = pnfs_get_lseg(desc->pg_lseg); |
| 1759 | ret = nfs_generic_pgio(desc, hdr); | 2052 | ret = nfs_generic_pgio(desc, hdr); |
| 1760 | if (ret != 0) { | 2053 | if (!ret) |
| 1761 | pnfs_put_lseg(desc->pg_lseg); | ||
| 1762 | desc->pg_lseg = NULL; | ||
| 1763 | } else | ||
| 1764 | pnfs_do_read(desc, hdr); | 2054 | pnfs_do_read(desc, hdr); |
| 1765 | return ret; | 2055 | return ret; |
| 1766 | } | 2056 | } |
| @@ -1966,6 +2256,7 @@ clear_layoutcommitting: | |||
| 1966 | pnfs_clear_layoutcommitting(inode); | 2256 | pnfs_clear_layoutcommitting(inode); |
| 1967 | goto out; | 2257 | goto out; |
| 1968 | } | 2258 | } |
| 2259 | EXPORT_SYMBOL_GPL(pnfs_layoutcommit_inode); | ||
| 1969 | 2260 | ||
| 1970 | struct nfs4_threshold *pnfs_mdsthreshold_alloc(void) | 2261 | struct nfs4_threshold *pnfs_mdsthreshold_alloc(void) |
| 1971 | { | 2262 | { |
diff --git a/fs/nfs/pnfs.h b/fs/nfs/pnfs.h index 9ae5b765b073..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,39 @@ 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 | |||
| 348 | static inline bool nfs_have_layout(struct inode *inode) | ||
| 349 | { | ||
| 350 | return NFS_I(inode)->layout != NULL; | ||
| 351 | } | ||
| 352 | |||
| 278 | static inline struct nfs4_deviceid_node * | 353 | static inline struct nfs4_deviceid_node * |
| 279 | nfs4_get_deviceid(struct nfs4_deviceid_node *d) | 354 | nfs4_get_deviceid(struct nfs4_deviceid_node *d) |
| 280 | { | 355 | { |
| @@ -282,6 +357,26 @@ nfs4_get_deviceid(struct nfs4_deviceid_node *d) | |||
| 282 | return d; | 357 | return d; |
| 283 | } | 358 | } |
| 284 | 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 | |||
| 285 | static inline struct pnfs_layout_segment * | 380 | static inline struct pnfs_layout_segment * |
| 286 | pnfs_get_lseg(struct pnfs_layout_segment *lseg) | 381 | pnfs_get_lseg(struct pnfs_layout_segment *lseg) |
| 287 | { | 382 | { |
| @@ -317,16 +412,22 @@ pnfs_get_ds_info(struct inode *inode) | |||
| 317 | return ld->get_ds_info(inode); | 412 | return ld->get_ds_info(inode); |
| 318 | } | 413 | } |
| 319 | 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 | |||
| 320 | static inline bool | 421 | static inline bool |
| 321 | 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, |
| 322 | struct nfs_commit_info *cinfo) | 423 | struct nfs_commit_info *cinfo, u32 ds_commit_idx) |
| 323 | { | 424 | { |
| 324 | struct inode *inode = req->wb_context->dentry->d_inode; | 425 | struct inode *inode = req->wb_context->dentry->d_inode; |
| 325 | struct pnfs_layoutdriver_type *ld = NFS_SERVER(inode)->pnfs_curr_ld; | 426 | struct pnfs_layoutdriver_type *ld = NFS_SERVER(inode)->pnfs_curr_ld; |
| 326 | 427 | ||
| 327 | if (lseg == NULL || ld->mark_request_commit == NULL) | 428 | if (lseg == NULL || ld->mark_request_commit == NULL) |
| 328 | return false; | 429 | return false; |
| 329 | ld->mark_request_commit(req, lseg, cinfo); | 430 | ld->mark_request_commit(req, lseg, cinfo, ds_commit_idx); |
| 330 | return true; | 431 | return true; |
| 331 | } | 432 | } |
| 332 | 433 | ||
| @@ -352,15 +453,6 @@ pnfs_scan_commit_lists(struct inode *inode, struct nfs_commit_info *cinfo, | |||
| 352 | 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); |
| 353 | } | 454 | } |
| 354 | 455 | ||
| 355 | static inline void | ||
| 356 | pnfs_recover_commit_reqs(struct inode *inode, struct list_head *list, | ||
| 357 | struct nfs_commit_info *cinfo) | ||
| 358 | { | ||
| 359 | if (cinfo->ds == NULL || cinfo->ds->nwritten == 0) | ||
| 360 | return; | ||
| 361 | NFS_SERVER(inode)->pnfs_curr_ld->recover_commit_reqs(list, cinfo); | ||
| 362 | } | ||
| 363 | |||
| 364 | static inline struct nfs_page * | 456 | static inline struct nfs_page * |
| 365 | 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, |
| 366 | struct page *page) | 458 | struct page *page) |
| @@ -427,6 +519,11 @@ static inline void nfs4_print_deviceid(const struct nfs4_deviceid *dev_id) | |||
| 427 | #endif /* NFS_DEBUG */ | 519 | #endif /* NFS_DEBUG */ |
| 428 | #else /* CONFIG_NFS_V4_1 */ | 520 | #else /* CONFIG_NFS_V4_1 */ |
| 429 | 521 | ||
| 522 | static inline bool nfs_have_layout(struct inode *inode) | ||
| 523 | { | ||
| 524 | return false; | ||
| 525 | } | ||
| 526 | |||
| 430 | static inline void pnfs_destroy_all_layouts(struct nfs_client *clp) | 527 | static inline void pnfs_destroy_all_layouts(struct nfs_client *clp) |
| 431 | { | 528 | { |
| 432 | } | 529 | } |
| @@ -513,7 +610,7 @@ pnfs_get_ds_info(struct inode *inode) | |||
| 513 | 610 | ||
| 514 | static inline bool | 611 | static inline bool |
| 515 | 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, |
| 516 | struct nfs_commit_info *cinfo) | 613 | struct nfs_commit_info *cinfo, u32 ds_commit_idx) |
| 517 | { | 614 | { |
| 518 | return false; | 615 | return false; |
| 519 | } | 616 | } |
| @@ -531,12 +628,6 @@ pnfs_scan_commit_lists(struct inode *inode, struct nfs_commit_info *cinfo, | |||
| 531 | return 0; | 628 | return 0; |
| 532 | } | 629 | } |
| 533 | 630 | ||
| 534 | static inline void | ||
| 535 | pnfs_recover_commit_reqs(struct inode *inode, struct list_head *list, | ||
| 536 | struct nfs_commit_info *cinfo) | ||
| 537 | { | ||
| 538 | } | ||
| 539 | |||
| 540 | static inline struct nfs_page * | 631 | static inline struct nfs_page * |
| 541 | 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, |
| 542 | struct page *page) | 633 | struct page *page) |
| @@ -568,6 +659,10 @@ static inline struct nfs4_threshold *pnfs_mdsthreshold_alloc(void) | |||
| 568 | return NULL; | 659 | return NULL; |
| 569 | } | 660 | } |
| 570 | 661 | ||
| 662 | static inline void nfs4_pnfs_v3_ds_connect_unload(void) | ||
| 663 | { | ||
| 664 | } | ||
| 665 | |||
| 571 | #endif /* CONFIG_NFS_V4_1 */ | 666 | #endif /* CONFIG_NFS_V4_1 */ |
| 572 | 667 | ||
| 573 | #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/super.c b/fs/nfs/super.c index 31a11b0e885d..322b2de02988 100644 --- a/fs/nfs/super.c +++ b/fs/nfs/super.c | |||
| @@ -311,7 +311,6 @@ const struct super_operations nfs_sops = { | |||
| 311 | .destroy_inode = nfs_destroy_inode, | 311 | .destroy_inode = nfs_destroy_inode, |
| 312 | .write_inode = nfs_write_inode, | 312 | .write_inode = nfs_write_inode, |
| 313 | .drop_inode = nfs_drop_inode, | 313 | .drop_inode = nfs_drop_inode, |
| 314 | .put_super = nfs_put_super, | ||
| 315 | .statfs = nfs_statfs, | 314 | .statfs = nfs_statfs, |
| 316 | .evict_inode = nfs_evict_inode, | 315 | .evict_inode = nfs_evict_inode, |
| 317 | .umount_begin = nfs_umount_begin, | 316 | .umount_begin = nfs_umount_begin, |
| @@ -405,12 +404,15 @@ void __exit unregister_nfs_fs(void) | |||
| 405 | unregister_filesystem(&nfs_fs_type); | 404 | unregister_filesystem(&nfs_fs_type); |
| 406 | } | 405 | } |
| 407 | 406 | ||
| 408 | void nfs_sb_active(struct super_block *sb) | 407 | bool nfs_sb_active(struct super_block *sb) |
| 409 | { | 408 | { |
| 410 | struct nfs_server *server = NFS_SB(sb); | 409 | struct nfs_server *server = NFS_SB(sb); |
| 411 | 410 | ||
| 412 | if (atomic_inc_return(&server->active) == 1) | 411 | if (!atomic_inc_not_zero(&sb->s_active)) |
| 413 | atomic_inc(&sb->s_active); | 412 | return false; |
| 413 | if (atomic_inc_return(&server->active) != 1) | ||
| 414 | atomic_dec(&sb->s_active); | ||
| 415 | return true; | ||
| 414 | } | 416 | } |
| 415 | EXPORT_SYMBOL_GPL(nfs_sb_active); | 417 | EXPORT_SYMBOL_GPL(nfs_sb_active); |
| 416 | 418 | ||
| @@ -2569,7 +2571,7 @@ struct dentry *nfs_fs_mount_common(struct nfs_server *server, | |||
| 2569 | error = nfs_bdi_register(server); | 2571 | error = nfs_bdi_register(server); |
| 2570 | if (error) { | 2572 | if (error) { |
| 2571 | mntroot = ERR_PTR(error); | 2573 | mntroot = ERR_PTR(error); |
| 2572 | goto error_splat_bdi; | 2574 | goto error_splat_super; |
| 2573 | } | 2575 | } |
| 2574 | server->super = s; | 2576 | server->super = s; |
| 2575 | } | 2577 | } |
| @@ -2601,9 +2603,6 @@ error_splat_root: | |||
| 2601 | dput(mntroot); | 2603 | dput(mntroot); |
| 2602 | mntroot = ERR_PTR(error); | 2604 | mntroot = ERR_PTR(error); |
| 2603 | error_splat_super: | 2605 | error_splat_super: |
| 2604 | if (server && !s->s_root) | ||
| 2605 | bdi_unregister(&server->backing_dev_info); | ||
| 2606 | error_splat_bdi: | ||
| 2607 | deactivate_locked_super(s); | 2606 | deactivate_locked_super(s); |
| 2608 | goto out; | 2607 | goto out; |
| 2609 | } | 2608 | } |
| @@ -2651,27 +2650,19 @@ out: | |||
| 2651 | EXPORT_SYMBOL_GPL(nfs_fs_mount); | 2650 | EXPORT_SYMBOL_GPL(nfs_fs_mount); |
| 2652 | 2651 | ||
| 2653 | /* | 2652 | /* |
| 2654 | * Ensure that we unregister the bdi before kill_anon_super | ||
| 2655 | * releases the device name | ||
| 2656 | */ | ||
| 2657 | void nfs_put_super(struct super_block *s) | ||
| 2658 | { | ||
| 2659 | struct nfs_server *server = NFS_SB(s); | ||
| 2660 | |||
| 2661 | bdi_unregister(&server->backing_dev_info); | ||
| 2662 | } | ||
| 2663 | EXPORT_SYMBOL_GPL(nfs_put_super); | ||
| 2664 | |||
| 2665 | /* | ||
| 2666 | * Destroy an NFS2/3 superblock | 2653 | * Destroy an NFS2/3 superblock |
| 2667 | */ | 2654 | */ |
| 2668 | void nfs_kill_super(struct super_block *s) | 2655 | void nfs_kill_super(struct super_block *s) |
| 2669 | { | 2656 | { |
| 2670 | struct nfs_server *server = NFS_SB(s); | 2657 | struct nfs_server *server = NFS_SB(s); |
| 2658 | dev_t dev = s->s_dev; | ||
| 2659 | |||
| 2660 | generic_shutdown_super(s); | ||
| 2671 | 2661 | ||
| 2672 | kill_anon_super(s); | ||
| 2673 | nfs_fscache_release_super_cookie(s); | 2662 | nfs_fscache_release_super_cookie(s); |
| 2663 | |||
| 2674 | nfs_free_server(server); | 2664 | nfs_free_server(server); |
| 2665 | free_anon_bdev(dev); | ||
| 2675 | } | 2666 | } |
| 2676 | EXPORT_SYMBOL_GPL(nfs_kill_super); | 2667 | EXPORT_SYMBOL_GPL(nfs_kill_super); |
| 2677 | 2668 | ||
diff --git a/fs/nfs/write.c b/fs/nfs/write.c index af3af685a9e3..88a6d2196ece 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 |
| @@ -786,7 +791,7 @@ nfs_request_add_commit_list(struct nfs_page *req, struct list_head *dst, | |||
| 786 | spin_unlock(cinfo->lock); | 791 | spin_unlock(cinfo->lock); |
| 787 | if (!cinfo->dreq) { | 792 | if (!cinfo->dreq) { |
| 788 | inc_zone_page_state(req->wb_page, NR_UNSTABLE_NFS); | 793 | inc_zone_page_state(req->wb_page, NR_UNSTABLE_NFS); |
| 789 | inc_bdi_stat(page_file_mapping(req->wb_page)->backing_dev_info, | 794 | inc_bdi_stat(inode_to_bdi(page_file_mapping(req->wb_page)->host), |
| 790 | BDI_RECLAIMABLE); | 795 | BDI_RECLAIMABLE); |
| 791 | __mark_inode_dirty(req->wb_context->dentry->d_inode, | 796 | __mark_inode_dirty(req->wb_context->dentry->d_inode, |
| 792 | I_DIRTY_DATASYNC); | 797 | I_DIRTY_DATASYNC); |
| @@ -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 | } |
| @@ -853,7 +858,7 @@ static void | |||
| 853 | nfs_clear_page_commit(struct page *page) | 858 | nfs_clear_page_commit(struct page *page) |
| 854 | { | 859 | { |
| 855 | dec_zone_page_state(page, NR_UNSTABLE_NFS); | 860 | dec_zone_page_state(page, NR_UNSTABLE_NFS); |
| 856 | dec_bdi_stat(page_file_mapping(page)->backing_dev_info, BDI_RECLAIMABLE); | 861 | dec_bdi_stat(inode_to_bdi(page_file_mapping(page)->host), BDI_RECLAIMABLE); |
| 857 | } | 862 | } |
| 858 | 863 | ||
| 859 | /* Called holding inode (/cinfo) lock */ | 864 | /* Called holding inode (/cinfo) lock */ |
| @@ -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: |
| @@ -1091,6 +1097,7 @@ int nfs_flush_incompatible(struct file *file, struct page *page) | |||
| 1091 | { | 1097 | { |
| 1092 | struct nfs_open_context *ctx = nfs_file_open_context(file); | 1098 | struct nfs_open_context *ctx = nfs_file_open_context(file); |
| 1093 | struct nfs_lock_context *l_ctx; | 1099 | struct nfs_lock_context *l_ctx; |
| 1100 | struct file_lock_context *flctx = file_inode(file)->i_flctx; | ||
| 1094 | struct nfs_page *req; | 1101 | struct nfs_page *req; |
| 1095 | int do_flush, status; | 1102 | int do_flush, status; |
| 1096 | /* | 1103 | /* |
| @@ -1109,7 +1116,9 @@ int nfs_flush_incompatible(struct file *file, struct page *page) | |||
| 1109 | do_flush = req->wb_page != page || req->wb_context != ctx; | 1116 | do_flush = req->wb_page != page || req->wb_context != ctx; |
| 1110 | /* for now, flush if more than 1 request in page_group */ | 1117 | /* for now, flush if more than 1 request in page_group */ |
| 1111 | do_flush |= req->wb_this_page != req; | 1118 | do_flush |= req->wb_this_page != req; |
| 1112 | if (l_ctx && ctx->dentry->d_inode->i_flock != NULL) { | 1119 | if (l_ctx && flctx && |
| 1120 | !(list_empty_careful(&flctx->flc_posix) && | ||
| 1121 | list_empty_careful(&flctx->flc_flock))) { | ||
| 1113 | do_flush |= l_ctx->lockowner.l_owner != current->files | 1122 | do_flush |= l_ctx->lockowner.l_owner != current->files |
| 1114 | || l_ctx->lockowner.l_pid != current->tgid; | 1123 | || l_ctx->lockowner.l_pid != current->tgid; |
| 1115 | } | 1124 | } |
| @@ -1170,6 +1179,13 @@ out: | |||
| 1170 | return PageUptodate(page) != 0; | 1179 | return PageUptodate(page) != 0; |
| 1171 | } | 1180 | } |
| 1172 | 1181 | ||
| 1182 | static bool | ||
| 1183 | is_whole_file_wrlock(struct file_lock *fl) | ||
| 1184 | { | ||
| 1185 | return fl->fl_start == 0 && fl->fl_end == OFFSET_MAX && | ||
| 1186 | fl->fl_type == F_WRLCK; | ||
| 1187 | } | ||
| 1188 | |||
| 1173 | /* If we know the page is up to date, and we're not using byte range locks (or | 1189 | /* If we know the page is up to date, and we're not using byte range locks (or |
| 1174 | * if we have the whole file locked for writing), it may be more efficient to | 1190 | * if we have the whole file locked for writing), it may be more efficient to |
| 1175 | * extend the write to cover the entire page in order to avoid fragmentation | 1191 | * extend the write to cover the entire page in order to avoid fragmentation |
| @@ -1180,17 +1196,36 @@ out: | |||
| 1180 | */ | 1196 | */ |
| 1181 | static int nfs_can_extend_write(struct file *file, struct page *page, struct inode *inode) | 1197 | static int nfs_can_extend_write(struct file *file, struct page *page, struct inode *inode) |
| 1182 | { | 1198 | { |
| 1199 | int ret; | ||
| 1200 | struct file_lock_context *flctx = inode->i_flctx; | ||
| 1201 | struct file_lock *fl; | ||
| 1202 | |||
| 1183 | if (file->f_flags & O_DSYNC) | 1203 | if (file->f_flags & O_DSYNC) |
| 1184 | return 0; | 1204 | return 0; |
| 1185 | if (!nfs_write_pageuptodate(page, inode)) | 1205 | if (!nfs_write_pageuptodate(page, inode)) |
| 1186 | return 0; | 1206 | return 0; |
| 1187 | if (NFS_PROTO(inode)->have_delegation(inode, FMODE_WRITE)) | 1207 | if (NFS_PROTO(inode)->have_delegation(inode, FMODE_WRITE)) |
| 1188 | return 1; | 1208 | return 1; |
| 1189 | if (inode->i_flock == NULL || (inode->i_flock->fl_start == 0 && | 1209 | if (!flctx || (list_empty_careful(&flctx->flc_flock) && |
| 1190 | inode->i_flock->fl_end == OFFSET_MAX && | 1210 | list_empty_careful(&flctx->flc_posix))) |
| 1191 | inode->i_flock->fl_type != F_RDLCK)) | 1211 | return 0; |
| 1192 | return 1; | 1212 | |
| 1193 | return 0; | 1213 | /* Check to see if there are whole file write locks */ |
| 1214 | ret = 0; | ||
| 1215 | spin_lock(&flctx->flc_lock); | ||
| 1216 | if (!list_empty(&flctx->flc_posix)) { | ||
| 1217 | fl = list_first_entry(&flctx->flc_posix, struct file_lock, | ||
| 1218 | fl_list); | ||
| 1219 | if (is_whole_file_wrlock(fl)) | ||
| 1220 | ret = 1; | ||
| 1221 | } else if (!list_empty(&flctx->flc_flock)) { | ||
| 1222 | fl = list_first_entry(&flctx->flc_flock, struct file_lock, | ||
| 1223 | fl_list); | ||
| 1224 | if (fl->fl_type == F_WRLCK) | ||
| 1225 | ret = 1; | ||
| 1226 | } | ||
| 1227 | spin_unlock(&flctx->flc_lock); | ||
| 1228 | return ret; | ||
| 1194 | } | 1229 | } |
| 1195 | 1230 | ||
| 1196 | /* | 1231 | /* |
| @@ -1240,15 +1275,15 @@ static int flush_task_priority(int how) | |||
| 1240 | 1275 | ||
| 1241 | static void nfs_initiate_write(struct nfs_pgio_header *hdr, | 1276 | static void nfs_initiate_write(struct nfs_pgio_header *hdr, |
| 1242 | struct rpc_message *msg, | 1277 | struct rpc_message *msg, |
| 1278 | const struct nfs_rpc_ops *rpc_ops, | ||
| 1243 | struct rpc_task_setup *task_setup_data, int how) | 1279 | struct rpc_task_setup *task_setup_data, int how) |
| 1244 | { | 1280 | { |
| 1245 | struct inode *inode = hdr->inode; | ||
| 1246 | int priority = flush_task_priority(how); | 1281 | int priority = flush_task_priority(how); |
| 1247 | 1282 | ||
| 1248 | task_setup_data->priority = priority; | 1283 | task_setup_data->priority = priority; |
| 1249 | NFS_PROTO(inode)->write_setup(hdr, msg); | 1284 | rpc_ops->write_setup(hdr, msg); |
| 1250 | 1285 | ||
| 1251 | nfs4_state_protect_write(NFS_SERVER(inode)->nfs_client, | 1286 | nfs4_state_protect_write(NFS_SERVER(hdr->inode)->nfs_client, |
| 1252 | &task_setup_data->rpc_client, msg, hdr); | 1287 | &task_setup_data->rpc_client, msg, hdr); |
| 1253 | } | 1288 | } |
| 1254 | 1289 | ||
| @@ -1298,8 +1333,14 @@ EXPORT_SYMBOL_GPL(nfs_pageio_init_write); | |||
| 1298 | 1333 | ||
| 1299 | void nfs_pageio_reset_write_mds(struct nfs_pageio_descriptor *pgio) | 1334 | void nfs_pageio_reset_write_mds(struct nfs_pageio_descriptor *pgio) |
| 1300 | { | 1335 | { |
| 1336 | struct nfs_pgio_mirror *mirror; | ||
| 1337 | |||
| 1301 | pgio->pg_ops = &nfs_pgio_rw_ops; | 1338 | pgio->pg_ops = &nfs_pgio_rw_ops; |
| 1302 | pgio->pg_bsize = NFS_SERVER(pgio->pg_inode)->wsize; | 1339 | |
| 1340 | nfs_pageio_stop_mirroring(pgio); | ||
| 1341 | |||
| 1342 | mirror = &pgio->pg_mirrors[0]; | ||
| 1343 | mirror->pg_bsize = NFS_SERVER(pgio->pg_inode)->wsize; | ||
| 1303 | } | 1344 | } |
| 1304 | EXPORT_SYMBOL_GPL(nfs_pageio_reset_write_mds); | 1345 | EXPORT_SYMBOL_GPL(nfs_pageio_reset_write_mds); |
| 1305 | 1346 | ||
| @@ -1465,6 +1506,7 @@ void nfs_commitdata_release(struct nfs_commit_data *data) | |||
| 1465 | EXPORT_SYMBOL_GPL(nfs_commitdata_release); | 1506 | EXPORT_SYMBOL_GPL(nfs_commitdata_release); |
| 1466 | 1507 | ||
| 1467 | int nfs_initiate_commit(struct rpc_clnt *clnt, struct nfs_commit_data *data, | 1508 | int nfs_initiate_commit(struct rpc_clnt *clnt, struct nfs_commit_data *data, |
| 1509 | const struct nfs_rpc_ops *nfs_ops, | ||
| 1468 | const struct rpc_call_ops *call_ops, | 1510 | const struct rpc_call_ops *call_ops, |
| 1469 | int how, int flags) | 1511 | int how, int flags) |
| 1470 | { | 1512 | { |
| @@ -1486,7 +1528,7 @@ int nfs_initiate_commit(struct rpc_clnt *clnt, struct nfs_commit_data *data, | |||
| 1486 | .priority = priority, | 1528 | .priority = priority, |
| 1487 | }; | 1529 | }; |
| 1488 | /* Set up the initial task struct. */ | 1530 | /* Set up the initial task struct. */ |
| 1489 | NFS_PROTO(data->inode)->commit_setup(data, &msg); | 1531 | nfs_ops->commit_setup(data, &msg); |
| 1490 | 1532 | ||
| 1491 | dprintk("NFS: %5u initiated commit call\n", data->task.tk_pid); | 1533 | dprintk("NFS: %5u initiated commit call\n", data->task.tk_pid); |
| 1492 | 1534 | ||
| @@ -1554,17 +1596,18 @@ EXPORT_SYMBOL_GPL(nfs_init_commit); | |||
| 1554 | 1596 | ||
| 1555 | void nfs_retry_commit(struct list_head *page_list, | 1597 | void nfs_retry_commit(struct list_head *page_list, |
| 1556 | struct pnfs_layout_segment *lseg, | 1598 | struct pnfs_layout_segment *lseg, |
| 1557 | struct nfs_commit_info *cinfo) | 1599 | struct nfs_commit_info *cinfo, |
| 1600 | u32 ds_commit_idx) | ||
| 1558 | { | 1601 | { |
| 1559 | struct nfs_page *req; | 1602 | struct nfs_page *req; |
| 1560 | 1603 | ||
| 1561 | while (!list_empty(page_list)) { | 1604 | while (!list_empty(page_list)) { |
| 1562 | req = nfs_list_entry(page_list->next); | 1605 | req = nfs_list_entry(page_list->next); |
| 1563 | nfs_list_remove_request(req); | 1606 | nfs_list_remove_request(req); |
| 1564 | nfs_mark_request_commit(req, lseg, cinfo); | 1607 | nfs_mark_request_commit(req, lseg, cinfo, ds_commit_idx); |
| 1565 | if (!cinfo->dreq) { | 1608 | if (!cinfo->dreq) { |
| 1566 | dec_zone_page_state(req->wb_page, NR_UNSTABLE_NFS); | 1609 | dec_zone_page_state(req->wb_page, NR_UNSTABLE_NFS); |
| 1567 | dec_bdi_stat(page_file_mapping(req->wb_page)->backing_dev_info, | 1610 | dec_bdi_stat(inode_to_bdi(page_file_mapping(req->wb_page)->host), |
| 1568 | BDI_RECLAIMABLE); | 1611 | BDI_RECLAIMABLE); |
| 1569 | } | 1612 | } |
| 1570 | nfs_unlock_and_release_request(req); | 1613 | nfs_unlock_and_release_request(req); |
| @@ -1589,10 +1632,10 @@ nfs_commit_list(struct inode *inode, struct list_head *head, int how, | |||
| 1589 | /* Set up the argument struct */ | 1632 | /* Set up the argument struct */ |
| 1590 | nfs_init_commit(data, head, NULL, cinfo); | 1633 | nfs_init_commit(data, head, NULL, cinfo); |
| 1591 | atomic_inc(&cinfo->mds->rpcs_out); | 1634 | atomic_inc(&cinfo->mds->rpcs_out); |
| 1592 | return nfs_initiate_commit(NFS_CLIENT(inode), data, data->mds_ops, | 1635 | return nfs_initiate_commit(NFS_CLIENT(inode), data, NFS_PROTO(inode), |
| 1593 | how, 0); | 1636 | data->mds_ops, how, 0); |
| 1594 | out_bad: | 1637 | out_bad: |
| 1595 | nfs_retry_commit(head, NULL, cinfo); | 1638 | nfs_retry_commit(head, NULL, cinfo, 0); |
| 1596 | cinfo->completion_ops->error_cleanup(NFS_I(inode)); | 1639 | cinfo->completion_ops->error_cleanup(NFS_I(inode)); |
| 1597 | return -ENOMEM; | 1640 | return -ENOMEM; |
| 1598 | } | 1641 | } |
