aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2020-11-02 10:57:48 +0000
committerPeter Maydell <peter.maydell@linaro.org>2020-11-02 10:57:48 +0000
commitb149dea55cce97cb226683d06af61984a1c11e96 (patch)
tree05e1089e9ce0fb1a2cc9e82aa48540026c53123f /tests
parent2c6605389c1f76973d92b69b85d40d94b8f1092c (diff)
parent4d0746e2135f56c59c6e61ef42d700b7139065b4 (diff)
Merge remote-tracking branch 'remotes/cschoenebeck/tags/pull-9p-20201102' into staging
9pfs: only test case changes this time * Fix occasional test failures with parallel tests. * Fix coverity error in test code. * Avoid error when auto removing test directory if it disappeared for some reason. * Refactor: Rename functions to make top-level test functions fs_*() easily distinguishable from utility test functions do_*(). * Refactor: Drop unnecessary function arguments in utility test functions. * More test cases using the 9pfs 'local' filesystem driver backend, namely for the following 9p requests: Tunlinkat, Tlcreate, Tsymlink and Tlink. # gpg: Signature made Mon 02 Nov 2020 09:31:35 GMT # gpg: using RSA key 96D8D110CF7AF8084F88590134C2B58765A47395 # gpg: issuer "qemu_oss@crudebyte.com" # gpg: Good signature from "Christian Schoenebeck <qemu_oss@crudebyte.com>" [unknown] # gpg: WARNING: This key is not certified with a trusted signature! # gpg: There is no indication that the signature belongs to the owner. # Primary key fingerprint: ECAB 1A45 4014 1413 BA38 4926 30DB 47C3 A012 D5F4 # Subkey fingerprint: 96D8 D110 CF7A F808 4F88 5901 34C2 B587 65A4 7395 * remotes/cschoenebeck/tags/pull-9p-20201102: tests/9pfs: add local Tunlinkat hard link test tests/9pfs: add local Tlink test tests/9pfs: add local Tunlinkat symlink test tests/9pfs: add local Tsymlink test tests/9pfs: add local Tunlinkat file test tests/9pfs: add local Tlcreate test tests/9pfs: add local Tunlinkat directory test tests/9pfs: simplify do_mkdir() tests/9pfs: Turn fs_mkdir() into a helper tests/9pfs: Turn fs_readdir_split() into a helper tests/9pfs: Factor out do_attach() helper tests/9pfs: Set alloc in fs_create_dir() tests/9pfs: Factor out do_version() helper tests/9pfs: Force removing of local 9pfs test directory tests/9pfs: fix coverity error in create_local_test_dir() tests/9pfs: fix test dir for parallel tests tests/9pfs: make create/remove test dir public Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/qtest/libqos/virtio-9p.c29
-rw-r--r--tests/qtest/libqos/virtio-9p.h10
-rw-r--r--tests/qtest/virtio-9p-test.c479
3 files changed, 470 insertions, 48 deletions
diff --git a/tests/qtest/libqos/virtio-9p.c b/tests/qtest/libqos/virtio-9p.c
index d43647b3b7..be91662c6f 100644
--- a/tests/qtest/libqos/virtio-9p.c
+++ b/tests/qtest/libqos/virtio-9p.c
@@ -35,17 +35,28 @@ static char *concat_path(const char* a, const char* b)
static void init_local_test_path(void)
{
char *pwd = g_get_current_dir();
- local_test_path = concat_path(pwd, "qtest-9p-local");
+ char *template = concat_path(pwd, "qtest-9p-local-XXXXXX");
+ local_test_path = mkdtemp(template);
+ if (!local_test_path) {
+ g_test_message("mkdtemp('%s') failed: %s", template, strerror(errno));
+ }
+ g_assert(local_test_path);
g_free(pwd);
}
-/* Creates the directory for the 9pfs 'local' filesystem driver to access. */
-static void create_local_test_dir(void)
+void virtio_9p_create_local_test_dir(void)
{
struct stat st;
+ int res;
+
+ init_local_test_path();
g_assert(local_test_path != NULL);
- mkdir(local_test_path, 0777);
+ res = mkdir(local_test_path, 0777);
+ if (res < 0) {
+ g_test_message("mkdir('%s') failed: %s", local_test_path,
+ strerror(errno));
+ }
/* ensure test directory exists now ... */
g_assert(stat(local_test_path, &st) == 0);
@@ -53,11 +64,10 @@ static void create_local_test_dir(void)
g_assert((st.st_mode & S_IFMT) == S_IFDIR);
}
-/* Deletes directory previously created by create_local_test_dir(). */
-static void remove_local_test_dir(void)
+void virtio_9p_remove_local_test_dir(void)
{
g_assert(local_test_path != NULL);
- char *cmd = g_strdup_printf("rm -r '%s'\n", local_test_path);
+ char *cmd = g_strdup_printf("rm -fr '%s'\n", local_test_path);
int res = system(cmd);
if (res < 0) {
/* ignore error, dummy check to prevent compiler error */
@@ -246,11 +256,6 @@ static void virtio_9p_register_nodes(void)
const char *str_simple = "fsdev=fsdev0,mount_tag=" MOUNT_TAG;
const char *str_addr = "fsdev=fsdev0,addr=04.0,mount_tag=" MOUNT_TAG;
- /* make sure test dir for the 'local' tests exists and is clean */
- init_local_test_path();
- remove_local_test_dir();
- create_local_test_dir();
-
QPCIAddress addr = {
.devfn = QPCI_DEVFN(4, 0),
};
diff --git a/tests/qtest/libqos/virtio-9p.h b/tests/qtest/libqos/virtio-9p.h
index 19a4d97454..480727120e 100644
--- a/tests/qtest/libqos/virtio-9p.h
+++ b/tests/qtest/libqos/virtio-9p.h
@@ -45,6 +45,16 @@ struct QVirtio9PDevice {
};
/**
+ * Creates the directory for the 9pfs 'local' filesystem driver to access.
+ */
+void virtio_9p_create_local_test_dir(void);
+
+/**
+ * Deletes directory previously created by virtio_9p_create_local_test_dir().
+ */
+void virtio_9p_remove_local_test_dir(void);
+
+/**
* Prepares QEMU command line for 9pfs tests using the 'local' fs driver.
*/
void virtio_9p_assign_local_driver(GString *cmd_line, const char *args);
diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c
index c15908f27b..21e340fa5f 100644
--- a/tests/qtest/virtio-9p-test.c
+++ b/tests/qtest/virtio-9p-test.c
@@ -258,6 +258,10 @@ static const char *rmessage_name(uint8_t id)
id == P9_RLOPEN ? "RLOPEN" :
id == P9_RWRITE ? "RWRITE" :
id == P9_RMKDIR ? "RMKDIR" :
+ id == P9_RLCREATE ? "RLCREATE" :
+ id == P9_RSYMLINK ? "RSYMLINK" :
+ id == P9_RLINK ? "RLINK" :
+ id == P9_RUNLINKAT ? "RUNLINKAT" :
id == P9_RFLUSH ? "RFLUSH" :
id == P9_RREADDIR ? "READDIR" :
"<unknown>";
@@ -567,10 +571,8 @@ static void v9fs_rflush(P9Req *req)
v9fs_req_free(req);
}
-static void fs_version(void *obj, void *data, QGuestAllocator *t_alloc)
+static void do_version(QVirtio9P *v9p)
{
- QVirtio9P *v9p = obj;
- alloc = t_alloc;
const char *version = "9P2000.L";
uint16_t server_len;
char *server_version;
@@ -585,18 +587,45 @@ static void fs_version(void *obj, void *data, QGuestAllocator *t_alloc)
g_free(server_version);
}
-static void fs_attach(void *obj, void *data, QGuestAllocator *t_alloc)
+/* utility function: walk to requested dir and return fid for that dir */
+static uint32_t do_walk(QVirtio9P *v9p, const char *path)
+{
+ char **wnames;
+ P9Req *req;
+ const uint32_t fid = genfid();
+
+ int nwnames = split(path, "/", &wnames);
+
+ req = v9fs_twalk(v9p, 0, fid, nwnames, wnames, 0);
+ v9fs_req_wait_for_reply(req, NULL);
+ v9fs_rwalk(req, NULL, NULL);
+
+ split_free(&wnames);
+ return fid;
+}
+
+static void fs_version(void *obj, void *data, QGuestAllocator *t_alloc)
{
- QVirtio9P *v9p = obj;
alloc = t_alloc;
+ do_version(obj);
+}
+
+static void do_attach(QVirtio9P *v9p)
+{
P9Req *req;
- fs_version(v9p, NULL, t_alloc);
+ do_version(v9p);
req = v9fs_tattach(v9p, 0, getuid(), 0);
v9fs_req_wait_for_reply(req, NULL);
v9fs_rattach(req, NULL);
}
+static void fs_attach(void *obj, void *data, QGuestAllocator *t_alloc)
+{
+ alloc = t_alloc;
+ do_attach(obj);
+}
+
static void fs_walk(void *obj, void *data, QGuestAllocator *t_alloc)
{
QVirtio9P *v9p = obj;
@@ -611,7 +640,7 @@ static void fs_walk(void *obj, void *data, QGuestAllocator *t_alloc)
wnames[i] = g_strdup_printf(QTEST_V9FS_SYNTH_WALK_FILE, i);
}
- fs_attach(v9p, NULL, t_alloc);
+ do_attach(v9p);
req = v9fs_twalk(v9p, 0, 1, P9_MAXWELEM, wnames, 0);
v9fs_req_wait_for_reply(req, NULL);
v9fs_rwalk(req, &nwqid, &wqid);
@@ -668,6 +697,131 @@ static void v9fs_rmkdir(P9Req *req, v9fs_qid *qid)
v9fs_req_free(req);
}
+/* size[4] Tlcreate tag[2] fid[4] name[s] flags[4] mode[4] gid[4] */
+static P9Req *v9fs_tlcreate(QVirtio9P *v9p, uint32_t fid, const char *name,
+ uint32_t flags, uint32_t mode, uint32_t gid,
+ uint16_t tag)
+{
+ P9Req *req;
+
+ uint32_t body_size = 4 + 4 + 4 + 4;
+ uint16_t string_size = v9fs_string_size(name);
+
+ g_assert_cmpint(body_size, <=, UINT32_MAX - string_size);
+ body_size += string_size;
+
+ req = v9fs_req_init(v9p, body_size, P9_TLCREATE, tag);
+ v9fs_uint32_write(req, fid);
+ v9fs_string_write(req, name);
+ v9fs_uint32_write(req, flags);
+ v9fs_uint32_write(req, mode);
+ v9fs_uint32_write(req, gid);
+ v9fs_req_send(req);
+ return req;
+}
+
+/* size[4] Rlcreate tag[2] qid[13] iounit[4] */
+static void v9fs_rlcreate(P9Req *req, v9fs_qid *qid, uint32_t *iounit)
+{
+ v9fs_req_recv(req, P9_RLCREATE);
+ if (qid) {
+ v9fs_memread(req, qid, 13);
+ } else {
+ v9fs_memskip(req, 13);
+ }
+ if (iounit) {
+ v9fs_uint32_read(req, iounit);
+ }
+ v9fs_req_free(req);
+}
+
+/* size[4] Tsymlink tag[2] fid[4] name[s] symtgt[s] gid[4] */
+static P9Req *v9fs_tsymlink(QVirtio9P *v9p, uint32_t fid, const char *name,
+ const char *symtgt, uint32_t gid, uint16_t tag)
+{
+ P9Req *req;
+
+ uint32_t body_size = 4 + 4;
+ uint16_t string_size = v9fs_string_size(name) + v9fs_string_size(symtgt);
+
+ g_assert_cmpint(body_size, <=, UINT32_MAX - string_size);
+ body_size += string_size;
+
+ req = v9fs_req_init(v9p, body_size, P9_TSYMLINK, tag);
+ v9fs_uint32_write(req, fid);
+ v9fs_string_write(req, name);
+ v9fs_string_write(req, symtgt);
+ v9fs_uint32_write(req, gid);
+ v9fs_req_send(req);
+ return req;
+}
+
+/* size[4] Rsymlink tag[2] qid[13] */
+static void v9fs_rsymlink(P9Req *req, v9fs_qid *qid)
+{
+ v9fs_req_recv(req, P9_RSYMLINK);
+ if (qid) {
+ v9fs_memread(req, qid, 13);
+ } else {
+ v9fs_memskip(req, 13);
+ }
+ v9fs_req_free(req);
+}
+
+/* size[4] Tlink tag[2] dfid[4] fid[4] name[s] */
+static P9Req *v9fs_tlink(QVirtio9P *v9p, uint32_t dfid, uint32_t fid,
+ const char *name, uint16_t tag)
+{
+ P9Req *req;
+
+ uint32_t body_size = 4 + 4;
+ uint16_t string_size = v9fs_string_size(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);
+ v9fs_req_send(req);
+ return req;
+}
+
+/* size[4] Rlink tag[2] */
+static void v9fs_rlink(P9Req *req)
+{
+ v9fs_req_recv(req, P9_RLINK);
+ v9fs_req_free(req);
+}
+
+/* size[4] Tunlinkat tag[2] dirfd[4] name[s] flags[4] */
+static P9Req *v9fs_tunlinkat(QVirtio9P *v9p, uint32_t dirfd, const char *name,
+ uint32_t flags, uint16_t tag)
+{
+ P9Req *req;
+
+ uint32_t body_size = 4 + 4;
+ uint16_t string_size = v9fs_string_size(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);
+ v9fs_req_send(req);
+ return req;
+}
+
+/* size[4] Runlinkat tag[2] */
+static void v9fs_runlinkat(P9Req *req)
+{
+ v9fs_req_recv(req, P9_RUNLINKAT);
+ v9fs_req_free(req);
+}
+
/* basic readdir test where reply fits into a single response message */
static void fs_readdir(void *obj, void *data, QGuestAllocator *t_alloc)
{
@@ -680,7 +834,7 @@ static void fs_readdir(void *obj, void *data, QGuestAllocator *t_alloc)
struct V9fsDirent *entries = NULL;
P9Req *req;
- fs_attach(v9p, NULL, t_alloc);
+ do_attach(v9p);
req = v9fs_twalk(v9p, 0, 1, 1, wnames, 0);
v9fs_req_wait_for_reply(req, NULL);
v9fs_rwalk(req, &nqid, NULL);
@@ -723,11 +877,8 @@ static void fs_readdir(void *obj, void *data, QGuestAllocator *t_alloc)
}
/* readdir test where overall request is split over several messages */
-static void fs_readdir_split(void *obj, void *data, QGuestAllocator *t_alloc,
- uint32_t count)
+static void do_readdir_split(QVirtio9P *v9p, uint32_t count)
{
- QVirtio9P *v9p = obj;
- alloc = t_alloc;
char *const wnames[] = { g_strdup(QTEST_V9FS_SYNTH_READDIR_DIR) };
uint16_t nqid;
v9fs_qid qid;
@@ -737,7 +888,7 @@ static void fs_readdir_split(void *obj, void *data, QGuestAllocator *t_alloc,
int fid;
uint64_t offset;
- fs_attach(v9p, NULL, t_alloc);
+ do_attach(v9p);
fid = 1;
offset = 0;
@@ -813,7 +964,7 @@ static void fs_walk_no_slash(void *obj, void *data, QGuestAllocator *t_alloc)
P9Req *req;
uint32_t err;
- fs_attach(v9p, NULL, t_alloc);
+ do_attach(v9p);
req = v9fs_twalk(v9p, 0, 1, 1, wnames, 0);
v9fs_req_wait_for_reply(req, NULL);
v9fs_rlerror(req, &err);
@@ -831,7 +982,7 @@ static void fs_walk_dotdot(void *obj, void *data, QGuestAllocator *t_alloc)
v9fs_qid root_qid, *wqid;
P9Req *req;
- fs_version(v9p, NULL, t_alloc);
+ do_version(v9p);
req = v9fs_tattach(v9p, 0, getuid(), 0);
v9fs_req_wait_for_reply(req, NULL);
v9fs_rattach(req, &root_qid);
@@ -853,7 +1004,7 @@ static void fs_lopen(void *obj, void *data, QGuestAllocator *t_alloc)
char *const wnames[] = { g_strdup(QTEST_V9FS_SYNTH_LOPEN_FILE) };
P9Req *req;
- fs_attach(v9p, NULL, t_alloc);
+ do_attach(v9p);
req = v9fs_twalk(v9p, 0, 1, 1, wnames, 0);
v9fs_req_wait_for_reply(req, NULL);
v9fs_rwalk(req, NULL, NULL);
@@ -875,7 +1026,7 @@ static void fs_write(void *obj, void *data, QGuestAllocator *t_alloc)
uint32_t count;
P9Req *req;
- fs_attach(v9p, NULL, t_alloc);
+ do_attach(v9p);
req = v9fs_twalk(v9p, 0, 1, 1, wnames, 0);
v9fs_req_wait_for_reply(req, NULL);
v9fs_rwalk(req, NULL, NULL);
@@ -902,7 +1053,7 @@ static void fs_flush_success(void *obj, void *data, QGuestAllocator *t_alloc)
uint32_t reply_len;
uint8_t should_block;
- fs_attach(v9p, NULL, t_alloc);
+ do_attach(v9p);
req = v9fs_twalk(v9p, 0, 1, 1, wnames, 0);
v9fs_req_wait_for_reply(req, NULL);
v9fs_rwalk(req, NULL, NULL);
@@ -939,7 +1090,7 @@ static void fs_flush_ignored(void *obj, void *data, QGuestAllocator *t_alloc)
uint32_t count;
uint8_t should_block;
- fs_attach(v9p, NULL, t_alloc);
+ do_attach(v9p);
req = v9fs_twalk(v9p, 0, 1, 1, wnames, 0);
v9fs_req_wait_for_reply(req, NULL);
v9fs_rwalk(req, NULL, NULL);
@@ -967,46 +1118,108 @@ static void fs_flush_ignored(void *obj, void *data, QGuestAllocator *t_alloc)
g_free(wnames[0]);
}
-static void fs_mkdir(void *obj, void *data, QGuestAllocator *t_alloc,
- const char *path, const char *cname)
+static void do_mkdir(QVirtio9P *v9p, const char *path, const char *cname)
{
- QVirtio9P *v9p = obj;
- alloc = t_alloc;
- char **wnames;
char *const name = g_strdup(cname);
+ uint32_t fid;
P9Req *req;
- const uint32_t fid = genfid();
-
- int nwnames = split(path, "/", &wnames);
- req = v9fs_twalk(v9p, 0, fid, nwnames, wnames, 0);
- v9fs_req_wait_for_reply(req, NULL);
- v9fs_rwalk(req, NULL, NULL);
+ fid = do_walk(v9p, path);
req = v9fs_tmkdir(v9p, fid, name, 0750, 0, 0);
v9fs_req_wait_for_reply(req, NULL);
v9fs_rmkdir(req, NULL);
g_free(name);
- split_free(&wnames);
+}
+
+/* create a regular file with Tlcreate and return file's fid */
+static uint32_t do_lcreate(QVirtio9P *v9p, const char *path,
+ const char *cname)
+{
+ char *const name = g_strdup(cname);
+ uint32_t fid;
+ P9Req *req;
+
+ fid = do_walk(v9p, path);
+
+ req = v9fs_tlcreate(v9p, fid, name, 0, 0750, 0, 0);
+ v9fs_req_wait_for_reply(req, NULL);
+ v9fs_rlcreate(req, NULL, NULL);
+
+ g_free(name);
+ return fid;
+}
+
+/* create symlink named @a clink in directory @a path pointing to @a to */
+static void do_symlink(QVirtio9P *v9p, const char *path, const char *clink,
+ const char *to)
+{
+ char *const name = g_strdup(clink);
+ char *const dst = g_strdup(to);
+ uint32_t fid;
+ P9Req *req;
+
+ fid = do_walk(v9p, path);
+
+ req = v9fs_tsymlink(v9p, fid, name, dst, 0, 0);
+ v9fs_req_wait_for_reply(req, NULL);
+ v9fs_rsymlink(req, NULL);
+
+ g_free(dst);
+ g_free(name);
+}
+
+/* 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 = do_walk(v9p, path);
+ fid = do_walk(v9p, to);
+
+ 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)
+{
+ char *const name = g_strdup(rpath);
+ uint32_t fid;
+ P9Req *req;
+
+ fid = do_walk(v9p, atpath);
+
+ req = v9fs_tunlinkat(v9p, fid, name, flags, 0);
+ v9fs_req_wait_for_reply(req, NULL);
+ v9fs_runlinkat(req);
+
+ g_free(name);
}
static void fs_readdir_split_128(void *obj, void *data,
QGuestAllocator *t_alloc)
{
- fs_readdir_split(obj, data, t_alloc, 128);
+ alloc = t_alloc;
+ do_readdir_split(obj, 128);
}
static void fs_readdir_split_256(void *obj, void *data,
QGuestAllocator *t_alloc)
{
- fs_readdir_split(obj, data, t_alloc, 256);
+ alloc = t_alloc;
+ do_readdir_split(obj, 256);
}
static void fs_readdir_split_512(void *obj, void *data,
QGuestAllocator *t_alloc)
{
- fs_readdir_split(obj, data, t_alloc, 512);
+ alloc = t_alloc;
+ do_readdir_split(obj, 512);
}
@@ -1015,24 +1228,197 @@ static void fs_readdir_split_512(void *obj, void *data,
static void fs_create_dir(void *obj, void *data, QGuestAllocator *t_alloc)
{
QVirtio9P *v9p = obj;
+ alloc = t_alloc;
struct stat st;
char *root_path = virtio_9p_test_path("");
char *new_dir = virtio_9p_test_path("01");
g_assert(root_path != NULL);
- fs_attach(v9p, NULL, t_alloc);
- fs_mkdir(v9p, data, t_alloc, "/", "01");
+ do_attach(v9p);
+ do_mkdir(v9p, "/", "01");
+
+ /* check if created directory really exists now ... */
+ g_assert(stat(new_dir, &st) == 0);
+ /* ... and is actually a directory */
+ g_assert((st.st_mode & S_IFMT) == S_IFDIR);
+
+ g_free(new_dir);
+ g_free(root_path);
+}
+
+static void fs_unlinkat_dir(void *obj, void *data, QGuestAllocator *t_alloc)
+{
+ QVirtio9P *v9p = obj;
+ alloc = t_alloc;
+ struct stat st;
+ char *root_path = virtio_9p_test_path("");
+ char *new_dir = virtio_9p_test_path("02");
+
+ g_assert(root_path != NULL);
+
+ do_attach(v9p);
+ do_mkdir(v9p, "/", "02");
/* check if created directory really exists now ... */
g_assert(stat(new_dir, &st) == 0);
/* ... and is actually a directory */
g_assert((st.st_mode & S_IFMT) == S_IFDIR);
+ do_unlinkat(v9p, "/", "02", AT_REMOVEDIR);
+ /* directory should be gone now */
+ g_assert(stat(new_dir, &st) != 0);
+
g_free(new_dir);
g_free(root_path);
}
+static void fs_create_file(void *obj, void *data, QGuestAllocator *t_alloc)
+{
+ QVirtio9P *v9p = obj;
+ alloc = t_alloc;
+ struct stat st;
+ char *new_file = virtio_9p_test_path("03/1st_file");
+
+ do_attach(v9p);
+ do_mkdir(v9p, "/", "03");
+ do_lcreate(v9p, "03", "1st_file");
+
+ /* check if created file exists now ... */
+ g_assert(stat(new_file, &st) == 0);
+ /* ... and is a regular file */
+ g_assert((st.st_mode & S_IFMT) == S_IFREG);
+
+ g_free(new_file);
+}
+
+static void fs_unlinkat_file(void *obj, void *data, QGuestAllocator *t_alloc)
+{
+ QVirtio9P *v9p = obj;
+ alloc = t_alloc;
+ struct stat st;
+ char *new_file = virtio_9p_test_path("04/doa_file");
+
+ do_attach(v9p);
+ do_mkdir(v9p, "/", "04");
+ do_lcreate(v9p, "04", "doa_file");
+
+ /* check if created file exists now ... */
+ g_assert(stat(new_file, &st) == 0);
+ /* ... and is a regular file */
+ g_assert((st.st_mode & S_IFMT) == S_IFREG);
+
+ do_unlinkat(v9p, "04", "doa_file", 0);
+ /* file should be gone now */
+ g_assert(stat(new_file, &st) != 0);
+
+ g_free(new_file);
+}
+
+static void fs_symlink_file(void *obj, void *data, QGuestAllocator *t_alloc)
+{
+ QVirtio9P *v9p = obj;
+ alloc = t_alloc;
+ struct stat st;
+ char *real_file = virtio_9p_test_path("05/real_file");
+ char *symlink_file = virtio_9p_test_path("05/symlink_file");
+
+ do_attach(v9p);
+ do_mkdir(v9p, "/", "05");
+ do_lcreate(v9p, "05", "real_file");
+ g_assert(stat(real_file, &st) == 0);
+ g_assert((st.st_mode & S_IFMT) == S_IFREG);
+
+ do_symlink(v9p, "05", "symlink_file", "real_file");
+
+ /* check if created link exists now */
+ g_assert(stat(symlink_file, &st) == 0);
+
+ g_free(symlink_file);
+ g_free(real_file);
+}
+
+static void fs_unlinkat_symlink(void *obj, void *data,
+ QGuestAllocator *t_alloc)
+{
+ QVirtio9P *v9p = obj;
+ alloc = t_alloc;
+ struct stat st;
+ char *real_file = virtio_9p_test_path("06/real_file");
+ char *symlink_file = virtio_9p_test_path("06/symlink_file");
+
+ do_attach(v9p);
+ do_mkdir(v9p, "/", "06");
+ do_lcreate(v9p, "06", "real_file");
+ g_assert(stat(real_file, &st) == 0);
+ g_assert((st.st_mode & S_IFMT) == S_IFREG);
+
+ do_symlink(v9p, "06", "symlink_file", "real_file");
+ g_assert(stat(symlink_file, &st) == 0);
+
+ do_unlinkat(v9p, "06", "symlink_file", 0);
+ /* symlink should be gone now */
+ g_assert(stat(symlink_file, &st) != 0);
+
+ g_free(symlink_file);
+ g_free(real_file);
+}
+
+static void fs_hardlink_file(void *obj, void *data, QGuestAllocator *t_alloc)
+{
+ QVirtio9P *v9p = obj;
+ alloc = t_alloc;
+ struct stat st_real, st_link;
+ char *real_file = virtio_9p_test_path("07/real_file");
+ char *hardlink_file = virtio_9p_test_path("07/hardlink_file");
+
+ do_attach(v9p);
+ do_mkdir(v9p, "/", "07");
+ do_lcreate(v9p, "07", "real_file");
+ 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");
+
+ /* check if link exists now ... */
+ g_assert(stat(hardlink_file, &st_link) == 0);
+ /* ... and it's a hard link, right? */
+ g_assert((st_link.st_mode & S_IFMT) == S_IFREG);
+ g_assert(st_link.st_dev == st_real.st_dev);
+ g_assert(st_link.st_ino == st_real.st_ino);
+
+ g_free(hardlink_file);
+ g_free(real_file);
+}
+
+static void fs_unlinkat_hardlink(void *obj, void *data,
+ QGuestAllocator *t_alloc)
+{
+ QVirtio9P *v9p = obj;
+ alloc = t_alloc;
+ struct stat st_real, st_link;
+ char *real_file = virtio_9p_test_path("08/real_file");
+ char *hardlink_file = virtio_9p_test_path("08/hardlink_file");
+
+ do_attach(v9p);
+ do_mkdir(v9p, "/", "08");
+ do_lcreate(v9p, "08", "real_file");
+ 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");
+ g_assert(stat(hardlink_file, &st_link) == 0);
+
+ do_unlinkat(v9p, "08", "hardlink_file", 0);
+ /* symlink should be gone now */
+ g_assert(stat(hardlink_file, &st_link) != 0);
+ /* and old file should still exist */
+ g_assert(stat(real_file, &st_real) == 0);
+
+ g_free(hardlink_file);
+ g_free(real_file);
+}
+
static void *assign_9p_local_driver(GString *cmd_line, void *arg)
{
virtio_9p_assign_local_driver(cmd_line, "security_model=mapped-xattr");
@@ -1073,6 +1459,27 @@ static void register_virtio_9p_test(void)
opts.before = assign_9p_local_driver;
qos_add_test("local/config", "virtio-9p", pci_config, &opts);
qos_add_test("local/create_dir", "virtio-9p", fs_create_dir, &opts);
+ qos_add_test("local/unlinkat_dir", "virtio-9p", fs_unlinkat_dir, &opts);
+ qos_add_test("local/create_file", "virtio-9p", fs_create_file, &opts);
+ qos_add_test("local/unlinkat_file", "virtio-9p", fs_unlinkat_file, &opts);
+ qos_add_test("local/symlink_file", "virtio-9p", fs_symlink_file, &opts);
+ qos_add_test("local/unlinkat_symlink", "virtio-9p", fs_unlinkat_symlink,
+ &opts);
+ qos_add_test("local/hardlink_file", "virtio-9p", fs_hardlink_file, &opts);
+ qos_add_test("local/unlinkat_hardlink", "virtio-9p", fs_unlinkat_hardlink,
+ &opts);
}
libqos_init(register_virtio_9p_test);
+
+static void __attribute__((constructor)) construct_9p_test(void)
+{
+ /* make sure test dir for the 'local' tests exists */
+ virtio_9p_create_local_test_dir();
+}
+
+static void __attribute__((destructor)) destruct_9p_test(void)
+{
+ /* remove previously created test dir when test suite completed */
+ virtio_9p_remove_local_test_dir();
+}