2 * QTest testcase for VirtIO 9P
4 * Copyright (c) 2014 SUSE LINUX Products GmbH
6 * This work is licensed under the terms of the GNU GPL, version 2 or later.
7 * See the COPYING file in the top-level directory.
11 * Not so fast! You might want to read the 9p developer docs first:
12 * https://wiki.qemu.org/Documentation/9p
15 #include "qemu/osdep.h"
16 #include "libqtest-single.h"
17 #include "qemu/module.h"
18 #include "hw/9pfs/9p.h"
19 #include "hw/9pfs/9p-synth.h"
20 #include "libqos/virtio-9p.h"
21 #include "libqos/qgraph.h"
23 #define QVIRTIO_9P_TIMEOUT_US (10 * 1000 * 1000)
24 static QGuestAllocator
*alloc
;
27 * Used to auto generate new fids. Start with arbitrary high value to avoid
28 * collision with hard coded fids in basic test code.
30 static uint32_t fid_generator
= 1000;
32 static uint32_t genfid(void)
34 return fid_generator
++;
38 * Splits the @a in string by @a delim into individual (non empty) strings
39 * and outputs them to @a out. The output array @a out is NULL terminated.
41 * Output array @a out must be freed by calling split_free().
43 * @returns number of individual elements in output array @a out (without the
44 * final NULL terminating element)
46 static int split(const char *in
, const char *delim
, char ***out
)
52 for (p
= strtok(tmp
, delim
); p
!= NULL
; p
= strtok(NULL
, delim
)) {
59 *out
= g_new0(char *, n
+ 1); /* last element NULL delimiter */
62 for (p
= strtok(tmp
, delim
); p
!= NULL
; p
= strtok(NULL
, delim
)) {
64 (*out
)[i
++] = g_strdup(p
);
72 static void split_free(char ***out
)
75 for (i
= 0; (*out
)[i
]; ++i
) {
82 static void pci_config(void *obj
, void *data
, QGuestAllocator
*t_alloc
)
86 size_t tag_len
= qvirtio_config_readw(v9p
->vdev
, 0);
87 g_autofree
char *tag
= NULL
;
90 g_assert_cmpint(tag_len
, ==, strlen(MOUNT_TAG
));
92 tag
= g_malloc(tag_len
);
93 for (i
= 0; i
< tag_len
; i
++) {
94 tag
[i
] = qvirtio_config_readb(v9p
->vdev
, i
+ 2);
96 g_assert_cmpmem(tag
, tag_len
, MOUNT_TAG
, tag_len
);
99 #define P9_MAX_SIZE 4096 /* Max size of a T-message or R-message */
108 /* No r_size, it is hardcoded to P9_MAX_SIZE */
114 static void v9fs_memwrite(P9Req
*req
, const void *addr
, size_t len
)
116 qtest_memwrite(req
->qts
, req
->t_msg
+ req
->t_off
, addr
, len
);
120 static void v9fs_memskip(P9Req
*req
, size_t len
)
125 static void v9fs_memread(P9Req
*req
, void *addr
, size_t len
)
127 qtest_memread(req
->qts
, req
->r_msg
+ req
->r_off
, addr
, len
);
131 static void v9fs_uint8_read(P9Req
*req
, uint8_t *val
)
133 v9fs_memread(req
, val
, 1);
136 static void v9fs_uint16_write(P9Req
*req
, uint16_t val
)
138 uint16_t le_val
= cpu_to_le16(val
);
140 v9fs_memwrite(req
, &le_val
, 2);
143 static void v9fs_uint16_read(P9Req
*req
, uint16_t *val
)
145 v9fs_memread(req
, val
, 2);
149 static void v9fs_uint32_write(P9Req
*req
, uint32_t val
)
151 uint32_t le_val
= cpu_to_le32(val
);
153 v9fs_memwrite(req
, &le_val
, 4);
156 static void v9fs_uint64_write(P9Req
*req
, uint64_t val
)
158 uint64_t le_val
= cpu_to_le64(val
);
160 v9fs_memwrite(req
, &le_val
, 8);
163 static void v9fs_uint32_read(P9Req
*req
, uint32_t *val
)
165 v9fs_memread(req
, val
, 4);
169 static void v9fs_uint64_read(P9Req
*req
, uint64_t *val
)
171 v9fs_memread(req
, val
, 8);
175 /* len[2] string[len] */
176 static uint16_t v9fs_string_size(const char *string
)
178 size_t len
= strlen(string
);
180 g_assert_cmpint(len
, <=, UINT16_MAX
- 2);
185 static void v9fs_string_write(P9Req
*req
, const char *string
)
187 int len
= strlen(string
);
189 g_assert_cmpint(len
, <=, UINT16_MAX
);
191 v9fs_uint16_write(req
, (uint16_t) len
);
192 v9fs_memwrite(req
, string
, len
);
195 static void v9fs_string_read(P9Req
*req
, uint16_t *len
, char **string
)
199 v9fs_uint16_read(req
, &local_len
);
204 *string
= g_malloc(local_len
+ 1);
205 v9fs_memread(req
, *string
, local_len
);
206 (*string
)[local_len
] = 0;
208 v9fs_memskip(req
, local_len
);
218 static P9Req
*v9fs_req_init(QVirtio9P
*v9p
, uint32_t size
, uint8_t id
,
221 P9Req
*req
= g_new0(P9Req
, 1);
222 uint32_t total_size
= 7; /* 9P header has well-known size of 7 bytes */
225 .tag
= cpu_to_le16(tag
)
228 g_assert_cmpint(total_size
, <=, UINT32_MAX
- size
);
230 hdr
.size
= cpu_to_le32(total_size
);
232 g_assert_cmpint(total_size
, <=, P9_MAX_SIZE
);
234 req
->qts
= global_qtest
;
236 req
->t_size
= total_size
;
237 req
->t_msg
= guest_alloc(alloc
, req
->t_size
);
238 v9fs_memwrite(req
, &hdr
, 7);
243 static void v9fs_req_send(P9Req
*req
)
245 QVirtio9P
*v9p
= req
->v9p
;
247 req
->r_msg
= guest_alloc(alloc
, P9_MAX_SIZE
);
248 req
->free_head
= qvirtqueue_add(req
->qts
, v9p
->vq
, req
->t_msg
, req
->t_size
,
250 qvirtqueue_add(req
->qts
, v9p
->vq
, req
->r_msg
, P9_MAX_SIZE
, true, false);
251 qvirtqueue_kick(req
->qts
, v9p
->vdev
, v9p
->vq
, req
->free_head
);
255 static const char *rmessage_name(uint8_t id
)
258 id
== P9_RLERROR
? "RLERROR" :
259 id
== P9_RVERSION
? "RVERSION" :
260 id
== P9_RATTACH
? "RATTACH" :
261 id
== P9_RWALK
? "RWALK" :
262 id
== P9_RLOPEN
? "RLOPEN" :
263 id
== P9_RWRITE
? "RWRITE" :
264 id
== P9_RMKDIR
? "RMKDIR" :
265 id
== P9_RLCREATE
? "RLCREATE" :
266 id
== P9_RSYMLINK
? "RSYMLINK" :
267 id
== P9_RLINK
? "RLINK" :
268 id
== P9_RUNLINKAT
? "RUNLINKAT" :
269 id
== P9_RFLUSH
? "RFLUSH" :
270 id
== P9_RREADDIR
? "READDIR" :
274 static void v9fs_req_wait_for_reply(P9Req
*req
, uint32_t *len
)
276 QVirtio9P
*v9p
= req
->v9p
;
278 qvirtio_wait_used_elem(req
->qts
, v9p
->vdev
, v9p
->vq
, req
->free_head
, len
,
279 QVIRTIO_9P_TIMEOUT_US
);
282 static void v9fs_req_recv(P9Req
*req
, uint8_t id
)
286 v9fs_memread(req
, &hdr
, 7);
287 hdr
.size
= ldl_le_p(&hdr
.size
);
288 hdr
.tag
= lduw_le_p(&hdr
.tag
);
290 g_assert_cmpint(hdr
.size
, >=, 7);
291 g_assert_cmpint(hdr
.size
, <=, P9_MAX_SIZE
);
292 g_assert_cmpint(hdr
.tag
, ==, req
->tag
);
295 g_printerr("Received response %d (%s) instead of %d (%s)\n",
296 hdr
.id
, rmessage_name(hdr
.id
), id
, rmessage_name(id
));
298 if (hdr
.id
== P9_RLERROR
) {
300 v9fs_uint32_read(req
, &err
);
301 g_printerr("Rlerror has errno %d (%s)\n", err
, strerror(err
));
304 g_assert_cmpint(hdr
.id
, ==, id
);
307 static void v9fs_req_free(P9Req
*req
)
309 guest_free(alloc
, req
->t_msg
);
310 guest_free(alloc
, req
->r_msg
);
314 /* size[4] Rlerror tag[2] ecode[4] */
315 static void v9fs_rlerror(P9Req
*req
, uint32_t *err
)
317 v9fs_req_recv(req
, P9_RLERROR
);
318 v9fs_uint32_read(req
, err
);
322 /* size[4] Tversion tag[2] msize[4] version[s] */
323 static P9Req
*v9fs_tversion(QVirtio9P
*v9p
, uint32_t msize
, const char *version
,
327 uint32_t body_size
= 4;
328 uint16_t string_size
= v9fs_string_size(version
);
330 g_assert_cmpint(body_size
, <=, UINT32_MAX
- string_size
);
331 body_size
+= string_size
;
332 req
= v9fs_req_init(v9p
, body_size
, P9_TVERSION
, tag
);
334 v9fs_uint32_write(req
, msize
);
335 v9fs_string_write(req
, version
);
340 /* size[4] Rversion tag[2] msize[4] version[s] */
341 static void v9fs_rversion(P9Req
*req
, uint16_t *len
, char **version
)
345 v9fs_req_recv(req
, P9_RVERSION
);
346 v9fs_uint32_read(req
, &msize
);
348 g_assert_cmpint(msize
, ==, P9_MAX_SIZE
);
350 if (len
|| version
) {
351 v9fs_string_read(req
, len
, version
);
357 /* size[4] Tattach tag[2] fid[4] afid[4] uname[s] aname[s] n_uname[4] */
358 static P9Req
*v9fs_tattach(QVirtio9P
*v9p
, uint32_t fid
, uint32_t n_uname
,
361 const char *uname
= ""; /* ignored by QEMU */
362 const char *aname
= ""; /* ignored by QEMU */
363 P9Req
*req
= v9fs_req_init(v9p
, 4 + 4 + 2 + 2 + 4, P9_TATTACH
, tag
);
365 v9fs_uint32_write(req
, fid
);
366 v9fs_uint32_write(req
, P9_NOFID
);
367 v9fs_string_write(req
, uname
);
368 v9fs_string_write(req
, aname
);
369 v9fs_uint32_write(req
, n_uname
);
374 /* type[1] version[4] path[8] */
375 typedef char v9fs_qid
[13];
377 static inline bool is_same_qid(v9fs_qid a
, v9fs_qid b
)
379 /* don't compare QID version for checking for file ID equalness */
380 return a
[0] == b
[0] && memcmp(&a
[5], &b
[5], 8) == 0;
383 /* size[4] Rattach tag[2] qid[13] */
384 static void v9fs_rattach(P9Req
*req
, v9fs_qid
*qid
)
386 v9fs_req_recv(req
, P9_RATTACH
);
388 v9fs_memread(req
, qid
, 13);
393 /* size[4] Twalk tag[2] fid[4] newfid[4] nwname[2] nwname*(wname[s]) */
394 static P9Req
*v9fs_twalk(QVirtio9P
*v9p
, uint32_t fid
, uint32_t newfid
,
395 uint16_t nwname
, char *const wnames
[], uint16_t tag
)
399 uint32_t body_size
= 4 + 4 + 2;
401 for (i
= 0; i
< nwname
; i
++) {
402 uint16_t wname_size
= v9fs_string_size(wnames
[i
]);
404 g_assert_cmpint(body_size
, <=, UINT32_MAX
- wname_size
);
405 body_size
+= wname_size
;
407 req
= v9fs_req_init(v9p
, body_size
, P9_TWALK
, tag
);
408 v9fs_uint32_write(req
, fid
);
409 v9fs_uint32_write(req
, newfid
);
410 v9fs_uint16_write(req
, nwname
);
411 for (i
= 0; i
< nwname
; i
++) {
412 v9fs_string_write(req
, wnames
[i
]);
418 /* size[4] Rwalk tag[2] nwqid[2] nwqid*(wqid[13]) */
419 static void v9fs_rwalk(P9Req
*req
, uint16_t *nwqid
, v9fs_qid
**wqid
)
421 uint16_t local_nwqid
;
423 v9fs_req_recv(req
, P9_RWALK
);
424 v9fs_uint16_read(req
, &local_nwqid
);
426 *nwqid
= local_nwqid
;
429 *wqid
= g_malloc(local_nwqid
* 13);
430 v9fs_memread(req
, *wqid
, local_nwqid
* 13);
435 /* size[4] Tgetattr tag[2] fid[4] request_mask[8] */
436 static P9Req
*v9fs_tgetattr(QVirtio9P
*v9p
, uint32_t fid
, uint64_t request_mask
,
441 req
= v9fs_req_init(v9p
, 4 + 8, P9_TGETATTR
, tag
);
442 v9fs_uint32_write(req
, fid
);
443 v9fs_uint64_write(req
, request_mask
);
448 typedef struct v9fs_attr
{
468 uint64_t data_version
;
471 #define P9_GETATTR_BASIC 0x000007ffULL /* Mask for fields up to BLOCKS */
474 * size[4] Rgetattr tag[2] valid[8] qid[13] mode[4] uid[4] gid[4] nlink[8]
475 * rdev[8] size[8] blksize[8] blocks[8]
476 * atime_sec[8] atime_nsec[8] mtime_sec[8] mtime_nsec[8]
477 * ctime_sec[8] ctime_nsec[8] btime_sec[8] btime_nsec[8]
478 * gen[8] data_version[8]
480 static void v9fs_rgetattr(P9Req
*req
, v9fs_attr
*attr
)
482 v9fs_req_recv(req
, P9_RGETATTR
);
484 v9fs_uint64_read(req
, &attr
->valid
);
485 v9fs_memread(req
, &attr
->qid
, 13);
486 v9fs_uint32_read(req
, &attr
->mode
);
487 v9fs_uint32_read(req
, &attr
->uid
);
488 v9fs_uint32_read(req
, &attr
->gid
);
489 v9fs_uint64_read(req
, &attr
->nlink
);
490 v9fs_uint64_read(req
, &attr
->rdev
);
491 v9fs_uint64_read(req
, &attr
->size
);
492 v9fs_uint64_read(req
, &attr
->blksize
);
493 v9fs_uint64_read(req
, &attr
->blocks
);
494 v9fs_uint64_read(req
, &attr
->atime_sec
);
495 v9fs_uint64_read(req
, &attr
->atime_nsec
);
496 v9fs_uint64_read(req
, &attr
->mtime_sec
);
497 v9fs_uint64_read(req
, &attr
->mtime_nsec
);
498 v9fs_uint64_read(req
, &attr
->ctime_sec
);
499 v9fs_uint64_read(req
, &attr
->ctime_nsec
);
500 v9fs_uint64_read(req
, &attr
->btime_sec
);
501 v9fs_uint64_read(req
, &attr
->btime_nsec
);
502 v9fs_uint64_read(req
, &attr
->gen
);
503 v9fs_uint64_read(req
, &attr
->data_version
);
508 /* size[4] Treaddir tag[2] fid[4] offset[8] count[4] */
509 static P9Req
*v9fs_treaddir(QVirtio9P
*v9p
, uint32_t fid
, uint64_t offset
,
510 uint32_t count
, uint16_t tag
)
514 req
= v9fs_req_init(v9p
, 4 + 8 + 4, P9_TREADDIR
, tag
);
515 v9fs_uint32_write(req
, fid
);
516 v9fs_uint64_write(req
, offset
);
517 v9fs_uint32_write(req
, count
);
527 struct V9fsDirent
*next
;
530 /* size[4] Rreaddir tag[2] count[4] data[count] */
531 static void v9fs_rreaddir(P9Req
*req
, uint32_t *count
, uint32_t *nentries
,
532 struct V9fsDirent
**entries
)
534 uint32_t local_count
;
535 struct V9fsDirent
*e
= NULL
;
539 v9fs_req_recv(req
, P9_RREADDIR
);
540 v9fs_uint32_read(req
, &local_count
);
543 *count
= local_count
;
546 for (int32_t togo
= (int32_t)local_count
;
547 togo
>= 13 + 8 + 1 + 2;
548 togo
-= 13 + 8 + 1 + 2 + slen
, ++n
)
551 e
= g_new(struct V9fsDirent
, 1);
556 e
= e
->next
= g_new(struct V9fsDirent
, 1);
559 /* qid[13] offset[8] type[1] name[s] */
560 v9fs_memread(req
, &e
->qid
, 13);
561 v9fs_uint64_read(req
, &e
->offset
);
562 v9fs_uint8_read(req
, &e
->type
);
563 v9fs_string_read(req
, &slen
, &e
->name
);
573 static void v9fs_free_dirents(struct V9fsDirent
*e
)
575 struct V9fsDirent
*next
= NULL
;
577 for (; e
; e
= next
) {
584 /* size[4] Tlopen tag[2] fid[4] flags[4] */
585 static P9Req
*v9fs_tlopen(QVirtio9P
*v9p
, uint32_t fid
, uint32_t flags
,
590 req
= v9fs_req_init(v9p
, 4 + 4, P9_TLOPEN
, tag
);
591 v9fs_uint32_write(req
, fid
);
592 v9fs_uint32_write(req
, flags
);
597 /* size[4] Rlopen tag[2] qid[13] iounit[4] */
598 static void v9fs_rlopen(P9Req
*req
, v9fs_qid
*qid
, uint32_t *iounit
)
600 v9fs_req_recv(req
, P9_RLOPEN
);
602 v9fs_memread(req
, qid
, 13);
604 v9fs_memskip(req
, 13);
607 v9fs_uint32_read(req
, iounit
);
612 /* size[4] Twrite tag[2] fid[4] offset[8] count[4] data[count] */
613 static P9Req
*v9fs_twrite(QVirtio9P
*v9p
, uint32_t fid
, uint64_t offset
,
614 uint32_t count
, const void *data
, uint16_t tag
)
617 uint32_t body_size
= 4 + 8 + 4;
619 g_assert_cmpint(body_size
, <=, UINT32_MAX
- count
);
621 req
= v9fs_req_init(v9p
, body_size
, P9_TWRITE
, tag
);
622 v9fs_uint32_write(req
, fid
);
623 v9fs_uint64_write(req
, offset
);
624 v9fs_uint32_write(req
, count
);
625 v9fs_memwrite(req
, data
, count
);
630 /* size[4] Rwrite tag[2] count[4] */
631 static void v9fs_rwrite(P9Req
*req
, uint32_t *count
)
633 v9fs_req_recv(req
, P9_RWRITE
);
635 v9fs_uint32_read(req
, count
);
640 /* size[4] Tflush tag[2] oldtag[2] */
641 static P9Req
*v9fs_tflush(QVirtio9P
*v9p
, uint16_t oldtag
, uint16_t tag
)
645 req
= v9fs_req_init(v9p
, 2, P9_TFLUSH
, tag
);
646 v9fs_uint32_write(req
, oldtag
);
651 /* size[4] Rflush tag[2] */
652 static void v9fs_rflush(P9Req
*req
)
654 v9fs_req_recv(req
, P9_RFLUSH
);
658 static void do_version(QVirtio9P
*v9p
)
660 const char *version
= "9P2000.L";
662 g_autofree
char *server_version
= NULL
;
665 req
= v9fs_tversion(v9p
, P9_MAX_SIZE
, version
, P9_NOTAG
);
666 v9fs_req_wait_for_reply(req
, NULL
);
667 v9fs_rversion(req
, &server_len
, &server_version
);
669 g_assert_cmpmem(server_version
, server_len
, version
, strlen(version
));
673 * utility function: walk to requested dir and return fid for that dir and
674 * the QIDs of server response
676 static uint32_t do_walk_rqids(QVirtio9P
*v9p
, const char *path
, uint16_t *nwqid
,
681 const uint32_t fid
= genfid();
683 int nwnames
= split(path
, "/", &wnames
);
685 req
= v9fs_twalk(v9p
, 0, fid
, nwnames
, wnames
, 0);
686 v9fs_req_wait_for_reply(req
, NULL
);
687 v9fs_rwalk(req
, nwqid
, wqid
);
693 /* utility function: walk to requested dir and return fid for that dir */
694 static uint32_t do_walk(QVirtio9P
*v9p
, const char *path
)
696 return do_walk_rqids(v9p
, path
, NULL
, NULL
);
699 /* utility function: walk to requested dir and expect passed error response */
700 static void do_walk_expect_error(QVirtio9P
*v9p
, const char *path
, uint32_t err
)
705 const uint32_t fid
= genfid();
707 int nwnames
= split(path
, "/", &wnames
);
709 req
= v9fs_twalk(v9p
, 0, fid
, nwnames
, wnames
, 0);
710 v9fs_req_wait_for_reply(req
, NULL
);
711 v9fs_rlerror(req
, &_err
);
713 g_assert_cmpint(_err
, ==, err
);
718 static void fs_version(void *obj
, void *data
, QGuestAllocator
*t_alloc
)
724 static void do_attach_rqid(QVirtio9P
*v9p
, v9fs_qid
*qid
)
729 req
= v9fs_tattach(v9p
, 0, getuid(), 0);
730 v9fs_req_wait_for_reply(req
, NULL
);
731 v9fs_rattach(req
, qid
);
734 static void do_attach(QVirtio9P
*v9p
)
736 do_attach_rqid(v9p
, NULL
);
739 static void fs_attach(void *obj
, void *data
, QGuestAllocator
*t_alloc
)
745 static void fs_walk(void *obj
, void *data
, QGuestAllocator
*t_alloc
)
747 QVirtio9P
*v9p
= obj
;
749 char *wnames
[P9_MAXWELEM
];
751 g_autofree v9fs_qid
*wqid
= NULL
;
755 for (i
= 0; i
< P9_MAXWELEM
; i
++) {
756 wnames
[i
] = g_strdup_printf(QTEST_V9FS_SYNTH_WALK_FILE
, i
);
760 req
= v9fs_twalk(v9p
, 0, 1, P9_MAXWELEM
, wnames
, 0);
761 v9fs_req_wait_for_reply(req
, NULL
);
762 v9fs_rwalk(req
, &nwqid
, &wqid
);
764 g_assert_cmpint(nwqid
, ==, P9_MAXWELEM
);
766 for (i
= 0; i
< P9_MAXWELEM
; i
++) {
771 static bool fs_dirents_contain_name(struct V9fsDirent
*e
, const char* name
)
773 for (; e
; e
= e
->next
) {
774 if (!strcmp(e
->name
, name
)) {
781 /* size[4] Tmkdir tag[2] dfid[4] name[s] mode[4] gid[4] */
782 static P9Req
*v9fs_tmkdir(QVirtio9P
*v9p
, uint32_t dfid
, const char *name
,
783 uint32_t mode
, uint32_t gid
, uint16_t tag
)
787 uint32_t body_size
= 4 + 4 + 4;
788 uint16_t string_size
= v9fs_string_size(name
);
790 g_assert_cmpint(body_size
, <=, UINT32_MAX
- string_size
);
791 body_size
+= string_size
;
793 req
= v9fs_req_init(v9p
, body_size
, P9_TMKDIR
, tag
);
794 v9fs_uint32_write(req
, dfid
);
795 v9fs_string_write(req
, name
);
796 v9fs_uint32_write(req
, mode
);
797 v9fs_uint32_write(req
, gid
);
802 /* size[4] Rmkdir tag[2] qid[13] */
803 static void v9fs_rmkdir(P9Req
*req
, v9fs_qid
*qid
)
805 v9fs_req_recv(req
, P9_RMKDIR
);
807 v9fs_memread(req
, qid
, 13);
809 v9fs_memskip(req
, 13);
814 /* size[4] Tlcreate tag[2] fid[4] name[s] flags[4] mode[4] gid[4] */
815 static P9Req
*v9fs_tlcreate(QVirtio9P
*v9p
, uint32_t fid
, const char *name
,
816 uint32_t flags
, uint32_t mode
, uint32_t gid
,
821 uint32_t body_size
= 4 + 4 + 4 + 4;
822 uint16_t string_size
= v9fs_string_size(name
);
824 g_assert_cmpint(body_size
, <=, UINT32_MAX
- string_size
);
825 body_size
+= string_size
;
827 req
= v9fs_req_init(v9p
, body_size
, P9_TLCREATE
, tag
);
828 v9fs_uint32_write(req
, fid
);
829 v9fs_string_write(req
, name
);
830 v9fs_uint32_write(req
, flags
);
831 v9fs_uint32_write(req
, mode
);
832 v9fs_uint32_write(req
, gid
);
837 /* size[4] Rlcreate tag[2] qid[13] iounit[4] */
838 static void v9fs_rlcreate(P9Req
*req
, v9fs_qid
*qid
, uint32_t *iounit
)
840 v9fs_req_recv(req
, P9_RLCREATE
);
842 v9fs_memread(req
, qid
, 13);
844 v9fs_memskip(req
, 13);
847 v9fs_uint32_read(req
, iounit
);
852 /* size[4] Tsymlink tag[2] fid[4] name[s] symtgt[s] gid[4] */
853 static P9Req
*v9fs_tsymlink(QVirtio9P
*v9p
, uint32_t fid
, const char *name
,
854 const char *symtgt
, uint32_t gid
, uint16_t tag
)
858 uint32_t body_size
= 4 + 4;
859 uint16_t string_size
= v9fs_string_size(name
) + v9fs_string_size(symtgt
);
861 g_assert_cmpint(body_size
, <=, UINT32_MAX
- string_size
);
862 body_size
+= string_size
;
864 req
= v9fs_req_init(v9p
, body_size
, P9_TSYMLINK
, tag
);
865 v9fs_uint32_write(req
, fid
);
866 v9fs_string_write(req
, name
);
867 v9fs_string_write(req
, symtgt
);
868 v9fs_uint32_write(req
, gid
);
873 /* size[4] Rsymlink tag[2] qid[13] */
874 static void v9fs_rsymlink(P9Req
*req
, v9fs_qid
*qid
)
876 v9fs_req_recv(req
, P9_RSYMLINK
);
878 v9fs_memread(req
, qid
, 13);
880 v9fs_memskip(req
, 13);
885 /* size[4] Tlink tag[2] dfid[4] fid[4] name[s] */
886 static P9Req
*v9fs_tlink(QVirtio9P
*v9p
, uint32_t dfid
, uint32_t fid
,
887 const char *name
, uint16_t tag
)
891 uint32_t body_size
= 4 + 4;
892 uint16_t string_size
= v9fs_string_size(name
);
894 g_assert_cmpint(body_size
, <=, UINT32_MAX
- string_size
);
895 body_size
+= string_size
;
897 req
= v9fs_req_init(v9p
, body_size
, P9_TLINK
, tag
);
898 v9fs_uint32_write(req
, dfid
);
899 v9fs_uint32_write(req
, fid
);
900 v9fs_string_write(req
, name
);
905 /* size[4] Rlink tag[2] */
906 static void v9fs_rlink(P9Req
*req
)
908 v9fs_req_recv(req
, P9_RLINK
);
912 /* size[4] Tunlinkat tag[2] dirfd[4] name[s] flags[4] */
913 static P9Req
*v9fs_tunlinkat(QVirtio9P
*v9p
, uint32_t dirfd
, const char *name
,
914 uint32_t flags
, uint16_t tag
)
918 uint32_t body_size
= 4 + 4;
919 uint16_t string_size
= v9fs_string_size(name
);
921 g_assert_cmpint(body_size
, <=, UINT32_MAX
- string_size
);
922 body_size
+= string_size
;
924 req
= v9fs_req_init(v9p
, body_size
, P9_TUNLINKAT
, tag
);
925 v9fs_uint32_write(req
, dirfd
);
926 v9fs_string_write(req
, name
);
927 v9fs_uint32_write(req
, flags
);
932 /* size[4] Runlinkat tag[2] */
933 static void v9fs_runlinkat(P9Req
*req
)
935 v9fs_req_recv(req
, P9_RUNLINKAT
);
939 /* basic readdir test where reply fits into a single response message */
940 static void fs_readdir(void *obj
, void *data
, QGuestAllocator
*t_alloc
)
942 QVirtio9P
*v9p
= obj
;
944 char *const wnames
[] = { g_strdup(QTEST_V9FS_SYNTH_READDIR_DIR
) };
947 uint32_t count
, nentries
;
948 struct V9fsDirent
*entries
= NULL
;
952 req
= v9fs_twalk(v9p
, 0, 1, 1, wnames
, 0);
953 v9fs_req_wait_for_reply(req
, NULL
);
954 v9fs_rwalk(req
, &nqid
, NULL
);
955 g_assert_cmpint(nqid
, ==, 1);
957 req
= v9fs_tlopen(v9p
, 1, O_DIRECTORY
, 0);
958 v9fs_req_wait_for_reply(req
, NULL
);
959 v9fs_rlopen(req
, &qid
, NULL
);
962 * submit count = msize - 11, because 11 is the header size of Rreaddir
964 req
= v9fs_treaddir(v9p
, 1, 0, P9_MAX_SIZE
- 11, 0);
965 v9fs_req_wait_for_reply(req
, NULL
);
966 v9fs_rreaddir(req
, &count
, &nentries
, &entries
);
969 * Assuming msize (P9_MAX_SIZE) is large enough so we can retrieve all
970 * dir entries with only one readdir request.
974 QTEST_V9FS_SYNTH_READDIR_NFILES
+ 2 /* "." and ".." */
978 * Check all file names exist in returned entries, ignore their order
981 g_assert_cmpint(fs_dirents_contain_name(entries
, "."), ==, true);
982 g_assert_cmpint(fs_dirents_contain_name(entries
, ".."), ==, true);
983 for (int i
= 0; i
< QTEST_V9FS_SYNTH_READDIR_NFILES
; ++i
) {
984 g_autofree
char *name
=
985 g_strdup_printf(QTEST_V9FS_SYNTH_READDIR_FILE
, i
);
986 g_assert_cmpint(fs_dirents_contain_name(entries
, name
), ==, true);
989 v9fs_free_dirents(entries
);
993 /* readdir test where overall request is split over several messages */
994 static void do_readdir_split(QVirtio9P
*v9p
, uint32_t count
)
996 char *const wnames
[] = { g_strdup(QTEST_V9FS_SYNTH_READDIR_DIR
) };
999 uint32_t nentries
, npartialentries
;
1000 struct V9fsDirent
*entries
, *tail
, *partialentries
;
1013 req
= v9fs_twalk(v9p
, 0, fid
, 1, wnames
, 0);
1014 v9fs_req_wait_for_reply(req
, NULL
);
1015 v9fs_rwalk(req
, &nqid
, NULL
);
1016 g_assert_cmpint(nqid
, ==, 1);
1018 req
= v9fs_tlopen(v9p
, fid
, O_DIRECTORY
, 0);
1019 v9fs_req_wait_for_reply(req
, NULL
);
1020 v9fs_rlopen(req
, &qid
, NULL
);
1023 * send as many Treaddir requests as required to get all directory
1027 npartialentries
= 0;
1028 partialentries
= NULL
;
1030 req
= v9fs_treaddir(v9p
, fid
, offset
, count
, 0);
1031 v9fs_req_wait_for_reply(req
, NULL
);
1032 v9fs_rreaddir(req
, &count
, &npartialentries
, &partialentries
);
1033 if (npartialentries
> 0 && partialentries
) {
1035 entries
= partialentries
;
1036 nentries
= npartialentries
;
1037 tail
= partialentries
;
1039 tail
->next
= partialentries
;
1040 nentries
+= npartialentries
;
1042 while (tail
->next
) {
1045 offset
= tail
->offset
;
1053 QTEST_V9FS_SYNTH_READDIR_NFILES
+ 2 /* "." and ".." */
1057 * Check all file names exist in returned entries, ignore their order
1060 g_assert_cmpint(fs_dirents_contain_name(entries
, "."), ==, true);
1061 g_assert_cmpint(fs_dirents_contain_name(entries
, ".."), ==, true);
1062 for (int i
= 0; i
< QTEST_V9FS_SYNTH_READDIR_NFILES
; ++i
) {
1063 char *name
= g_strdup_printf(QTEST_V9FS_SYNTH_READDIR_FILE
, i
);
1064 g_assert_cmpint(fs_dirents_contain_name(entries
, name
), ==, true);
1068 v9fs_free_dirents(entries
);
1073 static void fs_walk_no_slash(void *obj
, void *data
, QGuestAllocator
*t_alloc
)
1075 QVirtio9P
*v9p
= obj
;
1077 char *const wnames
[] = { g_strdup(" /") };
1082 req
= v9fs_twalk(v9p
, 0, 1, 1, wnames
, 0);
1083 v9fs_req_wait_for_reply(req
, NULL
);
1084 v9fs_rlerror(req
, &err
);
1086 g_assert_cmpint(err
, ==, ENOENT
);
1091 static void fs_walk_nonexistent(void *obj
, void *data
, QGuestAllocator
*t_alloc
)
1093 QVirtio9P
*v9p
= obj
;
1098 * The 9p2000 protocol spec says: "If the first element cannot be walked
1099 * for any reason, Rerror is returned."
1101 do_walk_expect_error(v9p
, "non-existent", ENOENT
);
1104 static void fs_walk_2nd_nonexistent(void *obj
, void *data
,
1105 QGuestAllocator
*t_alloc
)
1107 QVirtio9P
*v9p
= obj
;
1113 g_autofree v9fs_qid
*wqid
= NULL
;
1114 g_autofree
char *path
= g_strdup_printf(
1115 QTEST_V9FS_SYNTH_WALK_FILE
"/non-existent", 0
1118 do_attach_rqid(v9p
, &root_qid
);
1119 fid
= do_walk_rqids(v9p
, path
, &nwqid
, &wqid
);
1121 * The 9p2000 protocol spec says: "nwqid is therefore either nwname or the
1122 * index of the first elementwise walk that failed."
1126 /* returned QID wqid[0] is file ID of 1st subdir */
1127 g_assert(wqid
&& wqid
[0] && !is_same_qid(root_qid
, wqid
[0]));
1129 /* expect fid being unaffected by walk above */
1130 req
= v9fs_tgetattr(v9p
, fid
, P9_GETATTR_BASIC
, 0);
1131 v9fs_req_wait_for_reply(req
, NULL
);
1132 v9fs_rlerror(req
, &err
);
1134 g_assert_cmpint(err
, ==, ENOENT
);
1137 static void fs_walk_none(void *obj
, void *data
, QGuestAllocator
*t_alloc
)
1139 QVirtio9P
*v9p
= obj
;
1142 g_autofree v9fs_qid
*wqid
= NULL
;
1144 struct v9fs_attr attr
;
1147 req
= v9fs_tattach(v9p
, 0, getuid(), 0);
1148 v9fs_req_wait_for_reply(req
, NULL
);
1149 v9fs_rattach(req
, &root_qid
);
1151 req
= v9fs_twalk(v9p
, 0, 1, 0, NULL
, 0);
1152 v9fs_req_wait_for_reply(req
, NULL
);
1153 v9fs_rwalk(req
, NULL
, &wqid
);
1155 /* special case: no QID is returned if nwname=0 was sent */
1156 g_assert(wqid
== NULL
);
1158 req
= v9fs_tgetattr(v9p
, 1, P9_GETATTR_BASIC
, 0);
1159 v9fs_req_wait_for_reply(req
, NULL
);
1160 v9fs_rgetattr(req
, &attr
);
1162 g_assert(is_same_qid(root_qid
, attr
.qid
));
1165 static void fs_walk_dotdot(void *obj
, void *data
, QGuestAllocator
*t_alloc
)
1167 QVirtio9P
*v9p
= obj
;
1169 char *const wnames
[] = { g_strdup("..") };
1171 g_autofree v9fs_qid
*wqid
= NULL
;
1175 req
= v9fs_tattach(v9p
, 0, getuid(), 0);
1176 v9fs_req_wait_for_reply(req
, NULL
);
1177 v9fs_rattach(req
, &root_qid
);
1179 req
= v9fs_twalk(v9p
, 0, 1, 1, wnames
, 0);
1180 v9fs_req_wait_for_reply(req
, NULL
);
1181 v9fs_rwalk(req
, NULL
, &wqid
); /* We now we'll get one qid */
1183 g_assert_cmpmem(&root_qid
, 13, wqid
[0], 13);
1188 static void fs_lopen(void *obj
, void *data
, QGuestAllocator
*t_alloc
)
1190 QVirtio9P
*v9p
= obj
;
1192 char *const wnames
[] = { g_strdup(QTEST_V9FS_SYNTH_LOPEN_FILE
) };
1196 req
= v9fs_twalk(v9p
, 0, 1, 1, wnames
, 0);
1197 v9fs_req_wait_for_reply(req
, NULL
);
1198 v9fs_rwalk(req
, NULL
, NULL
);
1200 req
= v9fs_tlopen(v9p
, 1, O_WRONLY
, 0);
1201 v9fs_req_wait_for_reply(req
, NULL
);
1202 v9fs_rlopen(req
, NULL
, NULL
);
1207 static void fs_write(void *obj
, void *data
, QGuestAllocator
*t_alloc
)
1209 QVirtio9P
*v9p
= obj
;
1211 static const uint32_t write_count
= P9_MAX_SIZE
/ 2;
1212 char *const wnames
[] = { g_strdup(QTEST_V9FS_SYNTH_WRITE_FILE
) };
1213 g_autofree
char *buf
= g_malloc0(write_count
);
1218 req
= v9fs_twalk(v9p
, 0, 1, 1, wnames
, 0);
1219 v9fs_req_wait_for_reply(req
, NULL
);
1220 v9fs_rwalk(req
, NULL
, NULL
);
1222 req
= v9fs_tlopen(v9p
, 1, O_WRONLY
, 0);
1223 v9fs_req_wait_for_reply(req
, NULL
);
1224 v9fs_rlopen(req
, NULL
, NULL
);
1226 req
= v9fs_twrite(v9p
, 1, 0, write_count
, buf
, 0);
1227 v9fs_req_wait_for_reply(req
, NULL
);
1228 v9fs_rwrite(req
, &count
);
1229 g_assert_cmpint(count
, ==, write_count
);
1234 static void fs_flush_success(void *obj
, void *data
, QGuestAllocator
*t_alloc
)
1236 QVirtio9P
*v9p
= obj
;
1238 char *const wnames
[] = { g_strdup(QTEST_V9FS_SYNTH_FLUSH_FILE
) };
1239 P9Req
*req
, *flush_req
;
1241 uint8_t should_block
;
1244 req
= v9fs_twalk(v9p
, 0, 1, 1, wnames
, 0);
1245 v9fs_req_wait_for_reply(req
, NULL
);
1246 v9fs_rwalk(req
, NULL
, NULL
);
1248 req
= v9fs_tlopen(v9p
, 1, O_WRONLY
, 0);
1249 v9fs_req_wait_for_reply(req
, NULL
);
1250 v9fs_rlopen(req
, NULL
, NULL
);
1252 /* This will cause the 9p server to try to write data to the backend,
1253 * until the write request gets cancelled.
1256 req
= v9fs_twrite(v9p
, 1, 0, sizeof(should_block
), &should_block
, 0);
1258 flush_req
= v9fs_tflush(v9p
, req
->tag
, 1);
1260 /* The write request is supposed to be flushed: the server should just
1261 * mark the write request as used and reply to the flush request.
1263 v9fs_req_wait_for_reply(req
, &reply_len
);
1264 g_assert_cmpint(reply_len
, ==, 0);
1266 v9fs_rflush(flush_req
);
1271 static void fs_flush_ignored(void *obj
, void *data
, QGuestAllocator
*t_alloc
)
1273 QVirtio9P
*v9p
= obj
;
1275 char *const wnames
[] = { g_strdup(QTEST_V9FS_SYNTH_FLUSH_FILE
) };
1276 P9Req
*req
, *flush_req
;
1278 uint8_t should_block
;
1281 req
= v9fs_twalk(v9p
, 0, 1, 1, wnames
, 0);
1282 v9fs_req_wait_for_reply(req
, NULL
);
1283 v9fs_rwalk(req
, NULL
, NULL
);
1285 req
= v9fs_tlopen(v9p
, 1, O_WRONLY
, 0);
1286 v9fs_req_wait_for_reply(req
, NULL
);
1287 v9fs_rlopen(req
, NULL
, NULL
);
1289 /* This will cause the write request to complete right away, before it
1290 * could be actually cancelled.
1293 req
= v9fs_twrite(v9p
, 1, 0, sizeof(should_block
), &should_block
, 0);
1295 flush_req
= v9fs_tflush(v9p
, req
->tag
, 1);
1297 /* The write request is supposed to complete. The server should
1298 * reply to the write request and the flush request.
1300 v9fs_req_wait_for_reply(req
, NULL
);
1301 v9fs_rwrite(req
, &count
);
1302 g_assert_cmpint(count
, ==, sizeof(should_block
));
1303 v9fs_rflush(flush_req
);
1308 static void do_mkdir(QVirtio9P
*v9p
, const char *path
, const char *cname
)
1310 g_autofree
char *name
= g_strdup(cname
);
1314 fid
= do_walk(v9p
, path
);
1316 req
= v9fs_tmkdir(v9p
, fid
, name
, 0750, 0, 0);
1317 v9fs_req_wait_for_reply(req
, NULL
);
1318 v9fs_rmkdir(req
, NULL
);
1321 /* create a regular file with Tlcreate and return file's fid */
1322 static uint32_t do_lcreate(QVirtio9P
*v9p
, const char *path
,
1325 g_autofree
char *name
= g_strdup(cname
);
1329 fid
= do_walk(v9p
, path
);
1331 req
= v9fs_tlcreate(v9p
, fid
, name
, 0, 0750, 0, 0);
1332 v9fs_req_wait_for_reply(req
, NULL
);
1333 v9fs_rlcreate(req
, NULL
, NULL
);
1338 /* create symlink named @a clink in directory @a path pointing to @a to */
1339 static void do_symlink(QVirtio9P
*v9p
, const char *path
, const char *clink
,
1342 g_autofree
char *name
= g_strdup(clink
);
1343 g_autofree
char *dst
= g_strdup(to
);
1347 fid
= do_walk(v9p
, path
);
1349 req
= v9fs_tsymlink(v9p
, fid
, name
, dst
, 0, 0);
1350 v9fs_req_wait_for_reply(req
, NULL
);
1351 v9fs_rsymlink(req
, NULL
);
1354 /* create a hard link named @a clink in directory @a path pointing to @a to */
1355 static void do_hardlink(QVirtio9P
*v9p
, const char *path
, const char *clink
,
1361 dfid
= do_walk(v9p
, path
);
1362 fid
= do_walk(v9p
, to
);
1364 req
= v9fs_tlink(v9p
, dfid
, fid
, clink
, 0);
1365 v9fs_req_wait_for_reply(req
, NULL
);
1369 static void do_unlinkat(QVirtio9P
*v9p
, const char *atpath
, const char *rpath
,
1372 g_autofree
char *name
= g_strdup(rpath
);
1376 fid
= do_walk(v9p
, atpath
);
1378 req
= v9fs_tunlinkat(v9p
, fid
, name
, flags
, 0);
1379 v9fs_req_wait_for_reply(req
, NULL
);
1380 v9fs_runlinkat(req
);
1383 static void fs_readdir_split_128(void *obj
, void *data
,
1384 QGuestAllocator
*t_alloc
)
1387 do_readdir_split(obj
, 128);
1390 static void fs_readdir_split_256(void *obj
, void *data
,
1391 QGuestAllocator
*t_alloc
)
1394 do_readdir_split(obj
, 256);
1397 static void fs_readdir_split_512(void *obj
, void *data
,
1398 QGuestAllocator
*t_alloc
)
1401 do_readdir_split(obj
, 512);
1405 /* tests using the 9pfs 'local' fs driver */
1407 static void fs_create_dir(void *obj
, void *data
, QGuestAllocator
*t_alloc
)
1409 QVirtio9P
*v9p
= obj
;
1412 g_autofree
char *root_path
= virtio_9p_test_path("");
1413 g_autofree
char *new_dir
= virtio_9p_test_path("01");
1415 g_assert(root_path
!= NULL
);
1418 do_mkdir(v9p
, "/", "01");
1420 /* check if created directory really exists now ... */
1421 g_assert(stat(new_dir
, &st
) == 0);
1422 /* ... and is actually a directory */
1423 g_assert((st
.st_mode
& S_IFMT
) == S_IFDIR
);
1426 static void fs_unlinkat_dir(void *obj
, void *data
, QGuestAllocator
*t_alloc
)
1428 QVirtio9P
*v9p
= obj
;
1431 g_autofree
char *root_path
= virtio_9p_test_path("");
1432 g_autofree
char *new_dir
= virtio_9p_test_path("02");
1434 g_assert(root_path
!= NULL
);
1437 do_mkdir(v9p
, "/", "02");
1439 /* check if created directory really exists now ... */
1440 g_assert(stat(new_dir
, &st
) == 0);
1441 /* ... and is actually a directory */
1442 g_assert((st
.st_mode
& S_IFMT
) == S_IFDIR
);
1444 do_unlinkat(v9p
, "/", "02", P9_DOTL_AT_REMOVEDIR
);
1445 /* directory should be gone now */
1446 g_assert(stat(new_dir
, &st
) != 0);
1449 static void fs_create_file(void *obj
, void *data
, QGuestAllocator
*t_alloc
)
1451 QVirtio9P
*v9p
= obj
;
1454 g_autofree
char *new_file
= virtio_9p_test_path("03/1st_file");
1457 do_mkdir(v9p
, "/", "03");
1458 do_lcreate(v9p
, "03", "1st_file");
1460 /* check if created file exists now ... */
1461 g_assert(stat(new_file
, &st
) == 0);
1462 /* ... and is a regular file */
1463 g_assert((st
.st_mode
& S_IFMT
) == S_IFREG
);
1466 static void fs_unlinkat_file(void *obj
, void *data
, QGuestAllocator
*t_alloc
)
1468 QVirtio9P
*v9p
= obj
;
1471 g_autofree
char *new_file
= virtio_9p_test_path("04/doa_file");
1474 do_mkdir(v9p
, "/", "04");
1475 do_lcreate(v9p
, "04", "doa_file");
1477 /* check if created file exists now ... */
1478 g_assert(stat(new_file
, &st
) == 0);
1479 /* ... and is a regular file */
1480 g_assert((st
.st_mode
& S_IFMT
) == S_IFREG
);
1482 do_unlinkat(v9p
, "04", "doa_file", 0);
1483 /* file should be gone now */
1484 g_assert(stat(new_file
, &st
) != 0);
1487 static void fs_symlink_file(void *obj
, void *data
, QGuestAllocator
*t_alloc
)
1489 QVirtio9P
*v9p
= obj
;
1492 g_autofree
char *real_file
= virtio_9p_test_path("05/real_file");
1493 g_autofree
char *symlink_file
= virtio_9p_test_path("05/symlink_file");
1496 do_mkdir(v9p
, "/", "05");
1497 do_lcreate(v9p
, "05", "real_file");
1498 g_assert(stat(real_file
, &st
) == 0);
1499 g_assert((st
.st_mode
& S_IFMT
) == S_IFREG
);
1501 do_symlink(v9p
, "05", "symlink_file", "real_file");
1503 /* check if created link exists now */
1504 g_assert(stat(symlink_file
, &st
) == 0);
1507 static void fs_unlinkat_symlink(void *obj
, void *data
,
1508 QGuestAllocator
*t_alloc
)
1510 QVirtio9P
*v9p
= obj
;
1513 g_autofree
char *real_file
= virtio_9p_test_path("06/real_file");
1514 g_autofree
char *symlink_file
= virtio_9p_test_path("06/symlink_file");
1517 do_mkdir(v9p
, "/", "06");
1518 do_lcreate(v9p
, "06", "real_file");
1519 g_assert(stat(real_file
, &st
) == 0);
1520 g_assert((st
.st_mode
& S_IFMT
) == S_IFREG
);
1522 do_symlink(v9p
, "06", "symlink_file", "real_file");
1523 g_assert(stat(symlink_file
, &st
) == 0);
1525 do_unlinkat(v9p
, "06", "symlink_file", 0);
1526 /* symlink should be gone now */
1527 g_assert(stat(symlink_file
, &st
) != 0);
1530 static void fs_hardlink_file(void *obj
, void *data
, QGuestAllocator
*t_alloc
)
1532 QVirtio9P
*v9p
= obj
;
1534 struct stat st_real
, st_link
;
1535 g_autofree
char *real_file
= virtio_9p_test_path("07/real_file");
1536 g_autofree
char *hardlink_file
= virtio_9p_test_path("07/hardlink_file");
1539 do_mkdir(v9p
, "/", "07");
1540 do_lcreate(v9p
, "07", "real_file");
1541 g_assert(stat(real_file
, &st_real
) == 0);
1542 g_assert((st_real
.st_mode
& S_IFMT
) == S_IFREG
);
1544 do_hardlink(v9p
, "07", "hardlink_file", "07/real_file");
1546 /* check if link exists now ... */
1547 g_assert(stat(hardlink_file
, &st_link
) == 0);
1548 /* ... and it's a hard link, right? */
1549 g_assert((st_link
.st_mode
& S_IFMT
) == S_IFREG
);
1550 g_assert(st_link
.st_dev
== st_real
.st_dev
);
1551 g_assert(st_link
.st_ino
== st_real
.st_ino
);
1554 static void fs_unlinkat_hardlink(void *obj
, void *data
,
1555 QGuestAllocator
*t_alloc
)
1557 QVirtio9P
*v9p
= obj
;
1559 struct stat st_real
, st_link
;
1560 g_autofree
char *real_file
= virtio_9p_test_path("08/real_file");
1561 g_autofree
char *hardlink_file
= virtio_9p_test_path("08/hardlink_file");
1564 do_mkdir(v9p
, "/", "08");
1565 do_lcreate(v9p
, "08", "real_file");
1566 g_assert(stat(real_file
, &st_real
) == 0);
1567 g_assert((st_real
.st_mode
& S_IFMT
) == S_IFREG
);
1569 do_hardlink(v9p
, "08", "hardlink_file", "08/real_file");
1570 g_assert(stat(hardlink_file
, &st_link
) == 0);
1572 do_unlinkat(v9p
, "08", "hardlink_file", 0);
1573 /* symlink should be gone now */
1574 g_assert(stat(hardlink_file
, &st_link
) != 0);
1575 /* and old file should still exist */
1576 g_assert(stat(real_file
, &st_real
) == 0);
1579 static void *assign_9p_local_driver(GString
*cmd_line
, void *arg
)
1581 virtio_9p_assign_local_driver(cmd_line
, "security_model=mapped-xattr");
1585 static void register_virtio_9p_test(void)
1588 QOSGraphTestOptions opts
= {
1591 /* 9pfs test cases using the 'synth' filesystem driver */
1592 qos_add_test("synth/config", "virtio-9p", pci_config
, &opts
);
1593 qos_add_test("synth/version/basic", "virtio-9p", fs_version
, &opts
);
1594 qos_add_test("synth/attach/basic", "virtio-9p", fs_attach
, &opts
);
1595 qos_add_test("synth/walk/basic", "virtio-9p", fs_walk
, &opts
);
1596 qos_add_test("synth/walk/no_slash", "virtio-9p", fs_walk_no_slash
,
1598 qos_add_test("synth/walk/none", "virtio-9p", fs_walk_none
, &opts
);
1599 qos_add_test("synth/walk/dotdot_from_root", "virtio-9p",
1600 fs_walk_dotdot
, &opts
);
1601 qos_add_test("synth/walk/non_existent", "virtio-9p", fs_walk_nonexistent
,
1603 qos_add_test("synth/walk/2nd_non_existent", "virtio-9p",
1604 fs_walk_2nd_nonexistent
, &opts
);
1605 qos_add_test("synth/lopen/basic", "virtio-9p", fs_lopen
, &opts
);
1606 qos_add_test("synth/write/basic", "virtio-9p", fs_write
, &opts
);
1607 qos_add_test("synth/flush/success", "virtio-9p", fs_flush_success
,
1609 qos_add_test("synth/flush/ignored", "virtio-9p", fs_flush_ignored
,
1611 qos_add_test("synth/readdir/basic", "virtio-9p", fs_readdir
, &opts
);
1612 qos_add_test("synth/readdir/split_512", "virtio-9p",
1613 fs_readdir_split_512
, &opts
);
1614 qos_add_test("synth/readdir/split_256", "virtio-9p",
1615 fs_readdir_split_256
, &opts
);
1616 qos_add_test("synth/readdir/split_128", "virtio-9p",
1617 fs_readdir_split_128
, &opts
);
1620 /* 9pfs test cases using the 'local' filesystem driver */
1623 * XXX: Until we are sure that these tests can run everywhere,
1624 * keep them as "slow" so that they aren't run with "make check".
1626 if (!g_test_slow()) {
1630 opts
.before
= assign_9p_local_driver
;
1631 qos_add_test("local/config", "virtio-9p", pci_config
, &opts
);
1632 qos_add_test("local/create_dir", "virtio-9p", fs_create_dir
, &opts
);
1633 qos_add_test("local/unlinkat_dir", "virtio-9p", fs_unlinkat_dir
, &opts
);
1634 qos_add_test("local/create_file", "virtio-9p", fs_create_file
, &opts
);
1635 qos_add_test("local/unlinkat_file", "virtio-9p", fs_unlinkat_file
, &opts
);
1636 qos_add_test("local/symlink_file", "virtio-9p", fs_symlink_file
, &opts
);
1637 qos_add_test("local/unlinkat_symlink", "virtio-9p", fs_unlinkat_symlink
,
1639 qos_add_test("local/hardlink_file", "virtio-9p", fs_hardlink_file
, &opts
);
1640 qos_add_test("local/unlinkat_hardlink", "virtio-9p", fs_unlinkat_hardlink
,
1644 libqos_init(register_virtio_9p_test
);
1646 static void __attribute__((constructor
)) construct_9p_test(void)
1648 /* make sure test dir for the 'local' tests exists */
1649 virtio_9p_create_local_test_dir();
1652 static void __attribute__((destructor
)) destruct_9p_test(void)
1654 /* remove previously created test dir when test suite completed */
1655 virtio_9p_remove_local_test_dir();