client.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /*
  2. * include/net/9p/client.h
  3. *
  4. * 9P Client Definitions
  5. *
  6. * Copyright (C) 2008 by Eric Van Hensbergen <ericvh@gmail.com>
  7. * Copyright (C) 2007 by Latchesar Ionkov <lucho@ionkov.net>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2
  11. * as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to:
  20. * Free Software Foundation
  21. * 51 Franklin Street, Fifth Floor
  22. * Boston, MA 02111-1301 USA
  23. *
  24. */
  25. #ifndef NET_9P_CLIENT_H
  26. #define NET_9P_CLIENT_H
  27. /* Number of requests per row */
  28. #define P9_ROW_MAXTAG 255
  29. /** enum p9_proto_versions - 9P protocol versions
  30. * @p9_proto_legacy: 9P Legacy mode, pre-9P2000.u
  31. * @p9_proto_2000u: 9P2000.u extension
  32. * @p9_proto_2000L: 9P2000.L extension
  33. */
  34. enum p9_proto_versions{
  35. p9_proto_legacy,
  36. p9_proto_2000u,
  37. p9_proto_2000L,
  38. };
  39. /**
  40. * enum p9_trans_status - different states of underlying transports
  41. * @Connected: transport is connected and healthy
  42. * @Disconnected: transport has been disconnected
  43. * @Hung: transport is connected by wedged
  44. *
  45. * This enumeration details the various states a transport
  46. * instatiation can be in.
  47. */
  48. enum p9_trans_status {
  49. Connected,
  50. BeginDisconnect,
  51. Disconnected,
  52. Hung,
  53. };
  54. /**
  55. * enum p9_req_status_t - status of a request
  56. * @REQ_STATUS_IDLE: request slot unused
  57. * @REQ_STATUS_ALLOC: request has been allocated but not sent
  58. * @REQ_STATUS_UNSENT: request waiting to be sent
  59. * @REQ_STATUS_SENT: request sent to server
  60. * @REQ_STATUS_FLSH: a flush has been sent for this request
  61. * @REQ_STATUS_RCVD: response received from server
  62. * @REQ_STATUS_FLSHD: request has been flushed
  63. * @REQ_STATUS_ERROR: request encountered an error on the client side
  64. *
  65. * The @REQ_STATUS_IDLE state is used to mark a request slot as unused
  66. * but use is actually tracked by the idpool structure which handles tag
  67. * id allocation.
  68. *
  69. */
  70. enum p9_req_status_t {
  71. REQ_STATUS_IDLE,
  72. REQ_STATUS_ALLOC,
  73. REQ_STATUS_UNSENT,
  74. REQ_STATUS_SENT,
  75. REQ_STATUS_FLSH,
  76. REQ_STATUS_RCVD,
  77. REQ_STATUS_FLSHD,
  78. REQ_STATUS_ERROR,
  79. };
  80. /**
  81. * struct p9_req_t - request slots
  82. * @status: status of this request slot
  83. * @t_err: transport error
  84. * @flush_tag: tag of request being flushed (for flush requests)
  85. * @wq: wait_queue for the client to block on for this request
  86. * @tc: the request fcall structure
  87. * @rc: the response fcall structure
  88. * @aux: transport specific data (provided for trans_fd migration)
  89. * @req_list: link for higher level objects to chain requests
  90. *
  91. * Transport use an array to track outstanding requests
  92. * instead of a list. While this may incurr overhead during initial
  93. * allocation or expansion, it makes request lookup much easier as the
  94. * tag id is a index into an array. (We use tag+1 so that we can accommodate
  95. * the -1 tag for the T_VERSION request).
  96. * This also has the nice effect of only having to allocate wait_queues
  97. * once, instead of constantly allocating and freeing them. Its possible
  98. * other resources could benefit from this scheme as well.
  99. *
  100. */
  101. struct p9_req_t {
  102. int status;
  103. int t_err;
  104. wait_queue_head_t *wq;
  105. struct p9_fcall *tc;
  106. struct p9_fcall *rc;
  107. void *aux;
  108. struct list_head req_list;
  109. };
  110. /**
  111. * struct p9_client - per client instance state
  112. * @lock: protect @fidlist
  113. * @msize: maximum data size negotiated by protocol
  114. * @dotu: extension flags negotiated by protocol
  115. * @proto_version: 9P protocol version to use
  116. * @trans_mod: module API instantiated with this client
  117. * @trans: tranport instance state and API
  118. * @conn: connection state information used by trans_fd
  119. * @fidpool: fid handle accounting for session
  120. * @fidlist: List of active fid handles
  121. * @tagpool - transaction id accounting for session
  122. * @reqs - 2D array of requests
  123. * @max_tag - current maximum tag id allocated
  124. *
  125. * The client structure is used to keep track of various per-client
  126. * state that has been instantiated.
  127. * In order to minimize per-transaction overhead we use a
  128. * simple array to lookup requests instead of a hash table
  129. * or linked list. In order to support larger number of
  130. * transactions, we make this a 2D array, allocating new rows
  131. * when we need to grow the total number of the transactions.
  132. *
  133. * Each row is 256 requests and we'll support up to 256 rows for
  134. * a total of 64k concurrent requests per session.
  135. *
  136. * Bugs: duplicated data and potentially unnecessary elements.
  137. */
  138. struct p9_client {
  139. spinlock_t lock; /* protect client structure */
  140. unsigned int msize;
  141. unsigned char proto_version;
  142. struct p9_trans_module *trans_mod;
  143. enum p9_trans_status status;
  144. void *trans;
  145. struct p9_conn *conn;
  146. struct p9_idpool *fidpool;
  147. struct list_head fidlist;
  148. struct p9_idpool *tagpool;
  149. struct p9_req_t *reqs[P9_ROW_MAXTAG];
  150. int max_tag;
  151. };
  152. /**
  153. * struct p9_fid - file system entity handle
  154. * @clnt: back pointer to instantiating &p9_client
  155. * @fid: numeric identifier for this handle
  156. * @mode: current mode of this fid (enum?)
  157. * @qid: the &p9_qid server identifier this handle points to
  158. * @iounit: the server reported maximum transaction size for this file
  159. * @uid: the numeric uid of the local user who owns this handle
  160. * @rdir: readdir accounting structure (allocated on demand)
  161. * @flist: per-client-instance fid tracking
  162. * @dlist: per-dentry fid tracking
  163. *
  164. * TODO: This needs lots of explanation.
  165. */
  166. struct p9_fid {
  167. struct p9_client *clnt;
  168. u32 fid;
  169. int mode;
  170. struct p9_qid qid;
  171. u32 iounit;
  172. uid_t uid;
  173. void *rdir;
  174. struct list_head flist;
  175. struct list_head dlist; /* list of all fids attached to a dentry */
  176. };
  177. /**
  178. * struct p9_dirent - directory entry structure
  179. * @qid: The p9 server qid for this dirent
  180. * @d_off: offset to the next dirent
  181. * @d_type: type of file
  182. * @d_name: file name
  183. */
  184. struct p9_dirent {
  185. struct p9_qid qid;
  186. u64 d_off;
  187. unsigned char d_type;
  188. char d_name[256];
  189. };
  190. int p9_client_statfs(struct p9_fid *fid, struct p9_rstatfs *sb);
  191. int p9_client_rename(struct p9_fid *fid, struct p9_fid *newdirfid,
  192. const char *name);
  193. int p9_client_renameat(struct p9_fid *olddirfid, const char *old_name,
  194. struct p9_fid *newdirfid, const char *new_name);
  195. struct p9_client *p9_client_create(const char *dev_name, char *options);
  196. void p9_client_destroy(struct p9_client *clnt);
  197. void p9_client_disconnect(struct p9_client *clnt);
  198. void p9_client_begin_disconnect(struct p9_client *clnt);
  199. struct p9_fid *p9_client_attach(struct p9_client *clnt, struct p9_fid *afid,
  200. char *uname, u32 n_uname, char *aname);
  201. struct p9_fid *p9_client_walk(struct p9_fid *oldfid, uint16_t nwname,
  202. char **wnames, int clone);
  203. int p9_client_open(struct p9_fid *fid, int mode);
  204. int p9_client_fcreate(struct p9_fid *fid, char *name, u32 perm, int mode,
  205. char *extension);
  206. int p9_client_link(struct p9_fid *fid, struct p9_fid *oldfid, char *newname);
  207. int p9_client_symlink(struct p9_fid *fid, char *name, char *symname, gid_t gid,
  208. struct p9_qid *qid);
  209. int p9_client_create_dotl(struct p9_fid *ofid, char *name, u32 flags, u32 mode,
  210. gid_t gid, struct p9_qid *qid);
  211. int p9_client_clunk(struct p9_fid *fid);
  212. int p9_client_fsync(struct p9_fid *fid, int datasync);
  213. int p9_client_remove(struct p9_fid *fid);
  214. int p9_client_unlinkat(struct p9_fid *dfid, const char *name, int flags);
  215. int p9_client_read(struct p9_fid *fid, char *data, char __user *udata,
  216. u64 offset, u32 count);
  217. int p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
  218. u64 offset, u32 count);
  219. int p9_client_readdir(struct p9_fid *fid, char *data, u32 count, u64 offset);
  220. int p9dirent_read(struct p9_client *clnt, char *buf, int len,
  221. struct p9_dirent *dirent);
  222. struct p9_wstat *p9_client_stat(struct p9_fid *fid);
  223. int p9_client_wstat(struct p9_fid *fid, struct p9_wstat *wst);
  224. int p9_client_setattr(struct p9_fid *fid, struct p9_iattr_dotl *attr);
  225. struct p9_stat_dotl *p9_client_getattr_dotl(struct p9_fid *fid,
  226. u64 request_mask);
  227. int p9_client_mknod_dotl(struct p9_fid *oldfid, char *name, int mode,
  228. dev_t rdev, gid_t gid, struct p9_qid *);
  229. int p9_client_mkdir_dotl(struct p9_fid *fid, char *name, int mode,
  230. gid_t gid, struct p9_qid *);
  231. int p9_client_lock_dotl(struct p9_fid *fid, struct p9_flock *flock, u8 *status);
  232. int p9_client_getlock_dotl(struct p9_fid *fid, struct p9_getlock *fl);
  233. struct p9_req_t *p9_tag_lookup(struct p9_client *, u16);
  234. void p9_client_cb(struct p9_client *c, struct p9_req_t *req);
  235. int p9_parse_header(struct p9_fcall *, int32_t *, int8_t *, int16_t *, int);
  236. int p9stat_read(struct p9_client *, char *, int, struct p9_wstat *);
  237. void p9stat_free(struct p9_wstat *);
  238. int p9_is_proto_dotu(struct p9_client *clnt);
  239. int p9_is_proto_dotl(struct p9_client *clnt);
  240. struct p9_fid *p9_client_xattrwalk(struct p9_fid *, const char *, u64 *);
  241. int p9_client_xattrcreate(struct p9_fid *, const char *, u64, int);
  242. int p9_client_readlink(struct p9_fid *fid, char **target);
  243. #endif /* NET_9P_CLIENT_H */