diff options
Diffstat (limited to 'fs/nfs/direct.c')
-rw-r--r-- | fs/nfs/direct.c | 65 |
1 files changed, 42 insertions, 23 deletions
diff --git a/fs/nfs/direct.c b/fs/nfs/direct.c index 345aa5c0f382..00eee87510fe 100644 --- a/fs/nfs/direct.c +++ b/fs/nfs/direct.c | |||
@@ -122,19 +122,25 @@ ssize_t nfs_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov, loff_ | |||
122 | return -EINVAL; | 122 | return -EINVAL; |
123 | } | 123 | } |
124 | 124 | ||
125 | static void nfs_direct_dirty_pages(struct page **pages, int npages) | 125 | static void nfs_direct_dirty_pages(struct page **pages, unsigned int pgbase, size_t count) |
126 | { | 126 | { |
127 | int i; | 127 | unsigned int npages; |
128 | unsigned int i; | ||
129 | |||
130 | if (count == 0) | ||
131 | return; | ||
132 | pages += (pgbase >> PAGE_SHIFT); | ||
133 | npages = (count + (pgbase & ~PAGE_MASK) + PAGE_SIZE - 1) >> PAGE_SHIFT; | ||
128 | for (i = 0; i < npages; i++) { | 134 | for (i = 0; i < npages; i++) { |
129 | struct page *page = pages[i]; | 135 | struct page *page = pages[i]; |
130 | if (!PageCompound(page)) | 136 | if (!PageCompound(page)) |
131 | set_page_dirty_lock(page); | 137 | set_page_dirty(page); |
132 | } | 138 | } |
133 | } | 139 | } |
134 | 140 | ||
135 | static void nfs_direct_release_pages(struct page **pages, int npages) | 141 | static void nfs_direct_release_pages(struct page **pages, unsigned int npages) |
136 | { | 142 | { |
137 | int i; | 143 | unsigned int i; |
138 | for (i = 0; i < npages; i++) | 144 | for (i = 0; i < npages; i++) |
139 | page_cache_release(pages[i]); | 145 | page_cache_release(pages[i]); |
140 | } | 146 | } |
@@ -162,7 +168,7 @@ static inline struct nfs_direct_req *nfs_direct_req_alloc(void) | |||
162 | return dreq; | 168 | return dreq; |
163 | } | 169 | } |
164 | 170 | ||
165 | static void nfs_direct_req_release(struct kref *kref) | 171 | static void nfs_direct_req_free(struct kref *kref) |
166 | { | 172 | { |
167 | struct nfs_direct_req *dreq = container_of(kref, struct nfs_direct_req, kref); | 173 | struct nfs_direct_req *dreq = container_of(kref, struct nfs_direct_req, kref); |
168 | 174 | ||
@@ -171,6 +177,11 @@ static void nfs_direct_req_release(struct kref *kref) | |||
171 | kmem_cache_free(nfs_direct_cachep, dreq); | 177 | kmem_cache_free(nfs_direct_cachep, dreq); |
172 | } | 178 | } |
173 | 179 | ||
180 | static void nfs_direct_req_release(struct nfs_direct_req *dreq) | ||
181 | { | ||
182 | kref_put(&dreq->kref, nfs_direct_req_free); | ||
183 | } | ||
184 | |||
174 | /* | 185 | /* |
175 | * Collects and returns the final error value/byte-count. | 186 | * Collects and returns the final error value/byte-count. |
176 | */ | 187 | */ |
@@ -190,7 +201,6 @@ static ssize_t nfs_direct_wait(struct nfs_direct_req *dreq) | |||
190 | result = dreq->count; | 201 | result = dreq->count; |
191 | 202 | ||
192 | out: | 203 | out: |
193 | kref_put(&dreq->kref, nfs_direct_req_release); | ||
194 | return (ssize_t) result; | 204 | return (ssize_t) result; |
195 | } | 205 | } |
196 | 206 | ||
@@ -208,7 +218,7 @@ static void nfs_direct_complete(struct nfs_direct_req *dreq) | |||
208 | } | 218 | } |
209 | complete_all(&dreq->completion); | 219 | complete_all(&dreq->completion); |
210 | 220 | ||
211 | kref_put(&dreq->kref, nfs_direct_req_release); | 221 | nfs_direct_req_release(dreq); |
212 | } | 222 | } |
213 | 223 | ||
214 | /* | 224 | /* |
@@ -224,17 +234,18 @@ static void nfs_direct_read_result(struct rpc_task *task, void *calldata) | |||
224 | if (nfs_readpage_result(task, data) != 0) | 234 | if (nfs_readpage_result(task, data) != 0) |
225 | return; | 235 | return; |
226 | 236 | ||
227 | nfs_direct_dirty_pages(data->pagevec, data->npages); | ||
228 | nfs_direct_release_pages(data->pagevec, data->npages); | ||
229 | |||
230 | spin_lock(&dreq->lock); | 237 | spin_lock(&dreq->lock); |
231 | 238 | if (unlikely(task->tk_status < 0)) { | |
232 | if (likely(task->tk_status >= 0)) | ||
233 | dreq->count += data->res.count; | ||
234 | else | ||
235 | dreq->error = task->tk_status; | 239 | dreq->error = task->tk_status; |
236 | 240 | spin_unlock(&dreq->lock); | |
237 | spin_unlock(&dreq->lock); | 241 | } else { |
242 | dreq->count += data->res.count; | ||
243 | spin_unlock(&dreq->lock); | ||
244 | nfs_direct_dirty_pages(data->pagevec, | ||
245 | data->args.pgbase, | ||
246 | data->res.count); | ||
247 | } | ||
248 | nfs_direct_release_pages(data->pagevec, data->npages); | ||
238 | 249 | ||
239 | if (put_dreq(dreq)) | 250 | if (put_dreq(dreq)) |
240 | nfs_direct_complete(dreq); | 251 | nfs_direct_complete(dreq); |
@@ -279,9 +290,12 @@ static ssize_t nfs_direct_read_schedule(struct nfs_direct_req *dreq, unsigned lo | |||
279 | result = get_user_pages(current, current->mm, user_addr, | 290 | result = get_user_pages(current, current->mm, user_addr, |
280 | data->npages, 1, 0, data->pagevec, NULL); | 291 | data->npages, 1, 0, data->pagevec, NULL); |
281 | up_read(¤t->mm->mmap_sem); | 292 | up_read(¤t->mm->mmap_sem); |
282 | if (unlikely(result < data->npages)) { | 293 | if (result < 0) { |
283 | if (result > 0) | 294 | nfs_readdata_release(data); |
284 | nfs_direct_release_pages(data->pagevec, result); | 295 | break; |
296 | } | ||
297 | if ((unsigned)result < data->npages) { | ||
298 | nfs_direct_release_pages(data->pagevec, result); | ||
285 | nfs_readdata_release(data); | 299 | nfs_readdata_release(data); |
286 | break; | 300 | break; |
287 | } | 301 | } |
@@ -359,6 +373,7 @@ static ssize_t nfs_direct_read(struct kiocb *iocb, unsigned long user_addr, size | |||
359 | if (!result) | 373 | if (!result) |
360 | result = nfs_direct_wait(dreq); | 374 | result = nfs_direct_wait(dreq); |
361 | rpc_clnt_sigunmask(clnt, &oldset); | 375 | rpc_clnt_sigunmask(clnt, &oldset); |
376 | nfs_direct_req_release(dreq); | ||
362 | 377 | ||
363 | return result; | 378 | return result; |
364 | } | 379 | } |
@@ -610,9 +625,12 @@ static ssize_t nfs_direct_write_schedule(struct nfs_direct_req *dreq, unsigned l | |||
610 | result = get_user_pages(current, current->mm, user_addr, | 625 | result = get_user_pages(current, current->mm, user_addr, |
611 | data->npages, 0, 0, data->pagevec, NULL); | 626 | data->npages, 0, 0, data->pagevec, NULL); |
612 | up_read(¤t->mm->mmap_sem); | 627 | up_read(¤t->mm->mmap_sem); |
613 | if (unlikely(result < data->npages)) { | 628 | if (result < 0) { |
614 | if (result > 0) | 629 | nfs_writedata_release(data); |
615 | nfs_direct_release_pages(data->pagevec, result); | 630 | break; |
631 | } | ||
632 | if ((unsigned)result < data->npages) { | ||
633 | nfs_direct_release_pages(data->pagevec, result); | ||
616 | nfs_writedata_release(data); | 634 | nfs_writedata_release(data); |
617 | break; | 635 | break; |
618 | } | 636 | } |
@@ -703,6 +721,7 @@ static ssize_t nfs_direct_write(struct kiocb *iocb, unsigned long user_addr, siz | |||
703 | if (!result) | 721 | if (!result) |
704 | result = nfs_direct_wait(dreq); | 722 | result = nfs_direct_wait(dreq); |
705 | rpc_clnt_sigunmask(clnt, &oldset); | 723 | rpc_clnt_sigunmask(clnt, &oldset); |
724 | nfs_direct_req_release(dreq); | ||
706 | 725 | ||
707 | return result; | 726 | return result; |
708 | } | 727 | } |