aboutsummaryrefslogtreecommitdiff
path: root/tests/qtest/libqos/virtio-9p-client.c
diff options
context:
space:
mode:
authorChristian Schoenebeck <qemu_oss@crudebyte.com>2022-10-04 22:53:36 +0200
committerChristian Schoenebeck <qemu_oss@crudebyte.com>2022-10-24 12:24:32 +0200
commit74a160aba921a2ca37b026dbfcdd03386bc05e85 (patch)
tree2e3d17fbf73144d3c365412dbc4463aa8bc014b9 /tests/qtest/libqos/virtio-9p-client.c
parentbee8fda2f9841cc8d76fbe60f65f9aeb29fce1c2 (diff)
tests/9p: merge v9fs_tattach(), do_attach(), do_attach_rqid()
As with previous patches, unify those 3 functions into a single function v9fs_tattach() by using a declarative function arguments approach. Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com> Message-Id: <a6756b30bf2a1b25729c5bbabd1c9534a8f20d6f.1664917004.git.qemu_oss@crudebyte.com>
Diffstat (limited to 'tests/qtest/libqos/virtio-9p-client.c')
-rw-r--r--tests/qtest/libqos/virtio-9p-client.c40
1 files changed, 34 insertions, 6 deletions
diff --git a/tests/qtest/libqos/virtio-9p-client.c b/tests/qtest/libqos/virtio-9p-client.c
index e8364f8d64..5e6bd6120c 100644
--- a/tests/qtest/libqos/virtio-9p-client.c
+++ b/tests/qtest/libqos/virtio-9p-client.c
@@ -359,20 +359,48 @@ void v9fs_rversion(P9Req *req, uint16_t *len, char **version)
}
/* size[4] Tattach tag[2] fid[4] afid[4] uname[s] aname[s] n_uname[4] */
-P9Req *v9fs_tattach(QVirtio9P *v9p, uint32_t fid, uint32_t n_uname,
- uint16_t tag)
+TAttachRes v9fs_tattach(TAttachOpt opt)
{
+ uint32_t err;
const char *uname = ""; /* ignored by QEMU */
const char *aname = ""; /* ignored by QEMU */
- P9Req *req = v9fs_req_init(v9p, 4 + 4 + 2 + 2 + 4, P9_TATTACH, tag);
- v9fs_uint32_write(req, fid);
+ g_assert(opt.client);
+ /* expecting either Rattach or Rlerror, but obviously not both */
+ g_assert(!opt.expectErr || !opt.rattach.qid);
+
+ if (!opt.requestOnly) {
+ v9fs_tversion((TVersionOpt) { .client = opt.client });
+ }
+
+ if (!opt.n_uname) {
+ opt.n_uname = getuid();
+ }
+
+ P9Req *req = v9fs_req_init(opt.client, 4 + 4 + 2 + 2 + 4, P9_TATTACH,
+ opt.tag);
+
+ v9fs_uint32_write(req, opt.fid);
v9fs_uint32_write(req, P9_NOFID);
v9fs_string_write(req, uname);
v9fs_string_write(req, aname);
- v9fs_uint32_write(req, n_uname);
+ v9fs_uint32_write(req, opt.n_uname);
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_rattach(req, opt.rattach.qid);
+ }
+ req = NULL; /* request was freed */
+ }
+
+ return (TAttachRes) {
+ .req = req,
+ };
}
/* size[4] Rattach tag[2] qid[13] */