Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disk.IOCounters() fails in virtual windows #1094

Closed
sskserk opened this issue Jul 7, 2021 · 9 comments · Fixed by #1296
Closed

disk.IOCounters() fails in virtual windows #1094

sskserk opened this issue Jul 7, 2021 · 9 comments · Fixed by #1296

Comments

@sskserk
Copy link

sskserk commented Jul 7, 2021

Describe the bug
Executing of disk.IOCounters() in Virtual Windows (WEMU or VMWare) player results in error:
"The system cannot find the path specified"

To Reproduce
Compile the following code with the CLI: GOOS=windows go build -tags windows -o file.exe file.go

	_, err := disk.IOCounters()
	if err != nil {
		panic(err)
	}

Expected behavior
Returned disk io counters

Additional context

  • The code is compiled on Ubuntu 20.04 and executed on virtual Windows Server 2019 running in VMWare Player. Host is Ubuntu 20.04
  • Debugging of the source revealed that the path "\.\c:" cannot be found. The failure is observed in this piece of code
    err = windows.DeviceIoControl(h, IOCTL_DISK_PERFORMANCE, nil, 0, (*byte)(unsafe.Pointer(&diskPerformance)), uint32(unsafe.Sizeof(diskPerformance)), &diskPerformanceSize, nil)
@Lomanic
Copy link
Collaborator

Lomanic commented Aug 18, 2021

What surprises me here is that if the path is really missing the loop's step should be skipped above, is C: mounted and accessible? What happens if you replace these lines by these that check for this specific error, do you get some results back or all disks are skipped?

I won't be able to test in VMWare Player unfortunately, but I implemented this part on Virtualbox though, there shouldn't be much difference in my opinion.

@mixmind
Copy link

mixmind commented Oct 10, 2021

Hi, it dont collect information after adding check that you proposed but fixed error. Yes, C: is mounted and accesible, but discovered path is incorrect...
Had you received data in Virtualbox?

@xgfone
Copy link

xgfone commented Apr 15, 2022

I met with the trouble.

  1. Build the app with github.com/shirou/gopsutil/v3/disk on Windows 10 64bit.
  2. Run it in the Windows 10(Physical Host), and it's OK.
  3. Run it in the Virtual Windows 10 (QEMU 2.8), and it's OK.
  4. Run it in the Virtual Windows 2008~2019 Standard/DataCenter (QEMU 2.8). It does not work and reports the error The system cannot find the file specified..

@xgfone
Copy link

xgfone commented Apr 15, 2022

@Lomanic

  • For Windows 7 & 10, it is OK.
  • For all Windows Server 2008~2019, it does not work and reports the error.

@xgfone
Copy link

xgfone commented Apr 15, 2022

refer to #883, run diskperf -y, then it's OK.

@Lomanic
Copy link
Collaborator

Lomanic commented Apr 15, 2022

Thanks for linking the two issues together and finding a workaround @xgfone!

That probably explains why I couldn't reproduce #883 on Win7 x32 as it seems to only affect Server editions.

As I asked in #883 (comment), can you tell us if you can reproduce again after you run diskperf.exe -N? Can you check if diskperf.exe -Y creates the registry entry mentioned in #883 (comment) so we could automate this in gopsutil?

@xgfone
Copy link

xgfone commented Apr 16, 2022

@Lomanic I have done the tests as follow.

  • For Windows 10 64bit,
    1. diskperf.exe -N has no effect, and disk.IOCounters() returns always success.
    2. Execute diskperf.exe -Y, and check HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\PartMgr, no EnableCounterForIoctl.
  • For Windows Server 2008~2019,
    1. Call disk.IOCounters(), and return the error The system cannot find the file specified..
    2. Execute the command diskperf.exe -Y, then call disk.IOCounters() again, and it is OK.
    3. Check HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\PartMgr, EnableCounterForIoctl is set to 1.
    4. Execute the command diskperf.exe -N, then call disk.IOCounters() again, and it returns the error above.
    5. Again check HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\PartMgr, EnableCounterForIoctl has been deleted.
    6. Execute the command diskperf.exe -Y, and retstart the system.
    7. After restarting, login and call disk.IOCounters(), it is still OK.

In conclusion, Windows 7&10 does not use diskperf.exe and EnableCounterForIoctl to manage the disk performance counter, and enable it by default. However, Windows Servers use diskperf.exe and EnableCounterForIoctl to control DPC, and disable it by default.

For Windows Servers, we maybe enable it automatically when importing the sub-package disk in the initialization function init.

Lomanic added a commit to Lomanic/gopsutil that referenced this issue May 3, 2022
…utomatically enable diskperf on Server editions

Fixes shirou#1094
Lomanic added a commit to Lomanic/gopsutil that referenced this issue May 5, 2022
…utomatically enable diskperf on Server editions

Fixes shirou#1094
@CHN-STUDENT
Copy link

CHN-STUDENT commented Apr 12, 2023

@xgfone hi, so if we need to monitor windows disk io on windows server.
We need run diskperf.exe -Y on cmd command on first?

@xgfone
Copy link

xgfone commented Apr 12, 2023

@xgfone hi, so if we need to monitor windows disk io on windows server.
We need run diskperf.exe -Y on cmd command on first?

@CHN-STUDENT It should have been fixed #1296.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants