Bug 1772505

Summary: [RHEL7] swapon fails with "swapfile has holes" when created on a xfs filesystem by cloud-init
Product: Red Hat Enterprise Linux 7 Reporter: Teoman ONAY <tonay>
Component: cloud-initAssignee: Eduardo Otubo <eterrell>
Status: CLOSED ERRATA QA Contact: Huijuan Zhao <huzhao>
Severity: high Docs Contact: Jiri Herrmann <jherrman>
Priority: high    
Version: 7.7CC: eterrell, fperalta, gveitmic, huzhao, jgreguske, jherrman, jreznik, mrezanin, ribarry, xiachen, xialiu, yacao, yuxisun
Target Milestone: rcKeywords: Reopened, ZStream
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: cloud-init-19.4-5.el7 Doc Type: Bug Fix
Doc Text:
.Using `cloud-init` to create virtual machines with XFS and swap now works correctly Previously, using the `cloud-init` utility failed when creating a virtual machine (VM) with an XFS root file system and an enabled swap partition. In addition, the following error message was logged: `kernel: swapon: swapfile has holes` This update fixes the underlying code, which prevents the problem from occurring.
Story Points: ---
Clone Of:
: 1794664 1801093 1801094 (view as bug list) Environment:
Last Closed: 2020-09-29 19:48:41 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: 1794664, 1797441, 1801093, 1801094    

Comment 4 Eduardo Otubo 2019-11-18 13:21:58 UTC
This is the rhel7 package with the branch[0] applied:
http://people.redhat.com/~eterrell/cloud-init/1772505/

If this package fixes the issue, we'll still need to wait for it to be merged upstream and only then I'll be doing the backport.

Comment 6 Eduardo Otubo 2019-11-29 11:09:03 UTC
The mentioned pull-request[0] is almost one year old now, without any activities or updates.
I rebased the code, and updated the patche for the new code base on this new pull-request[1]. Still working on the tests as well.
As soon as it's merged I'll backport the patch and update this BZ.

[0] https://code.launchpad.net/~adobrawy/cloud-init/+git/cloud-init/+merge/354680
[1] https://github.com/canonical/cloud-init/pull/70

Comment 7 Francisco Peralta 2019-12-04 12:32:01 UTC
(In reply to Eduardo Otubo from comment #6)

Thank you very much Eduardo. Is it now something I can tell my customer that it's realistic to get in a fixpatch of RHEL 7.7 or how do you see it?

Kind Regards,
 Cisco.

Comment 8 Eduardo Otubo 2019-12-05 15:44:31 UTC
(In reply to Francisco Peralta from comment #7)
> (In reply to Eduardo Otubo from comment #6)
> 
> Thank you very much Eduardo. Is it now something I can tell my customer that
> it's realistic to get in a fixpatch of RHEL 7.7 or how do you see it?
> 
> Kind Regards,
>  Cisco.

In the current scenario it's most likely to have it landed on rhel-7.9, but we can have it backported as z-stream to 7.8 or 7.7 depending on customer needs.

Comment 9 Francisco Peralta 2019-12-05 16:56:32 UTC
(In reply to Eduardo Otubo from comment #8)
> (In reply to Francisco Peralta from comment #7)
> > (In reply to Eduardo Otubo from comment #6)
> > 
> > Thank you very much Eduardo. Is it now something I can tell my customer that
> > it's realistic to get in a fixpatch of RHEL 7.7 or how do you see it?
> > 
> > Kind Regards,
> >  Cisco.
> 
> In the current scenario it's most likely to have it landed on rhel-7.9, but
> we can have it backported as z-stream to 7.8 or 7.7 depending on customer
> needs.

Yes, that would definitely be needed then, customer confirmed already that the test package was working fine so I'd like them to get an official one soon and stay safe.

Thanks in advance!
 Cisco.

Comment 10 Huijuan Zhao 2019-12-06 08:15:19 UTC
QE can reproduce this issue with rhel-7.8(3.10.0-1111.el7.x86_64) + cloud-init-18.5-5.el7.x86_64 on Azure, qa_ack+

Test steps:
1. Create VM with rhel-7.8 on Azure
2. Add additional data disk, format file system as xfs, and mount to /datatest in /etc/fstab
3. Install cloud-init in VM
4. Configure cloud-config:
# cat /etc/cloud/cloud.cfg.d/06_swap.cfg 
swap:
  filename: /datatest/swap.img
  size: "auto" # or size in bytes
  maxsize: 2G 
5. Reboot VM
6. Login VM and check the /var/log/messages and /var/log/cloud-init.log

Actual results:
After step 6, swap file is created but swapon failed with this error : kernel: swapon: swapfile has holes.

# free -m
              total        used        free      shared  buff/cache   available
Mem:           3171         224        2736           9         211        2720
Swap:          2047           0        2047

# ls /datatest/
swap.img

/var/log/cloud-init.log
-----------------------
2019-12-06 07:12:26,228 - util.py[DEBUG]: Running command ['swapon', '-a'] with allowed return codes [0] (shell=False, capture=True)
2019-12-06 07:12:26,265 - cc_mounts.py[WARNING]: Activate mounts: FAIL:swapon -a
2019-12-06 07:12:26,266 - util.py[WARNING]: Activate mounts: FAIL:swapon -a
2019-12-06 07:12:26,266 - util.py[DEBUG]: Activate mounts: FAIL:swapon -a
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/cloudinit/config/cc_mounts.py", line 495, in handle
    util.subp(cmd)
  File "/usr/lib/python2.7/site-packages/cloudinit/util.py", line 2068, in subp
    cmd=args)
ProcessExecutionError: Unexpected error while running command.
Command: ['swapon', '-a']
Exit code: 255
Reason: -
Stdout:
Stderr: swapon: /mnt/cloudinitswap/swap.img: swapon failed: Invalid argument


/var/log/messages
-----------------
Dec  6 15:12:26  kernel: swapon: swapfile has holes
Dec  6 15:12:26  cloud-init: 2019-12-06 07:12:26,265 - cc_mounts.py[WARNING]: Activate mounts: FAIL:swapon -a
Dec  6 15:12:26  cloud-init: 2019-12-06 07:12:26,266 - util.py[WARNING]: Activate mounts: FAIL:swapon -a

Expected results:
swap should be enabled without error

Comment 43 Huijuan Zhao 2020-04-27 14:37:15 UTC
Tested with cloud-init-19.4-5.el7 in rhel-7.9, the issue is gone.
Change the status to VERIFIED.

Comment 46 errata-xmlrpc 2020-09-29 19:48:41 UTC
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 (Moderate: cloud-init security, 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/RHSA-2020:3898