blob: 2ae4ce7189c63d4adb767e9390e098ecde4787eb [file] [log] [blame]
Anthony Liguori9f107512010-04-29 17:44:44 +05301#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 {
Arun R Bharadwaj8f4d1ca2010-07-28 14:10:22 +053016 P9_TLERROR = 6,
17 P9_RLERROR,
M. Mohan Kumarbe940c82010-05-10 12:11:03 +053018 P9_TSTATFS = 8,
19 P9_RSTATFS,
M. Mohan Kumar771e9d42010-06-22 19:47:04 +053020 P9_TLOPEN = 12,
21 P9_RLOPEN,
Venkateswararao Jujjuri (JV)c1568af2010-06-17 18:27:24 -070022 P9_TLCREATE = 14,
23 P9_RLCREATE,
Venkateswararao Jujjuri (JV)08c60fc2010-06-09 14:02:08 -070024 P9_TSYMLINK = 16,
25 P9_RSYMLINK,
M. Mohan Kumar5268cec2010-06-22 12:24:09 +053026 P9_TMKNOD = 18,
27 P9_RMKNOD,
M. Mohan Kumarc7b4b0b2010-06-22 12:29:41 +053028 P9_TRENAME = 20,
29 P9_RRENAME,
M. Mohan Kumardf0973a2010-09-14 15:08:25 +053030 P9_TREADLINK = 22,
31 P9_RREADLINK,
Sripathi Kodi00ede4c2010-07-20 11:44:41 +053032 P9_TGETATTR = 24,
33 P9_RGETATTR,
Sripathi Kodic79ce732010-06-17 18:18:47 +053034 P9_TSETATTR = 26,
35 P9_RSETATTR,
Aneesh Kumar K.Vfa32ef82010-09-02 11:09:06 +053036 P9_TXATTRWALK = 30,
37 P9_RXATTRWALK,
Aneesh Kumar K.V10b468b2010-09-02 11:09:07 +053038 P9_TXATTRCREATE = 32,
39 P9_RXATTRCREATE,
Sripathi Kodic18e2f92010-06-09 14:57:57 +053040 P9_TREADDIR = 40,
41 P9_RREADDIR,
Venkateswararao Jujjuri (JV)b41e95d2010-09-22 17:18:33 -070042 P9_TFSYNC = 50,
43 P9_RFSYNC,
M. Mohan Kumar82cc3ee2010-09-08 02:19:32 +053044 P9_TLOCK = 52,
45 P9_RLOCK,
M. Mohan Kumar8f354002010-09-08 02:36:52 +053046 P9_TGETLOCK = 54,
47 P9_RGETLOCK,
Venkateswararao Jujjuri (JV)b2c224b2010-06-09 11:21:15 -070048 P9_TLINK = 70,
49 P9_RLINK,
M. Mohan Kumarb67592e2010-06-22 12:25:22 +053050 P9_TMKDIR = 72,
51 P9_RMKDIR,
Anthony Liguori9f107512010-04-29 17:44:44 +053052 P9_TVERSION = 100,
53 P9_RVERSION,
54 P9_TAUTH = 102,
55 P9_RAUTH,
56 P9_TATTACH = 104,
57 P9_RATTACH,
58 P9_TERROR = 106,
59 P9_RERROR,
60 P9_TFLUSH = 108,
61 P9_RFLUSH,
62 P9_TWALK = 110,
63 P9_RWALK,
64 P9_TOPEN = 112,
65 P9_ROPEN,
66 P9_TCREATE = 114,
67 P9_RCREATE,
68 P9_TREAD = 116,
69 P9_RREAD,
70 P9_TWRITE = 118,
71 P9_RWRITE,
72 P9_TCLUNK = 120,
73 P9_RCLUNK,
74 P9_TREMOVE = 122,
75 P9_RREMOVE,
76 P9_TSTAT = 124,
77 P9_RSTAT,
78 P9_TWSTAT = 126,
79 P9_RWSTAT,
80};
81
82
83/* qid.types */
84enum {
85 P9_QTDIR = 0x80,
86 P9_QTAPPEND = 0x40,
87 P9_QTEXCL = 0x20,
88 P9_QTMOUNT = 0x10,
89 P9_QTAUTH = 0x08,
90 P9_QTTMP = 0x04,
91 P9_QTSYMLINK = 0x02,
92 P9_QTLINK = 0x01,
93 P9_QTFILE = 0x00,
94};
95
M. Mohan Kumar84151512010-05-27 13:57:29 +053096enum p9_proto_version {
97 V9FS_PROTO_2000U = 0x01,
98 V9FS_PROTO_2000L = 0x02,
99};
100
Anthony Liguori9f107512010-04-29 17:44:44 +0530101#define P9_NOTAG (u16)(~0)
102#define P9_NOFID (u32)(~0)
103#define P9_MAXWELEM 16
104
M. Mohan Kumar5e94c102010-06-09 19:14:28 +0530105/*
106 * ample room for Twrite/Rread header
107 * size[4] Tread/Twrite tag[2] fid[4] offset[8] count[4]
108 */
109#define P9_IOHDRSZ 24
110
Anthony Liguori9f107512010-04-29 17:44:44 +0530111typedef struct V9fsPDU V9fsPDU;
112
113struct V9fsPDU
114{
115 uint32_t size;
116 uint16_t tag;
117 uint8_t id;
118 VirtQueueElement elem;
119 QLIST_ENTRY(V9fsPDU) next;
120};
121
122
123/* FIXME
124 * 1) change user needs to set groups and stuff
125 */
126
127/* from Linux's linux/virtio_9p.h */
128
129/* The ID for virtio console */
130#define VIRTIO_ID_9P 9
131#define MAX_REQ 128
132#define MAX_TAG_LEN 32
133
134#define BUG_ON(cond) assert(!(cond))
135
136typedef struct V9fsFidState V9fsFidState;
137
138typedef struct V9fsString
139{
140 int16_t size;
141 char *data;
142} V9fsString;
143
144typedef struct V9fsQID
145{
146 int8_t type;
147 int32_t version;
148 int64_t path;
149} V9fsQID;
150
151typedef struct V9fsStat
152{
153 int16_t size;
154 int16_t type;
155 int32_t dev;
156 V9fsQID qid;
157 int32_t mode;
158 int32_t atime;
159 int32_t mtime;
160 int64_t length;
161 V9fsString name;
162 V9fsString uid;
163 V9fsString gid;
164 V9fsString muid;
165 /* 9p2000.u */
166 V9fsString extension;
167 int32_t n_uid;
168 int32_t n_gid;
169 int32_t n_muid;
170} V9fsStat;
171
Aneesh Kumar K.Vd62dbb52010-09-02 11:09:06 +0530172enum {
173 P9_FID_NONE = 0,
174 P9_FID_FILE,
175 P9_FID_DIR,
176 P9_FID_XATTR,
177};
178
179typedef struct V9fsXattr
180{
181 int64_t copied_len;
182 int64_t len;
183 void *value;
184 V9fsString name;
185 int flags;
186} V9fsXattr;
187
Anthony Liguori9f107512010-04-29 17:44:44 +0530188struct V9fsFidState
189{
Aneesh Kumar K.Vd62dbb52010-09-02 11:09:06 +0530190 int fid_type;
Anthony Liguori9f107512010-04-29 17:44:44 +0530191 int32_t fid;
192 V9fsString path;
Aneesh Kumar K.Vd62dbb52010-09-02 11:09:06 +0530193 union {
194 int fd;
195 DIR *dir;
196 V9fsXattr xattr;
197 } fs;
Anthony Liguori9f107512010-04-29 17:44:44 +0530198 uid_t uid;
199 V9fsFidState *next;
200};
201
202typedef struct V9fsState
203{
204 VirtIODevice vdev;
205 VirtQueue *vq;
206 V9fsPDU pdus[MAX_REQ];
207 QLIST_HEAD(, V9fsPDU) free_list;
208 V9fsFidState *fid_list;
209 FileOperations *ops;
210 FsContext ctx;
211 uint16_t tag_len;
212 uint8_t *tag;
213 size_t config_size;
M. Mohan Kumar84151512010-05-27 13:57:29 +0530214 enum p9_proto_version proto_version;
M. Mohan Kumar5e94c102010-06-09 19:14:28 +0530215 int32_t msize;
Anthony Liguori9f107512010-04-29 17:44:44 +0530216} V9fsState;
217
Venkateswararao Jujjuri (JV)fac4f112010-06-01 13:30:51 -0700218typedef struct V9fsCreateState {
219 V9fsPDU *pdu;
220 size_t offset;
221 V9fsFidState *fidp;
222 V9fsQID qid;
223 int32_t perm;
224 int8_t mode;
225 struct stat stbuf;
226 V9fsString name;
227 V9fsString extension;
228 V9fsString fullname;
M. Mohan Kumar5e94c102010-06-09 19:14:28 +0530229 int iounit;
Venkateswararao Jujjuri (JV)fac4f112010-06-01 13:30:51 -0700230} V9fsCreateState;
231
Venkateswararao Jujjuri (JV)c1568af2010-06-17 18:27:24 -0700232typedef struct V9fsLcreateState {
233 V9fsPDU *pdu;
234 size_t offset;
235 V9fsFidState *fidp;
236 V9fsQID qid;
237 int32_t iounit;
238 struct stat stbuf;
239 V9fsString name;
240 V9fsString fullname;
241} V9fsLcreateState;
242
Venkateswararao Jujjuri (JV)fac4f112010-06-01 13:30:51 -0700243typedef struct V9fsStatState {
244 V9fsPDU *pdu;
245 size_t offset;
246 V9fsStat v9stat;
247 V9fsFidState *fidp;
248 struct stat stbuf;
249} V9fsStatState;
250
Sripathi Kodi00ede4c2010-07-20 11:44:41 +0530251typedef struct V9fsStatDotl {
252 uint64_t st_result_mask;
253 V9fsQID qid;
254 uint32_t st_mode;
255 uint32_t st_uid;
256 uint32_t st_gid;
257 uint64_t st_nlink;
258 uint64_t st_rdev;
259 uint64_t st_size;
260 uint64_t st_blksize;
261 uint64_t st_blocks;
262 uint64_t st_atime_sec;
263 uint64_t st_atime_nsec;
264 uint64_t st_mtime_sec;
265 uint64_t st_mtime_nsec;
266 uint64_t st_ctime_sec;
267 uint64_t st_ctime_nsec;
268 uint64_t st_btime_sec;
269 uint64_t st_btime_nsec;
270 uint64_t st_gen;
271 uint64_t st_data_version;
272} V9fsStatDotl;
273
274typedef struct V9fsStatStateDotl {
275 V9fsPDU *pdu;
276 size_t offset;
277 V9fsStatDotl v9stat_dotl;
278 struct stat stbuf;
279} V9fsStatStateDotl;
280
281
Venkateswararao Jujjuri (JV)fac4f112010-06-01 13:30:51 -0700282typedef struct V9fsWalkState {
283 V9fsPDU *pdu;
284 size_t offset;
285 int16_t nwnames;
286 int name_idx;
287 V9fsQID *qids;
288 V9fsFidState *fidp;
289 V9fsFidState *newfidp;
290 V9fsString path;
291 V9fsString *wnames;
292 struct stat stbuf;
293} V9fsWalkState;
294
295typedef struct V9fsOpenState {
296 V9fsPDU *pdu;
297 size_t offset;
M. Mohan Kumar771e9d42010-06-22 19:47:04 +0530298 int32_t mode;
Venkateswararao Jujjuri (JV)fac4f112010-06-01 13:30:51 -0700299 V9fsFidState *fidp;
300 V9fsQID qid;
301 struct stat stbuf;
M. Mohan Kumar5e94c102010-06-09 19:14:28 +0530302 int iounit;
Venkateswararao Jujjuri (JV)fac4f112010-06-01 13:30:51 -0700303} V9fsOpenState;
304
305typedef struct V9fsReadState {
306 V9fsPDU *pdu;
307 size_t offset;
308 int32_t count;
309 int32_t total;
310 int64_t off;
311 V9fsFidState *fidp;
312 struct iovec iov[128]; /* FIXME: bad, bad, bad */
313 struct iovec *sg;
314 off_t dir_pos;
315 struct dirent *dent;
316 struct stat stbuf;
317 V9fsString name;
318 V9fsStat v9stat;
319 int32_t len;
320 int32_t cnt;
321 int32_t max_count;
322} V9fsReadState;
323
324typedef struct V9fsWriteState {
325 V9fsPDU *pdu;
326 size_t offset;
327 int32_t len;
328 int32_t count;
329 int32_t total;
330 int64_t off;
331 V9fsFidState *fidp;
332 struct iovec iov[128]; /* FIXME: bad, bad, bad */
333 struct iovec *sg;
334 int cnt;
335} V9fsWriteState;
336
337typedef struct V9fsRemoveState {
338 V9fsPDU *pdu;
339 size_t offset;
340 V9fsFidState *fidp;
341} V9fsRemoveState;
342
343typedef struct V9fsWstatState
344{
345 V9fsPDU *pdu;
346 size_t offset;
347 int16_t unused;
348 V9fsStat v9stat;
349 V9fsFidState *fidp;
350 struct stat stbuf;
Venkateswararao Jujjuri (JV)fac4f112010-06-01 13:30:51 -0700351} V9fsWstatState;
352
Venkateswararao Jujjuri (JV)08c60fc2010-06-09 14:02:08 -0700353typedef struct V9fsSymlinkState
354{
355 V9fsPDU *pdu;
356 size_t offset;
357 V9fsString name;
358 V9fsString symname;
359 V9fsString fullname;
360 V9fsFidState *dfidp;
361 V9fsQID qid;
362 struct stat stbuf;
363} V9fsSymlinkState;
364
Sripathi Kodic79ce732010-06-17 18:18:47 +0530365typedef struct V9fsIattr
366{
367 int32_t valid;
368 int32_t mode;
369 int32_t uid;
370 int32_t gid;
371 int64_t size;
372 int64_t atime_sec;
373 int64_t atime_nsec;
374 int64_t mtime_sec;
375 int64_t mtime_nsec;
376} V9fsIattr;
377
378typedef struct V9fsSetattrState
379{
380 V9fsPDU *pdu;
381 size_t offset;
382 V9fsIattr v9iattr;
383 V9fsFidState *fidp;
384} V9fsSetattrState;
385
Anthony Liguori9f107512010-04-29 17:44:44 +0530386struct virtio_9p_config
387{
388 /* number of characters in tag */
389 uint16_t tag_len;
390 /* Variable size tag name */
391 uint8_t tag[0];
392} __attribute__((packed));
393
M. Mohan Kumarbe940c82010-05-10 12:11:03 +0530394typedef struct V9fsStatfs
395{
396 uint32_t f_type;
397 uint32_t f_bsize;
398 uint64_t f_blocks;
399 uint64_t f_bfree;
400 uint64_t f_bavail;
401 uint64_t f_files;
402 uint64_t f_ffree;
403 uint64_t fsid_val;
404 uint32_t f_namelen;
405} V9fsStatfs;
406
407typedef struct V9fsStatfsState {
408 V9fsPDU *pdu;
409 size_t offset;
410 int32_t fid;
411 V9fsStatfs v9statfs;
412 V9fsFidState *fidp;
413 struct statfs stbuf;
414} V9fsStatfsState;
415
M. Mohan Kumar5268cec2010-06-22 12:24:09 +0530416typedef struct V9fsMkState {
417 V9fsPDU *pdu;
418 size_t offset;
419 V9fsQID qid;
420 struct stat stbuf;
421 V9fsString name;
422 V9fsString fullname;
423} V9fsMkState;
424
M. Mohan Kumarc7b4b0b2010-06-22 12:29:41 +0530425typedef struct V9fsRenameState {
426 V9fsPDU *pdu;
427 V9fsFidState *fidp;
428 size_t offset;
429 int32_t newdirfid;
430 V9fsString name;
431} V9fsRenameState;
432
Aneesh Kumar K.Vfa32ef82010-09-02 11:09:06 +0530433typedef struct V9fsXattrState
434{
435 V9fsPDU *pdu;
436 size_t offset;
437 V9fsFidState *file_fidp;
438 V9fsFidState *xattr_fidp;
439 V9fsString name;
440 int64_t size;
441 int flags;
442 void *value;
443} V9fsXattrState;
444
M. Mohan Kumar82cc3ee2010-09-08 02:19:32 +0530445#define P9_LOCK_SUCCESS 0
446#define P9_LOCK_BLOCKED 1
447#define P9_LOCK_ERROR 2
448#define P9_LOCK_GRACE 3
449
450#define P9_LOCK_FLAGS_BLOCK 1
451#define P9_LOCK_FLAGS_RECLAIM 2
452
453typedef struct V9fsFlock
454{
455 uint8_t type;
456 uint32_t flags;
457 uint64_t start; /* absolute offset */
458 uint64_t length;
459 uint32_t proc_id;
460 V9fsString client_id;
461} V9fsFlock;
462
463typedef struct V9fsLockState
464{
465 V9fsPDU *pdu;
466 size_t offset;
467 int8_t status;
468 struct stat stbuf;
469 V9fsFidState *fidp;
470 V9fsFlock *flock;
471} V9fsLockState;
472
M. Mohan Kumar8f354002010-09-08 02:36:52 +0530473typedef struct V9fsGetlock
474{
475 uint8_t type;
476 uint64_t start; /* absolute offset */
477 uint64_t length;
478 uint32_t proc_id;
479 V9fsString client_id;
480} V9fsGetlock;
481
482typedef struct V9fsGetlockState
483{
484 V9fsPDU *pdu;
485 size_t offset;
486 struct stat stbuf;
487 V9fsFidState *fidp;
488 V9fsGetlock *glock;
489} V9fsGetlockState;
490
M. Mohan Kumardf0973a2010-09-14 15:08:25 +0530491typedef struct V9fsReadLinkState
492{
493 V9fsPDU *pdu;
494 size_t offset;
495 V9fsString target;
496} V9fsReadLinkState;
M. Mohan Kumar8f354002010-09-08 02:36:52 +0530497
Blue Swirl64b85a82011-01-23 16:21:20 +0000498size_t pdu_packunpack(void *addr, struct iovec *sg, int sg_count,
499 size_t offset, size_t size, int pack);
Anthony Liguori9f107512010-04-29 17:44:44 +0530500
501static inline size_t do_pdu_unpack(void *dst, struct iovec *sg, int sg_count,
502 size_t offset, size_t size)
503{
504 return pdu_packunpack(dst, sg, sg_count, offset, size, 0);
505}
506
507#endif