qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kurz <groug@kaod.org>
To: Christian Schoenebeck <qemu_oss@crudebyte.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [PATCH 2/3] 9pfs: Convert V9fsFidState::fid_list to QSIMPLEQ
Date: Tue, 19 Jan 2021 18:23:34 +0100	[thread overview]
Message-ID: <20210119182334.2d3381b5@bahia.lan> (raw)
In-Reply-To: <2181983.BdRbxLO5hT@silver>

On Tue, 19 Jan 2021 16:28:01 +0100
Christian Schoenebeck <qemu_oss@crudebyte.com> wrote:

> On Dienstag, 19. Januar 2021 15:34:07 CET Greg Kurz wrote:
> > On Tue, 19 Jan 2021 14:31:26 +0100
> > 
> > Christian Schoenebeck <qemu_oss@crudebyte.com> wrote:
> > > On Montag, 18. Januar 2021 15:22:59 CET Greg Kurz wrote:
> > > > The fid_list is currently open-coded. This doesn't seem to serve any
> > > > purpose that cannot be met with QEMU's generic lists. Let's go for a
> > > > QSIMPLEQ : this will allow to add new fids at the end of the list and
> > > > to improve the logic in v9fs_mark_fids_unreclaim().
> > > > 
> > > > Signed-off-by: Greg Kurz <groug@kaod.org>
> > > 
> > > In general LGTM hence:
> > > 
> > > Reviewed-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
> > > 
> > > Some comments below ...
> > > 
> > > > ---
> > > > 
> > > >  hw/9pfs/9p.c | 41 ++++++++++++++++++-----------------------
> > > >  hw/9pfs/9p.h |  4 ++--
> > > >  2 files changed, 20 insertions(+), 25 deletions(-)
> > > > 
> > > > diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
> > > > index 37c3379b7462..b65f320e6518 100644
> > > > --- a/hw/9pfs/9p.c
> > > > +++ b/hw/9pfs/9p.c
> > > > @@ -260,7 +260,7 @@ static V9fsFidState *coroutine_fn get_fid(V9fsPDU
> > > > *pdu,
> > > > int32_t fid) V9fsFidState *f;
> > > > 
> > > >      V9fsState *s = pdu->s;
> > > > 
> > > > -    for (f = s->fid_list; f; f = f->next) {
> > > > +    QSIMPLEQ_FOREACH(f, &s->fid_list, next) {
> > > > 
> > > >          BUG_ON(f->clunked);
> > > >          if (f->fid == fid) {
> > > >          
> > > >              /*
> > > > 
> > > > @@ -295,7 +295,7 @@ static V9fsFidState *alloc_fid(V9fsState *s, int32_t
> > > > fid) {
> > > > 
> > > >      V9fsFidState *f;
> > > > 
> > > > -    for (f = s->fid_list; f; f = f->next) {
> > > > +    QSIMPLEQ_FOREACH(f, &s->fid_list, next) {
> > > > 
> > > >          /* If fid is already there return NULL */
> > > >          BUG_ON(f->clunked);
> > > >          if (f->fid == fid) {
> > > > 
> > > > @@ -311,8 +311,7 @@ static V9fsFidState *alloc_fid(V9fsState *s, int32_t
> > > > fid) * reclaim won't close the file descriptor
> > > > 
> > > >       */
> > > >      
> > > >      f->flags |= FID_REFERENCED;
> > > > 
> > > > -    f->next = s->fid_list;
> > > > -    s->fid_list = f;
> > > > +    QSIMPLEQ_INSERT_HEAD(&s->fid_list, f, next);
> > > 
> > > Not related to this series, but I wonder why queue.h wraps everything
> > > into:
> > > 
> > > do {
> > > 
> > > 	...
> > > 
> > > } while (0);
> > 
> > Note, this is do { ... } while (0) *without* the trailing semi-colon, which
> > is the corner stone of this trick.
> 
> Yes, I got that. What I meant was, unless I am missing something, a simple 
> compound statement (without trailing semi-colon) a.k.a. a 'block' is the more 
> common way to handle this, like:
> 
> #define QSIMPLEQ_INIT(head) {                                        \
>     (head)->sqh_first = NULL;                                        \
>     (head)->sqh_last = &(head)->sqh_first;                           \
> }
> 

No this isn't the more common way because it doesn't work with
if...else statements, i.e.

    if (some_condition)
        QSIMPLEQ_INIT(&head);
    else
	do_some_other_stuff()

has illagal syntax because of the semi-colon.

Of course, since the QEMU coding styles mandates { } in if...else
statements, your suggestion should just work, but do { } while(0)
doesn't do harm (compilers optimize that flawlessly) and it is
so commonly used elsewhere that I don't think its worth changing.

> Third patch tomorrow ... thanks Greg!
> 
> Best regards,
> Christian Schoenebeck
> 
> 



  reply	other threads:[~2021-01-19 18:57 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-18 14:22 [PATCH 0/3] 9pfs: Improve unreclaim logic Greg Kurz
2021-01-18 14:22 ` [PATCH 1/3] 9pfs: Convert V9fsFidState::clunked to bool Greg Kurz
2021-01-18 14:42   ` Christian Schoenebeck
2021-01-18 14:22 ` [PATCH 2/3] 9pfs: Convert V9fsFidState::fid_list to QSIMPLEQ Greg Kurz
2021-01-19 13:31   ` Christian Schoenebeck
2021-01-19 14:34     ` Greg Kurz
2021-01-19 15:28       ` Christian Schoenebeck
2021-01-19 17:23         ` Greg Kurz [this message]
2021-01-18 14:23 ` [PATCH 3/3] 9pfs: Improve unreclaim loop Greg Kurz
2021-01-21 12:50   ` Christian Schoenebeck
2021-01-21 16:34     ` Greg Kurz
2021-01-21 17:02       ` Christian Schoenebeck
2021-01-21 17:05 ` [PATCH 0/3] 9pfs: Improve unreclaim logic Greg Kurz

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=20210119182334.2d3381b5@bahia.lan \
    --to=groug@kaod.org \
    --cc=qemu-devel@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 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).