xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Anthony PERARD <anthony.perard@citrix.com>
To: Ian Jackson <ian.jackson@citrix.com>
Cc: xen-devel@lists.xenproject.org, Wei Liu <wei.liu2@citrix.com>
Subject: Re: [PATCH v5 03/15] libxl_qmp: Implement fd callback and read data
Date: Thu, 11 Oct 2018 15:06:04 +0100	[thread overview]
Message-ID: <20181011140604.GH1331@perard.uk.xensource.com> (raw)
In-Reply-To: <23486.7932.781238.747508@mariner.uk.xensource.com>

On Wed, Oct 10, 2018 at 04:47:08PM +0100, Ian Jackson wrote:
> Anthony PERARD writes ("[PATCH v5 03/15] libxl_qmp: Implement fd callback and read data"):
> > First step into taking care of the input from QEMU's QMP socket. For
> > now, we read data and store them in a buffer.
> ...
> > +    if (!ev->rx_buf) {
> > +        ev->rx_buf = libxl__malloc(NOGC, QMP_RECEIVE_BUFFER_SIZE);
> > +        ev->buf_size = QMP_RECEIVE_BUFFER_SIZE;
> > +        ev->buf_used = 0;
> > +        ev->buf_consumed = 0;
> > +    }
> > +
> > +    /* Check if last buffer still have space, or increase size */
> > +    /* The -1 is because there is always space for a NUL character */
> > +    if (ev->buf_used == ev->buf_size - 1) {
> > +        ev->buf_size += QMP_RECEIVE_BUFFER_SIZE;
> > +        ev->rx_buf = libxl__realloc(NOGC, ev->rx_buf, ev->buf_size);
> > +    }
> 
> I think this is unnecessarily complex.  I think you should set buf_*
> to 0 in _init, and arrange to realloc(0, new_size) if the buffer is
> not big enough for "some space" plus a nul.
> 
> Also, you should increase the buffer size exponentially.  And you
> should put a limit on the buffer size, in case the sender goes mad.

Ok, I'll see what I can do.

> > +    /* The -1 is because there is always space for a NUL character */
> > +    r = read(fd, ev->rx_buf + ev->buf_used, ev->buf_size - ev->buf_used - 1);
> 
> Lines too long again.  (I will stop complaining about this now but can
> you pleae fix it throughout?)

But the comment is less than 70chr long, and the next line follow the
coding style, which is "Lines are limited to 75-80 characters.", and
I'm pretty sure that 77 is less that 75-80!

If the coding style described in CODING_STYLE change before my next
submition, I can wrap too long lines ;-).

> > +    if (r < 0) {
> > +        if (errno == EINTR)
> > +            return 0;
> 
> No, you need to go round again.  I'm afraid the whole of this function
> needs to be in a loop.  This is because you are not guaranteed that
> you will get more than one call to your readable callback per
> transition from not-readable to readable.

I've did it without a loop because POLLIN means "data may be read
without blocking", and I can't find anything speaking about a relation
with transition from one state to the other.

But I can add a loop around the code, as that seems to confuse everyone
that there is none.

> > +        assert(errno);
> > +        if (errno == EWOULDBLOCK)
> > +            return 0;
> 
> And again.

Surely here I need to return on EWOULDBLOCK. The fd is obviously in
non-readable state, so there is going to be a transition.

> > +        LOGED(ERROR, ev->domid, "error reading QMP socket");
> 
> I think you need to look up the error handling for (possibly
> long-running) connect operation fails on a stream socket which were in
> nonblocking mode when you called connect().  You may need to handle
> EINPROGRESS from the connect() syscall itself (that was in the
> previous patch).

Looks like it, I'll have a look at the error handling of the connect()
call.

> > +    if (r == 0) {
> > +        LOGD(ERROR, ev->domid, "No data read on QMP socket");
> 
> You mean "unexpected EOF" not "no data read".  Normally this would
> mean that qemu died or crashed.
> 
> > +        return 0;
> 
> Err, and then this needs to be handled as an error, not simply
> ignored.  If it happens, it will keep happening.

I think I'm been lazy and have just let this error been handle in the
next event where POLLHUP should be set. I can try to handle this error
better here.

> > +    LOG_QMP("received %ldB: '%.*s'", r, (int)r, ev->rx_buf + ev->buf_used);
> > +
> > +    ev->buf_used += r;
> > +    assert(ev->buf_used < ev->buf_size);
> 
> It would be really helpful if these partial functions were to contain
> an `xxx' or something where there is missing code.
> 
> As it is I know that more code will occur here, but nothing
> straightforward in the review will process will spot it the mistake if
> you forget to add it...
> 
> The loop I mentioned could be in qmp_ev_fd_callback.
> 
> TBH I find the split between qmp_ev_fd_callback and
> qmp_ev_callback_readable a bit confusing but I know that I'm unusual
> in preferring longer functions.
> 
> > +static void qmp_ev_callback_error(libxl__egc *egc, libxl__ev_qmp *ev)
> > +{
> > +    EGC_GC;
> > +
> > +    LOGD(ERROR, ev->domid, "Error happend with the QMP connection to QEMU");
> > +
> > +    /* On error, deallocate all private ressources */
> > +    libxl__ev_qmp_dispose(gc, ev);
> 
> Missing /* xxx */ to report the error upwards.
> 
> 
> Hrm.  I realise this is going to be annoying, but I think I should
> probably stop now because of the lack of xxx's means it's hard for me
> to review.
> 
> What do you think would be best:
>  (i) I should, in my own tree, squash several of your commits down
>      so I can review them together
>  (ii) You repost with a lot of XXXs added
>  (iii) We intend to squash the commits in xen.git ?
> 
> I think (ii) is a fair amount of work for polishing an intermediate
> state, and probably a waste.  I'm inclined to (i) (iii).  Can you tell
> me which patches I should sqaush ?
> 
> I think I need up to `libxl_qmp: Respond to QMP greeting' ?

Squashing all the relevant commits might not be that bad, since all
commits implement different functions.

There is one patch that can be reviewed separatly, and then yes, you
need up to 'libxl_qmp: Respond to QMP greeting'. That give us:

pick      libxl_qmp: Separate QMP message generation from qmp_send_prepare
pick      libxl_qmp: Connect to QMP socket
squash    libxl_qmp: Implement fd callback and read data
squash    libxl_qmp: Parse JSON input from QMP
squash    libxl_qmp: Prepare the command to be sent
squash    libxl_qmp: Handle write to QMP socket
squash    libxl_qmp: Handle messages from QEMU
squash    libxl_qmp: Respond to QMP greeting

That give us a patch with only 500 insertions.

Thanks,

-- 
Anthony PERARD

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  reply	other threads:[~2018-10-11 14:06 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20181015151630.3887-1-ian.jackson@eu.citrix.com>
2018-09-07 15:10 ` [PATCH v5 00/15] libxl: Enable save/restore/migration of a restricted QEMU + libxl__ev_qmp_* Anthony PERARD
2018-09-07 15:10   ` [PATCH v5 01/15] libxl: Design of an async API to issue QMP commands to QEMU Anthony PERARD
2018-10-10 15:18     ` Ian Jackson
2018-10-11 11:17       ` Anthony PERARD
2018-10-11 11:21         ` Ian Jackson
2018-10-10 23:49     ` Marek Marczykowski-Górecki
2018-10-11 14:29       ` Anthony PERARD
2018-09-07 15:10   ` [PATCH v5 02/15] libxl_qmp: Connect to QMP socket Anthony PERARD
2018-10-10 15:29     ` Ian Jackson
2018-10-11 11:27       ` Anthony PERARD
2018-09-07 15:10   ` [PATCH v5 03/15] libxl_qmp: Implement fd callback and read data Anthony PERARD
2018-10-10 15:47     ` Ian Jackson
2018-10-11 14:06       ` Anthony PERARD [this message]
2018-10-15 14:04         ` Ian Jackson
2018-10-15 16:35         ` [PATCH v5 03/15] libxl_qmp: Implement fd callback and read data [and 1 more messages] Ian Jackson
2018-10-29 15:52           ` Anthony PERARD
2018-10-29 17:31             ` Ian Jackson
2018-10-30 18:03               ` Anthony PERARD
2018-10-30 18:25                 ` Ian Jackson
2018-09-07 15:10   ` [PATCH v5 04/15] libxl_qmp: Parse JSON input from QMP Anthony PERARD
2018-09-07 15:10   ` [PATCH v5 05/15] libxl_qmp: Separate QMP message generation from qmp_send_prepare Anthony PERARD
2018-09-07 15:10   ` [PATCH v5 06/15] libxl_qmp: Prepare the command to be sent Anthony PERARD
2018-09-07 15:10   ` [PATCH v5 07/15] libxl_qmp: Handle write to QMP socket Anthony PERARD
2018-09-07 15:10   ` [PATCH v5 08/15] libxl_qmp: Handle messages from QEMU Anthony PERARD
2018-09-07 15:10   ` [PATCH v5 09/15] libxl_qmp: Respond to QMP greeting Anthony PERARD
2018-09-07 15:10   ` [PATCH v5 10/15] libxl_exec: Add libxl__spawn_initiate_failure Anthony PERARD
2018-10-16 14:02     ` Ian Jackson
2018-11-09 12:26       ` Anthony PERARD
2018-09-07 15:11   ` [PATCH v5 11/15] libxl_dm: Pre-open QMP socket for QEMU Anthony PERARD
2018-10-16 14:11     ` Ian Jackson
2018-11-12 14:52       ` Anthony PERARD
2018-11-12 15:14         ` Ian Jackson
2018-11-12 15:22           ` Anthony PERARD
2018-11-12 15:54             ` Ian Jackson
2018-09-07 15:11   ` [PATCH v5 12/15] libxl: QEMU startup sync based on QMP Anthony PERARD
2018-10-16 14:23     ` Ian Jackson
2018-11-12 15:00       ` Anthony PERARD
2018-11-12 15:17         ` Ian Jackson
2018-09-07 15:11   ` [PATCH v5 13/15] libxl_qmp: Store advertised QEMU version in libxl__ev_qmp Anthony PERARD
2018-10-16 14:25     ` Ian Jackson
2018-09-07 15:11   ` [PATCH v5 14/15] libxl: Change libxl__domain_suspend_device_model() to be async Anthony PERARD
2018-10-16 15:14     ` Ian Jackson
2018-09-07 15:11   ` [PATCH v5 15/15] libxl: Re-implement domain_suspend_device_model using libxl__ev_qmp Anthony PERARD
2018-10-16 15:28     ` Ian Jackson
2018-11-09 16:59       ` Anthony PERARD
2018-11-09 17:11         ` Ian Jackson
2018-11-09 17:30           ` Anthony PERARD

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=20181011140604.GH1331@perard.uk.xensource.com \
    --to=anthony.perard@citrix.com \
    --cc=ian.jackson@citrix.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xenproject.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).