Page MenuHomeFreeBSD

swapon: parse md.eli device for encrypted swapfile from fstab
ClosedPublic

Authored by ronald_klop.ws on Feb 6 2025, 10:15 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Sep 26, 2:17 AM
Unknown Object (File)
Wed, Sep 24, 11:19 AM
Unknown Object (File)
Wed, Sep 24, 4:07 AM
Unknown Object (File)
Tue, Sep 16, 7:06 PM
Unknown Object (File)
Mon, Sep 15, 2:20 AM
Unknown Object (File)
Sep 6 2025, 2:31 PM
Unknown Object (File)
Sep 5 2025, 9:17 AM
Unknown Object (File)
Sep 5 2025, 1:20 AM

Details

Summary

Although fstab(5) suggests usage of md(4) and an .eli suffix in the same
paragraph, the combination did not work.
This patch adds a bit of parsing, creates the md device and then passes
that device to the *_geli function.

PR: 186252
MFC after: 2 weeks
Relnotes: yes

Test Plan
# truncate -s 1m /tmp/swapfile
# echo "md0.eli    none    swap    sw,file=/tmp/swapfile  0       0" > /tmp/fstab
# /sbin/swapon -F /tmp/fstab -a
swapon: Bad device unit: md0.eli: Invalid argument

# /usr/obj/usr/src/arm64.aarch64/sbin/swapon/swapon -F /tmp/fstab -a
swapon: adding /dev/md0.eli as swap device

# swapinfo
Device          1K-blocks     Used    Avail Capacity
/dev/gpt/ssdswap0   8388608        0  8388608     0%
/dev/md0.eli         1024        0     1024     0%
Total             8389632        0  8389632     0%

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

Could you add a short test plan to follow?

ronald_klop.ws edited the test plan for this revision. (Show Details)
In D48874#1114805, @dsl wrote:

Could you add a short test plan to follow?

I hope the test plan is as expected. Otherwise please let me know.

allanjude added inline comments.
sbin/swapon/swapon.c
235

Wouldn't we end up calling swap_on_off_md() for a .eli that is NOT an md now?

Is _PATH_DEV missing here as well?

In D48874#1114805, @dsl wrote:

Could you add a short test plan to follow?

I hope the test plan is as expected. Otherwise please let me know.

I think the test plan needs to test other cases (a .eli that is not a md(4), and md without eli, etc)

Add unit test.
Use constant for repeated string.

ronald_klop.ws added inline comments.
sbin/swapon/swapon.c
235

For other .eli devices this if statement will not match. Tested it on my device with /dev/gpt/ssdswap0.eli.

Added _PATH_DEV similar to the non-eli statements.

And added unit test!

ronald_klop.ws marked an inline comment as done.

Add a more complete unit test set.

delphij added a subscriber: delphij.

Looks good to me overall, thanks for working on this! Please fix the free() operation in inline comment.

sbin/swapon/swapon.c
452

dname is not allocated by us; it may happen to be equal to devbuf but not guaranteed.

I think it's better to free(devbuf) here instead.

This revision is now accepted and ready to land.May 31 2025, 1:51 PM