qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Denis V. Lunev" <den@openvz.org>
Cc: Michael Roth <mdroth@linux.vnet.ibm.com>,
	Olga Krishtal <okrishtal@parallels.com>,
	qemu-devel@nongnu.org, "Denis V. Lunev" <den@openvz.org>
Subject: [Qemu-devel] [PATCH 10/10] qga: added GuestPCIAddress information
Date: Fri, 19 Jun 2015 19:51:33 +0300	[thread overview]
Message-ID: <1434732693-24127-11-git-send-email-den@openvz.org> (raw)
In-Reply-To: <1434732693-24127-1-git-send-email-den@openvz.org>

From: Olga Krishtal <okrishtal@parallels.com>

PCIAddress inforfation is obtained via SetupApi, which provides the
information about address, bus, etc. We look throught entire device tree
in the system and try to find device object for given volume. For this PDO
SetupDiGetDeviceRegistryProperty is called, which reads PCI configuration
for a given devicei if it is possible.

This is the most convinient way for a userspace service. The lookup is
performed for every volume available. However, this information is
not mandatory for vss-provider.

In order to use SetupApi we need to notify linker about it. We do not need
to install additional libs, so we do not make separate configuration
option to use libsetupapi.su

SetupApi gives as the same information as kernel driver
with IRP_MN_QUERY_INTERFACE.
https://support.microsoft.com/en-us/kb/253232

Signed-off-by: Olga Krishtal <okrishtal@parallels.com>
Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: Eric Blake <eblake@redhat.com>
CC: Michael Roth <mdroth@linux.vnet.ibm.com>
---
 configure            |  2 +-
 qga/commands-win32.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 78 insertions(+), 1 deletion(-)

diff --git a/configure b/configure
index 222694f..bf84c5a 100755
--- a/configure
+++ b/configure
@@ -731,7 +731,7 @@ if test "$mingw32" = "yes" ; then
   sysconfdir="\${prefix}"
   local_statedir=
   confsuffix=""
-  libs_qga="-lws2_32 -lwinmm -lpowrprof $libs_qga"
+  libs_qga="-lsetupapi -lws2_32 -lwinmm -lpowrprof $libs_qga"
 fi
 
 werror=""
diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index 09f0e82..f33ba7c 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -18,6 +18,8 @@
 #include <string.h>
 #include <winioctl.h>
 #include <ntddscsi.h>
+#include <setupapi.h>
+#include <initguid.h>
 #include "qga/guest-agent-core.h"
 #include "qga/vss-win32.h"
 #include "qga-qmp-commands.h"
@@ -29,6 +31,10 @@
 #define SHTDN_REASON_FLAG_PLANNED 0x80000000
 #endif
 
+DEFINE_GUID(GUID_DEVINTERFACE_VOLUME,
+        0x53f5630dL, 0xb6bf, 0x11d0, 0x94, 0xf2,
+        0x00, 0xa0, 0xc9, 0x1e, 0xfb, 0x8b);
+
 /* multiple of 100 nanoseconds elapsed between windows baseline
  *    (1/1/1601) and Unix Epoch (1/1/1970), accounting for leap years */
 #define W32_FT_OFFSET (10000000ULL * 60 * 60 * 24 * \
@@ -811,6 +817,77 @@ done:
 
 static GuestPCIAddress *get_pci_info(char *guid, Error **errp)
 {
+    HDEVINFO dev_info;
+    SP_DEVINFO_DATA dev_info_data;
+    int i;
+    char dev_name[MAX_PATH];
+    char *name = g_strdup(&guid[4]);
+    char *buffer = NULL;
+    if (!QueryDosDevice(name, dev_name, sizeof(dev_name)/sizeof(char))) {
+        error_setg_win32(errp, GetLastError(), "failed to get dos device name");
+        g_free(name);
+        return NULL;
+    }
+    g_free(name);
+
+    dev_info = SetupDiGetClassDevs(&GUID_DEVINTERFACE_VOLUME, 0, 0,
+            DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
+    if (dev_info == INVALID_HANDLE_VALUE) {
+        error_setg_win32(errp, GetLastError(), "failed to get devices tree");
+        return NULL;
+    }
+    dev_info_data.cbSize = sizeof(SP_DEVINFO_DATA);
+    for (i = 0; SetupDiEnumDeviceInfo(dev_info, i, &dev_info_data); i++) {
+        DWORD data, addr, bus, slot, func;
+        GuestPCIAddress *pci;
+        DWORD size = 0;
+
+        while (!SetupDiGetDeviceRegistryProperty(dev_info, &dev_info_data,
+                                SPDRP_PHYSICAL_DEVICE_OBJECT_NAME,
+                                &data, (PBYTE)buffer, size, &size)) {
+            if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
+                if (buffer) {
+                    g_free(buffer);
+                }
+                buffer = g_malloc0(sizeof(char)*(size*2));
+            } else {
+                error_setg_win32(errp, GetLastError(),
+                        "failed to get device name");
+                goto out;
+            }
+        }
+
+        if (g_strcmp0(buffer, dev_name)) {
+            continue;
+        }
+
+        if (!SetupDiGetDeviceRegistryProperty(dev_info, &dev_info_data,
+                    SPDRP_BUSNUMBER, &data, (PBYTE)&bus, size, &size)) {
+                goto out;
+        }
+
+        if (!SetupDiGetDeviceRegistryProperty(dev_info, &dev_info_data,
+                      SPDRP_ADDRESS, &data, (PBYTE)&addr, size, &size)) {
+                goto out;
+        }
+
+        slot = (addr >> 16) & 0xFFFF;
+        func = addr & 0xFFFF;
+        pci = g_malloc0(sizeof(*pci));
+        pci->domain = addr;
+        pci->slot = slot;
+        pci->function = func;
+        pci->bus = bus;
+
+        if (buffer) {
+            g_free(buffer);
+        }
+        return pci;
+    }
+out:
+    if (buffer) {
+        g_free(buffer);
+    }
     return NULL;
 }
 
-- 
1.9.1

  parent reply	other threads:[~2015-06-19 16:48 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-19 16:51 [Qemu-devel] [PATCH v4 0/10] QGA: disk and volume info for Windows & guest exec Denis V. Lunev
2015-06-19 16:51 ` [Qemu-devel] [PATCH 01/10] util, qga: drop guest_file_toggle_flags Denis V. Lunev
2015-06-19 16:51 ` [Qemu-devel] [PATCH 02/10] qga: implement guest-pipe-open command Denis V. Lunev
2015-06-19 16:51 ` [Qemu-devel] [PATCH 03/10] qga: guest exec functionality for Unix guests Denis V. Lunev
2015-06-19 16:51 ` [Qemu-devel] [PATCH 04/10] qga: handle possible SIGPIPE in guest-file-write Denis V. Lunev
2015-06-19 16:51 ` [Qemu-devel] [PATCH 05/10] qga: guest-pipe-open for Windows guest Denis V. Lunev
2015-06-19 16:51 ` [Qemu-devel] [PATCH 06/10] qga: guest exec functionality for Windows guests Denis V. Lunev
2015-06-19 16:51 ` [Qemu-devel] [PATCH 07/10] qga: added empty qmp_quest_get_fsinfo functionality Denis V. Lunev
2015-06-19 16:51 ` [Qemu-devel] [PATCH 08/10] qga: added mountpoint and filesystem type for single volume Denis V. Lunev
2015-06-19 16:51 ` [Qemu-devel] [PATCH 09/10] qga: added bus type and disk location path Denis V. Lunev
2015-06-19 16:51 ` Denis V. Lunev [this message]
  -- strict thread matches above, loose matches on Subject: below --
2015-06-19 16:57 [Qemu-devel] [PATCH v5 0/10] QGA: disk and volume info for Windows & guest exec Denis V. Lunev
2015-06-19 16:57 ` [Qemu-devel] [PATCH 10/10] qga: added GuestPCIAddress information Denis V. Lunev
2015-06-30 10:25 [Qemu-devel] [PATCH v6 0/10] QGA: disk and volume info for Windows & guest exec Denis V. Lunev
2015-06-30 10:25 ` [Qemu-devel] [PATCH 10/10] qga: added GuestPCIAddress information Denis V. Lunev
2015-07-07  4:40 [Qemu-devel] [PULL 00/10] qemu-ga patches for 2.4.0 Michael Roth
2015-07-07  4:40 ` [Qemu-devel] [PATCH 10/10] qga: added GuestPCIAddress information Michael Roth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1434732693-24127-11-git-send-email-den@openvz.org \
    --to=den@openvz.org \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=okrishtal@parallels.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).