* [PATCH v2] qga: do not run hwclock(8) on non-Linux POSIX OSes
@ 2026-10-15 14:23 Roman Bogorodskiy
2026-10-28 9:03 ` Kostiantyn Kostiuk
0 siblings, 1 reply; 5+ messages in thread
From: Roman Bogorodskiy @ 2026-10-15 14:23 UTC (permalink / raw)
To: qemu-devel
Cc: Brad Smith, Roman Bogorodskiy, Michael Roth, Kostiantyn Kostiuk
Currently, qmp_guest_set_time() sets system time using
the settimeofday(2) system call and then runs the hwclock(8)
util to set hardware time.
hwclock(8) is Linux only, so current implementation
always fails while trying to run it on non-Linux POSIX OSes,
such as BSDs (FreeBSD, OpenBSD, NetBSD) and illumos.
Update the code not to run it on non-Linux. The settimeofday(2)
call sets both system and hardware time on these systems.
For example, on FreeBSD settimeofday() calls settime()
which calls resettodr() [1] which updates RTC clock [2].
It is similar on OpenBSD and NetBSD, though implementations
differ a bit.
Additional detail: on FreeBSD RTC clock setting can be
disabled with the `machdep.disable_rtc_set` sysctl.
As we cannot do anything about it, do not handle that
case separately.
Non-Linux POSIX OSes do not provide a common utility
equivalent to hwclock -s, so report an unsupported operation
when no time is supplied.
1: https://cgit.freebsd.org/src/tree/sys/kern/kern_time.c
2: https://cgit.freebsd.org/src/tree/sys/kern/subr_rtc.c
Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
---
Changes since v1:
Replace "#if defined(CONFIG_BSD)" condition with
"#if !defined(CONFIG_LINUX)" as hwclock(8) is Linux only.
qga/commands-posix.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index 837e285b6d..ffd1744b74 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -322,6 +322,20 @@ void qmp_guest_set_time(bool has_time, int64_t time_ns, Error **errp)
}
}
+#if !defined(CONFIG_LINUX)
+ /*
+ * BSDs (FreeBSD, OpenBSD, NetBSD) and illumos do not have the
+ * hwclock(8) tool. These systems update hardware clock when
+ * settimeofday() sets system time, so no additional actions
+ * are needed. Setting system time from RTC is not supported.
+ */
+ if (!has_time) {
+ error_setg(errp, "Setting system time from RTC is not supported");
+ }
+
+ return;
+#endif
+
/* Now, if user has passed a time to set and the system time is set, we
* just need to synchronize the hardware clock. However, if no time was
* passed, user is requesting the opposite: set the system time from the
--
2.55.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2] qga: do not run hwclock(8) on non-Linux POSIX OSes
2026-10-15 14:23 [PATCH v2] qga: do not run hwclock(8) on non-Linux POSIX OSes Roman Bogorodskiy
@ 2026-10-28 9:03 ` Kostiantyn Kostiuk
2026-10-28 10:56 ` Roman Bogorodskiy
0 siblings, 1 reply; 5+ messages in thread
From: Kostiantyn Kostiuk @ 2026-10-28 9:03 UTC (permalink / raw)
To: Roman Bogorodskiy; +Cc: qemu-devel, Brad Smith, Michael Roth
[-- Attachment #1: Type: text/plain, Size: 2781 bytes --]
On Thu, Oct 15, 2026 at 5:24 PM Roman Bogorodskiy <bogorodskiy@gmail.com>
wrote:
> Currently, qmp_guest_set_time() sets system time using
> the settimeofday(2) system call and then runs the hwclock(8)
> util to set hardware time.
>
> hwclock(8) is Linux only, so current implementation
> always fails while trying to run it on non-Linux POSIX OSes,
> such as BSDs (FreeBSD, OpenBSD, NetBSD) and illumos.
>
> Update the code not to run it on non-Linux. The settimeofday(2)
> call sets both system and hardware time on these systems.
> For example, on FreeBSD settimeofday() calls settime()
> which calls resettodr() [1] which updates RTC clock [2].
> It is similar on OpenBSD and NetBSD, though implementations
> differ a bit.
>
> Additional detail: on FreeBSD RTC clock setting can be
> disabled with the `machdep.disable_rtc_set` sysctl.
> As we cannot do anything about it, do not handle that
> case separately.
>
> Non-Linux POSIX OSes do not provide a common utility
> equivalent to hwclock -s, so report an unsupported operation
> when no time is supplied.
>
> 1: https://cgit.freebsd.org/src/tree/sys/kern/kern_time.c
> 2: https://cgit.freebsd.org/src/tree/sys/kern/subr_rtc.c
>
> Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
> ---
> Changes since v1:
>
> Replace "#if defined(CONFIG_BSD)" condition with
> "#if !defined(CONFIG_LINUX)" as hwclock(8) is Linux only.
>
> qga/commands-posix.c | 14 ++++++++++++++
> 1 file changed, 14 insertions(+)
>
> diff --git a/qga/commands-posix.c b/qga/commands-posix.c
> index 837e285b6d..ffd1744b74 100644
> --- a/qga/commands-posix.c
> +++ b/qga/commands-posix.c
> @@ -322,6 +322,20 @@ void qmp_guest_set_time(bool has_time, int64_t
> time_ns, Error **errp)
> }
> }
>
> +#if !defined(CONFIG_LINUX)
> + /*
> + * BSDs (FreeBSD, OpenBSD, NetBSD) and illumos do not have the
> + * hwclock(8) tool. These systems update hardware clock when
> + * settimeofday() sets system time, so no additional actions
> + * are needed. Setting system time from RTC is not supported.
> + */
> + if (!has_time) {
> + error_setg(errp, "Setting system time from RTC is not supported");
> + }
> +
> + return;
> +#endif
> +
>
As only Linux (not POSIX) and Windows support this function
lets move qmp_guest_set_time to commands-linux and update QAPI with
'if': { 'any': ['CONFIG_LINUX', 'CONFIG_WIN32'] }
Best Regards,
Kostiantyn Kostiuk.
> /* Now, if user has passed a time to set and the system time is set,
> we
> * just need to synchronize the hardware clock. However, if no time
> was
> * passed, user is requesting the opposite: set the system time from
> the
> --
> 2.55.0
>
>
[-- Attachment #2: Type: text/html, Size: 3927 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] qga: do not run hwclock(8) on non-Linux POSIX OSes
2026-10-28 9:03 ` Kostiantyn Kostiuk
@ 2026-10-28 10:56 ` Roman Bogorodskiy
2026-10-28 11:51 ` Kostiantyn Kostiuk
0 siblings, 1 reply; 5+ messages in thread
From: Roman Bogorodskiy @ 2026-10-28 10:56 UTC (permalink / raw)
To: Kostiantyn Kostiuk; +Cc: qemu-devel, Brad Smith, Michael Roth
Kostiantyn Kostiuk wrote:
> On Thu, Oct 15, 2026 at 5:24 PM Roman Bogorodskiy <bogorodskiy@gmail.com>
> wrote:
>
> > Currently, qmp_guest_set_time() sets system time using
> > the settimeofday(2) system call and then runs the hwclock(8)
> > util to set hardware time.
> >
> > hwclock(8) is Linux only, so current implementation
> > always fails while trying to run it on non-Linux POSIX OSes,
> > such as BSDs (FreeBSD, OpenBSD, NetBSD) and illumos.
> >
> > Update the code not to run it on non-Linux. The settimeofday(2)
> > call sets both system and hardware time on these systems.
> > For example, on FreeBSD settimeofday() calls settime()
> > which calls resettodr() [1] which updates RTC clock [2].
> > It is similar on OpenBSD and NetBSD, though implementations
> > differ a bit.
> >
> > Additional detail: on FreeBSD RTC clock setting can be
> > disabled with the `machdep.disable_rtc_set` sysctl.
> > As we cannot do anything about it, do not handle that
> > case separately.
> >
> > Non-Linux POSIX OSes do not provide a common utility
> > equivalent to hwclock -s, so report an unsupported operation
> > when no time is supplied.
> >
> > 1: https://cgit.freebsd.org/src/tree/sys/kern/kern_time.c
> > 2: https://cgit.freebsd.org/src/tree/sys/kern/subr_rtc.c
> >
> > Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
> > ---
> > Changes since v1:
> >
> > Replace "#if defined(CONFIG_BSD)" condition with
> > "#if !defined(CONFIG_LINUX)" as hwclock(8) is Linux only.
> >
> > qga/commands-posix.c | 14 ++++++++++++++
> > 1 file changed, 14 insertions(+)
> >
> > diff --git a/qga/commands-posix.c b/qga/commands-posix.c
> > index 837e285b6d..ffd1744b74 100644
> > --- a/qga/commands-posix.c
> > +++ b/qga/commands-posix.c
> > @@ -322,6 +322,20 @@ void qmp_guest_set_time(bool has_time, int64_t
> > time_ns, Error **errp)
> > }
> > }
> >
> > +#if !defined(CONFIG_LINUX)
> > + /*
> > + * BSDs (FreeBSD, OpenBSD, NetBSD) and illumos do not have the
> > + * hwclock(8) tool. These systems update hardware clock when
> > + * settimeofday() sets system time, so no additional actions
> > + * are needed. Setting system time from RTC is not supported.
> > + */
> > + if (!has_time) {
> > + error_setg(errp, "Setting system time from RTC is not supported");
> > + }
> > +
> > + return;
> > +#endif
> > +
> >
>
> As only Linux (not POSIX) and Windows support this function
> lets move qmp_guest_set_time to commands-linux and update QAPI with
> 'if': { 'any': ['CONFIG_LINUX', 'CONFIG_WIN32'] }
Hi Kostiantyn,
Sorry if my commit message does not explain the situation clearly enough.
BSDs and illumos do support "guest-set-time" with "time" specified.
On these systems, calling settimeofday() is enough for that, it sets
both system time and hardware clock, so lack of the hwclock(8) does not
prevent it from working as intended.
Only "guest-set-time" without the "time" argument (i.e. setting system time
from the hardware clock) is not supported indeed, which we indicate with
an error message.
Therefore I think keeping qmp_guest_set_time() in commands-posix.c and
keeping the proposed conditional behavior is appropriate.
>
> Best Regards,
> Kostiantyn Kostiuk.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] qga: do not run hwclock(8) on non-Linux POSIX OSes
2026-10-28 10:56 ` Roman Bogorodskiy
@ 2026-10-28 11:51 ` Kostiantyn Kostiuk
2026-10-28 11:51 ` Kostiantyn Kostiuk
0 siblings, 1 reply; 5+ messages in thread
From: Kostiantyn Kostiuk @ 2026-10-28 11:51 UTC (permalink / raw)
To: Roman Bogorodskiy; +Cc: qemu-devel, Brad Smith, Michael Roth
[-- Attachment #1: Type: text/plain, Size: 3681 bytes --]
Make sense
Thanks for explanation
Best Regards,
Kostiantyn Kostiuk.
On Wed, Oct 28, 2026 at 12:57 PM Roman Bogorodskiy <bogorodskiy@gmail.com>
wrote:
> Kostiantyn Kostiuk wrote:
>
> > On Thu, Oct 15, 2026 at 5:24 PM Roman Bogorodskiy <bogorodskiy@gmail.com
> >
> > wrote:
> >
> > > Currently, qmp_guest_set_time() sets system time using
> > > the settimeofday(2) system call and then runs the hwclock(8)
> > > util to set hardware time.
> > >
> > > hwclock(8) is Linux only, so current implementation
> > > always fails while trying to run it on non-Linux POSIX OSes,
> > > such as BSDs (FreeBSD, OpenBSD, NetBSD) and illumos.
> > >
> > > Update the code not to run it on non-Linux. The settimeofday(2)
> > > call sets both system and hardware time on these systems.
> > > For example, on FreeBSD settimeofday() calls settime()
> > > which calls resettodr() [1] which updates RTC clock [2].
> > > It is similar on OpenBSD and NetBSD, though implementations
> > > differ a bit.
> > >
> > > Additional detail: on FreeBSD RTC clock setting can be
> > > disabled with the `machdep.disable_rtc_set` sysctl.
> > > As we cannot do anything about it, do not handle that
> > > case separately.
> > >
> > > Non-Linux POSIX OSes do not provide a common utility
> > > equivalent to hwclock -s, so report an unsupported operation
> > > when no time is supplied.
> > >
> > > 1: https://cgit.freebsd.org/src/tree/sys/kern/kern_time.c
> > > 2: https://cgit.freebsd.org/src/tree/sys/kern/subr_rtc.c
> > >
> > > Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
> > > ---
> > > Changes since v1:
> > >
> > > Replace "#if defined(CONFIG_BSD)" condition with
> > > "#if !defined(CONFIG_LINUX)" as hwclock(8) is Linux only.
> > >
> > > qga/commands-posix.c | 14 ++++++++++++++
> > > 1 file changed, 14 insertions(+)
> > >
> > > diff --git a/qga/commands-posix.c b/qga/commands-posix.c
> > > index 837e285b6d..ffd1744b74 100644
> > > --- a/qga/commands-posix.c
> > > +++ b/qga/commands-posix.c
> > > @@ -322,6 +322,20 @@ void qmp_guest_set_time(bool has_time, int64_t
> > > time_ns, Error **errp)
> > > }
> > > }
> > >
> > > +#if !defined(CONFIG_LINUX)
> > > + /*
> > > + * BSDs (FreeBSD, OpenBSD, NetBSD) and illumos do not have the
> > > + * hwclock(8) tool. These systems update hardware clock when
> > > + * settimeofday() sets system time, so no additional actions
> > > + * are needed. Setting system time from RTC is not supported.
> > > + */
> > > + if (!has_time) {
> > > + error_setg(errp, "Setting system time from RTC is not
> supported");
> > > + }
> > > +
> > > + return;
> > > +#endif
> > > +
> > >
> >
> > As only Linux (not POSIX) and Windows support this function
> > lets move qmp_guest_set_time to commands-linux and update QAPI with
> > 'if': { 'any': ['CONFIG_LINUX', 'CONFIG_WIN32'] }
>
> Hi Kostiantyn,
>
> Sorry if my commit message does not explain the situation clearly enough.
>
> BSDs and illumos do support "guest-set-time" with "time" specified.
> On these systems, calling settimeofday() is enough for that, it sets
> both system time and hardware clock, so lack of the hwclock(8) does not
> prevent it from working as intended.
>
> Only "guest-set-time" without the "time" argument (i.e. setting system time
> from the hardware clock) is not supported indeed, which we indicate with
> an error message.
>
> Therefore I think keeping qmp_guest_set_time() in commands-posix.c and
> keeping the proposed conditional behavior is appropriate.
>
> >
> > Best Regards,
> > Kostiantyn Kostiuk.
>
>
[-- Attachment #2: Type: text/html, Size: 5208 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] qga: do not run hwclock(8) on non-Linux POSIX OSes
2026-10-28 11:51 ` Kostiantyn Kostiuk
@ 2026-10-28 11:51 ` Kostiantyn Kostiuk
0 siblings, 0 replies; 5+ messages in thread
From: Kostiantyn Kostiuk @ 2026-10-28 11:51 UTC (permalink / raw)
To: Roman Bogorodskiy; +Cc: qemu-devel, Brad Smith, Michael Roth
[-- Attachment #1: Type: text/plain, Size: 3940 bytes --]
Reviewed-by: Kostiantyn Kostiuk <kkostiuk@redhat.com>
On Wed, Oct 28, 2026 at 1:51 PM Kostiantyn Kostiuk <kkostiuk@redhat.com>
wrote:
> Make sense
> Thanks for explanation
>
>
>
> Best Regards,
> Kostiantyn Kostiuk.
>
>
> On Wed, Oct 28, 2026 at 12:57 PM Roman Bogorodskiy <bogorodskiy@gmail.com>
> wrote:
>
>> Kostiantyn Kostiuk wrote:
>>
>> > On Thu, Oct 15, 2026 at 5:24 PM Roman Bogorodskiy <
>> bogorodskiy@gmail.com>
>> > wrote:
>> >
>> > > Currently, qmp_guest_set_time() sets system time using
>> > > the settimeofday(2) system call and then runs the hwclock(8)
>> > > util to set hardware time.
>> > >
>> > > hwclock(8) is Linux only, so current implementation
>> > > always fails while trying to run it on non-Linux POSIX OSes,
>> > > such as BSDs (FreeBSD, OpenBSD, NetBSD) and illumos.
>> > >
>> > > Update the code not to run it on non-Linux. The settimeofday(2)
>> > > call sets both system and hardware time on these systems.
>> > > For example, on FreeBSD settimeofday() calls settime()
>> > > which calls resettodr() [1] which updates RTC clock [2].
>> > > It is similar on OpenBSD and NetBSD, though implementations
>> > > differ a bit.
>> > >
>> > > Additional detail: on FreeBSD RTC clock setting can be
>> > > disabled with the `machdep.disable_rtc_set` sysctl.
>> > > As we cannot do anything about it, do not handle that
>> > > case separately.
>> > >
>> > > Non-Linux POSIX OSes do not provide a common utility
>> > > equivalent to hwclock -s, so report an unsupported operation
>> > > when no time is supplied.
>> > >
>> > > 1: https://cgit.freebsd.org/src/tree/sys/kern/kern_time.c
>> > > 2: https://cgit.freebsd.org/src/tree/sys/kern/subr_rtc.c
>> > >
>> > > Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
>> > > ---
>> > > Changes since v1:
>> > >
>> > > Replace "#if defined(CONFIG_BSD)" condition with
>> > > "#if !defined(CONFIG_LINUX)" as hwclock(8) is Linux only.
>> > >
>> > > qga/commands-posix.c | 14 ++++++++++++++
>> > > 1 file changed, 14 insertions(+)
>> > >
>> > > diff --git a/qga/commands-posix.c b/qga/commands-posix.c
>> > > index 837e285b6d..ffd1744b74 100644
>> > > --- a/qga/commands-posix.c
>> > > +++ b/qga/commands-posix.c
>> > > @@ -322,6 +322,20 @@ void qmp_guest_set_time(bool has_time, int64_t
>> > > time_ns, Error **errp)
>> > > }
>> > > }
>> > >
>> > > +#if !defined(CONFIG_LINUX)
>> > > + /*
>> > > + * BSDs (FreeBSD, OpenBSD, NetBSD) and illumos do not have the
>> > > + * hwclock(8) tool. These systems update hardware clock when
>> > > + * settimeofday() sets system time, so no additional actions
>> > > + * are needed. Setting system time from RTC is not supported.
>> > > + */
>> > > + if (!has_time) {
>> > > + error_setg(errp, "Setting system time from RTC is not
>> supported");
>> > > + }
>> > > +
>> > > + return;
>> > > +#endif
>> > > +
>> > >
>> >
>> > As only Linux (not POSIX) and Windows support this function
>> > lets move qmp_guest_set_time to commands-linux and update QAPI with
>> > 'if': { 'any': ['CONFIG_LINUX', 'CONFIG_WIN32'] }
>>
>> Hi Kostiantyn,
>>
>> Sorry if my commit message does not explain the situation clearly enough.
>>
>> BSDs and illumos do support "guest-set-time" with "time" specified.
>> On these systems, calling settimeofday() is enough for that, it sets
>> both system time and hardware clock, so lack of the hwclock(8) does not
>> prevent it from working as intended.
>>
>> Only "guest-set-time" without the "time" argument (i.e. setting system
>> time
>> from the hardware clock) is not supported indeed, which we indicate with
>> an error message.
>>
>> Therefore I think keeping qmp_guest_set_time() in commands-posix.c and
>> keeping the proposed conditional behavior is appropriate.
>>
>> >
>> > Best Regards,
>> > Kostiantyn Kostiuk.
>>
>>
[-- Attachment #2: Type: text/html, Size: 5655 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-10-28 11:53 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-15 14:23 [PATCH v2] qga: do not run hwclock(8) on non-Linux POSIX OSes Roman Bogorodskiy
2026-10-28 9:03 ` Kostiantyn Kostiuk
2026-10-28 10:56 ` Roman Bogorodskiy
2026-10-28 11:51 ` Kostiantyn Kostiuk
2026-10-28 11:51 ` Kostiantyn Kostiuk
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.