summaryrefslogtreecommitdiffstats
path: root/tests/qtest/libqos
diff options
context:
space:
mode:
authorChristian Schoenebeck2022-10-04 22:54:16 +0200
committerChristian Schoenebeck2022-10-24 12:24:32 +0200
commit43e0d9fb358b01539d0de9494208e80ff84b5456 (patch)
tree43a81e8f7a5d4d2e84e15859f40a7daf691dccae /tests/qtest/libqos
parenttests/9p: merge v9fs_tlink() and do_hardlink() (diff)
downloadqemu-43e0d9fb358b01539d0de9494208e80ff84b5456.tar.gz
qemu-43e0d9fb358b01539d0de9494208e80ff84b5456.tar.xz
qemu-43e0d9fb358b01539d0de9494208e80ff84b5456.zip
tests/9p: merge v9fs_tunlinkat() and do_unlinkat()
As with previous patches, unify those 2 functions into a single function v9fs_tunlinkat() by using a declarative function arguments approach. Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com> Message-Id: <1dea593edd464908d92501933c068388c01f1744.1664917004.git.qemu_oss@crudebyte.com>
Diffstat (limited to 'tests/qtest/libqos')
-rw-r--r--tests/qtest/libqos/virtio-9p-client.c37
-rw-r--r--tests/qtest/libqos/virtio-9p-client.h29
2 files changed, 56 insertions, 10 deletions
diff --git a/tests/qtest/libqos/virtio-9p-client.c b/tests/qtest/libqos/virtio-9p-client.c
index a2770719b9..e017e030ec 100644
--- a/tests/qtest/libqos/virtio-9p-client.c
+++ b/tests/qtest/libqos/virtio-9p-client.c
@@ -1004,23 +1004,44 @@ void v9fs_rlink(P9Req *req)
}
/* size[4] Tunlinkat tag[2] dirfd[4] name[s] flags[4] */
-P9Req *v9fs_tunlinkat(QVirtio9P *v9p, uint32_t dirfd, const char *name,
- uint32_t flags, uint16_t tag)
+TunlinkatRes v9fs_tunlinkat(TunlinkatOpt opt)
{
P9Req *req;
+ uint32_t err;
+
+ g_assert(opt.client);
+ /* expecting either hi-level atPath or low-level dirfd, but not both */
+ g_assert(!opt.atPath || !opt.dirfd);
+
+ if (opt.atPath) {
+ opt.dirfd = v9fs_twalk((TWalkOpt) { .client = opt.client,
+ .path = opt.atPath }).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_TUNLINKAT, tag);
- v9fs_uint32_write(req, dirfd);
- v9fs_string_write(req, name);
- v9fs_uint32_write(req, flags);
+ req = v9fs_req_init(opt.client, body_size, P9_TUNLINKAT, opt.tag);
+ v9fs_uint32_write(req, opt.dirfd);
+ v9fs_string_write(req, opt.name);
+ v9fs_uint32_write(req, opt.flags);
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_runlinkat(req);
+ }
+ req = NULL; /* request was freed */
+ }
+
+ return (TunlinkatRes) { .req = req };
}
/* size[4] Runlinkat tag[2] */
diff --git a/tests/qtest/libqos/virtio-9p-client.h b/tests/qtest/libqos/virtio-9p-client.h
index 49ffd0fc51..78228eb97d 100644
--- a/tests/qtest/libqos/virtio-9p-client.h
+++ b/tests/qtest/libqos/virtio-9p-client.h
@@ -415,6 +415,32 @@ typedef struct TlinkRes {
P9Req *req;
} TlinkRes;
+/* options for 'Tunlinkat' 9p request */
+typedef struct TunlinkatOpt {
+ /* 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 name shall be unlinked */
+ uint32_t dirfd;
+ /* high-level variant of directory where name shall be unlinked */
+ const char *atPath;
+ /* name of directory entry to be unlinked (required) */
+ const char *name;
+ /* Linux unlinkat(2) flags */
+ uint32_t flags;
+ /* only send Tunlinkat 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;
+} TunlinkatOpt;
+
+/* result of 'Tunlinkat' 9p request */
+typedef struct TunlinkatRes {
+ /* if requestOnly was set: request object for further processing */
+ P9Req *req;
+} TunlinkatRes;
+
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);
@@ -462,8 +488,7 @@ TsymlinkRes v9fs_tsymlink(TsymlinkOpt);
void v9fs_rsymlink(P9Req *req, v9fs_qid *qid);
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);
+TunlinkatRes v9fs_tunlinkat(TunlinkatOpt);
void v9fs_runlinkat(P9Req *req);
#endif