All of lore.kernel.org
 help / color / mirror / Atom feed
From: Roman Bogorodskiy <bogorodskiy@gmail.com>
To: Kostiantyn Kostiuk <kkostiuk@redhat.com>
Cc: qemu-devel@nongnu.org, Michael Roth <michael.roth@amd.com>,
	Eric Blake <eblake@redhat.com>,
	Markus Armbruster <armbru@redhat.com>
Subject: Re: [PATCH] qga: implement 'guest-get-diskstats' for FreeBSD
Date: Tue, 1 Sep 2026 19:31:09 +0200	[thread overview]
Message-ID: <apcL3cfPcBw9YEf9@tulp> (raw)
In-Reply-To: <CAPMcbCrLmS2NXASKAWujm6=do9cAvMcB4p5Yxp73T_6HshRGQA@mail.gmail.com>

  Kostiantyn Kostiuk wrote:

> Hi Roman,
> 
> Thanks for your patch, and sorry for the late reply
> 

Thanks for review!

> On Sun, Jul 19, 2026 at 7:04 PM Roman Bogorodskiy <bogorodskiy@gmail.com>
> wrote:
> 
> > Implement the 'guest-get-diskstats' for FreeBSD.
> > This implementation uses the devstat(3) library which is a part
> > of the FreeBSD base system.
> >
> > The build system is updated to link qga with `-ldevstat`.
> >
> > Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
> > ---
> >  qga/commands-bsd.c   | 127 +++++++++++++++++++++++++++++++++++++++++++
> >  qga/meson.build      |   3 +
> >  qga/qapi-schema.json |   6 +-
> >  3 files changed, 133 insertions(+), 3 deletions(-)
> >
> > diff --git a/qga/commands-bsd.c b/qga/commands-bsd.c
> > index 94ff6fee6a..763db33c9f 100644
> > --- a/qga/commands-bsd.c
> > +++ b/qga/commands-bsd.c
> > @@ -27,6 +27,9 @@
> >  #include <net/ethernet.h>
> >  #endif
> >  #include <paths.h>
> > +#ifdef CONFIG_FREEBSD
> > +#include <devstat.h>
> > +#endif
> >
> >  #if defined(CONFIG_FSFREEZE) || defined(CONFIG_FSTRIM)
> >  bool build_fs_mount_list(FsMountList *mounts, Error **errp)
> > @@ -178,3 +181,127 @@ bool guest_get_hw_addr(struct ifaddrs *ifa, unsigned
> > char *buf,
> >      return true;
> >  }
> >  #endif /* HAVE_GETIFADDRS */
> > +
> > +#ifdef CONFIG_FREEBSD
> > +static uint64_t bintime_to_msec(const struct bintime *bt)
> > +{
> > +    return (uint64_t)bt->sec * 1000ULL + (((bt->frac >> 32) * 1000ULL) >>
> > 32);
> > +}
> > +
> > +static void guest_diskstats_append(GuestDiskStatsInfoList ***tailp,
> > +                                   const struct devstat *dev)
> >
> 
> Can we simplify pointer logic?
> For example, return GuestDiskStatsInfo* for devstat* and then append the
> list in guest_get_diskstats.
> ***tailp -> more pointers - easier to make a mistake or memory leak.

Yes, will address in v2.

> > +
> > +    diskstat->has_ios_pgr = true;
> > +    if (dev->start_count >= dev->end_count) {
> > +        diskstat->ios_pgr = dev->start_count - dev->end_count;
> > +    }
> >
> 
> In case start_count < end_count, you have has_ios_pgr = true, and ios_pgr =
> 0 (g_new0 initialized to 0’s)
> Is this expected? And in general, is this possible?

That's an interesting question.
`start_count` and `end_count` are uint's. It is possible that
`start_count` will wrap sooner than `end_count`, so 

   start_count < end_count

But apparently the correct behaviour is still report the difference
instead of reporting 0.

devstat(9) describes that:

     start_count        Number of operations started.

     end_count          Number of operations completed.  The “busy_count” can
                        be calculated by subtracting end_count from
                        start_count.  (sequence0 and sequence1 are used to get
                        a consistent snapshot.)  This is the current number of
                        outstanding transactions for the device.  This should
                        never go below zero, and on an idle device it should
                        be zero.  If either one of these conditions is not
                        true, it indicates a problem.


So it looks like the conditional is not needed. libdevstat in FreeBSD
does not have it too [1].
I'll remove that in v2.

> > +
> > +GuestDiskStatsInfoList *qmp_guest_get_diskstats(Error **errp)
> > +{
> > +    return guest_get_diskstats(errp);
> >
> 
> Any reason for this wrapper?
> I see it in the Linux implementation, but not for other commands.

I followed the Linux implementation schema here. Apparently it is not
necessary. Will address in v2 as well.

1: https://cgit.freebsd.org/src/tree/lib/libdevstat/devstat.c#n1547
 


  reply	other threads:[~2026-09-01 17:32 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-19 16:03 [PATCH] qga: implement 'guest-get-diskstats' for FreeBSD Roman Bogorodskiy
2026-07-20 12:29 ` Markus Armbruster
2026-08-19  8:49 ` Roman Bogorodskiy
2026-08-31 16:05 ` Kostiantyn Kostiuk
2026-09-01 17:31   ` Roman Bogorodskiy [this message]
2026-09-01 17:41     ` Kostiantyn Kostiuk

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=apcL3cfPcBw9YEf9@tulp \
    --to=bogorodskiy@gmail.com \
    --cc=armbru@redhat.com \
    --cc=eblake@redhat.com \
    --cc=kkostiuk@redhat.com \
    --cc=michael.roth@amd.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.