From: Christian Schoenebeck <qemu_oss@crudebyte.com>
To: qemu-devel@nongnu.org
Cc: Greg Kurz <groug@kaod.org>
Subject: Re: [PATCH v3 05/11] tests/virtio-9p: added readdir test
Date: Fri, 17 Jan 2020 17:44:33 +0100 [thread overview]
Message-ID: <3128954.or4cCn8GAH@silver> (raw)
In-Reply-To: <20200117165129.064fbb30@bahia.lan>
On Freitag, 17. Januar 2020 16:51:29 CET Greg Kurz wrote:
> On Tue, 14 Jan 2020 00:08:51 +0100
>
> Christian Schoenebeck <qemu_oss@crudebyte.com> wrote:
> > The first readdir test simply checks the amount of directory
> > entries returned by 9pfs server, according to the created amount
> > of virtual files on 9pfs synth driver side. Then the subsequent
> > readdir test also checks whether all directory entries have the
> > expected file names (as created on 9pfs synth driver side),
> > ignoring their precise order in result list though.
> >
> > Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
> > ---
>
> LGTM but I'm afraid this needs rebasing because virtio-9p-test.c got moved
> to tests/qtest/ by this commit (merged earlier this week):
>
> commit 1e8a1fae7464ef79c9e50aa0f807d2c511be3c8e
> Author: Thomas Huth <thuth@redhat.com>
> Date: Mon Sep 9 12:04:01 2019 +0200
>
> test: Move qtests to a separate directory
>
> The tests directory itself is pretty overcrowded, and it's hard to
> see which test belongs to which test subsystem (unit, qtest, ...).
> Let's move the qtests to a separate folder for more clarity.
>
> Message-Id: <20191218103059.11729-6-thuth@redhat.com>
> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
> Signed-off-by: Thomas Huth <thuth@redhat.com>
Sure, I'll take care of that, and like previously discussed ...
> > tests/virtio-9p-test.c | 149 +++++++++++++++++++++++++++++++++++++++++
> > 1 file changed, 149 insertions(+)
> >
> > diff --git a/tests/virtio-9p-test.c b/tests/virtio-9p-test.c
> > index 06263edb53..721f13c1fb 100644
> > --- a/tests/virtio-9p-test.c
> > +++ b/tests/virtio-9p-test.c
> > @@ -68,6 +68,11 @@ static void v9fs_memread(P9Req *req, void *addr, size_t
> > len)>
> > req->r_off += len;
> >
> > }
> >
> > +static void v9fs_uint8_read(P9Req *req, uint8_t *val)
> > +{
> > + v9fs_memread(req, val, 1);
> > +}
> > +
> >
> > static void v9fs_uint16_write(P9Req *req, uint16_t val)
> > {
> >
> > uint16_t le_val = cpu_to_le16(val);
> >
> > @@ -101,6 +106,12 @@ static void v9fs_uint32_read(P9Req *req, uint32_t
> > *val)>
> > le32_to_cpus(val);
> >
> > }
> >
> > +static void v9fs_uint64_read(P9Req *req, uint64_t *val)
> > +{
> > + v9fs_memread(req, val, 8);
> > + le64_to_cpus(val);
> > +}
> > +
> >
> > /* len[2] string[len] */
> > static uint16_t v9fs_string_size(const char *string)
> > {
> >
> > @@ -191,6 +202,7 @@ static const char *rmessage_name(uint8_t id)
> >
> > id == P9_RLOPEN ? "RLOPEN" :
> > id == P9_RWRITE ? "RWRITE" :
> >
> > id == P9_RFLUSH ? "RFLUSH" :
> > + id == P9_RREADDIR ? "READDIR" :
> > "<unknown>";
> >
> > }
> >
> > @@ -348,6 +360,82 @@ static void v9fs_rwalk(P9Req *req, uint16_t *nwqid,
> > v9fs_qid **wqid)>
> > 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)
> > +{
> > + P9Req *req;
> > +
> > + req = v9fs_req_init(v9p, 4 + 8 + 4, P9_TREADDIR, tag);
> > + v9fs_uint32_write(req, fid);
> > + v9fs_uint64_write(req, offset);
> > + v9fs_uint32_write(req, count);
> > + v9fs_req_send(req);
> > + return req;
> > +}
> > +
> > +struct V9fsDirent {
> > + v9fs_qid qid;
> > + uint64_t offset;
> > + uint8_t type;
> > + char *name;
> > + struct V9fsDirent *next;
> > +};
> > +
> > +/* size[4] Rreaddir tag[2] count[4] data[count] */
> > +static void v9fs_rreaddir(P9Req *req, uint32_t *count, uint32_t
> > *nentries,
> > + struct V9fsDirent **entries)
> > +{
> > + uint32_t local_count;
> > + struct V9fsDirent *e = NULL;
> > + uint16_t slen;
> > + uint32_t n = 0;
> > +
> > + v9fs_req_recv(req, P9_RREADDIR);
> > + v9fs_uint32_read(req, &local_count);
> > +
> > + if (count) {
> > + *count = local_count;
> > + }
> > +
> > + for (int32_t togo = (int32_t)local_count;
> > + togo >= 13 + 8 + 1 + 2;
> > + togo -= 13 + 8 + 1 + 2 + slen, ++n)
> > + {
> > + if (!e) {
> > + e = g_malloc(sizeof(struct V9fsDirent));
> > + if (entries) {
> > + *entries = e;
> > + }
> > + } else {
> > + e = e->next = g_malloc(sizeof(struct V9fsDirent));
> > + }
> > + e->next = NULL;
> > + /* qid[13] offset[8] type[1] name[s] */
> > + v9fs_memread(req, &e->qid, 13);
> > + v9fs_uint64_read(req, &e->offset);
> > + v9fs_uint8_read(req, &e->type);
> > + v9fs_string_read(req, &slen, &e->name);
> > + }
> > +
> > + if (nentries) {
> > + *nentries = n;
> > + }
> > +
> > + v9fs_req_free(req);
> > +}
> > +
> > +static void v9fs_free_dirents(struct V9fsDirent *e)
> > +{
> > + struct V9fsDirent *next = NULL;
> > +
> > + for (; e; e = next) {
> > + next = e->next;
> > + g_free(e->name);
> > + g_free(e);
> > + }
> > +}
> > +
> >
> > /* size[4] Tlopen tag[2] fid[4] flags[4] */
> > static P9Req *v9fs_tlopen(QVirtio9P *v9p, uint32_t fid, uint32_t flags,
> >
> > uint16_t tag)
> >
> > @@ -480,6 +568,66 @@ static void fs_walk(void *obj, void *data,
> > QGuestAllocator *t_alloc)>
> > g_free(wqid);
> >
> > }
> >
> > +static bool fs_dirents_contain_name(struct V9fsDirent *e, const char*
> > name) +{
> > + for (; e; e = e->next) {
> > + if (!strcmp(e->name, name)) {
> > + return true;
> > + }
> > + }
> > + return false;
> > +}
> > +
> > +static void fs_readdir(void *obj, void *data, QGuestAllocator *t_alloc)
> > +{
> > + QVirtio9P *v9p = obj;
> > + alloc = t_alloc;
> > + char *const wnames[] = { g_strdup(QTEST_V9FS_SYNTH_READDIR_DIR) };
> > + uint16_t nqid;
> > + v9fs_qid qid;
> > + uint32_t count, nentries;
> > + struct V9fsDirent *entries = NULL;
> > + P9Req *req;
> > +
> > + fs_attach(v9p, NULL, t_alloc);
> > + req = v9fs_twalk(v9p, 0, 1, 1, wnames, 0);
> > + v9fs_req_wait_for_reply(req, NULL);
> > + v9fs_rwalk(req, &nqid, NULL);
> > + g_assert_cmpint(nqid, ==, 1);
> > +
> > + req = v9fs_tlopen(v9p, 1, O_DIRECTORY, 0);
> > + v9fs_req_wait_for_reply(req, NULL);
> > + v9fs_rlopen(req, &qid, NULL);
> > +
> > + req = v9fs_treaddir(v9p, 1, 0, P9_MAX_SIZE - P9_IOHDRSZ, 0);
... I'll have to change that to:
req = v9fs_treaddir(v9p, 1, 0, P9_MAX_SIZE - 11, 0);
> > + v9fs_req_wait_for_reply(req, NULL);
> > + v9fs_rreaddir(req, &count, &nentries, &entries);
> > +
> > + /*
> > + * Assuming msize (P9_MAX_SIZE) is large enough so we can retrieve
> > all
> > + * dir entries with only one readdir request.
> > + */
> > + g_assert_cmpint(
> > + nentries, ==,
> > + QTEST_V9FS_SYNTH_READDIR_NFILES + 2 /* "." and ".." */
> > + );
> > +
> > + /*
> > + * Check all file names exist in returned entries, ignore their order
> > + * though.
> > + */
> > + g_assert_cmpint(fs_dirents_contain_name(entries, "."), ==, true);
> > + g_assert_cmpint(fs_dirents_contain_name(entries, ".."), ==, true);
> > + for (int i = 0; i < QTEST_V9FS_SYNTH_READDIR_NFILES; ++i) {
> > + char *name = g_strdup_printf(QTEST_V9FS_SYNTH_READDIR_FILE, i);
> > + g_assert_cmpint(fs_dirents_contain_name(entries, name), ==,
> > true);
> > + g_free(name);
> > + }
> > +
> > + v9fs_free_dirents(entries);
> > + g_free(wnames[0]);
> > +}
> > +
> >
> > static void fs_walk_no_slash(void *obj, void *data, QGuestAllocator
> > *t_alloc) {
> >
> > QVirtio9P *v9p = obj;
> >
> > @@ -658,6 +806,7 @@ static void register_virtio_9p_test(void)
> >
> > NULL);
> >
> > qos_add_test("fs/flush/ignored", "virtio-9p", fs_flush_ignored,
> >
> > NULL);
> >
> > + qos_add_test("fs/readdir/basic", "virtio-9p", fs_readdir, NULL);
> >
> > }
> >
> > libqos_init(register_virtio_9p_test);
Best regards,
Christian Schoenebeck
next prev parent reply other threads:[~2020-01-17 16:45 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-13 23:18 [PATCH v3 00/11] 9pfs: readdir optimization Christian Schoenebeck
2020-01-13 22:20 ` [PATCH v3 01/11] tests/virtio-9p: add terminating null in v9fs_string_read() Christian Schoenebeck
2020-01-13 22:21 ` [PATCH v3 02/11] 9pfs: require msize >= 4096 Christian Schoenebeck
2020-01-16 13:15 ` Greg Kurz
2020-01-16 16:16 ` Christian Schoenebeck
2020-01-16 18:07 ` Greg Kurz
2020-01-16 21:39 ` Christian Schoenebeck
2020-01-17 10:24 ` Greg Kurz
2020-01-17 12:01 ` Christian Schoenebeck
2020-01-17 15:15 ` Greg Kurz
2020-01-17 16:41 ` Christian Schoenebeck
2020-01-13 22:22 ` [PATCH v3 03/11] 9pfs: validate count sent by client with T_readdir Christian Schoenebeck
2020-01-16 13:33 ` Greg Kurz
2020-01-16 16:51 ` Christian Schoenebeck
2020-01-17 15:50 ` Greg Kurz
2020-01-13 22:23 ` [PATCH v3 04/11] hw/9pfs/9p-synth: added directory for readdir test Christian Schoenebeck
2020-01-13 23:08 ` [PATCH v3 05/11] tests/virtio-9p: added " Christian Schoenebeck
2020-01-17 15:51 ` Greg Kurz
2020-01-17 16:44 ` Christian Schoenebeck [this message]
2020-01-13 23:11 ` [PATCH v3 06/11] tests/virtio-9p: added splitted " Christian Schoenebeck
2020-01-13 23:13 ` [PATCH v3 07/11] tests/virtio-9p: failing " Christian Schoenebeck
2020-01-13 23:16 ` [PATCH v3 08/11] 9pfs: readdir benchmark Christian Schoenebeck
2020-01-13 23:16 ` [PATCH v3 09/11] hw/9pfs/9p-synth: avoid n-square issue in synth_readdir() Christian Schoenebeck
2020-01-13 23:17 ` [PATCH v3 10/11] 9pfs: T_readdir latency optimization Christian Schoenebeck
2020-01-13 23:17 ` [PATCH v3 11/11] hw/9pfs/9p.c: benchmark time on T_readdir request 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=3128954.or4cCn8GAH@silver \
--to=qemu_oss@crudebyte.com \
--cc=groug@kaod.org \
--cc=qemu-devel@nongnu.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).