^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * linux/fs/nfs/write.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Write file data over NFS.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (C) 1996, 1997, Olaf Kirch <okir@monad.swb.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/pagemap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/writeback.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/swap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/migrate.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/sunrpc/clnt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/nfs_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/nfs_mount.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/nfs_page.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/backing-dev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/freezer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/wait.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/iversion.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/sched/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include "delegation.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include "internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include "iostat.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include "nfs4_fs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include "fscache.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include "pnfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include "nfstrace.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #define NFSDBG_FACILITY NFSDBG_PAGECACHE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #define MIN_POOL_WRITE (32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #define MIN_POOL_COMMIT (4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) struct nfs_io_completion {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) void (*complete)(void *data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) void *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) struct kref refcount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * Local function declarations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) static void nfs_redirty_request(struct nfs_page *req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) static const struct rpc_call_ops nfs_commit_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) static const struct nfs_pgio_completion_ops nfs_async_write_completion_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) static const struct nfs_commit_completion_ops nfs_commit_completion_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) static const struct nfs_rw_ops nfs_rw_write_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) static void nfs_inode_remove_request(struct nfs_page *req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) static void nfs_clear_request_commit(struct nfs_page *req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) static void nfs_init_cinfo_from_inode(struct nfs_commit_info *cinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) static struct nfs_page *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) nfs_page_search_commits_for_head_request_locked(struct nfs_inode *nfsi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) struct page *page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) static struct kmem_cache *nfs_wdata_cachep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) static mempool_t *nfs_wdata_mempool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) static struct kmem_cache *nfs_cdata_cachep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) static mempool_t *nfs_commit_mempool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) struct nfs_commit_data *nfs_commitdata_alloc(bool never_fail)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) struct nfs_commit_data *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) if (never_fail)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) p = mempool_alloc(nfs_commit_mempool, GFP_NOIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) /* It is OK to do some reclaim, not no safe to wait
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * for anything to be returned to the pool.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) * mempool_alloc() cannot handle that particular combination,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * so we need two separate attempts.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) p = mempool_alloc(nfs_commit_mempool, GFP_NOWAIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) if (!p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) p = kmem_cache_alloc(nfs_cdata_cachep, GFP_NOIO |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) __GFP_NOWARN | __GFP_NORETRY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) if (!p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) memset(p, 0, sizeof(*p));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) INIT_LIST_HEAD(&p->pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) return p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) EXPORT_SYMBOL_GPL(nfs_commitdata_alloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) void nfs_commit_free(struct nfs_commit_data *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) mempool_free(p, nfs_commit_mempool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) EXPORT_SYMBOL_GPL(nfs_commit_free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) static struct nfs_pgio_header *nfs_writehdr_alloc(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) struct nfs_pgio_header *p = mempool_alloc(nfs_wdata_mempool, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) memset(p, 0, sizeof(*p));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) p->rw_mode = FMODE_WRITE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) return p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) static void nfs_writehdr_free(struct nfs_pgio_header *hdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) mempool_free(hdr, nfs_wdata_mempool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) static struct nfs_io_completion *nfs_io_completion_alloc(gfp_t gfp_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) return kmalloc(sizeof(struct nfs_io_completion), gfp_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) static void nfs_io_completion_init(struct nfs_io_completion *ioc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) void (*complete)(void *), void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) ioc->complete = complete;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) ioc->data = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) kref_init(&ioc->refcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) static void nfs_io_completion_release(struct kref *kref)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) struct nfs_io_completion *ioc = container_of(kref,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) struct nfs_io_completion, refcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) ioc->complete(ioc->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) kfree(ioc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) static void nfs_io_completion_get(struct nfs_io_completion *ioc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) if (ioc != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) kref_get(&ioc->refcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) static void nfs_io_completion_put(struct nfs_io_completion *ioc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) if (ioc != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) kref_put(&ioc->refcount, nfs_io_completion_release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) nfs_page_set_inode_ref(struct nfs_page *req, struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) if (!test_and_set_bit(PG_INODE_REF, &req->wb_flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) kref_get(&req->wb_kref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) atomic_long_inc(&NFS_I(inode)->nrequests);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) nfs_cancel_remove_inode(struct nfs_page *req, struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) if (!test_bit(PG_REMOVE, &req->wb_flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) ret = nfs_page_group_lock(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) if (test_and_clear_bit(PG_REMOVE, &req->wb_flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) nfs_page_set_inode_ref(req, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) nfs_page_group_unlock(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) static struct nfs_page *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) nfs_page_private_request(struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) if (!PagePrivate(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) return (struct nfs_page *)page_private(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) * nfs_page_find_head_request_locked - find head request associated with @page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) * must be called while holding the inode lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) * returns matching head request with reference held, or NULL if not found.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) static struct nfs_page *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) nfs_page_find_private_request(struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) struct address_space *mapping = page_file_mapping(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) struct nfs_page *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) if (!PagePrivate(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) spin_lock(&mapping->private_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) req = nfs_page_private_request(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) if (req) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) WARN_ON_ONCE(req->wb_head != req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) kref_get(&req->wb_kref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) spin_unlock(&mapping->private_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) return req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) static struct nfs_page *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) nfs_page_find_swap_request(struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) struct inode *inode = page_file_mapping(page)->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) struct nfs_inode *nfsi = NFS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) struct nfs_page *req = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) if (!PageSwapCache(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) mutex_lock(&nfsi->commit_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) if (PageSwapCache(page)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) req = nfs_page_search_commits_for_head_request_locked(nfsi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) if (req) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) WARN_ON_ONCE(req->wb_head != req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) kref_get(&req->wb_kref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) mutex_unlock(&nfsi->commit_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) return req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) * nfs_page_find_head_request - find head request associated with @page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) * returns matching head request with reference held, or NULL if not found.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) static struct nfs_page *nfs_page_find_head_request(struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) struct nfs_page *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) req = nfs_page_find_private_request(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) if (!req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) req = nfs_page_find_swap_request(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) return req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) static struct nfs_page *nfs_find_and_lock_page_request(struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) struct inode *inode = page_file_mapping(page)->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) struct nfs_page *req, *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) req = nfs_page_find_head_request(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) if (!req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) return req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) head = nfs_page_group_lock_head(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) if (head != req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) nfs_release_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) if (IS_ERR(head))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) return head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) ret = nfs_cancel_remove_inode(head, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) nfs_unlock_and_release_request(head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) return ERR_PTR(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) /* Ensure that nobody removed the request before we locked it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) if (head == nfs_page_private_request(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) if (PageSwapCache(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) nfs_unlock_and_release_request(head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) return head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) /* Adjust the file length if we're writing beyond the end */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) static void nfs_grow_file(struct page *page, unsigned int offset, unsigned int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) struct inode *inode = page_file_mapping(page)->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) loff_t end, i_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) pgoff_t end_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) spin_lock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) i_size = i_size_read(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) end_index = (i_size - 1) >> PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) if (i_size > 0 && page_index(page) < end_index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) end = page_file_offset(page) + ((loff_t)offset+count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) if (i_size >= end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) i_size_write(inode, end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) NFS_I(inode)->cache_validity &= ~NFS_INO_INVALID_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) nfs_inc_stats(inode, NFSIOS_EXTENDWRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) spin_unlock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) /* A writeback failed: mark the page as bad, and invalidate the page cache */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) static void nfs_set_pageerror(struct address_space *mapping)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) struct inode *inode = mapping->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) nfs_zap_mapping(mapping->host, mapping);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) /* Force file size revalidation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) spin_lock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) NFS_I(inode)->cache_validity |= NFS_INO_REVAL_FORCED |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) NFS_INO_REVAL_PAGECACHE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) NFS_INO_INVALID_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) spin_unlock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) static void nfs_mapping_set_error(struct page *page, int error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) struct address_space *mapping = page_file_mapping(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) SetPageError(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) filemap_set_wb_err(mapping, error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) if (mapping->host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) errseq_set(&mapping->host->i_sb->s_wb_err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) error == -ENOSPC ? -ENOSPC : -EIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) nfs_set_pageerror(mapping);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) * nfs_page_group_search_locked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) * @head - head request of page group
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) * @page_offset - offset into page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) * Search page group with head @head to find a request that contains the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) * page offset @page_offset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) * Returns a pointer to the first matching nfs request, or NULL if no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) * match is found.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) * Must be called with the page group lock held
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) static struct nfs_page *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) nfs_page_group_search_locked(struct nfs_page *head, unsigned int page_offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) struct nfs_page *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) req = head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) if (page_offset >= req->wb_pgbase &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) page_offset < (req->wb_pgbase + req->wb_bytes))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) return req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) req = req->wb_this_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) } while (req != head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) * nfs_page_group_covers_page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) * @head - head request of page group
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) * Return true if the page group with head @head covers the whole page,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) * returns false otherwise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) static bool nfs_page_group_covers_page(struct nfs_page *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) struct nfs_page *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) unsigned int pos = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) unsigned int len = nfs_page_length(req->wb_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) nfs_page_group_lock(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) tmp = nfs_page_group_search_locked(req->wb_head, pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) if (!tmp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) pos = tmp->wb_pgbase + tmp->wb_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) nfs_page_group_unlock(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) return pos >= len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) /* We can set the PG_uptodate flag if we see that a write request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) * covers the full page.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) static void nfs_mark_uptodate(struct nfs_page *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) if (PageUptodate(req->wb_page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) if (!nfs_page_group_covers_page(req))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) SetPageUptodate(req->wb_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) static int wb_priority(struct writeback_control *wbc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) if (wbc->sync_mode == WB_SYNC_ALL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) ret = FLUSH_COND_STABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) * NFS congestion control
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) int nfs_congestion_kb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) #define NFS_CONGESTION_ON_THRESH (nfs_congestion_kb >> (PAGE_SHIFT-10))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) #define NFS_CONGESTION_OFF_THRESH \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) (NFS_CONGESTION_ON_THRESH - (NFS_CONGESTION_ON_THRESH >> 2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) static void nfs_set_page_writeback(struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) struct inode *inode = page_file_mapping(page)->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) struct nfs_server *nfss = NFS_SERVER(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) int ret = test_set_page_writeback(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) WARN_ON_ONCE(ret != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) if (atomic_long_inc_return(&nfss->writeback) >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) NFS_CONGESTION_ON_THRESH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) set_bdi_congested(inode_to_bdi(inode), BLK_RW_ASYNC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) static void nfs_end_page_writeback(struct nfs_page *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) struct inode *inode = page_file_mapping(req->wb_page)->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) struct nfs_server *nfss = NFS_SERVER(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) bool is_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) is_done = nfs_page_group_sync_on_bit(req, PG_WB_END);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) nfs_unlock_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) if (!is_done)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) end_page_writeback(req->wb_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) if (atomic_long_dec_return(&nfss->writeback) < NFS_CONGESTION_OFF_THRESH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) clear_bdi_congested(inode_to_bdi(inode), BLK_RW_ASYNC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) * nfs_destroy_unlinked_subrequests - destroy recently unlinked subrequests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) * @destroy_list - request list (using wb_this_page) terminated by @old_head
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) * @old_head - the old head of the list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) * All subrequests must be locked and removed from all lists, so at this point
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) * they are only "active" in this function, and possibly in nfs_wait_on_request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) * with a reference held by some other context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) nfs_destroy_unlinked_subrequests(struct nfs_page *destroy_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) struct nfs_page *old_head,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) while (destroy_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) struct nfs_page *subreq = destroy_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) destroy_list = (subreq->wb_this_page == old_head) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) NULL : subreq->wb_this_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) /* Note: lock subreq in order to change subreq->wb_head */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) nfs_page_set_headlock(subreq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) WARN_ON_ONCE(old_head != subreq->wb_head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) /* make sure old group is not used */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) subreq->wb_this_page = subreq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) subreq->wb_head = subreq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) clear_bit(PG_REMOVE, &subreq->wb_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) /* Note: races with nfs_page_group_destroy() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) if (!kref_read(&subreq->wb_kref)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) /* Check if we raced with nfs_page_group_destroy() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) if (test_and_clear_bit(PG_TEARDOWN, &subreq->wb_flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) nfs_page_clear_headlock(subreq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) nfs_free_request(subreq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) nfs_page_clear_headlock(subreq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) nfs_page_clear_headlock(subreq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) nfs_release_request(old_head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) if (test_and_clear_bit(PG_INODE_REF, &subreq->wb_flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) nfs_release_request(subreq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) atomic_long_dec(&NFS_I(inode)->nrequests);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) /* subreq is now totally disconnected from page group or any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) * write / commit lists. last chance to wake any waiters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) nfs_unlock_and_release_request(subreq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) * nfs_join_page_group - destroy subrequests of the head req
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) * @head: the page used to lookup the "page group" of nfs_page structures
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) * @inode: Inode to which the request belongs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) * This function joins all sub requests to the head request by first
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) * locking all requests in the group, cancelling any pending operations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) * and finally updating the head request to cover the whole range covered by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) * the (former) group. All subrequests are removed from any write or commit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) * lists, unlinked from the group and destroyed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) nfs_join_page_group(struct nfs_page *head, struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) struct nfs_page *subreq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) struct nfs_page *destroy_list = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) unsigned int pgbase, off, bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) pgbase = head->wb_pgbase;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) bytes = head->wb_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) off = head->wb_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) for (subreq = head->wb_this_page; subreq != head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) subreq = subreq->wb_this_page) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) /* Subrequests should always form a contiguous range */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) if (pgbase > subreq->wb_pgbase) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) off -= pgbase - subreq->wb_pgbase;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) bytes += pgbase - subreq->wb_pgbase;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) pgbase = subreq->wb_pgbase;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) bytes = max(subreq->wb_pgbase + subreq->wb_bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) - pgbase, bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) /* Set the head request's range to cover the former page group */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) head->wb_pgbase = pgbase;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) head->wb_bytes = bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) head->wb_offset = off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) /* Now that all requests are locked, make sure they aren't on any list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) * Commit list removal accounting is done after locks are dropped */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) subreq = head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) nfs_clear_request_commit(subreq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) subreq = subreq->wb_this_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) } while (subreq != head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) /* unlink subrequests from head, destroy them later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) if (head->wb_this_page != head) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) /* destroy list will be terminated by head */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) destroy_list = head->wb_this_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) head->wb_this_page = head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) nfs_destroy_unlinked_subrequests(destroy_list, head, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) * nfs_lock_and_join_requests - join all subreqs to the head req
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) * @page: the page used to lookup the "page group" of nfs_page structures
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) * This function joins all sub requests to the head request by first
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) * locking all requests in the group, cancelling any pending operations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) * and finally updating the head request to cover the whole range covered by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) * the (former) group. All subrequests are removed from any write or commit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) * lists, unlinked from the group and destroyed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) * Returns a locked, referenced pointer to the head request - which after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) * this call is guaranteed to be the only request associated with the page.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) * Returns NULL if no requests are found for @page, or a ERR_PTR if an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) * error was encountered.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) static struct nfs_page *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) nfs_lock_and_join_requests(struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) struct inode *inode = page_file_mapping(page)->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) struct nfs_page *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) * A reference is taken only on the head request which acts as a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) * reference to the whole page group - the group will not be destroyed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) * until the head reference is released.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) head = nfs_find_and_lock_page_request(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) if (IS_ERR_OR_NULL(head))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) return head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) /* lock each request in the page group */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) ret = nfs_page_group_lock_subrequests(head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) nfs_unlock_and_release_request(head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) return ERR_PTR(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) nfs_join_page_group(head, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) return head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) static void nfs_write_error(struct nfs_page *req, int error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) trace_nfs_write_error(req, error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) nfs_mapping_set_error(req->wb_page, error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) nfs_inode_remove_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) nfs_end_page_writeback(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) nfs_release_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) * Find an associated nfs write request, and prepare to flush it out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) * May return an error if the user signalled nfs_wait_on_request().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) static int nfs_page_async_flush(struct nfs_pageio_descriptor *pgio,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) struct nfs_page *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) req = nfs_lock_and_join_requests(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) if (!req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) ret = PTR_ERR(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) if (IS_ERR(req))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) nfs_set_page_writeback(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) WARN_ON_ONCE(test_bit(PG_CLEAN, &req->wb_flags));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) /* If there is a fatal error that covers this write, just exit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) ret = pgio->pg_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) if (nfs_error_is_fatal_on_server(ret))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) goto out_launder;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) if (!nfs_pageio_add_request(pgio, req)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) ret = pgio->pg_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) * Remove the problematic req upon fatal errors on the server
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) if (nfs_error_is_fatal(ret)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) if (nfs_error_is_fatal_on_server(ret))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) goto out_launder;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) ret = -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) nfs_redirty_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) pgio->pg_error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) nfs_add_stats(page_file_mapping(page)->host,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) NFSIOS_WRITEPAGES, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) out_launder:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) nfs_write_error(req, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) static int nfs_do_writepage(struct page *page, struct writeback_control *wbc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) struct nfs_pageio_descriptor *pgio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) nfs_pageio_cond_complete(pgio, page_index(page));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) ret = nfs_page_async_flush(pgio, page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) if (ret == -EAGAIN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) redirty_page_for_writepage(wbc, page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) ret = AOP_WRITEPAGE_ACTIVATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) * Write an mmapped page to the server.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) static int nfs_writepage_locked(struct page *page,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) struct writeback_control *wbc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) struct nfs_pageio_descriptor pgio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) struct inode *inode = page_file_mapping(page)->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) nfs_inc_stats(inode, NFSIOS_VFSWRITEPAGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) nfs_pageio_init_write(&pgio, inode, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) false, &nfs_async_write_completion_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) err = nfs_do_writepage(page, wbc, &pgio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) pgio.pg_error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) nfs_pageio_complete(&pgio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) if (nfs_error_is_fatal(pgio.pg_error))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) return pgio.pg_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) int nfs_writepage(struct page *page, struct writeback_control *wbc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) ret = nfs_writepage_locked(page, wbc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) if (ret != AOP_WRITEPAGE_ACTIVATE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) static int nfs_writepages_callback(struct page *page, struct writeback_control *wbc, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) ret = nfs_do_writepage(page, wbc, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) if (ret != AOP_WRITEPAGE_ACTIVATE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) static void nfs_io_completion_commit(void *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) nfs_commit_inode(inode, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) int nfs_writepages(struct address_space *mapping, struct writeback_control *wbc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) struct inode *inode = mapping->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) struct nfs_pageio_descriptor pgio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) struct nfs_io_completion *ioc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) nfs_inc_stats(inode, NFSIOS_VFSWRITEPAGES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) ioc = nfs_io_completion_alloc(GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) if (ioc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) nfs_io_completion_init(ioc, nfs_io_completion_commit, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) nfs_pageio_init_write(&pgio, inode, wb_priority(wbc), false,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) &nfs_async_write_completion_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) pgio.pg_io_completion = ioc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) err = write_cache_pages(mapping, wbc, nfs_writepages_callback, &pgio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) pgio.pg_error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) nfs_pageio_complete(&pgio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) nfs_io_completion_put(ioc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) err = pgio.pg_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) if (nfs_error_is_fatal(err))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) out_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) * Insert a write request into an inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) static void nfs_inode_add_request(struct inode *inode, struct nfs_page *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) struct address_space *mapping = page_file_mapping(req->wb_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) struct nfs_inode *nfsi = NFS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) WARN_ON_ONCE(req->wb_this_page != req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) /* Lock the request! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) nfs_lock_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) * Swap-space should not get truncated. Hence no need to plug the race
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) * with invalidate/truncate.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) spin_lock(&mapping->private_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) if (!nfs_have_writebacks(inode) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) NFS_PROTO(inode)->have_delegation(inode, FMODE_WRITE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) inode_inc_iversion_raw(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) if (likely(!PageSwapCache(req->wb_page))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) set_bit(PG_MAPPED, &req->wb_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) SetPagePrivate(req->wb_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) set_page_private(req->wb_page, (unsigned long)req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) spin_unlock(&mapping->private_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) atomic_long_inc(&nfsi->nrequests);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) /* this a head request for a page group - mark it as having an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) * extra reference so sub groups can follow suit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) * This flag also informs pgio layer when to bump nrequests when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) * adding subrequests. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) WARN_ON(test_and_set_bit(PG_INODE_REF, &req->wb_flags));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) kref_get(&req->wb_kref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) * Remove a write request from an inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) static void nfs_inode_remove_request(struct nfs_page *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) struct address_space *mapping = page_file_mapping(req->wb_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) struct inode *inode = mapping->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) struct nfs_inode *nfsi = NFS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) struct nfs_page *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) if (nfs_page_group_sync_on_bit(req, PG_REMOVE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) head = req->wb_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) spin_lock(&mapping->private_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) if (likely(head->wb_page && !PageSwapCache(head->wb_page))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) set_page_private(head->wb_page, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) ClearPagePrivate(head->wb_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) clear_bit(PG_MAPPED, &head->wb_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) spin_unlock(&mapping->private_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) if (test_and_clear_bit(PG_INODE_REF, &req->wb_flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) nfs_release_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) atomic_long_dec(&nfsi->nrequests);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) nfs_mark_request_dirty(struct nfs_page *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) if (req->wb_page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) __set_page_dirty_nobuffers(req->wb_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) * nfs_page_search_commits_for_head_request_locked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) * Search through commit lists on @inode for the head request for @page.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) * Must be called while holding the inode (which is cinfo) lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) * Returns the head request if found, or NULL if not found.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) static struct nfs_page *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) nfs_page_search_commits_for_head_request_locked(struct nfs_inode *nfsi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) struct nfs_page *freq, *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) struct nfs_commit_info cinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) struct inode *inode = &nfsi->vfs_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) nfs_init_cinfo_from_inode(&cinfo, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) /* search through pnfs commit lists */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) freq = pnfs_search_commit_reqs(inode, &cinfo, page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) if (freq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) return freq->wb_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) /* Linearly search the commit list for the correct request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) list_for_each_entry_safe(freq, t, &cinfo.mds->list, wb_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) if (freq->wb_page == page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) return freq->wb_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) * nfs_request_add_commit_list_locked - add request to a commit list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) * @req: pointer to a struct nfs_page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) * @dst: commit list head
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) * @cinfo: holds list lock and accounting info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) * This sets the PG_CLEAN bit, updates the cinfo count of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) * number of outstanding requests requiring a commit as well as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) * the MM page stats.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) * The caller must hold NFS_I(cinfo->inode)->commit_mutex, and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) * nfs_page lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) nfs_request_add_commit_list_locked(struct nfs_page *req, struct list_head *dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) struct nfs_commit_info *cinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) set_bit(PG_CLEAN, &req->wb_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) nfs_list_add_request(req, dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) atomic_long_inc(&cinfo->mds->ncommit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) EXPORT_SYMBOL_GPL(nfs_request_add_commit_list_locked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) * nfs_request_add_commit_list - add request to a commit list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) * @req: pointer to a struct nfs_page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) * @cinfo: holds list lock and accounting info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) * This sets the PG_CLEAN bit, updates the cinfo count of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) * number of outstanding requests requiring a commit as well as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) * the MM page stats.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) * The caller must _not_ hold the cinfo->lock, but must be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) * holding the nfs_page lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) nfs_request_add_commit_list(struct nfs_page *req, struct nfs_commit_info *cinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) mutex_lock(&NFS_I(cinfo->inode)->commit_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) nfs_request_add_commit_list_locked(req, &cinfo->mds->list, cinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) mutex_unlock(&NFS_I(cinfo->inode)->commit_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) if (req->wb_page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) nfs_mark_page_unstable(req->wb_page, cinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) EXPORT_SYMBOL_GPL(nfs_request_add_commit_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) * nfs_request_remove_commit_list - Remove request from a commit list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) * @req: pointer to a nfs_page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) * @cinfo: holds list lock and accounting info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) * This clears the PG_CLEAN bit, and updates the cinfo's count of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) * number of outstanding requests requiring a commit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) * It does not update the MM page stats.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) * The caller _must_ hold the cinfo->lock and the nfs_page lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) nfs_request_remove_commit_list(struct nfs_page *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) struct nfs_commit_info *cinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) if (!test_and_clear_bit(PG_CLEAN, &(req)->wb_flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) nfs_list_remove_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) atomic_long_dec(&cinfo->mds->ncommit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) EXPORT_SYMBOL_GPL(nfs_request_remove_commit_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) static void nfs_init_cinfo_from_inode(struct nfs_commit_info *cinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) cinfo->inode = inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) cinfo->mds = &NFS_I(inode)->commit_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) cinfo->ds = pnfs_get_ds_info(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) cinfo->dreq = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) cinfo->completion_ops = &nfs_commit_completion_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) void nfs_init_cinfo(struct nfs_commit_info *cinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) struct nfs_direct_req *dreq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) if (dreq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) nfs_init_cinfo_from_dreq(cinfo, dreq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) nfs_init_cinfo_from_inode(cinfo, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) EXPORT_SYMBOL_GPL(nfs_init_cinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) * Add a request to the inode's commit list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) nfs_mark_request_commit(struct nfs_page *req, struct pnfs_layout_segment *lseg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) struct nfs_commit_info *cinfo, u32 ds_commit_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) if (pnfs_mark_request_commit(req, lseg, cinfo, ds_commit_idx))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) nfs_request_add_commit_list(req, cinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) nfs_clear_page_commit(struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) dec_node_page_state(page, NR_WRITEBACK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) dec_wb_stat(&inode_to_bdi(page_file_mapping(page)->host)->wb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) WB_WRITEBACK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) /* Called holding the request lock on @req */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) nfs_clear_request_commit(struct nfs_page *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) if (test_bit(PG_CLEAN, &req->wb_flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) struct nfs_open_context *ctx = nfs_req_openctx(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) struct inode *inode = d_inode(ctx->dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) struct nfs_commit_info cinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) nfs_init_cinfo_from_inode(&cinfo, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) mutex_lock(&NFS_I(inode)->commit_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) if (!pnfs_clear_request_commit(req, &cinfo)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) nfs_request_remove_commit_list(req, &cinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) mutex_unlock(&NFS_I(inode)->commit_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) nfs_clear_page_commit(req->wb_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) int nfs_write_need_commit(struct nfs_pgio_header *hdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) if (hdr->verf.committed == NFS_DATA_SYNC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) return hdr->lseg == NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) return hdr->verf.committed != NFS_FILE_SYNC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) static void nfs_async_write_init(struct nfs_pgio_header *hdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) nfs_io_completion_get(hdr->io_completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) static void nfs_write_completion(struct nfs_pgio_header *hdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) struct nfs_commit_info cinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) unsigned long bytes = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) if (test_bit(NFS_IOHDR_REDO, &hdr->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) nfs_init_cinfo_from_inode(&cinfo, hdr->inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) while (!list_empty(&hdr->pages)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) struct nfs_page *req = nfs_list_entry(hdr->pages.next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) bytes += req->wb_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) nfs_list_remove_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) if (test_bit(NFS_IOHDR_ERROR, &hdr->flags) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) (hdr->good_bytes < bytes)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) trace_nfs_comp_error(req, hdr->error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) nfs_mapping_set_error(req->wb_page, hdr->error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) goto remove_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) if (nfs_write_need_commit(hdr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) /* Reset wb_nio, since the write was successful. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) req->wb_nio = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) memcpy(&req->wb_verf, &hdr->verf.verifier, sizeof(req->wb_verf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) nfs_mark_request_commit(req, hdr->lseg, &cinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) hdr->pgio_mirror_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) goto next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) remove_req:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) nfs_inode_remove_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) next:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) nfs_end_page_writeback(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) nfs_release_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) nfs_io_completion_put(hdr->io_completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) hdr->release(hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) unsigned long
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) nfs_reqs_to_commit(struct nfs_commit_info *cinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) return atomic_long_read(&cinfo->mds->ncommit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) /* NFS_I(cinfo->inode)->commit_mutex held by caller */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) nfs_scan_commit_list(struct list_head *src, struct list_head *dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) struct nfs_commit_info *cinfo, int max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) struct nfs_page *req, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) list_for_each_entry_safe(req, tmp, src, wb_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) kref_get(&req->wb_kref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) if (!nfs_lock_request(req)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) nfs_release_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) nfs_request_remove_commit_list(req, cinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) clear_bit(PG_COMMIT_TO_DS, &req->wb_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) nfs_list_add_request(req, dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) ret++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) if ((ret == max) && !cinfo->dreq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) cond_resched();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) EXPORT_SYMBOL_GPL(nfs_scan_commit_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) * nfs_scan_commit - Scan an inode for commit requests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) * @inode: NFS inode to scan
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) * @dst: mds destination list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) * @cinfo: mds and ds lists of reqs ready to commit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) * Moves requests from the inode's 'commit' request list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) * The requests are *not* checked to ensure that they form a contiguous set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) nfs_scan_commit(struct inode *inode, struct list_head *dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) struct nfs_commit_info *cinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) if (!atomic_long_read(&cinfo->mds->ncommit))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) mutex_lock(&NFS_I(cinfo->inode)->commit_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) if (atomic_long_read(&cinfo->mds->ncommit) > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) const int max = INT_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) ret = nfs_scan_commit_list(&cinfo->mds->list, dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) cinfo, max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) ret += pnfs_scan_commit_lists(inode, cinfo, max - ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) mutex_unlock(&NFS_I(cinfo->inode)->commit_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) * Search for an existing write request, and attempt to update
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) * it to reflect a new dirty region on a given page.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) * If the attempt fails, then the existing request is flushed out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) * to disk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) static struct nfs_page *nfs_try_to_update_request(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) struct page *page,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) unsigned int offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) unsigned int bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) struct nfs_page *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) unsigned int rqend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) unsigned int end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) end = offset + bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) req = nfs_lock_and_join_requests(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) if (IS_ERR_OR_NULL(req))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) return req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) rqend = req->wb_offset + req->wb_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) * Tell the caller to flush out the request if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) * the offsets are non-contiguous.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) * Note: nfs_flush_incompatible() will already
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) * have flushed out requests having wrong owners.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) if (offset > rqend || end < req->wb_offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) goto out_flushme;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) /* Okay, the request matches. Update the region */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) if (offset < req->wb_offset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) req->wb_offset = offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) req->wb_pgbase = offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) if (end > rqend)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) req->wb_bytes = end - req->wb_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) req->wb_bytes = rqend - req->wb_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) req->wb_nio = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) return req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) out_flushme:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) * Note: we mark the request dirty here because
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) * nfs_lock_and_join_requests() cannot preserve
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) * commit flags, so we have to replay the write.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) nfs_mark_request_dirty(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) nfs_unlock_and_release_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) error = nfs_wb_page(inode, page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) return (error < 0) ? ERR_PTR(error) : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) * Try to update an existing write request, or create one if there is none.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) * Note: Should always be called with the Page Lock held to prevent races
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) * if we have to add a new request. Also assumes that the caller has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) * already called nfs_flush_incompatible() if necessary.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) static struct nfs_page * nfs_setup_write_request(struct nfs_open_context* ctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) struct page *page, unsigned int offset, unsigned int bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) struct inode *inode = page_file_mapping(page)->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) struct nfs_page *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) req = nfs_try_to_update_request(inode, page, offset, bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) if (req != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) req = nfs_create_request(ctx, page, offset, bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) if (IS_ERR(req))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) nfs_inode_add_request(inode, req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) return req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) static int nfs_writepage_setup(struct nfs_open_context *ctx, struct page *page,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) unsigned int offset, unsigned int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) struct nfs_page *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) req = nfs_setup_write_request(ctx, page, offset, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) if (IS_ERR(req))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) return PTR_ERR(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) /* Update file length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) nfs_grow_file(page, offset, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) nfs_mark_uptodate(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) nfs_mark_request_dirty(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) nfs_unlock_and_release_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) int nfs_flush_incompatible(struct file *file, struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) struct nfs_open_context *ctx = nfs_file_open_context(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) struct nfs_lock_context *l_ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) struct file_lock_context *flctx = file_inode(file)->i_flctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) struct nfs_page *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) int do_flush, status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) * Look for a request corresponding to this page. If there
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) * is one, and it belongs to another file, we flush it out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) * before we try to copy anything into the page. Do this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) * due to the lack of an ACCESS-type call in NFSv2.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) * Also do the same if we find a request from an existing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) * dropped page.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) req = nfs_page_find_head_request(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) if (req == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) l_ctx = req->wb_lock_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) do_flush = req->wb_page != page ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) !nfs_match_open_context(nfs_req_openctx(req), ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) if (l_ctx && flctx &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) !(list_empty_careful(&flctx->flc_posix) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) list_empty_careful(&flctx->flc_flock))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) do_flush |= l_ctx->lockowner != current->files;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) nfs_release_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) if (!do_flush)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) status = nfs_wb_page(page_file_mapping(page)->host, page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) } while (status == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) * Avoid buffered writes when a open context credential's key would
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) * expire soon.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) * Returns -EACCES if the key will expire within RPC_KEY_EXPIRE_FAIL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) * Return 0 and set a credential flag which triggers the inode to flush
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) * and performs NFS_FILE_SYNC writes if the key will expired within
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) * RPC_KEY_EXPIRE_TIMEO.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) nfs_key_timeout_notify(struct file *filp, struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) struct nfs_open_context *ctx = nfs_file_open_context(filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) if (nfs_ctx_key_to_expire(ctx, inode) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) !ctx->ll_cred)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) /* Already expired! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) * Test if the open context credential key is marked to expire soon.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) bool nfs_ctx_key_to_expire(struct nfs_open_context *ctx, struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) struct rpc_auth *auth = NFS_SERVER(inode)->client->cl_auth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) struct rpc_cred *cred = ctx->ll_cred;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) struct auth_cred acred = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) .cred = ctx->cred,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) if (cred && !cred->cr_ops->crmatch(&acred, cred, 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) put_rpccred(cred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) ctx->ll_cred = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) cred = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) if (!cred)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) cred = auth->au_ops->lookup_cred(auth, &acred, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) if (!cred || IS_ERR(cred))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) ctx->ll_cred = cred;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) return !!(cred->cr_ops->crkey_timeout &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) cred->cr_ops->crkey_timeout(cred));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) * If the page cache is marked as unsafe or invalid, then we can't rely on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) * the PageUptodate() flag. In this case, we will need to turn off
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) * write optimisations that depend on the page contents being correct.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) static bool nfs_write_pageuptodate(struct page *page, struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) struct nfs_inode *nfsi = NFS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) if (nfs_have_delegated_attributes(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) if (nfsi->cache_validity & NFS_INO_REVAL_PAGECACHE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) smp_rmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) if (test_bit(NFS_INO_INVALIDATING, &nfsi->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) if (nfsi->cache_validity & NFS_INO_INVALID_DATA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) return PageUptodate(page) != 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) static bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) is_whole_file_wrlock(struct file_lock *fl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) return fl->fl_start == 0 && fl->fl_end == OFFSET_MAX &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) fl->fl_type == F_WRLCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) /* If we know the page is up to date, and we're not using byte range locks (or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) * if we have the whole file locked for writing), it may be more efficient to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) * extend the write to cover the entire page in order to avoid fragmentation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) * inefficiencies.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) * If the file is opened for synchronous writes then we can just skip the rest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) * of the checks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) static int nfs_can_extend_write(struct file *file, struct page *page, struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) struct file_lock_context *flctx = inode->i_flctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) struct file_lock *fl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) if (file->f_flags & O_DSYNC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) if (!nfs_write_pageuptodate(page, inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) if (NFS_PROTO(inode)->have_delegation(inode, FMODE_WRITE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) if (!flctx || (list_empty_careful(&flctx->flc_flock) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) list_empty_careful(&flctx->flc_posix)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) /* Check to see if there are whole file write locks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) spin_lock(&flctx->flc_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) if (!list_empty(&flctx->flc_posix)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) fl = list_first_entry(&flctx->flc_posix, struct file_lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) fl_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) if (is_whole_file_wrlock(fl))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) ret = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) } else if (!list_empty(&flctx->flc_flock)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) fl = list_first_entry(&flctx->flc_flock, struct file_lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) fl_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) if (fl->fl_type == F_WRLCK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) ret = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) spin_unlock(&flctx->flc_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) * Update and possibly write a cached page of an NFS file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) * XXX: Keep an eye on generic_file_read to make sure it doesn't do bad
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) * things with a page scheduled for an RPC call (e.g. invalidate it).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) int nfs_updatepage(struct file *file, struct page *page,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) unsigned int offset, unsigned int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) struct nfs_open_context *ctx = nfs_file_open_context(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) struct address_space *mapping = page_file_mapping(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) struct inode *inode = mapping->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) int status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) nfs_inc_stats(inode, NFSIOS_VFSUPDATEPAGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) dprintk("NFS: nfs_updatepage(%pD2 %d@%lld)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) file, count, (long long)(page_file_offset(page) + offset));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) if (!count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) if (nfs_can_extend_write(file, page, inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) count = max(count + offset, nfs_page_length(page));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) status = nfs_writepage_setup(ctx, page, offset, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) if (status < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) nfs_set_pageerror(mapping);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) __set_page_dirty_nobuffers(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) dprintk("NFS: nfs_updatepage returns %d (isize %lld)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) status, (long long)i_size_read(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) static int flush_task_priority(int how)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) switch (how & (FLUSH_HIGHPRI|FLUSH_LOWPRI)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) case FLUSH_HIGHPRI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) return RPC_PRIORITY_HIGH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) case FLUSH_LOWPRI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) return RPC_PRIORITY_LOW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) return RPC_PRIORITY_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) static void nfs_initiate_write(struct nfs_pgio_header *hdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) struct rpc_message *msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) const struct nfs_rpc_ops *rpc_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) struct rpc_task_setup *task_setup_data, int how)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) int priority = flush_task_priority(how);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) task_setup_data->priority = priority;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) rpc_ops->write_setup(hdr, msg, &task_setup_data->rpc_client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) trace_nfs_initiate_write(hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) /* If a nfs_flush_* function fails, it should remove reqs from @head and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) * call this on each, which will prepare them to be retried on next
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) * writeback using standard nfs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) static void nfs_redirty_request(struct nfs_page *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) /* Bump the transmission count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) req->wb_nio++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) nfs_mark_request_dirty(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) set_bit(NFS_CONTEXT_RESEND_WRITES, &nfs_req_openctx(req)->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) nfs_end_page_writeback(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) nfs_release_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) static void nfs_async_write_error(struct list_head *head, int error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) struct nfs_page *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) while (!list_empty(head)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) req = nfs_list_entry(head->next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) nfs_list_remove_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) if (nfs_error_is_fatal(error))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) nfs_write_error(req, error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) nfs_redirty_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) static void nfs_async_write_reschedule_io(struct nfs_pgio_header *hdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) nfs_async_write_error(&hdr->pages, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) filemap_fdatawrite_range(hdr->inode->i_mapping, hdr->args.offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) hdr->args.offset + hdr->args.count - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) static const struct nfs_pgio_completion_ops nfs_async_write_completion_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) .init_hdr = nfs_async_write_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) .error_cleanup = nfs_async_write_error,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) .completion = nfs_write_completion,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) .reschedule_io = nfs_async_write_reschedule_io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) void nfs_pageio_init_write(struct nfs_pageio_descriptor *pgio,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) struct inode *inode, int ioflags, bool force_mds,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) const struct nfs_pgio_completion_ops *compl_ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) struct nfs_server *server = NFS_SERVER(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) const struct nfs_pageio_ops *pg_ops = &nfs_pgio_rw_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) #ifdef CONFIG_NFS_V4_1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) if (server->pnfs_curr_ld && !force_mds)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) pg_ops = server->pnfs_curr_ld->pg_write_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) nfs_pageio_init(pgio, inode, pg_ops, compl_ops, &nfs_rw_write_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) server->wsize, ioflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) EXPORT_SYMBOL_GPL(nfs_pageio_init_write);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) void nfs_pageio_reset_write_mds(struct nfs_pageio_descriptor *pgio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) struct nfs_pgio_mirror *mirror;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) if (pgio->pg_ops && pgio->pg_ops->pg_cleanup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) pgio->pg_ops->pg_cleanup(pgio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) pgio->pg_ops = &nfs_pgio_rw_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) nfs_pageio_stop_mirroring(pgio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) mirror = &pgio->pg_mirrors[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) mirror->pg_bsize = NFS_SERVER(pgio->pg_inode)->wsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) EXPORT_SYMBOL_GPL(nfs_pageio_reset_write_mds);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) void nfs_commit_prepare(struct rpc_task *task, void *calldata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) struct nfs_commit_data *data = calldata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) NFS_PROTO(data->inode)->commit_rpc_prepare(task, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) * Special version of should_remove_suid() that ignores capabilities.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) static int nfs_should_remove_suid(const struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) umode_t mode = inode->i_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) int kill = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) /* suid always must be killed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) if (unlikely(mode & S_ISUID))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) kill = ATTR_KILL_SUID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) * sgid without any exec bits is just a mandatory locking mark; leave
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) * it alone. If some exec bits are set, it's a real sgid; kill it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) if (unlikely((mode & S_ISGID) && (mode & S_IXGRP)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) kill |= ATTR_KILL_SGID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) if (unlikely(kill && S_ISREG(mode)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) return kill;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) static void nfs_writeback_check_extend(struct nfs_pgio_header *hdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) struct nfs_fattr *fattr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) struct nfs_pgio_args *argp = &hdr->args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) struct nfs_pgio_res *resp = &hdr->res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) u64 size = argp->offset + resp->count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) if (!(fattr->valid & NFS_ATTR_FATTR_SIZE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) fattr->size = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) if (nfs_size_to_loff_t(fattr->size) < i_size_read(hdr->inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) fattr->valid &= ~NFS_ATTR_FATTR_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) if (size != fattr->size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) /* Set attribute barrier */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) nfs_fattr_set_barrier(fattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) /* ...and update size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) fattr->valid |= NFS_ATTR_FATTR_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) void nfs_writeback_update_inode(struct nfs_pgio_header *hdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) struct nfs_fattr *fattr = &hdr->fattr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) struct inode *inode = hdr->inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) spin_lock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) nfs_writeback_check_extend(hdr, fattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) nfs_post_op_update_inode_force_wcc_locked(inode, fattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) spin_unlock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) EXPORT_SYMBOL_GPL(nfs_writeback_update_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) * This function is called when the WRITE call is complete.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) static int nfs_writeback_done(struct rpc_task *task,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) struct nfs_pgio_header *hdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) * ->write_done will attempt to use post-op attributes to detect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) * conflicting writes by other clients. A strict interpretation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) * of close-to-open would allow us to continue caching even if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) * another writer had changed the file, but some applications
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) * depend on tighter cache coherency when writing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) status = NFS_PROTO(inode)->write_done(task, hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) if (status != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) nfs_add_stats(inode, NFSIOS_SERVERWRITTENBYTES, hdr->res.count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) trace_nfs_writeback_done(task, hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) if (hdr->res.verf->committed < hdr->args.stable &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) task->tk_status >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) /* We tried a write call, but the server did not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) * commit data to stable storage even though we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) * requested it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) * Note: There is a known bug in Tru64 < 5.0 in which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) * the server reports NFS_DATA_SYNC, but performs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) * NFS_FILE_SYNC. We therefore implement this checking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) * as a dprintk() in order to avoid filling syslog.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) static unsigned long complain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) /* Note this will print the MDS for a DS write */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) if (time_before(complain, jiffies)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) dprintk("NFS: faulty NFS server %s:"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) " (committed = %d) != (stable = %d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) NFS_SERVER(inode)->nfs_client->cl_hostname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) hdr->res.verf->committed, hdr->args.stable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) complain = jiffies + 300 * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) /* Deal with the suid/sgid bit corner case */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) if (nfs_should_remove_suid(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) spin_lock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) NFS_I(inode)->cache_validity |= NFS_INO_INVALID_OTHER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) spin_unlock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) * This function is called when the WRITE call is complete.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) static void nfs_writeback_result(struct rpc_task *task,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) struct nfs_pgio_header *hdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) struct nfs_pgio_args *argp = &hdr->args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) struct nfs_pgio_res *resp = &hdr->res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) if (resp->count < argp->count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) static unsigned long complain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) /* This a short write! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) nfs_inc_stats(hdr->inode, NFSIOS_SHORTWRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) /* Has the server at least made some progress? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) if (resp->count == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) if (time_before(complain, jiffies)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) printk(KERN_WARNING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) "NFS: Server wrote zero bytes, expected %u.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) argp->count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) complain = jiffies + 300 * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) nfs_set_pgio_error(hdr, -EIO, argp->offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) task->tk_status = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) /* For non rpc-based layout drivers, retry-through-MDS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) if (!task->tk_ops) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) hdr->pnfs_error = -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) /* Was this an NFSv2 write or an NFSv3 stable write? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) if (resp->verf->committed != NFS_UNSTABLE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) /* Resend from where the server left off */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) hdr->mds_offset += resp->count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) argp->offset += resp->count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) argp->pgbase += resp->count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) argp->count -= resp->count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) /* Resend as a stable write in order to avoid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) * headaches in the case of a server crash.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) argp->stable = NFS_FILE_SYNC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) resp->count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) resp->verf->committed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) rpc_restart_call_prepare(task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) static int wait_on_commit(struct nfs_mds_commit_info *cinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) return wait_var_event_killable(&cinfo->rpcs_out,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) !atomic_read(&cinfo->rpcs_out));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) static void nfs_commit_begin(struct nfs_mds_commit_info *cinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) atomic_inc(&cinfo->rpcs_out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) bool nfs_commit_end(struct nfs_mds_commit_info *cinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) if (atomic_dec_and_test(&cinfo->rpcs_out)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) wake_up_var(&cinfo->rpcs_out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) void nfs_commitdata_release(struct nfs_commit_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) put_nfs_open_context(data->context);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) nfs_commit_free(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) EXPORT_SYMBOL_GPL(nfs_commitdata_release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) int nfs_initiate_commit(struct rpc_clnt *clnt, struct nfs_commit_data *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) const struct nfs_rpc_ops *nfs_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) const struct rpc_call_ops *call_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) int how, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) struct rpc_task *task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) int priority = flush_task_priority(how);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) struct rpc_message msg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) .rpc_argp = &data->args,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) .rpc_resp = &data->res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) .rpc_cred = data->cred,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) struct rpc_task_setup task_setup_data = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) .task = &data->task,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) .rpc_client = clnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) .rpc_message = &msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) .callback_ops = call_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) .callback_data = data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) .workqueue = nfsiod_workqueue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) .flags = RPC_TASK_ASYNC | flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) .priority = priority,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) /* Set up the initial task struct. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) nfs_ops->commit_setup(data, &msg, &task_setup_data.rpc_client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) trace_nfs_initiate_commit(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) dprintk("NFS: initiated commit call\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) task = rpc_run_task(&task_setup_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) if (IS_ERR(task))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) return PTR_ERR(task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) if (how & FLUSH_SYNC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) rpc_wait_for_completion_task(task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) rpc_put_task(task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) EXPORT_SYMBOL_GPL(nfs_initiate_commit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) static loff_t nfs_get_lwb(struct list_head *head)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) loff_t lwb = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) struct nfs_page *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) list_for_each_entry(req, head, wb_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) if (lwb < (req_offset(req) + req->wb_bytes))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) lwb = req_offset(req) + req->wb_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) return lwb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) * Set up the argument/result storage required for the RPC call.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) void nfs_init_commit(struct nfs_commit_data *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) struct list_head *head,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) struct pnfs_layout_segment *lseg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) struct nfs_commit_info *cinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) struct nfs_page *first;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) struct nfs_open_context *ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) /* Set up the RPC argument and reply structs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) * NB: take care not to mess about with data->commit et al. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) if (head)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) list_splice_init(head, &data->pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) first = nfs_list_entry(data->pages.next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) ctx = nfs_req_openctx(first);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) inode = d_inode(ctx->dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) data->inode = inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) data->cred = ctx->cred;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) data->lseg = lseg; /* reference transferred */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) /* only set lwb for pnfs commit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) if (lseg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) data->lwb = nfs_get_lwb(&data->pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) data->mds_ops = &nfs_commit_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) data->completion_ops = cinfo->completion_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) data->dreq = cinfo->dreq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) data->args.fh = NFS_FH(data->inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) /* Note: we always request a commit of the entire inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) data->args.offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) data->args.count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) data->context = get_nfs_open_context(ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) data->res.fattr = &data->fattr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) data->res.verf = &data->verf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) nfs_fattr_init(&data->fattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) nfs_commit_begin(cinfo->mds);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) EXPORT_SYMBOL_GPL(nfs_init_commit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) void nfs_retry_commit(struct list_head *page_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) struct pnfs_layout_segment *lseg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) struct nfs_commit_info *cinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) u32 ds_commit_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) struct nfs_page *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) while (!list_empty(page_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) req = nfs_list_entry(page_list->next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) nfs_list_remove_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) nfs_mark_request_commit(req, lseg, cinfo, ds_commit_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) if (!cinfo->dreq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) nfs_clear_page_commit(req->wb_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) nfs_unlock_and_release_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) EXPORT_SYMBOL_GPL(nfs_retry_commit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) nfs_commit_resched_write(struct nfs_commit_info *cinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) struct nfs_page *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) __set_page_dirty_nobuffers(req->wb_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) * Commit dirty pages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) nfs_commit_list(struct inode *inode, struct list_head *head, int how,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) struct nfs_commit_info *cinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) struct nfs_commit_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) /* another commit raced with us */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) if (list_empty(head))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) data = nfs_commitdata_alloc(true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) /* Set up the argument struct */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) nfs_init_commit(data, head, NULL, cinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) return nfs_initiate_commit(NFS_CLIENT(inode), data, NFS_PROTO(inode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) data->mds_ops, how, RPC_TASK_CRED_NOREF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) * COMMIT call returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) static void nfs_commit_done(struct rpc_task *task, void *calldata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) struct nfs_commit_data *data = calldata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) dprintk("NFS: %5u nfs_commit_done (status %d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) task->tk_pid, task->tk_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) /* Call the NFS version-specific code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) NFS_PROTO(data->inode)->commit_done(task, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) trace_nfs_commit_done(task, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) static void nfs_commit_release_pages(struct nfs_commit_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) const struct nfs_writeverf *verf = data->res.verf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) struct nfs_page *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) int status = data->task.tk_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) struct nfs_commit_info cinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) struct nfs_server *nfss;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) while (!list_empty(&data->pages)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) req = nfs_list_entry(data->pages.next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) nfs_list_remove_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) if (req->wb_page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) nfs_clear_page_commit(req->wb_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) dprintk("NFS: commit (%s/%llu %d@%lld)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) nfs_req_openctx(req)->dentry->d_sb->s_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) (unsigned long long)NFS_FILEID(d_inode(nfs_req_openctx(req)->dentry)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) req->wb_bytes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) (long long)req_offset(req));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) if (status < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) if (req->wb_page) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) trace_nfs_commit_error(req, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) nfs_mapping_set_error(req->wb_page, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) nfs_inode_remove_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) dprintk_cont(", error = %d\n", status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) goto next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) /* Okay, COMMIT succeeded, apparently. Check the verifier
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) * returned by the server against all stored verfs. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) if (nfs_write_match_verf(verf, req)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) /* We have a match */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) if (req->wb_page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) nfs_inode_remove_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) dprintk_cont(" OK\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) goto next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) /* We have a mismatch. Write the page again */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) dprintk_cont(" mismatch\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) nfs_mark_request_dirty(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) set_bit(NFS_CONTEXT_RESEND_WRITES, &nfs_req_openctx(req)->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) next:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) nfs_unlock_and_release_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) /* Latency breaker */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) cond_resched();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) nfss = NFS_SERVER(data->inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) if (atomic_long_read(&nfss->writeback) < NFS_CONGESTION_OFF_THRESH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) clear_bdi_congested(inode_to_bdi(data->inode), BLK_RW_ASYNC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) nfs_init_cinfo(&cinfo, data->inode, data->dreq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) nfs_commit_end(cinfo.mds);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) static void nfs_commit_release(void *calldata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) struct nfs_commit_data *data = calldata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) data->completion_ops->completion(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) nfs_commitdata_release(calldata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) static const struct rpc_call_ops nfs_commit_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) .rpc_call_prepare = nfs_commit_prepare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) .rpc_call_done = nfs_commit_done,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) .rpc_release = nfs_commit_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) static const struct nfs_commit_completion_ops nfs_commit_completion_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) .completion = nfs_commit_release_pages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) .resched_write = nfs_commit_resched_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) int nfs_generic_commit_list(struct inode *inode, struct list_head *head,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) int how, struct nfs_commit_info *cinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) status = pnfs_commit_list(inode, head, how, cinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) if (status == PNFS_NOT_ATTEMPTED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) status = nfs_commit_list(inode, head, how, cinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) static int __nfs_commit_inode(struct inode *inode, int how,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) struct writeback_control *wbc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) LIST_HEAD(head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) struct nfs_commit_info cinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) int may_wait = how & FLUSH_SYNC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) int ret, nscan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) how &= ~FLUSH_SYNC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) nfs_init_cinfo_from_inode(&cinfo, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) nfs_commit_begin(cinfo.mds);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) ret = nscan = nfs_scan_commit(inode, &head, &cinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) if (ret <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) ret = nfs_generic_commit_list(inode, &head, how, &cinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) if (wbc && wbc->sync_mode == WB_SYNC_NONE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) if (nscan < wbc->nr_to_write)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) wbc->nr_to_write -= nscan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) wbc->nr_to_write = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) if (nscan < INT_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) cond_resched();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) nfs_commit_end(cinfo.mds);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) if (ret || !may_wait)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) return wait_on_commit(cinfo.mds);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) int nfs_commit_inode(struct inode *inode, int how)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) return __nfs_commit_inode(inode, how, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) EXPORT_SYMBOL_GPL(nfs_commit_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) int nfs_write_inode(struct inode *inode, struct writeback_control *wbc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) struct nfs_inode *nfsi = NFS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) int flags = FLUSH_SYNC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) if (wbc->sync_mode == WB_SYNC_NONE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) /* no commits means nothing needs to be done */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) if (!atomic_long_read(&nfsi->commit_info.ncommit))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) goto check_requests_outstanding;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) /* Don't commit yet if this is a non-blocking flush and there
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) * are a lot of outstanding writes for this mapping.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) if (mapping_tagged(inode->i_mapping, PAGECACHE_TAG_WRITEBACK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) goto out_mark_dirty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) /* don't wait for the COMMIT response */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) ret = __nfs_commit_inode(inode, flags, wbc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) if (flags & FLUSH_SYNC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) } else if (atomic_long_read(&nfsi->commit_info.ncommit))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) goto out_mark_dirty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) check_requests_outstanding:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) if (!atomic_read(&nfsi->commit_info.rpcs_out))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) out_mark_dirty:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) __mark_inode_dirty(inode, I_DIRTY_DATASYNC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) EXPORT_SYMBOL_GPL(nfs_write_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) * Wrapper for filemap_write_and_wait_range()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) * Needed for pNFS in order to ensure data becomes visible to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) * client.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) int nfs_filemap_write_and_wait_range(struct address_space *mapping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) loff_t lstart, loff_t lend)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) ret = filemap_write_and_wait_range(mapping, lstart, lend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) if (ret == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) ret = pnfs_sync_inode(mapping->host, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) EXPORT_SYMBOL_GPL(nfs_filemap_write_and_wait_range);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) * flush the inode to disk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) int nfs_wb_all(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) trace_nfs_writeback_inode_enter(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) ret = filemap_write_and_wait(inode->i_mapping);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) ret = nfs_commit_inode(inode, FLUSH_SYNC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) pnfs_sync_inode(inode, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) trace_nfs_writeback_inode_exit(inode, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) EXPORT_SYMBOL_GPL(nfs_wb_all);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) int nfs_wb_page_cancel(struct inode *inode, struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) struct nfs_page *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) wait_on_page_writeback(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) /* blocking call to cancel all requests and join to a single (head)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) * request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) req = nfs_lock_and_join_requests(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) if (IS_ERR(req)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) ret = PTR_ERR(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) } else if (req) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) /* all requests from this page have been cancelled by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) * nfs_lock_and_join_requests, so just remove the head
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) * request from the inode / page_private pointer and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) * release it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) nfs_inode_remove_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) nfs_unlock_and_release_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) * Write back all requests on one page - we do this before reading it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) int nfs_wb_page(struct inode *inode, struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) loff_t range_start = page_file_offset(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) loff_t range_end = range_start + (loff_t)(PAGE_SIZE - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) struct writeback_control wbc = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) .sync_mode = WB_SYNC_ALL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) .nr_to_write = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) .range_start = range_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) .range_end = range_end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) trace_nfs_writeback_page_enter(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) wait_on_page_writeback(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) if (clear_page_dirty_for_io(page)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) ret = nfs_writepage_locked(page, &wbc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) goto out_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) if (!PagePrivate(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) ret = nfs_commit_inode(inode, FLUSH_SYNC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) goto out_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) out_error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) trace_nfs_writeback_page_exit(inode, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093) #ifdef CONFIG_MIGRATION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) int nfs_migrate_page(struct address_space *mapping, struct page *newpage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) struct page *page, enum migrate_mode mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) * If PagePrivate is set, then the page is currently associated with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) * an in-progress read or write request. Don't try to migrate it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) * FIXME: we could do this in principle, but we'll need a way to ensure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) * that we can safely release the inode reference while holding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) * the page lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) if (PagePrivate(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) if (!nfs_fscache_release_page(page, GFP_KERNEL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) return migrate_page(mapping, newpage, page, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) int __init nfs_init_writepagecache(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117) nfs_wdata_cachep = kmem_cache_create("nfs_write_data",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) sizeof(struct nfs_pgio_header),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119) 0, SLAB_HWCACHE_ALIGN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121) if (nfs_wdata_cachep == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) nfs_wdata_mempool = mempool_create_slab_pool(MIN_POOL_WRITE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) nfs_wdata_cachep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) if (nfs_wdata_mempool == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) goto out_destroy_write_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) nfs_cdata_cachep = kmem_cache_create("nfs_commit_data",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) sizeof(struct nfs_commit_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) 0, SLAB_HWCACHE_ALIGN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) if (nfs_cdata_cachep == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) goto out_destroy_write_mempool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) nfs_commit_mempool = mempool_create_slab_pool(MIN_POOL_COMMIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) nfs_cdata_cachep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) if (nfs_commit_mempool == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) goto out_destroy_commit_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) * NFS congestion size, scale with available memory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) * 64MB: 8192k
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) * 128MB: 11585k
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) * 256MB: 16384k
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) * 512MB: 23170k
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) * 1GB: 32768k
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) * 2GB: 46340k
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150) * 4GB: 65536k
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) * 8GB: 92681k
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) * 16GB: 131072k
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) * This allows larger machines to have larger/more transfers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) * Limit the default to 256M
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) nfs_congestion_kb = (16*int_sqrt(totalram_pages())) << (PAGE_SHIFT-10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) if (nfs_congestion_kb > 256*1024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) nfs_congestion_kb = 256*1024;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) out_destroy_commit_cache:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) kmem_cache_destroy(nfs_cdata_cachep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) out_destroy_write_mempool:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) mempool_destroy(nfs_wdata_mempool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167) out_destroy_write_cache:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) kmem_cache_destroy(nfs_wdata_cachep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) void nfs_destroy_writepagecache(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) mempool_destroy(nfs_commit_mempool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) kmem_cache_destroy(nfs_cdata_cachep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) mempool_destroy(nfs_wdata_mempool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) kmem_cache_destroy(nfs_wdata_cachep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180) static const struct nfs_rw_ops nfs_rw_write_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) .rw_alloc_header = nfs_writehdr_alloc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182) .rw_free_header = nfs_writehdr_free,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) .rw_done = nfs_writeback_done,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) .rw_result = nfs_writeback_result,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185) .rw_initiate = nfs_initiate_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186) };