Make stopped ldom utilization appear as zero
authorkn <kn@openbsd.org>
Thu, 10 Aug 2023 07:50:45 +0000 (07:50 +0000)
committerkn <kn@openbsd.org>
Thu, 10 Aug 2023 07:50:45 +0000 (07:50 +0000)
ldomctl(8) 'status' updated the value only on running guests,
i.e. stopped ones repeated the last ones instead of showing zero.

Always reset per guest before updating it, From Koakuma, thanks!

usr.sbin/ldomctl/ldomctl.c

index e48a560..78dfdb3 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: ldomctl.c,v 1.40 2021/10/24 21:24:18 deraadt Exp $    */
+/*     $OpenBSD: ldomctl.c,v 1.41 2023/08/10 07:50:45 kn Exp $ */
 
 /*
  * Copyright (c) 2012 Mark Kettenis
@@ -592,6 +592,8 @@ guest_status(int argc, char **argv)
                if (nbytes != sizeof(msg))
                        err(1, "read");
 
+               utilisation = 0.0;
+
                memcpy(&state, msg.msg.resstat.data, sizeof(state));
                switch (state.state) {
                case GUEST_STATE_STOPPED:
@@ -644,8 +646,6 @@ guest_status(int argc, char **argv)
                        if (yielded_cycles <= total_cycles)
                                utilisation = (100.0 * (total_cycles
                                    - yielded_cycles)) / total_cycles;
-                       else
-                               utilisation = 0.0;
 
                        break;
                case GUEST_STATE_SUSPENDED: