All of lore.kernel.org
 help / color / mirror / Atom feed
From: <lu.zhipeng@zte.com.cn>
To: mdroth@linux.vnet.ibm.com
Cc: qemu-devel@nongnu.org
Subject: [Qemu-devel] 答复: Re: [PATCH v2] qga: replace GetIfEntry
Date: Wed, 8 Nov 2017 10:54:26 +0800 (CST)	[thread overview]
Message-ID: <201711081054264975328@zte.com.cn> (raw)
In-Reply-To: <151007437551.31225.7183381961531333303@sif>

[-- Attachment #1: Type: text/plain, Size: 5917 bytes --]

>I have the modified patch staged here:



>  https://github.com/mdroth/qemu/commit/de597a8b27722ce4f9cc660f930f7dccc712712d>Let me know if it looks okay and I'll send a pull request for rc1


 


the code right, but running QGA on the Windows XP, error: can not find the link to  GetIfEntry2 in iphlpapi.DLL.



















为了让您的VPlat虚拟机故障和docker故障得到高效的处理,请上报故障到: $VPlat技术支持。


芦志朋 luzhipeng






IT开发工程师 IT Development
Engineer
操作系统产品部/中心研究院/系统产品 OS Product Dept./Central R&D Institute/System Product









四川省成都市天府大道中段800号
E: lu.zhipeng@zte.com.cn 
www.zte.com.cn










原始邮件




发件人: <mdroth@linux.vnet.ibm.com>;
收件人:芦志朋10108272;
抄送人: <qemu-devel@nongnu.org>;芦志朋10108272;
日 期 :2017年11月08日 01:07
主 题 :Re: [PATCH v2] qga: replace GetIfEntry






Quoting ZhiPeng Lu (2017-11-03 09:54:20)
> The data obtained by GetIfEntry is 32 bits, and it may overflow. Thus using GetIfEntry2 instead of GetIfEntry.
> 
> Signed-off-by: ZhiPeng Lu <lu.zhipeng@zte.com.cn>
> ---
>  qga/commands-win32.c | 31 ++++++++++++++++++-------------
>  1 file changed, 18 insertions(+), 13 deletions(-)
> 
> diff --git a/qga/commands-win32.c b/qga/commands-win32.c
> index 0322188..d096dc2 100644
> --- a/qga/commands-win32.c
> +++ b/qga/commands-win32.c
> @@ -1173,20 +1173,25 @@ static int guest_get_network_stats(const char *name,
>                         GuestNetworkInterfaceStat *stats)
>  {
>      DWORD if_index = 0;
> -    MIB_IFROW a_mid_ifrow;
> -    memset(&a_mid_ifrow, 0, sizeof(a_mid_ifrow));
> +    OSVERSIONINFO OSver;
>      if_index = get_interface_index(name);
> -    a_mid_ifrow.dwIndex = if_index;
> -    if (NO_ERROR == GetIfEntry(&a_mid_ifrow)) {
> -        stats->rx_bytes = a_mid_ifrow.dwInOctets;
> -        stats->rx_packets = a_mid_ifrow.dwInUcastPkts;
> -        stats->rx_errs = a_mid_ifrow.dwInErrors;
> -        stats->rx_dropped = a_mid_ifrow.dwInDiscards;
> -        stats->tx_bytes = a_mid_ifrow.dwOutOctets;
> -        stats->tx_packets = a_mid_ifrow.dwOutUcastPkts;
> -        stats->tx_errs = a_mid_ifrow.dwOutErrors;
> -        stats->tx_dropped = a_mid_ifrow.dwOutDiscards;
> -        return 0;
> +    OSver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
> +    GetVersionEx(&OSver);
> +    if (OSver.dwMajorVersion >= 6) {
> +        MIB_IF_ROW2 a_mid_ifrow;
> +        memset(&a_mid_ifrow, 0, sizeof(a_mid_ifrow));
> +        a_mid_ifrow.dwIndex = if_index;
> +        if (NO_ERROR == GetIfEntry2(&a_mid_ifrow)) {
> +            stats->rx_bytes = a_mid_ifrow.dwInOctets;
> +            stats->rx_packets = a_mid_ifrow.dwInUcastPkts;
> +            stats->rx_errs = a_mid_ifrow.dwInErrors;
> +            stats->rx_dropped = a_mid_ifrow.dwInDiscards;
> +            stats->tx_bytes = a_mid_ifrow.dwOutOctets;
> +            stats->tx_packets = a_mid_ifrow.dwOutUcastPkts;
> +            stats->tx_errs = a_mid_ifrow.dwOutErrors;
> +            stats->tx_dropped = a_mid_ifrow.dwOutDiscards;
> +            return 0;

This fails to build in my fc20 mingw64 environment:

/home/mdroth/w/qemu4.git/qga/commands-win32.c:1184:20: error: 'MIB_IF_ROW2' has no member named 'dwIndex'
         a_mid_ifrow.dwIndex = if_index;
                    ^
/home/mdroth/w/qemu4.git/qga/commands-win32.c:1186:42: error: 'MIB_IF_ROW2' has no member named 'dwInOctets'
             stats->rx_bytes = a_mid_ifrow.dwInOctets;
                                          ^
/home/mdroth/w/qemu4.git/qga/commands-win32.c:1187:44: error: 'MIB_IF_ROW2' has no member named 'dwInUcastPkts'
             stats->rx_packets = a_mid_ifrow.dwInUcastPkts;

etc ...

The patch seems to assume MIB_IFROW and MIB_IF_ROW2 have the same field names
for the stats, but according to this they're slightly different:

  https://msdn.microsoft.com/en-us/library/windows/desktop/aa814491(v=vs.85).aspx

This change on top of your patch seems to work:

diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index e17fc3c284..58e470877f 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -1181,16 +1181,16 @@ static int guest_get_network_stats(const char *name,
     if (os_ver.dwMajorVersion >= 6) {
         MIB_IF_ROW2 a_mid_ifrow;
         memset(&a_mid_ifrow, 0, sizeof(a_mid_ifrow));
-        a_mid_ifrow.dwIndex = if_index;
+        a_mid_ifrow.InterfaceIndex = if_index;
         if (NO_ERROR == GetIfEntry2(&a_mid_ifrow)) {
-            stats->rx_bytes = a_mid_ifrow.dwInOctets;
-            stats->rx_packets = a_mid_ifrow.dwInUcastPkts;
-            stats->rx_errs = a_mid_ifrow.dwInErrors;
-            stats->rx_dropped = a_mid_ifrow.dwInDiscards;
-            stats->tx_bytes = a_mid_ifrow.dwOutOctets;
-            stats->tx_packets = a_mid_ifrow.dwOutUcastPkts;
-            stats->tx_errs = a_mid_ifrow.dwOutErrors;
-            stats->tx_dropped = a_mid_ifrow.dwOutDiscards;
+            stats->rx_bytes = a_mid_ifrow.InOctets;
+            stats->rx_packets = a_mid_ifrow.InUcastPkts;
+            stats->rx_errs = a_mid_ifrow.InErrors;
+            stats->rx_dropped = a_mid_ifrow.InDiscards;
+            stats->tx_bytes = a_mid_ifrow.OutOctets;
+            stats->tx_packets = a_mid_ifrow.OutUcastPkts;
+            stats->tx_errs = a_mid_ifrow.OutErrors;
+            stats->tx_dropped = a_mid_ifrow.OutDiscards;
             return 0;
         }
     }

I have the modified patch staged here:

  https://github.com/mdroth/qemu/commit/de597a8b27722ce4f9cc660f930f7dccc712712d

Let me know if it looks okay and I'll send a pull request for rc1

> +        }
>      }
>      return -1;
>  }
> -- 
> 1.8.3.1
>

[-- Attachment #2: 24242e5637af428891c4db731e7765ad.jpg --]
[-- Type: image/jpeg, Size: 2064 bytes --]

[-- Attachment #3: 9ae3e214c17d49ed935d87c674ba3ee2.jpg --]
[-- Type: image/jpeg, Size: 6015 bytes --]

  reply	other threads:[~2017-11-08  2:54 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-03 14:54 [Qemu-devel] [PATCH v2] qga: replace GetIfEntry ZhiPeng Lu
2017-11-03 17:54 ` no-reply
2017-11-07 17:06 ` Michael Roth
2017-11-08  2:54   ` lu.zhipeng [this message]
2017-11-09 11:26     ` [Qemu-devel] 答复: " lu.zhipeng
2017-11-13 23:57       ` Michael Roth
2017-11-14  2:32         ` [Qemu-devel] 答复:Re: " lu.zhipeng
2017-11-14 11:09         ` [Qemu-devel] 答复: " lu.zhipeng
2017-11-15  1:21           ` Michael Roth
2017-11-15  1:41             ` [Qemu-devel] 答复: " lu.zhipeng
2017-11-15  2:22               ` Michael Roth
2017-11-15  2:48                 ` [Qemu-devel] 答复: " lu.zhipeng
2017-11-20 21:57               ` [Qemu-devel] " 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=201711081054264975328@zte.com.cn \
    --to=lu.zhipeng@zte.com.cn \
    --cc=mdroth@linux.vnet.ibm.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.