blob: 1775fcc7f0e8efa8b22f4c14e6886d85a22faeb5 [file] [log] [blame]
Thomas Gleixner1f327612019-05-28 09:57:16 -07001/* SPDX-License-Identifier: GPL-2.0-only */
Eric Van Hensbergen9e82cf62005-09-09 13:04:20 -07002/*
3 * V9FS definitions.
4 *
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -06005 * Copyright (C) 2004-2008 by Eric Van Hensbergen <ericvh@gmail.com>
Eric Van Hensbergen9e82cf62005-09-09 13:04:20 -07006 * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
Eric Van Hensbergen9e82cf62005-09-09 13:04:20 -07007 */
Aneesh Kumar K.Ve0459f52011-02-28 17:04:09 +05308#ifndef FS_9P_V9FS_H
9#define FS_9P_V9FS_H
10
Jens Axboe0ed07dd2010-04-22 11:42:00 +020011#include <linux/backing-dev.h>
David Howellsbc899ee2021-06-29 22:37:05 +010012#include <linux/netfs.h>
Eric Van Hensbergen9e82cf62005-09-09 13:04:20 -070013
Eric Van Hensbergenee443992008-03-05 07:08:09 -060014/**
15 * enum p9_session_flags - option flags for each 9P session
Sripathi Kodidd6102f2010-03-05 18:48:00 +000016 * @V9FS_PROTO_2000U: whether or not to use 9P2000.u extensions
Sripathi Kodi45bc21e2010-03-08 17:33:04 +000017 * @V9FS_PROTO_2000L: whether or not to use 9P2000.l extensions
Eric Van Hensbergenee443992008-03-05 07:08:09 -060018 * @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)e782ef72011-01-25 15:40:54 -080020 * @V9FS_ACCESS_CLIENT: Just like user, but access check is performed on client.
Eric Van Hensbergenee443992008-03-05 07:08:09 -060021 * @V9FS_ACCESS_ANY: use a single attach for all users
22 * @V9FS_ACCESS_MASK: bit mask of different ACCESS options
Venkateswararao Jujjuri (JV)e782ef72011-01-25 15:40:54 -080023 * @V9FS_POSIX_ACL: POSIX ACLs are enforced
Eric Van Hensbergenee443992008-03-05 07:08:09 -060024 *
25 * Session flags reflect options selected by users at mount time
26 */
Aneesh Kumar K.V76381a42010-09-28 00:27:41 +053027#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)e782ef72011-01-25 15:40:54 -080031#define V9FS_ACL_MASK V9FS_POSIX_ACL
Aneesh Kumar K.V76381a42010-09-28 00:27:41 +053032
Eric Van Hensbergenee443992008-03-05 07:08:09 -060033enum p9_session_flags {
Eric Van Hensbergen4eb31172023-03-27 01:53:10 +000034 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 Hensbergenee443992008-03-05 07:08:09 -060044};
45
Eric Van Hensbergenee443992008-03-05 07:08:09 -060046/**
Eric Van Hensbergen4eb31172023-03-27 01:53:10 +000047 * 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 Hensbergenee443992008-03-05 07:08:09 -060053 *
Eric Van Hensbergenee443992008-03-05 07:08:09 -060054 */
55
Eric Van Hensbergen4eb31172023-03-27 01:53:10 +000056enum 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
75enum 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 Hensbergenee443992008-03-05 07:08:09 -060082};
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 Hensbergen4eb31172023-03-27 01:53:10 +000090 * @cache: cache mode of type &p9_cache_bits
Abhishek Kulkarni60e78d22009-09-23 13:00:27 -050091 * @cachetag: the tag of the cache associated with this session
92 * @fscache: session cookie associated with FS-Cache
Eric Van Hensbergenee443992008-03-05 07:08:09 -060093 * @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 Kulkarni60e78d22009-09-23 13:00:27 -0500100 * @slist: reference to list of registered 9p sessions
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600101 *
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 Hensbergen9e82cf62005-09-09 13:04:20 -0700108
109struct v9fs_session_info {
110 /* options */
Christophe JAILLET95f41d82023-04-25 08:47:27 +0200111 unsigned int flags;
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600112 unsigned char nodev;
113 unsigned short debug;
114 unsigned int afid;
115 unsigned int cache;
Abhishek Kulkarni60e78d22009-09-23 13:00:27 -0500116#ifdef CONFIG_9P_FSCACHE
117 char *cachetag;
David Howells24e42e32020-11-18 09:06:42 +0000118 struct fscache_volume *fscache;
Abhishek Kulkarni60e78d22009-09-23 13:00:27 -0500119#endif
Eric Van Hensbergen9e82cf62005-09-09 13:04:20 -0700120
Latchesar Ionkovba176742007-10-17 14:31:07 -0500121 char *uname; /* user name to mount as */
122 char *aname; /* name of remote hierarchy being mounted */
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600123 unsigned int maxdata; /* max data for client interface */
Eric W. Biederman76ed23a2013-01-30 11:57:40 -0800124 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 Ionkovbd238fb2007-07-10 17:57:28 -0500127 struct p9_client *clnt; /* 9p client */
Abhishek Kulkarni60e78d22009-09-23 13:00:27 -0500128 struct list_head slist; /* list of sessions registered with v9fs */
Aneesh Kumar K.Va534c8d2010-06-30 19:18:50 +0530129 struct rw_semaphore rename_sem;
Dinu-Razvan Chis-Serban5e172f72018-09-05 16:44:12 +0900130 long session_lock_timeout; /* retry interval for blocking locks */
Eric Van Hensbergen9e82cf62005-09-09 13:04:20 -0700131};
132
Aneesh Kumar K.Vb3cbea02011-02-28 17:04:06 +0530133/* cache_validity flags */
134#define V9FS_INO_INVALID_ATTR 0x01
135
Aneesh Kumar K.Va78ce052011-02-28 17:04:02 +0530136struct v9fs_inode {
David Howells874c8ca12022-06-09 21:46:04 +0100137 struct netfs_inode netfs; /* Netfslib context and vfs inode */
Aneesh Kumar K.Vfd2421f2011-07-11 16:40:59 +0000138 struct p9_qid qid;
Aneesh Kumar K.Vb3cbea02011-02-28 17:04:06 +0530139 unsigned int cache_validity;
Aneesh Kumar K.V5a7e0a82011-03-08 16:39:46 +0530140 struct mutex v_mutex;
Aneesh Kumar K.Va78ce052011-02-28 17:04:02 +0530141};
142
143static inline struct v9fs_inode *V9FS_I(const struct inode *inode)
144{
David Howells874c8ca12022-06-09 21:46:04 +0100145 return container_of(inode, struct v9fs_inode, netfs.inode);
Aneesh Kumar K.Va78ce052011-02-28 17:04:02 +0530146}
147
David Howellseb497942021-11-02 08:29:55 +0000148static inline struct fscache_cookie *v9fs_inode_cookie(struct v9fs_inode *v9inode)
149{
150#ifdef CONFIG_9P_FSCACHE
Linus Torvaldse81fb412022-06-09 15:04:01 -0700151 return netfs_i_cookie(&v9inode->netfs);
David Howellseb497942021-11-02 08:29:55 +0000152#else
153 return NULL;
154#endif
155}
156
David Howells24e42e32020-11-18 09:06:42 +0000157static 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 Howellsc4fac912017-07-05 16:25:37 +0100167extern int v9fs_show_options(struct seq_file *m, struct dentry *root);
168
Sohaib Mohamed772712c2021-10-01 08:34:44 +0200169struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses,
170 const char *dev_name, char *data);
Aneesh Kumar K.V53c06f42011-01-10 13:51:47 -0600171extern void v9fs_session_close(struct v9fs_session_info *v9ses);
172extern void v9fs_session_cancel(struct v9fs_session_info *v9ses);
173extern void v9fs_session_begin_cancel(struct v9fs_session_info *v9ses);
174extern struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
Sohaib Mohamed772712c2021-10-01 08:34:44 +0200175 unsigned int flags);
Aneesh Kumar K.V53c06f42011-01-10 13:51:47 -0600176extern int v9fs_vfs_unlink(struct inode *i, struct dentry *d);
177extern int v9fs_vfs_rmdir(struct inode *i, struct dentry *d);
Christian Braunere18275a2023-01-13 12:49:17 +0100178extern int v9fs_vfs_rename(struct mnt_idmap *idmap,
Christian Brauner549c7292021-01-21 14:19:43 +0100179 struct inode *old_dir, struct dentry *old_dentry,
Miklos Szeredi1cd66c92016-09-27 11:03:58 +0200180 struct inode *new_dir, struct dentry *new_dentry,
181 unsigned int flags);
Eric Van Hensbergend05dcfd2024-04-15 20:24:37 +0000182extern struct inode *v9fs_fid_iget(struct super_block *sb, struct p9_fid *fid,
183 bool new);
Aneesh Kumar K.V53c06f42011-01-10 13:51:47 -0600184extern const struct inode_operations v9fs_dir_inode_operations_dotl;
185extern const struct inode_operations v9fs_file_inode_operations_dotl;
186extern const struct inode_operations v9fs_symlink_inode_operations_dotl;
David Howellsbc899ee2021-06-29 22:37:05 +0100187extern const struct netfs_request_ops v9fs_req_ops;
Eric Van Hensbergen724a0842024-01-05 22:25:39 +0000188extern struct inode *v9fs_fid_iget_dotl(struct super_block *sb,
Eric Van Hensbergend05dcfd2024-04-15 20:24:37 +0000189 struct p9_fid *fid, bool new);
Eric Van Hensbergen9e82cf62005-09-09 13:04:20 -0700190
Eric Van Hensbergen9e82cf62005-09-09 13:04:20 -0700191/* other default globals */
Latchesar Ionkovbd32b822007-10-17 14:31:07 -0500192#define V9FS_PORT 564
Eric Van Hensbergen9e82cf62005-09-09 13:04:20 -0700193#define V9FS_DEFUSER "nobody"
194#define V9FS_DEFANAME ""
Eric W. Biederman76ed23a2013-01-30 11:57:40 -0800195#define V9FS_DEFUID KUIDT_INIT(-2)
196#define V9FS_DEFGID KGIDT_INIT(-2)
Eric Van Hensbergen9e82cf62005-09-09 13:04:20 -0700197
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500198static inline struct v9fs_session_info *v9fs_inode2v9ses(struct inode *inode)
199{
Sohaib Mohamed772712c2021-10-01 08:34:44 +0200200 return inode->i_sb->s_fs_info;
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500201}
Latchesar Ionkov24056692007-10-17 14:31:07 -0500202
Aneesh Kumar K.V42869c82011-03-08 16:39:50 +0530203static inline struct v9fs_session_info *v9fs_dentry2v9ses(struct dentry *dentry)
204{
205 return dentry->d_sb->s_fs_info;
206}
207
Sripathi Kodidd6102f2010-03-05 18:48:00 +0000208static inline int v9fs_proto_dotu(struct v9fs_session_info *v9ses)
Latchesar Ionkov24056692007-10-17 14:31:07 -0500209{
Sripathi Kodidd6102f2010-03-05 18:48:00 +0000210 return v9ses->flags & V9FS_PROTO_2000U;
211}
212
213static inline int v9fs_proto_dotl(struct v9fs_session_info *v9ses)
214{
Sripathi Kodi45bc21e2010-03-08 17:33:04 +0000215 return v9ses->flags & V9FS_PROTO_2000L;
Latchesar Ionkov24056692007-10-17 14:31:07 -0500216}
Aneesh Kumar K.V53c06f42011-01-10 13:51:47 -0600217
218/**
Aneesh Kumar K.Va78ce052011-02-28 17:04:02 +0530219 * v9fs_get_inode_from_fid - Helper routine to populate an inode by
Aneesh Kumar K.V53c06f42011-01-10 13:51:47 -0600220 * 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 */
226static inline struct inode *
Aneesh Kumar K.Va78ce052011-02-28 17:04:02 +0530227v9fs_get_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid,
Eric Van Hensbergend05dcfd2024-04-15 20:24:37 +0000228 struct super_block *sb, bool new)
Aneesh Kumar K.V53c06f42011-01-10 13:51:47 -0600229{
230 if (v9fs_proto_dotl(v9ses))
Eric Van Hensbergend05dcfd2024-04-15 20:24:37 +0000231 return v9fs_fid_iget_dotl(sb, fid, new);
Aneesh Kumar K.V53c06f42011-01-10 13:51:47 -0600232 else
Eric Van Hensbergend05dcfd2024-04-15 20:24:37 +0000233 return v9fs_fid_iget(sb, fid, new);
Aneesh Kumar K.Ved80fcf2011-07-06 16:32:31 +0530234}
235
Aneesh Kumar K.Ve0459f52011-02-28 17:04:09 +0530236#endif