trace: allow trace events with string arguments
[qemu.git] / hw / 9pfs / virtio-9p.h
blob17d44b41ca70693cdc8d1fc329295aeb643326c1
1 #ifndef _QEMU_VIRTIO_9P_H
2 #define _QEMU_VIRTIO_9P_H
4 #include <sys/types.h>
5 #include <dirent.h>
6 #include <sys/time.h>
7 #include <utime.h>
8 #include <sys/resource.h>
9 #include "hw/virtio.h"
10 #include "fsdev/file-op-9p.h"
12 /* The feature bitmap for virtio 9P */
13 /* The mount point is specified in a config variable */
14 #define VIRTIO_9P_MOUNT_TAG 0
16 enum {
17 P9_TLERROR = 6,
18 P9_RLERROR,
19 P9_TSTATFS = 8,
20 P9_RSTATFS,
21 P9_TLOPEN = 12,
22 P9_RLOPEN,
23 P9_TLCREATE = 14,
24 P9_RLCREATE,
25 P9_TSYMLINK = 16,
26 P9_RSYMLINK,
27 P9_TMKNOD = 18,
28 P9_RMKNOD,
29 P9_TRENAME = 20,
30 P9_RRENAME,
31 P9_TREADLINK = 22,
32 P9_RREADLINK,
33 P9_TGETATTR = 24,
34 P9_RGETATTR,
35 P9_TSETATTR = 26,
36 P9_RSETATTR,
37 P9_TXATTRWALK = 30,
38 P9_RXATTRWALK,
39 P9_TXATTRCREATE = 32,
40 P9_RXATTRCREATE,
41 P9_TREADDIR = 40,
42 P9_RREADDIR,
43 P9_TFSYNC = 50,
44 P9_RFSYNC,
45 P9_TLOCK = 52,
46 P9_RLOCK,
47 P9_TGETLOCK = 54,
48 P9_RGETLOCK,
49 P9_TLINK = 70,
50 P9_RLINK,
51 P9_TMKDIR = 72,
52 P9_RMKDIR,
53 P9_TRENAMEAT = 74,
54 P9_RRENAMEAT,
55 P9_TUNLINKAT = 76,
56 P9_RUNLINKAT,
57 P9_TVERSION = 100,
58 P9_RVERSION,
59 P9_TAUTH = 102,
60 P9_RAUTH,
61 P9_TATTACH = 104,
62 P9_RATTACH,
63 P9_TERROR = 106,
64 P9_RERROR,
65 P9_TFLUSH = 108,
66 P9_RFLUSH,
67 P9_TWALK = 110,
68 P9_RWALK,
69 P9_TOPEN = 112,
70 P9_ROPEN,
71 P9_TCREATE = 114,
72 P9_RCREATE,
73 P9_TREAD = 116,
74 P9_RREAD,
75 P9_TWRITE = 118,
76 P9_RWRITE,
77 P9_TCLUNK = 120,
78 P9_RCLUNK,
79 P9_TREMOVE = 122,
80 P9_RREMOVE,
81 P9_TSTAT = 124,
82 P9_RSTAT,
83 P9_TWSTAT = 126,
84 P9_RWSTAT,
88 /* qid.types */
89 enum {
90 P9_QTDIR = 0x80,
91 P9_QTAPPEND = 0x40,
92 P9_QTEXCL = 0x20,
93 P9_QTMOUNT = 0x10,
94 P9_QTAUTH = 0x08,
95 P9_QTTMP = 0x04,
96 P9_QTSYMLINK = 0x02,
97 P9_QTLINK = 0x01,
98 P9_QTFILE = 0x00,
101 enum p9_proto_version {
102 V9FS_PROTO_2000U = 0x01,
103 V9FS_PROTO_2000L = 0x02,
106 #define P9_NOTAG (u16)(~0)
107 #define P9_NOFID (u32)(~0)
108 #define P9_MAXWELEM 16
110 #define FID_REFERENCED 0x1
111 #define FID_NON_RECLAIMABLE 0x2
112 static inline const char *rpath(FsContext *ctx, const char *path, char *buffer)
114 snprintf(buffer, PATH_MAX, "%s/%s", ctx->fs_root, path);
115 return buffer;
119 * ample room for Twrite/Rread header
120 * size[4] Tread/Twrite tag[2] fid[4] offset[8] count[4]
122 #define P9_IOHDRSZ 24
124 typedef struct V9fsPDU V9fsPDU;
125 struct V9fsState;
127 struct V9fsPDU
129 uint32_t size;
130 uint16_t tag;
131 uint8_t id;
132 VirtQueueElement elem;
133 struct V9fsState *s;
134 QLIST_ENTRY(V9fsPDU) next;
138 /* FIXME
139 * 1) change user needs to set groups and stuff
142 /* from Linux's linux/virtio_9p.h */
144 /* The ID for virtio console */
145 #define VIRTIO_ID_9P 9
146 #define MAX_REQ 128
147 #define MAX_TAG_LEN 32
149 #define BUG_ON(cond) assert(!(cond))
151 typedef struct V9fsFidState V9fsFidState;
153 typedef struct V9fsString
155 int16_t size;
156 char *data;
157 } V9fsString;
159 typedef struct V9fsQID
161 int8_t type;
162 int32_t version;
163 int64_t path;
164 } V9fsQID;
166 typedef struct V9fsStat
168 int16_t size;
169 int16_t type;
170 int32_t dev;
171 V9fsQID qid;
172 int32_t mode;
173 int32_t atime;
174 int32_t mtime;
175 int64_t length;
176 V9fsString name;
177 V9fsString uid;
178 V9fsString gid;
179 V9fsString muid;
180 /* 9p2000.u */
181 V9fsString extension;
182 int32_t n_uid;
183 int32_t n_gid;
184 int32_t n_muid;
185 } V9fsStat;
187 enum {
188 P9_FID_NONE = 0,
189 P9_FID_FILE,
190 P9_FID_DIR,
191 P9_FID_XATTR,
194 typedef struct V9fsXattr
196 int64_t copied_len;
197 int64_t len;
198 void *value;
199 V9fsString name;
200 int flags;
201 } V9fsXattr;
203 struct V9fsFidState
205 int fid_type;
206 int32_t fid;
207 V9fsString path;
208 union {
209 int fd;
210 DIR *dir;
211 V9fsXattr xattr;
212 } fs;
213 union {
214 int fd;
215 DIR *dir;
216 } fs_reclaim;
217 int flags;
218 int open_flags;
219 uid_t uid;
220 int ref;
221 int clunked;
222 V9fsFidState *next;
223 V9fsFidState *rclm_lst;
226 typedef struct V9fsState
228 VirtIODevice vdev;
229 VirtQueue *vq;
230 V9fsPDU pdus[MAX_REQ];
231 QLIST_HEAD(, V9fsPDU) free_list;
232 V9fsFidState *fid_list;
233 FileOperations *ops;
234 FsContext ctx;
235 uint16_t tag_len;
236 uint8_t *tag;
237 size_t config_size;
238 enum p9_proto_version proto_version;
239 int32_t msize;
240 } V9fsState;
242 typedef struct V9fsStatState {
243 V9fsPDU *pdu;
244 size_t offset;
245 V9fsStat v9stat;
246 V9fsFidState *fidp;
247 struct stat stbuf;
248 } V9fsStatState;
250 typedef struct V9fsStatDotl {
251 uint64_t st_result_mask;
252 V9fsQID qid;
253 uint32_t st_mode;
254 uint32_t st_uid;
255 uint32_t st_gid;
256 uint64_t st_nlink;
257 uint64_t st_rdev;
258 uint64_t st_size;
259 uint64_t st_blksize;
260 uint64_t st_blocks;
261 uint64_t st_atime_sec;
262 uint64_t st_atime_nsec;
263 uint64_t st_mtime_sec;
264 uint64_t st_mtime_nsec;
265 uint64_t st_ctime_sec;
266 uint64_t st_ctime_nsec;
267 uint64_t st_btime_sec;
268 uint64_t st_btime_nsec;
269 uint64_t st_gen;
270 uint64_t st_data_version;
271 } V9fsStatDotl;
273 typedef struct V9fsOpenState {
274 V9fsPDU *pdu;
275 size_t offset;
276 int32_t mode;
277 V9fsFidState *fidp;
278 V9fsQID qid;
279 struct stat stbuf;
280 int iounit;
281 } V9fsOpenState;
283 typedef struct V9fsReadState {
284 V9fsPDU *pdu;
285 size_t offset;
286 int32_t count;
287 int32_t total;
288 int64_t off;
289 V9fsFidState *fidp;
290 struct iovec iov[128]; /* FIXME: bad, bad, bad */
291 struct iovec *sg;
292 off_t dir_pos;
293 struct dirent *dent;
294 struct stat stbuf;
295 V9fsString name;
296 V9fsStat v9stat;
297 int32_t len;
298 int32_t cnt;
299 int32_t max_count;
300 } V9fsReadState;
302 typedef struct V9fsWriteState {
303 V9fsPDU *pdu;
304 size_t offset;
305 int32_t len;
306 int32_t count;
307 int32_t total;
308 int64_t off;
309 V9fsFidState *fidp;
310 struct iovec iov[128]; /* FIXME: bad, bad, bad */
311 struct iovec *sg;
312 int cnt;
313 } V9fsWriteState;
315 typedef struct V9fsIattr
317 int32_t valid;
318 int32_t mode;
319 int32_t uid;
320 int32_t gid;
321 int64_t size;
322 int64_t atime_sec;
323 int64_t atime_nsec;
324 int64_t mtime_sec;
325 int64_t mtime_nsec;
326 } V9fsIattr;
328 struct virtio_9p_config
330 /* number of characters in tag */
331 uint16_t tag_len;
332 /* Variable size tag name */
333 uint8_t tag[0];
334 } QEMU_PACKED;
336 typedef struct V9fsMkState {
337 V9fsPDU *pdu;
338 size_t offset;
339 V9fsQID qid;
340 struct stat stbuf;
341 V9fsString name;
342 V9fsString fullname;
343 } V9fsMkState;
345 #define P9_LOCK_SUCCESS 0
346 #define P9_LOCK_BLOCKED 1
347 #define P9_LOCK_ERROR 2
348 #define P9_LOCK_GRACE 3
350 #define P9_LOCK_FLAGS_BLOCK 1
351 #define P9_LOCK_FLAGS_RECLAIM 2
353 typedef struct V9fsFlock
355 uint8_t type;
356 uint32_t flags;
357 uint64_t start; /* absolute offset */
358 uint64_t length;
359 uint32_t proc_id;
360 V9fsString client_id;
361 } V9fsFlock;
363 typedef struct V9fsGetlock
365 uint8_t type;
366 uint64_t start; /* absolute offset */
367 uint64_t length;
368 uint32_t proc_id;
369 V9fsString client_id;
370 } V9fsGetlock;
372 extern int open_fd_hw;
373 extern int total_open_fd;
375 size_t pdu_packunpack(void *addr, struct iovec *sg, int sg_count,
376 size_t offset, size_t size, int pack);
378 static inline size_t do_pdu_unpack(void *dst, struct iovec *sg, int sg_count,
379 size_t offset, size_t size)
381 return pdu_packunpack(dst, sg, sg_count, offset, size, 0);
384 extern void handle_9p_output(VirtIODevice *vdev, VirtQueue *vq);
385 extern void virtio_9p_set_fd_limit(void);
386 extern void v9fs_reclaim_fd(V9fsState *s);
387 #endif