diff mbox series

[v4,3/7] tests/9pfs: compare QIDs in fs_walk_none() test

Message ID 5bbe9c6931b4600a9a23742f5ff2d38c1188237d.1647339025.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 15, 2022, 10:08 a.m. UTC
Extend previously added fs_walk_none() test by comparing the QID
of the root fid with the QID of the cloned fid. They should be
equal.

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

Comments

Greg Kurz June 15, 2022, 3:08 p.m. UTC | #1
On Tue, 15 Mar 2022 11:08:35 +0100
Christian Schoenebeck <qemu_oss@crudebyte.com> wrote:

> Extend previously added fs_walk_none() test by comparing the QID
> of the root fid with the QID of the cloned fid. They should be
> equal.
> 
> Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
> ---

LGTM.

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

>  tests/qtest/virtio-9p-test.c | 87 ++++++++++++++++++++++++++++++++++++
>  1 file changed, 87 insertions(+)
> 
> diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c
> index 6c00da03f4..a1160f4659 100644
> --- a/tests/qtest/virtio-9p-test.c
> +++ b/tests/qtest/virtio-9p-test.c
> @@ -371,8 +371,15 @@ static P9Req *v9fs_tattach(QVirtio9P *v9p, uint32_t fid, uint32_t n_uname,
>      return req;
>  }
>  
> +/* type[1] version[4] path[8] */
>  typedef char v9fs_qid[13];
>  
> +static inline bool is_same_qid(v9fs_qid a, v9fs_qid b)
> +{
> +    /* don't compare QID version for checking for file ID equalness */
> +    return a[0] == b[0] && memcmp(&a[5], &b[5], 8) == 0;
> +}
> +
>  /* size[4] Rattach tag[2] qid[13] */
>  static void v9fs_rattach(P9Req *req, v9fs_qid *qid)
>  {
> @@ -425,6 +432,79 @@ static void v9fs_rwalk(P9Req *req, uint16_t *nwqid, v9fs_qid **wqid)
>      v9fs_req_free(req);
>  }
>  
> +/* size[4] Tgetattr tag[2] fid[4] request_mask[8] */
> +static P9Req *v9fs_tgetattr(QVirtio9P *v9p, uint32_t fid, uint64_t request_mask,
> +                            uint16_t tag)
> +{
> +    P9Req *req;
> +
> +    req = v9fs_req_init(v9p, 4 + 8, P9_TGETATTR, tag);
> +    v9fs_uint32_write(req, fid);
> +    v9fs_uint64_write(req, request_mask);
> +    v9fs_req_send(req);
> +    return req;
> +}
> +
> +typedef struct v9fs_attr {
> +    uint64_t valid;
> +    v9fs_qid qid;
> +    uint32_t mode;
> +    uint32_t uid;
> +    uint32_t gid;
> +    uint64_t nlink;
> +    uint64_t rdev;
> +    uint64_t size;
> +    uint64_t blksize;
> +    uint64_t blocks;
> +    uint64_t atime_sec;
> +    uint64_t atime_nsec;
> +    uint64_t mtime_sec;
> +    uint64_t mtime_nsec;
> +    uint64_t ctime_sec;
> +    uint64_t ctime_nsec;
> +    uint64_t btime_sec;
> +    uint64_t btime_nsec;
> +    uint64_t gen;
> +    uint64_t data_version;
> +} v9fs_attr;
> +
> +#define P9_GETATTR_BASIC    0x000007ffULL /* Mask for fields up to BLOCKS */
> +
> +/*
> + * size[4] Rgetattr tag[2] valid[8] qid[13] mode[4] uid[4] gid[4] nlink[8]
> + *                  rdev[8] size[8] blksize[8] blocks[8]
> + *                  atime_sec[8] atime_nsec[8] mtime_sec[8] mtime_nsec[8]
> + *                  ctime_sec[8] ctime_nsec[8] btime_sec[8] btime_nsec[8]
> + *                  gen[8] data_version[8]
> + */
> +static void v9fs_rgetattr(P9Req *req, v9fs_attr *attr)
> +{
> +    v9fs_req_recv(req, P9_RGETATTR);
> +
> +    v9fs_uint64_read(req, &attr->valid);
> +    v9fs_memread(req, &attr->qid, 13);
> +    v9fs_uint32_read(req, &attr->mode);
> +    v9fs_uint32_read(req, &attr->uid);
> +    v9fs_uint32_read(req, &attr->gid);
> +    v9fs_uint64_read(req, &attr->nlink);
> +    v9fs_uint64_read(req, &attr->rdev);
> +    v9fs_uint64_read(req, &attr->size);
> +    v9fs_uint64_read(req, &attr->blksize);
> +    v9fs_uint64_read(req, &attr->blocks);
> +    v9fs_uint64_read(req, &attr->atime_sec);
> +    v9fs_uint64_read(req, &attr->atime_nsec);
> +    v9fs_uint64_read(req, &attr->mtime_sec);
> +    v9fs_uint64_read(req, &attr->mtime_nsec);
> +    v9fs_uint64_read(req, &attr->ctime_sec);
> +    v9fs_uint64_read(req, &attr->ctime_nsec);
> +    v9fs_uint64_read(req, &attr->btime_sec);
> +    v9fs_uint64_read(req, &attr->btime_nsec);
> +    v9fs_uint64_read(req, &attr->gen);
> +    v9fs_uint64_read(req, &attr->data_version);
> +
> +    v9fs_req_free(req);
> +}
> +
>  /* size[4] Treaddir tag[2] fid[4] offset[8] count[4] */
>  static P9Req *v9fs_treaddir(QVirtio9P *v9p, uint32_t fid, uint64_t offset,
>                              uint32_t count, uint16_t tag)
> @@ -1009,6 +1089,7 @@ static void fs_walk_none(void *obj, void *data, QGuestAllocator *t_alloc)
>      v9fs_qid root_qid;
>      g_autofree v9fs_qid *wqid = NULL;
>      P9Req *req;
> +    struct v9fs_attr attr;
>  
>      do_version(v9p);
>      req = v9fs_tattach(v9p, 0, getuid(), 0);
> @@ -1021,6 +1102,12 @@ static void fs_walk_none(void *obj, void *data, QGuestAllocator *t_alloc)
>  
>      /* special case: no QID is returned if nwname=0 was sent */
>      g_assert(wqid == NULL);
> +
> +    req = v9fs_tgetattr(v9p, 1, P9_GETATTR_BASIC, 0);
> +    v9fs_req_wait_for_reply(req, NULL);
> +    v9fs_rgetattr(req, &attr);
> +
> +    g_assert(is_same_qid(root_qid, attr.qid));
>  }
>  
>  static void fs_walk_dotdot(void *obj, void *data, QGuestAllocator *t_alloc)
diff mbox series

Patch

diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c
index 6c00da03f4..a1160f4659 100644
--- a/tests/qtest/virtio-9p-test.c
+++ b/tests/qtest/virtio-9p-test.c
@@ -371,8 +371,15 @@  static P9Req *v9fs_tattach(QVirtio9P *v9p, uint32_t fid, uint32_t n_uname,
     return req;
 }
 
+/* type[1] version[4] path[8] */
 typedef char v9fs_qid[13];
 
+static inline bool is_same_qid(v9fs_qid a, v9fs_qid b)
+{
+    /* don't compare QID version for checking for file ID equalness */
+    return a[0] == b[0] && memcmp(&a[5], &b[5], 8) == 0;
+}
+
 /* size[4] Rattach tag[2] qid[13] */
 static void v9fs_rattach(P9Req *req, v9fs_qid *qid)
 {
@@ -425,6 +432,79 @@  static void v9fs_rwalk(P9Req *req, uint16_t *nwqid, v9fs_qid **wqid)
     v9fs_req_free(req);
 }
 
+/* size[4] Tgetattr tag[2] fid[4] request_mask[8] */
+static P9Req *v9fs_tgetattr(QVirtio9P *v9p, uint32_t fid, uint64_t request_mask,
+                            uint16_t tag)
+{
+    P9Req *req;
+
+    req = v9fs_req_init(v9p, 4 + 8, P9_TGETATTR, tag);
+    v9fs_uint32_write(req, fid);
+    v9fs_uint64_write(req, request_mask);
+    v9fs_req_send(req);
+    return req;
+}
+
+typedef struct v9fs_attr {
+    uint64_t valid;
+    v9fs_qid qid;
+    uint32_t mode;
+    uint32_t uid;
+    uint32_t gid;
+    uint64_t nlink;
+    uint64_t rdev;
+    uint64_t size;
+    uint64_t blksize;
+    uint64_t blocks;
+    uint64_t atime_sec;
+    uint64_t atime_nsec;
+    uint64_t mtime_sec;
+    uint64_t mtime_nsec;
+    uint64_t ctime_sec;
+    uint64_t ctime_nsec;
+    uint64_t btime_sec;
+    uint64_t btime_nsec;
+    uint64_t gen;
+    uint64_t data_version;
+} v9fs_attr;
+
+#define P9_GETATTR_BASIC    0x000007ffULL /* Mask for fields up to BLOCKS */
+
+/*
+ * size[4] Rgetattr tag[2] valid[8] qid[13] mode[4] uid[4] gid[4] nlink[8]
+ *                  rdev[8] size[8] blksize[8] blocks[8]
+ *                  atime_sec[8] atime_nsec[8] mtime_sec[8] mtime_nsec[8]
+ *                  ctime_sec[8] ctime_nsec[8] btime_sec[8] btime_nsec[8]
+ *                  gen[8] data_version[8]
+ */
+static void v9fs_rgetattr(P9Req *req, v9fs_attr *attr)
+{
+    v9fs_req_recv(req, P9_RGETATTR);
+
+    v9fs_uint64_read(req, &attr->valid);
+    v9fs_memread(req, &attr->qid, 13);
+    v9fs_uint32_read(req, &attr->mode);
+    v9fs_uint32_read(req, &attr->uid);
+    v9fs_uint32_read(req, &attr->gid);
+    v9fs_uint64_read(req, &attr->nlink);
+    v9fs_uint64_read(req, &attr->rdev);
+    v9fs_uint64_read(req, &attr->size);
+    v9fs_uint64_read(req, &attr->blksize);
+    v9fs_uint64_read(req, &attr->blocks);
+    v9fs_uint64_read(req, &attr->atime_sec);
+    v9fs_uint64_read(req, &attr->atime_nsec);
+    v9fs_uint64_read(req, &attr->mtime_sec);
+    v9fs_uint64_read(req, &attr->mtime_nsec);
+    v9fs_uint64_read(req, &attr->ctime_sec);
+    v9fs_uint64_read(req, &attr->ctime_nsec);
+    v9fs_uint64_read(req, &attr->btime_sec);
+    v9fs_uint64_read(req, &attr->btime_nsec);
+    v9fs_uint64_read(req, &attr->gen);
+    v9fs_uint64_read(req, &attr->data_version);
+
+    v9fs_req_free(req);
+}
+
 /* size[4] Treaddir tag[2] fid[4] offset[8] count[4] */
 static P9Req *v9fs_treaddir(QVirtio9P *v9p, uint32_t fid, uint64_t offset,
                             uint32_t count, uint16_t tag)
@@ -1009,6 +1089,7 @@  static void fs_walk_none(void *obj, void *data, QGuestAllocator *t_alloc)
     v9fs_qid root_qid;
     g_autofree v9fs_qid *wqid = NULL;
     P9Req *req;
+    struct v9fs_attr attr;
 
     do_version(v9p);
     req = v9fs_tattach(v9p, 0, getuid(), 0);
@@ -1021,6 +1102,12 @@  static void fs_walk_none(void *obj, void *data, QGuestAllocator *t_alloc)
 
     /* special case: no QID is returned if nwname=0 was sent */
     g_assert(wqid == NULL);
+
+    req = v9fs_tgetattr(v9p, 1, P9_GETATTR_BASIC, 0);
+    v9fs_req_wait_for_reply(req, NULL);
+    v9fs_rgetattr(req, &attr);
+
+    g_assert(is_same_qid(root_qid, attr.qid));
 }
 
 static void fs_walk_dotdot(void *obj, void *data, QGuestAllocator *t_alloc)