[libvirt] [PATCHv4 3/3] qemu: Implement virDomain{Get,Set}Time

Ján Tomko jtomko at redhat.com
Wed May 14 12:37:47 UTC 2014


On 05/07/2014 10:19 AM, Michal Privoznik wrote:
> One caveat though, qemu-ga is expecting time and returning time
> in nanoseconds. With all the buffering and propagation delay, the
> time is already wrong once it gets to the qemu-ga, but there's
> nothing we can do about it.
> 
> Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
> ---
>  src/qemu/qemu_agent.c  |  99 ++++++++++++++++++++++++++++++++++++++++++++
>  src/qemu/qemu_agent.h  |   8 ++++
>  src/qemu/qemu_driver.c | 109 +++++++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 216 insertions(+)

Jan

> 
> diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
> index 4082331..80a820e 100644
> --- a/src/qemu/qemu_agent.c
> +++ b/src/qemu/qemu_agent.c
> @@ -1646,3 +1646,102 @@ qemuAgentUpdateCPUInfo(unsigned int nvcpus,
>  
>      return 0;
>  }
> +
> +
> +int
> +qemuAgentGetTime(qemuAgentPtr mon,
> +                 long long *seconds,
> +                 unsigned int *nseconds)
> +{
> +    int ret = -1;
> +    unsigned long long json_time;
> +    virJSONValuePtr cmd;
> +    virJSONValuePtr reply = NULL;
> +
> +    cmd = qemuAgentMakeCommand("guest-get-time",
> +                               NULL);
> +    if (!cmd)
> +        return ret;
> +
> +    if (qemuAgentCommand(mon, cmd, &reply, true,
> +                         VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK) < 0)
> +        goto cleanup;
> +

> +    if (!reply || qemuAgentCheckError(cmd, reply) < 0)
> +        goto cleanup;
> +

Here too.

> +    if (virJSONValueObjectGetNumberUlong(reply, "return", &json_time) < 0) {
> +        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> +                       _("malformed return value"));
> +        goto cleanup;
> +    }
> +

...

> +
> +
> +/**
> + * qemuAgentSetTime:
> + * @setTime: time to set
> + * @sync: let guest agent to read domain's RTC (@setTime is ignored)
> + */
> +int
> +qemuAgentSetTime(qemuAgentPtr mon,
> +                long long seconds,
> +                unsigned int nseconds,
> +                bool sync)
> +{
> +    int ret = -1;
> +    virJSONValuePtr cmd;
> +    virJSONValuePtr reply = NULL;
> +

...

> +
> +    if (!cmd)
> +        return ret;
> +
> +    if (qemuAgentCommand(mon, cmd, &reply, true,
> +                         VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK) < 0)
> +        goto cleanup;
> +

> +    if (!reply || qemuAgentCheckError(cmd, reply) < 0)
> +        goto cleanup;

This should be checked by qemuAgentCommand already.

> +
> +    ret = 0;
> + cleanup:
> +    virJSONValueFree(cmd);
> +    virJSONValueFree(reply);
> +    return ret;
> +}

> @@ -16717,6 +16824,8 @@ static virDriver qemuDriver = {
>      .domainMigrateFinish3Params = qemuDomainMigrateFinish3Params, /* 1.1.0 */
>      .domainMigrateConfirm3Params = qemuDomainMigrateConfirm3Params, /* 1.1.0 */
>      .connectGetCPUModelNames = qemuConnectGetCPUModelNames, /* 1.1.3 */
> +    .domainGetTime = qemuDomainGetTime, /* 1.2.4 */
> +    .domainSetTime = qemuDomainSetTime, /* 1.2.4 */

1.2.5

>  };
>  
>  
> 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20140514/c62472ef/attachment-0001.sig>


More information about the libvir-list mailing list