Do not use fallocate in swap file creation on xfs.#70
Conversation
|
This is just the first draft RFC and check. No tests written yet. |
OddBloke
left a comment
There was a problem hiding this comment.
Broadly speaking, I'm happy with the direction here. Some high-level questions/comments left inline.
(Note that I do have some more specific comments to make in a future review pass, but they may no longer apply after we've worked through my high-level concerns so I figured it would be a waste of everyone's time to leave them at this juncture. :-)
|
Marking WIP till tests are written |
OddBloke
left a comment
There was a problem hiding this comment.
Thanks for the updates! I have a few more thoughts inline.
9a84a8f to
84736fb
Compare
|
Related bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1772505 |
|
Eduardo thanks for the contribution here github-side! Just one more step so we can correlate old launchpad accounts that have signed the CLA to your github account so that we have accountability for which accounts actually signed the Contribution License Agreement. Please run ./tools/migrate-lp-user-to-github to allow us to track your ownership of both launchpad and github accounts. Details are in our updated hacking guide https://cloudinit.readthedocs.io/en/latest/topics/hacking.html#do-these-things-once |
Thanks Chad! |
|
Also, I have to say that I already have a commit on cloud-init on the github repository before I run this tool: f1094b1 |
When creating a swap file on an xfs filesystem, fallocate cannot be used. Doing so results in failure of swapon and a message like: swapon: swapfile has holes The solution here is to maintain a list (currently containing only XFS) of filesystems where fallocate cannot be used. The, on those fileystems use the slower but functional 'dd' method. Based on initial pull request: https://code.launchpad.net/~adobrawy/cloud-init/+git/cloud-init/+merge/354680 And further comments from Scott Moser: http://paste.ubuntu.com/p/8pVhczVqG3/ Signed-off-by: Eduardo Otubo <otubo@redhat.com>
In order to avoid duplicate code the function create_swapfile() was reduced and a new function create_swap() was introduced. create_swapfile identifies which type of filesystem is currently in use (xfs or btrfs) and calls create_swap(), that chooses between dd and fallocate - this, in case of failure will try dd as fallback. Signed-off-by: Eduardo Otubo <otubo@redhat.com>
Signed-off-by: Eduardo Otubo <otubo@redhat.com>
* replacing function get_fstype() by util.del_file() * removing get_fstype() by it's return call, avoinding a new function call * replacing os.chmod() by util.chmod() and removing from try block Signed-off-by: Eduardo Otubo <otubo@redhat.com>
OddBloke
left a comment
There was a problem hiding this comment.
One remaining comment, we're very close!
blackboxsw
left a comment
There was a problem hiding this comment.
Thanks otubo for the fixes!
|
This commit broke swap file creation, with the following error: cc_mounts.py[WARNING]: failed to setup swap: %d format: a number is required, not str |
| fname, fstype, method) | ||
|
|
||
| if method == "fallocate": | ||
| cmd = ['fallocate', '-l', '%dM' % size, fname] |
There was a problem hiding this comment.
Size is a string, not a number, so '%s' format specifier should be used.
| cmd = ['fallocate', '-l', '%dM' % size, fname] | ||
| elif method == "dd": | ||
| cmd = ['dd', 'if=/dev/zero', 'of=%s' % fname, 'bs=1M', | ||
| 'count=%d' % size] |
There was a problem hiding this comment.
While I don't use xfs, I suspect this too should be using a '%s' format specifier since size is a string.
| def create_swapfile(fname, size): | ||
| """Size is in MiB.""" | ||
|
|
||
| errmsg = "Failed to create swapfile '%s' of size %dMB via %s: %s" |
There was a problem hiding this comment.
This too should likely be a '%s' format modifier instead of '%d' since size is a string.
|
@otubo thoughts on the above comments? @norrisjeremy if you have not already can you open a bug: https://bugs.launchpad.net/cloud-init/+filebug |
|
FYI, I discovered this when attempting to spin up the latest 20.04 beta cloud image and noticed that swapfile creation didn't work in my cloud-config.yml. Hopefully this can be fixed before next weeks release? |
|
Fix in #316 |
When creating a swap file on an xfs filesystem, fallocate cannot be used.
Doing so results in failure of swapon and a message like:
swapon: swapfile has holes
The solution here is to maintain a list (currently containing only XFS)
of filesystems where fallocate cannot be used. The, on those fileystems
use the slower but functional 'dd' method.
Based on initial pull request:
https://code.launchpad.net/~adobrawy/cloud-init/+git/cloud-init/+merge/354680
And further comments from Scott Moser:
http://paste.ubuntu.com/p/8pVhczVqG3/
Signed-off-by: Eduardo Otubo otubo@redhat.com