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-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *  linux/fs/9p/vfs_file.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * This file contians vfs file ops for 9P2000.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *  Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *  Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/inet.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/pagemap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/utsname.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/idr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/uio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <net/9p/9p.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <net/9p/client.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include "v9fs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include "v9fs_vfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include "fid.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include "cache.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) static const struct vm_operations_struct v9fs_file_vm_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) static const struct vm_operations_struct v9fs_mmap_file_vm_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  * v9fs_file_open - open a file (or directory)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  * @inode: inode to be opened
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  * @file: file being opened
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) int v9fs_file_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	struct v9fs_inode *v9inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	struct v9fs_session_info *v9ses;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	struct p9_fid *fid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	int omode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	p9_debug(P9_DEBUG_VFS, "inode: %p file: %p\n", inode, file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	v9inode = V9FS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	v9ses = v9fs_inode2v9ses(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	if (v9fs_proto_dotl(v9ses))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		omode = v9fs_open_to_dotl_flags(file->f_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		omode = v9fs_uflags2omode(file->f_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 					v9fs_proto_dotu(v9ses));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	fid = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	if (!fid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		fid = v9fs_fid_clone(file_dentry(file));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		if (IS_ERR(fid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 			return PTR_ERR(fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		err = p9_client_open(fid, omode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 			p9_client_clunk(fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		if ((file->f_flags & O_APPEND) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 			(!v9fs_proto_dotu(v9ses) && !v9fs_proto_dotl(v9ses)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 			generic_file_llseek(file, 0, SEEK_END);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	file->private_data = fid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	mutex_lock(&v9inode->v_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	if ((v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	    !v9inode->writeback_fid &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	    ((file->f_flags & O_ACCMODE) != O_RDONLY)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		 * clone a fid and add it to writeback_fid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		 * we do it during open time instead of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		 * page dirty time via write_begin/page_mkwrite
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		 * because we want write after unlink usecase
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		 * to work.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		fid = v9fs_writeback_fid(file_dentry(file));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		if (IS_ERR(fid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 			err = PTR_ERR(fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 			mutex_unlock(&v9inode->v_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 			goto out_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		v9inode->writeback_fid = (void *) fid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	mutex_unlock(&v9inode->v_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		v9fs_cache_inode_set_cookie(inode, file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) out_error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	p9_client_clunk(file->private_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	file->private_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)  * v9fs_file_lock - lock a file (or directory)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)  * @filp: file to be locked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)  * @cmd: lock command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)  * @fl: file lock structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)  * Bugs: this looks like a local only lock, we should extend into 9P
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)  *       by using open exclusive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) static int v9fs_file_lock(struct file *filp, int cmd, struct file_lock *fl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	int res = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	struct inode *inode = file_inode(filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	p9_debug(P9_DEBUG_VFS, "filp: %p lock: %p\n", filp, fl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	/* No mandatory locks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	if (__mandatory_lock(inode) && fl->fl_type != F_UNLCK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		return -ENOLCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	if ((IS_SETLK(cmd) || IS_SETLKW(cmd)) && fl->fl_type != F_UNLCK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		filemap_write_and_wait(inode->i_mapping);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		invalidate_mapping_pages(&inode->i_data, 0, -1);
^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) 	return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) static int v9fs_file_do_lock(struct file *filp, int cmd, struct file_lock *fl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	struct p9_flock flock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	struct p9_fid *fid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	uint8_t status = P9_LOCK_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	int res = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	unsigned char fl_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	struct v9fs_session_info *v9ses;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	fid = filp->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	BUG_ON(fid == NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	if ((fl->fl_flags & FL_POSIX) != FL_POSIX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	res = locks_lock_file_wait(filp, fl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	if (res < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	/* convert posix lock to p9 tlock args */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	memset(&flock, 0, sizeof(flock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	/* map the lock type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	switch (fl->fl_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	case F_RDLCK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		flock.type = P9_LOCK_TYPE_RDLCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	case F_WRLCK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		flock.type = P9_LOCK_TYPE_WRLCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	case F_UNLCK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		flock.type = P9_LOCK_TYPE_UNLCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	flock.start = fl->fl_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	if (fl->fl_end == OFFSET_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		flock.length = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		flock.length = fl->fl_end - fl->fl_start + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	flock.proc_id = fl->fl_pid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	flock.client_id = fid->clnt->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	if (IS_SETLKW(cmd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		flock.flags = P9_LOCK_FLAGS_BLOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	v9ses = v9fs_inode2v9ses(file_inode(filp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	 * if its a blocked request and we get P9_LOCK_BLOCKED as the status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	 * for lock request, keep on trying
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		res = p9_client_lock_dotl(fid, &flock, &status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		if (res < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 			goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		if (status != P9_LOCK_BLOCKED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		if (status == P9_LOCK_BLOCKED && !IS_SETLKW(cmd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		if (schedule_timeout_interruptible(v9ses->session_lock_timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 				!= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		 * p9_client_lock_dotl overwrites flock.client_id with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		 * server message, free and reuse the client name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		if (flock.client_id != fid->clnt->name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 			kfree(flock.client_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 			flock.client_id = fid->clnt->name;
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	/* map 9p status to VFS status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	switch (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	case P9_LOCK_SUCCESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		res = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	case P9_LOCK_BLOCKED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		res = -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		WARN_ONCE(1, "unknown lock status code: %d\n", status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	case P9_LOCK_ERROR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	case P9_LOCK_GRACE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		res = -ENOLCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	 * incase server returned error for lock request, revert
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	 * it locally
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	if (res < 0 && fl->fl_type != F_UNLCK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		fl_type = fl->fl_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		fl->fl_type = F_UNLCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		/* Even if this fails we want to return the remote error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		locks_lock_file_wait(filp, fl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		fl->fl_type = fl_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	if (flock.client_id != fid->clnt->name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		kfree(flock.client_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) static int v9fs_file_getlock(struct file *filp, struct file_lock *fl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	struct p9_getlock glock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	struct p9_fid *fid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	int res = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	fid = filp->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	BUG_ON(fid == NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	posix_test_lock(filp, fl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	 * if we have a conflicting lock locally, no need to validate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	 * with server
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	if (fl->fl_type != F_UNLCK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	/* convert posix lock to p9 tgetlock args */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	memset(&glock, 0, sizeof(glock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	glock.type  = P9_LOCK_TYPE_UNLCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	glock.start = fl->fl_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	if (fl->fl_end == OFFSET_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		glock.length = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		glock.length = fl->fl_end - fl->fl_start + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	glock.proc_id = fl->fl_pid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	glock.client_id = fid->clnt->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	res = p9_client_getlock_dotl(fid, &glock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	if (res < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	/* map 9p lock type to os lock type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	switch (glock.type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	case P9_LOCK_TYPE_RDLCK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		fl->fl_type = F_RDLCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	case P9_LOCK_TYPE_WRLCK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		fl->fl_type = F_WRLCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	case P9_LOCK_TYPE_UNLCK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		fl->fl_type = F_UNLCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	if (glock.type != P9_LOCK_TYPE_UNLCK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		fl->fl_start = glock.start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		if (glock.length == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 			fl->fl_end = OFFSET_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 			fl->fl_end = glock.start + glock.length - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		fl->fl_pid = -glock.proc_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	if (glock.client_id != fid->clnt->name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		kfree(glock.client_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	return res;
^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) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)  * v9fs_file_lock_dotl - lock a file (or directory)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)  * @filp: file to be locked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)  * @cmd: lock command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)  * @fl: file lock structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) static int v9fs_file_lock_dotl(struct file *filp, int cmd, struct file_lock *fl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	struct inode *inode = file_inode(filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	int ret = -ENOLCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	p9_debug(P9_DEBUG_VFS, "filp: %p cmd:%d lock: %p name: %pD\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		 filp, cmd, fl, filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	/* No mandatory locks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	if (__mandatory_lock(inode) && fl->fl_type != F_UNLCK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 		goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	if ((IS_SETLK(cmd) || IS_SETLKW(cmd)) && fl->fl_type != F_UNLCK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 		filemap_write_and_wait(inode->i_mapping);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 		invalidate_mapping_pages(&inode->i_data, 0, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	if (IS_SETLK(cmd) || IS_SETLKW(cmd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		ret = v9fs_file_do_lock(filp, cmd, fl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	else if (IS_GETLK(cmd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 		ret = v9fs_file_getlock(filp, fl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) out_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)  * v9fs_file_flock_dotl - lock a file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)  * @filp: file to be locked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)  * @cmd: lock command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)  * @fl: file lock structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) static int v9fs_file_flock_dotl(struct file *filp, int cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	struct file_lock *fl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	struct inode *inode = file_inode(filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	int ret = -ENOLCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	p9_debug(P9_DEBUG_VFS, "filp: %p cmd:%d lock: %p name: %pD\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 		 filp, cmd, fl, filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	/* No mandatory locks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	if (__mandatory_lock(inode) && fl->fl_type != F_UNLCK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 		goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	if (!(fl->fl_flags & FL_FLOCK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 		goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	if ((IS_SETLK(cmd) || IS_SETLKW(cmd)) && fl->fl_type != F_UNLCK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		filemap_write_and_wait(inode->i_mapping);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 		invalidate_mapping_pages(&inode->i_data, 0, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	/* Convert flock to posix lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	fl->fl_flags |= FL_POSIX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	fl->fl_flags ^= FL_FLOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	if (IS_SETLK(cmd) | IS_SETLKW(cmd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 		ret = v9fs_file_do_lock(filp, cmd, fl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) out_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	return ret;
^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) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)  * v9fs_file_read - read from a file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)  * @filp: file pointer to read
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)  * @udata: user data buffer to read data into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)  * @count: size of buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)  * @offset: offset at which to read data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) v9fs_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	struct p9_fid *fid = iocb->ki_filp->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	int ret, err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	p9_debug(P9_DEBUG_VFS, "count %zu offset %lld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 		 iov_iter_count(to), iocb->ki_pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	if (iocb->ki_filp->f_flags & O_NONBLOCK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 		ret = p9_client_read_once(fid, iocb->ki_pos, to, &err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 		ret = p9_client_read(fid, iocb->ki_pos, to, &err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	iocb->ki_pos += ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	return ret;
^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) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)  * v9fs_file_write - write to a file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)  * @filp: file pointer to write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)  * @data: data buffer to write data from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406)  * @count: size of buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407)  * @offset: offset at which to write data
^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) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) v9fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	struct file *file = iocb->ki_filp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	ssize_t retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	loff_t origin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	retval = generic_write_checks(iocb, from);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	if (retval <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 		return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	origin = iocb->ki_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	retval = p9_client_write(file->private_data, iocb->ki_pos, from, &err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	if (retval > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 		struct inode *inode = file_inode(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 		loff_t i_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 		unsigned long pg_start, pg_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 		pg_start = origin >> PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 		pg_end = (origin + retval - 1) >> PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 		if (inode->i_mapping && inode->i_mapping->nrpages)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 			invalidate_inode_pages2_range(inode->i_mapping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 						      pg_start, pg_end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 		iocb->ki_pos += retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 		i_size = i_size_read(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 		if (iocb->ki_pos > i_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 			inode_add_bytes(inode, iocb->ki_pos - i_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 			 * Need to serialize against i_size_write() in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 			 * v9fs_stat2inode()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 			v9fs_i_size_write(inode, iocb->ki_pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 		return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) static int v9fs_file_fsync(struct file *filp, loff_t start, loff_t end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 			   int datasync)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	struct p9_fid *fid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	struct inode *inode = filp->f_mapping->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	struct p9_wstat wstat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	retval = file_write_and_wait_range(filp, start, end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 		return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	inode_lock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	p9_debug(P9_DEBUG_VFS, "filp %p datasync %x\n", filp, datasync);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	fid = filp->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	v9fs_blank_wstat(&wstat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	retval = p9_client_wstat(fid, &wstat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	inode_unlock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) int v9fs_file_fsync_dotl(struct file *filp, loff_t start, loff_t end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 			 int datasync)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	struct p9_fid *fid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	struct inode *inode = filp->f_mapping->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	retval = file_write_and_wait_range(filp, start, end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 		return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	inode_lock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	p9_debug(P9_DEBUG_VFS, "filp %p datasync %x\n", filp, datasync);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	fid = filp->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	retval = p9_client_fsync(fid, datasync);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 	inode_unlock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) v9fs_file_mmap(struct file *filp, struct vm_area_struct *vma)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 	int retval;
^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) 	retval = generic_file_mmap(filp, vma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	if (!retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 		vma->vm_ops = &v9fs_file_vm_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) v9fs_mmap_file_mmap(struct file *filp, struct vm_area_struct *vma)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 	struct v9fs_inode *v9inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	struct p9_fid *fid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 	inode = file_inode(filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	v9inode = V9FS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	mutex_lock(&v9inode->v_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 	if (!v9inode->writeback_fid &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 	    (vma->vm_flags & VM_SHARED) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 	    (vma->vm_flags & VM_WRITE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 		 * clone a fid and add it to writeback_fid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 		 * we do it during mmap instead of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 		 * page dirty time via write_begin/page_mkwrite
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 		 * because we want write after unlink usecase
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 		 * to work.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 		fid = v9fs_writeback_fid(file_dentry(filp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 		if (IS_ERR(fid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 			retval = PTR_ERR(fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 			mutex_unlock(&v9inode->v_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 			return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 		v9inode->writeback_fid = (void *) fid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 	mutex_unlock(&v9inode->v_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 	retval = generic_file_mmap(filp, vma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 	if (!retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 		vma->vm_ops = &v9fs_mmap_file_vm_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) static vm_fault_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) v9fs_vm_page_mkwrite(struct vm_fault *vmf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 	struct v9fs_inode *v9inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 	struct page *page = vmf->page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 	struct file *filp = vmf->vma->vm_file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 	struct inode *inode = file_inode(filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 	p9_debug(P9_DEBUG_VFS, "page %p fid %lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 		 page, (unsigned long)filp->private_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 	/* Update file times before taking page lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 	file_update_time(filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 	v9inode = V9FS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 	/* make sure the cache has finished storing the page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 	v9fs_fscache_wait_on_page_write(inode, page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 	BUG_ON(!v9inode->writeback_fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 	lock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 	if (page->mapping != inode->i_mapping)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 		goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 	wait_for_stable_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 	return VM_FAULT_LOCKED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 	unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 	return VM_FAULT_NOPAGE;
^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) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576)  * v9fs_mmap_file_read - read from a file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577)  * @filp: file pointer to read
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578)  * @data: user data buffer to read data into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579)  * @count: size of buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580)  * @offset: offset at which to read data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) v9fs_mmap_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 	/* TODO: Check if there are dirty pages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 	return v9fs_file_read_iter(iocb, to);
^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) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591)  * v9fs_mmap_file_write - write to a file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592)  * @filp: file pointer to write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593)  * @data: data buffer to write data from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594)  * @count: size of buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)  * @offset: offset at which to write data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) v9fs_mmap_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 	 * TODO: invalidate mmaps on filp's inode between
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 	 * offset and offset+count
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 	return v9fs_file_write_iter(iocb, from);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) static void v9fs_mmap_vm_close(struct vm_area_struct *vma)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 	struct writeback_control wbc = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 		.nr_to_write = LONG_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 		.sync_mode = WB_SYNC_ALL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 		.range_start = (loff_t)vma->vm_pgoff * PAGE_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 		 /* absolute end, byte at end included */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 		.range_end = (loff_t)vma->vm_pgoff * PAGE_SIZE +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 			(vma->vm_end - vma->vm_start - 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 	if (!(vma->vm_flags & VM_SHARED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 	p9_debug(P9_DEBUG_VFS, "9p VMA close, %p, flushing", vma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 	inode = file_inode(vma->vm_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 	if (!mapping_can_writeback(inode->i_mapping))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 		wbc.nr_to_write = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 	might_sleep();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 	sync_inode(inode, &wbc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) static const struct vm_operations_struct v9fs_file_vm_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 	.fault = filemap_fault,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 	.map_pages = filemap_map_pages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 	.page_mkwrite = v9fs_vm_page_mkwrite,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) static const struct vm_operations_struct v9fs_mmap_file_vm_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 	.close = v9fs_mmap_vm_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 	.fault = filemap_fault,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 	.map_pages = filemap_map_pages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 	.page_mkwrite = v9fs_vm_page_mkwrite,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) const struct file_operations v9fs_cached_file_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 	.llseek = generic_file_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 	.read_iter = generic_file_read_iter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 	.write_iter = generic_file_write_iter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 	.open = v9fs_file_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 	.release = v9fs_dir_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 	.lock = v9fs_file_lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 	.mmap = v9fs_file_mmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 	.splice_read = generic_file_splice_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 	.splice_write = iter_file_splice_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 	.fsync = v9fs_file_fsync,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) const struct file_operations v9fs_cached_file_operations_dotl = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 	.llseek = generic_file_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 	.read_iter = generic_file_read_iter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 	.write_iter = generic_file_write_iter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 	.open = v9fs_file_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 	.release = v9fs_dir_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 	.lock = v9fs_file_lock_dotl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 	.flock = v9fs_file_flock_dotl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 	.mmap = v9fs_file_mmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 	.splice_read = generic_file_splice_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 	.splice_write = iter_file_splice_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 	.fsync = v9fs_file_fsync_dotl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) const struct file_operations v9fs_file_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 	.llseek = generic_file_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 	.read_iter = v9fs_file_read_iter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 	.write_iter = v9fs_file_write_iter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 	.open = v9fs_file_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 	.release = v9fs_dir_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 	.lock = v9fs_file_lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 	.mmap = generic_file_readonly_mmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 	.splice_read = generic_file_splice_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 	.splice_write = iter_file_splice_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 	.fsync = v9fs_file_fsync,
^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) const struct file_operations v9fs_file_operations_dotl = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 	.llseek = generic_file_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 	.read_iter = v9fs_file_read_iter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) 	.write_iter = v9fs_file_write_iter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) 	.open = v9fs_file_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 	.release = v9fs_dir_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 	.lock = v9fs_file_lock_dotl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) 	.flock = v9fs_file_flock_dotl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) 	.mmap = generic_file_readonly_mmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) 	.splice_read = generic_file_splice_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) 	.splice_write = iter_file_splice_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) 	.fsync = v9fs_file_fsync_dotl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) const struct file_operations v9fs_mmap_file_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) 	.llseek = generic_file_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) 	.read_iter = v9fs_mmap_file_read_iter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 	.write_iter = v9fs_mmap_file_write_iter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) 	.open = v9fs_file_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) 	.release = v9fs_dir_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) 	.lock = v9fs_file_lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) 	.mmap = v9fs_mmap_file_mmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 	.splice_read = generic_file_splice_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 	.splice_write = iter_file_splice_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) 	.fsync = v9fs_file_fsync,
^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) const struct file_operations v9fs_mmap_file_operations_dotl = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) 	.llseek = generic_file_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) 	.read_iter = v9fs_mmap_file_read_iter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) 	.write_iter = v9fs_mmap_file_write_iter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) 	.open = v9fs_file_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) 	.release = v9fs_dir_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) 	.lock = v9fs_file_lock_dotl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) 	.flock = v9fs_file_flock_dotl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) 	.mmap = v9fs_mmap_file_mmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) 	.splice_read = generic_file_splice_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) 	.splice_write = iter_file_splice_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) 	.fsync = v9fs_file_fsync_dotl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) };