1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
|
/*
* 9P network client for VirtIO 9P test cases (based on QTest)
*
* Copyright (c) 2014 SUSE LINUX Products GmbH
*
* This work is licensed under the terms of the GNU GPL, version 2 or later.
* See the COPYING file in the top-level directory.
*/
/*
* Not so fast! You might want to read the 9p developer docs first:
* https://wiki.qemu.org/Documentation/9p
*/
#ifndef TESTS_LIBQOS_VIRTIO_9P_CLIENT_H
#define TESTS_LIBQOS_VIRTIO_9P_CLIENT_H
#include "hw/9pfs/9p.h"
#include "hw/9pfs/9p-synth.h"
#include "virtio-9p.h"
#include "qgraph.h"
#include "tests/qtest/libqtest-single.h"
#define P9_MAX_SIZE 4096 /* Max size of a T-message or R-message */
typedef struct {
QTestState *qts;
QVirtio9P *v9p;
uint16_t tag;
uint64_t t_msg;
uint32_t t_size;
uint64_t r_msg;
/* No r_size, it is hardcoded to P9_MAX_SIZE */
size_t t_off;
size_t r_off;
uint32_t free_head;
} P9Req;
/* type[1] version[4] path[8] */
typedef char v9fs_qid[13];
typedef struct v9fs_attr {
uint64_t valid;
v9fs_qid qid;
uint32_t mode;
uint32_t uid;
uint32_t gid;
uint64_t nlink;
uint64_t rdev;
uint64_t size;
uint64_t blksize;
uint64_t blocks;
uint64_t atime_sec;
uint64_t atime_nsec;
uint64_t mtime_sec;
uint64_t mtime_nsec;
uint64_t ctime_sec;
uint64_t ctime_nsec;
uint64_t btime_sec;
uint64_t btime_nsec;
uint64_t gen;
uint64_t data_version;
} v9fs_attr;
#define P9_GETATTR_BASIC 0x000007ffULL /* Mask for fields up to BLOCKS */
#define P9_GETATTR_ALL 0x00003fffULL /* Mask for ALL fields */
struct V9fsDirent {
v9fs_qid qid;
uint64_t offset;
uint8_t type;
char *name;
struct V9fsDirent *next;
};
/* options for 'Twalk' 9p request */
typedef struct TWalkOpt {
/* 9P client being used (mandatory) */
QVirtio9P *client;
/* user supplied tag number being returned with response (optional) */
uint16_t tag;
/* file ID of directory from where walk should start (optional) */
uint32_t fid;
/* file ID for target directory being walked to (optional) */
uint32_t newfid;
/* low level variant of path to walk to (optional) */
uint16_t nwname;
char **wnames;
/* high level variant of path to walk to (optional) */
const char *path;
/* data being received from 9p server as 'Rwalk' response (optional) */
struct {
uint16_t *nwqid;
v9fs_qid **wqid;
} rwalk;
/* only send Twalk request but not wait for a reply? (optional) */
bool requestOnly;
/* do we expect an Rlerror response, if yes which error code? (optional) */
uint32_t expectErr;
} TWalkOpt;
/* result of 'Twalk' 9p request */
typedef struct TWalkRes {
/* file ID of target directory been walked to */
uint32_t newfid;
/* if requestOnly was set: request object for further processing */
P9Req *req;
} TWalkRes;
/* options for 'Tversion' 9p request */
typedef struct TVersionOpt {
/* 9P client being used (mandatory) */
QVirtio9P *client;
/* user supplied tag number being returned with response (optional) */
uint16_t tag;
/* maximum message size that can be handled by client (optional) */
uint32_t msize;
/* protocol version (optional) */
const char *version;
/* only send Tversion request but not wait for a reply? (optional) */
bool requestOnly;
/* do we expect an Rlerror response, if yes which error code? (optional) */
uint32_t expectErr;
} TVersionOpt;
/* result of 'Tversion' 9p request */
typedef struct TVersionRes {
/* if requestOnly was set: request object for further processing */
P9Req *req;
} TVersionRes;
/* options for 'Tattach' 9p request */
typedef struct TAttachOpt {
/* 9P client being used (mandatory) */
QVirtio9P *client;
/* user supplied tag number being returned with response (optional) */
uint16_t tag;
/* file ID to be associated with root of file tree (optional) */
uint32_t fid;
/* numerical uid of user being introduced to server (optional) */
uint32_t n_uname;
/* data being received from 9p server as 'Rattach' response (optional) */
struct {
/* server's idea of the root of the file tree */
v9fs_qid *qid;
} rattach;
/* only send Tattach request but not wait for a reply? (optional) */
bool requestOnly;
/* do we expect an Rlerror response, if yes which error code? (optional) */
uint32_t expectErr;
} TAttachOpt;
/* result of 'Tattach' 9p request */
typedef struct TAttachRes {
/* if requestOnly was set: request object for further processing */
P9Req *req;
} TAttachRes;
/* options for 'Tgetattr' 9p request */
typedef struct TGetAttrOpt {
/* 9P client being used (mandatory) */
QVirtio9P *client;
/* user supplied tag number being returned with response (optional) */
uint16_t tag;
/* file ID of file/dir whose attributes shall be retrieved (required) */
uint32_t fid;
/* bitmask indicating attribute fields to be retrieved (optional) */
uint64_t request_mask;
/* data being received from 9p server as 'Rgetattr' response (optional) */
struct {
v9fs_attr *attr;
} rgetattr;
/* only send Tgetattr request but not wait for a reply? (optional) */
bool requestOnly;
/* do we expect an Rlerror response, if yes which error code? (optional) */
uint32_t expectErr;
} TGetAttrOpt;
/* result of 'Tgetattr' 9p request */
typedef struct TGetAttrRes {
/* if requestOnly was set: request object for further processing */
P9Req *req;
} TGetAttrRes;
/* options for 'Treaddir' 9p request */
typedef struct TReadDirOpt {
/* 9P client being used (mandatory) */
QVirtio9P *client;
/* user supplied tag number being returned with response (optional) */
uint16_t tag;
/* file ID of directory whose entries shall be retrieved (required) */
uint32_t fid;
/* offset in entries stream, i.e. for multiple requests (optional) */
uint64_t offset;
/* maximum bytes to be returned by server (required) */
uint32_t count;
/* data being received from 9p server as 'Rreaddir' response (optional) */
struct {
uint32_t *count;
uint32_t *nentries;
struct V9fsDirent **entries;
} rreaddir;
/* only send Treaddir request but not wait for a reply? (optional) */
bool requestOnly;
/* do we expect an Rlerror response, if yes which error code? (optional) */
uint32_t expectErr;
} TReadDirOpt;
/* result of 'Treaddir' 9p request */
typedef struct TReadDirRes {
/* if requestOnly was set: request object for further processing */
P9Req *req;
} TReadDirRes;
/* options for 'Tlopen' 9p request */
typedef struct TLOpenOpt {
/* 9P client being used (mandatory) */
QVirtio9P *client;
/* user supplied tag number being returned with response (optional) */
uint16_t tag;
/* file ID of file / directory to be opened (required) */
uint32_t fid;
/* Linux open(2) flags such as O_RDONLY, O_RDWR, O_WRONLY (optional) */
uint32_t flags;
/* data being received from 9p server as 'Rlopen' response (optional) */
struct {
v9fs_qid *qid;
uint32_t *iounit;
} rlopen;
/* only send Tlopen request but not wait for a reply? (optional) */
bool requestOnly;
/* do we expect an Rlerror response, if yes which error code? (optional) */
uint32_t expectErr;
} TLOpenOpt;
/* result of 'Tlopen' 9p request */
typedef struct TLOpenRes {
/* if requestOnly was set: request object for further processing */
P9Req *req;
} TLOpenRes;
/* options for 'Twrite' 9p request */
typedef struct TWriteOpt {
/* 9P client being used (mandatory) */
QVirtio9P *client;
/* user supplied tag number being returned with response (optional) */
uint16_t tag;
/* file ID of file to write to (required) */
uint32_t fid;
/* start position of write from beginning of file (optional) */
uint64_t offset;
/* how many bytes to write */
uint32_t count;
/* data to be written */
const void *data;
/* only send Twrite request but not wait for a reply? (optional) */
bool requestOnly;
/* do we expect an Rlerror response, if yes which error code? (optional) */
uint32_t expectErr;
} TWriteOpt;
/* result of 'Twrite' 9p request */
typedef struct TWriteRes {
/* if requestOnly was set: request object for further processing */
P9Req *req;
/* amount of bytes written */
uint32_t count;
} TWriteRes;
/* options for 'Tflush' 9p request */
typedef struct TFlushOpt {
/* 9P client being used (mandatory) */
QVirtio9P *client;
/* user supplied tag number being returned with response (optional) */
uint16_t tag;
/* message to flush (required) */
uint16_t oldtag;
/* only send Tflush request but not wait for a reply? (optional) */
bool requestOnly;
/* do we expect an Rlerror response, if yes which error code? (optional) */
uint32_t expectErr;
} TFlushOpt;
/* result of 'Tflush' 9p request */
typedef struct TFlushRes {
/* if requestOnly was set: request object for further processing */
P9Req *req;
} TFlushRes;
void v9fs_set_allocator(QGuestAllocator *t_alloc);
void v9fs_memwrite(P9Req *req, const void *addr, size_t len);
void v9fs_memskip(P9Req *req, size_t len);
void v9fs_memread(P9Req *req, void *addr, size_t len);
void v9fs_uint8_read(P9Req *req, uint8_t *val);
void v9fs_uint16_write(P9Req *req, uint16_t val);
void v9fs_uint16_read(P9Req *req, uint16_t *val);
void v9fs_uint32_write(P9Req *req, uint32_t val);
void v9fs_uint64_write(P9Req *req, uint64_t val);
void v9fs_uint32_read(P9Req *req, uint32_t *val);
void v9fs_uint64_read(P9Req *req, uint64_t *val);
uint16_t v9fs_string_size(const char *string);
void v9fs_string_write(P9Req *req, const char *string);
void v9fs_string_read(P9Req *req, uint16_t *len, char **string);
P9Req *v9fs_req_init(QVirtio9P *v9p, uint32_t size, uint8_t id,
uint16_t tag);
void v9fs_req_send(P9Req *req);
void v9fs_req_wait_for_reply(P9Req *req, uint32_t *len);
void v9fs_req_recv(P9Req *req, uint8_t id);
void v9fs_req_free(P9Req *req);
void v9fs_rlerror(P9Req *req, uint32_t *err);
TVersionRes v9fs_tversion(TVersionOpt);
void v9fs_rversion(P9Req *req, uint16_t *len, char **version);
TAttachRes v9fs_tattach(TAttachOpt);
void v9fs_rattach(P9Req *req, v9fs_qid *qid);
TWalkRes v9fs_twalk(TWalkOpt opt);
void v9fs_rwalk(P9Req *req, uint16_t *nwqid, v9fs_qid **wqid);
TGetAttrRes v9fs_tgetattr(TGetAttrOpt);
void v9fs_rgetattr(P9Req *req, v9fs_attr *attr);
TReadDirRes v9fs_treaddir(TReadDirOpt);
void v9fs_rreaddir(P9Req *req, uint32_t *count, uint32_t *nentries,
struct V9fsDirent **entries);
void v9fs_free_dirents(struct V9fsDirent *e);
TLOpenRes v9fs_tlopen(TLOpenOpt);
void v9fs_rlopen(P9Req *req, v9fs_qid *qid, uint32_t *iounit);
TWriteRes v9fs_twrite(TWriteOpt);
void v9fs_rwrite(P9Req *req, uint32_t *count);
TFlushRes v9fs_tflush(TFlushOpt);
void v9fs_rflush(P9Req *req);
P9Req *v9fs_tmkdir(QVirtio9P *v9p, uint32_t dfid, const char *name,
uint32_t mode, uint32_t gid, uint16_t tag);
void v9fs_rmkdir(P9Req *req, v9fs_qid *qid);
P9Req *v9fs_tlcreate(QVirtio9P *v9p, uint32_t fid, const char *name,
uint32_t flags, uint32_t mode, uint32_t gid,
uint16_t tag);
void v9fs_rlcreate(P9Req *req, v9fs_qid *qid, uint32_t *iounit);
P9Req *v9fs_tsymlink(QVirtio9P *v9p, uint32_t fid, const char *name,
const char *symtgt, uint32_t gid, uint16_t tag);
void v9fs_rsymlink(P9Req *req, v9fs_qid *qid);
P9Req *v9fs_tlink(QVirtio9P *v9p, uint32_t dfid, uint32_t fid,
const char *name, uint16_t tag);
void v9fs_rlink(P9Req *req);
P9Req *v9fs_tunlinkat(QVirtio9P *v9p, uint32_t dirfd, const char *name,
uint32_t flags, uint16_t tag);
void v9fs_runlinkat(P9Req *req);
#endif
|