Thomas Gleixner | 1f32761 | 2019-05-28 09:57:16 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Eric Van Hensbergen | 9e82cf6 | 2005-09-09 13:04:20 -0700 | [diff] [blame] | 2 | /* |
| 3 | * V9FS definitions. |
| 4 | * |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 5 | * Copyright (C) 2004-2008 by Eric Van Hensbergen <ericvh@gmail.com> |
Eric Van Hensbergen | 9e82cf6 | 2005-09-09 13:04:20 -0700 | [diff] [blame] | 6 | * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov> |
Eric Van Hensbergen | 9e82cf6 | 2005-09-09 13:04:20 -0700 | [diff] [blame] | 7 | */ |
Aneesh Kumar K.V | e0459f5 | 2011-02-28 17:04:09 +0530 | [diff] [blame] | 8 | #ifndef FS_9P_V9FS_H |
| 9 | #define FS_9P_V9FS_H |
| 10 | |
Jens Axboe | 0ed07dd | 2010-04-22 11:42:00 +0200 | [diff] [blame] | 11 | #include <linux/backing-dev.h> |
David Howells | bc899ee | 2021-06-29 22:37:05 +0100 | [diff] [blame] | 12 | #include <linux/netfs.h> |
Eric Van Hensbergen | 9e82cf6 | 2005-09-09 13:04:20 -0700 | [diff] [blame] | 13 | |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 14 | /** |
| 15 | * enum p9_session_flags - option flags for each 9P session |
Sripathi Kodi | dd6102f | 2010-03-05 18:48:00 +0000 | [diff] [blame] | 16 | * @V9FS_PROTO_2000U: whether or not to use 9P2000.u extensions |
Sripathi Kodi | 45bc21e | 2010-03-08 17:33:04 +0000 | [diff] [blame] | 17 | * @V9FS_PROTO_2000L: whether or not to use 9P2000.l extensions |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 18 | * @V9FS_ACCESS_SINGLE: only the mounting user can access the hierarchy |
| 19 | * @V9FS_ACCESS_USER: a new attach will be issued for every user (default) |
Venkateswararao Jujjuri (JV) | e782ef7 | 2011-01-25 15:40:54 -0800 | [diff] [blame] | 20 | * @V9FS_ACCESS_CLIENT: Just like user, but access check is performed on client. |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 21 | * @V9FS_ACCESS_ANY: use a single attach for all users |
| 22 | * @V9FS_ACCESS_MASK: bit mask of different ACCESS options |
Venkateswararao Jujjuri (JV) | e782ef7 | 2011-01-25 15:40:54 -0800 | [diff] [blame] | 23 | * @V9FS_POSIX_ACL: POSIX ACLs are enforced |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 24 | * |
| 25 | * Session flags reflect options selected by users at mount time |
| 26 | */ |
Aneesh Kumar K.V | 76381a4 | 2010-09-28 00:27:41 +0530 | [diff] [blame] | 27 | #define V9FS_ACCESS_ANY (V9FS_ACCESS_SINGLE | \ |
| 28 | V9FS_ACCESS_USER | \ |
| 29 | V9FS_ACCESS_CLIENT) |
| 30 | #define V9FS_ACCESS_MASK V9FS_ACCESS_ANY |
Venkateswararao Jujjuri (JV) | e782ef7 | 2011-01-25 15:40:54 -0800 | [diff] [blame] | 31 | #define V9FS_ACL_MASK V9FS_POSIX_ACL |
Aneesh Kumar K.V | 76381a4 | 2010-09-28 00:27:41 +0530 | [diff] [blame] | 32 | |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 33 | enum p9_session_flags { |
Eric Van Hensbergen | 4eb3117 | 2023-03-27 01:53:10 +0000 | [diff] [blame] | 34 | V9FS_PROTO_2000U = 0x01, |
| 35 | V9FS_PROTO_2000L = 0x02, |
| 36 | V9FS_ACCESS_SINGLE = 0x04, |
| 37 | V9FS_ACCESS_USER = 0x08, |
| 38 | V9FS_ACCESS_CLIENT = 0x10, |
| 39 | V9FS_POSIX_ACL = 0x20, |
| 40 | V9FS_NO_XATTR = 0x40, |
| 41 | V9FS_IGNORE_QV = 0x80, /* ignore qid.version for cache hints */ |
| 42 | V9FS_DIRECT_IO = 0x100, |
| 43 | V9FS_SYNC = 0x200 |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 44 | }; |
| 45 | |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 46 | /** |
Eric Van Hensbergen | 4eb3117 | 2023-03-27 01:53:10 +0000 | [diff] [blame] | 47 | * enum p9_cache_shortcuts - human readable cache preferences |
| 48 | * @CACHE_SC_NONE: disable all caches |
| 49 | * @CACHE_SC_READAHEAD: only provide caching for readahead |
| 50 | * @CACHE_SC_MMAP: provide caching to enable mmap |
| 51 | * @CACHE_SC_LOOSE: non-coherent caching for files and meta data |
| 52 | * @CACHE_SC_FSCACHE: persistent non-coherent caching for files and meta-data |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 53 | * |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 54 | */ |
| 55 | |
Eric Van Hensbergen | 4eb3117 | 2023-03-27 01:53:10 +0000 | [diff] [blame] | 56 | enum p9_cache_shortcuts { |
| 57 | CACHE_SC_NONE = 0b00000000, |
| 58 | CACHE_SC_READAHEAD = 0b00000001, |
| 59 | CACHE_SC_MMAP = 0b00000101, |
| 60 | CACHE_SC_LOOSE = 0b00001111, |
| 61 | CACHE_SC_FSCACHE = 0b10001111, |
| 62 | }; |
| 63 | |
| 64 | /** |
| 65 | * enum p9_cache_bits - possible values of ->cache |
| 66 | * @CACHE_NONE: caches disabled |
| 67 | * @CACHE_FILE: file caching (open to close) |
| 68 | * @CACHE_META: meta-data and directory caching |
| 69 | * @CACHE_WRITEBACK: write-back caching for files |
| 70 | * @CACHE_LOOSE: don't check cache consistency |
| 71 | * @CACHE_FSCACHE: local persistent caches |
| 72 | * |
| 73 | */ |
| 74 | |
| 75 | enum p9_cache_bits { |
| 76 | CACHE_NONE = 0b00000000, |
| 77 | CACHE_FILE = 0b00000001, |
| 78 | CACHE_META = 0b00000010, |
| 79 | CACHE_WRITEBACK = 0b00000100, |
| 80 | CACHE_LOOSE = 0b00001000, |
| 81 | CACHE_FSCACHE = 0b10000000, |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | /** |
| 85 | * struct v9fs_session_info - per-instance session information |
| 86 | * @flags: session options of type &p9_session_flags |
| 87 | * @nodev: set to 1 to disable device mapping |
| 88 | * @debug: debug level |
| 89 | * @afid: authentication handle |
Eric Van Hensbergen | 4eb3117 | 2023-03-27 01:53:10 +0000 | [diff] [blame] | 90 | * @cache: cache mode of type &p9_cache_bits |
Abhishek Kulkarni | 60e78d2 | 2009-09-23 13:00:27 -0500 | [diff] [blame] | 91 | * @cachetag: the tag of the cache associated with this session |
| 92 | * @fscache: session cookie associated with FS-Cache |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 93 | * @uname: string user name to mount hierarchy as |
| 94 | * @aname: mount specifier for remote hierarchy |
| 95 | * @maxdata: maximum data to be sent/recvd per protocol message |
| 96 | * @dfltuid: default numeric userid to mount hierarchy as |
| 97 | * @dfltgid: default numeric groupid to mount hierarchy as |
| 98 | * @uid: if %V9FS_ACCESS_SINGLE, the numeric uid which mounted the hierarchy |
| 99 | * @clnt: reference to 9P network client instantiated for this session |
Abhishek Kulkarni | 60e78d2 | 2009-09-23 13:00:27 -0500 | [diff] [blame] | 100 | * @slist: reference to list of registered 9p sessions |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 101 | * |
| 102 | * This structure holds state for each session instance established during |
| 103 | * a sys_mount() . |
| 104 | * |
| 105 | * Bugs: there seems to be a lot of state which could be condensed and/or |
| 106 | * removed. |
| 107 | */ |
Eric Van Hensbergen | 9e82cf6 | 2005-09-09 13:04:20 -0700 | [diff] [blame] | 108 | |
| 109 | struct v9fs_session_info { |
| 110 | /* options */ |
Christophe JAILLET | 95f41d8 | 2023-04-25 08:47:27 +0200 | [diff] [blame] | 111 | unsigned int flags; |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 112 | unsigned char nodev; |
| 113 | unsigned short debug; |
| 114 | unsigned int afid; |
| 115 | unsigned int cache; |
Abhishek Kulkarni | 60e78d2 | 2009-09-23 13:00:27 -0500 | [diff] [blame] | 116 | #ifdef CONFIG_9P_FSCACHE |
| 117 | char *cachetag; |
David Howells | 24e42e3 | 2020-11-18 09:06:42 +0000 | [diff] [blame] | 118 | struct fscache_volume *fscache; |
Abhishek Kulkarni | 60e78d2 | 2009-09-23 13:00:27 -0500 | [diff] [blame] | 119 | #endif |
Eric Van Hensbergen | 9e82cf6 | 2005-09-09 13:04:20 -0700 | [diff] [blame] | 120 | |
Latchesar Ionkov | ba17674 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 121 | char *uname; /* user name to mount as */ |
| 122 | char *aname; /* name of remote hierarchy being mounted */ |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 123 | unsigned int maxdata; /* max data for client interface */ |
Eric W. Biederman | 76ed23a | 2013-01-30 11:57:40 -0800 | [diff] [blame] | 124 | kuid_t dfltuid; /* default uid/muid for legacy support */ |
| 125 | kgid_t dfltgid; /* default gid for legacy support */ |
| 126 | kuid_t uid; /* if ACCESS_SINGLE, the uid that has access */ |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 127 | struct p9_client *clnt; /* 9p client */ |
Abhishek Kulkarni | 60e78d2 | 2009-09-23 13:00:27 -0500 | [diff] [blame] | 128 | struct list_head slist; /* list of sessions registered with v9fs */ |
Aneesh Kumar K.V | a534c8d | 2010-06-30 19:18:50 +0530 | [diff] [blame] | 129 | struct rw_semaphore rename_sem; |
Dinu-Razvan Chis-Serban | 5e172f7 | 2018-09-05 16:44:12 +0900 | [diff] [blame] | 130 | long session_lock_timeout; /* retry interval for blocking locks */ |
Eric Van Hensbergen | 9e82cf6 | 2005-09-09 13:04:20 -0700 | [diff] [blame] | 131 | }; |
| 132 | |
Aneesh Kumar K.V | b3cbea0 | 2011-02-28 17:04:06 +0530 | [diff] [blame] | 133 | /* cache_validity flags */ |
| 134 | #define V9FS_INO_INVALID_ATTR 0x01 |
| 135 | |
Aneesh Kumar K.V | a78ce05 | 2011-02-28 17:04:02 +0530 | [diff] [blame] | 136 | struct v9fs_inode { |
David Howells | 874c8ca1 | 2022-06-09 21:46:04 +0100 | [diff] [blame] | 137 | struct netfs_inode netfs; /* Netfslib context and vfs inode */ |
Aneesh Kumar K.V | fd2421f | 2011-07-11 16:40:59 +0000 | [diff] [blame] | 138 | struct p9_qid qid; |
Aneesh Kumar K.V | b3cbea0 | 2011-02-28 17:04:06 +0530 | [diff] [blame] | 139 | unsigned int cache_validity; |
Aneesh Kumar K.V | 5a7e0a8 | 2011-03-08 16:39:46 +0530 | [diff] [blame] | 140 | struct mutex v_mutex; |
Aneesh Kumar K.V | a78ce05 | 2011-02-28 17:04:02 +0530 | [diff] [blame] | 141 | }; |
| 142 | |
| 143 | static inline struct v9fs_inode *V9FS_I(const struct inode *inode) |
| 144 | { |
David Howells | 874c8ca1 | 2022-06-09 21:46:04 +0100 | [diff] [blame] | 145 | return container_of(inode, struct v9fs_inode, netfs.inode); |
Aneesh Kumar K.V | a78ce05 | 2011-02-28 17:04:02 +0530 | [diff] [blame] | 146 | } |
| 147 | |
David Howells | eb49794 | 2021-11-02 08:29:55 +0000 | [diff] [blame] | 148 | static inline struct fscache_cookie *v9fs_inode_cookie(struct v9fs_inode *v9inode) |
| 149 | { |
| 150 | #ifdef CONFIG_9P_FSCACHE |
Linus Torvalds | e81fb41 | 2022-06-09 15:04:01 -0700 | [diff] [blame] | 151 | return netfs_i_cookie(&v9inode->netfs); |
David Howells | eb49794 | 2021-11-02 08:29:55 +0000 | [diff] [blame] | 152 | #else |
| 153 | return NULL; |
| 154 | #endif |
| 155 | } |
| 156 | |
David Howells | 24e42e3 | 2020-11-18 09:06:42 +0000 | [diff] [blame] | 157 | static inline struct fscache_volume *v9fs_session_cache(struct v9fs_session_info *v9ses) |
| 158 | { |
| 159 | #ifdef CONFIG_9P_FSCACHE |
| 160 | return v9ses->fscache; |
| 161 | #else |
| 162 | return NULL; |
| 163 | #endif |
| 164 | } |
| 165 | |
| 166 | |
David Howells | c4fac91 | 2017-07-05 16:25:37 +0100 | [diff] [blame] | 167 | extern int v9fs_show_options(struct seq_file *m, struct dentry *root); |
| 168 | |
Sohaib Mohamed | 772712c | 2021-10-01 08:34:44 +0200 | [diff] [blame] | 169 | struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses, |
| 170 | const char *dev_name, char *data); |
Aneesh Kumar K.V | 53c06f4 | 2011-01-10 13:51:47 -0600 | [diff] [blame] | 171 | extern void v9fs_session_close(struct v9fs_session_info *v9ses); |
| 172 | extern void v9fs_session_cancel(struct v9fs_session_info *v9ses); |
| 173 | extern void v9fs_session_begin_cancel(struct v9fs_session_info *v9ses); |
| 174 | extern struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry, |
Sohaib Mohamed | 772712c | 2021-10-01 08:34:44 +0200 | [diff] [blame] | 175 | unsigned int flags); |
Aneesh Kumar K.V | 53c06f4 | 2011-01-10 13:51:47 -0600 | [diff] [blame] | 176 | extern int v9fs_vfs_unlink(struct inode *i, struct dentry *d); |
| 177 | extern int v9fs_vfs_rmdir(struct inode *i, struct dentry *d); |
Christian Brauner | e18275a | 2023-01-13 12:49:17 +0100 | [diff] [blame] | 178 | extern int v9fs_vfs_rename(struct mnt_idmap *idmap, |
Christian Brauner | 549c729 | 2021-01-21 14:19:43 +0100 | [diff] [blame] | 179 | struct inode *old_dir, struct dentry *old_dentry, |
Miklos Szeredi | 1cd66c9 | 2016-09-27 11:03:58 +0200 | [diff] [blame] | 180 | struct inode *new_dir, struct dentry *new_dentry, |
| 181 | unsigned int flags); |
Eric Van Hensbergen | d05dcfd | 2024-04-15 20:24:37 +0000 | [diff] [blame] | 182 | extern struct inode *v9fs_fid_iget(struct super_block *sb, struct p9_fid *fid, |
| 183 | bool new); |
Aneesh Kumar K.V | 53c06f4 | 2011-01-10 13:51:47 -0600 | [diff] [blame] | 184 | extern const struct inode_operations v9fs_dir_inode_operations_dotl; |
| 185 | extern const struct inode_operations v9fs_file_inode_operations_dotl; |
| 186 | extern const struct inode_operations v9fs_symlink_inode_operations_dotl; |
David Howells | bc899ee | 2021-06-29 22:37:05 +0100 | [diff] [blame] | 187 | extern const struct netfs_request_ops v9fs_req_ops; |
Eric Van Hensbergen | 724a084 | 2024-01-05 22:25:39 +0000 | [diff] [blame] | 188 | extern struct inode *v9fs_fid_iget_dotl(struct super_block *sb, |
Eric Van Hensbergen | d05dcfd | 2024-04-15 20:24:37 +0000 | [diff] [blame] | 189 | struct p9_fid *fid, bool new); |
Eric Van Hensbergen | 9e82cf6 | 2005-09-09 13:04:20 -0700 | [diff] [blame] | 190 | |
Eric Van Hensbergen | 9e82cf6 | 2005-09-09 13:04:20 -0700 | [diff] [blame] | 191 | /* other default globals */ |
Latchesar Ionkov | bd32b82 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 192 | #define V9FS_PORT 564 |
Eric Van Hensbergen | 9e82cf6 | 2005-09-09 13:04:20 -0700 | [diff] [blame] | 193 | #define V9FS_DEFUSER "nobody" |
| 194 | #define V9FS_DEFANAME "" |
Eric W. Biederman | 76ed23a | 2013-01-30 11:57:40 -0800 | [diff] [blame] | 195 | #define V9FS_DEFUID KUIDT_INIT(-2) |
| 196 | #define V9FS_DEFGID KGIDT_INIT(-2) |
Eric Van Hensbergen | 9e82cf6 | 2005-09-09 13:04:20 -0700 | [diff] [blame] | 197 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 198 | static inline struct v9fs_session_info *v9fs_inode2v9ses(struct inode *inode) |
| 199 | { |
Sohaib Mohamed | 772712c | 2021-10-01 08:34:44 +0200 | [diff] [blame] | 200 | return inode->i_sb->s_fs_info; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 201 | } |
Latchesar Ionkov | 2405669 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 202 | |
Aneesh Kumar K.V | 42869c8 | 2011-03-08 16:39:50 +0530 | [diff] [blame] | 203 | static inline struct v9fs_session_info *v9fs_dentry2v9ses(struct dentry *dentry) |
| 204 | { |
| 205 | return dentry->d_sb->s_fs_info; |
| 206 | } |
| 207 | |
Sripathi Kodi | dd6102f | 2010-03-05 18:48:00 +0000 | [diff] [blame] | 208 | static inline int v9fs_proto_dotu(struct v9fs_session_info *v9ses) |
Latchesar Ionkov | 2405669 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 209 | { |
Sripathi Kodi | dd6102f | 2010-03-05 18:48:00 +0000 | [diff] [blame] | 210 | return v9ses->flags & V9FS_PROTO_2000U; |
| 211 | } |
| 212 | |
| 213 | static inline int v9fs_proto_dotl(struct v9fs_session_info *v9ses) |
| 214 | { |
Sripathi Kodi | 45bc21e | 2010-03-08 17:33:04 +0000 | [diff] [blame] | 215 | return v9ses->flags & V9FS_PROTO_2000L; |
Latchesar Ionkov | 2405669 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 216 | } |
Aneesh Kumar K.V | 53c06f4 | 2011-01-10 13:51:47 -0600 | [diff] [blame] | 217 | |
| 218 | /** |
Aneesh Kumar K.V | a78ce05 | 2011-02-28 17:04:02 +0530 | [diff] [blame] | 219 | * v9fs_get_inode_from_fid - Helper routine to populate an inode by |
Aneesh Kumar K.V | 53c06f4 | 2011-01-10 13:51:47 -0600 | [diff] [blame] | 220 | * issuing a attribute request |
| 221 | * @v9ses: session information |
| 222 | * @fid: fid to issue attribute request for |
| 223 | * @sb: superblock on which to create inode |
| 224 | * |
| 225 | */ |
| 226 | static inline struct inode * |
Aneesh Kumar K.V | a78ce05 | 2011-02-28 17:04:02 +0530 | [diff] [blame] | 227 | v9fs_get_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid, |
Eric Van Hensbergen | d05dcfd | 2024-04-15 20:24:37 +0000 | [diff] [blame] | 228 | struct super_block *sb, bool new) |
Aneesh Kumar K.V | 53c06f4 | 2011-01-10 13:51:47 -0600 | [diff] [blame] | 229 | { |
| 230 | if (v9fs_proto_dotl(v9ses)) |
Eric Van Hensbergen | d05dcfd | 2024-04-15 20:24:37 +0000 | [diff] [blame] | 231 | return v9fs_fid_iget_dotl(sb, fid, new); |
Aneesh Kumar K.V | 53c06f4 | 2011-01-10 13:51:47 -0600 | [diff] [blame] | 232 | else |
Eric Van Hensbergen | d05dcfd | 2024-04-15 20:24:37 +0000 | [diff] [blame] | 233 | return v9fs_fid_iget(sb, fid, new); |
Aneesh Kumar K.V | ed80fcf | 2011-07-06 16:32:31 +0530 | [diff] [blame] | 234 | } |
| 235 | |
Aneesh Kumar K.V | e0459f5 | 2011-02-28 17:04:09 +0530 | [diff] [blame] | 236 | #endif |