tests/9p: add use-dir-after-unlink test
cover tests/9p: add use-dir-after-unlink test
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(-)
Signature · 1 line
2.39.5
PATCH 1/3 tests/9p: rename test use_after_unlink -> use_file_after_unlink
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.
--- tests/qtest/virtio-9p-test.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
tests/qtest/virtio-9p-test.c +4 -4
@@ -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);
Signature · 1 line
2.39.5
PATCH 2/3 tests/9p: add use_dir_after_unlink test
In reply to Christian SchoenebeckAfter 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.
--- tests/qtest/virtio-9p-test.c | 39 ++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+)
tests/qtest/virtio-9p-test.c +39 -0
@@ -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);
Signature · 1 line
2.39.5
PATCH 3/3 tests/9p: extend use_dir_after_unlink test with Treaddir
In reply to Christian SchoenebeckSending 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.
--- tests/qtest/virtio-9p-test.c | 3 +++ 1 file changed, 3 insertions(+)
tests/qtest/virtio-9p-test.c +3 -0
@@ -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)
Signature · 1 line
2.39.5
Quoted 7 lines · CET Christian Schoenebeck
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.
Quoted 7 lines
Christian Schoenebeck (3):
tests/9p: rename testuse_after_unlink->use_file_after_unlinktests/9p: adduse_dir_after_unlinktest
tests/9p: extenduse_dir_after_unlinktest with Treaddirtests/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