tests/9p: add Tclunk / Rclunk test client functions
Add v9fs_tclunk() and v9fs_rclunk() functions to the 9P test client for closing file handles (or "FIDs") in test cases. Link: https://lore.kernel.org/qemu-devel/d53f0337eb7f8525a14e394599d809ecf6805e5e.1781361555.git.qemu_oss@crudebyte.com Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
Christian Schoenebeck committed
Jun 13, 2026 at 16:55 UTC
c46150530b3dd6370affa3422f2175ac4668836a
3 files changed
+57
tests/qtest/libqos/virtio-9p-client.c
+34
@@ -242,6 +242,7 @@ static const char *rmessage_name(uint8_t id)
242
id == P9_RFLUSH ? "RFLUSH" :
243
id == P9_RREADDIR ? "RREADDIR" :
244
id == P9_RREAD ? "RREAD" :
245
+ id == P9_RCLUNK ? "RCLUNK" :
246
"<unknown>";
247
}
248
@@ -1148,3 +1149,36 @@ void v9fs_rread(P9Req *req, uint32_t *count, void *data)
1149
}
1150
v9fs_req_free(req);
1151
}
1152
+
1153
+/* size[4] Tclunk tag[2] fid[4] */
1154
+TClunkRes v9fs_tclunk(TClunkOpt opt)
1155
+{
1156
+ P9Req *req;
1157
+ uint32_t err;
1158
+
1159
+ g_assert(opt.client);
1160
+
1161
+ req = v9fs_req_init(opt.client, 4, P9_TCLUNK, opt.tag);
1162
+ v9fs_uint32_write(req, opt.fid);
1163
+ v9fs_req_send(req);
1164
+
1165
+ if (!opt.requestOnly) {
1166
+ v9fs_req_wait_for_reply(req, NULL);
1167
+ if (opt.expectErr) {
1168
+ v9fs_rlerror(req, &err);
1169
+ g_assert_cmpint(err, ==, opt.expectErr);
1170
+ } else {
1171
+ v9fs_rclunk(req);
1172
+ }
1173
+ req = NULL; /* request was freed */
1174
+ }
1175
+
1176
+ return (TClunkRes) { .req = req };
1177
+}
1178
+
1179
+/* size[4] Rclunk tag[2] */
1180
+void v9fs_rclunk(P9Req *req)
1181
+{
1182
+ v9fs_req_recv(req, P9_RCLUNK);
1183
+ v9fs_req_free(req);
1184
+}
tests/qtest/libqos/virtio-9p-client.h
+22
@@ -504,6 +504,26 @@ typedef struct TReadRes {
504
uint32_t count;
505
} TReadRes;
506
507
+/* options for 'Tclunk' 9p request */
508
+typedef struct TClunkOpt {
509
+ /* 9P client being used (mandatory) */
510
+ QVirtio9P *client;
511
+ /* user supplied tag number being returned with response (optional) */
512
+ uint16_t tag;
513
+ /* file ID to clunk (required) */
514
+ uint32_t fid;
515
+ /* only send Tclunk request but not wait for a reply? (optional) */
516
+ bool requestOnly;
517
+ /* do we expect an Rlerror response, if yes which error code? (optional) */
518
+ uint32_t expectErr;
519
+} TClunkOpt;
520
+
521
+/* result of 'Tclunk' 9p request */
522
+typedef struct TClunkRes {
523
+ /* if requestOnly was set: request object for further processing */
524
+ P9Req *req;
525
+} TClunkRes;
526
+
527
void v9fs_set_allocator(QGuestAllocator *t_alloc);
528
void v9fs_memwrite(P9Req *req, const void *addr, size_t len);
529
void v9fs_memskip(P9Req *req, size_t len);
@@ -557,5 +577,7 @@ TunlinkatRes v9fs_tunlinkat(TunlinkatOpt);
577
void v9fs_runlinkat(P9Req *req);
578
TReadRes v9fs_tread(TReadOpt opt);
579
void v9fs_rread(P9Req *req, uint32_t *count, void *data);
580
+TClunkRes v9fs_tclunk(TClunkOpt opt);
581
+void v9fs_rclunk(P9Req *req);
582
583
#endif
tests/qtest/virtio-9p-test.c
+1
@@ -32,6 +32,7 @@
32
#define tlink(...) v9fs_tlink((TlinkOpt) __VA_ARGS__)
33
#define tunlinkat(...) v9fs_tunlinkat((TunlinkatOpt) __VA_ARGS__)
34
#define tread(...) v9fs_tread((TReadOpt) __VA_ARGS__)
35
+#define tclunk(...) v9fs_tclunk((TClunkOpt) __VA_ARGS__)
36
37
static void pci_config(void *obj, void *data, QGuestAllocator *t_alloc)
38
{