qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v4 08/10] qemu-ga: call Windows VSS requester in


From: Laszlo Ersek
Subject: Re: [Qemu-devel] [PATCH v4 08/10] qemu-ga: call Windows VSS requester in fsfreeze command handler
Date: Mon, 01 Jul 2013 15:29:10 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130513 Thunderbird/17.0.6

some comments below

On 06/06/13 17:06, Tomoki Sekiyama wrote:
> Support guest-fsfreeze-freeze and guest-fsfreeze-thaw commands for Windows
> guests. When fsfreeze command is issued, it calls the VSS requester to
> freeze filesystems and applications. On thaw command, it again tells the VSS
> requester to thaw them.
> 
> This also adds calling of initialize functions for the VSS requester.
> 
> Signed-off-by: Tomoki Sekiyama <address@hidden>
> ---
>  qga/commands-win32.c |   74 
> ++++++++++++++++++++++++++++++++++++++++++++++----
>  qga/main.c           |   33 ++++++++++++++++++++++
>  2 files changed, 100 insertions(+), 7 deletions(-)
> 
> diff --git a/qga/commands-win32.c b/qga/commands-win32.c
> index 24e4ad0..67dca60 100644
> --- a/qga/commands-win32.c
> +++ b/qga/commands-win32.c
> @@ -15,6 +15,7 @@
>  #include <wtypes.h>
>  #include <powrprof.h>
>  #include "qga/guest-agent-core.h"
> +#include "qga/vss-win32-requester.h"
>  #include "qga-qmp-commands.h"
>  #include "qapi/qmp/qerror.h"
>  
> @@ -151,34 +152,95 @@ void qmp_guest_file_flush(int64_t handle, Error **err)
>      error_set(err, QERR_UNSUPPORTED);
>  }
>  
> +#ifdef HAS_VSS_SDK
> +

(CONFIG_... as we've discussed)

>  /*
>   * Return status of freeze/thaw
>   */
>  GuestFsfreezeStatus qmp_guest_fsfreeze_status(Error **err)
>  {
> -    error_set(err, QERR_UNSUPPORTED);
> -    return 0;
> +    if (!vss_initialized()) {
> +        error_set(err, QERR_UNSUPPORTED);
> +        return 0;
> +    }
> +
> +    if (ga_is_frozen(ga_state)) {
> +        return GUEST_FSFREEZE_STATUS_FROZEN;
> +    }
> +
> +    return GUEST_FSFREEZE_STATUS_THAWED;
>  }
>  
>  /*
> - * Walk list of mounted file systems in the guest, and freeze the ones which
> - * are real local file systems.
> + * Freeze local file systems using Volume Shadow-copy Service.
> + * The frozen state is limited for up to 10 seconds by VSS.
>   */
>  int64_t qmp_guest_fsfreeze_freeze(Error **err)
>  {
> -    error_set(err, QERR_UNSUPPORTED);
> +    int i;
> +
> +    slog("guest-fsfreeze called");
> +
> +    if (!vss_initialized()) {
> +        error_set(err, QERR_UNSUPPORTED);
> +        return 0;
> +    }
> +
> +    /* cannot risk guest agent blocking itself on a write in this state */
> +    ga_set_frozen(ga_state);

Great! I wasn't expecting this, but in retrospect I don't know why :)

> +
> +    qga_vss_fsfreeze_freeze(&i, err);
> +    if (error_is_set(err)) {
> +        goto error;
> +    }
> +
> +    return i;
> +
> +error:
> +    qmp_guest_fsfreeze_thaw(NULL);

Passing NULL here as "errp" concerns me slightly. I've been assuming
that "errp" is never NULL due to the outermost QMP layer always wanting
to receive errors and to serialize them.

Specifically, a NULL "errp" would turn all error_set*(errp, ...) calls
into no-ops under qmp_guest_fsfreeze_thaw(), and all error_is_set(errp)
questions would answer with false. That said, nothing seems to be
affected right now.

Maybe a dummy local variable would be more future-proof... OTOH it would
be stylistically questionable :)


Because of the initial hEvent2 check in qga_vss_fsfreeze_thaw(), it
should be safe to call at any time AFAICS. OK.

>      return 0;
>  }
>  
>  /*
> - * Walk list of frozen file systems in the guest, and thaw them.
> + * Thaw local file systems using Volume Shadow-copy Service.
>   */
>  int64_t qmp_guest_fsfreeze_thaw(Error **err)
>  {
> +    int i;
> +
> +    if (!vss_initialized()) {
> +        error_set(err, QERR_UNSUPPORTED);
> +        return 0;
> +    }
> +
> +    qga_vss_fsfreeze_thaw(&i, err);

I wonder how libvirt interprets a failure to thaw -- does it expect
filesystems to remain frozen? (CC'ing Eric.)

For example, the VSS_E_HOLD_WRITES_TIMEOUT error is reported on the next
thaw attempt, but when this error occurs, filesystems have been
auto-thawed I think.

Anyway I can't suggest anything fail-safe here.

> +
> +    ga_unset_frozen(ga_state);
> +    return i;
> +}
> +
> +#else

(maybe mention the macro in a comment that the #else depends on here)

> +
> +GuestFsfreezeStatus qmp_guest_fsfreeze_status(Error **err)
> +{
> +    error_set(err, QERR_UNSUPPORTED);
> +    return 0;
> +}
> +
> +int64_t qmp_guest_fsfreeze_freeze(Error **err)
> +{
> +    error_set(err, QERR_UNSUPPORTED);
> +    return 0;
> +}
> +
> +int64_t qmp_guest_fsfreeze_thaw(Error **err)
> +{
>      error_set(err, QERR_UNSUPPORTED);
>      return 0;
>  }
>  
> +#endif
> +
>  /*
>   * Walk list of mounted file systems in the guest, and discard unused
>   * areas.
> diff --git a/qga/main.c b/qga/main.c
> index 0e04e73..8bcedaf 100644
> --- a/qga/main.c
> +++ b/qga/main.c
> @@ -34,6 +34,10 @@
>  #include "qemu/bswap.h"
>  #ifdef _WIN32
>  #include "qga/service-win32.h"
> +#ifdef HAS_VSS_SDK
> +#include "qga/vss-win32-provider.h"
> +#include "qga/vss-win32-requester.h"
> +#endif

The protection of #include "qga/vss-win32-requester.h" is inconsistent
between "commands-win32.c" and "qga/main.c". For now the header only
brings in a few prototypes, which shouldn't cause trouble in
"commands-win32.c" even without VSS. Still consistent guarding would be
nice.


>  #include <windows.h>
>  #endif
>  #ifdef __linux__
> @@ -701,6 +705,25 @@ static gboolean channel_init(GAState *s, const gchar 
> *method, const gchar *path)
>  }
>  
>  #ifdef _WIN32
> +
> +static gboolean vss_win32_init(void)
> +{
> +#ifdef HAS_VSS_SDK
> +    if (FAILED(vss_init())) {
> +        g_critical("failed to initialize VSS");
> +        return false;
> +    }
> +#endif
> +    return true;
> +}
> +
> +static void vss_win32_deinit(void)
> +{
> +#ifdef HAS_VSS_SDK
> +    vss_deinit();
> +#endif
> +}
> +
>  DWORD WINAPI service_ctrl_handler(DWORD ctrl, DWORD type, LPVOID data,
>                                    LPVOID ctx)
>  {
> @@ -743,8 +766,12 @@ VOID WINAPI service_main(DWORD argc, TCHAR *argv[])
>      service->status.dwWaitHint = 0;
>      SetServiceStatus(service->status_handle, &service->status);
>  
> +    if (!vss_win32_init()) {
> +        goto out_bad;
> +    }
>      g_main_loop_run(ga_state->main_loop);
> -
> +    vss_win32_deinit();
> +out_bad:
>      service->status.dwCurrentState = SERVICE_STOPPED;
>      SetServiceStatus(service->status_handle, &service->status);
>  }
> @@ -1175,7 +1202,11 @@ int main(int argc, char **argv)
>              { (char *)QGA_SERVICE_NAME, service_main }, { NULL, NULL } };
>          StartServiceCtrlDispatcher(service_table);
>      } else {
> +        if (!vss_win32_init()) {
> +            goto out_bad;
> +        }
>          g_main_loop_run(ga_state->main_loop);
> +        vss_win32_deinit();
>      }
>  #endif

Reviewed-by: Laszlo Ersek <address@hidden>


... This patch made me look at ga_command_state_cleanup_all().
Apparently the POSIX flavor thaws filesystems if qemu-ga exits before a
thaw command over QMP; see guest_fsfreeze_cleanup() and
ga_command_state_init(). Do you think something similar would be useful
for the Windows flavor as well?

Thanks
Laszlo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]