[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL v2 13/24] qga-win: refactor disk info
From: |
Michael Roth |
Subject: |
[Qemu-devel] [PULL v2 13/24] qga-win: refactor disk info |
Date: |
Tue, 30 Oct 2018 20:38:10 -0500 |
From: Tomáš Golembiovský <address@hidden>
Refactor building of disk info into a function that builds the list and
a function that returns infor for single disk. This will be used in
future commit that will handle multi-disk volumes.
Signed-off-by: Tomáš Golembiovský <address@hidden>
Signed-off-by: Michael Roth <address@hidden>
---
qga/commands-win32.c | 52 +++++++++++++++++++++++++++++---------------
1 file changed, 35 insertions(+), 17 deletions(-)
diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index 2d7b56d538..21a88d31e1 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -667,20 +667,15 @@ out_free:
return;
}
-/* VSS provider works with volumes, thus there is no difference if
- * the volume consist of spanned disks. Info about the first disk in the
- * volume is returned for the spanned disk group (LVM) */
-static GuestDiskAddressList *build_guest_disk_info(char *guid, Error **errp)
+static void get_single_disk_info(char *name, GuestDiskAddress *disk,
+ Error **errp)
{
- GuestDiskAddressList *list = NULL;
- GuestDiskAddress *disk;
SCSI_ADDRESS addr, *scsi_ad;
DWORD len;
HANDLE vol_h;
Error *local_err = NULL;
scsi_ad = &addr;
- char *name = g_strndup(guid, strlen(guid)-1);
g_debug("getting disk info for: %s", name);
vol_h = CreateFile(name, 0, FILE_SHARE_READ, NULL, OPEN_EXISTING,
@@ -690,7 +685,6 @@ static GuestDiskAddressList *build_guest_disk_info(char
*guid, Error **errp)
goto err;
}
- disk = g_malloc0(sizeof(*disk));
get_disk_properties(vol_h, disk, &local_err);
if (local_err) {
error_propagate(errp, local_err);
@@ -730,20 +724,44 @@ static GuestDiskAddressList *build_guest_disk_info(char
*guid, Error **errp)
* information about volume. */
}
- list = g_malloc0(sizeof(*list));
- list->value = disk;
- list->next = NULL;
- CloseHandle(vol_h);
- g_free(name);
- return list;
-
err_close:
- g_free(disk);
CloseHandle(vol_h);
err:
+ return;
+}
+
+/* VSS provider works with volumes, thus there is no difference if
+ * the volume consist of spanned disks. Info about the first disk in the
+ * volume is returned for the spanned disk group (LVM) */
+static GuestDiskAddressList *build_guest_disk_info(char *guid, Error **errp)
+{
+ Error *local_err = NULL;
+ GuestDiskAddressList *list = NULL, *cur_item = NULL;
+ GuestDiskAddress *disk = NULL;
+
+ /* strip final backslash */
+ char *name = g_strdup(guid);
+ if (g_str_has_suffix(name, "\\")) {
+ name[strlen(name) - 1] = 0;
+ }
+
+ disk = g_malloc0(sizeof(GuestDiskAddress));
+ get_single_disk_info(name, disk, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ goto out;
+ }
+
+ cur_item = g_malloc0(sizeof(*list));
+ cur_item->value = disk;
+ disk = NULL;
+ list = cur_item;
+
+out:
+ qapi_free_GuestDiskAddress(disk);
g_free(name);
- return NULL;
+ return list;
}
#else
--
2.17.1
- [Qemu-devel] [PULL v2 00/24] qemu-ga patch queue for soft-freeze, Michael Roth, 2018/10/30
- [Qemu-devel] [PULL v2 09/24] build: rename CONFIG_QGA_NTDDDISK to CONFIG_QGA_NTDDSCSI, Michael Roth, 2018/10/30
- [Qemu-devel] [PULL v2 11/24] qga-win: refactor disk properties (bus), Michael Roth, 2018/10/30
- [Qemu-devel] [PULL v2 13/24] qga-win: refactor disk info,
Michael Roth <=
- [Qemu-devel] [PULL v2 12/24] qga-win: report disk serial number, Michael Roth, 2018/10/30
- [Qemu-devel] [PULL v2 15/24] qga-win: return disk device in guest-get-fsinfo, Michael Roth, 2018/10/30
- [Qemu-devel] [PULL v2 10/24] qga-win: add debugging information, Michael Roth, 2018/10/30
- [Qemu-devel] [PULL v2 14/24] qga-win: handle multi-disk volumes, Michael Roth, 2018/10/30
- [Qemu-devel] [PULL v2 20/24] qga: move w32 service handling out of run_agent(), Michael Roth, 2018/10/30
- [Qemu-devel] [PULL v2 19/24] qga: hang GAConfig/socket_activation off of GAState global, Michael Roth, 2018/10/30
- [Qemu-devel] [PULL v2 17/24] qga: fix an off-by-one issue, Michael Roth, 2018/10/30
- [Qemu-devel] [PULL v2 01/24] qga: Support Unicode paths in guest-file-open on win32, Michael Roth, 2018/10/30
- [Qemu-devel] [PULL v2 21/24] qga: add --retry-path option for re-initializing channel on failure, Michael Roth, 2018/10/30
- [Qemu-devel] [PULL v2 18/24] qga: group agent init/cleanup init separate routines, Michael Roth, 2018/10/30