Skip to content

wnbd driver and qemu-nbd - DriveIO lockup and corruption  #63

Closed

Description

@hgkamath

I was doing some testing on WIN10-21H2-19044-1415/WNBD-0.2.2-4-g10c1fbe qemu-6.2.0-rc4/ExFAT/qcow2/NTFS

For complete details, see https://gitlab.com/qemu-project/qemu/-/issues/727#note_780895802

  • qemu-nbd is used to make a virtual-disk residing on a disk on host available to the host as a drive via nbd protocol.
  • WNBD is used to attach the nbd to Windows-10 as a drive.
  • about 85GiB of Data is copied into the drive.
  • A VHDX virtual-disk will choke during the copy. Copy fails midway and host becomes unresponsive
  • A qcow2 virtual-disk will result in corrupted data

On Linux, only the VHDX format corrupts during expansion, while qcow2 and other virtual-disk formats seem fine. But on Windows, I found that even the qcow2 format too can corrupt during expansion (TEST E). For this reason, I think this is a separate distinct bug from the original and wnbd may also be a factor. The windows only bug is in addition to the qemu-only bug, which is also lurking in there.

The bug is reproducible. A script for synthetic data generation is provided in an earlier comment in that issue filing (link).

It is possible that this is a qemu-nbd-windows only bug, but then the wnbd driver is also involved here. The semi-official driver was test-signed and seemed to be still under development. I guess the bug needs to be squashed by troubleshooting and closing in on it from both sides.

The 5 test-cases can also be part of wnbd testing.

Q) Is there are recommended version of qemu-nbd that is known to work reliably with WNBD and the two together have been well tested?

Activity

  1. petrutlucian94 commented on Dec 17, 2021

    @petrutlucian94
    Member

    Hi,

    Thank you for your bug report. From the link that you have provided, I understand that you've tested multiple nbd clients (wnbd as well as the Linux native nbd client), multiple qemu-nbd versions and image formats.

    Since you're hitting the same issue with the Linux nbd client, I doubt this is a wnbd bug. I'd suggest narrowing down the problem, even taking nbd out of the picture completely. In your Qemu bug report, you're stating that some image formats are affected while some are not. You can verify this by directly attaching the images to Qemu vms, which would exercise the same Qemu block drivers, without actually using NBD.

    My first assumption was there may be unflushed changes, but since you're unmounting the volumes before closing the nbd connection, that shouldn't be the case. It may be interesting to do a wnbd-client stats $mapping before removing the nbd connection though.

    Q) Is there are recommended version of qemu-nbd that is known to work reliably with WNBD and the two together have been well tested?

    wnbd provides a generic NBD client, the qemu-nbd version shouldn't really matter. In case of a protocol incompatibility, the connection would be dropped and the log would contain some meaningful error.

    By the way, WNBD-6.12.39.253 isn't the actual wnbd version, you may use wnbd-client version to retrieve it.

    Regards,
    Lucian

  2. hgkamath commented on Dec 18, 2021

    @hgkamath
    Author

    Thank-you for your reply.

    Trying the qemu-VM from the inside is a good suggestion. qemu-system-x86_64 is very flaky under WHPX (windows hypervisor HyperV), perhaps I should consider setting it off. The qemu-vm is more reliable with Intel-haxm hypervisor. qemu tools like qemu-img and qemu-nbd are smaller independent binaries that do not engage qemu's virtualization/emulation, just the qemu-block framework. I will try it to do it some time, and see if corruption happens that way.

    In Windows qemu-setup (https://qemu.weilnetz.de/), the qemu-nbd.exe binary started getting built and included with the shipped qemu-setup since 2021-05-05, qemu-version 6.0. So this windows qemu nbd-server is a relatively recent addition to the set of available nbd peer/server/clients.
    qemu-w64-setup-20210505.exe

    qemu-nbd is a local nbd-client. Both SSD and HDD are connected to mini-SATA. Hence read/write speeds are much higher than what one may get over the network. resmon.exe claims 70 million bytes per sec though the qemu-nbd.exe process. Ordinary network speeds are often lower than native bus speeds, even though they claim 1gbps ethernet, consumer network traffic seldom really reaches the speed of the system-pci-express-bus. At this native machine speed, there is bound to be bottlenecks and buffer-fill/overfill.

    • The xcopy process is reading files from HDD, at HDD read-speeds
    • The xcopy process is writing to K: (mapped drive)
    • The Windows-NTFS driver gives the io-writes to K: to the underlying disk which is managed by the WNBD SCSI Virtual Adapter
    • The WNBD SCSI Virtual Adapter sends these to the qemu-nbd NBD server, using the TCP/IP sockets and network-stack
    • The qemu-nbd has to ask the underlying Windows/ExFAT on SSD to preallocate blocks to the virtual-disk file
    • The Windows-ExFAT driver has to increase block allocation of the virtual-disk-file on ExFAT-volume, and update FS metadata on SSD
    • The qemu-nbd has to write the received blocks to the virtual-disk-file on ExFAT-volume.
    • The Windows-ExFAT driver writes the blocks to the underlying SSD disk on SATA AHCI controller on the PCIE root complex.
    • Every in/out of disk reads, is being page cached. I have 16GB of RAM. Page cache file is on a SSD partition, exclusively used for page-cache (G:). G: is an ExFAT volume that slightly over 16GB in size. Page cache is configured to be fixed-size of 16GB=16384MB. Windows would probably warn if it was running low on page-cache, no such warnings, and none of the usual signs of low page cache thrashing. In fact, because the machine is disk-io blocked, no thrashing is occurring.

    Description of what is meant by when the machine is stuck:
    When the stuck happens, it is lucky that some open GUI processes work/respond at all. I keep a few extra privileged cmd.exe pwsh.exe windows open. Any other process that makes any disk access goes into a presumably io-blocked "not responding state". It is not possible to invoke new programs. Hence, one must be very careful with the processes that do respond. As long as no disk access is made, processes such as resmon.exe, taskmgr.exe continue to refresh and display. GUI components like menus, selections work. Text in notepad.exe can be editted but if attempted to be saved will cause it to go into not-responding. CPU usage is cool, typing, menu GUI, mouse movements are normal. Those on-screen applications that work are responsive.
    The only program that works is the cmd/pwsh windows. Attempting to change directory with cd will also make the command shell become stuck. It does not matter which hard-disk is being accessed, SSD1, HDD1, HDD2 etc.

    I think the reason why wnbd_client.exe can be made to run from the cmd.exe prompt is because its dll, exe images are memory cached, and so shell is not disk-io blocked. However, other than stat, uninstall driver other commands have a very very long time of getting a response from the wnbd-driver.

    qemu, qcow2 and kernel-nbd are well tested and work pretty rock-solid-ly under Linux. This is the other main reason why this issue is most likely a separate bug (bug2-63) as its effect is seen in different pathway, and affect any type of virtual-disk-format including qcow2. In the original bug (bug1-727), only the virtual-disk-format VHDX is affected, everything else is fine.

    Uninstalling and reinstalling the driver is the only way to unstuck the situation. At this point, all not-responding processes/apps come back alive. Until I discovered this, I was only force shutting down laptop. the following don't work ctrl-C or taskmgr-end-task on qemu-nbd or xcopy, attempt wnd-client unmap. The taskmgr will accept the end-task the first time on the io-blocked not-responding process, but will be unable to truly terminate it. If the taskmgr end-task attempted again on a previously end-tasked process, a popup dialog "action not allowed" is shown.

    E:\vstorage\nbd\wnbd_client>wnbd-client.exe uninstall-driver
    libwnbd.dll!RemoveAllWnbdDisks INFO Hard removing WNBD disk: gkpics01
    libwnbd.dll!RemoveWnbdAdapterDevice INFO Removing WNBD adapter device. Hardware id: root\wnbd. Class GUID: {4D36E97B-E325-11CE-BFC1-08002BE10318}
    libwnbd.dll!CleanDrivers INFO Removing WNBD driver: oem30.inf
    
    E:\vstorage\nbd\wnbd_client>wnbd-client.exe install-driver E:\vstorage\nbd\wnbd_driver\wnbd.inf
    libwnbd.dll!WnbdInstallDriver INFO Cleaned up stale WNBD adapters.
    libwnbd.dll!InstallDriver INFO Installing WNBD driver: E:\vstorage\nbd\wnbd_driver\wnbd.inf
    libwnbd.dll!CreateWnbdAdapter INFO Creating WNBD adapter. Class: SCSIAdapter. Hardware id: root\wnbd.
    

    This also hints to me that it is the wnbd driver that is freezing the disk-accesses of the system. The desktop is logged-in as an unprivileged non-administrative user. The qemu-nbd.exe is an unprivileged process started/run in an unprivileged shell. Under normal use, while running, it is easily stopped with ctrl-C or taskmgr. It can't really do anything to bring the whole system down.

    Summary of why bug2-63 is separate from bug1-727 and why it might be WNBD and not qemu-nbd.exe

    1. any virtual-disk format is affected (even qcow2, not just VHDX)
    2. The whole local-machine with unrelated process is stuck, disk-io frozen (an unprivileged process cannot do this)
    3. uninstalling, installing the driver using the wnbd-client, unstucks the system
    4. qemu-nbd is a local nbd-server. Other previous use-cases of wnbd may have been true remote network-based NBD-servers, that may not push wnbd-driver and local machine windows-kernel to block-transfer speed limits.

    Miscellaneous troubleshooting logs

    PS E:\vstorage\nbd\wnbd_client> .\wnbd-client.exe list-opt
    LogLevel           : 1 (Default: 1)
    NewMappingsAllowed : true (Default: true)
    EtwLoggingEnabled  : true (Default: true)
    WppLoggingEnabled  : false (Default: false)
    DbgPrintEnabled    : true (Default: true)
    PS E:\vstorage\nbd\wnbd_client> .\wnbd-client.exe set-opt LogLevel 4
    PS E:\vstorage\nbd\wnbd_client> .\wnbd-client.exe list-opt
    LogLevel           : 4 (Default: 1)
    NewMappingsAllowed : true (Default: true)
    EtwLoggingEnabled  : true (Default: true)
    WppLoggingEnabled  : false (Default: false)
    DbgPrintEnabled    : true (Default: true)
    
    PS E:\vstorage\nbd\wnbd_client> logman delete "WNBD_tracing_session"
    The command completed successfully.
    PS E:\vstorage\nbd\wnbd_client> logman create trace "WNBD_tracing_session" -p "{E35EAF83-0F07-418A-907C-141CD200F252}" "0xffffffff" "0xff" -o e:\tmpq\TraceFile_2.etl -rt
    

    still trying to capture some logs.

    Miscellaneous trouble shooting

    qemu-w64-setup-20210505.exe (6.0.0)
    qemu-w64-setup-20210619.exe (6.0.0) <- i used this
    qemu-w64-setup-20211215.exe (6.2.0) <- earlier I had tried this
    

    Below are the files one needs, and one can just extract these exe/dlls from the qemu-setup and cephpacific-setup without doing a full install

    PS E:\vstorage\nbd\qemu-nbd-6.0> (Get-ChildItem).Name
    iconv.dll
    libbz2-1.dll
    libcurl-4.dll
    libffi-6.dll
    libglib-2.0-0.dll
    libgmp-10.dll
    libgnutls-30.dll
    libhogweed-4.dll
    libidn2-0.dll
    libintl-8.dll
    libnettle-6.dll
    libnghttp2-14.dll
    libp11-kit-0.dll
    libpcre-1.dll
    libssp-0.dll
    libtasn1-6.dll
    libunistring-2.dll
    libwinpthread-1.dll
    libzstd-1.dll
    qemu-nbd.exe
    zlib1.dll
    
    PS E:\vstorage\nbd\wnbd_client> (Get-ChildItem).Name
    libwnbd.dll
    wnbd-client.exe
    
    PS E:\vstorage\nbd\wnbd_driver> (Get-ChildItem).Name
    wnbd.cat
    wnbd.inf
    wnbd.sys
    

    below are some wnbdclient stat captures. Usually the numbers OutstandingIO, pendingSubmittedIO and TotalReceivedIO add up. But start diverging after the stuck happens. Thereafter, the wnbd-client collecting stat responses is not longer quick but takes quiet some time.

    PS E:\vstorage\nbd\wnbd_client> ./wnbd-client.exe stats --instance-name gkpics01
    Disk stats
    TotalReceivedIORequests        : 4645
    TotalSubmittedIORequests       : 4645
    TotalReceivedIOReplies         : 4645
    UnsubmittedIORequests          : 0
    PendingSubmittedIORequests     : 0
    AbortedSubmittedIORequests     : 0
    AbortedUnsubmittedIORequests   : 0
    CompletedAbortedIORequests     : 0
    OutstandingIOCount             : 0
    

    When stuck happens,

    • resmon.exe shows that qemu-nbd.exe write-thoughput drops from 70Mbps to almost nothing and disappearing from the disk-IO using process list.
    • in wnbd_clent stats, the aborted counts start to increase
    • successive wnbd-client stats, take a much longer time to respond.
    Just when the-stuck has kicked in 
    E:\vstorage\nbd\wnbd_client>wnbd-client.exe stats --instance-name gkpics01
    Disk stats
    TotalReceivedIORequests        : 8689
    TotalSubmittedIORequests       : 8689
    TotalReceivedIOReplies         : 8677
    UnsubmittedIORequests          : 0
    PendingSubmittedIORequests     : 12
    AbortedSubmittedIORequests     : 6
    AbortedUnsubmittedIORequests   : 0
    CompletedAbortedIORequests     : 0
    OutstandingIOCount             : 6
    

    The below file (contains random bytes) in the xcopy of the synthetic generated data set is when the system become stuck

    PS C:\Users\gana> pwsh -Command { $sdate=$(date) ; echo "$sdate" ; xcopy /E E:\test\sgdata K:\ ; echo "$sdate" ; date } 
    12/18/2021 15:41:18
    E:\test\sgdata\photos001\find.CHECKSUM
    :
    E:\test\sgdata\photos001\D0000_88114831\File_0000.binE:\test\sgdata\photos001\D0011_325a7df4\D0007_cfa36bee\File_0000.bin
    
    E:\vstorage\nbd\wnbd_client>dir H:
     Volume in drive H is CPERF0
     Volume Serial Number is F196-DB9E
    
     Directory of H:\
    
    12/18/2021  03:44 PM     6,194,987,008 gkpics01.vhdx
                   1 File(s)  6,194,987,008 bytes
                   0 Dir(s)  149,989,228,544 bytes free
    
    E:\vstorage\nbd\wnbd_client>wnbd-client.exe stats --instance-name gkpics01
    Disk stats
    TotalReceivedIORequests        : 8706
    TotalSubmittedIORequests       : 8695
    TotalReceivedIOReplies         : 8677
    UnsubmittedIORequests          : 11
    PendingSubmittedIORequests     : 18
    AbortedSubmittedIORequests     : 19
    AbortedUnsubmittedIORequests   : 9
    CompletedAbortedIORequests     : 0
    OutstandingIOCount             : 1
    
    
    E:\vstorage\nbd\wnbd_client>wnbd-client.exe stats --instance-name gkpics01
    Disk stats
    TotalReceivedIORequests        : 8841
    TotalSubmittedIORequests       : 8695
    TotalReceivedIOReplies         : 8677
    UnsubmittedIORequests          : 146
    PendingSubmittedIORequests     : 18
    AbortedSubmittedIORequests     : 19
    AbortedUnsubmittedIORequests   : 144
    CompletedAbortedIORequests     : 0
    OutstandingIOCount             : 1
    
    
  3. changed the title [-]corruption between wnbd driver and qemu-nbd[/-] [+]wnbd driver and qemu-nbd - DriveIO lockup and corruption [/+] on Dec 19, 2021
  4. hgkamath commented on Dec 19, 2021

    @hgkamath
    Author

    In the below test I use a qemu VM to do copy from inside VM.

    • test1
      • test: copy sgdata onto qcow2 disk
      • result: VHDX corrupted
      • comment: nothing surprising here
    • test 2
      • test: copy sgdata onto qcow2 disk
      • result: QCOW2 corrupted
      • comment: surprising, but no system DriveIO lockup. I will need to test this on linux as well

    Preparation

    • I use alpine linux, (alpine-standard-3.15.0-x86_64.iso) because that was the only live-cd as of today with kernel-5.15.4 which has the paragon ntfs3 driver and boots into multi-user non-graphical console login.
    • Synthetic generated data is copied into E:\test\sgdata.vhdx so that it can be attached as a drive to the VM
    • Fresh empty gkpics01.vhdx is placed in H:\
    • Create empty qcow2: qemu-img.exe create -f qcow2 H:\gkpics01.qcow2 99723771904

    After booting Alpine Linux 3.15

    • setup-alpine: us, us, localhost, eth0, dhcp, no-manual-nw, timezone, noproxy, select repository, openssh, nodrives, nocfg, default apkcache
    • apk add gzip rsync e2fsprogs sgdisk gptfdisk
    • mkdir /mnt/a /mnt/b
    • mount partition of src drive (sgdata.vhdx): mount -t ntfs3 /dev/sdb2 /mnt/b
    • mount partition of dst drive
      • for vhdx: mount -t ntfs3 /dev/sda2 /mnt/a
      • for qcow2:
        • create partition /dev/sda1 using gdisk
        • mkfs -t ext4 -L fs_gkpics_01 /dev/sda1
        • mount -t ext4 /dev/sda1 /mnt/a

    VHDX TEST

    In cmd prompt: 
    C:\Windows> copy E:\vstorage\gkpics01_new.vhdx H:\gkpics01.vhdx
    
    C:\Users\gana>dir E:\vstorage\gkpics01_new.vhdx
     Volume in drive E is 15KJ_Images
     Volume Serial Number is 1EA6-2771
    
     Directory of E:\vstorage
    
    11/12/2021  01:21 PM       205,520,896 gkpics01_new.vhdx
                   1 File(s)    205,520,896 bytes
                   0 Dir(s)  360,436,940,800 bytes free
    
    PS E:\vstorage\nbd\qemu-nbd-6.0> & C:\vol\scoop_01\scoopg\shims\qemu-system-x86_64 -cpu qemu64 -m 4096 -machine "type=q35,kernel-irqchip=off" -accel whpx -smp "sockets=1,cores=8,threads=1" -boot d -cdrom E:\transcend\alpine-standard-3.15.0-x86_64.iso -hda H:\gkpics01.vhdx -hdb E:\test\sgdata.vhdx  -display gtk -vga virtio -rtc base=utc -net user -device "virtio-net,netdev=vmnic" -netdev "user,id=vmnic,net=192.168.20.0/24,dns=192.168.20.3,dhcpstart=192.168.20.15"
    C:\vol\scoop_01\scoopg\apps\qemu\current\qemu-system-x86_64.exe: warning: GdkPixbuf: Cannot open pixbuf loader module file 'C:\vol\scoop_01\scoopg\apps\qemu\current\lib\gdk-pixbuf-2.0\2.10.0\loaders.cache': No such file or directory
    
    This likely means that your installation is broken.
    Try running the command
      gdk-pixbuf-query-loaders > C:\vol\scoop_01\scoopg\apps\qemu\current\lib\gdk-pixbuf-2.0\2.10.0\loaders.cache
    to make things work again for the time being.
    Windows Hypervisor Platform accelerator is operational
    C:\vol\scoop_01\scoopg\apps\qemu\current\qemu-system-x86_64.exe: warning: hub 0 with no nics
    

    Inside VM, prepare machine as mentioned earlier, setup-alpine .. mount partitions

    localhost:/mnt# (sdate=`date` ; cd /mnt/b ; rsync -avH ./photos001 /mnt/a ; echo "$sdate" ; date ) 
    localhost:/mnt# ls -l /mnt/a/photos001
    

    The VHDX fails badly, even an ls -l did not succeed. Reboot was not required. nothing surprising here.

    QCOW2 TEST

    E:\vstorage\nbd\wnbd_client>C:\vol\scoop_01\scoopg\apps\qemu\current\qemu-img.exe create -f qcow2 H:\gkpics01.qcow2 99723771904
    Formatting 'H:\gkpics01.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=99723771904 lazy_refcounts=off refcount_bits=16
    
    E:\vstorage\nbd\wnbd_client>dir H:\gkpics01.qcow2
     Volume in drive H is CPERF0
     Volume Serial Number is F196-DB9E
    
     Directory of H:\
    
    12/19/2021  07:52 PM           198,144 gkpics01.qcow2
                   1 File(s)        198,144 bytes
                   0 Dir(s)  156,183,953,408 bytes free
    
    PS E:\vstorage\nbd\qemu-nbd-6.0> & C:\vol\scoop_01\scoopg\shims\qemu-system-x86_64 -cpu qemu64 -m 4096 -machine "type=q35,kernel-irqchip=off" -accel whpx -smp "sockets=1,cores=8,threads=1" -boot d -cdrom E:\transcend\alpine-standard-3.15.0-x86_64.iso -hda H:\gkpics01.qcow2 -hdb E:\test\sgdata.vhdx  -display gtk -vga virtio -rtc base=utc -net user -device "virtio-net,netdev=vmnic" -netdev "user,id=vmnic,net=192.168.20.0/24,dns=192.168.20.3,dhcpstart=192.168.20.15"
    C:\vol\scoop_01\scoopg\apps\qemu\current\qemu-system-x86_64.exe: warning: GdkPixbuf: Cannot open pixbuf loader module file 'C:\vol\scoop_01\scoopg\apps\qemu\current\lib\gdk-pixbuf-2.0\2.10.0\loaders.cache': No such file or directory
    
    This likely means that your installation is broken.
    Try running the command
      gdk-pixbuf-query-loaders > C:\vol\scoop_01\scoopg\apps\qemu\current\lib\gdk-pixbuf-2.0\2.10.0\loaders.cache
    to make things work again for the time being.
    Windows Hypervisor Platform accelerator is operational
    C:\vol\scoop_01\scoopg\apps\qemu\current\qemu-system-x86_64.exe: warning: hub 0 with no nics
    

    Inside VM, prepare machine as mentioned earlier, setup-alpine .. mount partitions
    rsync copy

    localhost:/mnt# (sdate=`date` ; cd /mnt/b ; rsync -avH ./photos001 /mnt/a ; echo "$sdate" ; date ) 
    :
    Sent 90,963,665,782 bytes  recevied 298,855 bytes  60,622,431.61 bytes/sec
    total size is 90,940,594,995  speedup is 1.00
    Sun Dec 19 20:19:26 IST 2021
    Sun Dec 19 20:44:26 IST 2021
    

    Verifying source drive

    localhost:/mnt# (sdate=`date` ; cd /mnt/b/photos001 ; sha256sum -c ./find.CHECKSUM | tee /tmp/fb ; echo "$sdate" ; date ) 
    :
    Sun Dec 19 21:28:09 IST 2021
    Sun Dec 19 21:48:35 IST 2021
    localhost:/mnt# cat /tmp/fb | grep -v ": OK" | wc -l  
    0
    

    Verifying the Destination drive containing with the rsynced/copied sgdata

    localhost:/mnt# (sdate=`date` ; cd /mnt/a/photos001 ;  sha256sum -c ./find.CHECKSUM | tee /tmp/fa ; echo "$sdate" ; date ) 
    :
    /D0039_1923a8ec/File_0002.bin: OK
    Sun Dec 19 20:47:53 IST 2021
    Sun Dec 19 21:07:39 IST 2021
    localhost:/mnt# cat /tmp/fa | grep -v ": OK" | wc -l  
    202
    

    !! QCOW2 is corrupted

    It is true that there are bugs in both code pathway of VHDX and qcow2 qemu virtual-disks, which show up even without the code-pathway of nbd being involved.
    However, it is also true that no system-stuck lockup happened.
    The system lockup is the doing of the wnbd driver.
    That is why I think wnbd itself does also have a bug.

    The nbd protocol, and the wnbd kernel driver need to be robust/resilient towards failures in the nbd-peer. So if nbd peer is screwing up, at worst it should disconnect drive backend connection, or refuse service, or try re-transmission, and if it is re-transmission, it shouldn't get stuck in an infinite loop, locking up the whole system

    The system drive-io lockup is reminiscent of situations like bad hard-drive bad-sector errors, or cdrom-read errors, where-in the windows-system get stuck trying to do a retry without ever succeeding, or taking a long time to move on. I don't think the my SSD drive really has problem blocks. Data integrity is fine when large virtual-disks are copied onto and off. So because qemu-nbd is screwing up, wnbd is locking up.

    Summary posted to bug1-727 comment https://gitlab.com/qemu-project/qemu/-/issues/727#note_789170496

  5. petrutlucian94 commented on Dec 20, 2021

    @petrutlucian94
    Member

    So in your case, some IO operations are hanging on the nbd server side. Windows (storport.sys to be precise) will cancel pending IO requests after about 30s, in which case that AbortedSubmittedIORequests counter will be increased.

    It's true that the Windows explorer usually hangs if the drives become unresponsive, but that's not WNBD's fault. It's the same with directly attached disk drives or SMB shares. WNBD simply receives IO requests from Storport and forwards them to an NBD server (or to a registered userspace app that uses libwnbd, but that's a different topic).

    Storport miniport drivers, such as WNBD, are not supposed to retry canceled operations. At best, we may try to detect IO deadlocks and disconnect the disk, but that should be configurable.

    A few other tests that you could make:

  6. petrutlucian94 commented on Apr 28, 2022

    @petrutlucian94
    Member

    I'm going to close this issue since it's not a WNBD driver bug, but rather a qemu-nbd or environment issue.

  7. hgkamath commented on Apr 28, 2022

    @hgkamath
    Author

    sorry for not updating, This is on my mind, but didn't yet got to do it. I'm still yet to test qemu-7 , which just got recently released. qemu-project also released a new binary qemu-storage-daemon.exe which also can act like a nbd server, amongst other things.

    Just some updates.
    The kernel-5.15.x series upto 5.15.24, had ntfs3 read-side bugs, and upto 5.17.x series there were folio/mmotm feature commits and I had taken a pause until some other qemu/kernel bugs sorted out, so that there is less ambiguity and compounding. I don't think the wnbd driver is in the clear yet. But it is true, that some of the negative test-results above, that I did, after taking your very-good-suggestion of testing wholly inside a qemu-vm, were on account of these bugs.

    I'll reopen this when I get to test it and it seems more sure that it isn't due to a qemu/linux-guest-kernel/linux-host-kernel issue

    Also on a side note, I wish cloudbase released a regular-signed wnbd driver, which you should, if you think it is bug free. On my laptop, in order to use the testsigned driver, I need to use the 1 time disable device-driver-signature-enforcement special boot, or use the testsign mode which the HP-UEFI requires me to disable secureboot. The test-mode also puts a ugly wallpaper watermark. This hassle is what creates reluctance to test. Suppose things work well, I am not sure if I would go down a decision of mounting drives via wnbd this way on a regular basis, if it requires me to permanently turn off secureboot.

  8. petrutlucian94 commented on Apr 28, 2022

    @petrutlucian94
    Member

    Thanks for feedback. We're currently shipping a signed version of the driver with the Ceph msi installer: https://cloudbase.it/ceph-for-windows/, I hope that helps. In the future, we may consider a standalone WNBD installer.

  9. hgkamath commented on Apr 29, 2022

    @hgkamath
    Author

    I think the ceph-msi-installer ceph_pacific_beta.msi which is still beta is also just test-signed. (am i wrong?)
    I had used the same before also.

    1. Open device manager, right click any wnbd SCSI virtual adapter and uninstall device
    2. Open admin cmd prompt
    3. (only if updating driver) Uninstall ceph from programs and features
    4. Ensure that there is no prior certificate under trusted publisher from Cloudbase Solutions Srl .
      a. Open cmd certmgr
      b. Delete cloudbase certificate under trusted-publishers/certificates
    5. (only if updating driver) Reinstall ceph
    6. issue command : .\wnbd-client.exe install-driver --filename 'C:\Program Files\Ceph\driver\wnbd.inf'
    7. Dialog prompt comes up: "would you like to install this device software with name and publisher
      a. ensure checkbox always trust software from Cloudbase Solutions Srl is checked
      b. click install
    8. Driver is installed, and wnbd driver shows up under storage controllers in device manager
    9. Close certmgr.exe, wait a minute and again reopen certmgr.exe.
      a. verify that cloudbase certificate is again present under trusted-publishers/certificates
      b. Double click/Open the certificate. Verify -
      . 1. In general tab: The digital signature is OK , certificate validity is from 8/13/2021 to 8/12/2024
      . 2. In details tab: Key usage under has yellow triangle for Key Usage : Digital Signature (80)
    10. However, driver in device mgr has yellow triangle. and right click property gives code 52
      Windows cannot verify the digital signature for the drivers required for this device. A recent hardware or software change might have installed a file that is signed incorrectly or damaged, or that might be malicious software from an unknown source. (Code 52)
    PS E:\vstorage\nbd\wnbd_client> .\wnbd-client.exe -v
    wnbd-client.exe: 0.2.2-4-g10c1fbe
    libwnbd.dll: 0.2.2-4-g10c1fbe
    libwnbd.dll!WnbdOpenAdapterEx ERROR No WNBD adapter found. Please make sure that the driver is installed.
    

    driverver from wnbd.inf: DriverVer = 04/28/2022,6.15.27.572

  10. petrutlucian94 commented on Apr 29, 2022

    @petrutlucian94
    Member

    Right, it's signed using a Cloudbase certificate and not by Microsoft, which is why secure boot will have to remain disabled. However, you may disable the "testsigning" setting (allowing self signed drivers) when using the Ceph msi.

    We decided to keep the "beta" label until we implement CI testing and get more user feedback. The good news is that a Windows Ceph CI job has been added recently [1] and that we got quite a few users already, which provide valuable feedback (as you did already).

    A stable driver release will also go through the Microsoft driver attestation and signing process. Unfortunately, I can't provide an ETA but I hope that this will be ready by the next Ceph release.

    [1] https://jenkins.ceph.com/job/ceph-windows-pull-requests/6850/

  11. Jazz9 commented on Jun 21, 2022

    @Jazz9

    I have been chasing the same issue for a few months now. 16.2.7 ceph and windows 2019. I see this across 4 separate clusters. The larger the cluster the worse it seems to be ( ranging from 50 -340 osds per cluster )

    We had a firmware bug where OSDs restarted randomly and this would trigger the windows RBD volume to lock up and never return. A restart of the windows server would sometimes cause refs to corrupt and go RAW. We have implemented snapshots to try mitigate this.

    A planned reboot of a ceph node doesn't seem to cause the issue. Only a OSD assert.

    The fault is characterized by PendingSubmittedIORequests going up but not aborts.

    We are open to paying for support to correct this issue.

  12. petrutlucian94 commented on Jun 21, 2022

    @petrutlucian94
    Member

    @Jazz9 thanks for feedback. The issue may be slightly different as the OP wasn't using RBD but actually NBD (wnbd can also act as a standalone nbd client) and it affected other NBD clients as well.

    There might be some problem around aborted or timed out requests, so I think it's worth reopening this issue. The bug may also reside on the Ceph side (rbd-wnbd leverages wnbd), which may not be able to gracefully handle lost OSD connections (at least on Windows). Just checking: have you encountered similar issues with Linux RBD clients?

    As a side note, there is a recent Ceph fix that replaces select() with poll() on Windows in order to avoid fd limitations, which can be a problem when having a large amount of OSDs: ceph/ceph#46525.

    We'll definitely need to investigate this issue. Unfortunately, I'm no longer actively working on this project (at least for now), so I can't provide an ETA. One of my colleagues may be able to reproduce it.

    If needed, you may get in touch with our support team by filling this form: https://cloudbase.it/about/#contact

  13. petrutlucian94 commented on Jun 23, 2022

    @petrutlucian94
    Member

    We found the issue. If all the IO dispatch workers are waiting for RBD callbacks indefinitely, the userspace (libwnbd) may never get notified of mapping removals. We'll need to improve the way in which the driver informs the IO dispatcher that the disk has been removed (e.g. by using a seperate control thread or some disconnect events).

    We'll also have to avoid waiting for IO operations indefinitely on the rbd side (e.g. maybe double check our timeouts).

  14. 34 remaining items

  15. petrutlucian94 commented on May 9, 2023

    @petrutlucian94
    Member

    I've replicated the issue using qemu-storage-daemon.exe. The NBD connection eventually hangs and we can no longer send requests or receive replies. Windows becomes extremely unresponsive when that happens.

    This doesn't affect rbd-wnbd, so the potential causes are:

    • nbd client issue
      • nbd protocol implementation
      • WSK or libksocket bug
    • nbd server bug

    Thanks again for the bug report, I'm reopening the issue. Sorry for the slow progress, our main focus is currently Ceph, we're providing the NBD client functionality as a best effort.

    LE: NBD socket reads and writes hang indefinitely: https://pastebin.com/raw/6rrggyDs. We'll move the NBD client to userspace as soon as possible.

    LLE: there seems to be a problem with qemu-storage-daemon on Windows. Wnbd works fine with Linux qemu-storage-daemon NBD servers or the standard Linux nbd-server.

    I did prepare a draft that moves the NBD implementation to userspace, making it easier to maintain: #122. I'll probably prepare another PR that forwards LUN resets to the wnbd daemon so that it may reset or remove the connection instead of blocking the host.

    Looks like qemu's blk_co_pwrite hangs at some point: https://github.com/qemu/qemu/blob/6972ef1440a9d685482d78672620a7482f2bd09a/nbd/server.c#L2514. This might also affect Qemu VMs on Windows.

  16. petrutlucian94 commented on May 17, 2023

    @petrutlucian94
    Member

    @hgkamath I spent some time looking at qemu-storage-daemon, some WriteFile calls were hanging. The good news is that it seems to work fine when passing cache.direct=on, for example:

    qemu-storage-daemon.exe  --blockdev driver=file,node-name=file,filename=e:\img\test_100gb.raw,cache.direct=on --blockdev driver=raw,node-name=raw,file=file --nbd-server addr.type=inet,addr.host=127.0.0.1,addr.port=10809 --export type=nbd,id=export,node-name=raw,name=test_100gb,writable=on
    
  17. hgkamath commented on May 17, 2023

    @hgkamath
    Author

    I'll try that out.

    One thought, that I wanted to pass along, was that
    I discovered qemu-win also uses mingw-winpthreads by default.
    There is a bug, which I filed myself, https://gitlab.com/qemu-project/qemu/-/issues/1605
    in which I found that the workaround is to use native threads with aio=native instead of the default mingw-winpthreads, the implicit option being aio=threads

    I have encountered that particular qemu-bug only with rapid expansion of VHDX-dynamic vdisk-file (vhdx-dyn).
    The chance that it surfaces here is slim because, this test uses qcow2-fixed.
    a) for starters, qemu-s implementation of its codenative format qcow2 is much more performant than VHDX
    b) being a fixed vdisk, the block-allocation is complete and so this bug's vdisk file does not have to expand.

    Also, your comment, also confirms it happens for raw format itself. Indeed, one should test in raw. This bug is independent of the qemu's vdisk format, and it is best to choose raw, to remove uncertainties arising due to qemu's vdisk implementations.

    Nevertheless, I now test with a drive option aio=native just to reduce the chance of that.
    PS C:\Users\admin> qemu-storage-daemon.exe --blockdev driver=file,aio=native,node-name=file,filename=F:\gkpics01.qcow2 --blockdev driver=qcow2,node-name=qcow2,file=file --nbd-server addr.type=inet,addr.host=127.0.0.1,addr.port=10809 --export type=nbd,id=export,node-name=qcow2,name=gkpics01,writable=on

    PS C:\Windows\system32> $(dir F:\gkpics01.qcow2).Length
    99739238400
    PS C:\Windows\system32> fsutil sparse queryflag F:\gkpics01.qcow2
    This file is NOT set as sparse
    

    Expectedly, I still did experience a hang with aio=native also.

    In one of the hangs, it was possible to do an uninstall-driver, install-driver, map and resume/restart the xcopy without having to Ctrl-C the qemu-storage-daemon, meaning, that in that run, the qemu-storage-daemon nbd-server was not stuck and nbd reconnection succeeded.

    From the qemu manual pdf pg41 :
    cache.direct : The host page cache can be avoided with cache.direct=on. This will attempt to do disk IO directly to the guest’s memory. QEMU may still perform an internal copy of the data.
    For cache.direct to work on windows. the file-open-flag O_DIRECT should should be supported on windows/mingw/win32 api, also the filesystem and filesystem-driver should support it.
    win32 file has FILE_FLAG_NO_BUFFERING for CreateFile, ReOpenFile, file-buffering
    FILE_FLAG_NO_BUFFERING maps to the O_DIRECT flag for the Linux open command.
    So, it does. block/file-win32.c does use the flag.
    In file-win32.c/file-posix.c, the function raw_parse_flags() sets the corresponding flags based on if BDRV_O_NOCACHE is set, which is set if cache.direct option is provided.
    ... just checking.

    Its a good idea to quickly detect stuck situation, and react by uninstalling driver.
    Superstition: I think, leaving machine unattended and risking it remaining in this stuck-state can lead to machine becoming slower and eventually having a more serious system-crash.
    Techniques I use to quickly detect a stuck-situation

    1. Usually, for small files, one can see xcopy progressing. That clearly means system not stuck.
    2. For larger files, xcopy takes a long time on the file. So, if one keeps a notepad open and alternatively press-space-bar and ctrl-S (save) When machine is not stuck, the unsaved asterix indicator in the titlebar will toggle. When machine becomes suck, notepad becomes unresponsive on save.
    3. IDEA-FAIL: Run the below script in powershell. It should not block on file-access, and keep printing the time every 6 seconds. Not that I expect the file-size to change.
      PS C:\Windows\system32> $i=0 ; while ($true -and ($i -lt 400)) { "{0} {1}" -f $(date),$(dir F:\gkpics01.qcow2).Length ; sleep 6 ; $i = $i + 1 }
      The above turned out to be ineffective. So I tried the below
      PS C:\Windows\system32> $i=0 ; while ($true -and ($i -lt 400)) { "{0} {1} {2}" -f $(date),$(dir F:\gkpics01.qcow2).Length,$(dir F:\gkpics01.qcow2).LastWriteTime[0].ToString() ; "test" | Out-File -FilePath K:\tmpq\Downloads\a.txt ; sleep 6 ; $i = $i + 1 }
      But with this, I could not reproduce the stuck-state, it was acting like a keep-alive.

    Another superstition that I am still watching out for is that I think if stuck happens its most likely at the really large files. Its not always the same file, but I will need to see if it is always one of the below large ones.
    EDIT: This is maybe just that, a superstition, I started noting the ending file's file-size, and neither its, or the next's was always large, sometimes files were as small as 3Mib.
    >512 MiB

    D:\test\sgdata>forfiles /S /M * /C "cmd /c if @fsize GEQ 536870912 echo @path @fsize"
    "D:\test\sgdata\photos001\D0011_325a7df4\D0004_ff4697dc\File_0000.bin" 870548550
    "D:\test\sgdata\photos001\D0011_325a7df4\D0007_cfa36bee\File_0000.bin" 917280712
    "D:\test\sgdata\photos001\D0011_325a7df4\D0007_cfa36bee\File_0001.bin" 1193905888
    "D:\test\sgdata\photos001\D0014_127c4d62\File_0000.bin" 4294694852
    "D:\test\sgdata\photos001\D0015_a42d4363\File_0000.bin" 2381007674
    "D:\test\sgdata\photos001\D0015_a42d4363\File_0001.bin" 2103925866
    "D:\test\sgdata\photos001\D0016_bcd34db1\File_0012.bin" 1223441112
    "D:\test\sgdata\photos001\D0016_bcd34db1\File_0014.bin" 1498293582
    "D:\test\sgdata\photos001\D0016_bcd34db1\File_0019.bin" 800657438
    "D:\test\sgdata\photos001\D0017_6986e32f\File_0000.bin" 1889579172
    "D:\test\sgdata\photos001\D0017_6986e32f\File_0001.bin" 1978039382
    "D:\test\sgdata\photos001\D0020_bf23a7e9\File_1824.bin" 885577878
    "D:\test\sgdata\photos001\D0020_bf23a7e9\File_1849.bin" 758393712
    "D:\test\sgdata\photos001\D0020_bf23a7e9\File_1861.bin" 622607906
    "D:\test\sgdata\photos001\D0020_bf23a7e9\File_1867.bin" 559405836
    "D:\test\sgdata\photos001\D0021_1ab60b0c\File_1027.bin" 790637902
    "D:\test\sgdata\photos001\D0021_1ab60b0c\File_1030.bin" 859589186
    "D:\test\sgdata\photos001\D0024_fded2015\D0000_2b73ea53\File_0030.bin" 586790162
    "D:\test\sgdata\photos001\D0024_fded2015\D0000_2b73ea53\File_0032.bin" 710406956
    "D:\test\sgdata\photos001\D0024_fded2015\D0000_2b73ea53\File_0034.bin" 632330336
    "D:\test\sgdata\photos001\D0024_fded2015\D0000_2b73ea53\File_0036.bin" 662133078
    "D:\test\sgdata\photos001\D0024_fded2015\D0000_2b73ea53\File_0040.bin" 1157315322
    "D:\test\sgdata\photos001\D0024_fded2015\D0000_2b73ea53\File_0042.bin" 1553586422
    "D:\test\sgdata\photos001\D0025_7bd77bae\File_0110.bin" 785962104
    "D:\test\sgdata\photos001\D0025_7bd77bae\File_0112.bin" 689221632
    "D:\test\sgdata\photos001\D0026_409200f8\File_0034.bin" 797661226
    "D:\test\sgdata\photos001\D0026_409200f8\File_0036.bin" 1151132800
    "D:\test\sgdata\photos001\D0030_2a29839c\File_0516.bin" 835986114
    "D:\test\sgdata\photos001\D0031_b20f40a7\File_0045.bin" 828452346
    

    >1 GiB

    D:\test\sgdata>forfiles /S /M * /C "cmd /c if @fsize GEQ 1073741824 echo @path @fsize"
    
    "D:\test\sgdata\photos001\D0011_325a7df4\D0007_cfa36bee\File_0001.bin" 1193905888
    "D:\test\sgdata\photos001\D0014_127c4d62\File_0000.bin" 4294694852
    "D:\test\sgdata\photos001\D0015_a42d4363\File_0000.bin" 2381007674
    "D:\test\sgdata\photos001\D0015_a42d4363\File_0001.bin" 2103925866
    "D:\test\sgdata\photos001\D0016_bcd34db1\File_0012.bin" 1223441112
    "D:\test\sgdata\photos001\D0016_bcd34db1\File_0014.bin" 1498293582
    "D:\test\sgdata\photos001\D0017_6986e32f\File_0000.bin" 1889579172
    "D:\test\sgdata\photos001\D0017_6986e32f\File_0001.bin" 1978039382
    "D:\test\sgdata\photos001\D0024_fded2015\D0000_2b73ea53\File_0040.bin" 1157315322
    "D:\test\sgdata\photos001\D0024_fded2015\D0000_2b73ea53\File_0042.bin" 1553586422
    "D:\test\sgdata\photos001\D0026_409200f8\File_0036.bin" 1151132800
    
  18. hgkamath commented on May 18, 2023

    @hgkamath
    Author

    Confirming that the workaround cache.direct=on gave me a successful run.
    Will do future tests both with and without it.

    I theorize that be removing the OS/host-caching from the picture, probably increases the responsivity (time to respond to wnbd-client), and hence makes it less likely for the protocol to trip and lead into stuck-state.
    Probably WinOS sends processes to sleep state during the time of data going into cache and out.
    The question becomes: is it winOS tripping on caching, qemu tripping on caching, or wnbd client tripping due to delay.

    PS C:\Windows\system32> qemu-storage-daemon.exe  --blockdev driver=file,aio=native,node-name=file,filename=F:\gkpics01.qcow2,cache.direct=on --blockdev driver=qcow2,node-name=qcow2,file=file --nbd-server addr.type=inet,addr.host=127.0.0.1,addr.port=10809 --export type=nbd,id=export,node-name=qcow2,name=gkpics01,writable=on
    
    PS C:\Windows\system32> powershell -Command { $fl="photos001" ; $rtpt="J:" ; cd "${rtpt}/${fl}" ; $sdate=$(date) ; echo "$sdate" ; C:\vol\scoop_01\scoopg\apps\git\current\usr\bin\sha256sum.exe -c "$rtpt/$fl/find.CHECKSUM" --quiet ; echo "$sdate" ; echo "$(date)"  }
    :
    15377 File(s) copied
    05/18/2023 17:33:06
    05/18/2023 17:50:19
    
    # unmap remap
    PS C:\Windows\system32> D:\vstorage\nbd\wnbd_client\wnbd-client.exe unmap gkpics01
    libwnbd.dll!PnpRemoveDevice WARNING Could not remove device. CM status: 23, veto type 6, veto name: STORAGE\Volume\{50a6c206-f464-11ed-9807-3464a9d34f26}#0000000001000000. Time elapsed: 1.87s, time left: 28s. Check the Windows System event log (Kernel-PnP source) for more information about the process that is holding the disk.
    PS C:\Windows\system32>  D:\vstorage\nbd\wnbd_client\wnbd-client.exe map --hostname localhost --port 10809 --instance-name gkpics01
    PS C:\Windows\system32>
    
    PS C:\Windows\system32> powershell -Command { $fl="photos001" ; $rtpt="J:" ; cd "${rtpt}/${fl}" ; $sdate=$(date) ; echo "$sdate" ; C:\vol\scoop_01\scoopg\apps\git\current\usr\bin\sha256sum.exe -c "$rtpt/$fl/find.CHECKSUM" --quiet ; echo "$sdate" ; echo "$(date)"  }
    05/18/2023 17:50:49
    05/18/2023 17:50:49
    05/18/2023 18:06:20
    
  19. petrutlucian94 commented on May 18, 2023

    @petrutlucian94
    Member

    Thanks for the confirmation. It doesn't seem related to NBD or the wnbd client. Qemu's WriteFile calls [1] are hanging unless we disable caching. I didn't dig too much into qemu's caching related code so I'm not sure if apart from FILE_FLAG_NO_BUFFERING [2] there are any other changes when passing cache-direct=on.

    I wouldn't completely exclude some Windows overlapped IO weirdness, we had some similar issues [3].

    [1] https://github.com/qemu/qemu/blob/d27e7c359330ba7020bdbed7ed2316cb4cf6ffc1/block/file-win32.c#L86
    [2] https://github.com/qemu/qemu/blob/d27e7c359330ba7020bdbed7ed2316cb4cf6ffc1/block/file-win32.c#L281
    [3] #30

  20. hgkamath commented on May 19, 2023

    @hgkamath
    Author

    It feels like we're getting somewhere. Much thanks to your effort.
    Most of what I write here I probably just verbiage to what you wrote succinctly.
    (also do note that I am a user not a developer, so terms I say might not be correct)

    In the qemu-project, on the windows side of things, there are only maintainers and no developers. Windows bugs get fixed if it was a happy side-effect of something else they were doing, usually on linux, or when windows users who have done the troubleshooting, nail something down, point out what-exactly has to be done. There aren't that many advanced-level windows-users.

    Just to remember: When drive-lockup/system-stuck happens, only open windows/applications respond, until they are forced to do some disk-access. If an application attempts to do something with the disk, it freezes and becomes unresponsive. Ex notepad, powershell command load, etc.

    Either one of following is true:

    1. the WriteFile() is just yet another symptom of the drive-lockup/system-stuck (the chain of events leading to drive-lockup being caused elsewhere) , which would be a possibility if, as you said, if cause could be pinned to something cache.direct=on did elsewhere, apart from setting FILE_FLAG_NO_BUFFERING , wherever-else BDRV_O_NOCACHE influences ... and the overlapped-io-weirdness
    2. or the WriteFile(), in conjunction with other asynchronous read/write calls, due to some combination of faulty flags and structure-parameters, is causing the block/deadlock, and everything is stuck because of it
    3. or the WriteFile() is actively part of a cylic-chain of components that are in deadlock (cyclic-deadlock)

    If it is a cyclic deadlock

    • Then
      • wnbd is stuck because qemu nbd is not responsive.
      • win10 is stuck and causes drive-lockup because wnbd is stuck.
      • qemu Writefile() is stuck because win10 is in drive-lockup.
    • Maybe, when one gives cache.direct=on the disabling of host-pagefile-caching/file-buffering,
      • makes qemu do its write sort-of atomically, which lets it respond to wnbd
      • the responsiveness prevents wnbd from making win10 go into drive lockup
      • as win10 drive lockup does not happen qemu does not get stuck on write.
    • If host-pagefile-caching/file-buffering is allowed (default), perhaps
      • qemu writefile() is in some half-and-half state of data being committed to disk. qemu is waiting on win10
      • but wnbd is also waiting on qemu and causes win10 to go into drive-lockup
      • and because win10 went into drive-lockup, the qemu-writefile() isn't going to complete.
    • When trying to recover from drive-lockup/system-stuck, when wnbd driver is uninstalled.
      • J: is force unmounted, Probably a Write() call return in error, xcopy process bails-out/get terminated.
      • Win10 is no longer waiting on wnbd, frees the drive-lockup
      • In qemu-storage-daemon, the WriteFile() call returns, and so it goes back to being responsive

    Maybe,

    • giving cache.direct=on necessary and one way to avoid the avoid cyclic-deadlock. It obviously works by cutting out win10-OS from the picture, removing one extra copy-in copy-out step. But why does it work? Could it be that under more rigorous OS workloads, deadlock may happen even without file-buffering.
    • or cache.direct=on is unnecessary.
      When xcopy copies a file, assuming xcopy doesn't disable file-buffering in its read()/write() calls, there will be some drive host-pagefile-caching/file-buffering happening at the mounted storage-level (J:). File-buffering in the in-between layers stage (F: and qemu-nbd-block-device emulation) is redundant
      But even if host-pagefile-caching/file-buffering, though unnecessary, it is allowed to be enabled, one should not run into drive-lockup/system-stuck, there must be another way to to prevent the cyclic-deadlock.

    .

    • xcopy has a /J option. I'll do some test-runs with that and default cache.direct=off
      • Prediction: leaning towards maybe it won't matter.
      • ref: learn.microsoft: link
      • Result: 2 of 2 testruns succeeded (prediction refuted)
      • new hypthesis: the two file-buffering caches might be vying for memory

    PS C:\Windows\system32> qemu-storage-daemon.exe --blockdev driver=file,aio=native,node-name=file,filename=F:\gkpics01.qcow2 --blockdev driver=qcow2,node-name=qcow2,file=file --nbd-server addr.type=inet,addr.host=127.0.0.1,addr.port=10809 --export type=nbd,id=export,node-name=qcow2,name=gkpics01,writable=on

    PS C:\Windows\system32> xcopy /?
    :
     /J           Copies using unbuffered I/O. Recommended for very large files.
    :
    

    PS C:\Windows\system32> $sdate=$(date) ; echo "$sdate" ; xcopy /J /E D:\test\sgdata\photos001 J:\photos001 ; echo "$sdate" ; $edate=$(date) ; echo "$edate

    15377 File(s) copied
    05/19/2023 15:00:32
    05/19/2023 15:18:43
    

    PS C:\Windows\system32> powershell -Command { $fl="photos001" ; $rtpt="J:" ; cd "${rtpt}/${fl}" ; $sdate=$(date) ; echo "$sdate" ; C:\vol\scoop_01\scoopg\apps\git\current\usr\bin\sha256sum.exe -c "$rtpt/$fl/find.CHECKSUM" --quiet ; echo "$sdate" ; echo "$(date)" }

    05/19/2023 15:23:59
    05/19/2023 15:23:59
    05/19/2023 15:39:13
    

    Unbuffered write

    • Seems to be reccommeded when the file being copied is large
      • 20110426 How to determine when to use the xcopy with the /j parameter? : link
      • quote: Nina Liu MSFT - Unbuffered I/O (or a raw file copy) is preferred when attempting to copy a large file from one location to another when we do not intend to access the source file after the copy is complete. This will avoid the file system cache overhead and prevent the file system cache from being effectively flushed by the large file data.
    • In that light, it probably makes sense for VMs, emulated backend devices and the like to always use unbuffered write for its internal block-device emulation: For a qemu-VM, a guest OS will have its own page-cache and filesystem buffering. For WNBD, the windows filesystem layer will do it.

    Its also possible that if the nbd-client part of wnbd were jettisoned into userspace, the the OS/kernel would not be insistent that wnbd should respond immediately or within short timebound, allowing for a slower or delayed response from the emulated drive..

    Q) Another question is to learn from you. Requesting you to document what you did, and what tools you used. As seen in bug qemu-#1605 so far, I am able to compile my own qemu-8.0 with debuginfo symbols using mingw, and do some very basic troubleshooting using gdb like putting assert() /printf() statements and inspecting stack frame variables.
    How did you troubleshoot this? How did you know qemu was stuck on writefile()

  21. petrutlucian94 commented on May 19, 2023

    @petrutlucian94
    Member

    That's a very interesting observation about the cache dependency. I'd be curious to see what happens when connecting to qemu-storage-daemon from another host/vm (either Linux or Windows), thus avoiding this dependency.

    So the idea is that WNBD disk writes are cached and so are the underlying qemu image file writes. This might lead to a deadlock when Windows attempts to flush its cache. I'm not really familiar with the Windows cache manager internals, the guys from OSR (https://community.osr.com) might be able to provide more insight (some Microsoft engineers used to post there). However, it's highly likely that writes are blocked while there's a pending cache flush, despite targeting a different disk.

    If this situation is confirmed, we could document something along those lines:

    When using WNBD to connect to a local NBD server, make sure to disable
    caching either at the WNBD disk level or at the NBD server level. Windows cache
    flushes may otherwise deadlock.
    
    For example, when using ``qemu-storage-daemon.exe`` locally, make sure to pass
    ``cache.direct=on`` like so:
    
        qemu-storage-daemon.exe  \
          --blockdev driver=file,node-name=file,filename=e:\img\test_100gb.raw,cache.direct=on \
          --blockdev driver=raw,node-name=raw,file=file \
          --nbd-server addr.type=inet,addr.host=127.0.0.1,addr.port=10809 \
          --export type=nbd,id=export,node-name=raw,name=test_100gb,writable=on
    

    Its also possible that if the nbd-client part of wnbd were jettisoned into userspace, the the OS/kernel would not be insistent that wnbd should respond immediately or within short timebound, allowing for a slower or delayed response from the emulated drive..

    I've been testing using the userspace nbd client proposed here: #122. The behavior is the same.

    Q) Another question is to learn from you. Requesting you to document what you did, and what tools you used. As seen in bug qemu-#1605 so far, I am able to compile my own qemu-8.0 with debuginfo symbols using mingw, and do some very basic troubleshooting using gdb like putting assert() /printf() statements and inspecting stack frame variables.
    How did you troubleshoot this? How did you know qemu was stuck on writefile()

    I did mostly the same. I was initially considering using Ubuntu to cross compile Qemu for Windows, however it was easier to go with msys2 since it already had all the dependencies (e.g. glib).

    Then I checked the nbd server code, looking for the main entry points for NBD IO operations. I was a bit familiar with the qemu block drivers since I wrote a few patches for vhd(x) about 10 years ago :). I knew that raw image file writes should eventually hit this: https://github.com/qemu/qemu/blob/d27e7c359330ba7020bdbed7ed2316cb4cf6ffc1/block/file-win32.c#L86.

    I added a few log messages to track IO requests more easily: petrutlucian94/qemu@b18da91. Probably I could've just used qemu tracing, however I haven't used that in a while and it was easier to just add a few print messages :). I was running wnbd in debug mode and checking the last 10 requests or so before the deadlock occurred. I was mostly ensuring that the write address, length and nbd tag match the ones received by the nbd server.

    Sure, a stack trace would've also told me about the WriteFile hang, however I was also looking for unusual IO patterns. When building qemu using mingw-gcc, the debug symbols use dwarf format, which can't be used by WinDBG. I usually use this gdb fork for opening Windows dumps (the upstream version doesn't support this feature): https://github.com/ssbssa/gdb/releases/tag/gdb-13.1.90.20230220.

    Another option might be to compile qemu using mingw-llvm, which has .pdb symbol support, which can be handled by WinDBG.

  22. hgkamath commented on May 19, 2023

    @hgkamath
    Author

    In comment, 1551603847
    I had this idea of using a script to detect drive-lock, quickly, visually without manual checking.

    1. PARTIAL-IDEA-FAIL: While xcopy is in progress, run the below script in powershell. It should not block on file-access, and keep printing the time every 6 seconds. Not that I expect the file-size to change.
      PS C:\Windows\system32> $i=0 ; while ($true -and ($i -lt 400)) { "{0} {1}" -f $(date),$(dir F:\gkpics01.qcow2).Length ; sleep 6 ; $i = $i + 1 }
      The above turned out to be ineffective. It probably got the filesize from RAM/fs-metadata-cache. So I tried the below
      PS C:\Windows\system32> $i=0 ; while ($true -and ($i -lt 400)) { "{0} {1} {2}" -f $(date),$(dir F:\gkpics01.qcow2).Length,$(dir F:\gkpics01.qcow2).LastWriteTime[0].ToString() ; "test" | Out-File -FilePath K:\tmpq\Downloads\a.txt ; sleep 6 ; $i = $i + 1 }
      But with this, I could not reproduce the stuck-state, it was acting like a keep-alive.
      while neither disabling filebuffering in xcopy nor in qsd
      [EDIT] I got the stuck-state to happen at-least once in this way.

    It feels like it is less likely for the stuck-state to happen, (shows up much later into the run), when I just stay glued to the same desktop-screen with the powershell windows and do nothing else but wait for xcopy or notepad to become stuck, and hoping to see a stuck script as well. Either stuck-state happens but script does not stop, or stuck-state-never-happens.
    It feels like it is more likely for the stuck-state to happen (shows up sooner into the run), when I had multi-tasked to a Firefox window on a different desktop-screen (win10 multiple desktop feature), which is what I did most of the time. After a while, as one browses, drive-lock happens. When a new weblink/tab is opened, the Firefox window freezes/becomes unresponsive. Perhaps, using something like Firefox, creates contention for filebuffer cache. One might take longer notice the stuck state, if one only context switches between browser tabs for which Firefox already has the pages artifacts in memory.
    Its a good thing that even in the stuck-state/drive-lockup, when things like even start-menu and taskbar might freeze, one can switch between desktops using Ctrl-Win-Left and Ctrl-Win-Right Keyboard shortcuts. (Rapid switching between desktop screens does not increase chances of the bug)

    So file-activity on the host may have an influence on this bug.

    • activities like the running the script and monitoring it, tends to keep the file-buffer usage around the files being operated on, i.e. the qcow2
      and hence make the stuck-state/bug less likely to happen later
    • activities like firefox, might be contending and using up filebuffer space
      and hence make the stuck-state/bug more likely to happen sooner
    • Using the workaround, either in qsd or in xcopy, preventing double layered file buffering,
      avoids encountering the stuck-state/bug.

    These hunches I get could be superstitions.

    That something external to both qsd and wnbd has this effect makes me think.
    This could be a bug involving file-buffering inside Win10 kernel itself.

    writes are blocked while there's a pending cache flush, despite targeting a different disk

    A cache flush of files at a top layer storage (J:), become block-writes into a vdisk-file, that are also cached, the vdisk-file being located on a lower layer (F:).
    The Windows File Cache-Manager manages Caching per file object. ref: learn.ms/file-caching
    Maybe fs-filebuffer for F: caches a small no blocks of the single large vdisk file (93 GiB), perhaps those blocks from the last few accesses WriteFile() / ReadFile()
    The qsd workaround works because when J: files are being flushed, the qemu-writeFile() F: no longer requires interception and decision by the Windows File Cache-Manager.
    The xcopy /J workaround works because, there is no J: layer file-buffer cache to flush that is intense enough to cause F: writes to block.

    • Commands like Write-VolumeCache learn.ms/write-volumecache and sync F J sysinternals/sync are used to manually commit file-buffer to disk. An admin usually invokes them before unmounting/detaching a volume/disk.
    • 1/8th of the yet-unwritten pages to the drive were written out per second ans.ms/031a , learn.ms/file-caching
    • Windows flushes its internal file cache on an eight-second rotating window. That is, every second, one-eighth of the dirty pages in the cache are queued for writing superuser.com
    • Disk queue length vs secs/rw learn.ms/qa19898
    • Performance Monitoring and Analysis Pierre Bijaoui, Juergen Hasslauer, in Designing Storage for Exchange 2007 SP1, 2008 Disk Queue Length
      • There should never be more than half the number of spindles in the queue length sciencedirect
    • David B Probert - Windows Kernel Internals Cache Manager , Lectures
      • Flushes are synchronous
    • An application can force the operating system to write the contents of these data buffers to the disk by using the FlushFileBuffers() function. Takes file handle as argument. learn.ms/flushing-buffered-io , learn.ms/FlushFIleBuffers
    • Should VM-s/Storage-Backends use the host-file-buffer-cache
      • some sources say yes as it is a performance benefit suse
      • From my reading and thinking so far,
        • letting a VM/Storage-Backend use host-file-buffer-cache
          • con: the VM will consume host resources, and may exhaust the host-file-buffer-memory
          • con: one guest-VM may unfairly use more host-page-cache-resources, and flush-out/ squeeze out another VM-s page cache resources
        • specifying cache.direct=on
          • pro: avoids bugs such as these.
          • if VM and letting VM guest OS manage its own file-buffer-cache in its own memory
            • pro: the guest OS will anyway use a small part of its memory for page-cache
            • pro: the guest OS has more information of the filesystem and file blocks it is saving, so it is in a better position to decide on how to flush/prune/populate its file-buffer-cache. Ex is the file marked as a tmp file, likelihood of frequent access, etc
            • pro: host and guest are insulated from one another.
          • If Storage-backend
            • pro: the file caching will anyway be done on the top level filesystem of host (or guest or whoever else client uses it).
        • letting VM software/Storage-Backend (qemu/qsd) emulate its own disk-block-caches in its (qemu process's) userspace
          • this depends on the implementation, as of today, qemu/qsd doesn't have this, didn't see a way to configure a cache-size option per disk.
    • When we talk about file-caching
      • There is the caching of files (and blocks of files) that have already been recently read or recently saved, to save on future access time.
      • and there is also the caching of files (and blocks of files) that are still yet to be saved, to avoid lowering write-performance by having to do synchronous IO-writes to disks at slower disk-io-speed .
      • The former if lost is not an issue, the later has much higher priority.
      • When cache is flushed, the latter must be written to disks, while the former can be erased from memory.

    Not yet had a testrun where workarounds (cache.direct=off or xcopy /j) did not work, That's good.
    Though the reproducibility without the workaround is probabilistic, the reason I may have had more certainty of running into it, is because I used to let it this run in the background while doing other things, including using Firefox to browse.
    In the 85GiB copy, most stucks do happen under copying of 13 GiB (5 min), I get a bit antsy if xcopy passes that mark. But, I've also had a testrun wherein the stuck-state happened near to the end of the xcopy.

    In the event success happens, one needs to repeat the test a few times, in order to get a statistical feel so as to differentiate between the following cases.

    • test_for_bug_real_fail_success (common, mainly-expected)
    • test_for_bug_spurious_pass (happens rarely)
    • test_for_workaround_real_pass_success (common, mainly-expected)
    • test_for_workaround_spurious_pass (one never knows)
    • test_for_workaround_failure (never happened)
  23. petrutlucian94 commented on May 22, 2023

    @petrutlucian94
    Member

    I had a simple loop that was just copying files and it used to hang after about 5 minutes. After disabling the cache on the nbd server side, it transferred a few TBs overnight without problems.

    The best thing we can do right now is to document this, I'll send a patch. Another option would be to forward LUN resets to the nbd daemon, however that would still be less than ideal: having IO stuck every 5 minutes for 30s (under load), until Storport issues a reset.

    By the way, I've merged the PR that moves the NBD daemon to userspace (libwnbd): #122.

    LE: I've documented it here: #123.

  24. added
    bug
    on May 22, 2023
  25. petrutlucian94 commented on Jun 7, 2023

    @petrutlucian94
    Member

    After documenting the NBD caching issue and implementing stale connection detection (#126), I think we can close this issue.

  26. hgkamath commented on Jun 7, 2023

    @hgkamath
    Author

    Yes, go ahead,

    This is the corresponding issue on the qemu side, just for reference.
    https://gitlab.com/qemu-project/qemu/-/issues/814
    It only contains only occasional summaries as things cleared up.
    I may need to update its description as many confounding issues cleared since time of first filing.

    In a direct email communication that I had with qemu block-code developers, some points that came up :

    • Surprise that cache.direct / file-buffering matters as it is thought that the flag does not affect code path.
    • Insufficient testing of file-win32.c as well as development on the windows side of things
    • Possibility that createfile/overlapped flags were incorrect (as we ourselves had considered)
    • Surprise that qsd continues running normally after being blocked on the writefile, when drive-lockup is ended by uninstalling wnbd-driver and aborting the xcopy.
    • Speculation on whether worker thread exhaustion of a finite-pool of a pre-determined max-number-of-threads was a cause, Thread exhaustion could prevent nbd-export co-routine from waking up and responding to wnbd, thereby initiating the cyclic deadlock. One suggestion I made was to consider if it is possible to reserve a worker thread for nbd.
    • To test if QMP has also gone non-responsive during deadlock, in the manner of nbd. But to do this one needs a port of python-qmp on windows, and complicating matters is that the machine is in drive-lockup and so one can barely start/run anything.
  27. petrutlucian94 commented on Jun 8, 2023

    @petrutlucian94
    Member

    For what is worth, the issue doesn't occur when connecting to remote hosts, even with cache.direct=off. I double checked by running wnbd in a vm and connecting to a qemu nbd server that ran on the physical host.

    This further suggests that the issue comes from the fact that we have buffering at the wnbd disk level as well as the underlying NBD daemon, which receives the actual wnbd IO requests.

    There's probably not much that can be done on the qemu side, other than supporting cache.direct=on with other image formats such as qcow2, assuming that it complies with the IO alignment requirements: https://learn.microsoft.com/en-us/windows/win32/fileio/file-buffering#alignment-and-file-access-requirements. vhd/x images can be attached by Windows natively (e.g. using mount-vhd), so no need to use qemu-nbd/wnbd in that case.

    Talking about natively mounted vhd/x images, it's highly likely that Windows uses ZwCreateFile with FILE_NO_INTERMEDIATE_BUFFERING behind the scenes, especially considering that the vhd/x internal structures are sector aligned.

    By the way, you may also hit this with the latest qemu MSI: https://gitlab.com/qemu-project/qemu/-/issues/1695.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions