* [PATCH 1/3] tests/9p: rename test use_after_unlink -> use_file_after_unlink
2025-01-09 13:04 [PATCH 0/3] tests/9p: add use-dir-after-unlink test Christian Schoenebeck
@ 2025-01-09 12:59 ` Christian Schoenebeck
2025-01-09 12:59 ` [PATCH 2/3] tests/9p: add use_dir_after_unlink test Christian Schoenebeck
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Christian Schoenebeck @ 2025-01-09 12:59 UTC (permalink / raw)
To: qemu-devel; +Cc: Greg Kurz
To pave the way for adding new test use_dir_after_unlink with subsequent
patch, i.e. making it clear that the existing test is just about unlinked
files, not unlinked directories.
Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
---
tests/qtest/virtio-9p-test.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c
index ab3a12c816..07459c5289 100644
--- a/tests/qtest/virtio-9p-test.c
+++ b/tests/qtest/virtio-9p-test.c
@@ -693,8 +693,8 @@ static void fs_unlinkat_hardlink(void *obj, void *data,
g_assert(stat(real_file, &st_real) == 0);
}
-static void fs_use_after_unlink(void *obj, void *data,
- QGuestAllocator *t_alloc)
+static void fs_use_file_after_unlink(void *obj, void *data,
+ QGuestAllocator *t_alloc)
{
QVirtio9P *v9p = obj;
v9fs_set_allocator(t_alloc);
@@ -802,8 +802,8 @@ static void register_virtio_9p_test(void)
qos_add_test("local/hardlink_file", "virtio-9p", fs_hardlink_file, &opts);
qos_add_test("local/unlinkat_hardlink", "virtio-9p", fs_unlinkat_hardlink,
&opts);
- qos_add_test("local/use_after_unlink", "virtio-9p", fs_use_after_unlink,
- &opts);
+ qos_add_test("local/use_file_after_unlink", "virtio-9p",
+ fs_use_file_after_unlink, &opts);
}
libqos_init(register_virtio_9p_test);
--
2.39.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/3] tests/9p: add use_dir_after_unlink test
2025-01-09 13:04 [PATCH 0/3] tests/9p: add use-dir-after-unlink test Christian Schoenebeck
2025-01-09 12:59 ` [PATCH 1/3] tests/9p: rename test use_after_unlink -> use_file_after_unlink Christian Schoenebeck
@ 2025-01-09 12:59 ` Christian Schoenebeck
2025-01-09 12:59 ` [PATCH 3/3] tests/9p: extend use_dir_after_unlink test with Treaddir Christian Schoenebeck
2025-01-30 14:27 ` [PATCH 0/3] tests/9p: add use-dir-after-unlink test Christian Schoenebeck
3 siblings, 0 replies; 5+ messages in thread
From: Christian Schoenebeck @ 2025-01-09 12:59 UTC (permalink / raw)
To: qemu-devel; +Cc: Greg Kurz
After removing a directory from the filesystem, it should still be
possible to operate on the directory if the directory has been opened
before.
As a first step this new test will verify whether Tgetattr request
works on the unlinked directory.
Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
---
tests/qtest/virtio-9p-test.c | 39 ++++++++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)
diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c
index 07459c5289..35c42cd0d7 100644
--- a/tests/qtest/virtio-9p-test.c
+++ b/tests/qtest/virtio-9p-test.c
@@ -737,6 +737,43 @@ static void fs_use_file_after_unlink(void *obj, void *data,
g_assert_cmpint(count, ==, write_count);
}
+static void fs_use_dir_after_unlink(void *obj, void *data,
+ QGuestAllocator *t_alloc)
+{
+ QVirtio9P *v9p = obj;
+ v9fs_set_allocator(t_alloc);
+ g_autofree char *real_dir = virtio_9p_test_path("10/doa_dir");
+ struct stat st_dir;
+ struct v9fs_attr attr;
+ uint32_t fid_dir;
+
+ tattach({ .client = v9p });
+
+ /* create a dir "10/doa_dir" and make sure it exists */
+ tmkdir({ .client = v9p, .atPath = "/", .name = "10" });
+ tmkdir({ .client = v9p, .atPath = "10", .name = "doa_dir" });
+ g_assert(stat(real_dir, &st_dir) == 0);
+ g_assert((st_dir.st_mode & S_IFMT) == S_IFDIR);
+
+ /* request a FID for that directory that we can work with next */
+ fid_dir = twalk({
+ .client = v9p, .fid = 0, .path = "10/doa_dir"
+ }).newfid;
+ g_assert(fid_dir != 0);
+
+ /* now first open the dir before ... */
+ tlopen({ .client = v9p, .fid = fid_dir, .flags = O_RDONLY });
+ /* ... removing the dir from file system */
+ tunlinkat({ .client = v9p, .atPath = "10", .name = "doa_dir",
+ .flags = AT_REMOVEDIR });
+
+ /* dir is removed, but we still have it open, so this should succeed */
+ tgetattr({
+ .client = v9p, .fid = fid_dir, .request_mask = P9_GETATTR_BASIC,
+ .rgetattr.attr = &attr
+ });
+}
+
static void cleanup_9p_local_driver(void *data)
{
/* remove previously created test dir when test is completed */
@@ -804,6 +841,8 @@ static void register_virtio_9p_test(void)
&opts);
qos_add_test("local/use_file_after_unlink", "virtio-9p",
fs_use_file_after_unlink, &opts);
+ qos_add_test("local/use_dir_after_unlink", "virtio-9p",
+ fs_use_dir_after_unlink, &opts);
}
libqos_init(register_virtio_9p_test);
--
2.39.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/3] tests/9p: extend use_dir_after_unlink test with Treaddir
2025-01-09 13:04 [PATCH 0/3] tests/9p: add use-dir-after-unlink test Christian Schoenebeck
2025-01-09 12:59 ` [PATCH 1/3] tests/9p: rename test use_after_unlink -> use_file_after_unlink Christian Schoenebeck
2025-01-09 12:59 ` [PATCH 2/3] tests/9p: add use_dir_after_unlink test Christian Schoenebeck
@ 2025-01-09 12:59 ` Christian Schoenebeck
2025-01-30 14:27 ` [PATCH 0/3] tests/9p: add use-dir-after-unlink test Christian Schoenebeck
3 siblings, 0 replies; 5+ messages in thread
From: Christian Schoenebeck @ 2025-01-09 12:59 UTC (permalink / raw)
To: qemu-devel; +Cc: Greg Kurz
Sending a Treaddir request on an unlinked directory should also succeed
if the directory was alread opened before unlink. We just check that no
error occurs and that we get some kind of Treaddir result, but completely
ignore the actual Treaddir result content. In fact, there should be no
system as of to date that would allow a removed directory to have any
content (files, links, devices, subdirectories) and POSIX specifies that
a directory must be empty when trying to remove it from the file system.
Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
---
tests/qtest/virtio-9p-test.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c
index 35c42cd0d7..10243247ab 100644
--- a/tests/qtest/virtio-9p-test.c
+++ b/tests/qtest/virtio-9p-test.c
@@ -772,6 +772,9 @@ static void fs_use_dir_after_unlink(void *obj, void *data,
.client = v9p, .fid = fid_dir, .request_mask = P9_GETATTR_BASIC,
.rgetattr.attr = &attr
});
+ treaddir({
+ .client = v9p, .fid = fid_dir, .offset = 0, .count = P9_MAX_SIZE - 11
+ });
}
static void cleanup_9p_local_driver(void *data)
--
2.39.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 0/3] tests/9p: add use-dir-after-unlink test
@ 2025-01-09 13:04 Christian Schoenebeck
2025-01-09 12:59 ` [PATCH 1/3] tests/9p: rename test use_after_unlink -> use_file_after_unlink Christian Schoenebeck
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Christian Schoenebeck @ 2025-01-09 13:04 UTC (permalink / raw)
To: qemu-devel; +Cc: Greg Kurz
Add a test case that verifies that it is possible to do some basic operations
on a deleted directory if 9p client opened the directory before directory was
removed.
Unlike the previous open-unlink-fstat idiom: no fix required here. It already
works with 9p server.
Christian Schoenebeck (3):
tests/9p: rename test use_after_unlink -> use_file_after_unlink
tests/9p: add use_dir_after_unlink test
tests/9p: extend use_dir_after_unlink test with Treaddir
tests/qtest/virtio-9p-test.c | 50 +++++++++++++++++++++++++++++++++---
1 file changed, 46 insertions(+), 4 deletions(-)
--
2.39.5
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 0/3] tests/9p: add use-dir-after-unlink test
2025-01-09 13:04 [PATCH 0/3] tests/9p: add use-dir-after-unlink test Christian Schoenebeck
` (2 preceding siblings ...)
2025-01-09 12:59 ` [PATCH 3/3] tests/9p: extend use_dir_after_unlink test with Treaddir Christian Schoenebeck
@ 2025-01-30 14:27 ` Christian Schoenebeck
3 siblings, 0 replies; 5+ messages in thread
From: Christian Schoenebeck @ 2025-01-30 14:27 UTC (permalink / raw)
To: qemu-devel; +Cc: Greg Kurz
On Thursday, January 9, 2025 2:04:38 PM CET Christian Schoenebeck wrote:
> Add a test case that verifies that it is possible to do some basic operations
> on a deleted directory if 9p client opened the directory before directory was
> removed.
>
> Unlike the previous open-unlink-fstat idiom: no fix required here. It already
> works with 9p server.
>
> Christian Schoenebeck (3):
> tests/9p: rename test use_after_unlink -> use_file_after_unlink
> tests/9p: add use_dir_after_unlink test
> tests/9p: extend use_dir_after_unlink test with Treaddir
>
> tests/qtest/virtio-9p-test.c | 50 +++++++++++++++++++++++++++++++++---
> 1 file changed, 46 insertions(+), 4 deletions(-)
Queued on 9p.next:
https://github.com/cschoenebeck/qemu/commits/9p.next
Thanks!
/Christian
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-01-30 14:27 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-09 13:04 [PATCH 0/3] tests/9p: add use-dir-after-unlink test Christian Schoenebeck
2025-01-09 12:59 ` [PATCH 1/3] tests/9p: rename test use_after_unlink -> use_file_after_unlink Christian Schoenebeck
2025-01-09 12:59 ` [PATCH 2/3] tests/9p: add use_dir_after_unlink test Christian Schoenebeck
2025-01-09 12:59 ` [PATCH 3/3] tests/9p: extend use_dir_after_unlink test with Treaddir Christian Schoenebeck
2025-01-30 14:27 ` [PATCH 0/3] tests/9p: add use-dir-after-unlink test Christian Schoenebeck
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).