]> git.proxmox.com Git - qemu.git/blame - hw/virtio-9p.h
[virtio-9p] Introduce server side TFSYNC/RFSYNC for dotl
[qemu.git] / hw / virtio-9p.h
CommitLineData
9f107513
AL
1#ifndef _QEMU_VIRTIO_9P_H
2#define _QEMU_VIRTIO_9P_H
3
4#include <sys/types.h>
5#include <dirent.h>
6#include <sys/time.h>
7#include <utime.h>
8
9#include "file-op-9p.h"
10
11/* The feature bitmap for virtio 9P */
12/* The mount point is specified in a config variable */
13#define VIRTIO_9P_MOUNT_TAG 0
14
15enum {
8f4d1ca5
AB
16 P9_TLERROR = 6,
17 P9_RLERROR,
be940c87
MK
18 P9_TSTATFS = 8,
19 P9_RSTATFS,
771e9d4c
MK
20 P9_TLOPEN = 12,
21 P9_RLOPEN,
c1568af5
VJJ
22 P9_TLCREATE = 14,
23 P9_RLCREATE,
08c60fc9
VJJ
24 P9_TSYMLINK = 16,
25 P9_RSYMLINK,
5268cecc
MK
26 P9_TMKNOD = 18,
27 P9_RMKNOD,
c7b4b0b3
MK
28 P9_TRENAME = 20,
29 P9_RRENAME,
00ede4c2
SK
30 P9_TGETATTR = 24,
31 P9_RGETATTR,
c79ce737
SK
32 P9_TSETATTR = 26,
33 P9_RSETATTR,
fa32ef88
AK
34 P9_TXATTRWALK = 30,
35 P9_RXATTRWALK,
10b468bd
AK
36 P9_TXATTRCREATE = 32,
37 P9_RXATTRCREATE,
c18e2f94
SK
38 P9_TREADDIR = 40,
39 P9_RREADDIR,
b41e95d3
VJJ
40 P9_TFSYNC = 50,
41 P9_RFSYNC,
82cc3ee8
MK
42 P9_TLOCK = 52,
43 P9_RLOCK,
8f354003
MK
44 P9_TGETLOCK = 54,
45 P9_RGETLOCK,
b2c224be
VJJ
46 P9_TLINK = 70,
47 P9_RLINK,
b67592ea
MK
48 P9_TMKDIR = 72,
49 P9_RMKDIR,
9f107513
AL
50 P9_TVERSION = 100,
51 P9_RVERSION,
52 P9_TAUTH = 102,
53 P9_RAUTH,
54 P9_TATTACH = 104,
55 P9_RATTACH,
56 P9_TERROR = 106,
57 P9_RERROR,
58 P9_TFLUSH = 108,
59 P9_RFLUSH,
60 P9_TWALK = 110,
61 P9_RWALK,
62 P9_TOPEN = 112,
63 P9_ROPEN,
64 P9_TCREATE = 114,
65 P9_RCREATE,
66 P9_TREAD = 116,
67 P9_RREAD,
68 P9_TWRITE = 118,
69 P9_RWRITE,
70 P9_TCLUNK = 120,
71 P9_RCLUNK,
72 P9_TREMOVE = 122,
73 P9_RREMOVE,
74 P9_TSTAT = 124,
75 P9_RSTAT,
76 P9_TWSTAT = 126,
77 P9_RWSTAT,
78};
79
80
81/* qid.types */
82enum {
83 P9_QTDIR = 0x80,
84 P9_QTAPPEND = 0x40,
85 P9_QTEXCL = 0x20,
86 P9_QTMOUNT = 0x10,
87 P9_QTAUTH = 0x08,
88 P9_QTTMP = 0x04,
89 P9_QTSYMLINK = 0x02,
90 P9_QTLINK = 0x01,
91 P9_QTFILE = 0x00,
92};
93
84151514
MK
94enum p9_proto_version {
95 V9FS_PROTO_2000U = 0x01,
96 V9FS_PROTO_2000L = 0x02,
97};
98
9f107513
AL
99#define P9_NOTAG (u16)(~0)
100#define P9_NOFID (u32)(~0)
101#define P9_MAXWELEM 16
102
5e94c103
MK
103/*
104 * ample room for Twrite/Rread header
105 * size[4] Tread/Twrite tag[2] fid[4] offset[8] count[4]
106 */
107#define P9_IOHDRSZ 24
108
9f107513
AL
109typedef struct V9fsPDU V9fsPDU;
110
111struct V9fsPDU
112{
113 uint32_t size;
114 uint16_t tag;
115 uint8_t id;
116 VirtQueueElement elem;
117 QLIST_ENTRY(V9fsPDU) next;
118};
119
120
121/* FIXME
122 * 1) change user needs to set groups and stuff
123 */
124
125/* from Linux's linux/virtio_9p.h */
126
127/* The ID for virtio console */
128#define VIRTIO_ID_9P 9
129#define MAX_REQ 128
130#define MAX_TAG_LEN 32
131
132#define BUG_ON(cond) assert(!(cond))
133
134typedef struct V9fsFidState V9fsFidState;
135
136typedef struct V9fsString
137{
138 int16_t size;
139 char *data;
140} V9fsString;
141
142typedef struct V9fsQID
143{
144 int8_t type;
145 int32_t version;
146 int64_t path;
147} V9fsQID;
148
149typedef struct V9fsStat
150{
151 int16_t size;
152 int16_t type;
153 int32_t dev;
154 V9fsQID qid;
155 int32_t mode;
156 int32_t atime;
157 int32_t mtime;
158 int64_t length;
159 V9fsString name;
160 V9fsString uid;
161 V9fsString gid;
162 V9fsString muid;
163 /* 9p2000.u */
164 V9fsString extension;
165 int32_t n_uid;
166 int32_t n_gid;
167 int32_t n_muid;
168} V9fsStat;
169
d62dbb51
AK
170enum {
171 P9_FID_NONE = 0,
172 P9_FID_FILE,
173 P9_FID_DIR,
174 P9_FID_XATTR,
175};
176
177typedef struct V9fsXattr
178{
179 int64_t copied_len;
180 int64_t len;
181 void *value;
182 V9fsString name;
183 int flags;
184} V9fsXattr;
185
9f107513
AL
186struct V9fsFidState
187{
d62dbb51 188 int fid_type;
9f107513
AL
189 int32_t fid;
190 V9fsString path;
d62dbb51
AK
191 union {
192 int fd;
193 DIR *dir;
194 V9fsXattr xattr;
195 } fs;
9f107513
AL
196 uid_t uid;
197 V9fsFidState *next;
198};
199
200typedef struct V9fsState
201{
202 VirtIODevice vdev;
203 VirtQueue *vq;
204 V9fsPDU pdus[MAX_REQ];
205 QLIST_HEAD(, V9fsPDU) free_list;
206 V9fsFidState *fid_list;
207 FileOperations *ops;
208 FsContext ctx;
209 uint16_t tag_len;
210 uint8_t *tag;
211 size_t config_size;
84151514 212 enum p9_proto_version proto_version;
5e94c103 213 int32_t msize;
9f107513
AL
214} V9fsState;
215
fac4f111
VJJ
216typedef struct V9fsCreateState {
217 V9fsPDU *pdu;
218 size_t offset;
219 V9fsFidState *fidp;
220 V9fsQID qid;
221 int32_t perm;
222 int8_t mode;
223 struct stat stbuf;
224 V9fsString name;
225 V9fsString extension;
226 V9fsString fullname;
5e94c103 227 int iounit;
fac4f111
VJJ
228} V9fsCreateState;
229
c1568af5
VJJ
230typedef struct V9fsLcreateState {
231 V9fsPDU *pdu;
232 size_t offset;
233 V9fsFidState *fidp;
234 V9fsQID qid;
235 int32_t iounit;
236 struct stat stbuf;
237 V9fsString name;
238 V9fsString fullname;
239} V9fsLcreateState;
240
fac4f111
VJJ
241typedef struct V9fsStatState {
242 V9fsPDU *pdu;
243 size_t offset;
244 V9fsStat v9stat;
245 V9fsFidState *fidp;
246 struct stat stbuf;
247} V9fsStatState;
248
00ede4c2
SK
249typedef struct V9fsStatDotl {
250 uint64_t st_result_mask;
251 V9fsQID qid;
252 uint32_t st_mode;
253 uint32_t st_uid;
254 uint32_t st_gid;
255 uint64_t st_nlink;
256 uint64_t st_rdev;
257 uint64_t st_size;
258 uint64_t st_blksize;
259 uint64_t st_blocks;
260 uint64_t st_atime_sec;
261 uint64_t st_atime_nsec;
262 uint64_t st_mtime_sec;
263 uint64_t st_mtime_nsec;
264 uint64_t st_ctime_sec;
265 uint64_t st_ctime_nsec;
266 uint64_t st_btime_sec;
267 uint64_t st_btime_nsec;
268 uint64_t st_gen;
269 uint64_t st_data_version;
270} V9fsStatDotl;
271
272typedef struct V9fsStatStateDotl {
273 V9fsPDU *pdu;
274 size_t offset;
275 V9fsStatDotl v9stat_dotl;
276 struct stat stbuf;
277} V9fsStatStateDotl;
278
279
fac4f111
VJJ
280typedef struct V9fsWalkState {
281 V9fsPDU *pdu;
282 size_t offset;
283 int16_t nwnames;
284 int name_idx;
285 V9fsQID *qids;
286 V9fsFidState *fidp;
287 V9fsFidState *newfidp;
288 V9fsString path;
289 V9fsString *wnames;
290 struct stat stbuf;
291} V9fsWalkState;
292
293typedef struct V9fsOpenState {
294 V9fsPDU *pdu;
295 size_t offset;
771e9d4c 296 int32_t mode;
fac4f111
VJJ
297 V9fsFidState *fidp;
298 V9fsQID qid;
299 struct stat stbuf;
5e94c103 300 int iounit;
fac4f111
VJJ
301} V9fsOpenState;
302
303typedef struct V9fsReadState {
304 V9fsPDU *pdu;
305 size_t offset;
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 off_t dir_pos;
313 struct dirent *dent;
314 struct stat stbuf;
315 V9fsString name;
316 V9fsStat v9stat;
317 int32_t len;
318 int32_t cnt;
319 int32_t max_count;
320} V9fsReadState;
321
322typedef struct V9fsWriteState {
323 V9fsPDU *pdu;
324 size_t offset;
325 int32_t len;
326 int32_t count;
327 int32_t total;
328 int64_t off;
329 V9fsFidState *fidp;
330 struct iovec iov[128]; /* FIXME: bad, bad, bad */
331 struct iovec *sg;
332 int cnt;
333} V9fsWriteState;
334
335typedef struct V9fsRemoveState {
336 V9fsPDU *pdu;
337 size_t offset;
338 V9fsFidState *fidp;
339} V9fsRemoveState;
340
341typedef struct V9fsWstatState
342{
343 V9fsPDU *pdu;
344 size_t offset;
345 int16_t unused;
346 V9fsStat v9stat;
347 V9fsFidState *fidp;
348 struct stat stbuf;
fac4f111
VJJ
349} V9fsWstatState;
350
08c60fc9
VJJ
351typedef struct V9fsSymlinkState
352{
353 V9fsPDU *pdu;
354 size_t offset;
355 V9fsString name;
356 V9fsString symname;
357 V9fsString fullname;
358 V9fsFidState *dfidp;
359 V9fsQID qid;
360 struct stat stbuf;
361} V9fsSymlinkState;
362
c79ce737
SK
363typedef struct V9fsIattr
364{
365 int32_t valid;
366 int32_t mode;
367 int32_t uid;
368 int32_t gid;
369 int64_t size;
370 int64_t atime_sec;
371 int64_t atime_nsec;
372 int64_t mtime_sec;
373 int64_t mtime_nsec;
374} V9fsIattr;
375
376typedef struct V9fsSetattrState
377{
378 V9fsPDU *pdu;
379 size_t offset;
380 V9fsIattr v9iattr;
381 V9fsFidState *fidp;
382} V9fsSetattrState;
383
9f107513
AL
384struct virtio_9p_config
385{
386 /* number of characters in tag */
387 uint16_t tag_len;
388 /* Variable size tag name */
389 uint8_t tag[0];
390} __attribute__((packed));
391
be940c87
MK
392typedef struct V9fsStatfs
393{
394 uint32_t f_type;
395 uint32_t f_bsize;
396 uint64_t f_blocks;
397 uint64_t f_bfree;
398 uint64_t f_bavail;
399 uint64_t f_files;
400 uint64_t f_ffree;
401 uint64_t fsid_val;
402 uint32_t f_namelen;
403} V9fsStatfs;
404
405typedef struct V9fsStatfsState {
406 V9fsPDU *pdu;
407 size_t offset;
408 int32_t fid;
409 V9fsStatfs v9statfs;
410 V9fsFidState *fidp;
411 struct statfs stbuf;
412} V9fsStatfsState;
413
5268cecc
MK
414typedef struct V9fsMkState {
415 V9fsPDU *pdu;
416 size_t offset;
417 V9fsQID qid;
418 struct stat stbuf;
419 V9fsString name;
420 V9fsString fullname;
421} V9fsMkState;
422
c7b4b0b3
MK
423typedef struct V9fsRenameState {
424 V9fsPDU *pdu;
425 V9fsFidState *fidp;
426 size_t offset;
427 int32_t newdirfid;
428 V9fsString name;
429} V9fsRenameState;
430
fa32ef88
AK
431typedef struct V9fsXattrState
432{
433 V9fsPDU *pdu;
434 size_t offset;
435 V9fsFidState *file_fidp;
436 V9fsFidState *xattr_fidp;
437 V9fsString name;
438 int64_t size;
439 int flags;
440 void *value;
441} V9fsXattrState;
442
82cc3ee8
MK
443#define P9_LOCK_SUCCESS 0
444#define P9_LOCK_BLOCKED 1
445#define P9_LOCK_ERROR 2
446#define P9_LOCK_GRACE 3
447
448#define P9_LOCK_FLAGS_BLOCK 1
449#define P9_LOCK_FLAGS_RECLAIM 2
450
451typedef struct V9fsFlock
452{
453 uint8_t type;
454 uint32_t flags;
455 uint64_t start; /* absolute offset */
456 uint64_t length;
457 uint32_t proc_id;
458 V9fsString client_id;
459} V9fsFlock;
460
461typedef struct V9fsLockState
462{
463 V9fsPDU *pdu;
464 size_t offset;
465 int8_t status;
466 struct stat stbuf;
467 V9fsFidState *fidp;
468 V9fsFlock *flock;
469} V9fsLockState;
470
8f354003
MK
471typedef struct V9fsGetlock
472{
473 uint8_t type;
474 uint64_t start; /* absolute offset */
475 uint64_t length;
476 uint32_t proc_id;
477 V9fsString client_id;
478} V9fsGetlock;
479
480typedef struct V9fsGetlockState
481{
482 V9fsPDU *pdu;
483 size_t offset;
484 struct stat stbuf;
485 V9fsFidState *fidp;
486 V9fsGetlock *glock;
487} V9fsGetlockState;
488
489
9f107513
AL
490extern size_t pdu_packunpack(void *addr, struct iovec *sg, int sg_count,
491 size_t offset, size_t size, int pack);
492
493static inline size_t do_pdu_unpack(void *dst, struct iovec *sg, int sg_count,
494 size_t offset, size_t size)
495{
496 return pdu_packunpack(dst, sg, sg_count, offset, size, 0);
497}
498
499#endif