I've taken a look at the qemu source code (7.2.0 happens to be unpacked on my hard drive).
I have noticed that there probably two separate implementations of virtual disk devices supporting unmap/discard. My scrapbook notes on this chapter: 1) hw/scsi/scsi-disk.c: // The following reflects in max_unmap_size and max_unmap_sectors // in VPD page 0xb0 AKA "block limits". // How 'bout if we redefine this to 0 ? #define DEFAULT_MAX_UNMAP_SIZE (1 * GiB) Curiously, the Logical Block Provisioning VPD page (0x82) is not considered... in function scsi_disk_emulate_vpd_page() 2) the virtio collective: hw/block/virtio-blk.c hw/block/virtio-blk-common.c include/standard-headers/linux/virtio_blk.h VIRTIO_BLK_F_DISCARD conf.max_discard_sectors block/export/vhost-user-blk-server.c VIRTIO_BLK_MAX_DISCARD_SECTORS struct virtio_blk_config virtio_blk_set_config virtio_blk_handle_scsi_req() is a passthrough to async IO ? Here, it appears that VIRTIO_BLK_F_DISCARD is a feature of the "disk controller" (virtio itself) i.e. it is global, but there's a device-private member "max_discard_sectors" which sounds interesting, perhaps could be set to 0. Somewhere in the code, I've spotted a check, if VIRTIO_BLK_F_DISCARD is wholesale enabled, that max_discard_sectors must be non-zero, otherwise virtio-blk throws a fit (error). Curiously the virtio_blk_set_config() appears to have a single settable option, which is "write cache enable" (or wce for short). Perhaps this could be extended to have the max_discard_sectors affected as well. But, I'm also wondering how the guest-side virtio drivers go about inquiring the disk devices. If they tap directly into the virtio_blk_config and maybe even the virtio global config, then it may as well be hard cheese :-) I.e. the guest OS will get informed that the virtio-blk devices *do* categorically support Discard, and may throw erros at the guest side, if it turns out that the maximum Discard length is 0 sectors :-) The truth is, that I haven't found the exact mechanism, how the guest-side drivers ask the host-side Virtio stack / how it inquires the virtio devices. And, there is also a "SCSI command handler" within hw/block/virtio-blk.c which seems to just take any incoming SCSI commands and shovel them "down some further pipeline" - looks like an async IO ioctl() or something... makes me wonder if "there someplace else" the Inquiry could actually be handled, including the VPD page 0x82, which we could catch and maybe rig... I just don't know. This is over my head. I'm done :-) Frank BTW see also SCSI Commands Reference Manual https://www.seagate.com/files/staticfiles/support/docs/manual/Interfac e%20manuals/100293068j.pdf 5.4.13 Logical Block Provisioning VPD page (82h) That's where the LBPU flag is defined...
