From: Sameeh Jubran <sjub...@redhat.com> The defrag.exe tool which is used for executing the fstrim command on Windows doesn't support retrim for OSes lower than Win8. This commit handles this case and returns a suitable error.
Output of fstrim before this commit: {"execute":"guest-fstrim"} {"return": {"paths": [{"path": "C:\\", "error": "An invalid command line option was specified. (0x89000008)"}, {"path": "F:\\", "error": "An invalid command line option was specified. (0x89000008)"}, {"path": "S:\\", "error": "An invalid command line option was specified. (0x89000008)"}]}} Reported on: https://bugzilla.redhat.com/show_bug.cgi?id=1594113 Signed-off-by: Sameeh Jubran <sjub...@redhat.com> --- qga/commands-win32.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/qga/commands-win32.c b/qga/commands-win32.c index d79974f212..0bdcd9dd38 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -30,6 +30,7 @@ #include <lm.h> #include <wtsapi32.h> #include <wininet.h> +#include <versionhelpers.h> #include "qga/guest-agent-core.h" #include "qga/vss-win32.h" @@ -852,6 +853,11 @@ qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error **errp) HANDLE handle; WCHAR guid[MAX_PATH] = L""; + if (!IsWindows8OrGreater()) { + error_setg(errp, "fstrim is only supported for Win8+"); + return NULL; + } + handle = FindFirstVolumeW(guid, ARRAYSIZE(guid)); if (handle == INVALID_HANDLE_VALUE) { error_setg_win32(errp, GetLastError(), "failed to find any volume"); -- 2.13.6