Commit Graph

71 Commits

Author SHA1 Message Date
Kyle Evans
d05fa0d949 bectl(8): create non-recursive boot environments
bectl advertises that it has the ability to create recursive and
non-recursive boot environments. This patch implements that functionality
using the be_create_depth API provided by libbe. With this patch, bectl now
works as bectl(8) describes in regards to creating recursive/non-recursive
boot environments.

Submitted by:	Rob Fairbanks <rob.fx907 gmail com> (with minor changes)
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D20240
2019-06-27 14:03:32 +00:00
Kyle Evans
7c08a497ba bectl(8): Don't accept jid=0 from jail_getid
This will trivially exist, but we don't want it - none of our jailed BEs
will have jid=0.

MFC after:	3 days
2019-06-02 14:05:51 +00:00
Kyle Evans
515fa27bb0 bectl(8): Address Coverity complaints
CID 1400451: case 0 is missing a break/return and falling through to the
default case.  waitpid(0, ...) makes little sense in the child, we likely
wanted to terminate immediately.

CID 1400453: size argument uses sizeof(char **) instead of sizeof(char *)
and is assigned to a char **; sizeof's match but "this isn't a portable
assumption".

CID:	1400451, 1400453
MFC after:	3 days
2019-05-28 16:12:16 +00:00
Kyle Evans
22554a341e bectl(8): Add a test for jail/unjail of numeric BE names
Fixed by r348215, bectl ujail first attempts the trivial fetch of a jid by
passing the first argument to 'ujail' to jail_getid(3) in case a jid/name
have been passed in instead of a BE name. For numerically named BEs, this
was doing the wrong thing: instead of failing to locate the jid specified
and falling back to mountpath search, jail_getid(3) would return the input
as-is.

While here, I've fixed bectl_jail_cleanup which still used a hard-coded pool
name that was overlooked w.r.t. other work that was in-flight around the
same time.

MFC after:	3 days
2019-05-24 01:53:45 +00:00
Kyle Evans
55ece394c2 bectl(8): add description for create subcommand
In commit r345845, a portion of documentation for the create subcommand was
removed. Specifically, for creating a snapshot of an existing boot
environment. bectl even has a test-case for this functionality.

Removing the sub-command description was discussed in PR 235850.

This patch brings back the second "create" description that was originally
in place. Albeit, with a few wording/clarifying changes.

Submitted by:	Rob Fairbanks <rob.fx907 gmail com>
Reviewed by:	kevans
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D20249
2019-05-22 23:07:40 +00:00
Mateusz Piotrowski
2b9dde098f bectl.8: Bump date after r345845
Approved by:	kevans
2019-04-03 13:59:35 +00:00
Mateusz Piotrowski
77688bff1e bectl.8: Clean up & clarify the create subcommand
- Improve formatting
- Use consistent variable names
- Improve the description of the create subcommand (1)

PR:		235850 (1)
Submitted by:	kevans (1)
Reported by:	ler (1)
Reviewed by:	kevans
Approved by:	src (kevans)
Differential Revision:	https://reviews.freebsd.org/D19666
2019-04-03 13:46:43 +00:00
Kyle Evans
e1ee62302a libbe: Fix zfs_is_mounted check w/ snapshots
'be_destroy' can destroy a boot environment (by name) or a given snapshot.
If the target to be destroyed is a dataset, check if it's mounted. We don't
want to check if the origin dataset is mounted when destroying a snapshot.

PR:		236043
Submitted by:	Rob Fairbanks <rob.fx907 gmail com>
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D19650
2019-04-01 17:44:20 +00:00
Kyle Evans
938b7a44d9 bectl(8): change jail command to execute jail(8)
The jail(8) command provides a variety of jail pseudo-parameters that are
useful to consumers of bectl, mount.devfs being the most-often-requested
paramater by bectl users.

command, exec.start, nopersist, and persist may not be specified via -o to
bectl. The command/exec.start remains passed as it always has at the end of
bectl, and persistence is dictated by -b/-U bectl jail arguments.

Submitted by:	Wes Maag <jwmaag gmail com>
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D19282
2019-03-19 17:38:54 +00:00
Enji Cooper
794022b04a Fix up concurrent test zpool setup and teardown
Set up zpools with a more unique name, stash the zpool name away in a file pointed
to by `$ZPOOL_NAME_FILE` (which is relative to a per-testcase generated temporary
directory), then remove the file based on `$ZPOOL_NAME_FILE` in the cleanup
routines.

This is a more concurrency-safe solution and will allow the testcases to be safely
executed in parallel.

Reviewed by:	kevans, jtl
Approved by:	jtl (mentor)
MFC after:	1 week
Differential Revision: https://reviews.freebsd.org/D19024
2019-02-12 23:35:46 +00:00
Kyle Evans
6286a6438e bectl(8): commit missing test modifications from r343993
X-MFC-With:	r343993
2019-02-11 04:00:42 +00:00
Kyle Evans
77b4126ce6 bectl(8): Add -o flag to destroy to clean up the origin snapshot of BE
We can't predict when destruction of origin is needed, and currently we have
a precedent for not prompting for things. Leave the decision up to the user
of bectl(8) if they want the origin snapshot to be destroyed or not.

Emits a warning when -o isn't used and an origin snapshot is left to be
cleaned up, for the time being. This is handy when one drops the -o flag but
really did want to clean up the origin.

A couple of -e ignore's have been sprinkled around the test suite for places
that we don't care that the origin's not been cleaned up. -o functionality
tests will be added in the future, but are omitted for now to reduce
conflicts with work in flight to fix bits of the tests.

Reported by:	Shawn Webb
MFC after:	1 week
2019-02-11 04:00:01 +00:00
Kyle Evans
bf05ccc397 bectl(8) test: Force destroy the zpool in cleanup
This is a wild guess as to why bectl tests failed once upon a time in CI,
given no apparent way to see a transcript of cleanup routines with Kyua. The
bectl tests construct a new, clean zpool for every test. The failure
indicated was because of a mount that was leftover from a previous test, but
the previous test had succeeded so it's not clear how the mount remained
leftover unless the `zpool get health ${pool}` had somehow failed.

MFC after:	1 week
2019-01-29 04:08:49 +00:00
Kyle Evans
0a603a6ece libbe(3): Change be_mount to mount/unmount child datasets
This set of changes is geared towards making bectl respect deep boot
environments when they exist and are mounted. The deep BE composition
functionality (`bectl add`) remains disabled for the time being. This set of
changes has no effect for the average user. but allows deep BE users to
upgrade properly with their current setup.

libbe(3): Open the target boot environment and get a zfs handle, then pass
that with the target mountpoint to be_mount_iter; If the BE_MNT_DEEP flag is
set call zfs_iter_filesystems and mount the child datasets.

Similar logic is employed when unmounting the datasets, save for children
are unmounted first.

bectl(8): Change bectl_cmd_jail to pass the BE_MNT_DEEP flag when
calling be_mount as well as call be_unmount when cleaning up after the
jail has exited instead of umount(2) directly.

PR:		234795
Submitted by:	Wes Maag <jwmaag_gmail.com> (test additions by kevans)
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D18796
2019-01-10 03:27:20 +00:00
Kyle Evans
7ce09314b2 bectl: use jail id as the default jail name for a boot environment
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.

Additionally, this commit addresses two other bugs that prevented unjailing
in scenarios where the jail name does not match the boot environment name:

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 dataset is actually mounted.

2. 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, so amend
  that to use a string instead.

Test cases have been amended to reflect the bugs found.

PR:		233637
Submitted by:	Rob <rob.fx907_gmail.com>
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D18607
2018-12-25 15:18:41 +00:00
Yuri Pankov
52ee41b778 bectl: sync usage with man page, removing stray multibyte characters
in the process.

PR:		233526
Submitted by:	tigersharke@gmail.com (original version)
Reviewed by:	kevans
Approved by:	kib (mentor, implicit)
MFC after:	3 days
Differential revision:	https://reviews.freebsd.org/D18335
2018-11-26 15:11:32 +00:00
Mateusz Piotrowski
f5c8cb4c35 Cross-reference libbe(3) and bectl(8).
Those two manual pages are already referencing each other in the HISTORY
sections, which people might skip. Mention those manual pages explicitly in
the SEE ALSO sections.  Also, remove a reference to be(1) from libbe(3).

Reviewed by:	bcr
Approved by:	krion (mentor, implicit), mat (mentor, implicit)
Differential Revision:	https://reviews.freebsd.org/D18136
2018-11-21 12:46:28 +00:00
Kyle Evans
6fc21012a3 bectl(8) tests: attempt to load the ZFS module
Observed in a CI test image, bectl_create test will run and be marked as
skipped because the module is not loaded. The first zpool invocation will
automagically load the module, but bectl_create is still skipped. Subsequent
tests all pass as expected because the module is now loaded and everything
is OK.

MFC after:	3 days
2018-11-19 17:09:57 +00:00
Kyle Evans
9c1535e9ab bectl(8): Add some regression tests
These tests operate on a file-backed zpool that gets created in the kyua
temp dir. root and ZFS support are both required for these tests. Current
tests cover create, destroy, export/import, jail, list (kind of), mount,
rename, and jail.

List tests should later be extended to cover formatting and the different
list flags, but for now only covers basic "are create/destroy actually
reflected properly"

MFC after:	3 days
2018-11-19 02:30:12 +00:00
Kyle Evans
cc624025b4 bectl(3)/libbe(3): Allow BE root to be specified
Add an undocumented -r option preceding the bectl subcommand to specify a BE
root to operate out of. This will remain undocumented for now, as some
caveats apply:

- BEs cannot be activated in the pool that doesn't contain the rootfs
- bectl create cannot work out of the box without the -e option right now,
  since it defaults to the rootfs and cross-pool cloning doesn't work like
  that (IIRC)

Plumb the BE root through to libbe(3) so that some things -can- be done to
it, e.g.

bectl -r tank/ROOT create -e default upgrade
bectl -r tank/ROOT mount upgrade /mnt

this aides in some upgrade setups where rootfs is not necessarily ZFS, and
also makes it easier/possible to regression-test bectl when combined with a
file-backed zpool.

MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D18029
2018-11-19 02:12:08 +00:00
Kyle Evans
8369ba427a libbe(3)/bectl(8): Make consistent with beadm
vermaden (maintainer of beadm) points out the following inconsistencies:
- "missing command" is not printed prior to usage if the error is simply a
   missing command; this should be obvious from the context
- "bectl rename" isn't using the "don't unmount" flag (zfs rename -u), so
   the active BE can't be renamed. It doesn't make sense in our context to
   *not* use -u, so use it.

Documentation updates reflect the above and note an inconsistency with the
'destroy' command that is consistent with other parts of the base system.

A fix for libbe(3) not properly being installed to /lib is included.
SHLIBDIR should have been added when it was moved in r337995.

Approved by:	re (kib)
2018-08-24 20:44:58 +00:00
Kyle Evans
d81df689b8 bectl(8): Man page and usage cleanup
- Some overly-long lines
- Consistently using .Brq ({})
- Consistently using .Cm
- Not using .Ao/.Ac around .Ar

PR:		230576
Submitted by:	Yuri Pankov (with a fair amount of rebasing pre-commit)
2018-08-23 02:09:52 +00:00
Kyle Evans
db9db0e790 bectl(8): jail: Tear down jail by default after command exits
Add a -U flag to get back the old behavior. The new behavior is a little
more friendly to the common use cases, jail the BE and execute a script.
Having the jail torn down automatically when the script is finished, or when
you exit the shell, is a little more friendly than having to remember to
`bectl ujail`.

Batch mode (-b) will continue to leave the jail up, as it's assumed the
caller has other intentions.

Submitted by:	Shawn Webb (partially)
2018-08-23 01:45:18 +00:00
Kyle Evans
cd816834d4 bectl(8): Allow running a custom command in the 'jail' subcommand
Instead of always running /bin/sh, allow the user to specify the command
to run. The jail is not removed when the command finishes. Meaning,
`bectl unjail` will still need to be run.

For example:

```
bectl jail newBE pkg upgrade
bectl ujail newBE
```

Submitted by:	Shawn Webb
Obtained from:	HardenedBSD (8b451014ab)
2018-08-18 01:12:44 +00:00
Kyle Evans
b509cad4fe bectl(8): Add batch mode to jail subcommand
Adding batch mode to the jail `bectl(8)` subcommand enables jailing of
ZFS Boot Environments in a scriptable fashion.

Submitted by:	Shawn Webb
Obtained from:	HardenedBSD (9e72d1c59a and ef7b6d9e1c with minor edit)
2018-08-17 01:59:19 +00:00
Kyle Evans
25eeb3ea95 bectl(8): Kit-kat bar 2018-08-16 18:27:43 +00:00
Kyle Evans
a9c660b0d5 bectl(8): Implement the 'create a snapshot' variant of create 2018-08-16 18:26:43 +00:00
Kyle Evans
9491dcf564 bectl(8): Appease clang-scan
Use strlcpy instead of a plain strcpy
2018-08-16 17:59:49 +00:00
Kyle Evans
55b0e92b89 libbe(3)/bectl(8): Hit rewind on a bunch of off-by-ones
While here, use sizeof() in some places that it makes sense to reduce room
for error and prefer strlcpy to strncpy
2018-08-16 17:56:03 +00:00
Kyle Evans
4c5d19fda4 bectl(8): Check jailparam_* return values
Previous iteration of this assumed that these won't fail because we've
already setup the jail param to this point, but the allocations could still
fail in pretty bad conditions.

Admit that it's possible and return (ENOENT, EINVAL, ENOMEM, or 0) when
deleting arguments. EINVAL shouldn't happen since we're passing optarg;
which may satisfy *optarg == '\0' but never optarg == NULL.

CID:		1394885, 1394901
2018-08-14 18:35:33 +00:00
Kyle Evans
f2fdf2a1dc libbe(3)/bectl(8): Remove now-redundant include paths
These were previously necessary because the libnvpair and libzfs_core
includes were not installed into the SYSROOT, being a part of the copies
target in include/Makefile rather than being installed with the library.

This was fixed in r337696 and the headers are now installed properly, so we
may let go of the cruft.
2018-08-13 05:01:19 +00:00
Kyle Evans
1b057aac2b libbe(3): Fix be_import to delete temp snapshot
Deleting the temp snapshot isn't immediately possible because it's the
origin of the newly imported boot environment. However, this is trivially
solved by opening the new boot environment and promoting it. The roles are
now reversed and the temp snapshot/dataset may be completely destroyed.

Remove the BUGS from libbe(3) and bectl(8).
2018-08-13 03:42:14 +00:00
Kyle Evans
9fe5b5bf13 bectl(8): Use strcmp, rather than trying to directly compare 2018-08-12 00:09:52 +00:00
Kyle Evans
e903601824 bectl(8): Rename "index" variable, which shadows a global in some lands 2018-08-12 00:00:13 +00:00
Kyle Evans
35d2028fb8 libbe(3)/bectl(8): More SYSROOT/GCC build fixes
- Missing include path
- Fully specify libzfs's dependencies (except for deps pulled in by other
  deps) in Makefile.inc1
- Drop WARNS back down to 2 for libbe(3). I do this with much hesitation,
  but the libzfs headers are apparently a hot warning-filled mess as far as
  GCC 4.2 is concerned.
2018-08-11 22:45:39 +00:00
Kyle Evans
efa70a5614 bectl(8): Add missing include path 2018-08-11 20:47:35 +00:00
Kyle Evans
6eeb282e00 bectl(8): Also document the import bug. 2018-08-11 04:11:34 +00:00
Kyle Evans
216d435975 bectl(8): Swap the order of ujail/umount documentation...
"Despite my inconsistency, consistency is king." -Anonymous
2018-08-11 04:03:05 +00:00
Kyle Evans
34761e8423 bectl(8): Document export/import 2018-08-11 04:01:24 +00:00
Kyle Evans
84e6121955 libbe(3)/bectl(8): Make igor and mandoc -Tlint a little happier 2018-08-11 01:40:24 +00:00
Kyle Evans
3d1a1f2caf libbe(3)/bectl(8): Kill off the 'add' functionality for now
The mostly-undocumented 'add' functionality, from initial read-through, is
intended for construction of deep ("bdrewery style") boot environments.
However, it's mostly broken at this point. `#if SOON` it out on both sides
so that we're not exposing a broken API/feature.

Work will resume on it in due time.
2018-08-11 01:02:27 +00:00
Kyle Evans
b6e7c421b7 libbe(3)/bectl(8): Standardize $FreeBSD$ IDs 2018-08-07 14:02:41 +00:00
Kyle Evans
b179da0111 libbe(3)/bectl(8): Standardize copyright headers
- File names don't necessarily need to be repeated
- Add SPDX tags
- Add a missing copyright for Kyle Kneitinger in bectl.8, originally written
  by him in GSoC 2017; his standard copyright notice has been copied from
  other files within the same directory to remain consistent with how he
  clearly wished to portray it
2018-08-07 13:46:06 +00:00
Kyle Evans
709b553cd0 libbe(3): Check that dataset is to be mounted at / for be_exists
This makes the be_exists behavior match the comments that assert that we've
already checked that the dataset derived from the BE name is set to mount at
/.

Other changes of note:
- bectl_list sees another change; changing mountpoint based on mount status
  turns out to be a bad idea, so instead make the mounted property of the
  returned nvlist the path that it's mounted at

- Always return the "mountpoint" property in "mountpoint" if it's ste
2018-08-07 03:07:54 +00:00
Kyle Evans
9c65c7fb48 bectl(8): Only show mountpoint if the dataset is actually mounted
This is to accomodate a later change in libbe(3) that will always return the
mountpoint, whether it be the directory the dataset is actively mounted at
or the "mountpoint" property.
2018-08-07 03:01:04 +00:00
Kyle Evans
2a0b8dc2cb bectl(8): Provide -u option to unset jail parameters
All but name, host.hostname, and path may be completely unset.
2018-08-06 15:21:46 +00:00
Kyle Evans
526ad58e80 bectl(8): Split list functionality out into its own file as well 2018-08-06 03:41:52 +00:00
Kyle Evans
d694059f1e bectl(8): bectl jail improvements
- Support passing arbitrary jail arguments via -o
- Split the related (and rewritten since the GSoC) jail bits out into a new
  bectl_jail.c file, to reduce clutter in bectl.c
- Don't use RFC 1918 IP space [0]; we'll instead set no default IPv4 and let
  the user pass in any address options they wish via -o

Reported by:	rgrimes [0], Shawn Webb [0]
2018-08-06 03:32:25 +00:00
Kyle Evans
9a460e6fd2 bectl(8): Some light cleanup and commenting 2018-08-05 20:03:05 +00:00
Kyle Evans
96c5db5854 bectl(8): Implement bectl list -s
be_get_dataset_snapshots has been added to libbe(3), effectively returning
the same information as be_get_bootenv_props but for snapshots of the given
dataset. The assumption is that one will have the BE dataset name before
wanting to grab snapshots.
2018-08-05 19:38:56 +00:00