Note: This is a public test instance of Red Hat Bugzilla. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback at bugzilla.redhat.com.

Bug 1926954

Summary: virt-sparsify of NTFS image in-place fails with FITRIM ioctl failed: Device or resource busy
Product: [Fedora] Fedora Reporter: Andrew M. <andrew>
Component: kernelAssignee: Kernel Maintainer List <kernel-maint>
Status: NEW --- QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 33CC: acaringi, adscvr, airlied, alciregi, bskeggs, hdegoede, itamar, jarodwilson, jeremy, jglisse, jonathan, josef, juzhou, kernel-maint, kheine7, lgoncalv, linville, masami256, mchehab, mxie, ptalbert, rjones, steved, tyan, tzheng, xiaodwan, yoguo, zili
Target Milestone: ---   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 1927184 (view as bug list) Environment:
Last Closed: Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 910269, 1927184    
Attachments:
Description Flags
virt-sparsify-debug.log none

Description Andrew M. 2021-02-09 18:04:36 UTC
Created attachment 1755998 [details]
virt-sparsify-debug.log

Description of problem:

Attempting to in-place sparsify an NTFS image fails.


Version-Release number of selected component (if applicable):
libguestfs-1:1.43.2-2.fc33.x86_64
libguestfs-tools-1:1.43.2-2.fc33.noarch

How reproducible:
Always


Steps to Reproduce:
1. Create NTFS qcow2 image
```
guestfish <<EOF
disk-create test.qcow2 qcow2 1G
add test.qcow2
run
part-disk /dev/sda gpt
mkfs ntfs /dev/sda1
EOF
```
2. virt-sparsify --in-place -x -v test.qcow2

(this also occurs on a qcow2 image from a clean Windows install)

Actual results:

virt-sparsify: error: libguestfs error: fstrim: fstrim: /sysroot/: FITRIM 
ioctl failed: Device or resource busy


Expected results:

Sparsify in-place operation completed with no errors


Additional info:
- Omitting `--in-place` and specifying a destination image works.
- Tested with vfat and ext4 instead of ntfs; both were successful with in-place.
- Debug log is attached
- libguestfs-test-tool reports OK

Comment 1 Richard W.M. Jones 2021-02-09 18:33:20 UTC
I can reproduce the bug.  It fails in the same way in virt-rescue too:

$ virt-rescue --ro -a test.qcow2 
><rescue> mount -o discard /dev/sda1 /sysroot/
><rescue> fstrim -v /sysroot/
fstrim: /sysroot/: FITRIM ioctl failed: Device or resource busy

Comment 2 Richard W.M. Jones 2021-02-09 18:38:07 UTC
With ntfs-3g option -o debug enabled:

unique: 4, opcode: GETATTR (3), nodeid: 1, insize: 56
   unique: 4, error: 0 (Success), outsize: 120
unique: 6, opcode: GETATTR (3), nodeid: 1, insize: 56
   unique: 6, error: 0 (Success), outsize: 120
unique: 8, opcode: GETATTR (3), nodeid: 1, insize: 56
   unique: 8, error: 0 (Success), outsize: 120
unique: 10, opcode: ACCESS (34), nodeid: 1, insize: 48
ACCESS / 00
   unique: 10, error: 0 (Success), outsize: 16
unique: 12, opcode: OPENDIR (27), nodeid: 1, insize: 48
   unique: 12, error: 0 (Success), outsize: 32
unique: 14, opcode: IOCTL (39), nodeid: 1, insize: 96
   unique: 14, error: 0 (Success), outsize: 56
fstrim: /sysroot/: FITRIM ioctl failed: Device or resource busy
unique: 16, opcode: RELEASEDIR (29), nodeid: 1, insize: 64
   unique: 16, error: 0 (Success), outsize: 16

Which makes me think the error must actually be coming from FUSE or the
host kernel.  (Note that the ioctl call succeeds according to ntfs-3g.)

Comment 4 Richard W.M. Jones 2021-02-09 21:33:54 UTC
I have bisected this in the kernel.  Please see my comments
on the upstream bug:
https://bugzilla.kernel.org/show_bug.cgi?id=211167

Comment 5 Richard W.M. Jones 2021-02-09 21:34:16 UTC
*** Bug 1922857 has been marked as a duplicate of this bug. ***

Comment 6 Andrew M. 2021-04-30 21:03:37 UTC
Upstream Kernel bug linked above indicates this is resolved, and my test case succeeds now in Fedora using Kernel 5.11.16-300.fc34.x86_64.