qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v2 10/14] char: generalize qemu_chr_write_all()


From: Marc-André Lureau
Subject: Re: [Qemu-devel] [PATCH v2 10/14] char: generalize qemu_chr_write_all()
Date: Tue, 30 May 2017 05:59:57 +0000

Hi

On Tue, May 30, 2017 at 1:09 AM Philippe Mathieu-Daudé <address@hidden>
wrote:

> Hi Marc-André,
>
> On 05/29/2017 05:45 AM, Marc-André Lureau wrote:
> > qemu_chr_fe_write() is similar to qemu_chr_write_all(): the later write
> > all with a chardev backend.
> >
> > Make qemu_chr_write() and qemu_chr_fe_write_buffer() take an 'all'
> > argument. If false, handle 'partial' write the way qemu_chr_fe_write()
> > use to, and call qemu_chr_write() from qemu_chr_fe_write().
> >
> > Signed-off-by: Marc-André Lureau <address@hidden>
> > ---
> >  chardev/char.c | 70
> +++++++++++++++++++++++-----------------------------------
> >  1 file changed, 28 insertions(+), 42 deletions(-)
> >
> > diff --git a/chardev/char.c b/chardev/char.c
> > index a747e0279a..9a7c70c7aa 100644
> > --- a/chardev/char.c
> > +++ b/chardev/char.c
> > @@ -96,7 +96,8 @@ static void qemu_chr_fe_write_log(Chardev *s,
> >  }
> >
> >  static int qemu_chr_fe_write_buffer(Chardev *s,
> > -                                    const uint8_t *buf, int len, int
> *offset)
> > +                                    const uint8_t *buf, int len,
> > +                                    int *offset, bool write_all)
> >  {
> >      ChardevClass *cc = CHARDEV_GET_CLASS(s);
> >      int res = 0;
> > @@ -106,7 +107,7 @@ static int qemu_chr_fe_write_buffer(Chardev *s,
> >      while (*offset < len) {
> >      retry:
> >          res = cc->chr_write(s, buf + *offset, len - *offset);
> > -        if (res < 0 && errno == EAGAIN) {
> > +        if (res < 0 && errno == EAGAIN && write_all) {
> >              g_usleep(100);
> >              goto retry;
> >          }
> > @@ -116,6 +117,9 @@ static int qemu_chr_fe_write_buffer(Chardev *s,
> >          }
> >
> >          *offset += res;
> > +        if (!write_all) {
> > +            break;
> > +        }
> >      }
> >      if (*offset > 0) {
> >          qemu_chr_fe_write_log(s, buf, *offset);
> > @@ -130,54 +134,20 @@ static bool qemu_chr_replay(Chardev *chr)
> >      return qemu_chr_has_feature(chr, QEMU_CHAR_FEATURE_REPLAY);
> >  }
> >
> > -int qemu_chr_fe_write(CharBackend *be, const uint8_t *buf, int len)
> > +static int qemu_chr_write(Chardev *s, const uint8_t *buf, int len,
> > +                          bool write_all)
> >  {
> > -    Chardev *s = be->chr;
> > -    ChardevClass *cc;
> > -    int ret;
> > -
> > -    if (!s) {
> > -        return 0;
> > -    }
> > -
> > -    if (qemu_chr_replay(s) && replay_mode == REPLAY_MODE_PLAY) {
> > -        int offset;
> > -        replay_char_write_event_load(&ret, &offset);
> > -        assert(offset <= len);
> > -        qemu_chr_fe_write_buffer(s, buf, offset, &offset);
> > -        return ret;
> > -    }
> > -
> > -    cc = CHARDEV_GET_CLASS(s);
> > -    qemu_mutex_lock(&s->chr_write_lock);
> > -    ret = cc->chr_write(s, buf, len);
> > -
> > -    if (ret > 0) {
> > -        qemu_chr_fe_write_log(s, buf, ret);
> > -    }
> > -
> > -    qemu_mutex_unlock(&s->chr_write_lock);
> > -
> > -    if (qemu_chr_replay(s) && replay_mode == REPLAY_MODE_RECORD) {
> > -        replay_char_write_event_save(ret, ret < 0 ? 0 : ret);
> > -    }
> > -
> > -    return ret;
> > -}
> > -
> > -int qemu_chr_write_all(Chardev *s, const uint8_t *buf, int len)
> > -{
> > -    int offset;
> > +    int offset = 0;
> >      int res;
> >
> >      if (qemu_chr_replay(s) && replay_mode == REPLAY_MODE_PLAY) {
> >          replay_char_write_event_load(&res, &offset);
> >          assert(offset <= len);
> > -        qemu_chr_fe_write_buffer(s, buf, offset, &offset);
> > +        qemu_chr_fe_write_buffer(s, buf, offset, &offset, true);
> >          return res;
> >      }
> >
> > -    res = qemu_chr_fe_write_buffer(s, buf, len, &offset);
> > +    res = qemu_chr_fe_write_buffer(s, buf, len, &offset, write_all);
> >
> >      if (qemu_chr_replay(s) && replay_mode == REPLAY_MODE_RECORD) {
> >          replay_char_write_event_save(res, offset);
> > @@ -189,6 +159,22 @@ int qemu_chr_write_all(Chardev *s, const uint8_t
> *buf, int len)
> >      return offset;
> >  }
> >
> > +int qemu_chr_write_all(Chardev *s, const uint8_t *buf, int len)
> > +{
> > +    return qemu_chr_write(s, buf, len, true);
> > +}
> > +
> > +int qemu_chr_fe_write(CharBackend *be, const uint8_t *buf, int len)
> > +{
> > +    Chardev *s = be->chr;
> > +
> > +    if (!s) {
> > +        return 0;
> > +    }
> > +
> > +    return qemu_chr_write(s, buf, len, false);
> > +}
> > +
> >  int qemu_chr_fe_write_all(CharBackend *be, const uint8_t *buf, int len)
> >  {
> >      Chardev *s = be->chr;
> > @@ -197,7 +183,7 @@ int qemu_chr_fe_write_all(CharBackend *be, const
> uint8_t *buf, int len)
> >          return 0;
> >      }
> >
> > -    return qemu_chr_write_all(s, buf, len);
> > +    return qemu_chr_write(s, buf, len, true);
>
> I think calling qemu_chr_write_all() is more readable.
>

 qemu_chr_write_all() would imply that you cannot change the 'all'
behaviour to me, but this is a matter of taste I guess


> Either ways:
> Reviewed-by: Philippe Mathieu-Daudé <address@hidden>
>

thanks
-- 
Marc-André Lureau


reply via email to

[Prev in Thread] Current Thread [Next in Thread]