All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg Kurz <groug@kaod.org>
To: Christian Schoenebeck <qemu_oss@crudebyte.com>
Cc: <qemu-devel@nongnu.org>, <qemu-stable@nongnu.org>
Subject: Re: [PATCH 1/6] tests/9p: add 'use-after-unlink' test
Date: Mon, 25 Nov 2024 09:47:17 +0100	[thread overview]
Message-ID: <20241125094717.50e0344b@bahia> (raw)
In-Reply-To: <3d6449d4df25bcdd3e807eff169f46f1385e5257.1732465720.git.qemu_oss@crudebyte.com>

Hi Christian,

On Wed, 21 Feb 2024 15:13:13 +0100
Christian Schoenebeck <qemu_oss@crudebyte.com> wrote:

> After removing a file from the file system, we should still be able to
> work with the file if we already had it open before removal.
> 
> As a first step we verify that it is possible to write to an unlinked
> file, as this is what already works. This test is extended later on
> after having fixed other use cases after unlink that are not working
> yet.
> 
> Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
> ---

Test looks good but make sure it is merged last to preserve bisect.

Reviewed-by: Greg Kurz <groug@kaod.org>

>  tests/qtest/virtio-9p-test.c | 41 ++++++++++++++++++++++++++++++++++++
>  1 file changed, 41 insertions(+)
> 
> diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c
> index 3c8cd235cf..f6d7400a87 100644
> --- a/tests/qtest/virtio-9p-test.c
> +++ b/tests/qtest/virtio-9p-test.c
> @@ -693,6 +693,45 @@ 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)
> +{
> +    QVirtio9P *v9p = obj;
> +    v9fs_set_allocator(t_alloc);
> +    static const uint32_t write_count = P9_MAX_SIZE / 2;
> +    g_autofree char *real_file = virtio_9p_test_path("09/doa_file");
> +    g_autofree char *buf = g_malloc0(write_count);
> +    struct stat st_file;
> +    uint32_t fid_file;
> +    uint32_t count;
> +
> +    tattach({ .client = v9p });
> +
> +    /* create a file "09/doa_file" and make sure it exists and is regular */
> +    tmkdir({ .client = v9p, .atPath = "/", .name = "09" });
> +    tlcreate({ .client = v9p, .atPath = "09", .name = "doa_file" });
> +    g_assert(stat(real_file, &st_file) == 0);
> +    g_assert((st_file.st_mode & S_IFMT) == S_IFREG);
> +
> +    /* request a FID for that regular file that we can work with next */
> +    fid_file = twalk({
> +        .client = v9p, .fid = 0, .path = "09/doa_file"
> +    }).newfid;
> +    g_assert(fid_file != 0);
> +
> +    /* now first open the file in write mode before ... */
> +    tlopen({ .client = v9p, .fid = fid_file, .flags = O_WRONLY });
> +    /* ... removing the file from file system */
> +    tunlinkat({ .client = v9p, .atPath = "09", .name = "doa_file" });
> +
> +    /* file is removed, but we still have it open, so this should succeed */
> +    count = twrite({
> +        .client = v9p, .fid = fid_file, .offset = 0, .count = write_count,
> +        .data = buf
> +    }).count;
> +    g_assert_cmpint(count, ==, write_count);
> +}
> +
>  static void cleanup_9p_local_driver(void *data)
>  {
>      /* remove previously created test dir when test is completed */
> @@ -758,6 +797,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);
>  }
>  
>  libqos_init(register_virtio_9p_test);


Cheers,

-- 
Greg


  reply	other threads:[~2024-11-25  8:47 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-24 16:28 [PATCH 0/6] 9pfs: fix fstat() after unlink() (with a Linux guest) Christian Schoenebeck
2024-02-21 14:13 ` [PATCH 1/6] tests/9p: add 'use-after-unlink' test Christian Schoenebeck
2024-11-25  8:47   ` Greg Kurz [this message]
2024-11-25  9:34     ` Christian Schoenebeck
2024-11-24 13:34 ` [PATCH 2/6] tests/9p: fix Rreaddir response name Christian Schoenebeck
2024-11-24 19:41   ` Christian Schoenebeck
2024-11-25  8:48   ` Greg Kurz
2024-11-24 14:49 ` [PATCH 3/6] tests/9p: add missing Rgetattr " Christian Schoenebeck
2024-11-24 19:42   ` Christian Schoenebeck
2024-11-25  8:51   ` Greg Kurz
2024-11-24 15:06 ` [PATCH 4/6] 9pfs: remove obsolete comment in v9fs_getattr() Christian Schoenebeck
2024-11-24 19:43   ` Christian Schoenebeck
2024-11-25  8:54   ` Greg Kurz
2024-11-24 15:50 ` [PATCH 5/6] 9pfs: fix 'Tgetattr' after unlink Christian Schoenebeck
2024-11-24 19:44   ` Christian Schoenebeck
2024-11-26 16:03   ` Christian Schoenebeck
2024-11-26 16:58     ` Greg Kurz
2024-11-24 16:05 ` [PATCH 6/6] tests/9p: also check 'Tgetattr' in 'use-after-unlink' test Christian Schoenebeck
2024-11-26 17:02   ` Greg Kurz
2024-11-25  8:45 ` [PATCH 0/6] 9pfs: fix fstat() after unlink() (with a Linux guest) Greg Kurz
2024-11-25  9:05   ` Greg Kurz
2024-11-25 10:23   ` Christian Schoenebeck
2024-11-25 11:35     ` Greg Kurz
2024-11-25 14:11       ` Christian Schoenebeck
2024-11-27  9:58 ` Christian Schoenebeck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241125094717.50e0344b@bahia \
    --to=groug@kaod.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-stable@nongnu.org \
    --cc=qemu_oss@crudebyte.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.