v9fs.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * V9FS definitions.
  4. *
  5. * Copyright (C) 2004-2008 by Eric Van Hensbergen <ericvh@gmail.com>
  6. * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
  7. */
  8. #ifndef FS_9P_V9FS_H
  9. #define FS_9P_V9FS_H
  10. #include <linux/backing-dev.h>
  11. #include <linux/netfs.h>
  12. #include <linux/fs_parser.h>
  13. #include <net/9p/client.h>
  14. #include <net/9p/transport.h>
  15. /**
  16. * enum p9_session_flags - option flags for each 9P session
  17. * @V9FS_PROTO_2000U: whether or not to use 9P2000.u extensions
  18. * @V9FS_PROTO_2000L: whether or not to use 9P2000.l extensions
  19. * @V9FS_ACCESS_SINGLE: only the mounting user can access the hierarchy
  20. * @V9FS_ACCESS_USER: a new attach will be issued for every user (default)
  21. * @V9FS_ACCESS_CLIENT: Just like user, but access check is performed on client.
  22. * @V9FS_ACCESS_ANY: use a single attach for all users
  23. * @V9FS_ACCESS_MASK: bit mask of different ACCESS options
  24. * @V9FS_POSIX_ACL: POSIX ACLs are enforced
  25. *
  26. * Session flags reflect options selected by users at mount time
  27. */
  28. #define V9FS_ACCESS_ANY (V9FS_ACCESS_SINGLE | \
  29. V9FS_ACCESS_USER | \
  30. V9FS_ACCESS_CLIENT)
  31. #define V9FS_ACCESS_MASK V9FS_ACCESS_ANY
  32. #define V9FS_ACL_MASK V9FS_POSIX_ACL
  33. enum p9_session_flags {
  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
  44. };
  45. /**
  46. * enum p9_cache_shortcuts - human readable cache preferences
  47. * @CACHE_SC_NONE: disable all caches
  48. * @CACHE_SC_READAHEAD: only provide caching for readahead
  49. * @CACHE_SC_MMAP: provide caching to enable mmap
  50. * @CACHE_SC_LOOSE: non-coherent caching for files and meta data
  51. * @CACHE_SC_FSCACHE: persistent non-coherent caching for files and meta-data
  52. *
  53. */
  54. enum p9_cache_shortcuts {
  55. CACHE_SC_NONE = 0b00000000,
  56. CACHE_SC_READAHEAD = 0b00000001,
  57. CACHE_SC_MMAP = 0b00000101,
  58. CACHE_SC_LOOSE = 0b00001111,
  59. CACHE_SC_FSCACHE = 0b10001111,
  60. };
  61. /**
  62. * enum p9_cache_bits - possible values of ->cache
  63. * @CACHE_NONE: caches disabled
  64. * @CACHE_FILE: file caching (open to close)
  65. * @CACHE_META: meta-data and directory caching
  66. * @CACHE_WRITEBACK: write-back caching for files
  67. * @CACHE_LOOSE: don't check cache consistency
  68. * @CACHE_FSCACHE: local persistent caches
  69. *
  70. */
  71. enum p9_cache_bits {
  72. CACHE_NONE = 0b00000000,
  73. CACHE_FILE = 0b00000001,
  74. CACHE_META = 0b00000010,
  75. CACHE_WRITEBACK = 0b00000100,
  76. CACHE_LOOSE = 0b00001000,
  77. CACHE_FSCACHE = 0b10000000,
  78. };
  79. /**
  80. * struct v9fs_session_info - per-instance session information
  81. * @flags: session options of type &p9_session_flags
  82. * @nodev: set to 1 to disable device mapping
  83. * @debug: debug level
  84. * @afid: authentication handle
  85. * @cache: cache mode of type &p9_cache_bits
  86. * @cachetag: the tag of the cache associated with this session
  87. * @fscache: session cookie associated with FS-Cache
  88. * @uname: string user name to mount hierarchy as
  89. * @aname: mount specifier for remote hierarchy
  90. * @maxdata: maximum data to be sent/recvd per protocol message
  91. * @dfltuid: default numeric userid to mount hierarchy as
  92. * @dfltgid: default numeric groupid to mount hierarchy as
  93. * @uid: if %V9FS_ACCESS_SINGLE, the numeric uid which mounted the hierarchy
  94. * @clnt: reference to 9P network client instantiated for this session
  95. * @slist: reference to list of registered 9p sessions
  96. *
  97. * This structure holds state for each session instance established during
  98. * a sys_mount() .
  99. *
  100. * Bugs: there seems to be a lot of state which could be condensed and/or
  101. * removed.
  102. */
  103. struct v9fs_session_info {
  104. /* options */
  105. unsigned int flags;
  106. unsigned char nodev;
  107. unsigned short debug;
  108. unsigned int afid;
  109. unsigned int cache;
  110. #ifdef CONFIG_9P_FSCACHE
  111. char *cachetag;
  112. struct fscache_volume *fscache;
  113. #endif
  114. char *uname; /* user name to mount as */
  115. char *aname; /* name of remote hierarchy being mounted */
  116. unsigned int maxdata; /* max data for client interface */
  117. kuid_t dfltuid; /* default uid/muid for legacy support */
  118. kgid_t dfltgid; /* default gid for legacy support */
  119. kuid_t uid; /* if ACCESS_SINGLE, the uid that has access */
  120. struct p9_client *clnt; /* 9p client */
  121. struct list_head slist; /* list of sessions registered with v9fs */
  122. struct rw_semaphore rename_sem;
  123. long session_lock_timeout; /* retry interval for blocking locks */
  124. };
  125. /* cache_validity flags */
  126. #define V9FS_INO_INVALID_ATTR 0x01
  127. struct v9fs_inode {
  128. struct netfs_inode netfs; /* Netfslib context and vfs inode */
  129. struct p9_qid qid;
  130. unsigned int cache_validity;
  131. struct mutex v_mutex;
  132. };
  133. static inline struct v9fs_inode *V9FS_I(const struct inode *inode)
  134. {
  135. return container_of(inode, struct v9fs_inode, netfs.inode);
  136. }
  137. static inline struct fscache_cookie *v9fs_inode_cookie(struct v9fs_inode *v9inode)
  138. {
  139. #ifdef CONFIG_9P_FSCACHE
  140. return netfs_i_cookie(&v9inode->netfs);
  141. #else
  142. return NULL;
  143. #endif
  144. }
  145. static inline struct fscache_volume *v9fs_session_cache(struct v9fs_session_info *v9ses)
  146. {
  147. #ifdef CONFIG_9P_FSCACHE
  148. return v9ses->fscache;
  149. #else
  150. return NULL;
  151. #endif
  152. }
  153. extern const struct fs_parameter_spec v9fs_param_spec[];
  154. extern int v9fs_parse_param(struct fs_context *fc, struct fs_parameter *param);
  155. extern int v9fs_show_options(struct seq_file *m, struct dentry *root);
  156. struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses,
  157. struct fs_context *fc);
  158. extern void v9fs_session_close(struct v9fs_session_info *v9ses);
  159. extern void v9fs_session_cancel(struct v9fs_session_info *v9ses);
  160. extern void v9fs_session_begin_cancel(struct v9fs_session_info *v9ses);
  161. extern struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
  162. unsigned int flags);
  163. extern int v9fs_vfs_unlink(struct inode *i, struct dentry *d);
  164. extern int v9fs_vfs_rmdir(struct inode *i, struct dentry *d);
  165. extern int v9fs_vfs_rename(struct mnt_idmap *idmap,
  166. struct inode *old_dir, struct dentry *old_dentry,
  167. struct inode *new_dir, struct dentry *new_dentry,
  168. unsigned int flags);
  169. extern struct inode *v9fs_inode_from_fid(struct v9fs_session_info *v9ses,
  170. struct p9_fid *fid,
  171. struct super_block *sb, int new);
  172. extern const struct inode_operations v9fs_dir_inode_operations_dotl;
  173. extern const struct inode_operations v9fs_file_inode_operations_dotl;
  174. extern const struct inode_operations v9fs_symlink_inode_operations_dotl;
  175. extern const struct netfs_request_ops v9fs_req_ops;
  176. extern struct inode *v9fs_inode_from_fid_dotl(struct v9fs_session_info *v9ses,
  177. struct p9_fid *fid,
  178. struct super_block *sb, int new);
  179. /* other default globals */
  180. #define V9FS_PORT 564
  181. #define V9FS_DEFUSER "nobody"
  182. #define V9FS_DEFANAME ""
  183. #define V9FS_DEFUID KUIDT_INIT(-2)
  184. #define V9FS_DEFGID KGIDT_INIT(-2)
  185. static inline struct v9fs_session_info *v9fs_inode2v9ses(struct inode *inode)
  186. {
  187. return inode->i_sb->s_fs_info;
  188. }
  189. static inline struct v9fs_session_info *v9fs_dentry2v9ses(const struct dentry *dentry)
  190. {
  191. return dentry->d_sb->s_fs_info;
  192. }
  193. static inline int v9fs_proto_dotu(struct v9fs_session_info *v9ses)
  194. {
  195. return v9ses->flags & V9FS_PROTO_2000U;
  196. }
  197. static inline int v9fs_proto_dotl(struct v9fs_session_info *v9ses)
  198. {
  199. return v9ses->flags & V9FS_PROTO_2000L;
  200. }
  201. /**
  202. * v9fs_get_inode_from_fid - Helper routine to populate an inode by
  203. * issuing a attribute request
  204. * @v9ses: session information
  205. * @fid: fid to issue attribute request for
  206. * @sb: superblock on which to create inode
  207. *
  208. */
  209. static inline struct inode *
  210. v9fs_get_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid,
  211. struct super_block *sb)
  212. {
  213. if (v9fs_proto_dotl(v9ses))
  214. return v9fs_inode_from_fid_dotl(v9ses, fid, sb, 0);
  215. else
  216. return v9fs_inode_from_fid(v9ses, fid, sb, 0);
  217. }
  218. /**
  219. * v9fs_get_new_inode_from_fid - Helper routine to populate an inode by
  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 *
  227. v9fs_get_new_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid,
  228. struct super_block *sb)
  229. {
  230. if (v9fs_proto_dotl(v9ses))
  231. return v9fs_inode_from_fid_dotl(v9ses, fid, sb, 1);
  232. else
  233. return v9fs_inode_from_fid(v9ses, fid, sb, 1);
  234. }
  235. #endif