From patchwork Tue Oct 23 11:23:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?VG9tw6HFoSBHb2xlbWJpb3Zza8O9?= X-Patchwork-Id: 988145 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42fWHy0l6Jz9sN9 for ; Tue, 23 Oct 2018 22:24:30 +1100 (AEDT) Received: from localhost ([::1]:40274 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gEunT-0001u2-Hm for incoming@patchwork.ozlabs.org; Tue, 23 Oct 2018 07:24:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42813) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gEumk-0001qs-Ji for qemu-devel@nongnu.org; Tue, 23 Oct 2018 07:23:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gEumi-0007l6-Fg for qemu-devel@nongnu.org; Tue, 23 Oct 2018 07:23:42 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:38736) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gEumi-0007h8-86 for qemu-devel@nongnu.org; Tue, 23 Oct 2018 07:23:40 -0400 Received: by mail-wr1-f68.google.com with SMTP id d10-v6so1269909wrs.5 for ; Tue, 23 Oct 2018 04:23:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=s29R5/FRXevPoLX8I6gNciHnAQejaKibg9gsiOhCzVk=; b=ZSzc/y8c7oLG5dstCtO5Mp/lv9nXfZR8/sHlNk/D21zwPujpaiRgnhVdJDEdCYhgFE 4rEXwWCWKjr+/CqKtnclNfbWqYa9D5c4eCi+foivUIVSL0Xmv7jpU1NNFgvPUuKbck+T Xp/BhioKl9oyBDqPM4tnZ9IhetRDRzXrLZCCxS0jPJcub8ot4x1LuQw9b02awoOVxZKi ORFkmwLFINEoZhEA1jr+nUXQu5pAbNnD6FX8IIt9BIH3QMsse7W2KlOzQfBDGX2z9TUQ QzVMNuBazhNfFEKin0CNDaFB5YFXq3YJsZ7LXVgg67YJ3NA/dLRRJKhgMc5S383oWbh4 oC+A== X-Gm-Message-State: ABuFfogR1vT8HoV2Wm8S13j8aq9dER16wfz5QoTRv8gE3QHAbKEu6CzB jP5ORH+g3pb4zVTLVebgdXDjLiNFrLo= X-Google-Smtp-Source: ACcGV61fIvfFMiS//R5xFQ4ggAEhbvCP+85L1BpFkFzQz3Nfx/AGCjJzYj3Xxcm/K+7bGcXsMVJZ+g== X-Received: by 2002:a5d:5342:: with SMTP id t2-v6mr48455275wrv.257.1540293816944; Tue, 23 Oct 2018 04:23:36 -0700 (PDT) Received: from localhost.localdomain (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id g8-v6sm1498990wmf.45.2018.10.23.04.23.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Oct 2018 04:23:36 -0700 (PDT) From: =?utf-8?b?VG9tw6HFoSBHb2xlbWJpb3Zza8O9?= To: qemu-devel@nongnu.org Date: Tue, 23 Oct 2018 13:23:18 +0200 Message-Id: <4a25866e48d9e3bb5c0b35547b723d1f4806b3c8.1540293796.git.tgolembi@redhat.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: References: MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.221.68 Subject: [Qemu-devel] [PATCH v5 09/14] qga-win: refactor disk properties (bus) X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , Olga Krishtal , =?utf-8?b?VG9tw6HFoSBHb2xlbWJpb3Zza8O9?= , Sameeh Jubran , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Refactor code that queries bus type to be more generic. The function get_disk_bus_type() has been renamed to build_guest_disk_info(). Following commit(s) will extend this function. Signed-off-by: Tomáš Golembiovský --- qga/commands-win32.c | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/qga/commands-win32.c b/qga/commands-win32.c index a3d28d06b3..5ebacd241f 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -588,25 +588,28 @@ out: return pci; } -static int get_disk_bus_type(HANDLE vol_h, Error **errp) +static void get_disk_properties(HANDLE vol_h, GuestDiskAddress *disk, + Error **errp) { STORAGE_PROPERTY_QUERY query; STORAGE_DEVICE_DESCRIPTOR *dev_desc, buf; DWORD received; + ULONG size = sizeof(buf); dev_desc = &buf; - dev_desc->Size = sizeof(buf); query.PropertyId = StorageDeviceProperty; query.QueryType = PropertyStandardQuery; if (!DeviceIoControl(vol_h, IOCTL_STORAGE_QUERY_PROPERTY, &query, sizeof(STORAGE_PROPERTY_QUERY), dev_desc, - dev_desc->Size, &received, NULL)) { + size, &received, NULL)) { error_setg_win32(errp, GetLastError(), "failed to get bus type"); - return -1; + return; } + disk->bus_type = find_bus_type(dev_desc->BusType); + g_debug("bus type %d", disk->bus_type); - return dev_desc->BusType; + return; } /* VSS provider works with volumes, thus there is no difference if @@ -618,8 +621,8 @@ static GuestDiskAddressList *build_guest_disk_info(char *guid, Error **errp) GuestDiskAddress *disk; SCSI_ADDRESS addr, *scsi_ad; DWORD len; - int bus; HANDLE vol_h; + Error *local_err = NULL; scsi_ad = &addr; char *name = g_strndup(guid, strlen(guid)-1); @@ -629,26 +632,27 @@ static GuestDiskAddressList *build_guest_disk_info(char *guid, Error **errp) 0, NULL); if (vol_h == INVALID_HANDLE_VALUE) { error_setg_win32(errp, GetLastError(), "failed to open volume"); - goto out_free; + goto err; } - g_debug("getting bus type"); - bus = get_disk_bus_type(vol_h, errp); - if (bus < 0) { - goto out_close; + disk = g_malloc0(sizeof(*disk)); + get_disk_properties(vol_h, disk, &local_err); + if (local_err) { + error_propagate(errp, local_err); + goto err_close; } - disk = g_malloc0(sizeof(*disk)); - disk->bus_type = find_bus_type(bus); g_debug("bus type %d", disk->bus_type); /* always set pci_controller as required by schema. get_pci_info() should * report -1 values for non-PCI buses rather than fail. */ disk->pci_controller = get_pci_info(name, errp); - if (bus == BusTypeScsi || bus == BusTypeAta || bus == BusTypeRAID + if (disk->bus_type == GUEST_DISK_BUS_TYPE_SCSI + || disk->bus_type == GUEST_DISK_BUS_TYPE_IDE + || disk->bus_type == GUEST_DISK_BUS_TYPE_RAID #if (_WIN32_WINNT >= 0x0600) /* This bus type is not supported before Windows Server 2003 SP1 */ - || bus == BusTypeSas + || disk->bus_type == GUEST_DISK_BUS_TYPE_SAS #endif ) { /* We are able to use the same ioctls for different bus types @@ -668,11 +672,17 @@ static GuestDiskAddressList *build_guest_disk_info(char *guid, Error **errp) list = g_malloc0(sizeof(*list)); list->value = disk; list->next = NULL; -out_close: CloseHandle(vol_h); -out_free: g_free(name); return list; + +err_close: + g_free(disk); + CloseHandle(vol_h); +err: + g_free(name); + + return NULL; } #else