[libvirt] [PATCH 1/3] qemu_agent: Create file system freeze and thaw functions

Jiri Denemark jdenemar at redhat.com
Tue Jan 24 18:21:01 UTC 2012


On Tue, Jan 24, 2012 at 18:37:43 +0100, Michal Privoznik wrote:
> These functions simply issue command to guest agent which
> should freeze or unfreeze all file systems within guest.
> ---
>  src/qemu/qemu_agent.c |   68 +++++++++++++++++++++++++++++++++++++++++++++++++
>  src/qemu/qemu_agent.h |    3 ++
>  2 files changed, 71 insertions(+), 0 deletions(-)
> 
> diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
> index 6a7c7b3..3a5cc4b 100644
> --- a/src/qemu/qemu_agent.c
> +++ b/src/qemu/qemu_agent.c
> @@ -1110,3 +1110,71 @@ int qemuAgentShutdown(qemuAgentPtr mon,
>      virJSONValueFree(reply);
>      return ret;
>  }
> +
> +/*
> + * qemuAgentFSFreeze:
> + * @mon: Agent
> + *
> + * Issue guest-fsfreeze-freeze command to guest agent,
> + * which freezes all mounted file systems and returns
> + * number of frozen file systems on success.
> + *
> + * Returns: number of file system frozen on success,
> + *          -1 on error.
> + */
> +int qemuAgentFSFreeze(qemuAgentPtr mon)
> +{
> +    int ret = -1;
> +    virJSONValuePtr cmd;
> +    virJSONValuePtr reply = NULL;
> +
> +    cmd = qemuAgentMakeCommand("guest-fsfreeze-freeze", NULL);
> +
> +    if (!cmd)
> +        return -1;
> +
> +    if (qemuAgentCommand(mon, cmd, &reply) < 0 ||
> +        qemuAgentCheckError(cmd, reply) < 0)
> +        goto cleanup;
> +
> +    virJSONValueObjectGetNumberInt(reply, "return", &ret);

Doesn't the above function need to be checked for errors? That is, what if
there's no "return" key in the reply? In json monitor code, we usually have
something like the following code:

        if (virJSONValueObjectGetNumberInt(reply, "return", &ret) < 0) {
            qemuReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                            _("guest-fsfreeze-freeze reply was missing return"
                              " data"));
        }

> +
> +cleanup:
> +    virJSONValueFree(cmd);
> +    virJSONValueFree(reply);
> +    return ret;
> +}
> +
> +/*
> + * qemuAgentFSThaw:
> + * @mon: Agent
> + *
> + * Issue guest-fsfreeze-thaw command to guest agent,
> + * which unfreezes all mounted file systems and returns
> + * number of thawed file systems on success.
> + *
> + * Returns: number of file system thawed on success,
> + *          -1 on error.
> + */
> +int qemuAgentFSThaw(qemuAgentPtr mon)
> +{
> +    int ret = -1;
> +    virJSONValuePtr cmd;
> +    virJSONValuePtr reply = NULL;
> +
> +    cmd = qemuAgentMakeCommand("guest-fsfreeze-thaw", NULL);
> +
> +    if (!cmd)
> +        return -1;
> +
> +    if (qemuAgentCommand(mon, cmd, &reply) < 0 ||
> +        qemuAgentCheckError(cmd, reply) < 0)
> +        goto cleanup;
> +
> +    virJSONValueObjectGetNumberInt(reply, "return", &ret);

And similar check for this line as well.

> +
> +cleanup:
> +    virJSONValueFree(cmd);
> +    virJSONValueFree(reply);
> +    return ret;
> +}
> diff --git a/src/qemu/qemu_agent.h b/src/qemu/qemu_agent.h
> index 93c2ae7..df59ef7 100644
> --- a/src/qemu/qemu_agent.h
> +++ b/src/qemu/qemu_agent.h
> @@ -66,4 +66,7 @@ typedef enum {
>  int qemuAgentShutdown(qemuAgentPtr mon,
>                        qemuAgentShutdownMode mode);
>  
> +int qemuAgentFSFreeze(qemuAgentPtr mon);
> +int qemuAgentFSThaw(qemuAgentPtr mon);
> +
>  #endif /* __QEMU_AGENT_H__ */
> -- 
> 1.7.3.4
> 
> --
> libvir-list mailing list
> libvir-list at redhat.com
> https://www.redhat.com/mailman/listinfo/libvir-list




More information about the libvir-list mailing list