v9fs.h 8.0 KB

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