summaryrefslogtreecommitdiffstats
path: root/tests/qtest/libqos
diff options
context:
space:
mode:
authorChristian Schoenebeck2022-10-04 22:54:14 +0200
committerChristian Schoenebeck2022-10-24 12:24:32 +0200
commitd41a9462ea15f0e3ef789d496032536c33098275 (patch)
tree15055a6f88541fc78254df0fee3a66bff2eeea60 /tests/qtest/libqos
parenttests/9p: merge v9fs_tsymlink() and do_symlink() (diff)
downloadqemu-d41a9462ea15f0e3ef789d496032536c33098275.tar.gz
qemu-d41a9462ea15f0e3ef789d496032536c33098275.tar.xz
qemu-d41a9462ea15f0e3ef789d496032536c33098275.zip
tests/9p: merge v9fs_tlink() and do_hardlink()
As with previous patches, unify those 2 functions into a single function v9fs_tlink() by using a declarative function arguments approach. Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com> Message-Id: <cb4d42203e1e4e6027df4924bbe4bdbc002f668b.1664917004.git.qemu_oss@crudebyte.com>
Diffstat (limited to 'tests/qtest/libqos')
-rw-r--r--tests/qtest/libqos/virtio-9p-client.c43
-rw-r--r--tests/qtest/libqos/virtio-9p-client.h31
2 files changed, 64 insertions, 10 deletions
diff --git a/tests/qtest/libqos/virtio-9p-client.c b/tests/qtest/libqos/virtio-9p-client.c
index 89eaf50355..a2770719b9 100644
--- a/tests/qtest/libqos/virtio-9p-client.c
+++ b/tests/qtest/libqos/virtio-9p-client.c
@@ -950,23 +950,50 @@ void v9fs_rsymlink(P9Req *req, v9fs_qid *qid)
}
/* size[4] Tlink tag[2] dfid[4] fid[4] name[s] */
-P9Req *v9fs_tlink(QVirtio9P *v9p, uint32_t dfid, uint32_t fid,
- const char *name, uint16_t tag)
+TlinkRes v9fs_tlink(TlinkOpt opt)
{
P9Req *req;
+ uint32_t err;
+
+ g_assert(opt.client);
+ /* expecting either hi-level atPath or low-level dfid, but not both */
+ g_assert(!opt.atPath || !opt.dfid);
+ /* expecting either hi-level toPath or low-level fid, but not both */
+ g_assert(!opt.toPath || !opt.fid);
+
+ if (opt.atPath) {
+ opt.dfid = v9fs_twalk((TWalkOpt) { .client = opt.client,
+ .path = opt.atPath }).newfid;
+ }
+ if (opt.toPath) {
+ opt.fid = v9fs_twalk((TWalkOpt) { .client = opt.client,
+ .path = opt.toPath }).newfid;
+ }
uint32_t body_size = 4 + 4;
- uint16_t string_size = v9fs_string_size(name);
+ uint16_t string_size = v9fs_string_size(opt.name);
g_assert_cmpint(body_size, <=, UINT32_MAX - string_size);
body_size += string_size;
- req = v9fs_req_init(v9p, body_size, P9_TLINK, tag);
- v9fs_uint32_write(req, dfid);
- v9fs_uint32_write(req, fid);
- v9fs_string_write(req, name);
+ req = v9fs_req_init(opt.client, body_size, P9_TLINK, opt.tag);
+ v9fs_uint32_write(req, opt.dfid);
+ v9fs_uint32_write(req, opt.fid);
+ v9fs_string_write(req, opt.name);
v9fs_req_send(req);
- return req;
+
+ if (!opt.requestOnly) {
+ v9fs_req_wait_for_reply(req, NULL);
+ if (opt.expectErr) {
+ v9fs_rlerror(req, &err);
+ g_assert_cmpint(err, ==, opt.expectErr);
+ } else {
+ v9fs_rlink(req);
+ }
+ req = NULL; /* request was freed */
+ }
+
+ return (TlinkRes) { .req = req };
}
/* size[4] Rlink tag[2] */
diff --git a/tests/qtest/libqos/virtio-9p-client.h b/tests/qtest/libqos/virtio-9p-client.h
index b905a54966..49ffd0fc51 100644
--- a/tests/qtest/libqos/virtio-9p-client.h
+++ b/tests/qtest/libqos/virtio-9p-client.h
@@ -387,6 +387,34 @@ typedef struct TsymlinkRes {
P9Req *req;
} TsymlinkRes;
+/* options for 'Tlink' 9p request */
+typedef struct TlinkOpt {
+ /* 9P client being used (mandatory) */
+ QVirtio9P *client;
+ /* user supplied tag number being returned with response (optional) */
+ uint16_t tag;
+ /* low-level variant of directory where hard link shall be created */
+ uint32_t dfid;
+ /* high-level variant of directory where hard link shall be created */
+ const char *atPath;
+ /* low-level variant of target referenced by new hard link */
+ uint32_t fid;
+ /* high-level variant of target referenced by new hard link */
+ const char *toPath;
+ /* name of hard link (required) */
+ const char *name;
+ /* only send Tlink 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;
+} TlinkOpt;
+
+/* result of 'Tlink' 9p request */
+typedef struct TlinkRes {
+ /* if requestOnly was set: request object for further processing */
+ P9Req *req;
+} TlinkRes;
+
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);
@@ -432,8 +460,7 @@ TlcreateRes v9fs_tlcreate(TlcreateOpt);
void v9fs_rlcreate(P9Req *req, v9fs_qid *qid, uint32_t *iounit);
TsymlinkRes v9fs_tsymlink(TsymlinkOpt);
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);
+TlinkRes v9fs_tlink(TlinkOpt);
void v9fs_rlink(P9Req *req);
P9Req *v9fs_tunlinkat(QVirtio9P *v9p, uint32_t dirfd, const char *name,
uint32_t flags, uint16_t tag);