blob: 1e3725e51df18688cfb8222b1414ad1fe9c03ee9 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Chuck Lever88467052006-03-20 13:44:34 -050010 * (multiple copies of the same instance running on separate hosts)
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 * implement their own cache coherency protocol that subsumes file
Chuck Lever88467052006-03-20 13:44:34 -050012 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070015 * 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
Chuck Lever88467052006-03-20 13:44:34 -050037 * 04 May 2005 support O_DIRECT with aio --cel
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 *
39 */
40
41#include <linux/config.h>
42#include <linux/errno.h>
43#include <linux/sched.h>
44#include <linux/kernel.h>
45#include <linux/smp_lock.h>
46#include <linux/file.h>
47#include <linux/pagemap.h>
48#include <linux/kref.h>
49
50#include <linux/nfs_fs.h>
51#include <linux/nfs_page.h>
52#include <linux/sunrpc/clnt.h>
53
54#include <asm/system.h>
55#include <asm/uaccess.h>
56#include <asm/atomic.h>
57
Chuck Lever91d5b472006-03-20 13:44:14 -050058#include "iostat.h"
59
Linus Torvalds1da177e2005-04-16 15:20:36 -070060#define NFSDBG_FACILITY NFSDBG_VFS
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
Trond Myklebust143f4122006-03-13 21:20:46 -080062static void nfs_free_user_pages(struct page **pages, int npages, int do_dirty);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063static 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 */
Chuck Lever15ce4a02006-03-20 13:44:34 -050070
71 /* I/O parameters */
Trond Myklebustfad61492006-03-20 13:44:36 -050072 struct list_head list, /* nfs_read/write_data structs */
73 rewrite_list; /* saved nfs_write_data structs */
Trond Myklebusta8881f52006-03-20 13:44:36 -050074 struct nfs_open_context *ctx; /* file open context info */
Chuck Lever99514f82006-03-20 13:44:30 -050075 struct kiocb * iocb; /* controlling i/o request */
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 wait_queue_head_t wait; /* wait for i/o completion */
Chuck Lever88467052006-03-20 13:44:34 -050077 struct inode * inode; /* target file of i/o */
Trond Myklebustfad61492006-03-20 13:44:36 -050078 unsigned long user_addr; /* location of user's buffer */
79 size_t user_count; /* total bytes to move */
80 loff_t pos; /* starting offset in file */
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 struct page ** pages; /* pages in our buffer */
82 unsigned int npages; /* count of pages */
Chuck Lever15ce4a02006-03-20 13:44:34 -050083
84 /* completion state */
85 spinlock_t lock; /* protect completion state */
86 int outstanding; /* i/os we're waiting for */
87 ssize_t count, /* bytes actually processed */
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 error; /* any reported error */
Trond Myklebustfad61492006-03-20 13:44:36 -050089
90 /* commit state */
91 struct nfs_write_data * commit_data; /* special write_data for commits */
92 int flags;
93#define NFS_ODIRECT_DO_COMMIT (1) /* an unstable reply was received */
94#define NFS_ODIRECT_RESCHED_WRITES (2) /* write verification failed */
95 struct nfs_writeverf verf; /* unstable write verifier */
Linus Torvalds1da177e2005-04-16 15:20:36 -070096};
97
Trond Myklebustfad61492006-03-20 13:44:36 -050098static void nfs_direct_write_schedule(struct nfs_direct_req *dreq, int sync);
99static void nfs_direct_write_complete(struct nfs_direct_req *dreq, struct inode *inode);
100
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101/**
Chuck Leverb8a32e22006-03-20 13:44:28 -0500102 * nfs_direct_IO - NFS address space operation for direct I/O
103 * @rw: direction (read or write)
104 * @iocb: target I/O control block
105 * @iov: array of vectors that define I/O buffer
106 * @pos: offset in file to begin the operation
107 * @nr_segs: size of iovec array
108 *
109 * The presence of this routine in the address space ops vector means
110 * the NFS client supports direct I/O. However, we shunt off direct
111 * read and write requests before the VFS gets them, so this method
112 * should never be called.
113 */
114ssize_t nfs_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov, loff_t pos, unsigned long nr_segs)
115{
116 struct dentry *dentry = iocb->ki_filp->f_dentry;
117
118 dprintk("NFS: nfs_direct_IO (%s) off/no(%Ld/%lu) EINVAL\n",
119 dentry->d_name.name, (long long) pos, nr_segs);
120
121 return -EINVAL;
122}
123
Chuck Leverd4cc9482006-03-20 13:44:28 -0500124static inline int nfs_get_user_pages(int rw, unsigned long user_addr, size_t size, struct page ***pages)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125{
126 int result = -ENOMEM;
127 unsigned long page_count;
128 size_t array_size;
129
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 page_count = (user_addr + size + PAGE_SIZE - 1) >> PAGE_SHIFT;
131 page_count -= user_addr >> PAGE_SHIFT;
132
133 array_size = (page_count * sizeof(struct page *));
134 *pages = kmalloc(array_size, GFP_KERNEL);
135 if (*pages) {
136 down_read(&current->mm->mmap_sem);
137 result = get_user_pages(current, current->mm, user_addr,
138 page_count, (rw == READ), 0,
139 *pages, NULL);
140 up_read(&current->mm->mmap_sem);
Trond Myklebust143f4122006-03-13 21:20:46 -0800141 /*
142 * If we got fewer pages than expected from get_user_pages(),
143 * the user buffer runs off the end of a mapping; return EFAULT.
144 */
145 if (result >= 0 && result < page_count) {
146 nfs_free_user_pages(*pages, result, 0);
147 *pages = NULL;
148 result = -EFAULT;
149 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 }
151 return result;
152}
153
Chuck Leverd4cc9482006-03-20 13:44:28 -0500154static void nfs_free_user_pages(struct page **pages, int npages, int do_dirty)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155{
156 int i;
157 for (i = 0; i < npages; i++) {
Trond Myklebust566dd602006-01-03 09:55:35 +0100158 struct page *page = pages[i];
159 if (do_dirty && !PageCompound(page))
160 set_page_dirty_lock(page);
161 page_cache_release(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 }
163 kfree(pages);
164}
165
Chuck Lever93619e52006-03-20 13:44:31 -0500166static inline struct nfs_direct_req *nfs_direct_req_alloc(void)
167{
168 struct nfs_direct_req *dreq;
169
170 dreq = kmem_cache_alloc(nfs_direct_cachep, SLAB_KERNEL);
171 if (!dreq)
172 return NULL;
173
174 kref_init(&dreq->kref);
175 init_waitqueue_head(&dreq->wait);
176 INIT_LIST_HEAD(&dreq->list);
Trond Myklebustfad61492006-03-20 13:44:36 -0500177 INIT_LIST_HEAD(&dreq->rewrite_list);
Chuck Lever93619e52006-03-20 13:44:31 -0500178 dreq->iocb = NULL;
Trond Myklebusta8881f52006-03-20 13:44:36 -0500179 dreq->ctx = NULL;
Chuck Lever15ce4a02006-03-20 13:44:34 -0500180 spin_lock_init(&dreq->lock);
181 dreq->outstanding = 0;
182 dreq->count = 0;
183 dreq->error = 0;
Trond Myklebustfad61492006-03-20 13:44:36 -0500184 dreq->flags = 0;
Chuck Lever93619e52006-03-20 13:44:31 -0500185
186 return dreq;
187}
188
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189static void nfs_direct_req_release(struct kref *kref)
190{
191 struct nfs_direct_req *dreq = container_of(kref, struct nfs_direct_req, kref);
Trond Myklebusta8881f52006-03-20 13:44:36 -0500192
193 if (dreq->ctx != NULL)
194 put_nfs_open_context(dreq->ctx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 kmem_cache_free(nfs_direct_cachep, dreq);
196}
197
Chuck Leverd4cc9482006-03-20 13:44:28 -0500198/*
Chuck Leverbc0fb202006-03-20 13:44:31 -0500199 * Collects and returns the final error value/byte-count.
200 */
201static ssize_t nfs_direct_wait(struct nfs_direct_req *dreq)
202{
Chuck Lever15ce4a02006-03-20 13:44:34 -0500203 ssize_t result = -EIOCBQUEUED;
Chuck Leverbc0fb202006-03-20 13:44:31 -0500204
205 /* Async requests don't wait here */
206 if (dreq->iocb)
207 goto out;
208
Chuck Lever15ce4a02006-03-20 13:44:34 -0500209 result = wait_event_interruptible(dreq->wait, (dreq->outstanding == 0));
Chuck Leverbc0fb202006-03-20 13:44:31 -0500210
211 if (!result)
Chuck Lever15ce4a02006-03-20 13:44:34 -0500212 result = dreq->error;
Chuck Leverbc0fb202006-03-20 13:44:31 -0500213 if (!result)
Chuck Lever15ce4a02006-03-20 13:44:34 -0500214 result = dreq->count;
Chuck Leverbc0fb202006-03-20 13:44:31 -0500215
216out:
217 kref_put(&dreq->kref, nfs_direct_req_release);
218 return (ssize_t) result;
219}
220
221/*
Chuck Lever63ab46a2006-03-20 13:44:31 -0500222 * We must hold a reference to all the pages in this direct read request
223 * until the RPCs complete. This could be long *after* we are woken up in
224 * nfs_direct_wait (for instance, if someone hits ^C on a slow server).
225 *
226 * In addition, synchronous I/O uses a stack-allocated iocb. Thus we
227 * can't trust the iocb is still valid here if this is a synchronous
228 * request. If the waiter is woken prematurely, the iocb is long gone.
229 */
230static void nfs_direct_complete(struct nfs_direct_req *dreq)
231{
232 nfs_free_user_pages(dreq->pages, dreq->npages, 1);
233
234 if (dreq->iocb) {
Chuck Lever15ce4a02006-03-20 13:44:34 -0500235 long res = (long) dreq->error;
Chuck Lever63ab46a2006-03-20 13:44:31 -0500236 if (!res)
Chuck Lever15ce4a02006-03-20 13:44:34 -0500237 res = (long) dreq->count;
Chuck Lever63ab46a2006-03-20 13:44:31 -0500238 aio_complete(dreq->iocb, res, 0);
239 } else
240 wake_up(&dreq->wait);
241
242 kref_put(&dreq->kref, nfs_direct_req_release);
243}
244
245/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 * Note we also set the number of requests we have in the dreq when we are
247 * done. This prevents races with I/O completion so we will always wait
248 * until all requests have been dispatched and completed.
249 */
Chuck Lever5dd602f2006-03-20 13:44:29 -0500250static struct nfs_direct_req *nfs_direct_read_alloc(size_t nbytes, size_t rsize)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251{
252 struct list_head *list;
253 struct nfs_direct_req *dreq;
Chuck Lever40859d72005-11-30 18:09:02 -0500254 unsigned int rpages = (rsize + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255
Chuck Lever93619e52006-03-20 13:44:31 -0500256 dreq = nfs_direct_req_alloc();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 if (!dreq)
258 return NULL;
259
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 list = &dreq->list;
261 for(;;) {
Chuck Lever40859d72005-11-30 18:09:02 -0500262 struct nfs_read_data *data = nfs_readdata_alloc(rpages);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263
264 if (unlikely(!data)) {
265 while (!list_empty(list)) {
266 data = list_entry(list->next,
267 struct nfs_read_data, pages);
268 list_del(&data->pages);
269 nfs_readdata_free(data);
270 }
271 kref_put(&dreq->kref, nfs_direct_req_release);
272 return NULL;
273 }
274
275 INIT_LIST_HEAD(&data->pages);
276 list_add(&data->pages, list);
277
278 data->req = (struct nfs_page *) dreq;
Chuck Lever15ce4a02006-03-20 13:44:34 -0500279 dreq->outstanding++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 if (nbytes <= rsize)
281 break;
282 nbytes -= rsize;
283 }
284 kref_get(&dreq->kref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 return dreq;
286}
287
Trond Myklebustec06c092006-03-20 13:44:27 -0500288static void nfs_direct_read_result(struct rpc_task *task, void *calldata)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289{
Trond Myklebustec06c092006-03-20 13:44:27 -0500290 struct nfs_read_data *data = calldata;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 struct nfs_direct_req *dreq = (struct nfs_direct_req *) data->req;
292
Trond Myklebustec06c092006-03-20 13:44:27 -0500293 if (nfs_readpage_result(task, data) != 0)
294 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
Chuck Lever15ce4a02006-03-20 13:44:34 -0500296 spin_lock(&dreq->lock);
297
298 if (likely(task->tk_status >= 0))
299 dreq->count += data->res.count;
300 else
301 dreq->error = task->tk_status;
302
303 if (--dreq->outstanding) {
304 spin_unlock(&dreq->lock);
305 return;
306 }
307
308 spin_unlock(&dreq->lock);
309 nfs_direct_complete(dreq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310}
311
Trond Myklebustec06c092006-03-20 13:44:27 -0500312static const struct rpc_call_ops nfs_read_direct_ops = {
313 .rpc_call_done = nfs_direct_read_result,
314 .rpc_release = nfs_readdata_release,
315};
316
Chuck Leverd4cc9482006-03-20 13:44:28 -0500317/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 * For each nfs_read_data struct that was allocated on the list, dispatch
319 * an NFS READ operation
320 */
Trond Myklebustfad61492006-03-20 13:44:36 -0500321static void nfs_direct_read_schedule(struct nfs_direct_req *dreq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322{
Trond Myklebusta8881f52006-03-20 13:44:36 -0500323 struct nfs_open_context *ctx = dreq->ctx;
324 struct inode *inode = ctx->dentry->d_inode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 struct list_head *list = &dreq->list;
326 struct page **pages = dreq->pages;
Trond Myklebustfad61492006-03-20 13:44:36 -0500327 size_t count = dreq->user_count;
328 loff_t pos = dreq->pos;
Chuck Lever5dd602f2006-03-20 13:44:29 -0500329 size_t rsize = NFS_SERVER(inode)->rsize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 unsigned int curpage, pgbase;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331
332 curpage = 0;
Trond Myklebustfad61492006-03-20 13:44:36 -0500333 pgbase = dreq->user_addr & ~PAGE_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 do {
335 struct nfs_read_data *data;
Chuck Lever5dd602f2006-03-20 13:44:29 -0500336 size_t bytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337
338 bytes = rsize;
339 if (count < rsize)
340 bytes = count;
341
Trond Myklebust5db3a7b2006-03-20 13:44:37 -0500342 BUG_ON(list_empty(list));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 data = list_entry(list->next, struct nfs_read_data, pages);
344 list_del_init(&data->pages);
345
346 data->inode = inode;
347 data->cred = ctx->cred;
348 data->args.fh = NFS_FH(inode);
349 data->args.context = ctx;
Chuck Lever88467052006-03-20 13:44:34 -0500350 data->args.offset = pos;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 data->args.pgbase = pgbase;
352 data->args.pages = &pages[curpage];
353 data->args.count = bytes;
354 data->res.fattr = &data->fattr;
355 data->res.eof = 0;
356 data->res.count = bytes;
357
Trond Myklebustec06c092006-03-20 13:44:27 -0500358 rpc_init_task(&data->task, NFS_CLIENT(inode), RPC_TASK_ASYNC,
359 &nfs_read_direct_ops, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 NFS_PROTO(inode)->read_setup(data);
361
362 data->task.tk_cookie = (unsigned long) inode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363
364 lock_kernel();
365 rpc_execute(&data->task);
366 unlock_kernel();
367
368 dfprintk(VFS, "NFS: %4d initiated direct read call (req %s/%Ld, %u bytes @ offset %Lu)\n",
369 data->task.tk_pid,
370 inode->i_sb->s_id,
371 (long long)NFS_FILEID(inode),
372 bytes,
373 (unsigned long long)data->args.offset);
374
Chuck Lever88467052006-03-20 13:44:34 -0500375 pos += bytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 pgbase += bytes;
377 curpage += pgbase >> PAGE_SHIFT;
378 pgbase &= ~PAGE_MASK;
379
380 count -= bytes;
381 } while (count != 0);
Trond Myklebust5db3a7b2006-03-20 13:44:37 -0500382 BUG_ON(!list_empty(list));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383}
384
Chuck Lever88467052006-03-20 13:44:34 -0500385static ssize_t nfs_direct_read(struct kiocb *iocb, unsigned long user_addr, size_t count, loff_t pos, struct page **pages, unsigned int nr_pages)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386{
387 ssize_t result;
388 sigset_t oldset;
Chuck Lever99514f82006-03-20 13:44:30 -0500389 struct inode *inode = iocb->ki_filp->f_mapping->host;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 struct rpc_clnt *clnt = NFS_CLIENT(inode);
391 struct nfs_direct_req *dreq;
392
393 dreq = nfs_direct_read_alloc(count, NFS_SERVER(inode)->rsize);
394 if (!dreq)
395 return -ENOMEM;
396
Trond Myklebustfad61492006-03-20 13:44:36 -0500397 dreq->user_addr = user_addr;
398 dreq->user_count = count;
399 dreq->pos = pos;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 dreq->pages = pages;
401 dreq->npages = nr_pages;
Chuck Lever91d5b472006-03-20 13:44:14 -0500402 dreq->inode = inode;
Trond Myklebusta8881f52006-03-20 13:44:36 -0500403 dreq->ctx = get_nfs_open_context((struct nfs_open_context *)iocb->ki_filp->private_data);
Chuck Lever487b8372006-03-20 13:44:30 -0500404 if (!is_sync_kiocb(iocb))
405 dreq->iocb = iocb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406
Chuck Lever91d5b472006-03-20 13:44:14 -0500407 nfs_add_stats(inode, NFSIOS_DIRECTREADBYTES, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 rpc_clnt_sigmask(clnt, &oldset);
Trond Myklebustfad61492006-03-20 13:44:36 -0500409 nfs_direct_read_schedule(dreq);
Chuck Leverbc0fb202006-03-20 13:44:31 -0500410 result = nfs_direct_wait(dreq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 rpc_clnt_sigunmask(clnt, &oldset);
412
413 return result;
414}
415
Trond Myklebustfad61492006-03-20 13:44:36 -0500416static void nfs_direct_free_writedata(struct nfs_direct_req *dreq)
417{
418 list_splice_init(&dreq->rewrite_list, &dreq->list);
419 while (!list_empty(&dreq->list)) {
420 struct nfs_write_data *data = list_entry(dreq->list.next, struct nfs_write_data, pages);
421 list_del(&data->pages);
422 nfs_writedata_release(data);
423 }
424}
425
426#if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4)
427static void nfs_direct_write_reschedule(struct nfs_direct_req *dreq)
428{
429 struct list_head *pos;
430
431 list_splice_init(&dreq->rewrite_list, &dreq->list);
432 list_for_each(pos, &dreq->list)
433 dreq->outstanding++;
434 dreq->count = 0;
435
436 nfs_direct_write_schedule(dreq, FLUSH_STABLE);
437}
438
439static void nfs_direct_commit_result(struct rpc_task *task, void *calldata)
440{
441 struct nfs_write_data *data = calldata;
442 struct nfs_direct_req *dreq = (struct nfs_direct_req *) data->req;
443
444 /* Call the NFS version-specific code */
445 if (NFS_PROTO(data->inode)->commit_done(task, data) != 0)
446 return;
447 if (unlikely(task->tk_status < 0)) {
448 dreq->error = task->tk_status;
449 dreq->flags = NFS_ODIRECT_RESCHED_WRITES;
450 }
451 if (memcmp(&dreq->verf, &data->verf, sizeof(data->verf))) {
452 dprintk("NFS: %5u commit verify failed\n", task->tk_pid);
453 dreq->flags = NFS_ODIRECT_RESCHED_WRITES;
454 }
455
456 dprintk("NFS: %5u commit returned %d\n", task->tk_pid, task->tk_status);
457 nfs_direct_write_complete(dreq, data->inode);
458}
459
460static const struct rpc_call_ops nfs_commit_direct_ops = {
461 .rpc_call_done = nfs_direct_commit_result,
462 .rpc_release = nfs_commit_release,
463};
464
465static void nfs_direct_commit_schedule(struct nfs_direct_req *dreq)
466{
Trond Myklebustfad61492006-03-20 13:44:36 -0500467 struct nfs_write_data *data = dreq->commit_data;
468 struct rpc_task *task = &data->task;
469
470 data->inode = dreq->inode;
Trond Myklebusta8881f52006-03-20 13:44:36 -0500471 data->cred = dreq->ctx->cred;
Trond Myklebustfad61492006-03-20 13:44:36 -0500472
473 data->args.fh = NFS_FH(data->inode);
474 data->args.offset = dreq->pos;
475 data->args.count = dreq->user_count;
476 data->res.count = 0;
477 data->res.fattr = &data->fattr;
478 data->res.verf = &data->verf;
479
480 rpc_init_task(&data->task, NFS_CLIENT(dreq->inode), RPC_TASK_ASYNC,
481 &nfs_commit_direct_ops, data);
482 NFS_PROTO(data->inode)->commit_setup(data, 0);
483
484 data->task.tk_priority = RPC_PRIORITY_NORMAL;
485 data->task.tk_cookie = (unsigned long)data->inode;
486 /* Note: task.tk_ops->rpc_release will free dreq->commit_data */
487 dreq->commit_data = NULL;
488
489 dprintk("NFS: %5u initiated commit call\n", task->tk_pid);
490
491 lock_kernel();
492 rpc_execute(&data->task);
493 unlock_kernel();
494}
495
496static void nfs_direct_write_complete(struct nfs_direct_req *dreq, struct inode *inode)
497{
498 int flags = dreq->flags;
499
500 dreq->flags = 0;
501 switch (flags) {
502 case NFS_ODIRECT_DO_COMMIT:
503 nfs_direct_commit_schedule(dreq);
504 break;
505 case NFS_ODIRECT_RESCHED_WRITES:
506 nfs_direct_write_reschedule(dreq);
507 break;
508 default:
509 nfs_end_data_update(inode);
510 if (dreq->commit_data != NULL)
511 nfs_commit_free(dreq->commit_data);
512 nfs_direct_free_writedata(dreq);
513 nfs_direct_complete(dreq);
514 }
515}
516
517static void nfs_alloc_commit_data(struct nfs_direct_req *dreq)
518{
519 dreq->commit_data = nfs_commit_alloc(0);
520 if (dreq->commit_data != NULL)
521 dreq->commit_data->req = (struct nfs_page *) dreq;
522}
523#else
524static inline void nfs_alloc_commit_data(struct nfs_direct_req *dreq)
525{
526 dreq->commit_data = NULL;
527}
528
529static void nfs_direct_write_complete(struct nfs_direct_req *dreq, struct inode *inode)
530{
531 nfs_end_data_update(inode);
532 nfs_direct_free_writedata(dreq);
533 nfs_direct_complete(dreq);
534}
535#endif
536
Chuck Lever462d5b32006-03-20 13:44:32 -0500537static struct nfs_direct_req *nfs_direct_write_alloc(size_t nbytes, size_t wsize)
538{
539 struct list_head *list;
540 struct nfs_direct_req *dreq;
Chuck Lever462d5b32006-03-20 13:44:32 -0500541 unsigned int wpages = (wsize + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
542
543 dreq = nfs_direct_req_alloc();
544 if (!dreq)
545 return NULL;
546
547 list = &dreq->list;
548 for(;;) {
549 struct nfs_write_data *data = nfs_writedata_alloc(wpages);
550
551 if (unlikely(!data)) {
552 while (!list_empty(list)) {
553 data = list_entry(list->next,
554 struct nfs_write_data, pages);
555 list_del(&data->pages);
556 nfs_writedata_free(data);
557 }
558 kref_put(&dreq->kref, nfs_direct_req_release);
559 return NULL;
560 }
561
562 INIT_LIST_HEAD(&data->pages);
563 list_add(&data->pages, list);
564
565 data->req = (struct nfs_page *) dreq;
Chuck Lever15ce4a02006-03-20 13:44:34 -0500566 dreq->outstanding++;
Chuck Lever462d5b32006-03-20 13:44:32 -0500567 if (nbytes <= wsize)
568 break;
569 nbytes -= wsize;
570 }
Trond Myklebustfad61492006-03-20 13:44:36 -0500571
572 nfs_alloc_commit_data(dreq);
573
Chuck Lever462d5b32006-03-20 13:44:32 -0500574 kref_get(&dreq->kref);
Chuck Lever462d5b32006-03-20 13:44:32 -0500575 return dreq;
576}
577
Chuck Lever462d5b32006-03-20 13:44:32 -0500578static void nfs_direct_write_result(struct rpc_task *task, void *calldata)
579{
580 struct nfs_write_data *data = calldata;
581 struct nfs_direct_req *dreq = (struct nfs_direct_req *) data->req;
582 int status = task->tk_status;
583
584 if (nfs_writeback_done(task, data) != 0)
585 return;
Chuck Lever462d5b32006-03-20 13:44:32 -0500586
Chuck Lever15ce4a02006-03-20 13:44:34 -0500587 spin_lock(&dreq->lock);
Chuck Lever462d5b32006-03-20 13:44:32 -0500588
Chuck Lever15ce4a02006-03-20 13:44:34 -0500589 if (likely(status >= 0))
590 dreq->count += data->res.count;
591 else
Trond Myklebustfad61492006-03-20 13:44:36 -0500592 dreq->error = task->tk_status;
Chuck Lever15ce4a02006-03-20 13:44:34 -0500593
Trond Myklebustfad61492006-03-20 13:44:36 -0500594 if (data->res.verf->committed != NFS_FILE_SYNC) {
595 switch (dreq->flags) {
596 case 0:
597 memcpy(&dreq->verf, &data->verf, sizeof(dreq->verf));
598 dreq->flags = NFS_ODIRECT_DO_COMMIT;
599 break;
600 case NFS_ODIRECT_DO_COMMIT:
601 if (memcmp(&dreq->verf, &data->verf, sizeof(dreq->verf))) {
602 dprintk("NFS: %5u write verify failed\n", task->tk_pid);
603 dreq->flags = NFS_ODIRECT_RESCHED_WRITES;
604 }
605 }
606 }
607 /* In case we have to resend */
608 data->args.stable = NFS_FILE_SYNC;
609
610 spin_unlock(&dreq->lock);
611}
612
613/*
614 * NB: Return the value of the first error return code. Subsequent
615 * errors after the first one are ignored.
616 */
617static void nfs_direct_write_release(void *calldata)
618{
619 struct nfs_write_data *data = calldata;
620 struct nfs_direct_req *dreq = (struct nfs_direct_req *) data->req;
621
622 spin_lock(&dreq->lock);
Chuck Lever15ce4a02006-03-20 13:44:34 -0500623 if (--dreq->outstanding) {
624 spin_unlock(&dreq->lock);
625 return;
Chuck Lever9eafa8c2006-03-20 13:44:33 -0500626 }
Chuck Lever15ce4a02006-03-20 13:44:34 -0500627 spin_unlock(&dreq->lock);
628
Trond Myklebustfad61492006-03-20 13:44:36 -0500629 nfs_direct_write_complete(dreq, data->inode);
Chuck Lever462d5b32006-03-20 13:44:32 -0500630}
631
632static const struct rpc_call_ops nfs_write_direct_ops = {
633 .rpc_call_done = nfs_direct_write_result,
Trond Myklebustfad61492006-03-20 13:44:36 -0500634 .rpc_release = nfs_direct_write_release,
Chuck Lever462d5b32006-03-20 13:44:32 -0500635};
636
637/*
638 * For each nfs_write_data struct that was allocated on the list, dispatch
639 * an NFS WRITE operation
Chuck Lever462d5b32006-03-20 13:44:32 -0500640 */
Trond Myklebustfad61492006-03-20 13:44:36 -0500641static void nfs_direct_write_schedule(struct nfs_direct_req *dreq, int sync)
Chuck Lever462d5b32006-03-20 13:44:32 -0500642{
Trond Myklebusta8881f52006-03-20 13:44:36 -0500643 struct nfs_open_context *ctx = dreq->ctx;
644 struct inode *inode = ctx->dentry->d_inode;
Chuck Lever462d5b32006-03-20 13:44:32 -0500645 struct list_head *list = &dreq->list;
646 struct page **pages = dreq->pages;
Trond Myklebustfad61492006-03-20 13:44:36 -0500647 size_t count = dreq->user_count;
648 loff_t pos = dreq->pos;
Chuck Lever462d5b32006-03-20 13:44:32 -0500649 size_t wsize = NFS_SERVER(inode)->wsize;
650 unsigned int curpage, pgbase;
651
652 curpage = 0;
Trond Myklebustfad61492006-03-20 13:44:36 -0500653 pgbase = dreq->user_addr & ~PAGE_MASK;
Chuck Lever462d5b32006-03-20 13:44:32 -0500654 do {
655 struct nfs_write_data *data;
656 size_t bytes;
657
658 bytes = wsize;
659 if (count < wsize)
660 bytes = count;
661
Trond Myklebust5db3a7b2006-03-20 13:44:37 -0500662 BUG_ON(list_empty(list));
Chuck Lever462d5b32006-03-20 13:44:32 -0500663 data = list_entry(list->next, struct nfs_write_data, pages);
Trond Myklebustfad61492006-03-20 13:44:36 -0500664 list_move_tail(&data->pages, &dreq->rewrite_list);
Chuck Lever462d5b32006-03-20 13:44:32 -0500665
666 data->inode = inode;
667 data->cred = ctx->cred;
668 data->args.fh = NFS_FH(inode);
669 data->args.context = ctx;
Chuck Lever88467052006-03-20 13:44:34 -0500670 data->args.offset = pos;
Chuck Lever462d5b32006-03-20 13:44:32 -0500671 data->args.pgbase = pgbase;
672 data->args.pages = &pages[curpage];
673 data->args.count = bytes;
674 data->res.fattr = &data->fattr;
675 data->res.count = bytes;
Chuck Lever47989d72006-03-20 13:44:32 -0500676 data->res.verf = &data->verf;
Chuck Lever462d5b32006-03-20 13:44:32 -0500677
678 rpc_init_task(&data->task, NFS_CLIENT(inode), RPC_TASK_ASYNC,
679 &nfs_write_direct_ops, data);
Trond Myklebustfad61492006-03-20 13:44:36 -0500680 NFS_PROTO(inode)->write_setup(data, sync);
Chuck Lever462d5b32006-03-20 13:44:32 -0500681
682 data->task.tk_priority = RPC_PRIORITY_NORMAL;
683 data->task.tk_cookie = (unsigned long) inode;
684
685 lock_kernel();
686 rpc_execute(&data->task);
687 unlock_kernel();
688
689 dfprintk(VFS, "NFS: %4d initiated direct write call (req %s/%Ld, %u bytes @ offset %Lu)\n",
690 data->task.tk_pid,
691 inode->i_sb->s_id,
692 (long long)NFS_FILEID(inode),
693 bytes,
694 (unsigned long long)data->args.offset);
695
Chuck Lever88467052006-03-20 13:44:34 -0500696 pos += bytes;
Chuck Lever462d5b32006-03-20 13:44:32 -0500697 pgbase += bytes;
698 curpage += pgbase >> PAGE_SHIFT;
699 pgbase &= ~PAGE_MASK;
700
701 count -= bytes;
702 } while (count != 0);
Trond Myklebust5db3a7b2006-03-20 13:44:37 -0500703 BUG_ON(!list_empty(list));
Chuck Lever462d5b32006-03-20 13:44:32 -0500704}
705
Chuck Lever88467052006-03-20 13:44:34 -0500706static ssize_t nfs_direct_write(struct kiocb *iocb, unsigned long user_addr, size_t count, loff_t pos, struct page **pages, int nr_pages)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707{
Chuck Lever462d5b32006-03-20 13:44:32 -0500708 ssize_t result;
709 sigset_t oldset;
Chuck Leverc89f2ee2006-03-20 13:44:33 -0500710 struct inode *inode = iocb->ki_filp->f_mapping->host;
Chuck Lever462d5b32006-03-20 13:44:32 -0500711 struct rpc_clnt *clnt = NFS_CLIENT(inode);
712 struct nfs_direct_req *dreq;
Trond Myklebustfad61492006-03-20 13:44:36 -0500713 size_t wsize = NFS_SERVER(inode)->wsize;
714 int sync = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715
Trond Myklebustfad61492006-03-20 13:44:36 -0500716 dreq = nfs_direct_write_alloc(count, wsize);
Chuck Lever462d5b32006-03-20 13:44:32 -0500717 if (!dreq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 return -ENOMEM;
Trond Myklebustfad61492006-03-20 13:44:36 -0500719 if (dreq->commit_data == NULL || count < wsize)
720 sync = FLUSH_STABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721
Trond Myklebustfad61492006-03-20 13:44:36 -0500722 dreq->user_addr = user_addr;
723 dreq->user_count = count;
724 dreq->pos = pos;
Chuck Lever462d5b32006-03-20 13:44:32 -0500725 dreq->pages = pages;
726 dreq->npages = nr_pages;
Chuck Leverc89f2ee2006-03-20 13:44:33 -0500727 dreq->inode = inode;
Trond Myklebusta8881f52006-03-20 13:44:36 -0500728 dreq->ctx = get_nfs_open_context((struct nfs_open_context *)iocb->ki_filp->private_data);
Chuck Leverc89f2ee2006-03-20 13:44:33 -0500729 if (!is_sync_kiocb(iocb))
730 dreq->iocb = iocb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731
Chuck Lever47989d72006-03-20 13:44:32 -0500732 nfs_add_stats(inode, NFSIOS_DIRECTWRITTENBYTES, count);
733
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 nfs_begin_data_update(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735
Chuck Lever462d5b32006-03-20 13:44:32 -0500736 rpc_clnt_sigmask(clnt, &oldset);
Trond Myklebustfad61492006-03-20 13:44:36 -0500737 nfs_direct_write_schedule(dreq, sync);
Chuck Leverc89f2ee2006-03-20 13:44:33 -0500738 result = nfs_direct_wait(dreq);
Chuck Lever462d5b32006-03-20 13:44:32 -0500739 rpc_clnt_sigunmask(clnt, &oldset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740
Chuck Lever462d5b32006-03-20 13:44:32 -0500741 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742}
743
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 * nfs_file_direct_read - file direct read operation for NFS files
746 * @iocb: target I/O control block
747 * @buf: user's buffer into which to read data
Chuck Lever88467052006-03-20 13:44:34 -0500748 * @count: number of bytes to read
749 * @pos: byte offset in file where reading starts
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 *
751 * We use this function for direct reads instead of calling
752 * generic_file_aio_read() in order to avoid gfar's check to see if
753 * the request starts before the end of the file. For that check
754 * to work, we must generate a GETATTR before each direct read, and
755 * even then there is a window between the GETATTR and the subsequent
Chuck Lever88467052006-03-20 13:44:34 -0500756 * READ where the file size could change. Our preference is simply
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 * to do all reads the application wants, and the server will take
758 * care of managing the end of file boundary.
Chuck Lever88467052006-03-20 13:44:34 -0500759 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 * This function also eliminates unnecessarily updating the file's
761 * atime locally, as the NFS server sets the file's atime, and this
762 * client must read the updated atime from the server back into its
763 * cache.
764 */
Chuck Leverd4cc9482006-03-20 13:44:28 -0500765ssize_t nfs_file_direct_read(struct kiocb *iocb, char __user *buf, size_t count, loff_t pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766{
767 ssize_t retval = -EINVAL;
Chuck Lever0cdd80d2006-03-20 13:44:29 -0500768 int page_count;
769 struct page **pages;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 struct file *file = iocb->ki_filp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 struct address_space *mapping = file->f_mapping;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772
Chuck Leverce1a8e62005-11-30 18:08:17 -0500773 dprintk("nfs: direct read(%s/%s, %lu@%Ld)\n",
Chuck Lever0bbacc42005-11-01 16:53:32 -0500774 file->f_dentry->d_parent->d_name.name,
775 file->f_dentry->d_name.name,
Chuck Leverce1a8e62005-11-30 18:08:17 -0500776 (unsigned long) count, (long long) pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 if (count < 0)
779 goto out;
780 retval = -EFAULT;
Chuck Lever0cdd80d2006-03-20 13:44:29 -0500781 if (!access_ok(VERIFY_WRITE, buf, count))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 goto out;
783 retval = 0;
784 if (!count)
785 goto out;
786
Trond Myklebust29884df2005-12-13 16:13:54 -0500787 retval = nfs_sync_mapping(mapping);
788 if (retval)
789 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790
Chuck Lever0cdd80d2006-03-20 13:44:29 -0500791 page_count = nfs_get_user_pages(READ, (unsigned long) buf,
792 count, &pages);
793 if (page_count < 0) {
794 nfs_free_user_pages(pages, 0, 0);
795 retval = page_count;
796 goto out;
797 }
798
Chuck Lever99514f82006-03-20 13:44:30 -0500799 retval = nfs_direct_read(iocb, (unsigned long) buf, count, pos,
Chuck Lever0cdd80d2006-03-20 13:44:29 -0500800 pages, page_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 if (retval > 0)
Chuck Lever0cdd80d2006-03-20 13:44:29 -0500802 iocb->ki_pos = pos + retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803
804out:
805 return retval;
806}
807
808/**
809 * nfs_file_direct_write - file direct write operation for NFS files
810 * @iocb: target I/O control block
811 * @buf: user's buffer from which to write data
Chuck Lever88467052006-03-20 13:44:34 -0500812 * @count: number of bytes to write
813 * @pos: byte offset in file where writing starts
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 *
815 * We use this function for direct writes instead of calling
816 * generic_file_aio_write() in order to avoid taking the inode
817 * semaphore and updating the i_size. The NFS server will set
818 * the new i_size and this client must read the updated size
819 * back into its cache. We let the server do generic write
820 * parameter checking and report problems.
821 *
822 * We also avoid an unnecessary invocation of generic_osync_inode(),
823 * as it is fairly meaningless to sync the metadata of an NFS file.
824 *
825 * We eliminate local atime updates, see direct read above.
826 *
827 * We avoid unnecessary page cache invalidations for normal cached
828 * readers of this file.
829 *
830 * Note that O_APPEND is not supported for NFS direct writes, as there
831 * is no atomic O_APPEND write facility in the NFS protocol.
832 */
Chuck Leverd4cc9482006-03-20 13:44:28 -0500833ssize_t nfs_file_direct_write(struct kiocb *iocb, const char __user *buf, size_t count, loff_t pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834{
Chuck Leverce1a8e62005-11-30 18:08:17 -0500835 ssize_t retval;
Chuck Lever47989d72006-03-20 13:44:32 -0500836 int page_count;
837 struct page **pages;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 struct file *file = iocb->ki_filp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 struct address_space *mapping = file->f_mapping;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840
Chuck Leverce1a8e62005-11-30 18:08:17 -0500841 dfprintk(VFS, "nfs: direct write(%s/%s, %lu@%Ld)\n",
Chuck Lever0bbacc42005-11-01 16:53:32 -0500842 file->f_dentry->d_parent->d_name.name,
Chuck Leverce1a8e62005-11-30 18:08:17 -0500843 file->f_dentry->d_name.name,
844 (unsigned long) count, (long long) pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845
Chuck Leverce1a8e62005-11-30 18:08:17 -0500846 retval = generic_write_checks(file, &pos, &count, 0);
847 if (retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 goto out;
Chuck Leverce1a8e62005-11-30 18:08:17 -0500849
850 retval = -EINVAL;
851 if ((ssize_t) count < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 retval = 0;
854 if (!count)
855 goto out;
Chuck Leverce1a8e62005-11-30 18:08:17 -0500856
857 retval = -EFAULT;
Chuck Lever47989d72006-03-20 13:44:32 -0500858 if (!access_ok(VERIFY_READ, buf, count))
Chuck Leverce1a8e62005-11-30 18:08:17 -0500859 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860
Trond Myklebust29884df2005-12-13 16:13:54 -0500861 retval = nfs_sync_mapping(mapping);
862 if (retval)
863 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864
Chuck Lever47989d72006-03-20 13:44:32 -0500865 page_count = nfs_get_user_pages(WRITE, (unsigned long) buf,
866 count, &pages);
867 if (page_count < 0) {
868 nfs_free_user_pages(pages, 0, 0);
869 retval = page_count;
870 goto out;
871 }
872
Chuck Leverc89f2ee2006-03-20 13:44:33 -0500873 retval = nfs_direct_write(iocb, (unsigned long) buf, count,
Chuck Lever47989d72006-03-20 13:44:32 -0500874 pos, pages, page_count);
Chuck Lever9eafa8c2006-03-20 13:44:33 -0500875
876 /*
877 * XXX: nfs_end_data_update() already ensures this file's
878 * cached data is subsequently invalidated. Do we really
879 * need to call invalidate_inode_pages2() again here?
880 *
881 * For aio writes, this invalidation will almost certainly
882 * occur before the writes complete. Kind of racey.
883 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 if (mapping->nrpages)
885 invalidate_inode_pages2(mapping);
Chuck Lever9eafa8c2006-03-20 13:44:33 -0500886
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 if (retval > 0)
Chuck Leverce1a8e62005-11-30 18:08:17 -0500888 iocb->ki_pos = pos + retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889
890out:
891 return retval;
892}
893
Chuck Lever88467052006-03-20 13:44:34 -0500894/**
895 * nfs_init_directcache - create a slab cache for nfs_direct_req structures
896 *
897 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898int nfs_init_directcache(void)
899{
900 nfs_direct_cachep = kmem_cache_create("nfs_direct_cache",
901 sizeof(struct nfs_direct_req),
902 0, SLAB_RECLAIM_ACCOUNT,
903 NULL, NULL);
904 if (nfs_direct_cachep == NULL)
905 return -ENOMEM;
906
907 return 0;
908}
909
Chuck Lever88467052006-03-20 13:44:34 -0500910/**
911 * nfs_init_directcache - destroy the slab cache for nfs_direct_req structures
912 *
913 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914void nfs_destroy_directcache(void)
915{
916 if (kmem_cache_destroy(nfs_direct_cachep))
917 printk(KERN_INFO "nfs_direct_cache: not all structures were freed\n");
918}