Page MenuHomeFreeBSD

bectl: use jail id as the default jail name for a boot environment
ClosedPublic

Authored by rew on Dec 19 2018, 11:14 AM.
Tags
None
Referenced Files
Unknown Object (File)
Jan 4 2024, 3:23 AM
Unknown Object (File)
Dec 31 2023, 1:43 PM
Unknown Object (File)
Dec 20 2023, 4:25 AM
Unknown Object (File)
Nov 8 2023, 2:05 PM
Unknown Object (File)
Sep 17 2023, 12:22 AM
Unknown Object (File)
Aug 22 2023, 4:18 PM
Unknown Object (File)
Jun 28 2023, 8:10 AM
Unknown Object (File)
Jun 28 2023, 8:09 AM
Subscribers

Details

Summary

This is about bug 233637 and the patch is based off r342069

By default, bectl is setting the jail 'name' parameter to the
boot environment name, which causes an error when the boot
environment name is not a valid jail name. With the attached fix,
when no name is supplied, the default jail name will be the
jail id - this is is the same behavior as the jail command.

During testing, when I started using the jail id as the default
name, the jail would execute with no errors. However, bectl
wasn't able to unjail a boot environment because it was
failing to match the boot environment path with an existing
jail path. The source of this problem was two bugs.

  1. in 'bectl_locate_jail', 'mountpoint' is used to resolve the boot environment path, but really 'mounted' should be used. 'mountpoint' is the path where the zfs dataset will be mounted. 'mounted' is the path where the boot environment is mounted.
  1. in 'bectl_search_jail_paths', 'jail_getv' would fail after the first call. Which is fine, if the boot environment you're unjailing is the next one up. According to 'man jail_getv', it's expecting name and value strings. 'jail_getv' is being passed an integer for the lastjid. The attached patch uses a string for the lastjid instead.

link to bug report: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=233637

Test Plan

create a boot environment that's an invalid jail name.
create a jail for the boot environment with default name.
try to unjail the boot environment

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

Thanks for the submission, just some small nits and I'll bump .Dd on bectl(8) pre-commit.

sbin/bectl/bectl_jail.c
313 ↗(On Diff #52160)

style(9) nit; initialization of jid should happen independently of the declaration, right around the below snprintf.

320 ↗(On Diff #52160)

Good catch!

Can I coax you into adding a test to ^/sbin/bectl/tests for this bit? This clearly was the result of improper testing and my 'still trying (and failing, kind of) to figure out libjail' while playing with this.

Added tests in sbin/bectl/test and fixed styling issues.

I've included 2 tests.

  1. when a jail name is not set explicitly, it should match the jail id.
  2. test 'unjail'ing by boot environment name. In this test, the purpose is to force bectl to lookup the jail id by the boot environment name.

In sbin/bectl/tests, I added additional cleanup code in 'bectl_jail_cleanuo()'. I
first wrote these tests to fail without the patch. When the tests would fail
the test zpool would fail to destroy because the boot environment jails hadn't
been removed. The additional clean-up code checks if there are any boot
environments with a corresponding jail and removes the jail if a match was found.

This revision is now accepted and ready to land.Dec 24 2018, 5:41 AM
This revision was automatically updated to reflect the committed changes.