mirror of https://github.com/xemu-project/xemu.git
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>
This commit is contained in:
parent
9beabfa52c
commit
d41a9462ea
|
@ -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] */
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#define tmkdir(...) v9fs_tmkdir((TMkdirOpt) __VA_ARGS__)
|
||||
#define tlcreate(...) v9fs_tlcreate((TlcreateOpt) __VA_ARGS__)
|
||||
#define tsymlink(...) v9fs_tsymlink((TsymlinkOpt) __VA_ARGS__)
|
||||
#define tlink(...) v9fs_tlink((TlinkOpt) __VA_ARGS__)
|
||||
|
||||
static void pci_config(void *obj, void *data, QGuestAllocator *t_alloc)
|
||||
{
|
||||
|
@ -480,21 +481,6 @@ static void fs_flush_ignored(void *obj, void *data, QGuestAllocator *t_alloc)
|
|||
g_free(wnames[0]);
|
||||
}
|
||||
|
||||
/* create a hard link named @a clink in directory @a path pointing to @a to */
|
||||
static void do_hardlink(QVirtio9P *v9p, const char *path, const char *clink,
|
||||
const char *to)
|
||||
{
|
||||
uint32_t dfid, fid;
|
||||
P9Req *req;
|
||||
|
||||
dfid = twalk({ .client = v9p, .path = path }).newfid;
|
||||
fid = twalk({ .client = v9p, .path = to }).newfid;
|
||||
|
||||
req = v9fs_tlink(v9p, dfid, fid, clink, 0);
|
||||
v9fs_req_wait_for_reply(req, NULL);
|
||||
v9fs_rlink(req);
|
||||
}
|
||||
|
||||
static void do_unlinkat(QVirtio9P *v9p, const char *atpath, const char *rpath,
|
||||
uint32_t flags)
|
||||
{
|
||||
|
@ -676,7 +662,10 @@ static void fs_hardlink_file(void *obj, void *data, QGuestAllocator *t_alloc)
|
|||
g_assert(stat(real_file, &st_real) == 0);
|
||||
g_assert((st_real.st_mode & S_IFMT) == S_IFREG);
|
||||
|
||||
do_hardlink(v9p, "07", "hardlink_file", "07/real_file");
|
||||
tlink({
|
||||
.client = v9p, .atPath = "07", .name = "hardlink_file",
|
||||
.toPath = "07/real_file"
|
||||
});
|
||||
|
||||
/* check if link exists now ... */
|
||||
g_assert(stat(hardlink_file, &st_link) == 0);
|
||||
|
@ -701,7 +690,10 @@ static void fs_unlinkat_hardlink(void *obj, void *data,
|
|||
g_assert(stat(real_file, &st_real) == 0);
|
||||
g_assert((st_real.st_mode & S_IFMT) == S_IFREG);
|
||||
|
||||
do_hardlink(v9p, "08", "hardlink_file", "08/real_file");
|
||||
tlink({
|
||||
.client = v9p, .atPath = "08", .name = "hardlink_file",
|
||||
.toPath = "08/real_file"
|
||||
});
|
||||
g_assert(stat(hardlink_file, &st_link) == 0);
|
||||
|
||||
do_unlinkat(v9p, "08", "hardlink_file", 0);
|
||||
|
|
Loading…
Reference in New Issue