1 Star 0 Fork 126

ZhangBo/qemu_src

forked from src-openEuler/qemu 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
freeclock-add-qmp-command-to-get-time-offset-of-vm-i.patch 3.73 KB
一键复制 编辑 原始数据 按行查看 历史
From 124d427a1fdae2d1eeed433093ec4ab78b81237e Mon Sep 17 00:00:00 2001
From: "shenghualong@huawei.com" <shenghualong@huawei.com>
Date: Thu, 10 Feb 2022 11:11:37 +0800
Subject: [PATCH] freeclock: add qmp command to get time offset of vm in
seconds
When setting the system time in VM, a RTC_CHANGE event will be reported.
However, if libvirt is restarted while the event is be reporting, the
event will be lost and we will get the old time (not the time we set in
VM) after rebooting the VM.
We save the delta time in QEMU and add a rtc-date-diff qmp to get the
delta time so that libvirt can get the latest time in VM according to
the qmp after libvirt is restarted.
Signed-off-by: Peng Liang <liangpeng10@huawei.com>
Signed-off-by: zhangxinhao <zhangxinhao1@huawei.com>
---
include/qemu-common.h | 4 +++-
monitor/qmp-cmds.c | 5 +++++
qapi/misc.json | 9 +++++++++
qapi/pragma.json | 3 ++-
softmmu/rtc.c | 13 ++++++++++++-
5 files changed, 31 insertions(+), 3 deletions(-)
diff --git a/include/qemu-common.h b/include/qemu-common.h
index 73bcf763ed..9ed8832152 100644
--- a/include/qemu-common.h
+++ b/include/qemu-common.h
@@ -27,7 +27,9 @@ int qemu_main(int argc, char **argv, char **envp);
#endif
void qemu_get_timedate(struct tm *tm, int offset);
-int qemu_timedate_diff(struct tm *tm);
+time_t qemu_timedate_diff(struct tm *tm);
+time_t get_rtc_date_diff(void);
+void set_rtc_date_diff(time_t diff);
void *qemu_oom_check(void *ptr);
diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c
index 343353e27a..98868cee03 100644
--- a/monitor/qmp-cmds.c
+++ b/monitor/qmp-cmds.c
@@ -466,3 +466,8 @@ HumanReadableText *qmp_x_query_irq(Error **errp)
return human_readable_text_from_str(buf);
}
+
+int64_t qmp_query_rtc_date_diff(Error **errp)
+{
+ return get_rtc_date_diff();
+}
diff --git a/qapi/misc.json b/qapi/misc.json
index 358548abe1..5b6d653682 100644
--- a/qapi/misc.json
+++ b/qapi/misc.json
@@ -527,3 +527,12 @@
'data': { '*option': 'str' },
'returns': ['CommandLineOptionInfo'],
'allow-preconfig': true }
+
+##
+# @query-rtc-date-diff:
+#
+# get vm's time offset
+#
+# Since: 2.8
+##
+{ 'command': 'query-rtc-date-diff', 'returns': 'int64' }
diff --git a/qapi/pragma.json b/qapi/pragma.json
index 3bc0335d1f..b37f6de445 100644
--- a/qapi/pragma.json
+++ b/qapi/pragma.json
@@ -26,7 +26,8 @@
'qom-get',
'query-tpm-models',
'query-tpm-types',
- 'ringbuf-read' ],
+ 'ringbuf-read',
+ 'query-rtc-date-diff' ],
# Externally visible types whose member names may use uppercase
'member-name-exceptions': [ # visible in:
'ACPISlotType', # query-acpi-ospm-status
diff --git a/softmmu/rtc.c b/softmmu/rtc.c
index 5632684fc9..57bb8bba7c 100644
--- a/softmmu/rtc.c
+++ b/softmmu/rtc.c
@@ -43,6 +43,7 @@ static time_t rtc_ref_start_datetime;
static int rtc_realtime_clock_offset; /* used only with QEMU_CLOCK_REALTIME */
static int rtc_host_datetime_offset = -1; /* valid & used only with
RTC_BASE_DATETIME */
+static time_t rtc_date_diff = 0;
QEMUClockType rtc_clock;
/***********************************************************/
/* RTC reference time/date access */
@@ -84,7 +85,7 @@ void qemu_get_timedate(struct tm *tm, int offset)
}
}
-int qemu_timedate_diff(struct tm *tm)
+time_t qemu_timedate_diff(struct tm *tm)
{
time_t seconds;
@@ -107,6 +108,16 @@ int qemu_timedate_diff(struct tm *tm)
return seconds - qemu_ref_timedate(QEMU_CLOCK_HOST);
}
+time_t get_rtc_date_diff(void)
+{
+ return rtc_date_diff;
+}
+
+void set_rtc_date_diff(time_t diff)
+{
+ rtc_date_diff = diff;
+}
+
static void configure_rtc_base_datetime(const char *startdate)
{
time_t rtc_start_datetime;
--
2.27.0
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ooorz/qemu_src.git
git@gitee.com:ooorz/qemu_src.git
ooorz
qemu_src
qemu_src
master

搜索帮助