Skip to content

[BUG] swapfile size is incorrect if value is not integer multiple of 64M in ext4 filesystem #2286

@yuxisun1217

Description

@yuxisun1217

Describe the bug: A clear and concise description of what the bug is.
In ext4 filesystem, if set the swapfile size as non-integer multiple of 64M(e.g. 1025), the actual swapfile size is 1024. The remaining sizes are not added.

Distro and WALinuxAgent details (please complete the following information):

  • Distro and Version: RHEL-8
  • WALinuxAgent version:
    WALinuxAgent-2.3.0.2 running on redhat 8.5
    Python: 3.6.8
    Goal state agent: 2.3.0.2

Additional context
The log is:

2021-06-29T07:24:18.819616Z INFO Daemon Daemon Create swap file
2021-06-29T07:24:18.820073Z VERBOSE Daemon Daemon Command: [umask 0077 && dd if=/dev/zero bs=67108864 count=16 conv=notrunc of='/mnt/resource/swapfile']
2021-06-29T07:24:20.011228Z VERBOSE Daemon Daemon Command: [umask 0077 && dd if=/dev/zero bs=1048576 count=1 conv=notrunc of='/mnt/resource/swapfile']

If run these 2 commands manually, the second command cannot append the remain size to the swapfile.

[root@walaautowaf1 resource]# umask 0077 && dd if=/dev/zero bs=67108864 count=16 conv=notrunc of='/mnt/resource/swapfile1'
16+0 records in
16+0 records out
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 1.04277 s, 1.0 GB/s
[root@walaautowaf1 resource]# ll swapfile1
-rw-------. 1 root root 1073741824 Jun 29 15:42 swapfile1
[root@walaautowaf1 resource]# umask 0077 && dd if=/dev/zero bs=1048576 count=1 conv=notrunc of='/mnt/resource/swapfile1'
1+0 records in
1+0 records out
1048576 bytes (1.0 MB, 1.0 MiB) copied, 0.000946101 s, 1.1 GB/s
[root@walaautowaf1 resource]# ll swapfile1
-rw-------. 1 root root 1073741824 Jun 29 15:42 swapfile1

ret += shellutil.run(dd_cmd.format(remains, 1, fn_sh))

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions