Bug 1889822
| Summary: | creating file base backing store does not create sparse files when requested | ||
|---|---|---|---|
| Product: | Red Hat Enterprise Linux 8 | Reporter: | Ken Green <Ken.Green> |
| Component: | targetcli | Assignee: | Maurizio Lombardi <mlombard> |
| Status: | CLOSED ERRATA | QA Contact: | Filip Suba <fsuba> |
| Severity: | unspecified | Docs Contact: | |
| Priority: | unspecified | ||
| Version: | 8.2 | CC: | fsuba, ldixon, sostapov |
| Target Milestone: | rc | Keywords: | Triaged |
| Target Release: | 8.0 | Flags: | pm-rhel:
mirror+
|
| Hardware: | Unspecified | ||
| OS: | Unspecified | ||
| Whiteboard: | |||
| Fixed In Version: | Doc Type: | If docs needed, set a value | |
| Doc Text: | Story Points: | --- | |
| Clone Of: | Environment: | ||
| Last Closed: | 2021-05-18 15:52:28 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: | |||
|
Description
Ken Green
2020-10-20 16:26:18 UTC
Thanks for reporting this bug.
I gave the code a quick look and I think this has been introduced by an old targetcli patch merged in 2013 (id 3bd4d8ef7c9b154c53e8b8dd863a570bce7f5c2c)
The commit message reads:
Fix issue #23: use fallocate() to create fileio backstores
Python 3.3 provides the fallocate() system call which is better for
allocating disk space than ftruncate(). ftruncate() sets the file size
to the requested size but does not reserve the blocks in the file
system. Unlike ftruncate(), fallocate() fails if there is not enough
free space.
if sparse:
- os.ftruncate(f.fileno(), size)
+ try:
+ os.posix_fallocate(f.fileno(), 0, size)
+ except AttributeError:
+ # Prior to version 3.3, Python does not provide fallocate
+ os.ftruncate(f.fileno(), size)
This explains why it works correctly on RHEL7:
RHEL7 ships with Python2, so it doesn't call fallocate() and falls back to ftruncate().
Thanks for that Maurizio The work around from the shell is easy enough, just use dd to make a sparse file and the Linux dd allows a count=0. [root@m10vm3 ~]# [root@m10vm3 ~]# mkdir /iscsi [root@m10vm3 ~]# dd if=/dev/zero of=/iscsi/test1 bs=1024k seek=16384 count=0 0+0 records in 0+0 records out 0 bytes copied, 0.000141885 s, 0.0 kB/s [root@m10vm3 ~]# targetcli <<< "/backstores/fileio create test1 /iscsi/test1 16G write_back=false sparse=true" targetcli shell version 2.1.51 Copyright 2011-2013 by Datera, Inc and others. For help on commands, type 'help'. /> /iscsi/test1 exists, using its size (17179869184 bytes) instead Created fileio test1 with size 17179869184 /> exit Global pref auto_save_on_exit=true Last 10 configs saved in /etc/target/backup/. Configuration saved to /etc/target/saveconfig.json [root@m10vm3 ~]# [root@m10vm3 ~]# ls -ls /iscsi/test1 0 -rw-r--r--. 1 root root 17179869184 Oct 21 13:11 /iscsi/test1 [root@m10vm3 ~]# The solution fallocate would be great for the non-sparse case. It looks like the script is writing billions of NULLs in a rather inefficient way. Besides the underlying storage probably can't do anything like thin provision it. Cheers Ken This bug bit me too. I have always used fallocate to create sparse files for fileio backstores. Where I wanted to allocate the blocks, but not consume any space until the blocks were actually used. I could easily do this in RHEL7, but when I upgraded to RHEL8 I found I couldnt create sparse files anymore. I had to use the dd trick mentioned in https://bugzilla.redhat.com/show_bug.cgi?id=1889822#c2 I submitted a pull request to targetcli upstream https://github.com/open-iscsi/targetcli-fb/pull/177 Verified with targetcli-2.1.53-2.el8. Regression testing passed. /backstores/fileio> create test test.img 16G write_back=false sparse=true # ls -ls 0 -rw-r--r--. 1 root root 17179869184 Dec 15 10:06 test.img Since the problem described in this bug report should be resolved in a recent advisory, it has been closed with a resolution of ERRATA. For information on the advisory (targetcli bug fix and enhancement update), and where to find the updated files, follow the link below. If the solution does not work for you, open a new bug report. https://access.redhat.com/errata/RHBA-2021:1867 |