diff options
author | Sameeh Jubran <sjubran@redhat.com> | 2018-06-24 15:45:40 +0300 |
---|---|---|
committer | Michael Roth <mdroth@linux.vnet.ibm.com> | 2018-07-23 18:45:21 -0500 |
commit | c5840b905e3e471833b277a27910f577d0e30d59 (patch) | |
tree | 475433578a4a5ee642733c20687d41b696fcb71a /qga/commands-win32.c | |
parent | 4eecc2e212bae7308d8582d99f665dfc253c9dda (diff) | |
download | qemu-c5840b905e3e471833b277a27910f577d0e30d59.zip qemu-c5840b905e3e471833b277a27910f577d0e30d59.tar.gz qemu-c5840b905e3e471833b277a27910f577d0e30d59.tar.bz2 |
qga-win: Handle fstrim for OSes lower than Win8
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 <sjubran@redhat.com>
* use alternative version query code proposed by Sameeh
* fix up version check logic
* avoid CamelCase variable names when possible
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Diffstat (limited to 'qga/commands-win32.c')
-rw-r--r-- | qga/commands-win32.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 318d760..98d9735 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -865,6 +865,19 @@ qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error **errp) GuestFilesystemTrimResponse *resp; HANDLE handle; WCHAR guid[MAX_PATH] = L""; + OSVERSIONINFO osvi; + BOOL win8_or_later; + + ZeroMemory(&osvi, sizeof(OSVERSIONINFO)); + osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + GetVersionEx(&osvi); + win8_or_later = (osvi.dwMajorVersion > 6 || + ((osvi.dwMajorVersion == 6) && + (osvi.dwMinorVersion >= 2))); + if (!win8_or_later) { + error_setg(errp, "fstrim is only supported for Win8+"); + return NULL; + } handle = FindFirstVolumeW(guid, ARRAYSIZE(guid)); if (handle == INVALID_HANDLE_VALUE) { |