Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /* AFS filesystem file handling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (C) 2002, 2007 Red Hat, Inc. All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Written by David Howells (dhowells@redhat.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/pagemap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/writeback.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/gfp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/task_io_accounting_ops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include "internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) static int afs_file_mmap(struct file *file, struct vm_area_struct *vma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) static int afs_readpage(struct file *file, struct page *page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) static void afs_invalidatepage(struct page *page, unsigned int offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 			       unsigned int length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) static int afs_releasepage(struct page *page, gfp_t gfp_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) static int afs_readpages(struct file *filp, struct address_space *mapping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 			 struct list_head *pages, unsigned nr_pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) const struct file_operations afs_file_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	.open		= afs_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	.release	= afs_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	.llseek		= generic_file_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	.read_iter	= generic_file_read_iter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	.write_iter	= afs_file_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	.mmap		= afs_file_mmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	.splice_read	= generic_file_splice_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	.splice_write	= iter_file_splice_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	.fsync		= afs_fsync,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	.lock		= afs_lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	.flock		= afs_flock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) const struct inode_operations afs_file_inode_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	.getattr	= afs_getattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	.setattr	= afs_setattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	.permission	= afs_permission,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) const struct address_space_operations afs_fs_aops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	.readpage	= afs_readpage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	.readpages	= afs_readpages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	.set_page_dirty	= afs_set_page_dirty,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	.launder_page	= afs_launder_page,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	.releasepage	= afs_releasepage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	.invalidatepage	= afs_invalidatepage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	.write_begin	= afs_write_begin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	.write_end	= afs_write_end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	.writepage	= afs_writepage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	.writepages	= afs_writepages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) static const struct vm_operations_struct afs_vm_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	.fault		= filemap_fault,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	.map_pages	= filemap_map_pages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	.page_mkwrite	= afs_page_mkwrite,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68)  * Discard a pin on a writeback key.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) void afs_put_wb_key(struct afs_wb_key *wbk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	if (wbk && refcount_dec_and_test(&wbk->usage)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		key_put(wbk->key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		kfree(wbk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79)  * Cache key for writeback.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) int afs_cache_wb_key(struct afs_vnode *vnode, struct afs_file *af)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	struct afs_wb_key *wbk, *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	wbk = kzalloc(sizeof(struct afs_wb_key), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	if (!wbk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	refcount_set(&wbk->usage, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	wbk->key = af->key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	spin_lock(&vnode->wb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	list_for_each_entry(p, &vnode->wb_keys, vnode_link) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		if (p->key == wbk->key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 			goto found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	key_get(wbk->key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	list_add_tail(&wbk->vnode_link, &vnode->wb_keys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	spin_unlock(&vnode->wb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	af->wb = wbk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) found:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	refcount_inc(&p->usage);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	spin_unlock(&vnode->wb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	af->wb = p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	kfree(wbk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)  * open an AFS file or directory and attach a key to it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) int afs_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	struct afs_vnode *vnode = AFS_FS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	struct afs_file *af;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	struct key *key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	_enter("{%llx:%llu},", vnode->fid.vid, vnode->fid.vnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	key = afs_request_key(vnode->volume->cell);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	if (IS_ERR(key)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		ret = PTR_ERR(key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	af = kzalloc(sizeof(*af), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	if (!af) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		goto error_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	af->key = key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	ret = afs_validate(vnode, key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		goto error_af;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	if (file->f_mode & FMODE_WRITE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		ret = afs_cache_wb_key(vnode, af);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 			goto error_af;
^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) 	if (file->f_flags & O_TRUNC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		set_bit(AFS_VNODE_NEW_CONTENT, &vnode->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	file->private_data = af;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	_leave(" = 0");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) error_af:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	kfree(af);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) error_key:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	key_put(key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	_leave(" = %d", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)  * release an AFS file or directory and discard its key
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) int afs_release(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	struct afs_vnode *vnode = AFS_FS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	struct afs_file *af = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	_enter("{%llx:%llu},", vnode->fid.vid, vnode->fid.vnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	if ((file->f_mode & FMODE_WRITE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		ret = vfs_fsync(file, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	file->private_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	if (af->wb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		afs_put_wb_key(af->wb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	key_put(af->key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	kfree(af);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	afs_prune_wb_keys(vnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	_leave(" = %d", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	return ret;
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)  * Dispose of a ref to a read record.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) void afs_put_read(struct afs_read *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	if (refcount_dec_and_test(&req->usage)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		if (req->pages) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 			for (i = 0; i < req->nr_pages; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 				if (req->pages[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 					put_page(req->pages[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 			if (req->pages != req->array)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 				kfree(req->pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		kfree(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) #ifdef CONFIG_AFS_FSCACHE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)  * deal with notification that a page was read from the cache
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) static void afs_file_readpage_read_complete(struct page *page,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 					    void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 					    int error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	_enter("%p,%p,%d", page, data, error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	/* if the read completes with an error, we just unlock the page and let
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	 * the VM reissue the readpage */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	if (!error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		SetPageUptodate(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) static void afs_fetch_data_success(struct afs_operation *op)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	struct afs_vnode *vnode = op->file[0].vnode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	_enter("op=%08x", op->debug_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	afs_vnode_commit_status(op, &op->file[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	afs_stat_v(vnode, n_fetches);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	atomic_long_add(op->fetch.req->actual_len, &op->net->n_fetch_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) static void afs_fetch_data_put(struct afs_operation *op)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	afs_put_read(op->fetch.req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) static const struct afs_operation_ops afs_fetch_data_operation = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	.issue_afs_rpc	= afs_fs_fetch_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	.issue_yfs_rpc	= yfs_fs_fetch_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	.success	= afs_fetch_data_success,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	.aborted	= afs_check_for_remote_deletion,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	.put		= afs_fetch_data_put,
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)  * Fetch file data from the volume.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) int afs_fetch_data(struct afs_vnode *vnode, struct key *key, struct afs_read *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	struct afs_operation *op;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	_enter("%s{%llx:%llu.%u},%x,,,",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	       vnode->volume->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	       vnode->fid.vid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	       vnode->fid.vnode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	       vnode->fid.unique,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	       key_serial(key));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	op = afs_alloc_operation(key, vnode->volume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	if (IS_ERR(op))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		return PTR_ERR(op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	afs_op_set_vnode(op, 0, vnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	op->fetch.req	= afs_get_read(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	op->ops		= &afs_fetch_data_operation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	return afs_do_sync_operation(op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)  * read page from file, directory or symlink, given a key to use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) int afs_page_filler(void *data, struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	struct inode *inode = page->mapping->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	struct afs_vnode *vnode = AFS_FS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	struct afs_read *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	struct key *key = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	_enter("{%x},{%lu},{%lu}", key_serial(key), inode->i_ino, page->index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	BUG_ON(!PageLocked(page));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	ret = -ESTALE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	if (test_bit(AFS_VNODE_DELETED, &vnode->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	/* is it cached? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) #ifdef CONFIG_AFS_FSCACHE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	ret = fscache_read_or_alloc_page(vnode->cache,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 					 page,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 					 afs_file_readpage_read_complete,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 					 NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 					 GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	ret = -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	switch (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		/* read BIO submitted (page in cache) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		/* page not yet cached */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	case -ENODATA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		_debug("cache said ENODATA");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 		goto go_on;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 		/* page will not be cached */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	case -ENOBUFS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		_debug("cache said ENOBUFS");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	go_on:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		req = kzalloc(struct_size(req, array, 1), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 		if (!req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 			goto enomem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 		/* We request a full page.  If the page is a partial one at the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 		 * end of the file, the server will return a short read and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		 * unmarshalling code will clear the unfilled space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 		refcount_set(&req->usage, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 		req->pos = (loff_t)page->index << PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 		req->len = PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 		req->nr_pages = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 		req->pages = req->array;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 		req->pages[0] = page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 		get_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 		/* read the contents of the file from the server into the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 		 * page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 		ret = afs_fetch_data(vnode, key, req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 		afs_put_read(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 			if (ret == -ENOENT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 				_debug("got NOENT from server"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 				       " - marking file deleted and stale");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 				set_bit(AFS_VNODE_DELETED, &vnode->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 				ret = -ESTALE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) #ifdef CONFIG_AFS_FSCACHE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 			fscache_uncache_page(vnode->cache, page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 			BUG_ON(PageFsCache(page));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 			if (ret == -EINTR ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 			    ret == -ENOMEM ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 			    ret == -ERESTARTSYS ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 			    ret == -EAGAIN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 				goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 			goto io_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 		SetPageUptodate(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 		/* send the page to the cache */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) #ifdef CONFIG_AFS_FSCACHE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 		if (PageFsCache(page) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 		    fscache_write_page(vnode->cache, page, vnode->status.size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 				       GFP_KERNEL) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 			fscache_uncache_page(vnode->cache, page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 			BUG_ON(PageFsCache(page));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 		unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	_leave(" = 0");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) io_error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	SetPageError(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) enomem:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	_leave(" = %d", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)  * read page from file, directory or symlink, given a file to nominate the key
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)  * to be used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) static int afs_readpage(struct file *file, struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	struct key *key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	if (file) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 		key = afs_file_key(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 		ASSERT(key != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 		ret = afs_page_filler(key, page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 		struct inode *inode = page->mapping->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 		key = afs_request_key(AFS_FS_S(inode->i_sb)->cell);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 		if (IS_ERR(key)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 			ret = PTR_ERR(key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 			ret = afs_page_filler(key, page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 			key_put(key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414)  * Make pages available as they're filled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) static void afs_readpages_page_done(struct afs_read *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) #ifdef CONFIG_AFS_FSCACHE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	struct afs_vnode *vnode = req->vnode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	struct page *page = req->pages[req->index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	req->pages[req->index] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	SetPageUptodate(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	/* send the page to the cache */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) #ifdef CONFIG_AFS_FSCACHE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	if (PageFsCache(page) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	    fscache_write_page(vnode->cache, page, vnode->status.size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 			       GFP_KERNEL) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 		fscache_uncache_page(vnode->cache, page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 		BUG_ON(PageFsCache(page));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) }
^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)  * Read a contiguous set of pages.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) static int afs_readpages_one(struct file *file, struct address_space *mapping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 			     struct list_head *pages)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	struct afs_vnode *vnode = AFS_FS_I(mapping->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	struct afs_read *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	struct list_head *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	struct page *first, *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	struct key *key = afs_file_key(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	pgoff_t index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	int ret, n, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	/* Count the number of contiguous pages at the front of the list.  Note
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	 * that the list goes prev-wards rather than next-wards.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	first = lru_to_page(pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	index = first->index + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	n = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	for (p = first->lru.prev; p != pages; p = p->prev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 		page = list_entry(p, struct page, lru);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 		if (page->index != index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 		index++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 		n++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	req = kzalloc(struct_size(req, array, n), GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	if (!req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	refcount_set(&req->usage, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	req->vnode = vnode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	req->page_done = afs_readpages_page_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	req->pos = first->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	req->pos <<= PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	req->pages = req->array;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	/* Transfer the pages to the request.  We add them in until one fails
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	 * to add to the LRU and then we stop (as that'll make a hole in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	 * contiguous run.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	 * Note that it's possible for the file size to change whilst we're
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	 * doing this, but we rely on the server returning less than we asked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	 * for if the file shrank.  We also rely on this to deal with a partial
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	 * page at the end of the file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 		page = lru_to_page(pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 		list_del(&page->lru);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 		index = page->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 		if (add_to_page_cache_lru(page, mapping, index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 					  readahead_gfp_mask(mapping))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) #ifdef CONFIG_AFS_FSCACHE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 			fscache_uncache_page(vnode->cache, page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 			put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 		req->pages[req->nr_pages++] = page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 		req->len += PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	} while (req->nr_pages < n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	if (req->nr_pages == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 		kfree(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	ret = afs_fetch_data(vnode, key, req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	task_io_account_read(PAGE_SIZE * req->nr_pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 	afs_put_read(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 	if (ret == -ENOENT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 		_debug("got NOENT from server"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 		       " - marking file deleted and stale");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 		set_bit(AFS_VNODE_DELETED, &vnode->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 		ret = -ESTALE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 	for (i = 0; i < req->nr_pages; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 		page = req->pages[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 		if (page) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) #ifdef CONFIG_AFS_FSCACHE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 			fscache_uncache_page(vnode->cache, page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 			SetPageError(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 			unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 	afs_put_read(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541)  * read a set of pages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) static int afs_readpages(struct file *file, struct address_space *mapping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 			 struct list_head *pages, unsigned nr_pages)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 	struct key *key = afs_file_key(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 	struct afs_vnode *vnode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 	_enter("{%d},{%lu},,%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 	       key_serial(key), mapping->host->i_ino, nr_pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 	ASSERT(key != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 	vnode = AFS_FS_I(mapping->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 	if (test_bit(AFS_VNODE_DELETED, &vnode->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 		_leave(" = -ESTALE");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 		return -ESTALE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 	/* attempt to read as many of the pages as possible */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) #ifdef CONFIG_AFS_FSCACHE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 	ret = fscache_read_or_alloc_pages(vnode->cache,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 					  mapping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 					  pages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 					  &nr_pages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 					  afs_file_readpage_read_complete,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 					  NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 					  mapping_gfp_mask(mapping));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 	ret = -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 	switch (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 		/* all pages are being read from the cache */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 	case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 		BUG_ON(!list_empty(pages));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 		BUG_ON(nr_pages != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 		_leave(" = 0 [reading all]");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 		/* there were pages that couldn't be read from the cache */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 	case -ENODATA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 	case -ENOBUFS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 		/* other error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 		_leave(" = %d", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 	while (!list_empty(pages)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 		ret = afs_readpages_one(file, mapping, pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 		if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 	_leave(" = %d [netting]", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) }
^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)  * Adjust the dirty region of the page on truncation or full invalidation,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605)  * getting rid of the markers altogether if the region is entirely invalidated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) static void afs_invalidate_dirty(struct page *page, unsigned int offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 				 unsigned int length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 	struct afs_vnode *vnode = AFS_FS_I(page->mapping->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 	unsigned long priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 	unsigned int f, t, end = offset + length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 	priv = page_private(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 	/* we clean up only if the entire page is being invalidated */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 	if (offset == 0 && length == thp_size(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 		goto full_invalidate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 	 /* If the page was dirtied by page_mkwrite(), the PTE stays writable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 	  * and we don't get another notification to tell us to expand it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 	  * again.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 	  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 	if (afs_is_page_dirty_mmapped(priv))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 	/* We may need to shorten the dirty region */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 	f = afs_page_dirty_from(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 	t = afs_page_dirty_to(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 	if (t <= offset || f >= end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 		return; /* Doesn't overlap */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 	if (f < offset && t > end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 		return; /* Splits the dirty region - just absorb it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 	if (f >= offset && t <= end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 		goto undirty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 	if (f < offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 		t = offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 		f = end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 	if (f == t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 		goto undirty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 	priv = afs_page_dirty(f, t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 	set_page_private(page, priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 	trace_afs_page_dirty(vnode, tracepoint_string("trunc"), page->index, priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) undirty:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 	trace_afs_page_dirty(vnode, tracepoint_string("undirty"), page->index, priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 	clear_page_dirty_for_io(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) full_invalidate:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 	priv = (unsigned long)detach_page_private(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 	trace_afs_page_dirty(vnode, tracepoint_string("inval"), page->index, priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661)  * invalidate part or all of a page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662)  * - release a page and clean up its private data if offset is 0 (indicating
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663)  *   the entire page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) static void afs_invalidatepage(struct page *page, unsigned int offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 			       unsigned int length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 	_enter("{%lu},%u,%u", page->index, offset, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 	BUG_ON(!PageLocked(page));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) #ifdef CONFIG_AFS_FSCACHE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 	/* we clean up only if the entire page is being invalidated */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 	if (offset == 0 && length == PAGE_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 		if (PageFsCache(page)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 			struct afs_vnode *vnode = AFS_FS_I(page->mapping->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 			fscache_wait_on_page_write(vnode->cache, page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 			fscache_uncache_page(vnode->cache, page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 	if (PagePrivate(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 		afs_invalidate_dirty(page, offset, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 	_leave("");
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690)  * release a page and clean up its private state if it's not busy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691)  * - return true if the page can now be released, false if not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) static int afs_releasepage(struct page *page, gfp_t gfp_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 	struct afs_vnode *vnode = AFS_FS_I(page->mapping->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 	unsigned long priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) 	_enter("{{%llx:%llu}[%lu],%lx},%x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) 	       vnode->fid.vid, vnode->fid.vnode, page->index, page->flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) 	       gfp_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) 	/* deny if page is being written to the cache and the caller hasn't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 	 * elected to wait */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) #ifdef CONFIG_AFS_FSCACHE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) 	if (!fscache_maybe_release_page(vnode->cache, page, gfp_flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) 		_leave(" = F [cache busy]");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) 	if (PagePrivate(page)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 		priv = (unsigned long)detach_page_private(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 		trace_afs_page_dirty(vnode, tracepoint_string("rel"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) 				     page->index, priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) 	/* indicate that the page can be released */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) 	_leave(" = T");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723)  * Handle setting up a memory mapping on an AFS file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) static int afs_file_mmap(struct file *file, struct vm_area_struct *vma)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) 	ret = generic_file_mmap(file, vma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) 	if (ret == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) 		vma->vm_ops = &afs_vm_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) }