diff mbox series

[6/6] tests/9pfs: guard recent 'Twalk' behaviour fix

Message ID 51e7f12fad3f36ce166e2f6e415784b13c4df5c4.1646850707.git.qemu_oss@crudebyte.com (mailing list archive)
State New, archived
Headers show
Series 9pfs: fix 'Twalk' protocol violation | expand

Commit Message

Christian Schoenebeck March 9, 2022, 6:21 p.m. UTC
Previous 9p patch fixed 'Twalk' request handling, which was previously not
behaving as specified by the 9p2000 protocol spec. This patch adds a new test
case which guards the new 'Twalk' behaviour in question.

More specifically: it sends a 'Twalk' request where the 1st path component
is valid, whereas the 2nd path component transmitted to server does not
exist. The expected behaviour is that 9p server would respond by sending
a 'Rwalk' response with exactly 1 QID (instead of 'Rlerror' response).

Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
---
 tests/qtest/virtio-9p-test.c | 42 +++++++++++++++++++++++++++++++++---
 1 file changed, 39 insertions(+), 3 deletions(-)

Comments

Christian Schoenebeck March 11, 2022, 10:32 a.m. UTC | #1
On Mittwoch, 9. März 2022 19:21:18 CET Christian Schoenebeck wrote:
> Previous 9p patch fixed 'Twalk' request handling, which was previously not
> behaving as specified by the 9p2000 protocol spec. This patch adds a new
> test case which guards the new 'Twalk' behaviour in question.
> 
> More specifically: it sends a 'Twalk' request where the 1st path component
> is valid, whereas the 2nd path component transmitted to server does not
> exist. The expected behaviour is that 9p server would respond by sending
> a 'Rwalk' response with exactly 1 QID (instead of 'Rlerror' response).
> 
> Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
> ---
>  tests/qtest/virtio-9p-test.c | 42 +++++++++++++++++++++++++++++++++---
>  1 file changed, 39 insertions(+), 3 deletions(-)
> 
> diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c
> index 9098e21173..f29de1ca64 100644
> --- a/tests/qtest/virtio-9p-test.c
> +++ b/tests/qtest/virtio-9p-test.c
> @@ -638,8 +638,12 @@ static void do_version(QVirtio9P *v9p)
>      g_assert_cmpmem(server_version, server_len, version, strlen(version));
>  }
> 
> -/* utility function: walk to requested dir and return fid for that dir */
> -static uint32_t do_walk(QVirtio9P *v9p, const char *path)
> +/*
> + * utility function: walk to requested dir and return fid for that dir and
> + * the QIDs of server response
> + */
> +static uint32_t do_walk_rqids(QVirtio9P *v9p, const char *path, uint16_t
> *nwqid, +                              v9fs_qid **wqid)
>  {
>      char **wnames;
>      P9Req *req;
> @@ -649,12 +653,18 @@ static uint32_t do_walk(QVirtio9P *v9p, const char
> *path)
> 
>      req = v9fs_twalk(v9p, 0, fid, nwnames, wnames, 0);
>      v9fs_req_wait_for_reply(req, NULL);
> -    v9fs_rwalk(req, NULL, NULL);
> +    v9fs_rwalk(req, nwqid, wqid);
> 
>      split_free(&wnames);
>      return fid;
>  }
> 
> +/* utility function: walk to requested dir and return fid for that dir */
> +static uint32_t do_walk(QVirtio9P *v9p, const char *path)
> +{
> +    return do_walk_rqids(v9p, path, NULL, NULL);
> +}
> +
>  /* utility function: walk to requested dir and expect passed error response
> */ static void do_walk_expect_error(QVirtio9P *v9p, const char *path,
> uint32_t err) {
> @@ -1048,9 +1058,33 @@ static void fs_walk_nonexistent(void *obj, void
> *data, QGuestAllocator *t_alloc) alloc = t_alloc;
> 
>      do_attach(v9p);
> +    /*
> +     * The 9p2000 protocol spec sais: "If the first element cannot be
> walked +     * for any reason, Rerror is returned."
> +     */
>      do_walk_expect_error(v9p, "non-existent", ENOENT);
>  }
> 
> +static void fs_walk_2nd_nonexistent(void *obj, void *data,
> +                                    QGuestAllocator *t_alloc)
> +{
> +    QVirtio9P *v9p = obj;
> +    alloc = t_alloc;
> +    uint16_t nwqid;
> +    g_autofree v9fs_qid *wqid = NULL;
> +    g_autofree char *path = g_strdup_printf(
> +        QTEST_V9FS_SYNTH_WALK_FILE "/non-existent", 0
> +    );
> +
> +    do_attach(v9p);
> +    do_walk_rqids(v9p, path, &nwqid, &wqid);
> +    /*
> +     * The 9p2000 protocol spec sais: "nwqid is therefore either nwname or
> the +     * index of the first elementwise walk that failed."
> +     */
> +    assert(nwqid == 1);
> +}

I should probably extend this test case with a separate 7th patch to check 
that fid was really unaffected by Twalk, by comparing the QID before vs. after 
the walk (similar to what patch 3 does).

> +
>  static void fs_walk_none(void *obj, void *data, QGuestAllocator *t_alloc)
>  {
>      QVirtio9P *v9p = obj;
> @@ -1531,6 +1565,8 @@ static void register_virtio_9p_test(void)
>                   fs_walk_dotdot,  &opts);
>      qos_add_test("synth/walk/non_existent", "virtio-9p",
> fs_walk_nonexistent, &opts);
> +    qos_add_test("synth/walk/2nd_non_existent", "virtio-9p",
> +                 fs_walk_2nd_nonexistent, &opts);
>      qos_add_test("synth/lopen/basic", "virtio-9p", fs_lopen,  &opts);
>      qos_add_test("synth/write/basic", "virtio-9p", fs_write,  &opts);
>      qos_add_test("synth/flush/success", "virtio-9p", fs_flush_success,
Greg Kurz March 11, 2022, 4:40 p.m. UTC | #2
On Wed, 9 Mar 2022 19:21:18 +0100
Christian Schoenebeck <qemu_oss@crudebyte.com> wrote:

> Previous 9p patch fixed 'Twalk' request handling, which was previously not
> behaving as specified by the 9p2000 protocol spec. This patch adds a new test
> case which guards the new 'Twalk' behaviour in question.
> 
> More specifically: it sends a 'Twalk' request where the 1st path component
> is valid, whereas the 2nd path component transmitted to server does not
> exist. The expected behaviour is that 9p server would respond by sending
> a 'Rwalk' response with exactly 1 QID (instead of 'Rlerror' response).
> 
> Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
> ---
>  tests/qtest/virtio-9p-test.c | 42 +++++++++++++++++++++++++++++++++---
>  1 file changed, 39 insertions(+), 3 deletions(-)
> 
> diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c
> index 9098e21173..f29de1ca64 100644
> --- a/tests/qtest/virtio-9p-test.c
> +++ b/tests/qtest/virtio-9p-test.c
> @@ -638,8 +638,12 @@ static void do_version(QVirtio9P *v9p)
>      g_assert_cmpmem(server_version, server_len, version, strlen(version));
>  }
>  
> -/* utility function: walk to requested dir and return fid for that dir */
> -static uint32_t do_walk(QVirtio9P *v9p, const char *path)
> +/*
> + * utility function: walk to requested dir and return fid for that dir and
> + * the QIDs of server response
> + */
> +static uint32_t do_walk_rqids(QVirtio9P *v9p, const char *path, uint16_t *nwqid,
> +                              v9fs_qid **wqid)
>  {
>      char **wnames;
>      P9Req *req;
> @@ -649,12 +653,18 @@ static uint32_t do_walk(QVirtio9P *v9p, const char *path)
>  
>      req = v9fs_twalk(v9p, 0, fid, nwnames, wnames, 0);
>      v9fs_req_wait_for_reply(req, NULL);
> -    v9fs_rwalk(req, NULL, NULL);
> +    v9fs_rwalk(req, nwqid, wqid);
>  
>      split_free(&wnames);
>      return fid;
>  }
>  
> +/* utility function: walk to requested dir and return fid for that dir */
> +static uint32_t do_walk(QVirtio9P *v9p, const char *path)
> +{
> +    return do_walk_rqids(v9p, path, NULL, NULL);
> +}
> +
>  /* utility function: walk to requested dir and expect passed error response */
>  static void do_walk_expect_error(QVirtio9P *v9p, const char *path, uint32_t err)
>  {
> @@ -1048,9 +1058,33 @@ static void fs_walk_nonexistent(void *obj, void *data, QGuestAllocator *t_alloc)
>      alloc = t_alloc;
>  
>      do_attach(v9p);
> +    /*
> +     * The 9p2000 protocol spec sais: "If the first element cannot be walked

s/sais/says/ and elsewhere

LGTM.

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

> +     * for any reason, Rerror is returned."
> +     */
>      do_walk_expect_error(v9p, "non-existent", ENOENT);
>  }
>  
> +static void fs_walk_2nd_nonexistent(void *obj, void *data,
> +                                    QGuestAllocator *t_alloc)
> +{
> +    QVirtio9P *v9p = obj;
> +    alloc = t_alloc;
> +    uint16_t nwqid;
> +    g_autofree v9fs_qid *wqid = NULL;
> +    g_autofree char *path = g_strdup_printf(
> +        QTEST_V9FS_SYNTH_WALK_FILE "/non-existent", 0
> +    );
> +
> +    do_attach(v9p);
> +    do_walk_rqids(v9p, path, &nwqid, &wqid);
> +    /*
> +     * The 9p2000 protocol spec sais: "nwqid is therefore either nwname or the
> +     * index of the first elementwise walk that failed."
> +     */
> +    assert(nwqid == 1);
> +}
> +
>  static void fs_walk_none(void *obj, void *data, QGuestAllocator *t_alloc)
>  {
>      QVirtio9P *v9p = obj;
> @@ -1531,6 +1565,8 @@ static void register_virtio_9p_test(void)
>                   fs_walk_dotdot,  &opts);
>      qos_add_test("synth/walk/non_existent", "virtio-9p", fs_walk_nonexistent,
>                    &opts);
> +    qos_add_test("synth/walk/2nd_non_existent", "virtio-9p",
> +                 fs_walk_2nd_nonexistent, &opts);
>      qos_add_test("synth/lopen/basic", "virtio-9p", fs_lopen,  &opts);
>      qos_add_test("synth/write/basic", "virtio-9p", fs_write,  &opts);
>      qos_add_test("synth/flush/success", "virtio-9p", fs_flush_success,
diff mbox series

Patch

diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c
index 9098e21173..f29de1ca64 100644
--- a/tests/qtest/virtio-9p-test.c
+++ b/tests/qtest/virtio-9p-test.c
@@ -638,8 +638,12 @@  static void do_version(QVirtio9P *v9p)
     g_assert_cmpmem(server_version, server_len, version, strlen(version));
 }
 
-/* utility function: walk to requested dir and return fid for that dir */
-static uint32_t do_walk(QVirtio9P *v9p, const char *path)
+/*
+ * utility function: walk to requested dir and return fid for that dir and
+ * the QIDs of server response
+ */
+static uint32_t do_walk_rqids(QVirtio9P *v9p, const char *path, uint16_t *nwqid,
+                              v9fs_qid **wqid)
 {
     char **wnames;
     P9Req *req;
@@ -649,12 +653,18 @@  static uint32_t do_walk(QVirtio9P *v9p, const char *path)
 
     req = v9fs_twalk(v9p, 0, fid, nwnames, wnames, 0);
     v9fs_req_wait_for_reply(req, NULL);
-    v9fs_rwalk(req, NULL, NULL);
+    v9fs_rwalk(req, nwqid, wqid);
 
     split_free(&wnames);
     return fid;
 }
 
+/* utility function: walk to requested dir and return fid for that dir */
+static uint32_t do_walk(QVirtio9P *v9p, const char *path)
+{
+    return do_walk_rqids(v9p, path, NULL, NULL);
+}
+
 /* utility function: walk to requested dir and expect passed error response */
 static void do_walk_expect_error(QVirtio9P *v9p, const char *path, uint32_t err)
 {
@@ -1048,9 +1058,33 @@  static void fs_walk_nonexistent(void *obj, void *data, QGuestAllocator *t_alloc)
     alloc = t_alloc;
 
     do_attach(v9p);
+    /*
+     * The 9p2000 protocol spec sais: "If the first element cannot be walked
+     * for any reason, Rerror is returned."
+     */
     do_walk_expect_error(v9p, "non-existent", ENOENT);
 }
 
+static void fs_walk_2nd_nonexistent(void *obj, void *data,
+                                    QGuestAllocator *t_alloc)
+{
+    QVirtio9P *v9p = obj;
+    alloc = t_alloc;
+    uint16_t nwqid;
+    g_autofree v9fs_qid *wqid = NULL;
+    g_autofree char *path = g_strdup_printf(
+        QTEST_V9FS_SYNTH_WALK_FILE "/non-existent", 0
+    );
+
+    do_attach(v9p);
+    do_walk_rqids(v9p, path, &nwqid, &wqid);
+    /*
+     * The 9p2000 protocol spec sais: "nwqid is therefore either nwname or the
+     * index of the first elementwise walk that failed."
+     */
+    assert(nwqid == 1);
+}
+
 static void fs_walk_none(void *obj, void *data, QGuestAllocator *t_alloc)
 {
     QVirtio9P *v9p = obj;
@@ -1531,6 +1565,8 @@  static void register_virtio_9p_test(void)
                  fs_walk_dotdot,  &opts);
     qos_add_test("synth/walk/non_existent", "virtio-9p", fs_walk_nonexistent,
                   &opts);
+    qos_add_test("synth/walk/2nd_non_existent", "virtio-9p",
+                 fs_walk_2nd_nonexistent, &opts);
     qos_add_test("synth/lopen/basic", "virtio-9p", fs_lopen,  &opts);
     qos_add_test("synth/write/basic", "virtio-9p", fs_write,  &opts);
     qos_add_test("synth/flush/success", "virtio-9p", fs_flush_success,