* [PATCH 0/5] tests/9pfs: Code refactoring @ 2020-10-20 15:10 Greg Kurz 2020-10-20 15:11 ` [PATCH 1/5] tests/9pfs: Factor out do_fs_version() helper Greg Kurz ` (4 more replies) 0 siblings, 5 replies; 9+ messages in thread From: Greg Kurz @ 2020-10-20 15:10 UTC (permalink / raw) To: Christian Schoenebeck; +Cc: qemu-devel, Greg Kurz Some code refactoring to have a clear distinction between top level test functions and helper functions. --- Greg Kurz (5): tests/9pfs: Factor out do_fs_version() helper tests/9pfs: Turn fs_readdir_split() into a helper tests/9pfs: Set alloc in fs_create_dir() tests/9pfs: Factor out do_fs_attach() helper tests/9pfs: Turn fs_mkdir() into a helper tests/qtest/virtio-9p-test.c | 62 +++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 28 deletions(-) -- Greg ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 1/5] tests/9pfs: Factor out do_fs_version() helper 2020-10-20 15:10 [PATCH 0/5] tests/9pfs: Code refactoring Greg Kurz @ 2020-10-20 15:11 ` Greg Kurz 2020-10-20 15:34 ` Christian Schoenebeck 2020-10-20 15:11 ` [PATCH 2/5] tests/9pfs: Turn fs_readdir_split() into a helper Greg Kurz ` (3 subsequent siblings) 4 siblings, 1 reply; 9+ messages in thread From: Greg Kurz @ 2020-10-20 15:11 UTC (permalink / raw) To: Christian Schoenebeck; +Cc: qemu-devel, Greg Kurz fs_version() is a top level test function. Factor out the sugar to a separate helper instead of hijacking it in other tests. Signed-off-by: Greg Kurz <groug@kaod.org> --- tests/qtest/virtio-9p-test.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c index c15908f27b3d..63f91aaf77e6 100644 --- a/tests/qtest/virtio-9p-test.c +++ b/tests/qtest/virtio-9p-test.c @@ -567,10 +567,8 @@ static void v9fs_rflush(P9Req *req) v9fs_req_free(req); } -static void fs_version(void *obj, void *data, QGuestAllocator *t_alloc) +static void do_fs_version(QVirtio9P *v9p) { - QVirtio9P *v9p = obj; - alloc = t_alloc; const char *version = "9P2000.L"; uint16_t server_len; char *server_version; @@ -585,13 +583,19 @@ static void fs_version(void *obj, void *data, QGuestAllocator *t_alloc) g_free(server_version); } +static void fs_version(void *obj, void *data, QGuestAllocator *t_alloc) +{ + alloc = t_alloc; + do_fs_version(obj); +} + static void fs_attach(void *obj, void *data, QGuestAllocator *t_alloc) { QVirtio9P *v9p = obj; alloc = t_alloc; P9Req *req; - fs_version(v9p, NULL, t_alloc); + do_fs_version(v9p); req = v9fs_tattach(v9p, 0, getuid(), 0); v9fs_req_wait_for_reply(req, NULL); v9fs_rattach(req, NULL); @@ -831,7 +835,7 @@ static void fs_walk_dotdot(void *obj, void *data, QGuestAllocator *t_alloc) v9fs_qid root_qid, *wqid; P9Req *req; - fs_version(v9p, NULL, t_alloc); + do_fs_version(v9p); req = v9fs_tattach(v9p, 0, getuid(), 0); v9fs_req_wait_for_reply(req, NULL); v9fs_rattach(req, &root_qid); ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 1/5] tests/9pfs: Factor out do_fs_version() helper 2020-10-20 15:11 ` [PATCH 1/5] tests/9pfs: Factor out do_fs_version() helper Greg Kurz @ 2020-10-20 15:34 ` Christian Schoenebeck 2020-10-20 15:41 ` Greg Kurz 0 siblings, 1 reply; 9+ messages in thread From: Christian Schoenebeck @ 2020-10-20 15:34 UTC (permalink / raw) To: Greg Kurz; +Cc: qemu-devel On Dienstag, 20. Oktober 2020 17:11:05 CEST Greg Kurz wrote: > fs_version() is a top level test function. Factor out the sugar > to a separate helper instead of hijacking it in other tests. > > Signed-off-by: Greg Kurz <groug@kaod.org> > --- > tests/qtest/virtio-9p-test.c | 14 +++++++++----- > 1 file changed, 9 insertions(+), 5 deletions(-) > > diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c > index c15908f27b3d..63f91aaf77e6 100644 > --- a/tests/qtest/virtio-9p-test.c > +++ b/tests/qtest/virtio-9p-test.c > @@ -567,10 +567,8 @@ static void v9fs_rflush(P9Req *req) > v9fs_req_free(req); > } > > -static void fs_version(void *obj, void *data, QGuestAllocator *t_alloc) > +static void do_fs_version(QVirtio9P *v9p) > { > - QVirtio9P *v9p = obj; > - alloc = t_alloc; > const char *version = "9P2000.L"; > uint16_t server_len; > char *server_version; > @@ -585,13 +583,19 @@ static void fs_version(void *obj, void *data, > QGuestAllocator *t_alloc) g_free(server_version); > } So the naming convention from now on shall be do_fs_*() for non-toplevel functions there. Not that I care too much about the precise prefix, but how about just do_*() for them instead? Except of that, your patches look fine to me. Best regards, Christian Schoenebeck ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/5] tests/9pfs: Factor out do_fs_version() helper 2020-10-20 15:34 ` Christian Schoenebeck @ 2020-10-20 15:41 ` Greg Kurz 2020-10-20 15:50 ` Christian Schoenebeck 0 siblings, 1 reply; 9+ messages in thread From: Greg Kurz @ 2020-10-20 15:41 UTC (permalink / raw) To: Christian Schoenebeck; +Cc: qemu-devel On Tue, 20 Oct 2020 17:34:05 +0200 Christian Schoenebeck <qemu_oss@crudebyte.com> wrote: > On Dienstag, 20. Oktober 2020 17:11:05 CEST Greg Kurz wrote: > > fs_version() is a top level test function. Factor out the sugar > > to a separate helper instead of hijacking it in other tests. > > > > Signed-off-by: Greg Kurz <groug@kaod.org> > > --- > > tests/qtest/virtio-9p-test.c | 14 +++++++++----- > > 1 file changed, 9 insertions(+), 5 deletions(-) > > > > diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c > > index c15908f27b3d..63f91aaf77e6 100644 > > --- a/tests/qtest/virtio-9p-test.c > > +++ b/tests/qtest/virtio-9p-test.c > > @@ -567,10 +567,8 @@ static void v9fs_rflush(P9Req *req) > > v9fs_req_free(req); > > } > > > > -static void fs_version(void *obj, void *data, QGuestAllocator *t_alloc) > > +static void do_fs_version(QVirtio9P *v9p) > > { > > - QVirtio9P *v9p = obj; > > - alloc = t_alloc; > > const char *version = "9P2000.L"; > > uint16_t server_len; > > char *server_version; > > @@ -585,13 +583,19 @@ static void fs_version(void *obj, void *data, > > QGuestAllocator *t_alloc) g_free(server_version); > > } > > So the naming convention from now on shall be do_fs_*() for non-toplevel > functions there. Not that I care too much about the precise prefix, but how > about just do_*() for them instead? > I've prepended "do_" to the existing names by pure laziness but I'm fine with any prefix or naming convention actually. So just tell me what you prefer and I'll send a v2. > Except of that, your patches look fine to me. > > Best regards, > Christian Schoenebeck > > ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/5] tests/9pfs: Factor out do_fs_version() helper 2020-10-20 15:41 ` Greg Kurz @ 2020-10-20 15:50 ` Christian Schoenebeck 0 siblings, 0 replies; 9+ messages in thread From: Christian Schoenebeck @ 2020-10-20 15:50 UTC (permalink / raw) To: qemu-devel; +Cc: Greg Kurz On Dienstag, 20. Oktober 2020 17:41:56 CEST Greg Kurz wrote: > On Tue, 20 Oct 2020 17:34:05 +0200 > > Christian Schoenebeck <qemu_oss@crudebyte.com> wrote: > > On Dienstag, 20. Oktober 2020 17:11:05 CEST Greg Kurz wrote: > > > fs_version() is a top level test function. Factor out the sugar > > > to a separate helper instead of hijacking it in other tests. > > > > > > Signed-off-by: Greg Kurz <groug@kaod.org> > > > --- > > > > > > tests/qtest/virtio-9p-test.c | 14 +++++++++----- > > > 1 file changed, 9 insertions(+), 5 deletions(-) > > > > > > diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c > > > index c15908f27b3d..63f91aaf77e6 100644 > > > --- a/tests/qtest/virtio-9p-test.c > > > +++ b/tests/qtest/virtio-9p-test.c > > > @@ -567,10 +567,8 @@ static void v9fs_rflush(P9Req *req) > > > > > > v9fs_req_free(req); > > > > > > } > > > > > > -static void fs_version(void *obj, void *data, QGuestAllocator *t_alloc) > > > +static void do_fs_version(QVirtio9P *v9p) > > > > > > { > > > > > > - QVirtio9P *v9p = obj; > > > - alloc = t_alloc; > > > > > > const char *version = "9P2000.L"; > > > uint16_t server_len; > > > char *server_version; > > > > > > @@ -585,13 +583,19 @@ static void fs_version(void *obj, void *data, > > > QGuestAllocator *t_alloc) g_free(server_version); > > > > > > } > > > > So the naming convention from now on shall be do_fs_*() for non-toplevel > > functions there. Not that I care too much about the precise prefix, but > > how > > about just do_*() for them instead? > > I've prepended "do_" to the existing names by pure laziness but I'm > fine with any prefix or naming convention actually. > > So just tell me what you prefer and I'll send a v2. It's really just more pleasant for the eye to have the prefix a bit shorter. So use do_*() or any other kind of xx_*() or xxx_*() prefix that comes to your mind. It will be fine with me. Thanks Greg! Best regards, Christian Schoenebeck ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 2/5] tests/9pfs: Turn fs_readdir_split() into a helper 2020-10-20 15:10 [PATCH 0/5] tests/9pfs: Code refactoring Greg Kurz 2020-10-20 15:11 ` [PATCH 1/5] tests/9pfs: Factor out do_fs_version() helper Greg Kurz @ 2020-10-20 15:11 ` Greg Kurz 2020-10-20 15:11 ` [PATCH 3/5] tests/9pfs: Set alloc in fs_create_dir() Greg Kurz ` (2 subsequent siblings) 4 siblings, 0 replies; 9+ messages in thread From: Greg Kurz @ 2020-10-20 15:11 UTC (permalink / raw) To: Christian Schoenebeck; +Cc: qemu-devel, Greg Kurz fs_readdir_split() isn't a top level test function and thus shouldn't take the "void *obj, void *data, QGuestAllocator *t_alloc" arguments. Turn it into a helper to be used by test functions. Signed-off-by: Greg Kurz <groug@kaod.org> --- tests/qtest/virtio-9p-test.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c index 63f91aaf77e6..d0cdc14fee3e 100644 --- a/tests/qtest/virtio-9p-test.c +++ b/tests/qtest/virtio-9p-test.c @@ -727,11 +727,8 @@ static void fs_readdir(void *obj, void *data, QGuestAllocator *t_alloc) } /* readdir test where overall request is split over several messages */ -static void fs_readdir_split(void *obj, void *data, QGuestAllocator *t_alloc, - uint32_t count) +static void do_fs_readdir_split(QVirtio9P *v9p, uint32_t count) { - QVirtio9P *v9p = obj; - alloc = t_alloc; char *const wnames[] = { g_strdup(QTEST_V9FS_SYNTH_READDIR_DIR) }; uint16_t nqid; v9fs_qid qid; @@ -998,19 +995,22 @@ static void fs_mkdir(void *obj, void *data, QGuestAllocator *t_alloc, static void fs_readdir_split_128(void *obj, void *data, QGuestAllocator *t_alloc) { - fs_readdir_split(obj, data, t_alloc, 128); + alloc = t_alloc; + do_fs_readdir_split(obj, 128); } static void fs_readdir_split_256(void *obj, void *data, QGuestAllocator *t_alloc) { - fs_readdir_split(obj, data, t_alloc, 256); + alloc = t_alloc; + do_fs_readdir_split(obj, 256); } static void fs_readdir_split_512(void *obj, void *data, QGuestAllocator *t_alloc) { - fs_readdir_split(obj, data, t_alloc, 512); + alloc = t_alloc; + do_fs_readdir_split(obj, 512); } ^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 3/5] tests/9pfs: Set alloc in fs_create_dir() 2020-10-20 15:10 [PATCH 0/5] tests/9pfs: Code refactoring Greg Kurz 2020-10-20 15:11 ` [PATCH 1/5] tests/9pfs: Factor out do_fs_version() helper Greg Kurz 2020-10-20 15:11 ` [PATCH 2/5] tests/9pfs: Turn fs_readdir_split() into a helper Greg Kurz @ 2020-10-20 15:11 ` Greg Kurz 2020-10-20 15:11 ` [PATCH 4/5] tests/9pfs: Factor out do_fs_attach() helper Greg Kurz 2020-10-20 15:11 ` [PATCH 5/5] tests/9pfs: Turn fs_mkdir() into a helper Greg Kurz 4 siblings, 0 replies; 9+ messages in thread From: Greg Kurz @ 2020-10-20 15:11 UTC (permalink / raw) To: Christian Schoenebeck; +Cc: qemu-devel, Greg Kurz fs_create_dir() is a top level test function. It should set alloc. Signed-off-by: Greg Kurz <groug@kaod.org> --- tests/qtest/virtio-9p-test.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c index d0cdc14fee3e..95638662e14d 100644 --- a/tests/qtest/virtio-9p-test.c +++ b/tests/qtest/virtio-9p-test.c @@ -1019,6 +1019,7 @@ static void fs_readdir_split_512(void *obj, void *data, static void fs_create_dir(void *obj, void *data, QGuestAllocator *t_alloc) { QVirtio9P *v9p = obj; + alloc = t_alloc; struct stat st; char *root_path = virtio_9p_test_path(""); char *new_dir = virtio_9p_test_path("01"); ^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 4/5] tests/9pfs: Factor out do_fs_attach() helper 2020-10-20 15:10 [PATCH 0/5] tests/9pfs: Code refactoring Greg Kurz ` (2 preceding siblings ...) 2020-10-20 15:11 ` [PATCH 3/5] tests/9pfs: Set alloc in fs_create_dir() Greg Kurz @ 2020-10-20 15:11 ` Greg Kurz 2020-10-20 15:11 ` [PATCH 5/5] tests/9pfs: Turn fs_mkdir() into a helper Greg Kurz 4 siblings, 0 replies; 9+ messages in thread From: Greg Kurz @ 2020-10-20 15:11 UTC (permalink / raw) To: Christian Schoenebeck; +Cc: qemu-devel, Greg Kurz fs_attach() is a top level test function. Factor out the sugar to a separate helper instead of hijacking it in other tests. Signed-off-by: Greg Kurz <groug@kaod.org> --- tests/qtest/virtio-9p-test.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c index 95638662e14d..1e1b1433014b 100644 --- a/tests/qtest/virtio-9p-test.c +++ b/tests/qtest/virtio-9p-test.c @@ -589,10 +589,8 @@ static void fs_version(void *obj, void *data, QGuestAllocator *t_alloc) do_fs_version(obj); } -static void fs_attach(void *obj, void *data, QGuestAllocator *t_alloc) +static void do_fs_attach(QVirtio9P *v9p) { - QVirtio9P *v9p = obj; - alloc = t_alloc; P9Req *req; do_fs_version(v9p); @@ -601,6 +599,12 @@ static void fs_attach(void *obj, void *data, QGuestAllocator *t_alloc) v9fs_rattach(req, NULL); } +static void fs_attach(void *obj, void *data, QGuestAllocator *t_alloc) +{ + alloc = t_alloc; + do_fs_attach(obj); +} + static void fs_walk(void *obj, void *data, QGuestAllocator *t_alloc) { QVirtio9P *v9p = obj; @@ -615,7 +619,7 @@ static void fs_walk(void *obj, void *data, QGuestAllocator *t_alloc) wnames[i] = g_strdup_printf(QTEST_V9FS_SYNTH_WALK_FILE, i); } - fs_attach(v9p, NULL, t_alloc); + do_fs_attach(v9p); req = v9fs_twalk(v9p, 0, 1, P9_MAXWELEM, wnames, 0); v9fs_req_wait_for_reply(req, NULL); v9fs_rwalk(req, &nwqid, &wqid); @@ -684,7 +688,7 @@ static void fs_readdir(void *obj, void *data, QGuestAllocator *t_alloc) struct V9fsDirent *entries = NULL; P9Req *req; - fs_attach(v9p, NULL, t_alloc); + do_fs_attach(v9p); req = v9fs_twalk(v9p, 0, 1, 1, wnames, 0); v9fs_req_wait_for_reply(req, NULL); v9fs_rwalk(req, &nqid, NULL); @@ -738,7 +742,7 @@ static void do_fs_readdir_split(QVirtio9P *v9p, uint32_t count) int fid; uint64_t offset; - fs_attach(v9p, NULL, t_alloc); + do_fs_attach(v9p); fid = 1; offset = 0; @@ -814,7 +818,7 @@ static void fs_walk_no_slash(void *obj, void *data, QGuestAllocator *t_alloc) P9Req *req; uint32_t err; - fs_attach(v9p, NULL, t_alloc); + do_fs_attach(v9p); req = v9fs_twalk(v9p, 0, 1, 1, wnames, 0); v9fs_req_wait_for_reply(req, NULL); v9fs_rlerror(req, &err); @@ -854,7 +858,7 @@ static void fs_lopen(void *obj, void *data, QGuestAllocator *t_alloc) char *const wnames[] = { g_strdup(QTEST_V9FS_SYNTH_LOPEN_FILE) }; P9Req *req; - fs_attach(v9p, NULL, t_alloc); + do_fs_attach(v9p); req = v9fs_twalk(v9p, 0, 1, 1, wnames, 0); v9fs_req_wait_for_reply(req, NULL); v9fs_rwalk(req, NULL, NULL); @@ -876,7 +880,7 @@ static void fs_write(void *obj, void *data, QGuestAllocator *t_alloc) uint32_t count; P9Req *req; - fs_attach(v9p, NULL, t_alloc); + do_fs_attach(v9p); req = v9fs_twalk(v9p, 0, 1, 1, wnames, 0); v9fs_req_wait_for_reply(req, NULL); v9fs_rwalk(req, NULL, NULL); @@ -903,7 +907,7 @@ static void fs_flush_success(void *obj, void *data, QGuestAllocator *t_alloc) uint32_t reply_len; uint8_t should_block; - fs_attach(v9p, NULL, t_alloc); + do_fs_attach(v9p); req = v9fs_twalk(v9p, 0, 1, 1, wnames, 0); v9fs_req_wait_for_reply(req, NULL); v9fs_rwalk(req, NULL, NULL); @@ -940,7 +944,7 @@ static void fs_flush_ignored(void *obj, void *data, QGuestAllocator *t_alloc) uint32_t count; uint8_t should_block; - fs_attach(v9p, NULL, t_alloc); + do_fs_attach(v9p); req = v9fs_twalk(v9p, 0, 1, 1, wnames, 0); v9fs_req_wait_for_reply(req, NULL); v9fs_rwalk(req, NULL, NULL); @@ -1026,7 +1030,7 @@ static void fs_create_dir(void *obj, void *data, QGuestAllocator *t_alloc) g_assert(root_path != NULL); - fs_attach(v9p, NULL, t_alloc); + do_fs_attach(v9p); fs_mkdir(v9p, data, t_alloc, "/", "01"); /* check if created directory really exists now ... */ ^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 5/5] tests/9pfs: Turn fs_mkdir() into a helper 2020-10-20 15:10 [PATCH 0/5] tests/9pfs: Code refactoring Greg Kurz ` (3 preceding siblings ...) 2020-10-20 15:11 ` [PATCH 4/5] tests/9pfs: Factor out do_fs_attach() helper Greg Kurz @ 2020-10-20 15:11 ` Greg Kurz 4 siblings, 0 replies; 9+ messages in thread From: Greg Kurz @ 2020-10-20 15:11 UTC (permalink / raw) To: Christian Schoenebeck; +Cc: qemu-devel, Greg Kurz fs_mkdir() isn't a top level test function and thus shouldn't take the "void *obj, void *data, QGuestAllocator *t_alloc" arguments. Turn it into a helper to be used by test functions. Signed-off-by: Greg Kurz <groug@kaod.org> --- tests/qtest/virtio-9p-test.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c index 1e1b1433014b..155d327fd9f5 100644 --- a/tests/qtest/virtio-9p-test.c +++ b/tests/qtest/virtio-9p-test.c @@ -972,11 +972,8 @@ static void fs_flush_ignored(void *obj, void *data, QGuestAllocator *t_alloc) g_free(wnames[0]); } -static void fs_mkdir(void *obj, void *data, QGuestAllocator *t_alloc, - const char *path, const char *cname) +static void do_fs_mkdir(QVirtio9P *v9p, const char *path, const char *cname) { - QVirtio9P *v9p = obj; - alloc = t_alloc; char **wnames; char *const name = g_strdup(cname); P9Req *req; @@ -1031,7 +1028,7 @@ static void fs_create_dir(void *obj, void *data, QGuestAllocator *t_alloc) g_assert(root_path != NULL); do_fs_attach(v9p); - fs_mkdir(v9p, data, t_alloc, "/", "01"); + do_fs_mkdir(v9p, "/", "01"); /* check if created directory really exists now ... */ g_assert(stat(new_dir, &st) == 0); ^ permalink raw reply related [flat|nested] 9+ messages in thread
end of thread, other threads:[~2020-10-20 15:51 UTC | newest] Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2020-10-20 15:10 [PATCH 0/5] tests/9pfs: Code refactoring Greg Kurz 2020-10-20 15:11 ` [PATCH 1/5] tests/9pfs: Factor out do_fs_version() helper Greg Kurz 2020-10-20 15:34 ` Christian Schoenebeck 2020-10-20 15:41 ` Greg Kurz 2020-10-20 15:50 ` Christian Schoenebeck 2020-10-20 15:11 ` [PATCH 2/5] tests/9pfs: Turn fs_readdir_split() into a helper Greg Kurz 2020-10-20 15:11 ` [PATCH 3/5] tests/9pfs: Set alloc in fs_create_dir() Greg Kurz 2020-10-20 15:11 ` [PATCH 4/5] tests/9pfs: Factor out do_fs_attach() helper Greg Kurz 2020-10-20 15:11 ` [PATCH 5/5] tests/9pfs: Turn fs_mkdir() into a helper Greg Kurz
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).