diff mbox series

[v3,6/6] tests/9p: Test `Tsetattr` can truncate unlinked file

Message ID 20250312152933.383967-7-groug@kaod.org (mailing list archive)
State New
Headers show
Series 9pfs: Fix ftruncate-after-unlink | expand

Commit Message

Greg Kurz March 12, 2025, 3:29 p.m. UTC
Enhance the `use-after-unlink` test with a new check for the
case where the client wants to alter the size of an unlinked
file for which it still has an active fid.

Suggested-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
Signed-off-by: Greg Kurz <groug@kaod.org>

v3: - check the size of the truncated file
---
 tests/qtest/virtio-9p-test.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

Comments

Christian Schoenebeck March 12, 2025, 4:21 p.m. UTC | #1
On Wednesday, March 12, 2025 4:29:32 PM CET Greg Kurz wrote:
> Enhance the `use-after-unlink` test with a new check for the
> case where the client wants to alter the size of an unlinked
> file for which it still has an active fid.
> 
> Suggested-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
> Signed-off-by: Greg Kurz <groug@kaod.org>
> 
> v3: - check the size of the truncated file
> ---
>  tests/qtest/virtio-9p-test.c | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c
> index f515a9bb157b..ac38ccf59513 100644
> --- a/tests/qtest/virtio-9p-test.c
> +++ b/tests/qtest/virtio-9p-test.c
> @@ -736,6 +736,20 @@ static void fs_use_after_unlink(void *obj, void *data,
>          .data = buf
>      }).count;
>      g_assert_cmpint(count, ==, write_count);
> +
> +    /* truncate file to (arbitrarily chosen) size 2001 */
> +    tsetattr({
> +        .client = v9p, .fid = fid_file, .attr = (v9fs_attr) {
> +            .valid = P9_SETATTR_SIZE,
> +            .size = 2001
> +        }
> +     });
> +    /* truncate apparently succeeded, let's double-check the size */
> +    tgetattr({
> +        .client = v9p, .fid = fid_file, .request_mask = P9_GETATTR_BASIC,
> +        .rgetattr.attr = &attr
> +    });
> +    g_assert_cmpint(attr.size, ==, 2001);
>  }
>  
>  static void cleanup_9p_local_driver(void *data)

Ah OK, even better than the suggested stat() call!

Reviewed-by: Christian Schoenebeck <qemu_oss@crudebyte.com>

Thanks!

/Christian
diff mbox series

Patch

diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c
index f515a9bb157b..ac38ccf59513 100644
--- a/tests/qtest/virtio-9p-test.c
+++ b/tests/qtest/virtio-9p-test.c
@@ -736,6 +736,20 @@  static void fs_use_after_unlink(void *obj, void *data,
         .data = buf
     }).count;
     g_assert_cmpint(count, ==, write_count);
+
+    /* truncate file to (arbitrarily chosen) size 2001 */
+    tsetattr({
+        .client = v9p, .fid = fid_file, .attr = (v9fs_attr) {
+            .valid = P9_SETATTR_SIZE,
+            .size = 2001
+        }
+     });
+    /* truncate apparently succeeded, let's double-check the size */
+    tgetattr({
+        .client = v9p, .fid = fid_file, .request_mask = P9_GETATTR_BASIC,
+        .rgetattr.attr = &attr
+    });
+    g_assert_cmpint(attr.size, ==, 2001);
 }
 
 static void cleanup_9p_local_driver(void *data)