Skip to content

Do not use fallocate in swap file creation on xfs.#70

Merged
blackboxsw merged 7 commits into
canonical:masterfrom
otubo:fallocate_swap
Jan 23, 2020
Merged

Do not use fallocate in swap file creation on xfs.#70
blackboxsw merged 7 commits into
canonical:masterfrom
otubo:fallocate_swap

Conversation

@otubo
Copy link
Copy Markdown
Contributor

@otubo otubo commented Nov 29, 2019

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

@otubo
Copy link
Copy Markdown
Contributor Author

otubo commented Nov 29, 2019

This is just the first draft RFC and check. No tests written yet.

Copy link
Copy Markdown
Collaborator

@OddBloke OddBloke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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. :-)

Comment thread cloudinit/config/cc_mounts.py Outdated
Comment thread cloudinit/config/cc_mounts.py Outdated
Comment thread cloudinit/config/cc_mounts.py Outdated
@powersj
Copy link
Copy Markdown
Contributor

powersj commented Dec 11, 2019

Marking WIP till tests are written

@powersj powersj added the wip Work in progress, do not land label Dec 11, 2019
@otubo otubo requested a review from OddBloke December 12, 2019 12:03
Copy link
Copy Markdown
Collaborator

@OddBloke OddBloke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates! I have a few more thoughts inline.

Comment thread cloudinit/config/cc_mounts.py Outdated
Comment thread cloudinit/config/cc_mounts.py
Comment thread cloudinit/config/cc_mounts.py Outdated
Comment thread cloudinit/config/cc_mounts.py Outdated
Comment thread cloudinit/config/cc_mounts.py Outdated
Comment thread cloudinit/config/cc_mounts.py
Comment thread tests/unittests/test_handler/test_handler_mounts.py Outdated
Comment thread cloudinit/config/cc_mounts.py Outdated
Copy link
Copy Markdown
Collaborator

@igalic igalic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙋

Comment thread cloudinit/config/cc_mounts.py
@otubo
Copy link
Copy Markdown
Contributor Author

otubo commented Dec 19, 2019

Related bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1772505

@blackboxsw
Copy link
Copy Markdown
Collaborator

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

@blackboxsw blackboxsw added the CLA not signed The submitter of the PR has not (yet) signed the CLA label Dec 19, 2019
@otubo
Copy link
Copy Markdown
Contributor Author

otubo commented Dec 20, 2019

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!
I started the process here: #135

@otubo
Copy link
Copy Markdown
Contributor Author

otubo commented Dec 20, 2019

Also, I have to say that I already have a commit on cloud-init on the github repository before I run this tool: f1094b1
Not sure if there's anything to be done on this commit for some reason :-)

@blackboxsw blackboxsw added CLA signed The submitter of the PR has signed the CLA and removed CLA not signed The submitter of the PR has not (yet) signed the CLA labels Jan 9, 2020
Copy link
Copy Markdown
Collaborator

@igalic igalic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment thread cloudinit/config/cc_mounts.py Outdated
Comment thread cloudinit/config/cc_mounts.py Outdated
Comment thread cloudinit/config/cc_mounts.py Outdated
otubo added 5 commits January 15, 2020 13:13
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>
Copy link
Copy Markdown
Collaborator

@OddBloke OddBloke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One remaining comment, we're very close!

Comment thread cloudinit/config/cc_mounts.py Outdated
Copy link
Copy Markdown
Collaborator

@OddBloke OddBloke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM now, thank you!

@OddBloke OddBloke removed the wip Work in progress, do not land label Jan 23, 2020
Copy link
Copy Markdown
Collaborator

@blackboxsw blackboxsw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks otubo for the fixes!

@blackboxsw blackboxsw merged commit 6603706 into canonical:master Jan 23, 2020
@norrisjeremy
Copy link
Copy Markdown

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]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This too should likely be a '%s' format modifier instead of '%d' since size is a string.

@powersj
Copy link
Copy Markdown
Contributor

powersj commented Apr 14, 2020

@otubo thoughts on the above comments?

@norrisjeremy if you have not already can you open a bug: https://bugs.launchpad.net/cloud-init/+filebug

@norrisjeremy
Copy link
Copy Markdown

@powersj Please see https://bugs.launchpad.net/cloud-init/+bug/1872836

@norrisjeremy
Copy link
Copy Markdown

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?

@powersj
Copy link
Copy Markdown
Contributor

powersj commented Apr 15, 2020

Fix in #316

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA signed The submitter of the PR has signed the CLA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants