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: CLOSED RAWHIDE 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: 2021-11-04 15:26:37 UTC 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.

Comment 7 Ben Cotton 2021-11-04 14:05:07 UTC
This message is a reminder that Fedora 33 is nearing its end of life.
Fedora will stop maintaining and issuing updates for Fedora 33 on 2021-11-30.
It is Fedora's policy to close all bug reports from releases that are no longer
maintained. At that time this bug will be closed as EOL if it remains open with a
Fedora 'version' of '33'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version' 
to a later Fedora version.

Thank you for reporting this issue and we are sorry that we were not 
able to fix it before Fedora 33 is end of life. If you would still like 
to see this bug fixed and are able to reproduce it against a later version 
of Fedora, you are encouraged  change the 'version' to a later Fedora 
version prior this bug is closed as described in the policy above.

Although we aim to fix as many bugs as possible during every release's 
lifetime, sometimes those efforts are overtaken by events. Often a 
more recent Fedora release includes newer upstream software that fixes 
bugs or makes them obsolete.

Comment 8 Ben Cotton 2021-11-04 14:34:07 UTC
This message is a reminder that Fedora 33 is nearing its end of life.
Fedora will stop maintaining and issuing updates for Fedora 33 on 2021-11-30.
It is Fedora's policy to close all bug reports from releases that are no longer
maintained. At that time this bug will be closed as EOL if it remains open with a
Fedora 'version' of '33'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version' 
to a later Fedora version.

Thank you for reporting this issue and we are sorry that we were not 
able to fix it before Fedora 33 is end of life. If you would still like 
to see this bug fixed and are able to reproduce it against a later version 
of Fedora, you are encouraged  change the 'version' to a later Fedora 
version prior this bug is closed as described in the policy above.

Although we aim to fix as many bugs as possible during every release's 
lifetime, sometimes those efforts are overtaken by events. Often a 
more recent Fedora release includes newer upstream software that fixes 
bugs or makes them obsolete.

Comment 9 Richard W.M. Jones 2021-11-04 15:26:37 UTC
This was fixed a few months ago and the fix is definitely in Rawhide
and probably earlier releases too (not sure about F33).

Comment 10 Ben Cotton 2021-11-04 15:31:58 UTC
This message is a reminder that Fedora 33 is nearing its end of life.
Fedora will stop maintaining and issuing updates for Fedora 33 on 2021-11-30.
It is Fedora's policy to close all bug reports from releases that are no longer
maintained. At that time this bug will be closed as EOL if it remains open with a
Fedora 'version' of '33'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version' 
to a later Fedora version.

Thank you for reporting this issue and we are sorry that we were not 
able to fix it before Fedora 33 is end of life. If you would still like 
to see this bug fixed and are able to reproduce it against a later version 
of Fedora, you are encouraged  change the 'version' to a later Fedora 
version prior this bug is closed as described in the policy above.

Although we aim to fix as many bugs as possible during every release's 
lifetime, sometimes those efforts are overtaken by events. Often a 
more recent Fedora release includes newer upstream software that fixes 
bugs or makes them obsolete.