]> bbs.cooldavid.org Git - net-next-2.6.git/blame - fs/nfs/direct.c
NFS: remove support for multi-segment iovs in the direct read path
[net-next-2.6.git] / fs / nfs / direct.c
CommitLineData
1da177e4
LT
1/*
2 * linux/fs/nfs/direct.c
3 *
4 * Copyright (C) 2003 by Chuck Lever <cel@netapp.com>
5 *
6 * High-performance uncached I/O for the Linux NFS client
7 *
8 * There are important applications whose performance or correctness
9 * depends on uncached access to file data. Database clusters
10 * (multiple copies of the same instance running on separate hosts)
11 * implement their own cache coherency protocol that subsumes file
12 * system cache protocols. Applications that process datasets
13 * considerably larger than the client's memory do not always benefit
14 * from a local cache. A streaming video server, for instance, has no
15 * need to cache the contents of a file.
16 *
17 * When an application requests uncached I/O, all read and write requests
18 * are made directly to the server; data stored or fetched via these
19 * requests is not cached in the Linux page cache. The client does not
20 * correct unaligned requests from applications. All requested bytes are
21 * held on permanent storage before a direct write system call returns to
22 * an application.
23 *
24 * Solaris implements an uncached I/O facility called directio() that
25 * is used for backups and sequential I/O to very large files. Solaris
26 * also supports uncaching whole NFS partitions with "-o forcedirectio,"
27 * an undocumented mount option.
28 *
29 * Designed by Jeff Kimmel, Chuck Lever, and Trond Myklebust, with
30 * help from Andrew Morton.
31 *
32 * 18 Dec 2001 Initial implementation for 2.4 --cel
33 * 08 Jul 2002 Version for 2.4.19, with bug fixes --trondmy
34 * 08 Jun 2003 Port to 2.5 APIs --cel
35 * 31 Mar 2004 Handle direct I/O without VFS support --cel
36 * 15 Sep 2004 Parallel async reads --cel
37 *
38 */
39
40#include <linux/config.h>
41#include <linux/errno.h>
42#include <linux/sched.h>
43#include <linux/kernel.h>
44#include <linux/smp_lock.h>
45#include <linux/file.h>
46#include <linux/pagemap.h>
47#include <linux/kref.h>
48
49#include <linux/nfs_fs.h>
50#include <linux/nfs_page.h>
51#include <linux/sunrpc/clnt.h>
52
53#include <asm/system.h>
54#include <asm/uaccess.h>
55#include <asm/atomic.h>
56
91d5b470
CL
57#include "iostat.h"
58
1da177e4
LT
59#define NFSDBG_FACILITY NFSDBG_VFS
60#define MAX_DIRECTIO_SIZE (4096UL << PAGE_SHIFT)
61
143f412e 62static void nfs_free_user_pages(struct page **pages, int npages, int do_dirty);
1da177e4
LT
63static kmem_cache_t *nfs_direct_cachep;
64
65/*
66 * This represents a set of asynchronous requests that we're waiting on
67 */
68struct nfs_direct_req {
69 struct kref kref; /* release manager */
70 struct list_head list; /* nfs_read_data structs */
71 wait_queue_head_t wait; /* wait for i/o completion */
91d5b470 72 struct inode * inode; /* target file of I/O */
1da177e4
LT
73 struct page ** pages; /* pages in our buffer */
74 unsigned int npages; /* count of pages */
75 atomic_t complete, /* i/os we're waiting for */
76 count, /* bytes actually processed */
77 error; /* any reported error */
78};
79
80
b8a32e2b
CL
81/**
82 * nfs_direct_IO - NFS address space operation for direct I/O
83 * @rw: direction (read or write)
84 * @iocb: target I/O control block
85 * @iov: array of vectors that define I/O buffer
86 * @pos: offset in file to begin the operation
87 * @nr_segs: size of iovec array
88 *
89 * The presence of this routine in the address space ops vector means
90 * the NFS client supports direct I/O. However, we shunt off direct
91 * read and write requests before the VFS gets them, so this method
92 * should never be called.
93 */
94ssize_t nfs_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov, loff_t pos, unsigned long nr_segs)
95{
96 struct dentry *dentry = iocb->ki_filp->f_dentry;
97
98 dprintk("NFS: nfs_direct_IO (%s) off/no(%Ld/%lu) EINVAL\n",
99 dentry->d_name.name, (long long) pos, nr_segs);
100
101 return -EINVAL;
102}
103
d4cc948b 104static inline int nfs_get_user_pages(int rw, unsigned long user_addr, size_t size, struct page ***pages)
1da177e4
LT
105{
106 int result = -ENOMEM;
107 unsigned long page_count;
108 size_t array_size;
109
110 /* set an arbitrary limit to prevent type overflow */
111 /* XXX: this can probably be as large as INT_MAX */
112 if (size > MAX_DIRECTIO_SIZE) {
113 *pages = NULL;
114 return -EFBIG;
115 }
116
117 page_count = (user_addr + size + PAGE_SIZE - 1) >> PAGE_SHIFT;
118 page_count -= user_addr >> PAGE_SHIFT;
119
120 array_size = (page_count * sizeof(struct page *));
121 *pages = kmalloc(array_size, GFP_KERNEL);
122 if (*pages) {
123 down_read(&current->mm->mmap_sem);
124 result = get_user_pages(current, current->mm, user_addr,
125 page_count, (rw == READ), 0,
126 *pages, NULL);
127 up_read(&current->mm->mmap_sem);
143f412e
TM
128 /*
129 * If we got fewer pages than expected from get_user_pages(),
130 * the user buffer runs off the end of a mapping; return EFAULT.
131 */
132 if (result >= 0 && result < page_count) {
133 nfs_free_user_pages(*pages, result, 0);
134 *pages = NULL;
135 result = -EFAULT;
136 }
1da177e4
LT
137 }
138 return result;
139}
140
d4cc948b 141static void nfs_free_user_pages(struct page **pages, int npages, int do_dirty)
1da177e4
LT
142{
143 int i;
144 for (i = 0; i < npages; i++) {
566dd606
TM
145 struct page *page = pages[i];
146 if (do_dirty && !PageCompound(page))
147 set_page_dirty_lock(page);
148 page_cache_release(page);
1da177e4
LT
149 }
150 kfree(pages);
151}
152
1da177e4
LT
153static void nfs_direct_req_release(struct kref *kref)
154{
155 struct nfs_direct_req *dreq = container_of(kref, struct nfs_direct_req, kref);
156 kmem_cache_free(nfs_direct_cachep, dreq);
157}
158
d4cc948b 159/*
1da177e4
LT
160 * Note we also set the number of requests we have in the dreq when we are
161 * done. This prevents races with I/O completion so we will always wait
162 * until all requests have been dispatched and completed.
163 */
5dd602f2 164static struct nfs_direct_req *nfs_direct_read_alloc(size_t nbytes, size_t rsize)
1da177e4
LT
165{
166 struct list_head *list;
167 struct nfs_direct_req *dreq;
168 unsigned int reads = 0;
40859d7e 169 unsigned int rpages = (rsize + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
1da177e4
LT
170
171 dreq = kmem_cache_alloc(nfs_direct_cachep, SLAB_KERNEL);
172 if (!dreq)
173 return NULL;
174
175 kref_init(&dreq->kref);
176 init_waitqueue_head(&dreq->wait);
177 INIT_LIST_HEAD(&dreq->list);
178 atomic_set(&dreq->count, 0);
179 atomic_set(&dreq->error, 0);
180
181 list = &dreq->list;
182 for(;;) {
40859d7e 183 struct nfs_read_data *data = nfs_readdata_alloc(rpages);
1da177e4
LT
184
185 if (unlikely(!data)) {
186 while (!list_empty(list)) {
187 data = list_entry(list->next,
188 struct nfs_read_data, pages);
189 list_del(&data->pages);
190 nfs_readdata_free(data);
191 }
192 kref_put(&dreq->kref, nfs_direct_req_release);
193 return NULL;
194 }
195
196 INIT_LIST_HEAD(&data->pages);
197 list_add(&data->pages, list);
198
199 data->req = (struct nfs_page *) dreq;
200 reads++;
201 if (nbytes <= rsize)
202 break;
203 nbytes -= rsize;
204 }
205 kref_get(&dreq->kref);
206 atomic_set(&dreq->complete, reads);
207 return dreq;
208}
209
d4cc948b 210/*
1da177e4
LT
211 * We must hold a reference to all the pages in this direct read request
212 * until the RPCs complete. This could be long *after* we are woken up in
213 * nfs_direct_read_wait (for instance, if someone hits ^C on a slow server).
214 */
ec06c096 215static void nfs_direct_read_result(struct rpc_task *task, void *calldata)
1da177e4 216{
ec06c096 217 struct nfs_read_data *data = calldata;
1da177e4
LT
218 struct nfs_direct_req *dreq = (struct nfs_direct_req *) data->req;
219
ec06c096
TM
220 if (nfs_readpage_result(task, data) != 0)
221 return;
222 if (likely(task->tk_status >= 0))
1da177e4
LT
223 atomic_add(data->res.count, &dreq->count);
224 else
ec06c096 225 atomic_set(&dreq->error, task->tk_status);
1da177e4
LT
226
227 if (unlikely(atomic_dec_and_test(&dreq->complete))) {
228 nfs_free_user_pages(dreq->pages, dreq->npages, 1);
229 wake_up(&dreq->wait);
230 kref_put(&dreq->kref, nfs_direct_req_release);
231 }
232}
233
ec06c096
TM
234static const struct rpc_call_ops nfs_read_direct_ops = {
235 .rpc_call_done = nfs_direct_read_result,
236 .rpc_release = nfs_readdata_release,
237};
238
d4cc948b 239/*
1da177e4
LT
240 * For each nfs_read_data struct that was allocated on the list, dispatch
241 * an NFS READ operation
242 */
d4cc948b 243static void nfs_direct_read_schedule(struct nfs_direct_req *dreq, struct inode *inode, struct nfs_open_context *ctx, unsigned long user_addr, size_t count, loff_t file_offset)
1da177e4
LT
244{
245 struct list_head *list = &dreq->list;
246 struct page **pages = dreq->pages;
5dd602f2 247 size_t rsize = NFS_SERVER(inode)->rsize;
1da177e4 248 unsigned int curpage, pgbase;
1da177e4
LT
249
250 curpage = 0;
251 pgbase = user_addr & ~PAGE_MASK;
252 do {
253 struct nfs_read_data *data;
5dd602f2 254 size_t bytes;
1da177e4
LT
255
256 bytes = rsize;
257 if (count < rsize)
258 bytes = count;
259
260 data = list_entry(list->next, struct nfs_read_data, pages);
261 list_del_init(&data->pages);
262
263 data->inode = inode;
264 data->cred = ctx->cred;
265 data->args.fh = NFS_FH(inode);
266 data->args.context = ctx;
267 data->args.offset = file_offset;
268 data->args.pgbase = pgbase;
269 data->args.pages = &pages[curpage];
270 data->args.count = bytes;
271 data->res.fattr = &data->fattr;
272 data->res.eof = 0;
273 data->res.count = bytes;
274
ec06c096
TM
275 rpc_init_task(&data->task, NFS_CLIENT(inode), RPC_TASK_ASYNC,
276 &nfs_read_direct_ops, data);
1da177e4
LT
277 NFS_PROTO(inode)->read_setup(data);
278
279 data->task.tk_cookie = (unsigned long) inode;
1da177e4
LT
280
281 lock_kernel();
282 rpc_execute(&data->task);
283 unlock_kernel();
284
285 dfprintk(VFS, "NFS: %4d initiated direct read call (req %s/%Ld, %u bytes @ offset %Lu)\n",
286 data->task.tk_pid,
287 inode->i_sb->s_id,
288 (long long)NFS_FILEID(inode),
289 bytes,
290 (unsigned long long)data->args.offset);
291
292 file_offset += bytes;
293 pgbase += bytes;
294 curpage += pgbase >> PAGE_SHIFT;
295 pgbase &= ~PAGE_MASK;
296
297 count -= bytes;
298 } while (count != 0);
299}
300
d4cc948b 301/*
1da177e4
LT
302 * Collects and returns the final error value/byte-count.
303 */
304static ssize_t nfs_direct_read_wait(struct nfs_direct_req *dreq, int intr)
305{
306 int result = 0;
307
308 if (intr) {
309 result = wait_event_interruptible(dreq->wait,
310 (atomic_read(&dreq->complete) == 0));
311 } else {
312 wait_event(dreq->wait, (atomic_read(&dreq->complete) == 0));
313 }
314
315 if (!result)
316 result = atomic_read(&dreq->error);
317 if (!result)
318 result = atomic_read(&dreq->count);
319
320 kref_put(&dreq->kref, nfs_direct_req_release);
321 return (ssize_t) result;
322}
323
0cdd80d0 324static ssize_t nfs_direct_read(struct inode *inode, struct nfs_open_context *ctx, unsigned long user_addr, size_t count, loff_t file_offset, struct page **pages, unsigned int nr_pages)
1da177e4
LT
325{
326 ssize_t result;
327 sigset_t oldset;
328 struct rpc_clnt *clnt = NFS_CLIENT(inode);
329 struct nfs_direct_req *dreq;
330
331 dreq = nfs_direct_read_alloc(count, NFS_SERVER(inode)->rsize);
332 if (!dreq)
333 return -ENOMEM;
334
335 dreq->pages = pages;
336 dreq->npages = nr_pages;
91d5b470 337 dreq->inode = inode;
1da177e4 338
91d5b470 339 nfs_add_stats(inode, NFSIOS_DIRECTREADBYTES, count);
1da177e4
LT
340 rpc_clnt_sigmask(clnt, &oldset);
341 nfs_direct_read_schedule(dreq, inode, ctx, user_addr, count,
342 file_offset);
343 result = nfs_direct_read_wait(dreq, clnt->cl_intr);
344 rpc_clnt_sigunmask(clnt, &oldset);
345
346 return result;
347}
348
d4cc948b 349static ssize_t nfs_direct_write_seg(struct inode *inode, struct nfs_open_context *ctx, unsigned long user_addr, size_t count, loff_t file_offset, struct page **pages, int nr_pages)
1da177e4
LT
350{
351 const unsigned int wsize = NFS_SERVER(inode)->wsize;
352 size_t request;
353 int curpage, need_commit;
354 ssize_t result, tot_bytes;
355 struct nfs_writeverf first_verf;
356 struct nfs_write_data *wdata;
357
40859d7e 358 wdata = nfs_writedata_alloc(NFS_SERVER(inode)->wpages);
1da177e4
LT
359 if (!wdata)
360 return -ENOMEM;
361
362 wdata->inode = inode;
363 wdata->cred = ctx->cred;
364 wdata->args.fh = NFS_FH(inode);
365 wdata->args.context = ctx;
366 wdata->args.stable = NFS_UNSTABLE;
367 if (IS_SYNC(inode) || NFS_PROTO(inode)->version == 2 || count <= wsize)
368 wdata->args.stable = NFS_FILE_SYNC;
369 wdata->res.fattr = &wdata->fattr;
370 wdata->res.verf = &wdata->verf;
371
372 nfs_begin_data_update(inode);
373retry:
374 need_commit = 0;
375 tot_bytes = 0;
376 curpage = 0;
377 request = count;
378 wdata->args.pgbase = user_addr & ~PAGE_MASK;
379 wdata->args.offset = file_offset;
380 do {
381 wdata->args.count = request;
382 if (wdata->args.count > wsize)
383 wdata->args.count = wsize;
384 wdata->args.pages = &pages[curpage];
385
386 dprintk("NFS: direct write: c=%u o=%Ld ua=%lu, pb=%u, cp=%u\n",
387 wdata->args.count, (long long) wdata->args.offset,
388 user_addr + tot_bytes, wdata->args.pgbase, curpage);
389
390 lock_kernel();
391 result = NFS_PROTO(inode)->write(wdata);
392 unlock_kernel();
393
394 if (result <= 0) {
395 if (tot_bytes > 0)
396 break;
397 goto out;
398 }
399
400 if (tot_bytes == 0)
401 memcpy(&first_verf.verifier, &wdata->verf.verifier,
402 sizeof(first_verf.verifier));
403 if (wdata->verf.committed != NFS_FILE_SYNC) {
404 need_commit = 1;
405 if (memcmp(&first_verf.verifier, &wdata->verf.verifier,
19352456 406 sizeof(first_verf.verifier)))
1da177e4
LT
407 goto sync_retry;
408 }
409
410 tot_bytes += result;
411
412 /* in case of a short write: stop now, let the app recover */
413 if (result < wdata->args.count)
414 break;
415
416 wdata->args.offset += result;
417 wdata->args.pgbase += result;
418 curpage += wdata->args.pgbase >> PAGE_SHIFT;
419 wdata->args.pgbase &= ~PAGE_MASK;
420 request -= result;
421 } while (request != 0);
422
423 /*
424 * Commit data written so far, even in the event of an error
425 */
426 if (need_commit) {
427 wdata->args.count = tot_bytes;
428 wdata->args.offset = file_offset;
429
430 lock_kernel();
431 result = NFS_PROTO(inode)->commit(wdata);
432 unlock_kernel();
433
434 if (result < 0 || memcmp(&first_verf.verifier,
435 &wdata->verf.verifier,
436 sizeof(first_verf.verifier)) != 0)
437 goto sync_retry;
438 }
439 result = tot_bytes;
440
441out:
951a143b 442 nfs_end_data_update(inode);
1da177e4
LT
443 nfs_writedata_free(wdata);
444 return result;
445
446sync_retry:
447 wdata->args.stable = NFS_FILE_SYNC;
448 goto retry;
449}
450
d4cc948b 451/*
1da177e4
LT
452 * Upon return, generic_file_direct_IO invalidates any cached pages
453 * that non-direct readers might access, so they will pick up these
454 * writes immediately.
455 */
d4cc948b 456static ssize_t nfs_direct_write(struct inode *inode, struct nfs_open_context *ctx, const struct iovec *iov, loff_t file_offset, unsigned long nr_segs)
1da177e4
LT
457{
458 ssize_t tot_bytes = 0;
459 unsigned long seg = 0;
460
461 while ((seg < nr_segs) && (tot_bytes >= 0)) {
462 ssize_t result;
463 int page_count;
464 struct page **pages;
465 const struct iovec *vec = &iov[seg++];
466 unsigned long user_addr = (unsigned long) vec->iov_base;
467 size_t size = vec->iov_len;
468
469 page_count = nfs_get_user_pages(WRITE, user_addr, size, &pages);
470 if (page_count < 0) {
471 nfs_free_user_pages(pages, 0, 0);
472 if (tot_bytes > 0)
473 break;
474 return page_count;
475 }
476
91d5b470 477 nfs_add_stats(inode, NFSIOS_DIRECTWRITTENBYTES, size);
1da177e4
LT
478 result = nfs_direct_write_seg(inode, ctx, user_addr, size,
479 file_offset, pages, page_count);
480 nfs_free_user_pages(pages, page_count, 0);
481
482 if (result <= 0) {
483 if (tot_bytes > 0)
484 break;
485 return result;
486 }
91d5b470 487 nfs_add_stats(inode, NFSIOS_SERVERWRITTENBYTES, result);
1da177e4
LT
488 tot_bytes += result;
489 file_offset += result;
490 if (result < size)
491 break;
492 }
493 return tot_bytes;
494}
495
1da177e4
LT
496/**
497 * nfs_file_direct_read - file direct read operation for NFS files
498 * @iocb: target I/O control block
499 * @buf: user's buffer into which to read data
500 * count: number of bytes to read
501 * pos: byte offset in file where reading starts
502 *
503 * We use this function for direct reads instead of calling
504 * generic_file_aio_read() in order to avoid gfar's check to see if
505 * the request starts before the end of the file. For that check
506 * to work, we must generate a GETATTR before each direct read, and
507 * even then there is a window between the GETATTR and the subsequent
508 * READ where the file size could change. So our preference is simply
509 * to do all reads the application wants, and the server will take
510 * care of managing the end of file boundary.
511 *
512 * This function also eliminates unnecessarily updating the file's
513 * atime locally, as the NFS server sets the file's atime, and this
514 * client must read the updated atime from the server back into its
515 * cache.
516 */
d4cc948b 517ssize_t nfs_file_direct_read(struct kiocb *iocb, char __user *buf, size_t count, loff_t pos)
1da177e4
LT
518{
519 ssize_t retval = -EINVAL;
0cdd80d0
CL
520 int page_count;
521 struct page **pages;
1da177e4
LT
522 struct file *file = iocb->ki_filp;
523 struct nfs_open_context *ctx =
524 (struct nfs_open_context *) file->private_data;
1da177e4
LT
525 struct address_space *mapping = file->f_mapping;
526 struct inode *inode = mapping->host;
1da177e4 527
ce1a8e67 528 dprintk("nfs: direct read(%s/%s, %lu@%Ld)\n",
0bbacc40
CL
529 file->f_dentry->d_parent->d_name.name,
530 file->f_dentry->d_name.name,
ce1a8e67 531 (unsigned long) count, (long long) pos);
1da177e4
LT
532
533 if (!is_sync_kiocb(iocb))
534 goto out;
535 if (count < 0)
536 goto out;
537 retval = -EFAULT;
0cdd80d0 538 if (!access_ok(VERIFY_WRITE, buf, count))
1da177e4
LT
539 goto out;
540 retval = 0;
541 if (!count)
542 goto out;
543
29884df0
TM
544 retval = nfs_sync_mapping(mapping);
545 if (retval)
546 goto out;
1da177e4 547
0cdd80d0
CL
548 page_count = nfs_get_user_pages(READ, (unsigned long) buf,
549 count, &pages);
550 if (page_count < 0) {
551 nfs_free_user_pages(pages, 0, 0);
552 retval = page_count;
553 goto out;
554 }
555
556 retval = nfs_direct_read(inode, ctx, (unsigned long) buf, count, pos,
557 pages, page_count);
1da177e4 558 if (retval > 0)
0cdd80d0 559 iocb->ki_pos = pos + retval;
1da177e4
LT
560
561out:
562 return retval;
563}
564
565/**
566 * nfs_file_direct_write - file direct write operation for NFS files
567 * @iocb: target I/O control block
568 * @buf: user's buffer from which to write data
569 * count: number of bytes to write
570 * pos: byte offset in file where writing starts
571 *
572 * We use this function for direct writes instead of calling
573 * generic_file_aio_write() in order to avoid taking the inode
574 * semaphore and updating the i_size. The NFS server will set
575 * the new i_size and this client must read the updated size
576 * back into its cache. We let the server do generic write
577 * parameter checking and report problems.
578 *
579 * We also avoid an unnecessary invocation of generic_osync_inode(),
580 * as it is fairly meaningless to sync the metadata of an NFS file.
581 *
582 * We eliminate local atime updates, see direct read above.
583 *
584 * We avoid unnecessary page cache invalidations for normal cached
585 * readers of this file.
586 *
587 * Note that O_APPEND is not supported for NFS direct writes, as there
588 * is no atomic O_APPEND write facility in the NFS protocol.
589 */
d4cc948b 590ssize_t nfs_file_direct_write(struct kiocb *iocb, const char __user *buf, size_t count, loff_t pos)
1da177e4 591{
ce1a8e67 592 ssize_t retval;
1da177e4
LT
593 struct file *file = iocb->ki_filp;
594 struct nfs_open_context *ctx =
595 (struct nfs_open_context *) file->private_data;
1da177e4
LT
596 struct address_space *mapping = file->f_mapping;
597 struct inode *inode = mapping->host;
598 struct iovec iov = {
599 .iov_base = (char __user *)buf,
1da177e4
LT
600 };
601
ce1a8e67 602 dfprintk(VFS, "nfs: direct write(%s/%s, %lu@%Ld)\n",
0bbacc40 603 file->f_dentry->d_parent->d_name.name,
ce1a8e67
CL
604 file->f_dentry->d_name.name,
605 (unsigned long) count, (long long) pos);
1da177e4 606
ce1a8e67 607 retval = -EINVAL;
1da177e4
LT
608 if (!is_sync_kiocb(iocb))
609 goto out;
ce1a8e67
CL
610
611 retval = generic_write_checks(file, &pos, &count, 0);
612 if (retval)
1da177e4 613 goto out;
ce1a8e67
CL
614
615 retval = -EINVAL;
616 if ((ssize_t) count < 0)
1da177e4 617 goto out;
1da177e4
LT
618 retval = 0;
619 if (!count)
620 goto out;
ce1a8e67
CL
621 iov.iov_len = count,
622
623 retval = -EFAULT;
624 if (!access_ok(VERIFY_READ, iov.iov_base, iov.iov_len))
625 goto out;
1da177e4 626
29884df0
TM
627 retval = nfs_sync_mapping(mapping);
628 if (retval)
629 goto out;
1da177e4
LT
630
631 retval = nfs_direct_write(inode, ctx, &iov, pos, 1);
632 if (mapping->nrpages)
633 invalidate_inode_pages2(mapping);
634 if (retval > 0)
ce1a8e67 635 iocb->ki_pos = pos + retval;
1da177e4
LT
636
637out:
638 return retval;
639}
640
641int nfs_init_directcache(void)
642{
643 nfs_direct_cachep = kmem_cache_create("nfs_direct_cache",
644 sizeof(struct nfs_direct_req),
645 0, SLAB_RECLAIM_ACCOUNT,
646 NULL, NULL);
647 if (nfs_direct_cachep == NULL)
648 return -ENOMEM;
649
650 return 0;
651}
652
653void nfs_destroy_directcache(void)
654{
655 if (kmem_cache_destroy(nfs_direct_cachep))
656 printk(KERN_INFO "nfs_direct_cache: not all structures were freed\n");
657}