xref: /openbmc/linux/fs/9p/fid.h (revision 93696d8f)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * V9FS FID Management
4  *
5  *  Copyright (C) 2005 by Eric Van Hensbergen <ericvh@gmail.com>
6  */
7 #ifndef FS_9P_FID_H
8 #define FS_9P_FID_H
9 #include <linux/list.h>
10 #include "v9fs.h"
11 
12 struct p9_fid *v9fs_fid_find_inode(struct inode *inode, bool want_writeable,
13 	kuid_t uid, bool any);
14 struct p9_fid *v9fs_fid_lookup(struct dentry *dentry);
15 static inline struct p9_fid *v9fs_parent_fid(struct dentry *dentry)
16 {
17 	return v9fs_fid_lookup(dentry->d_parent);
18 }
19 void v9fs_fid_add(struct dentry *dentry, struct p9_fid **fid);
20 void v9fs_open_fid_add(struct inode *inode, struct p9_fid **fid);
21 static inline struct p9_fid *clone_fid(struct p9_fid *fid)
22 {
23 	return IS_ERR(fid) ? fid :  p9_client_walk(fid, 0, NULL, 1);
24 }
25 static inline struct p9_fid *v9fs_fid_clone(struct dentry *dentry)
26 {
27 	struct p9_fid *fid, *nfid;
28 
29 	fid = v9fs_fid_lookup(dentry);
30 	if (!fid || IS_ERR(fid))
31 		return fid;
32 
33 	nfid = clone_fid(fid);
34 	p9_fid_put(fid);
35 	return nfid;
36 }
37 /**
38  * v9fs_fid_addmodes - add cache flags to fid mode (for client use only)
39  * @fid: fid to augment
40  * @s_flags: session info mount flags
41  * @s_cache: session info cache flags
42  * @f_flags: unix open flags
43  *
44  * make sure mode reflects flags of underlying mounts
45  * also qid.version == 0 reflects a synthetic or legacy file system
46  * NOTE: these are set after open so only reflect 9p client not
47  * underlying file system on server.
48  */
49 static inline void v9fs_fid_add_modes(struct p9_fid *fid, unsigned int s_flags,
50 	unsigned int s_cache, unsigned int f_flags)
51 {
52 	if ((!s_cache) ||
53 	   ((fid->qid.version == 0) && !(s_flags & V9FS_IGNORE_QV)) ||
54 	   (s_flags & V9FS_DIRECT_IO) || (f_flags & O_DIRECT)) {
55 		fid->mode |= P9L_DIRECT; /* no read or write cache */
56 	} else if ((!(s_cache & CACHE_WRITEBACK)) ||
57 				(f_flags & O_DSYNC) || (s_flags & V9FS_SYNC)) {
58 		fid->mode |= P9L_NOWRITECACHE;
59 	}
60 }
61 #endif
62