From nobody Mon Feb 9 20:10:16 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539896602764217.64415438937203; Thu, 18 Oct 2018 14:03:22 -0700 (PDT) Received: from localhost ([::1]:44670 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDFRx-0008Rg-GC for importer@patchew.org; Thu, 18 Oct 2018 17:03:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48111) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDEyJ-0007JX-FE for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDEyG-0006Kp-RC for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:43 -0400 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]:33430) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDEyG-0006GZ-7Q for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:40 -0400 Received: by mail-wm1-x335.google.com with SMTP id y140-v6so2640969wmd.0 for ; Thu, 18 Oct 2018 13:32:37 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-231-174.clienti.tiscali.it. [78.12.231.174]) by smtp.gmail.com with ESMTPSA id a12-v6sm14270952wrr.71.2018.10.18.13.32.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 13:32:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=PL14QHgu4wUm3jVRt3OniFqE50Ah2xyJTud4OSLrkBE=; b=V74y5okfQw/feRs25ZFB8a+ybemGHr7W+POQGvSUhczQllr14HVevCIIgZ/t5Nn5sN PIXPp+f0nZXCsJq0XKd6qm0sE/e2g8Czy7NNi7BXXM+yuJmXlXlc+lWVcwiV/KwfbVT8 fg4GHh96dsYet6O7gcT8E654L0+BOuhubRzSUogPOFwKsx724aPv7wniidPOVnPVi/b+ NWTS8wO53NPuPYTp/XSPHR7sPBv5pZx+mQ9us+rAoqNMEExxSTnys+2+P130wjgXviIP YmIl2TZtCutaiAQw/YXFT5bj/+/ZmLsqmnOZxSMrM55Im9+iVBBTukZigD624TMyujye EWkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=PL14QHgu4wUm3jVRt3OniFqE50Ah2xyJTud4OSLrkBE=; b=ciB4pASSusTh5xaSbWpQDH7jr6MYuig5EpiJ0PGc2QWTeOHadsUPpPHbkrCzv75rN8 m/KHIM6EVry/g9jY2q1x2ogVKGDCH+a23DtlkIodF0ZL5hoFCwm8JYIS2J/Imwd95yW/ 0SWv9TGmbW41m4FG0pMYRCUk4prMaSiU5/wlCFVdymmtFAJo5v0AoSEfLR7nRM5ZrSdo BBOvQ6RyhhBUB79KeBkmo/6A6YFaGQG8iIiFbauEoTadU0JRxUrmXIOxtwhrJfbHwe3E ZB77WWDoUUjQ8+djAgjCN22fV9iecpKIMAYfwWSXv8i0mffNkIIWGYcvcXwkCZfiw0p8 JfFA== X-Gm-Message-State: ABuFfoiKeqZ0DjZRO4CtK4anALCjyr1670sjUaoMDVSh3lh/8PzchwjB ZfhzKLeg+l8wF/tF3jNgMiGFdnUd X-Google-Smtp-Source: ACcGV60Nhios1cdctUaT6wCfER0cz0wSwtdkq2sBKrZ1uB8ZIawQ48ldIcp4+E98hVIVNcfh9jnslQ== X-Received: by 2002:a1c:700b:: with SMTP id l11-v6mr1773820wmc.81.1539894756343; Thu, 18 Oct 2018 13:32:36 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 22:31:44 +0200 Message-Id: <1539894735-14232-18-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> References: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::335 Subject: [Qemu-devel] [PULL 17/48] vl: refactor -rtc option references X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Artem Pisarenko Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Artem Pisarenko Improve code readability and prepare for fixing bug #1797033 Signed-off-by: Artem Pisarenko Message-Id: <9330a48899f997431a34460014886d118a7c0960.1539846575.git.artem.= k.pisarenko@gmail.com> Signed-off-by: Paolo Bonzini --- vl.c | 84 +++++++++++++++++++++++++++++++++++++++++-----------------------= ---- 1 file changed, 51 insertions(+), 33 deletions(-) diff --git a/vl.c b/vl.c index 4e25c78..d15e086 100644 --- a/vl.c +++ b/vl.c @@ -147,8 +147,13 @@ bool enable_cpu_pm =3D false; int nb_nics; NICInfo nd_table[MAX_NICS]; int autostart; -static int rtc_utc =3D 1; -static int rtc_date_offset =3D -1; /* -1 means no change */ +static enum { + RTC_BASE_UTC, + RTC_BASE_LOCALTIME, + RTC_BASE_DATETIME, +} rtc_base_type =3D RTC_BASE_UTC; +static int rtc_host_datetime_offset =3D -1; /* valid only for host rtc_clo= ck and + rtc_base_type=3DRTC_BASE_DATE= TIME */ QEMUClockType rtc_clock; int vga_interface_type =3D VGA_NONE; static DisplayOptions dpy; @@ -782,26 +787,30 @@ void qemu_system_vmstop_request(RunState state) /***********************************************************/ /* real time host monotonic timer */ =20 -static time_t qemu_time(void) +static time_t qemu_timedate(void) { return qemu_clock_get_ms(QEMU_CLOCK_HOST) / 1000; } =20 /***********************************************************/ -/* host time/date access */ +/* RTC reference time/date access */ void qemu_get_timedate(struct tm *tm, int offset) { - time_t ti =3D qemu_time(); + time_t ti =3D qemu_timedate(); =20 ti +=3D offset; - if (rtc_date_offset =3D=3D -1) { - if (rtc_utc) - gmtime_r(&ti, tm); - else - localtime_r(&ti, tm); - } else { - ti -=3D rtc_date_offset; + + switch (rtc_base_type) { + case RTC_BASE_UTC: gmtime_r(&ti, tm); + break; + case RTC_BASE_LOCALTIME: + localtime_r(&ti, tm); + break; + case RTC_BASE_DATETIME: + ti -=3D rtc_host_datetime_offset; + gmtime_r(&ti, tm); + break; } } =20 @@ -809,23 +818,30 @@ int qemu_timedate_diff(struct tm *tm) { time_t seconds; =20 - if (rtc_date_offset =3D=3D -1) - if (rtc_utc) - seconds =3D mktimegm(tm); - else { - struct tm tmp =3D *tm; - tmp.tm_isdst =3D -1; /* use timezone to figure it out */ - seconds =3D mktime(&tmp); - } - else - seconds =3D mktimegm(tm) + rtc_date_offset; - - return seconds - qemu_time(); + switch (rtc_base_type) { + case RTC_BASE_UTC: + seconds =3D mktimegm(tm); + break; + case RTC_BASE_LOCALTIME: + { + struct tm tmp =3D *tm; + tmp.tm_isdst =3D -1; /* use timezone to figure it out */ + seconds =3D mktime(&tmp); + break; + } + case RTC_BASE_DATETIME: + seconds =3D mktimegm(tm) + rtc_host_datetime_offset; + break; + default: + abort(); + } + + return seconds - qemu_timedate(); } =20 -static void configure_rtc_date_offset(const char *startdate) +static void configure_rtc_host_datetime_offset(const char *startdate) { - time_t rtc_start_date; + time_t rtc_start_datetime; struct tm tm; =20 if (sscanf(startdate, "%d-%d-%dT%d:%d:%d", &tm.tm_year, &tm.tm_mon, @@ -841,15 +857,16 @@ static void configure_rtc_date_offset(const char *sta= rtdate) } tm.tm_year -=3D 1900; tm.tm_mon--; - rtc_start_date =3D mktimegm(&tm); - if (rtc_start_date =3D=3D -1) { + rtc_start_datetime =3D mktimegm(&tm); + if (rtc_start_datetime =3D=3D -1) { date_fail: - error_report("invalid date format"); + error_report("invalid datetime format"); error_printf("valid formats: " "'2006-06-17T16:01:21' or '2006-06-17'\n"); exit(1); } - rtc_date_offset =3D qemu_time() - rtc_start_date; + rtc_host_datetime_offset =3D (qemu_clock_get_ms(QEMU_CLOCK_HOST) / 100= 0) + - rtc_start_datetime; } =20 static void configure_rtc(QemuOpts *opts) @@ -859,15 +876,16 @@ static void configure_rtc(QemuOpts *opts) value =3D qemu_opt_get(opts, "base"); if (value) { if (!strcmp(value, "utc")) { - rtc_utc =3D 1; + rtc_base_type =3D RTC_BASE_UTC; } else if (!strcmp(value, "localtime")) { Error *blocker =3D NULL; - rtc_utc =3D 0; + rtc_base_type =3D RTC_BASE_LOCALTIME; error_setg(&blocker, QERR_REPLAY_NOT_SUPPORTED, "-rtc base=3Dlocaltime"); replay_add_blocker(blocker); } else { - configure_rtc_date_offset(value); + rtc_base_type =3D RTC_BASE_DATETIME; + configure_rtc_host_datetime_offset(value); } } value =3D qemu_opt_get(opts, "clock"); --=20 1.8.3.1