mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-05 00:33:55 -06:00
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>
This commit is contained in:
parent
d41a9462ea
commit
43e0d9fb35
3 changed files with 64 additions and 28 deletions
|
@ -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] */
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue