11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * linux/fs/nfs/write.c 31da177e4SLinus Torvalds * 47c85d900STrond Myklebust * Write file data over NFS. 51da177e4SLinus Torvalds * 61da177e4SLinus Torvalds * Copyright (C) 1996, 1997, Olaf Kirch <okir@monad.swb.de> 71da177e4SLinus Torvalds */ 81da177e4SLinus Torvalds 91da177e4SLinus Torvalds #include <linux/types.h> 101da177e4SLinus Torvalds #include <linux/slab.h> 111da177e4SLinus Torvalds #include <linux/mm.h> 121da177e4SLinus Torvalds #include <linux/pagemap.h> 131da177e4SLinus Torvalds #include <linux/file.h> 141da177e4SLinus Torvalds #include <linux/writeback.h> 1589a09141SPeter Zijlstra #include <linux/swap.h> 161da177e4SLinus Torvalds 171da177e4SLinus Torvalds #include <linux/sunrpc/clnt.h> 181da177e4SLinus Torvalds #include <linux/nfs_fs.h> 191da177e4SLinus Torvalds #include <linux/nfs_mount.h> 201da177e4SLinus Torvalds #include <linux/nfs_page.h> 213fcfab16SAndrew Morton #include <linux/backing-dev.h> 223fcfab16SAndrew Morton 231da177e4SLinus Torvalds #include <asm/uaccess.h> 241da177e4SLinus Torvalds 251da177e4SLinus Torvalds #include "delegation.h" 2649a70f27STrond Myklebust #include "internal.h" 2791d5b470SChuck Lever #include "iostat.h" 281da177e4SLinus Torvalds 291da177e4SLinus Torvalds #define NFSDBG_FACILITY NFSDBG_PAGECACHE 301da177e4SLinus Torvalds 311da177e4SLinus Torvalds #define MIN_POOL_WRITE (32) 321da177e4SLinus Torvalds #define MIN_POOL_COMMIT (4) 331da177e4SLinus Torvalds 341da177e4SLinus Torvalds /* 351da177e4SLinus Torvalds * Local function declarations 361da177e4SLinus Torvalds */ 371da177e4SLinus Torvalds static struct nfs_page * nfs_update_request(struct nfs_open_context*, 381da177e4SLinus Torvalds struct page *, 391da177e4SLinus Torvalds unsigned int, unsigned int); 40c63c7b05STrond Myklebust static void nfs_pageio_init_write(struct nfs_pageio_descriptor *desc, 41c63c7b05STrond Myklebust struct inode *inode, int ioflags); 42788e7a89STrond Myklebust static const struct rpc_call_ops nfs_write_partial_ops; 43788e7a89STrond Myklebust static const struct rpc_call_ops nfs_write_full_ops; 44788e7a89STrond Myklebust static const struct rpc_call_ops nfs_commit_ops; 451da177e4SLinus Torvalds 46e18b890bSChristoph Lameter static struct kmem_cache *nfs_wdata_cachep; 473feb2d49STrond Myklebust static mempool_t *nfs_wdata_mempool; 481da177e4SLinus Torvalds static mempool_t *nfs_commit_mempool; 491da177e4SLinus Torvalds 50e9f7bee1STrond Myklebust struct nfs_write_data *nfs_commit_alloc(void) 511da177e4SLinus Torvalds { 52e6b4f8daSChristoph Lameter struct nfs_write_data *p = mempool_alloc(nfs_commit_mempool, GFP_NOFS); 5340859d7eSChuck Lever 541da177e4SLinus Torvalds if (p) { 551da177e4SLinus Torvalds memset(p, 0, sizeof(*p)); 561da177e4SLinus Torvalds INIT_LIST_HEAD(&p->pages); 571da177e4SLinus Torvalds } 581da177e4SLinus Torvalds return p; 591da177e4SLinus Torvalds } 601da177e4SLinus Torvalds 6110afec90STrond Myklebust static void nfs_commit_rcu_free(struct rcu_head *head) 621da177e4SLinus Torvalds { 638aca67f0STrond Myklebust struct nfs_write_data *p = container_of(head, struct nfs_write_data, task.u.tk_rcu); 6440859d7eSChuck Lever if (p && (p->pagevec != &p->page_array[0])) 6540859d7eSChuck Lever kfree(p->pagevec); 661da177e4SLinus Torvalds mempool_free(p, nfs_commit_mempool); 671da177e4SLinus Torvalds } 681da177e4SLinus Torvalds 698aca67f0STrond Myklebust void nfs_commit_free(struct nfs_write_data *wdata) 708aca67f0STrond Myklebust { 718aca67f0STrond Myklebust call_rcu_bh(&wdata->task.u.tk_rcu, nfs_commit_rcu_free); 728aca67f0STrond Myklebust } 738aca67f0STrond Myklebust 748d5658c9STrond Myklebust struct nfs_write_data *nfs_writedata_alloc(unsigned int pagecount) 753feb2d49STrond Myklebust { 76e6b4f8daSChristoph Lameter struct nfs_write_data *p = mempool_alloc(nfs_wdata_mempool, GFP_NOFS); 773feb2d49STrond Myklebust 783feb2d49STrond Myklebust if (p) { 793feb2d49STrond Myklebust memset(p, 0, sizeof(*p)); 803feb2d49STrond Myklebust INIT_LIST_HEAD(&p->pages); 81e9f7bee1STrond Myklebust p->npages = pagecount; 820d0b5cb3SChuck Lever if (pagecount <= ARRAY_SIZE(p->page_array)) 830d0b5cb3SChuck Lever p->pagevec = p->page_array; 843feb2d49STrond Myklebust else { 850d0b5cb3SChuck Lever p->pagevec = kcalloc(pagecount, sizeof(struct page *), GFP_NOFS); 860d0b5cb3SChuck Lever if (!p->pagevec) { 873feb2d49STrond Myklebust mempool_free(p, nfs_wdata_mempool); 883feb2d49STrond Myklebust p = NULL; 893feb2d49STrond Myklebust } 903feb2d49STrond Myklebust } 913feb2d49STrond Myklebust } 923feb2d49STrond Myklebust return p; 933feb2d49STrond Myklebust } 943feb2d49STrond Myklebust 958aca67f0STrond Myklebust static void nfs_writedata_rcu_free(struct rcu_head *head) 963feb2d49STrond Myklebust { 978aca67f0STrond Myklebust struct nfs_write_data *p = container_of(head, struct nfs_write_data, task.u.tk_rcu); 983feb2d49STrond Myklebust if (p && (p->pagevec != &p->page_array[0])) 993feb2d49STrond Myklebust kfree(p->pagevec); 1003feb2d49STrond Myklebust mempool_free(p, nfs_wdata_mempool); 1013feb2d49STrond Myklebust } 1023feb2d49STrond Myklebust 1038aca67f0STrond Myklebust static void nfs_writedata_free(struct nfs_write_data *wdata) 1048aca67f0STrond Myklebust { 1058aca67f0STrond Myklebust call_rcu_bh(&wdata->task.u.tk_rcu, nfs_writedata_rcu_free); 1068aca67f0STrond Myklebust } 1078aca67f0STrond Myklebust 108963d8fe5STrond Myklebust void nfs_writedata_release(void *wdata) 1091da177e4SLinus Torvalds { 1101da177e4SLinus Torvalds nfs_writedata_free(wdata); 1111da177e4SLinus Torvalds } 1121da177e4SLinus Torvalds 113277459d2STrond Myklebust static struct nfs_page *nfs_page_find_request_locked(struct page *page) 114277459d2STrond Myklebust { 115277459d2STrond Myklebust struct nfs_page *req = NULL; 116277459d2STrond Myklebust 117277459d2STrond Myklebust if (PagePrivate(page)) { 118277459d2STrond Myklebust req = (struct nfs_page *)page_private(page); 119277459d2STrond Myklebust if (req != NULL) 120277459d2STrond Myklebust atomic_inc(&req->wb_count); 121277459d2STrond Myklebust } 122277459d2STrond Myklebust return req; 123277459d2STrond Myklebust } 124277459d2STrond Myklebust 125277459d2STrond Myklebust static struct nfs_page *nfs_page_find_request(struct page *page) 126277459d2STrond Myklebust { 127277459d2STrond Myklebust struct nfs_page *req = NULL; 128277459d2STrond Myklebust spinlock_t *req_lock = &NFS_I(page->mapping->host)->req_lock; 129277459d2STrond Myklebust 130277459d2STrond Myklebust spin_lock(req_lock); 131277459d2STrond Myklebust req = nfs_page_find_request_locked(page); 132277459d2STrond Myklebust spin_unlock(req_lock); 133277459d2STrond Myklebust return req; 134277459d2STrond Myklebust } 135277459d2STrond Myklebust 1361da177e4SLinus Torvalds /* Adjust the file length if we're writing beyond the end */ 1371da177e4SLinus Torvalds static void nfs_grow_file(struct page *page, unsigned int offset, unsigned int count) 1381da177e4SLinus Torvalds { 1391da177e4SLinus Torvalds struct inode *inode = page->mapping->host; 1401da177e4SLinus Torvalds loff_t end, i_size = i_size_read(inode); 141ca52fec1STrond Myklebust pgoff_t end_index = (i_size - 1) >> PAGE_CACHE_SHIFT; 1421da177e4SLinus Torvalds 1431da177e4SLinus Torvalds if (i_size > 0 && page->index < end_index) 1441da177e4SLinus Torvalds return; 1451da177e4SLinus Torvalds end = ((loff_t)page->index << PAGE_CACHE_SHIFT) + ((loff_t)offset+count); 1461da177e4SLinus Torvalds if (i_size >= end) 1471da177e4SLinus Torvalds return; 14891d5b470SChuck Lever nfs_inc_stats(inode, NFSIOS_EXTENDWRITE); 1491da177e4SLinus Torvalds i_size_write(inode, end); 1501da177e4SLinus Torvalds } 1511da177e4SLinus Torvalds 152a301b777STrond Myklebust /* A writeback failed: mark the page as bad, and invalidate the page cache */ 153a301b777STrond Myklebust static void nfs_set_pageerror(struct page *page) 154a301b777STrond Myklebust { 155a301b777STrond Myklebust SetPageError(page); 156a301b777STrond Myklebust nfs_zap_mapping(page->mapping->host, page->mapping); 157a301b777STrond Myklebust } 158a301b777STrond Myklebust 1591da177e4SLinus Torvalds /* We can set the PG_uptodate flag if we see that a write request 1601da177e4SLinus Torvalds * covers the full page. 1611da177e4SLinus Torvalds */ 1621da177e4SLinus Torvalds static void nfs_mark_uptodate(struct page *page, unsigned int base, unsigned int count) 1631da177e4SLinus Torvalds { 1641da177e4SLinus Torvalds if (PageUptodate(page)) 1651da177e4SLinus Torvalds return; 1661da177e4SLinus Torvalds if (base != 0) 1671da177e4SLinus Torvalds return; 16849a70f27STrond Myklebust if (count != nfs_page_length(page)) 1691da177e4SLinus Torvalds return; 17049a70f27STrond Myklebust if (count != PAGE_CACHE_SIZE) 17160945cb7SNate Diller zero_user_page(page, count, PAGE_CACHE_SIZE - count, KM_USER0); 1721da177e4SLinus Torvalds SetPageUptodate(page); 1731da177e4SLinus Torvalds } 1741da177e4SLinus Torvalds 175e21195a7STrond Myklebust static int nfs_writepage_setup(struct nfs_open_context *ctx, struct page *page, 1761da177e4SLinus Torvalds unsigned int offset, unsigned int count) 1771da177e4SLinus Torvalds { 1781da177e4SLinus Torvalds struct nfs_page *req; 179e21195a7STrond Myklebust int ret; 1801da177e4SLinus Torvalds 181e21195a7STrond Myklebust for (;;) { 182e21195a7STrond Myklebust req = nfs_update_request(ctx, page, offset, count); 183e21195a7STrond Myklebust if (!IS_ERR(req)) 184e21195a7STrond Myklebust break; 185e21195a7STrond Myklebust ret = PTR_ERR(req); 186e21195a7STrond Myklebust if (ret != -EBUSY) 187e21195a7STrond Myklebust return ret; 188e21195a7STrond Myklebust ret = nfs_wb_page(page->mapping->host, page); 189e21195a7STrond Myklebust if (ret != 0) 190e21195a7STrond Myklebust return ret; 191e21195a7STrond Myklebust } 1921da177e4SLinus Torvalds /* Update file length */ 1931da177e4SLinus Torvalds nfs_grow_file(page, offset, count); 1941da177e4SLinus Torvalds /* Set the PG_uptodate flag? */ 1951da177e4SLinus Torvalds nfs_mark_uptodate(page, offset, count); 1961da177e4SLinus Torvalds nfs_unlock_request(req); 197abd3e641STrond Myklebust return 0; 1981da177e4SLinus Torvalds } 1991da177e4SLinus Torvalds 2001da177e4SLinus Torvalds static int wb_priority(struct writeback_control *wbc) 2011da177e4SLinus Torvalds { 2021da177e4SLinus Torvalds if (wbc->for_reclaim) 203c63c7b05STrond Myklebust return FLUSH_HIGHPRI | FLUSH_STABLE; 2041da177e4SLinus Torvalds if (wbc->for_kupdate) 2051da177e4SLinus Torvalds return FLUSH_LOWPRI; 2061da177e4SLinus Torvalds return 0; 2071da177e4SLinus Torvalds } 2081da177e4SLinus Torvalds 2091da177e4SLinus Torvalds /* 21089a09141SPeter Zijlstra * NFS congestion control 21189a09141SPeter Zijlstra */ 21289a09141SPeter Zijlstra 21389a09141SPeter Zijlstra int nfs_congestion_kb; 21489a09141SPeter Zijlstra 21589a09141SPeter Zijlstra #define NFS_CONGESTION_ON_THRESH (nfs_congestion_kb >> (PAGE_SHIFT-10)) 21689a09141SPeter Zijlstra #define NFS_CONGESTION_OFF_THRESH \ 21789a09141SPeter Zijlstra (NFS_CONGESTION_ON_THRESH - (NFS_CONGESTION_ON_THRESH >> 2)) 21889a09141SPeter Zijlstra 2195a6d41b3STrond Myklebust static int nfs_set_page_writeback(struct page *page) 22089a09141SPeter Zijlstra { 2215a6d41b3STrond Myklebust int ret = test_set_page_writeback(page); 2225a6d41b3STrond Myklebust 2235a6d41b3STrond Myklebust if (!ret) { 22489a09141SPeter Zijlstra struct inode *inode = page->mapping->host; 22589a09141SPeter Zijlstra struct nfs_server *nfss = NFS_SERVER(inode); 22689a09141SPeter Zijlstra 227277866a0SPeter Zijlstra if (atomic_long_inc_return(&nfss->writeback) > 22889a09141SPeter Zijlstra NFS_CONGESTION_ON_THRESH) 22989a09141SPeter Zijlstra set_bdi_congested(&nfss->backing_dev_info, WRITE); 23089a09141SPeter Zijlstra } 2315a6d41b3STrond Myklebust return ret; 23289a09141SPeter Zijlstra } 23389a09141SPeter Zijlstra 23489a09141SPeter Zijlstra static void nfs_end_page_writeback(struct page *page) 23589a09141SPeter Zijlstra { 23689a09141SPeter Zijlstra struct inode *inode = page->mapping->host; 23789a09141SPeter Zijlstra struct nfs_server *nfss = NFS_SERVER(inode); 23889a09141SPeter Zijlstra 23989a09141SPeter Zijlstra end_page_writeback(page); 240277866a0SPeter Zijlstra if (atomic_long_dec_return(&nfss->writeback) < NFS_CONGESTION_OFF_THRESH) { 24189a09141SPeter Zijlstra clear_bdi_congested(&nfss->backing_dev_info, WRITE); 24289a09141SPeter Zijlstra congestion_end(WRITE); 24389a09141SPeter Zijlstra } 24489a09141SPeter Zijlstra } 24589a09141SPeter Zijlstra 24689a09141SPeter Zijlstra /* 247e261f51fSTrond Myklebust * Find an associated nfs write request, and prepare to flush it out 248e261f51fSTrond Myklebust * Returns 1 if there was no write request, or if the request was 249e261f51fSTrond Myklebust * already tagged by nfs_set_page_dirty.Returns 0 if the request 250e261f51fSTrond Myklebust * was not tagged. 251e261f51fSTrond Myklebust * May also return an error if the user signalled nfs_wait_on_request(). 252e261f51fSTrond Myklebust */ 253c63c7b05STrond Myklebust static int nfs_page_async_flush(struct nfs_pageio_descriptor *pgio, 254c63c7b05STrond Myklebust struct page *page) 255e261f51fSTrond Myklebust { 256e261f51fSTrond Myklebust struct nfs_page *req; 257612c9384STrond Myklebust struct nfs_inode *nfsi = NFS_I(page->mapping->host); 258612c9384STrond Myklebust spinlock_t *req_lock = &nfsi->req_lock; 259e261f51fSTrond Myklebust int ret; 260e261f51fSTrond Myklebust 261e261f51fSTrond Myklebust spin_lock(req_lock); 262e261f51fSTrond Myklebust for(;;) { 263e261f51fSTrond Myklebust req = nfs_page_find_request_locked(page); 264e261f51fSTrond Myklebust if (req == NULL) { 265e261f51fSTrond Myklebust spin_unlock(req_lock); 266e261f51fSTrond Myklebust return 1; 267e261f51fSTrond Myklebust } 268e261f51fSTrond Myklebust if (nfs_lock_request_dontget(req)) 269e261f51fSTrond Myklebust break; 270e261f51fSTrond Myklebust /* Note: If we hold the page lock, as is the case in nfs_writepage, 271e261f51fSTrond Myklebust * then the call to nfs_lock_request_dontget() will always 272e261f51fSTrond Myklebust * succeed provided that someone hasn't already marked the 273e261f51fSTrond Myklebust * request as dirty (in which case we don't care). 274e261f51fSTrond Myklebust */ 275e261f51fSTrond Myklebust spin_unlock(req_lock); 276e261f51fSTrond Myklebust ret = nfs_wait_on_request(req); 277e261f51fSTrond Myklebust nfs_release_request(req); 278e261f51fSTrond Myklebust if (ret != 0) 279e261f51fSTrond Myklebust return ret; 280e261f51fSTrond Myklebust spin_lock(req_lock); 281e261f51fSTrond Myklebust } 282612c9384STrond Myklebust if (test_bit(PG_NEED_COMMIT, &req->wb_flags)) { 283612c9384STrond Myklebust /* This request is marked for commit */ 284e261f51fSTrond Myklebust spin_unlock(req_lock); 285612c9384STrond Myklebust nfs_unlock_request(req); 286c63c7b05STrond Myklebust nfs_pageio_complete(pgio); 287612c9384STrond Myklebust return 1; 288612c9384STrond Myklebust } 289c63c7b05STrond Myklebust if (nfs_set_page_writeback(page) != 0) { 290612c9384STrond Myklebust spin_unlock(req_lock); 291c63c7b05STrond Myklebust BUG(); 292c63c7b05STrond Myklebust } 293c63c7b05STrond Myklebust radix_tree_tag_set(&nfsi->nfs_page_tree, req->wb_index, 294c63c7b05STrond Myklebust NFS_PAGE_TAG_WRITEBACK); 295e261f51fSTrond Myklebust ret = test_bit(PG_NEED_FLUSH, &req->wb_flags); 296c63c7b05STrond Myklebust spin_unlock(req_lock); 297c63c7b05STrond Myklebust nfs_pageio_add_request(pgio, req); 298e261f51fSTrond Myklebust return ret; 299e261f51fSTrond Myklebust } 300e261f51fSTrond Myklebust 301e261f51fSTrond Myklebust /* 3021da177e4SLinus Torvalds * Write an mmapped page to the server. 3031da177e4SLinus Torvalds */ 3044d770ccfSTrond Myklebust static int nfs_writepage_locked(struct page *page, struct writeback_control *wbc) 3051da177e4SLinus Torvalds { 306c63c7b05STrond Myklebust struct nfs_pageio_descriptor mypgio, *pgio; 3071da177e4SLinus Torvalds struct nfs_open_context *ctx; 3081da177e4SLinus Torvalds struct inode *inode = page->mapping->host; 30949a70f27STrond Myklebust unsigned offset; 310e261f51fSTrond Myklebust int err; 3111da177e4SLinus Torvalds 31291d5b470SChuck Lever nfs_inc_stats(inode, NFSIOS_VFSWRITEPAGE); 31391d5b470SChuck Lever nfs_add_stats(inode, NFSIOS_WRITEPAGES, 1); 31491d5b470SChuck Lever 315c63c7b05STrond Myklebust if (wbc->for_writepages) 316c63c7b05STrond Myklebust pgio = wbc->fs_private; 317c63c7b05STrond Myklebust else { 318c63c7b05STrond Myklebust nfs_pageio_init_write(&mypgio, inode, wb_priority(wbc)); 319c63c7b05STrond Myklebust pgio = &mypgio; 320c63c7b05STrond Myklebust } 321c63c7b05STrond Myklebust 322*7fe7f848STrond Myklebust nfs_pageio_cond_complete(pgio, page->index); 323*7fe7f848STrond Myklebust 324c63c7b05STrond Myklebust err = nfs_page_async_flush(pgio, page); 325e261f51fSTrond Myklebust if (err <= 0) 3261a54533eSTrond Myklebust goto out; 327e261f51fSTrond Myklebust err = 0; 32849a70f27STrond Myklebust offset = nfs_page_length(page); 32949a70f27STrond Myklebust if (!offset) 3301da177e4SLinus Torvalds goto out; 33149a70f27STrond Myklebust 332*7fe7f848STrond Myklebust nfs_pageio_cond_complete(pgio, page->index); 333*7fe7f848STrond Myklebust 334d530838bSTrond Myklebust ctx = nfs_find_open_context(inode, NULL, FMODE_WRITE); 3351da177e4SLinus Torvalds if (ctx == NULL) { 3361da177e4SLinus Torvalds err = -EBADF; 3371da177e4SLinus Torvalds goto out; 3381da177e4SLinus Torvalds } 339e21195a7STrond Myklebust err = nfs_writepage_setup(ctx, page, 0, offset); 340200baa21STrond Myklebust put_nfs_open_context(ctx); 341e261f51fSTrond Myklebust if (err != 0) 342e261f51fSTrond Myklebust goto out; 343c63c7b05STrond Myklebust err = nfs_page_async_flush(pgio, page); 344e261f51fSTrond Myklebust if (err > 0) 345e261f51fSTrond Myklebust err = 0; 346200baa21STrond Myklebust out: 347abd3e641STrond Myklebust if (!wbc->for_writepages) 348c63c7b05STrond Myklebust nfs_pageio_complete(pgio); 3494d770ccfSTrond Myklebust return err; 3504d770ccfSTrond Myklebust } 3514d770ccfSTrond Myklebust 3524d770ccfSTrond Myklebust int nfs_writepage(struct page *page, struct writeback_control *wbc) 3534d770ccfSTrond Myklebust { 3544d770ccfSTrond Myklebust int err; 3554d770ccfSTrond Myklebust 3564d770ccfSTrond Myklebust err = nfs_writepage_locked(page, wbc); 3571da177e4SLinus Torvalds unlock_page(page); 3581da177e4SLinus Torvalds return err; 3591da177e4SLinus Torvalds } 3601da177e4SLinus Torvalds 3611da177e4SLinus Torvalds int nfs_writepages(struct address_space *mapping, struct writeback_control *wbc) 3621da177e4SLinus Torvalds { 3631da177e4SLinus Torvalds struct inode *inode = mapping->host; 364c63c7b05STrond Myklebust struct nfs_pageio_descriptor pgio; 3651da177e4SLinus Torvalds int err; 3661da177e4SLinus Torvalds 36791d5b470SChuck Lever nfs_inc_stats(inode, NFSIOS_VFSWRITEPAGES); 36891d5b470SChuck Lever 369c63c7b05STrond Myklebust nfs_pageio_init_write(&pgio, inode, wb_priority(wbc)); 370c63c7b05STrond Myklebust wbc->fs_private = &pgio; 3711da177e4SLinus Torvalds err = generic_writepages(mapping, wbc); 372c63c7b05STrond Myklebust nfs_pageio_complete(&pgio); 3731da177e4SLinus Torvalds if (err) 3741da177e4SLinus Torvalds return err; 375c63c7b05STrond Myklebust if (pgio.pg_error) 376c63c7b05STrond Myklebust return pgio.pg_error; 377c63c7b05STrond Myklebust return 0; 3781da177e4SLinus Torvalds } 3791da177e4SLinus Torvalds 3801da177e4SLinus Torvalds /* 3811da177e4SLinus Torvalds * Insert a write request into an inode 3821da177e4SLinus Torvalds */ 3831da177e4SLinus Torvalds static int nfs_inode_add_request(struct inode *inode, struct nfs_page *req) 3841da177e4SLinus Torvalds { 3851da177e4SLinus Torvalds struct nfs_inode *nfsi = NFS_I(inode); 3861da177e4SLinus Torvalds int error; 3871da177e4SLinus Torvalds 3881da177e4SLinus Torvalds error = radix_tree_insert(&nfsi->nfs_page_tree, req->wb_index, req); 3891da177e4SLinus Torvalds BUG_ON(error == -EEXIST); 3901da177e4SLinus Torvalds if (error) 3911da177e4SLinus Torvalds return error; 3921da177e4SLinus Torvalds if (!nfsi->npages) { 3931da177e4SLinus Torvalds igrab(inode); 3941da177e4SLinus Torvalds nfs_begin_data_update(inode); 3951da177e4SLinus Torvalds if (nfs_have_delegation(inode, FMODE_WRITE)) 3961da177e4SLinus Torvalds nfsi->change_attr++; 3971da177e4SLinus Torvalds } 398deb7d638STrond Myklebust SetPagePrivate(req->wb_page); 399277459d2STrond Myklebust set_page_private(req->wb_page, (unsigned long)req); 4002b82f190STrond Myklebust if (PageDirty(req->wb_page)) 4012b82f190STrond Myklebust set_bit(PG_NEED_FLUSH, &req->wb_flags); 4021da177e4SLinus Torvalds nfsi->npages++; 4031da177e4SLinus Torvalds atomic_inc(&req->wb_count); 4041da177e4SLinus Torvalds return 0; 4051da177e4SLinus Torvalds } 4061da177e4SLinus Torvalds 4071da177e4SLinus Torvalds /* 40889a09141SPeter Zijlstra * Remove a write request from an inode 4091da177e4SLinus Torvalds */ 4101da177e4SLinus Torvalds static void nfs_inode_remove_request(struct nfs_page *req) 4111da177e4SLinus Torvalds { 4121da177e4SLinus Torvalds struct inode *inode = req->wb_context->dentry->d_inode; 4131da177e4SLinus Torvalds struct nfs_inode *nfsi = NFS_I(inode); 4141da177e4SLinus Torvalds 4151da177e4SLinus Torvalds BUG_ON (!NFS_WBACK_BUSY(req)); 4161da177e4SLinus Torvalds 4171da177e4SLinus Torvalds spin_lock(&nfsi->req_lock); 418277459d2STrond Myklebust set_page_private(req->wb_page, 0); 419deb7d638STrond Myklebust ClearPagePrivate(req->wb_page); 4201da177e4SLinus Torvalds radix_tree_delete(&nfsi->nfs_page_tree, req->wb_index); 4212b82f190STrond Myklebust if (test_and_clear_bit(PG_NEED_FLUSH, &req->wb_flags)) 4222b82f190STrond Myklebust __set_page_dirty_nobuffers(req->wb_page); 4231da177e4SLinus Torvalds nfsi->npages--; 4241da177e4SLinus Torvalds if (!nfsi->npages) { 4251da177e4SLinus Torvalds spin_unlock(&nfsi->req_lock); 426951a143bSTrond Myklebust nfs_end_data_update(inode); 4271da177e4SLinus Torvalds iput(inode); 4281da177e4SLinus Torvalds } else 4291da177e4SLinus Torvalds spin_unlock(&nfsi->req_lock); 4301da177e4SLinus Torvalds nfs_clear_request(req); 4311da177e4SLinus Torvalds nfs_release_request(req); 4321da177e4SLinus Torvalds } 4331da177e4SLinus Torvalds 43461822ab5STrond Myklebust static void 43561822ab5STrond Myklebust nfs_redirty_request(struct nfs_page *req) 43661822ab5STrond Myklebust { 43761822ab5STrond Myklebust __set_page_dirty_nobuffers(req->wb_page); 43861822ab5STrond Myklebust } 43961822ab5STrond Myklebust 4401da177e4SLinus Torvalds /* 4411da177e4SLinus Torvalds * Check if a request is dirty 4421da177e4SLinus Torvalds */ 4431da177e4SLinus Torvalds static inline int 4441da177e4SLinus Torvalds nfs_dirty_request(struct nfs_page *req) 4451da177e4SLinus Torvalds { 4465a6d41b3STrond Myklebust struct page *page = req->wb_page; 4475a6d41b3STrond Myklebust 448612c9384STrond Myklebust if (page == NULL || test_bit(PG_NEED_COMMIT, &req->wb_flags)) 4495a6d41b3STrond Myklebust return 0; 4505a6d41b3STrond Myklebust return !PageWriteback(req->wb_page); 4511da177e4SLinus Torvalds } 4521da177e4SLinus Torvalds 4531da177e4SLinus Torvalds #if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4) 4541da177e4SLinus Torvalds /* 4551da177e4SLinus Torvalds * Add a request to the inode's commit list. 4561da177e4SLinus Torvalds */ 4571da177e4SLinus Torvalds static void 4581da177e4SLinus Torvalds nfs_mark_request_commit(struct nfs_page *req) 4591da177e4SLinus Torvalds { 4601da177e4SLinus Torvalds struct inode *inode = req->wb_context->dentry->d_inode; 4611da177e4SLinus Torvalds struct nfs_inode *nfsi = NFS_I(inode); 4621da177e4SLinus Torvalds 4631da177e4SLinus Torvalds spin_lock(&nfsi->req_lock); 4641da177e4SLinus Torvalds nfs_list_add_request(req, &nfsi->commit); 4651da177e4SLinus Torvalds nfsi->ncommit++; 466612c9384STrond Myklebust set_bit(PG_NEED_COMMIT, &(req)->wb_flags); 4671da177e4SLinus Torvalds spin_unlock(&nfsi->req_lock); 468fd39fc85SChristoph Lameter inc_zone_page_state(req->wb_page, NR_UNSTABLE_NFS); 469a1803044STrond Myklebust __mark_inode_dirty(inode, I_DIRTY_DATASYNC); 4701da177e4SLinus Torvalds } 4718e821cadSTrond Myklebust 4728e821cadSTrond Myklebust static inline 4738e821cadSTrond Myklebust int nfs_write_need_commit(struct nfs_write_data *data) 4748e821cadSTrond Myklebust { 4758e821cadSTrond Myklebust return data->verf.committed != NFS_FILE_SYNC; 4768e821cadSTrond Myklebust } 4778e821cadSTrond Myklebust 4788e821cadSTrond Myklebust static inline 4798e821cadSTrond Myklebust int nfs_reschedule_unstable_write(struct nfs_page *req) 4808e821cadSTrond Myklebust { 481612c9384STrond Myklebust if (test_bit(PG_NEED_COMMIT, &req->wb_flags)) { 4828e821cadSTrond Myklebust nfs_mark_request_commit(req); 4838e821cadSTrond Myklebust return 1; 4848e821cadSTrond Myklebust } 4858e821cadSTrond Myklebust if (test_and_clear_bit(PG_NEED_RESCHED, &req->wb_flags)) { 4868e821cadSTrond Myklebust nfs_redirty_request(req); 4878e821cadSTrond Myklebust return 1; 4888e821cadSTrond Myklebust } 4898e821cadSTrond Myklebust return 0; 4908e821cadSTrond Myklebust } 4918e821cadSTrond Myklebust #else 4928e821cadSTrond Myklebust static inline void 4938e821cadSTrond Myklebust nfs_mark_request_commit(struct nfs_page *req) 4948e821cadSTrond Myklebust { 4958e821cadSTrond Myklebust } 4968e821cadSTrond Myklebust 4978e821cadSTrond Myklebust static inline 4988e821cadSTrond Myklebust int nfs_write_need_commit(struct nfs_write_data *data) 4998e821cadSTrond Myklebust { 5008e821cadSTrond Myklebust return 0; 5018e821cadSTrond Myklebust } 5028e821cadSTrond Myklebust 5038e821cadSTrond Myklebust static inline 5048e821cadSTrond Myklebust int nfs_reschedule_unstable_write(struct nfs_page *req) 5058e821cadSTrond Myklebust { 5068e821cadSTrond Myklebust return 0; 5078e821cadSTrond Myklebust } 5081da177e4SLinus Torvalds #endif 5091da177e4SLinus Torvalds 5101da177e4SLinus Torvalds /* 5111da177e4SLinus Torvalds * Wait for a request to complete. 5121da177e4SLinus Torvalds * 5131da177e4SLinus Torvalds * Interruptible by signals only if mounted with intr flag. 5141da177e4SLinus Torvalds */ 515ca52fec1STrond Myklebust static int nfs_wait_on_requests_locked(struct inode *inode, pgoff_t idx_start, unsigned int npages) 5161da177e4SLinus Torvalds { 5171da177e4SLinus Torvalds struct nfs_inode *nfsi = NFS_I(inode); 5181da177e4SLinus Torvalds struct nfs_page *req; 519ca52fec1STrond Myklebust pgoff_t idx_end, next; 5201da177e4SLinus Torvalds unsigned int res = 0; 5211da177e4SLinus Torvalds int error; 5221da177e4SLinus Torvalds 5231da177e4SLinus Torvalds if (npages == 0) 5241da177e4SLinus Torvalds idx_end = ~0; 5251da177e4SLinus Torvalds else 5261da177e4SLinus Torvalds idx_end = idx_start + npages - 1; 5271da177e4SLinus Torvalds 5281da177e4SLinus Torvalds next = idx_start; 529c6a556b8STrond Myklebust while (radix_tree_gang_lookup_tag(&nfsi->nfs_page_tree, (void **)&req, next, 1, NFS_PAGE_TAG_WRITEBACK)) { 5301da177e4SLinus Torvalds if (req->wb_index > idx_end) 5311da177e4SLinus Torvalds break; 5321da177e4SLinus Torvalds 5331da177e4SLinus Torvalds next = req->wb_index + 1; 534c6a556b8STrond Myklebust BUG_ON(!NFS_WBACK_BUSY(req)); 5351da177e4SLinus Torvalds 5361da177e4SLinus Torvalds atomic_inc(&req->wb_count); 5371da177e4SLinus Torvalds spin_unlock(&nfsi->req_lock); 5381da177e4SLinus Torvalds error = nfs_wait_on_request(req); 5391da177e4SLinus Torvalds nfs_release_request(req); 540c42de9ddSTrond Myklebust spin_lock(&nfsi->req_lock); 5411da177e4SLinus Torvalds if (error < 0) 5421da177e4SLinus Torvalds return error; 5431da177e4SLinus Torvalds res++; 5441da177e4SLinus Torvalds } 5451da177e4SLinus Torvalds return res; 5461da177e4SLinus Torvalds } 5471da177e4SLinus Torvalds 54883715ad5STrond Myklebust static void nfs_cancel_commit_list(struct list_head *head) 54983715ad5STrond Myklebust { 55083715ad5STrond Myklebust struct nfs_page *req; 55183715ad5STrond Myklebust 55283715ad5STrond Myklebust while(!list_empty(head)) { 55383715ad5STrond Myklebust req = nfs_list_entry(head->next); 554b6dff26aSTrond Myklebust dec_zone_page_state(req->wb_page, NR_UNSTABLE_NFS); 55583715ad5STrond Myklebust nfs_list_remove_request(req); 556612c9384STrond Myklebust clear_bit(PG_NEED_COMMIT, &(req)->wb_flags); 55783715ad5STrond Myklebust nfs_inode_remove_request(req); 558b6dff26aSTrond Myklebust nfs_unlock_request(req); 55983715ad5STrond Myklebust } 56083715ad5STrond Myklebust } 56183715ad5STrond Myklebust 5621da177e4SLinus Torvalds #if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4) 5631da177e4SLinus Torvalds /* 5641da177e4SLinus Torvalds * nfs_scan_commit - Scan an inode for commit requests 5651da177e4SLinus Torvalds * @inode: NFS inode to scan 5661da177e4SLinus Torvalds * @dst: destination list 5671da177e4SLinus Torvalds * @idx_start: lower bound of page->index to scan. 5681da177e4SLinus Torvalds * @npages: idx_start + npages sets the upper bound to scan. 5691da177e4SLinus Torvalds * 5701da177e4SLinus Torvalds * Moves requests from the inode's 'commit' request list. 5711da177e4SLinus Torvalds * The requests are *not* checked to ensure that they form a contiguous set. 5721da177e4SLinus Torvalds */ 5731da177e4SLinus Torvalds static int 574ca52fec1STrond Myklebust nfs_scan_commit(struct inode *inode, struct list_head *dst, pgoff_t idx_start, unsigned int npages) 5751da177e4SLinus Torvalds { 5761da177e4SLinus Torvalds struct nfs_inode *nfsi = NFS_I(inode); 5773da28eb1STrond Myklebust int res = 0; 5783da28eb1STrond Myklebust 5793da28eb1STrond Myklebust if (nfsi->ncommit != 0) { 580d2ccddf0STrond Myklebust res = nfs_scan_list(nfsi, &nfsi->commit, dst, idx_start, npages); 5811da177e4SLinus Torvalds nfsi->ncommit -= res; 5821da177e4SLinus Torvalds if ((nfsi->ncommit == 0) != list_empty(&nfsi->commit)) 5831da177e4SLinus Torvalds printk(KERN_ERR "NFS: desynchronized value of nfs_i.ncommit.\n"); 5843da28eb1STrond Myklebust } 5851da177e4SLinus Torvalds return res; 5861da177e4SLinus Torvalds } 587c42de9ddSTrond Myklebust #else 588ca52fec1STrond Myklebust static inline int nfs_scan_commit(struct inode *inode, struct list_head *dst, pgoff_t idx_start, unsigned int npages) 589c42de9ddSTrond Myklebust { 590c42de9ddSTrond Myklebust return 0; 591c42de9ddSTrond Myklebust } 5921da177e4SLinus Torvalds #endif 5931da177e4SLinus Torvalds 5941da177e4SLinus Torvalds /* 5951da177e4SLinus Torvalds * Try to update any existing write request, or create one if there is none. 5961da177e4SLinus Torvalds * In order to match, the request's credentials must match those of 5971da177e4SLinus Torvalds * the calling process. 5981da177e4SLinus Torvalds * 5991da177e4SLinus Torvalds * Note: Should always be called with the Page Lock held! 6001da177e4SLinus Torvalds */ 6011da177e4SLinus Torvalds static struct nfs_page * nfs_update_request(struct nfs_open_context* ctx, 602e21195a7STrond Myklebust struct page *page, unsigned int offset, unsigned int bytes) 6031da177e4SLinus Torvalds { 60489a09141SPeter Zijlstra struct address_space *mapping = page->mapping; 60589a09141SPeter Zijlstra struct inode *inode = mapping->host; 6061da177e4SLinus Torvalds struct nfs_inode *nfsi = NFS_I(inode); 6071da177e4SLinus Torvalds struct nfs_page *req, *new = NULL; 608ca52fec1STrond Myklebust pgoff_t rqend, end; 6091da177e4SLinus Torvalds 6101da177e4SLinus Torvalds end = offset + bytes; 6111da177e4SLinus Torvalds 6121da177e4SLinus Torvalds for (;;) { 6131da177e4SLinus Torvalds /* Loop over all inode entries and see if we find 6141da177e4SLinus Torvalds * A request for the page we wish to update 6151da177e4SLinus Torvalds */ 6161da177e4SLinus Torvalds spin_lock(&nfsi->req_lock); 617277459d2STrond Myklebust req = nfs_page_find_request_locked(page); 6181da177e4SLinus Torvalds if (req) { 6191da177e4SLinus Torvalds if (!nfs_lock_request_dontget(req)) { 6201da177e4SLinus Torvalds int error; 621277459d2STrond Myklebust 6221da177e4SLinus Torvalds spin_unlock(&nfsi->req_lock); 6231da177e4SLinus Torvalds error = nfs_wait_on_request(req); 6241da177e4SLinus Torvalds nfs_release_request(req); 6251dd594b2SNeil Brown if (error < 0) { 6261dd594b2SNeil Brown if (new) 6271dd594b2SNeil Brown nfs_release_request(new); 6281da177e4SLinus Torvalds return ERR_PTR(error); 6291dd594b2SNeil Brown } 6301da177e4SLinus Torvalds continue; 6311da177e4SLinus Torvalds } 6321da177e4SLinus Torvalds spin_unlock(&nfsi->req_lock); 6331da177e4SLinus Torvalds if (new) 6341da177e4SLinus Torvalds nfs_release_request(new); 6351da177e4SLinus Torvalds break; 6361da177e4SLinus Torvalds } 6371da177e4SLinus Torvalds 6381da177e4SLinus Torvalds if (new) { 6391da177e4SLinus Torvalds int error; 6401da177e4SLinus Torvalds nfs_lock_request_dontget(new); 6411da177e4SLinus Torvalds error = nfs_inode_add_request(inode, new); 6421da177e4SLinus Torvalds if (error) { 6431da177e4SLinus Torvalds spin_unlock(&nfsi->req_lock); 6441da177e4SLinus Torvalds nfs_unlock_request(new); 6451da177e4SLinus Torvalds return ERR_PTR(error); 6461da177e4SLinus Torvalds } 6471da177e4SLinus Torvalds spin_unlock(&nfsi->req_lock); 6481da177e4SLinus Torvalds return new; 6491da177e4SLinus Torvalds } 6501da177e4SLinus Torvalds spin_unlock(&nfsi->req_lock); 6511da177e4SLinus Torvalds 6521da177e4SLinus Torvalds new = nfs_create_request(ctx, inode, page, offset, bytes); 6531da177e4SLinus Torvalds if (IS_ERR(new)) 6541da177e4SLinus Torvalds return new; 6551da177e4SLinus Torvalds } 6561da177e4SLinus Torvalds 6571da177e4SLinus Torvalds /* We have a request for our page. 6581da177e4SLinus Torvalds * If the creds don't match, or the 6591da177e4SLinus Torvalds * page addresses don't match, 6601da177e4SLinus Torvalds * tell the caller to wait on the conflicting 6611da177e4SLinus Torvalds * request. 6621da177e4SLinus Torvalds */ 6631da177e4SLinus Torvalds rqend = req->wb_offset + req->wb_bytes; 6641da177e4SLinus Torvalds if (req->wb_context != ctx 6651da177e4SLinus Torvalds || req->wb_page != page 6661da177e4SLinus Torvalds || !nfs_dirty_request(req) 6671da177e4SLinus Torvalds || offset > rqend || end < req->wb_offset) { 6681da177e4SLinus Torvalds nfs_unlock_request(req); 6691da177e4SLinus Torvalds return ERR_PTR(-EBUSY); 6701da177e4SLinus Torvalds } 6711da177e4SLinus Torvalds 6721da177e4SLinus Torvalds /* Okay, the request matches. Update the region */ 6731da177e4SLinus Torvalds if (offset < req->wb_offset) { 6741da177e4SLinus Torvalds req->wb_offset = offset; 6751da177e4SLinus Torvalds req->wb_pgbase = offset; 6761da177e4SLinus Torvalds req->wb_bytes = rqend - req->wb_offset; 6771da177e4SLinus Torvalds } 6781da177e4SLinus Torvalds 6791da177e4SLinus Torvalds if (end > rqend) 6801da177e4SLinus Torvalds req->wb_bytes = end - req->wb_offset; 6811da177e4SLinus Torvalds 6821da177e4SLinus Torvalds return req; 6831da177e4SLinus Torvalds } 6841da177e4SLinus Torvalds 6851da177e4SLinus Torvalds int nfs_flush_incompatible(struct file *file, struct page *page) 6861da177e4SLinus Torvalds { 6871da177e4SLinus Torvalds struct nfs_open_context *ctx = (struct nfs_open_context *)file->private_data; 6881da177e4SLinus Torvalds struct nfs_page *req; 6891a54533eSTrond Myklebust int do_flush, status; 6901da177e4SLinus Torvalds /* 6911da177e4SLinus Torvalds * Look for a request corresponding to this page. If there 6921da177e4SLinus Torvalds * is one, and it belongs to another file, we flush it out 6931da177e4SLinus Torvalds * before we try to copy anything into the page. Do this 6941da177e4SLinus Torvalds * due to the lack of an ACCESS-type call in NFSv2. 6951da177e4SLinus Torvalds * Also do the same if we find a request from an existing 6961da177e4SLinus Torvalds * dropped page. 6971da177e4SLinus Torvalds */ 6981a54533eSTrond Myklebust do { 699277459d2STrond Myklebust req = nfs_page_find_request(page); 7001a54533eSTrond Myklebust if (req == NULL) 7011a54533eSTrond Myklebust return 0; 7021a54533eSTrond Myklebust do_flush = req->wb_page != page || req->wb_context != ctx 703e261f51fSTrond Myklebust || !nfs_dirty_request(req); 7041da177e4SLinus Torvalds nfs_release_request(req); 7051a54533eSTrond Myklebust if (!do_flush) 7061a54533eSTrond Myklebust return 0; 707277459d2STrond Myklebust status = nfs_wb_page(page->mapping->host, page); 7081a54533eSTrond Myklebust } while (status == 0); 7091a54533eSTrond Myklebust return status; 7101da177e4SLinus Torvalds } 7111da177e4SLinus Torvalds 7121da177e4SLinus Torvalds /* 7131da177e4SLinus Torvalds * Update and possibly write a cached page of an NFS file. 7141da177e4SLinus Torvalds * 7151da177e4SLinus Torvalds * XXX: Keep an eye on generic_file_read to make sure it doesn't do bad 7161da177e4SLinus Torvalds * things with a page scheduled for an RPC call (e.g. invalidate it). 7171da177e4SLinus Torvalds */ 7181da177e4SLinus Torvalds int nfs_updatepage(struct file *file, struct page *page, 7191da177e4SLinus Torvalds unsigned int offset, unsigned int count) 7201da177e4SLinus Torvalds { 7211da177e4SLinus Torvalds struct nfs_open_context *ctx = (struct nfs_open_context *)file->private_data; 7221da177e4SLinus Torvalds struct inode *inode = page->mapping->host; 7231da177e4SLinus Torvalds int status = 0; 7241da177e4SLinus Torvalds 72591d5b470SChuck Lever nfs_inc_stats(inode, NFSIOS_VFSUPDATEPAGE); 72691d5b470SChuck Lever 7271da177e4SLinus Torvalds dprintk("NFS: nfs_updatepage(%s/%s %d@%Ld)\n", 72801cce933SJosef "Jeff" Sipek file->f_path.dentry->d_parent->d_name.name, 72901cce933SJosef "Jeff" Sipek file->f_path.dentry->d_name.name, count, 7300bbacc40SChuck Lever (long long)(page_offset(page) +offset)); 7311da177e4SLinus Torvalds 7321da177e4SLinus Torvalds /* If we're not using byte range locks, and we know the page 7331da177e4SLinus Torvalds * is entirely in cache, it may be more efficient to avoid 7341da177e4SLinus Torvalds * fragmenting write requests. 7351da177e4SLinus Torvalds */ 736ab0a3dbeSTrond Myklebust if (PageUptodate(page) && inode->i_flock == NULL && !(file->f_mode & O_SYNC)) { 73749a70f27STrond Myklebust count = max(count + offset, nfs_page_length(page)); 7381da177e4SLinus Torvalds offset = 0; 7391da177e4SLinus Torvalds } 7401da177e4SLinus Torvalds 741e21195a7STrond Myklebust status = nfs_writepage_setup(ctx, page, offset, count); 742e261f51fSTrond Myklebust __set_page_dirty_nobuffers(page); 7431da177e4SLinus Torvalds 7441da177e4SLinus Torvalds dprintk("NFS: nfs_updatepage returns %d (isize %Ld)\n", 7451da177e4SLinus Torvalds status, (long long)i_size_read(inode)); 7461da177e4SLinus Torvalds if (status < 0) 747a301b777STrond Myklebust nfs_set_pageerror(page); 7481da177e4SLinus Torvalds return status; 7491da177e4SLinus Torvalds } 7501da177e4SLinus Torvalds 7511da177e4SLinus Torvalds static void nfs_writepage_release(struct nfs_page *req) 7521da177e4SLinus Torvalds { 7538e821cadSTrond Myklebust 7548e821cadSTrond Myklebust if (PageError(req->wb_page) || !nfs_reschedule_unstable_write(req)) { 75589a09141SPeter Zijlstra nfs_end_page_writeback(req->wb_page); 7561da177e4SLinus Torvalds nfs_inode_remove_request(req); 7578e821cadSTrond Myklebust } else 7588e821cadSTrond Myklebust nfs_end_page_writeback(req->wb_page); 759c6a556b8STrond Myklebust nfs_clear_page_writeback(req); 7601da177e4SLinus Torvalds } 7611da177e4SLinus Torvalds 7621da177e4SLinus Torvalds static inline int flush_task_priority(int how) 7631da177e4SLinus Torvalds { 7641da177e4SLinus Torvalds switch (how & (FLUSH_HIGHPRI|FLUSH_LOWPRI)) { 7651da177e4SLinus Torvalds case FLUSH_HIGHPRI: 7661da177e4SLinus Torvalds return RPC_PRIORITY_HIGH; 7671da177e4SLinus Torvalds case FLUSH_LOWPRI: 7681da177e4SLinus Torvalds return RPC_PRIORITY_LOW; 7691da177e4SLinus Torvalds } 7701da177e4SLinus Torvalds return RPC_PRIORITY_NORMAL; 7711da177e4SLinus Torvalds } 7721da177e4SLinus Torvalds 7731da177e4SLinus Torvalds /* 7741da177e4SLinus Torvalds * Set up the argument/result storage required for the RPC call. 7751da177e4SLinus Torvalds */ 7761da177e4SLinus Torvalds static void nfs_write_rpcsetup(struct nfs_page *req, 7771da177e4SLinus Torvalds struct nfs_write_data *data, 778788e7a89STrond Myklebust const struct rpc_call_ops *call_ops, 7791da177e4SLinus Torvalds unsigned int count, unsigned int offset, 7801da177e4SLinus Torvalds int how) 7811da177e4SLinus Torvalds { 7821da177e4SLinus Torvalds struct inode *inode; 783788e7a89STrond Myklebust int flags; 7841da177e4SLinus Torvalds 7851da177e4SLinus Torvalds /* Set up the RPC argument and reply structs 7861da177e4SLinus Torvalds * NB: take care not to mess about with data->commit et al. */ 7871da177e4SLinus Torvalds 7881da177e4SLinus Torvalds data->req = req; 7891da177e4SLinus Torvalds data->inode = inode = req->wb_context->dentry->d_inode; 7901da177e4SLinus Torvalds data->cred = req->wb_context->cred; 7911da177e4SLinus Torvalds 7921da177e4SLinus Torvalds data->args.fh = NFS_FH(inode); 7931da177e4SLinus Torvalds data->args.offset = req_offset(req) + offset; 7941da177e4SLinus Torvalds data->args.pgbase = req->wb_pgbase + offset; 7951da177e4SLinus Torvalds data->args.pages = data->pagevec; 7961da177e4SLinus Torvalds data->args.count = count; 7971da177e4SLinus Torvalds data->args.context = req->wb_context; 7981da177e4SLinus Torvalds 7991da177e4SLinus Torvalds data->res.fattr = &data->fattr; 8001da177e4SLinus Torvalds data->res.count = count; 8011da177e4SLinus Torvalds data->res.verf = &data->verf; 8020e574af1STrond Myklebust nfs_fattr_init(&data->fattr); 8031da177e4SLinus Torvalds 804788e7a89STrond Myklebust /* Set up the initial task struct. */ 805788e7a89STrond Myklebust flags = (how & FLUSH_SYNC) ? 0 : RPC_TASK_ASYNC; 806788e7a89STrond Myklebust rpc_init_task(&data->task, NFS_CLIENT(inode), flags, call_ops, data); 8071da177e4SLinus Torvalds NFS_PROTO(inode)->write_setup(data, how); 8081da177e4SLinus Torvalds 8091da177e4SLinus Torvalds data->task.tk_priority = flush_task_priority(how); 8101da177e4SLinus Torvalds data->task.tk_cookie = (unsigned long)inode; 8111da177e4SLinus Torvalds 812a3f565b1SChuck Lever dprintk("NFS: %5u initiated write call " 813a3f565b1SChuck Lever "(req %s/%Ld, %u bytes @ offset %Lu)\n", 8140bbacc40SChuck Lever data->task.tk_pid, 8151da177e4SLinus Torvalds inode->i_sb->s_id, 8161da177e4SLinus Torvalds (long long)NFS_FILEID(inode), 8171da177e4SLinus Torvalds count, 8181da177e4SLinus Torvalds (unsigned long long)data->args.offset); 8191da177e4SLinus Torvalds } 8201da177e4SLinus Torvalds 8211da177e4SLinus Torvalds static void nfs_execute_write(struct nfs_write_data *data) 8221da177e4SLinus Torvalds { 8231da177e4SLinus Torvalds struct rpc_clnt *clnt = NFS_CLIENT(data->inode); 8241da177e4SLinus Torvalds sigset_t oldset; 8251da177e4SLinus Torvalds 8261da177e4SLinus Torvalds rpc_clnt_sigmask(clnt, &oldset); 8271da177e4SLinus Torvalds rpc_execute(&data->task); 8281da177e4SLinus Torvalds rpc_clnt_sigunmask(clnt, &oldset); 8291da177e4SLinus Torvalds } 8301da177e4SLinus Torvalds 8311da177e4SLinus Torvalds /* 8321da177e4SLinus Torvalds * Generate multiple small requests to write out a single 8331da177e4SLinus Torvalds * contiguous dirty area on one page. 8341da177e4SLinus Torvalds */ 8358d5658c9STrond Myklebust static int nfs_flush_multi(struct inode *inode, struct list_head *head, unsigned int npages, size_t count, int how) 8361da177e4SLinus Torvalds { 8371da177e4SLinus Torvalds struct nfs_page *req = nfs_list_entry(head->next); 8381da177e4SLinus Torvalds struct page *page = req->wb_page; 8391da177e4SLinus Torvalds struct nfs_write_data *data; 840e9f7bee1STrond Myklebust size_t wsize = NFS_SERVER(inode)->wsize, nbytes; 841e9f7bee1STrond Myklebust unsigned int offset; 8421da177e4SLinus Torvalds int requests = 0; 8431da177e4SLinus Torvalds LIST_HEAD(list); 8441da177e4SLinus Torvalds 8451da177e4SLinus Torvalds nfs_list_remove_request(req); 8461da177e4SLinus Torvalds 847bcb71bbaSTrond Myklebust nbytes = count; 848e9f7bee1STrond Myklebust do { 849e9f7bee1STrond Myklebust size_t len = min(nbytes, wsize); 850e9f7bee1STrond Myklebust 8518d5658c9STrond Myklebust data = nfs_writedata_alloc(1); 8521da177e4SLinus Torvalds if (!data) 8531da177e4SLinus Torvalds goto out_bad; 8541da177e4SLinus Torvalds list_add(&data->pages, &list); 8551da177e4SLinus Torvalds requests++; 856e9f7bee1STrond Myklebust nbytes -= len; 857e9f7bee1STrond Myklebust } while (nbytes != 0); 8581da177e4SLinus Torvalds atomic_set(&req->wb_complete, requests); 8591da177e4SLinus Torvalds 8601da177e4SLinus Torvalds ClearPageError(page); 8611da177e4SLinus Torvalds offset = 0; 862bcb71bbaSTrond Myklebust nbytes = count; 8631da177e4SLinus Torvalds do { 8641da177e4SLinus Torvalds data = list_entry(list.next, struct nfs_write_data, pages); 8651da177e4SLinus Torvalds list_del_init(&data->pages); 8661da177e4SLinus Torvalds 8671da177e4SLinus Torvalds data->pagevec[0] = page; 8681da177e4SLinus Torvalds 869bcb71bbaSTrond Myklebust if (nbytes < wsize) 870bcb71bbaSTrond Myklebust wsize = nbytes; 871788e7a89STrond Myklebust nfs_write_rpcsetup(req, data, &nfs_write_partial_ops, 872788e7a89STrond Myklebust wsize, offset, how); 8731da177e4SLinus Torvalds offset += wsize; 8741da177e4SLinus Torvalds nbytes -= wsize; 8751da177e4SLinus Torvalds nfs_execute_write(data); 8761da177e4SLinus Torvalds } while (nbytes != 0); 8771da177e4SLinus Torvalds 8781da177e4SLinus Torvalds return 0; 8791da177e4SLinus Torvalds 8801da177e4SLinus Torvalds out_bad: 8811da177e4SLinus Torvalds while (!list_empty(&list)) { 8821da177e4SLinus Torvalds data = list_entry(list.next, struct nfs_write_data, pages); 8831da177e4SLinus Torvalds list_del(&data->pages); 8848aca67f0STrond Myklebust nfs_writedata_release(data); 8851da177e4SLinus Torvalds } 88661822ab5STrond Myklebust nfs_redirty_request(req); 8876d677e35STrond Myklebust nfs_end_page_writeback(req->wb_page); 888c6a556b8STrond Myklebust nfs_clear_page_writeback(req); 8891da177e4SLinus Torvalds return -ENOMEM; 8901da177e4SLinus Torvalds } 8911da177e4SLinus Torvalds 8921da177e4SLinus Torvalds /* 8931da177e4SLinus Torvalds * Create an RPC task for the given write request and kick it. 8941da177e4SLinus Torvalds * The page must have been locked by the caller. 8951da177e4SLinus Torvalds * 8961da177e4SLinus Torvalds * It may happen that the page we're passed is not marked dirty. 8971da177e4SLinus Torvalds * This is the case if nfs_updatepage detects a conflicting request 8981da177e4SLinus Torvalds * that has been written but not committed. 8991da177e4SLinus Torvalds */ 9008d5658c9STrond Myklebust static int nfs_flush_one(struct inode *inode, struct list_head *head, unsigned int npages, size_t count, int how) 9011da177e4SLinus Torvalds { 9021da177e4SLinus Torvalds struct nfs_page *req; 9031da177e4SLinus Torvalds struct page **pages; 9041da177e4SLinus Torvalds struct nfs_write_data *data; 9051da177e4SLinus Torvalds 9068d5658c9STrond Myklebust data = nfs_writedata_alloc(npages); 9071da177e4SLinus Torvalds if (!data) 9081da177e4SLinus Torvalds goto out_bad; 9091da177e4SLinus Torvalds 9101da177e4SLinus Torvalds pages = data->pagevec; 9111da177e4SLinus Torvalds while (!list_empty(head)) { 9121da177e4SLinus Torvalds req = nfs_list_entry(head->next); 9131da177e4SLinus Torvalds nfs_list_remove_request(req); 9141da177e4SLinus Torvalds nfs_list_add_request(req, &data->pages); 9151da177e4SLinus Torvalds ClearPageError(req->wb_page); 9161da177e4SLinus Torvalds *pages++ = req->wb_page; 9171da177e4SLinus Torvalds } 9181da177e4SLinus Torvalds req = nfs_list_entry(data->pages.next); 9191da177e4SLinus Torvalds 9201da177e4SLinus Torvalds /* Set up the argument struct */ 921788e7a89STrond Myklebust nfs_write_rpcsetup(req, data, &nfs_write_full_ops, count, 0, how); 9221da177e4SLinus Torvalds 9231da177e4SLinus Torvalds nfs_execute_write(data); 9241da177e4SLinus Torvalds return 0; 9251da177e4SLinus Torvalds out_bad: 9261da177e4SLinus Torvalds while (!list_empty(head)) { 92710afec90STrond Myklebust req = nfs_list_entry(head->next); 9281da177e4SLinus Torvalds nfs_list_remove_request(req); 92961822ab5STrond Myklebust nfs_redirty_request(req); 9306d677e35STrond Myklebust nfs_end_page_writeback(req->wb_page); 931c6a556b8STrond Myklebust nfs_clear_page_writeback(req); 9321da177e4SLinus Torvalds } 9331da177e4SLinus Torvalds return -ENOMEM; 9341da177e4SLinus Torvalds } 9351da177e4SLinus Torvalds 936c63c7b05STrond Myklebust static void nfs_pageio_init_write(struct nfs_pageio_descriptor *pgio, 937c63c7b05STrond Myklebust struct inode *inode, int ioflags) 9381da177e4SLinus Torvalds { 9397d46a49fSTrond Myklebust int wsize = NFS_SERVER(inode)->wsize; 9401da177e4SLinus Torvalds 941bcb71bbaSTrond Myklebust if (wsize < PAGE_CACHE_SIZE) 942c63c7b05STrond Myklebust nfs_pageio_init(pgio, inode, nfs_flush_multi, wsize, ioflags); 943bcb71bbaSTrond Myklebust else 944c63c7b05STrond Myklebust nfs_pageio_init(pgio, inode, nfs_flush_one, wsize, ioflags); 9451da177e4SLinus Torvalds } 9461da177e4SLinus Torvalds 9471da177e4SLinus Torvalds /* 9481da177e4SLinus Torvalds * Handle a write reply that flushed part of a page. 9491da177e4SLinus Torvalds */ 950788e7a89STrond Myklebust static void nfs_writeback_done_partial(struct rpc_task *task, void *calldata) 9511da177e4SLinus Torvalds { 952788e7a89STrond Myklebust struct nfs_write_data *data = calldata; 9531da177e4SLinus Torvalds struct nfs_page *req = data->req; 9541da177e4SLinus Torvalds struct page *page = req->wb_page; 9551da177e4SLinus Torvalds 9561da177e4SLinus Torvalds dprintk("NFS: write (%s/%Ld %d@%Ld)", 9571da177e4SLinus Torvalds req->wb_context->dentry->d_inode->i_sb->s_id, 9581da177e4SLinus Torvalds (long long)NFS_FILEID(req->wb_context->dentry->d_inode), 9591da177e4SLinus Torvalds req->wb_bytes, 9601da177e4SLinus Torvalds (long long)req_offset(req)); 9611da177e4SLinus Torvalds 962788e7a89STrond Myklebust if (nfs_writeback_done(task, data) != 0) 963788e7a89STrond Myklebust return; 964788e7a89STrond Myklebust 965788e7a89STrond Myklebust if (task->tk_status < 0) { 966a301b777STrond Myklebust nfs_set_pageerror(page); 967788e7a89STrond Myklebust req->wb_context->error = task->tk_status; 968788e7a89STrond Myklebust dprintk(", error = %d\n", task->tk_status); 9698e821cadSTrond Myklebust goto out; 9708e821cadSTrond Myklebust } 9718e821cadSTrond Myklebust 9728e821cadSTrond Myklebust if (nfs_write_need_commit(data)) { 9738e821cadSTrond Myklebust spinlock_t *req_lock = &NFS_I(page->mapping->host)->req_lock; 9748e821cadSTrond Myklebust 9758e821cadSTrond Myklebust spin_lock(req_lock); 9768e821cadSTrond Myklebust if (test_bit(PG_NEED_RESCHED, &req->wb_flags)) { 9778e821cadSTrond Myklebust /* Do nothing we need to resend the writes */ 9788e821cadSTrond Myklebust } else if (!test_and_set_bit(PG_NEED_COMMIT, &req->wb_flags)) { 9791da177e4SLinus Torvalds memcpy(&req->wb_verf, &data->verf, sizeof(req->wb_verf)); 9801da177e4SLinus Torvalds dprintk(" defer commit\n"); 9811da177e4SLinus Torvalds } else if (memcmp(&req->wb_verf, &data->verf, sizeof(req->wb_verf))) { 9828e821cadSTrond Myklebust set_bit(PG_NEED_RESCHED, &req->wb_flags); 9838e821cadSTrond Myklebust clear_bit(PG_NEED_COMMIT, &req->wb_flags); 9841da177e4SLinus Torvalds dprintk(" server reboot detected\n"); 9851da177e4SLinus Torvalds } 9868e821cadSTrond Myklebust spin_unlock(req_lock); 9871da177e4SLinus Torvalds } else 9881da177e4SLinus Torvalds dprintk(" OK\n"); 9891da177e4SLinus Torvalds 9908e821cadSTrond Myklebust out: 9911da177e4SLinus Torvalds if (atomic_dec_and_test(&req->wb_complete)) 9921da177e4SLinus Torvalds nfs_writepage_release(req); 9931da177e4SLinus Torvalds } 9941da177e4SLinus Torvalds 995788e7a89STrond Myklebust static const struct rpc_call_ops nfs_write_partial_ops = { 996788e7a89STrond Myklebust .rpc_call_done = nfs_writeback_done_partial, 997788e7a89STrond Myklebust .rpc_release = nfs_writedata_release, 998788e7a89STrond Myklebust }; 999788e7a89STrond Myklebust 10001da177e4SLinus Torvalds /* 10011da177e4SLinus Torvalds * Handle a write reply that flushes a whole page. 10021da177e4SLinus Torvalds * 10031da177e4SLinus Torvalds * FIXME: There is an inherent race with invalidate_inode_pages and 10041da177e4SLinus Torvalds * writebacks since the page->count is kept > 1 for as long 10051da177e4SLinus Torvalds * as the page has a write request pending. 10061da177e4SLinus Torvalds */ 1007788e7a89STrond Myklebust static void nfs_writeback_done_full(struct rpc_task *task, void *calldata) 10081da177e4SLinus Torvalds { 1009788e7a89STrond Myklebust struct nfs_write_data *data = calldata; 10101da177e4SLinus Torvalds struct nfs_page *req; 10111da177e4SLinus Torvalds struct page *page; 10121da177e4SLinus Torvalds 1013788e7a89STrond Myklebust if (nfs_writeback_done(task, data) != 0) 1014788e7a89STrond Myklebust return; 1015788e7a89STrond Myklebust 10161da177e4SLinus Torvalds /* Update attributes as result of writeback. */ 10171da177e4SLinus Torvalds while (!list_empty(&data->pages)) { 10181da177e4SLinus Torvalds req = nfs_list_entry(data->pages.next); 10191da177e4SLinus Torvalds nfs_list_remove_request(req); 10201da177e4SLinus Torvalds page = req->wb_page; 10211da177e4SLinus Torvalds 10221da177e4SLinus Torvalds dprintk("NFS: write (%s/%Ld %d@%Ld)", 10231da177e4SLinus Torvalds req->wb_context->dentry->d_inode->i_sb->s_id, 10241da177e4SLinus Torvalds (long long)NFS_FILEID(req->wb_context->dentry->d_inode), 10251da177e4SLinus Torvalds req->wb_bytes, 10261da177e4SLinus Torvalds (long long)req_offset(req)); 10271da177e4SLinus Torvalds 1028788e7a89STrond Myklebust if (task->tk_status < 0) { 1029a301b777STrond Myklebust nfs_set_pageerror(page); 1030788e7a89STrond Myklebust req->wb_context->error = task->tk_status; 1031788e7a89STrond Myklebust dprintk(", error = %d\n", task->tk_status); 10328e821cadSTrond Myklebust goto remove_request; 10331da177e4SLinus Torvalds } 10341da177e4SLinus Torvalds 10358e821cadSTrond Myklebust if (nfs_write_need_commit(data)) { 10361da177e4SLinus Torvalds memcpy(&req->wb_verf, &data->verf, sizeof(req->wb_verf)); 10371da177e4SLinus Torvalds nfs_mark_request_commit(req); 10388e821cadSTrond Myklebust nfs_end_page_writeback(page); 10391da177e4SLinus Torvalds dprintk(" marked for commit\n"); 10408e821cadSTrond Myklebust goto next; 10418e821cadSTrond Myklebust } 10428e821cadSTrond Myklebust dprintk(" OK\n"); 10438e821cadSTrond Myklebust remove_request: 10448e821cadSTrond Myklebust nfs_end_page_writeback(page); 10451da177e4SLinus Torvalds nfs_inode_remove_request(req); 10461da177e4SLinus Torvalds next: 1047c6a556b8STrond Myklebust nfs_clear_page_writeback(req); 10481da177e4SLinus Torvalds } 10491da177e4SLinus Torvalds } 10501da177e4SLinus Torvalds 1051788e7a89STrond Myklebust static const struct rpc_call_ops nfs_write_full_ops = { 1052788e7a89STrond Myklebust .rpc_call_done = nfs_writeback_done_full, 1053788e7a89STrond Myklebust .rpc_release = nfs_writedata_release, 1054788e7a89STrond Myklebust }; 1055788e7a89STrond Myklebust 1056788e7a89STrond Myklebust 10571da177e4SLinus Torvalds /* 10581da177e4SLinus Torvalds * This function is called when the WRITE call is complete. 10591da177e4SLinus Torvalds */ 1060462d5b32SChuck Lever int nfs_writeback_done(struct rpc_task *task, struct nfs_write_data *data) 10611da177e4SLinus Torvalds { 10621da177e4SLinus Torvalds struct nfs_writeargs *argp = &data->args; 10631da177e4SLinus Torvalds struct nfs_writeres *resp = &data->res; 1064788e7a89STrond Myklebust int status; 10651da177e4SLinus Torvalds 1066a3f565b1SChuck Lever dprintk("NFS: %5u nfs_writeback_done (status %d)\n", 10671da177e4SLinus Torvalds task->tk_pid, task->tk_status); 10681da177e4SLinus Torvalds 1069f551e44fSChuck Lever /* 1070f551e44fSChuck Lever * ->write_done will attempt to use post-op attributes to detect 1071f551e44fSChuck Lever * conflicting writes by other clients. A strict interpretation 1072f551e44fSChuck Lever * of close-to-open would allow us to continue caching even if 1073f551e44fSChuck Lever * another writer had changed the file, but some applications 1074f551e44fSChuck Lever * depend on tighter cache coherency when writing. 1075f551e44fSChuck Lever */ 1076788e7a89STrond Myklebust status = NFS_PROTO(data->inode)->write_done(task, data); 1077788e7a89STrond Myklebust if (status != 0) 1078788e7a89STrond Myklebust return status; 107991d5b470SChuck Lever nfs_add_stats(data->inode, NFSIOS_SERVERWRITTENBYTES, resp->count); 108091d5b470SChuck Lever 10811da177e4SLinus Torvalds #if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4) 10821da177e4SLinus Torvalds if (resp->verf->committed < argp->stable && task->tk_status >= 0) { 10831da177e4SLinus Torvalds /* We tried a write call, but the server did not 10841da177e4SLinus Torvalds * commit data to stable storage even though we 10851da177e4SLinus Torvalds * requested it. 10861da177e4SLinus Torvalds * Note: There is a known bug in Tru64 < 5.0 in which 10871da177e4SLinus Torvalds * the server reports NFS_DATA_SYNC, but performs 10881da177e4SLinus Torvalds * NFS_FILE_SYNC. We therefore implement this checking 10891da177e4SLinus Torvalds * as a dprintk() in order to avoid filling syslog. 10901da177e4SLinus Torvalds */ 10911da177e4SLinus Torvalds static unsigned long complain; 10921da177e4SLinus Torvalds 10931da177e4SLinus Torvalds if (time_before(complain, jiffies)) { 10941da177e4SLinus Torvalds dprintk("NFS: faulty NFS server %s:" 10951da177e4SLinus Torvalds " (committed = %d) != (stable = %d)\n", 109654ceac45SDavid Howells NFS_SERVER(data->inode)->nfs_client->cl_hostname, 10971da177e4SLinus Torvalds resp->verf->committed, argp->stable); 10981da177e4SLinus Torvalds complain = jiffies + 300 * HZ; 10991da177e4SLinus Torvalds } 11001da177e4SLinus Torvalds } 11011da177e4SLinus Torvalds #endif 11021da177e4SLinus Torvalds /* Is this a short write? */ 11031da177e4SLinus Torvalds if (task->tk_status >= 0 && resp->count < argp->count) { 11041da177e4SLinus Torvalds static unsigned long complain; 11051da177e4SLinus Torvalds 110691d5b470SChuck Lever nfs_inc_stats(data->inode, NFSIOS_SHORTWRITE); 110791d5b470SChuck Lever 11081da177e4SLinus Torvalds /* Has the server at least made some progress? */ 11091da177e4SLinus Torvalds if (resp->count != 0) { 11101da177e4SLinus Torvalds /* Was this an NFSv2 write or an NFSv3 stable write? */ 11111da177e4SLinus Torvalds if (resp->verf->committed != NFS_UNSTABLE) { 11121da177e4SLinus Torvalds /* Resend from where the server left off */ 11131da177e4SLinus Torvalds argp->offset += resp->count; 11141da177e4SLinus Torvalds argp->pgbase += resp->count; 11151da177e4SLinus Torvalds argp->count -= resp->count; 11161da177e4SLinus Torvalds } else { 11171da177e4SLinus Torvalds /* Resend as a stable write in order to avoid 11181da177e4SLinus Torvalds * headaches in the case of a server crash. 11191da177e4SLinus Torvalds */ 11201da177e4SLinus Torvalds argp->stable = NFS_FILE_SYNC; 11211da177e4SLinus Torvalds } 11221da177e4SLinus Torvalds rpc_restart_call(task); 1123788e7a89STrond Myklebust return -EAGAIN; 11241da177e4SLinus Torvalds } 11251da177e4SLinus Torvalds if (time_before(complain, jiffies)) { 11261da177e4SLinus Torvalds printk(KERN_WARNING 11271da177e4SLinus Torvalds "NFS: Server wrote zero bytes, expected %u.\n", 11281da177e4SLinus Torvalds argp->count); 11291da177e4SLinus Torvalds complain = jiffies + 300 * HZ; 11301da177e4SLinus Torvalds } 11311da177e4SLinus Torvalds /* Can't do anything about it except throw an error. */ 11321da177e4SLinus Torvalds task->tk_status = -EIO; 11331da177e4SLinus Torvalds } 1134788e7a89STrond Myklebust return 0; 11351da177e4SLinus Torvalds } 11361da177e4SLinus Torvalds 11371da177e4SLinus Torvalds 11381da177e4SLinus Torvalds #if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4) 1139963d8fe5STrond Myklebust void nfs_commit_release(void *wdata) 11401da177e4SLinus Torvalds { 11411da177e4SLinus Torvalds nfs_commit_free(wdata); 11421da177e4SLinus Torvalds } 11431da177e4SLinus Torvalds 11441da177e4SLinus Torvalds /* 11451da177e4SLinus Torvalds * Set up the argument/result storage required for the RPC call. 11461da177e4SLinus Torvalds */ 11471da177e4SLinus Torvalds static void nfs_commit_rpcsetup(struct list_head *head, 1148788e7a89STrond Myklebust struct nfs_write_data *data, 1149788e7a89STrond Myklebust int how) 11501da177e4SLinus Torvalds { 11513da28eb1STrond Myklebust struct nfs_page *first; 11521da177e4SLinus Torvalds struct inode *inode; 1153788e7a89STrond Myklebust int flags; 11541da177e4SLinus Torvalds 11551da177e4SLinus Torvalds /* Set up the RPC argument and reply structs 11561da177e4SLinus Torvalds * NB: take care not to mess about with data->commit et al. */ 11571da177e4SLinus Torvalds 11581da177e4SLinus Torvalds list_splice_init(head, &data->pages); 11591da177e4SLinus Torvalds first = nfs_list_entry(data->pages.next); 11601da177e4SLinus Torvalds inode = first->wb_context->dentry->d_inode; 11611da177e4SLinus Torvalds 11621da177e4SLinus Torvalds data->inode = inode; 11631da177e4SLinus Torvalds data->cred = first->wb_context->cred; 11641da177e4SLinus Torvalds 11651da177e4SLinus Torvalds data->args.fh = NFS_FH(data->inode); 11663da28eb1STrond Myklebust /* Note: we always request a commit of the entire inode */ 11673da28eb1STrond Myklebust data->args.offset = 0; 11683da28eb1STrond Myklebust data->args.count = 0; 11693da28eb1STrond Myklebust data->res.count = 0; 11701da177e4SLinus Torvalds data->res.fattr = &data->fattr; 11711da177e4SLinus Torvalds data->res.verf = &data->verf; 11720e574af1STrond Myklebust nfs_fattr_init(&data->fattr); 11731da177e4SLinus Torvalds 1174788e7a89STrond Myklebust /* Set up the initial task struct. */ 1175788e7a89STrond Myklebust flags = (how & FLUSH_SYNC) ? 0 : RPC_TASK_ASYNC; 1176788e7a89STrond Myklebust rpc_init_task(&data->task, NFS_CLIENT(inode), flags, &nfs_commit_ops, data); 11771da177e4SLinus Torvalds NFS_PROTO(inode)->commit_setup(data, how); 11781da177e4SLinus Torvalds 11791da177e4SLinus Torvalds data->task.tk_priority = flush_task_priority(how); 11801da177e4SLinus Torvalds data->task.tk_cookie = (unsigned long)inode; 11811da177e4SLinus Torvalds 1182a3f565b1SChuck Lever dprintk("NFS: %5u initiated commit call\n", data->task.tk_pid); 11831da177e4SLinus Torvalds } 11841da177e4SLinus Torvalds 11851da177e4SLinus Torvalds /* 11861da177e4SLinus Torvalds * Commit dirty pages 11871da177e4SLinus Torvalds */ 11881da177e4SLinus Torvalds static int 118940859d7eSChuck Lever nfs_commit_list(struct inode *inode, struct list_head *head, int how) 11901da177e4SLinus Torvalds { 11911da177e4SLinus Torvalds struct nfs_write_data *data; 11921da177e4SLinus Torvalds struct nfs_page *req; 11931da177e4SLinus Torvalds 1194e9f7bee1STrond Myklebust data = nfs_commit_alloc(); 11951da177e4SLinus Torvalds 11961da177e4SLinus Torvalds if (!data) 11971da177e4SLinus Torvalds goto out_bad; 11981da177e4SLinus Torvalds 11991da177e4SLinus Torvalds /* Set up the argument struct */ 12001da177e4SLinus Torvalds nfs_commit_rpcsetup(head, data, how); 12011da177e4SLinus Torvalds 12021da177e4SLinus Torvalds nfs_execute_write(data); 12031da177e4SLinus Torvalds return 0; 12041da177e4SLinus Torvalds out_bad: 12051da177e4SLinus Torvalds while (!list_empty(head)) { 12061da177e4SLinus Torvalds req = nfs_list_entry(head->next); 12071da177e4SLinus Torvalds nfs_list_remove_request(req); 12081da177e4SLinus Torvalds nfs_mark_request_commit(req); 120983715ad5STrond Myklebust dec_zone_page_state(req->wb_page, NR_UNSTABLE_NFS); 12105c2d97cbSTrond Myklebust nfs_clear_page_writeback(req); 12111da177e4SLinus Torvalds } 12121da177e4SLinus Torvalds return -ENOMEM; 12131da177e4SLinus Torvalds } 12141da177e4SLinus Torvalds 12151da177e4SLinus Torvalds /* 12161da177e4SLinus Torvalds * COMMIT call returned 12171da177e4SLinus Torvalds */ 1218788e7a89STrond Myklebust static void nfs_commit_done(struct rpc_task *task, void *calldata) 12191da177e4SLinus Torvalds { 1220963d8fe5STrond Myklebust struct nfs_write_data *data = calldata; 12211da177e4SLinus Torvalds struct nfs_page *req; 12221da177e4SLinus Torvalds 1223a3f565b1SChuck Lever dprintk("NFS: %5u nfs_commit_done (status %d)\n", 12241da177e4SLinus Torvalds task->tk_pid, task->tk_status); 12251da177e4SLinus Torvalds 1226788e7a89STrond Myklebust /* Call the NFS version-specific code */ 1227788e7a89STrond Myklebust if (NFS_PROTO(data->inode)->commit_done(task, data) != 0) 1228788e7a89STrond Myklebust return; 1229788e7a89STrond Myklebust 12301da177e4SLinus Torvalds while (!list_empty(&data->pages)) { 12311da177e4SLinus Torvalds req = nfs_list_entry(data->pages.next); 12321da177e4SLinus Torvalds nfs_list_remove_request(req); 1233612c9384STrond Myklebust clear_bit(PG_NEED_COMMIT, &(req)->wb_flags); 1234fd39fc85SChristoph Lameter dec_zone_page_state(req->wb_page, NR_UNSTABLE_NFS); 12351da177e4SLinus Torvalds 12361da177e4SLinus Torvalds dprintk("NFS: commit (%s/%Ld %d@%Ld)", 12371da177e4SLinus Torvalds req->wb_context->dentry->d_inode->i_sb->s_id, 12381da177e4SLinus Torvalds (long long)NFS_FILEID(req->wb_context->dentry->d_inode), 12391da177e4SLinus Torvalds req->wb_bytes, 12401da177e4SLinus Torvalds (long long)req_offset(req)); 12411da177e4SLinus Torvalds if (task->tk_status < 0) { 12421da177e4SLinus Torvalds req->wb_context->error = task->tk_status; 12431da177e4SLinus Torvalds nfs_inode_remove_request(req); 12441da177e4SLinus Torvalds dprintk(", error = %d\n", task->tk_status); 12451da177e4SLinus Torvalds goto next; 12461da177e4SLinus Torvalds } 12471da177e4SLinus Torvalds 12481da177e4SLinus Torvalds /* Okay, COMMIT succeeded, apparently. Check the verifier 12491da177e4SLinus Torvalds * returned by the server against all stored verfs. */ 12501da177e4SLinus Torvalds if (!memcmp(req->wb_verf.verifier, data->verf.verifier, sizeof(data->verf.verifier))) { 12511da177e4SLinus Torvalds /* We have a match */ 12521da177e4SLinus Torvalds nfs_inode_remove_request(req); 12531da177e4SLinus Torvalds dprintk(" OK\n"); 12541da177e4SLinus Torvalds goto next; 12551da177e4SLinus Torvalds } 12561da177e4SLinus Torvalds /* We have a mismatch. Write the page again */ 12571da177e4SLinus Torvalds dprintk(" mismatch\n"); 125861822ab5STrond Myklebust nfs_redirty_request(req); 12591da177e4SLinus Torvalds next: 1260c6a556b8STrond Myklebust nfs_clear_page_writeback(req); 12611da177e4SLinus Torvalds } 12621da177e4SLinus Torvalds } 1263788e7a89STrond Myklebust 1264788e7a89STrond Myklebust static const struct rpc_call_ops nfs_commit_ops = { 1265788e7a89STrond Myklebust .rpc_call_done = nfs_commit_done, 1266788e7a89STrond Myklebust .rpc_release = nfs_commit_release, 1267788e7a89STrond Myklebust }; 12681da177e4SLinus Torvalds 12693da28eb1STrond Myklebust int nfs_commit_inode(struct inode *inode, int how) 12701da177e4SLinus Torvalds { 12711da177e4SLinus Torvalds struct nfs_inode *nfsi = NFS_I(inode); 12721da177e4SLinus Torvalds LIST_HEAD(head); 12737d46a49fSTrond Myklebust int res; 12741da177e4SLinus Torvalds 12751da177e4SLinus Torvalds spin_lock(&nfsi->req_lock); 12763da28eb1STrond Myklebust res = nfs_scan_commit(inode, &head, 0, 0); 12773da28eb1STrond Myklebust spin_unlock(&nfsi->req_lock); 12781da177e4SLinus Torvalds if (res) { 12797d46a49fSTrond Myklebust int error = nfs_commit_list(inode, &head, how); 12801da177e4SLinus Torvalds if (error < 0) 12811da177e4SLinus Torvalds return error; 12823da28eb1STrond Myklebust } 12831da177e4SLinus Torvalds return res; 12841da177e4SLinus Torvalds } 1285c63c7b05STrond Myklebust #else 1286c63c7b05STrond Myklebust static inline int nfs_commit_list(struct inode *inode, struct list_head *head, int how) 1287c63c7b05STrond Myklebust { 1288c63c7b05STrond Myklebust return 0; 1289c63c7b05STrond Myklebust } 12901da177e4SLinus Torvalds #endif 12911da177e4SLinus Torvalds 12921c75950bSTrond Myklebust long nfs_sync_mapping_wait(struct address_space *mapping, struct writeback_control *wbc, int how) 12931da177e4SLinus Torvalds { 12941c75950bSTrond Myklebust struct inode *inode = mapping->host; 1295c42de9ddSTrond Myklebust struct nfs_inode *nfsi = NFS_I(inode); 1296ca52fec1STrond Myklebust pgoff_t idx_start, idx_end; 12971c75950bSTrond Myklebust unsigned int npages = 0; 1298c42de9ddSTrond Myklebust LIST_HEAD(head); 129970b9ecbdSTrond Myklebust int nocommit = how & FLUSH_NOCOMMIT; 13003f442547STrond Myklebust long pages, ret; 13011da177e4SLinus Torvalds 13021c75950bSTrond Myklebust /* FIXME */ 13031c75950bSTrond Myklebust if (wbc->range_cyclic) 13041c75950bSTrond Myklebust idx_start = 0; 13051c75950bSTrond Myklebust else { 13061c75950bSTrond Myklebust idx_start = wbc->range_start >> PAGE_CACHE_SHIFT; 13071c75950bSTrond Myklebust idx_end = wbc->range_end >> PAGE_CACHE_SHIFT; 13081c75950bSTrond Myklebust if (idx_end > idx_start) { 1309ca52fec1STrond Myklebust pgoff_t l_npages = 1 + idx_end - idx_start; 13101c75950bSTrond Myklebust npages = l_npages; 13111c75950bSTrond Myklebust if (sizeof(npages) != sizeof(l_npages) && 1312ca52fec1STrond Myklebust (pgoff_t)npages != l_npages) 13131c75950bSTrond Myklebust npages = 0; 13141c75950bSTrond Myklebust } 13151c75950bSTrond Myklebust } 1316c42de9ddSTrond Myklebust how &= ~FLUSH_NOCOMMIT; 1317c42de9ddSTrond Myklebust spin_lock(&nfsi->req_lock); 13181da177e4SLinus Torvalds do { 1319c42de9ddSTrond Myklebust ret = nfs_wait_on_requests_locked(inode, idx_start, npages); 1320c42de9ddSTrond Myklebust if (ret != 0) 1321c42de9ddSTrond Myklebust continue; 1322c42de9ddSTrond Myklebust if (nocommit) 1323c42de9ddSTrond Myklebust break; 1324d2ccddf0STrond Myklebust pages = nfs_scan_commit(inode, &head, idx_start, npages); 1325724c439cSTrond Myklebust if (pages == 0) 1326c42de9ddSTrond Myklebust break; 1327d2ccddf0STrond Myklebust if (how & FLUSH_INVALIDATE) { 1328d2ccddf0STrond Myklebust spin_unlock(&nfsi->req_lock); 132983715ad5STrond Myklebust nfs_cancel_commit_list(&head); 1330e8e058e8STrond Myklebust ret = pages; 1331d2ccddf0STrond Myklebust spin_lock(&nfsi->req_lock); 1332d2ccddf0STrond Myklebust continue; 1333d2ccddf0STrond Myklebust } 1334d2ccddf0STrond Myklebust pages += nfs_scan_commit(inode, &head, 0, 0); 1335c42de9ddSTrond Myklebust spin_unlock(&nfsi->req_lock); 1336c42de9ddSTrond Myklebust ret = nfs_commit_list(inode, &head, how); 1337c42de9ddSTrond Myklebust spin_lock(&nfsi->req_lock); 1338c42de9ddSTrond Myklebust } while (ret >= 0); 1339c42de9ddSTrond Myklebust spin_unlock(&nfsi->req_lock); 1340c42de9ddSTrond Myklebust return ret; 13411da177e4SLinus Torvalds } 13421da177e4SLinus Torvalds 13431c75950bSTrond Myklebust /* 13441c75950bSTrond Myklebust * flush the inode to disk. 13451c75950bSTrond Myklebust */ 13461c75950bSTrond Myklebust int nfs_wb_all(struct inode *inode) 13471c75950bSTrond Myklebust { 13481c75950bSTrond Myklebust struct address_space *mapping = inode->i_mapping; 13491c75950bSTrond Myklebust struct writeback_control wbc = { 13501c75950bSTrond Myklebust .bdi = mapping->backing_dev_info, 13511c75950bSTrond Myklebust .sync_mode = WB_SYNC_ALL, 13521c75950bSTrond Myklebust .nr_to_write = LONG_MAX, 135361822ab5STrond Myklebust .for_writepages = 1, 13541c75950bSTrond Myklebust .range_cyclic = 1, 13551c75950bSTrond Myklebust }; 13561c75950bSTrond Myklebust int ret; 13571c75950bSTrond Myklebust 1358c63c7b05STrond Myklebust ret = nfs_writepages(mapping, &wbc); 135961822ab5STrond Myklebust if (ret < 0) 136061822ab5STrond Myklebust goto out; 13611c75950bSTrond Myklebust ret = nfs_sync_mapping_wait(mapping, &wbc, 0); 13621c75950bSTrond Myklebust if (ret >= 0) 13631c75950bSTrond Myklebust return 0; 136461822ab5STrond Myklebust out: 1365e507d9ebSTrond Myklebust __mark_inode_dirty(mapping->host, I_DIRTY_PAGES); 13661c75950bSTrond Myklebust return ret; 13671c75950bSTrond Myklebust } 13681c75950bSTrond Myklebust 13691c75950bSTrond Myklebust int nfs_sync_mapping_range(struct address_space *mapping, loff_t range_start, loff_t range_end, int how) 13701c75950bSTrond Myklebust { 13711c75950bSTrond Myklebust struct writeback_control wbc = { 13721c75950bSTrond Myklebust .bdi = mapping->backing_dev_info, 13731c75950bSTrond Myklebust .sync_mode = WB_SYNC_ALL, 13741c75950bSTrond Myklebust .nr_to_write = LONG_MAX, 13751c75950bSTrond Myklebust .range_start = range_start, 13761c75950bSTrond Myklebust .range_end = range_end, 137761822ab5STrond Myklebust .for_writepages = 1, 13781c75950bSTrond Myklebust }; 13791c75950bSTrond Myklebust int ret; 13801c75950bSTrond Myklebust 1381c63c7b05STrond Myklebust ret = nfs_writepages(mapping, &wbc); 138261822ab5STrond Myklebust if (ret < 0) 138361822ab5STrond Myklebust goto out; 13841c75950bSTrond Myklebust ret = nfs_sync_mapping_wait(mapping, &wbc, how); 13851c75950bSTrond Myklebust if (ret >= 0) 13861c75950bSTrond Myklebust return 0; 138761822ab5STrond Myklebust out: 1388e507d9ebSTrond Myklebust __mark_inode_dirty(mapping->host, I_DIRTY_PAGES); 13891c75950bSTrond Myklebust return ret; 13901c75950bSTrond Myklebust } 13911c75950bSTrond Myklebust 139261822ab5STrond Myklebust int nfs_wb_page_priority(struct inode *inode, struct page *page, int how) 13931c75950bSTrond Myklebust { 13941c75950bSTrond Myklebust loff_t range_start = page_offset(page); 13951c75950bSTrond Myklebust loff_t range_end = range_start + (loff_t)(PAGE_CACHE_SIZE - 1); 13964d770ccfSTrond Myklebust struct writeback_control wbc = { 13974d770ccfSTrond Myklebust .bdi = page->mapping->backing_dev_info, 13984d770ccfSTrond Myklebust .sync_mode = WB_SYNC_ALL, 13994d770ccfSTrond Myklebust .nr_to_write = LONG_MAX, 14004d770ccfSTrond Myklebust .range_start = range_start, 14014d770ccfSTrond Myklebust .range_end = range_end, 14024d770ccfSTrond Myklebust }; 14034d770ccfSTrond Myklebust int ret; 14041c75950bSTrond Myklebust 14054d770ccfSTrond Myklebust BUG_ON(!PageLocked(page)); 1406c63c7b05STrond Myklebust if (clear_page_dirty_for_io(page)) { 14074d770ccfSTrond Myklebust ret = nfs_writepage_locked(page, &wbc); 14084d770ccfSTrond Myklebust if (ret < 0) 14094d770ccfSTrond Myklebust goto out; 14104d770ccfSTrond Myklebust } 1411f40313acSTrond Myklebust if (!PagePrivate(page)) 1412f40313acSTrond Myklebust return 0; 14134d770ccfSTrond Myklebust ret = nfs_sync_mapping_wait(page->mapping, &wbc, how); 14144d770ccfSTrond Myklebust if (ret >= 0) 14154d770ccfSTrond Myklebust return 0; 14164d770ccfSTrond Myklebust out: 1417e507d9ebSTrond Myklebust __mark_inode_dirty(inode, I_DIRTY_PAGES); 14184d770ccfSTrond Myklebust return ret; 14191c75950bSTrond Myklebust } 14201c75950bSTrond Myklebust 14211c75950bSTrond Myklebust /* 14221c75950bSTrond Myklebust * Write back all requests on one page - we do this before reading it. 14231c75950bSTrond Myklebust */ 14241c75950bSTrond Myklebust int nfs_wb_page(struct inode *inode, struct page* page) 14251c75950bSTrond Myklebust { 14264d770ccfSTrond Myklebust return nfs_wb_page_priority(inode, page, FLUSH_STABLE); 14271c75950bSTrond Myklebust } 14281c75950bSTrond Myklebust 14291a54533eSTrond Myklebust int nfs_set_page_dirty(struct page *page) 14301a54533eSTrond Myklebust { 1431d585158bSTrond Myklebust struct address_space *mapping = page->mapping; 1432d585158bSTrond Myklebust struct inode *inode; 1433d585158bSTrond Myklebust spinlock_t *req_lock; 14341a54533eSTrond Myklebust struct nfs_page *req; 14352b82f190STrond Myklebust int ret; 14361a54533eSTrond Myklebust 1437d585158bSTrond Myklebust if (!mapping) 1438d585158bSTrond Myklebust goto out_raced; 1439d585158bSTrond Myklebust inode = mapping->host; 1440d585158bSTrond Myklebust if (!inode) 1441d585158bSTrond Myklebust goto out_raced; 1442d585158bSTrond Myklebust req_lock = &NFS_I(inode)->req_lock; 14432b82f190STrond Myklebust spin_lock(req_lock); 14442b82f190STrond Myklebust req = nfs_page_find_request_locked(page); 14451a54533eSTrond Myklebust if (req != NULL) { 14461a54533eSTrond Myklebust /* Mark any existing write requests for flushing */ 14472b82f190STrond Myklebust ret = !test_and_set_bit(PG_NEED_FLUSH, &req->wb_flags); 14482b82f190STrond Myklebust spin_unlock(req_lock); 14491a54533eSTrond Myklebust nfs_release_request(req); 14502b82f190STrond Myklebust return ret; 14511a54533eSTrond Myklebust } 14522b82f190STrond Myklebust ret = __set_page_dirty_nobuffers(page); 14532b82f190STrond Myklebust spin_unlock(req_lock); 14542b82f190STrond Myklebust return ret; 1455d585158bSTrond Myklebust out_raced: 1456d585158bSTrond Myklebust return !TestSetPageDirty(page); 14571a54533eSTrond Myklebust } 14581a54533eSTrond Myklebust 14591c75950bSTrond Myklebust 1460f7b422b1SDavid Howells int __init nfs_init_writepagecache(void) 14611da177e4SLinus Torvalds { 14621da177e4SLinus Torvalds nfs_wdata_cachep = kmem_cache_create("nfs_write_data", 14631da177e4SLinus Torvalds sizeof(struct nfs_write_data), 14641da177e4SLinus Torvalds 0, SLAB_HWCACHE_ALIGN, 14651da177e4SLinus Torvalds NULL, NULL); 14661da177e4SLinus Torvalds if (nfs_wdata_cachep == NULL) 14671da177e4SLinus Torvalds return -ENOMEM; 14681da177e4SLinus Torvalds 146993d2341cSMatthew Dobson nfs_wdata_mempool = mempool_create_slab_pool(MIN_POOL_WRITE, 14701da177e4SLinus Torvalds nfs_wdata_cachep); 14711da177e4SLinus Torvalds if (nfs_wdata_mempool == NULL) 14721da177e4SLinus Torvalds return -ENOMEM; 14731da177e4SLinus Torvalds 147493d2341cSMatthew Dobson nfs_commit_mempool = mempool_create_slab_pool(MIN_POOL_COMMIT, 14751da177e4SLinus Torvalds nfs_wdata_cachep); 14761da177e4SLinus Torvalds if (nfs_commit_mempool == NULL) 14771da177e4SLinus Torvalds return -ENOMEM; 14781da177e4SLinus Torvalds 147989a09141SPeter Zijlstra /* 148089a09141SPeter Zijlstra * NFS congestion size, scale with available memory. 148189a09141SPeter Zijlstra * 148289a09141SPeter Zijlstra * 64MB: 8192k 148389a09141SPeter Zijlstra * 128MB: 11585k 148489a09141SPeter Zijlstra * 256MB: 16384k 148589a09141SPeter Zijlstra * 512MB: 23170k 148689a09141SPeter Zijlstra * 1GB: 32768k 148789a09141SPeter Zijlstra * 2GB: 46340k 148889a09141SPeter Zijlstra * 4GB: 65536k 148989a09141SPeter Zijlstra * 8GB: 92681k 149089a09141SPeter Zijlstra * 16GB: 131072k 149189a09141SPeter Zijlstra * 149289a09141SPeter Zijlstra * This allows larger machines to have larger/more transfers. 149389a09141SPeter Zijlstra * Limit the default to 256M 149489a09141SPeter Zijlstra */ 149589a09141SPeter Zijlstra nfs_congestion_kb = (16*int_sqrt(totalram_pages)) << (PAGE_SHIFT-10); 149689a09141SPeter Zijlstra if (nfs_congestion_kb > 256*1024) 149789a09141SPeter Zijlstra nfs_congestion_kb = 256*1024; 149889a09141SPeter Zijlstra 14991da177e4SLinus Torvalds return 0; 15001da177e4SLinus Torvalds } 15011da177e4SLinus Torvalds 1502266bee88SDavid Brownell void nfs_destroy_writepagecache(void) 15031da177e4SLinus Torvalds { 15041da177e4SLinus Torvalds mempool_destroy(nfs_commit_mempool); 15051da177e4SLinus Torvalds mempool_destroy(nfs_wdata_mempool); 15061a1d92c1SAlexey Dobriyan kmem_cache_destroy(nfs_wdata_cachep); 15071da177e4SLinus Torvalds } 15081da177e4SLinus Torvalds 1509