Commit Graph

98 Commits

Author SHA1 Message Date
Don Lewis
1bf6738f80 Fix a logic bug in error handling code. It is an error if p == NULL.
The linelen tests are only meaningful when p != NULL.

Reported by:	Coverity
Coverity CID:	1368655
MFC after:	1 month
2019-12-09 07:18:40 +00:00
Doug Moore
504f5e294e swap_pager.c reserves 2 blocks for a bsd label. Change that 2 to the
expression howmany(BBSIZE, PAGE_SIZE), where BBSIZE is the size of the
boot block area.  That can be less than 2 if PAGE_SIZE is big.

swapon(8) has an option to trim (delete) all the blocks of a device at
startup.  However, if the first of those blocks is a bsd label, then
trimming those blocks is destructive.  Change swapon to leave the
first BBSIZE bytes untrimmed.

Update manual pages to reflect changes in how swapon and how it may be
used, espeically in association with savecore.

Reviewed by: alc
Approved by: markj (mentor)
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D21191
2019-08-15 02:30:44 +00:00
Doug Moore
473fe2c000 Rewrite the comments that explain swapon_trim() to make them more
comprehensible.

Suggested by: rpokala
Approved by: markj (mentor)
Differential Revision: https://reviews.freebsd.org/D21034
2019-07-26 15:18:11 +00:00
Doug Moore
6d5685c762 In trimming on startup, invoke swapon before closing the fd used for
trimming so that a geli device isn't detached before swapon is
invoked.

Submitted by: sigsys_gmail.com
Discussed with: alc
Approved by: markj (mentor)
Differential Revision:	https://reviews.freebsd.org/D21006
2019-07-20 20:47:07 +00:00
Doug Moore
9035b2257f You can't use block special nodes for swap, so don't let that happen.
Fix a style violation with regard to header file arrangement.

Improved by: alc
Approved by: markj, kib (mentor)
Differential Revision: https://reviews.freebsd.org/D20723
2019-06-22 19:27:09 +00:00
Doug Moore
a616b25342 Modify swapon(8) to invoke BIO_DELETE to trim swap devices, either if
'-E' appears on the swapon command line, or if "trimonce" appears as
an fstab option.

Discussed at: BSDCAN
Tested by: markj
Reviewed by: markj
Approved by: markj (mentor)
Differential Revision:https://reviews.freebsd.org/D20599
2019-06-22 03:16:01 +00:00
Pedro F. Giffuni
8a16b7a18f General further adoption of SPDX licensing ID tags.
Mainly focus on files that use BSD 3-Clause license.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

Special thanks to Wind River for providing access to "The Duke of
Highlander" tool: an older (2014) run over FreeBSD tree was useful as a
starting point.
2017-11-20 19:49:47 +00:00
Bryan Drewery
ea825d0274 DIRDEPS_BUILD: Update dependencies.
Sponsored by:	Dell EMC Isilon
2017-10-31 00:07:04 +00:00
Dmitry Marakasov
8d27c2000b Fix late and noauto with geli swap
With the following in /etc/fstab:

/dev/gpt/swap.eli none swap sw,late 0 0

swap will not be enabled, with `swapon -aL' complaining:

swapon: Invalid option: late

This happens because swap_on_geli_args() which parses geli arguments
out of all mount options does not expect late or noauto among them.
Fix this by explicitly allowing these arguments.

Reviewed by:	jilles
Approved by:	jilles
MFC after:	2 weeks
Differential Revision:	D9835
2017-03-14 12:39:19 +00:00
Warner Losh
fbbd9655e5 Renumber copyright clause 4
Renumber cluase 4 to 3, per what everybody else did when BSD granted
them permission to remove clause 3. My insistance on keeping the same
numbering for legal reasons is too pedantic, so give up on that point.

Submitted by:	Jan Schaumann <jschauma@stevens.edu>
Pull Request:	https://github.com/freebsd/freebsd/pull/96
2017-02-28 23:42:47 +00:00
Jilles Tjoelker
7627b33010 swapoff: Remove only late devices with -aL.
Currently, '/etc/rc.d/swaplate stop' removes all swap devices. This can be
very slow and may not even be possible if there is a lot of swap space in
use. However, removing swap devices is only needed for late swap devices
that may depend on daemons that subsequent shutdown steps stop. Normal swap
devices such as hard disk partitions will remain available throughout the
shutdown process and need not be removed.

In swapoff, interpret -aL to remove late swap devices only, and use this in
etc/rc.d/swaplate. The meaning of -aL in swapon remains unchanged (add all
swap devices, both normal and late).

PR:		187081
Reviewed by:	wblock (man page only), ngie
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D8126
2016-10-21 21:55:50 +00:00
Jilles Tjoelker
a7d1d41617 swapon(8): Update to reality: swapoff ignores -L and the late option in fstab.
MFC after:	1 week
2016-10-02 15:01:31 +00:00
Ed Schouten
e47c947e6e Stop using the non-standard basename_r() function.
This change makes the code use the POSIX basename() function. It has the
advantage that (if implemented correctly), it also imposes no restrict
on the pathname length.

Notice that I haven't added any error handling to the strdup() call. It
looks like none of the other calls to strdup() and malloc() performed by
this utility do it either.

Reviewed by:	hrs
Differential Revision:	https://reviews.freebsd.org/D6626
2016-05-31 06:45:19 +00:00
Pedro F. Giffuni
b68ac8007d sbin: minor spelling fixes.
No functional change.
2016-04-30 19:04:59 +00:00
Glen Barber
406d87b1c3 Explicitly add more files to the 'runtime' package.
Sponsored by:	The FreeBSD Foundation
2016-02-09 20:19:31 +00:00
Enji Cooper
24cd0f8516 Delete argsize to fix a -Wunused-but-set-variable warning with gcc 4.9
The variable isn't actually checked -- just the end result which gets
returned from the function

Differential Revision: https://reviews.freebsd.org/D5156
Reviewed by: araujo, delphij
MFC after: 1 month
Sponsored by: EMC / Isilon Storage Division
2016-02-01 08:06:17 +00:00
Enji Cooper
33c2e470b4 Call va_end on ap when vsnprintf fails in run_cmd(..) to clean up
the variable state

MFC after: 1 week
Reported by: cppcheck
Sponsored by: EMC / Isilon Storage Division
2015-12-09 01:24:34 +00:00
Pawel Jakub Dawidek
445bda3f4f Allow to disable BIO_DELETE passthru in fstab for swap-on-geli devices by
passing 'notrim' option.

PR:		198863
Submitted by:	Matthew D. Fuller fullermd at over-yonder dot net
2015-08-08 09:57:38 +00:00
Simon J. Gerraty
ccfb965433 Add META_MODE support.
Off by default, build behaves normally.
WITH_META_MODE we get auto objdir creation, the ability to
start build from anywhere in the tree.

Still need to add real targets under targets/ to build packages.

Differential Revision:       D2796
Reviewed by: brooks imp
2015-06-13 19:20:56 +00:00
Simon J. Gerraty
44d314f704 dirdeps.mk now sets DEP_RELDIR 2015-06-08 23:35:17 +00:00
Simon J. Gerraty
98e0ffaefb Merge sync of head 2015-05-27 01:19:58 +00:00
Baptiste Daroussin
13eb765f2d Convert sbin/ to LIBADD
Reduce overlinking
2014-11-25 11:23:12 +00:00
Simon J. Gerraty
9268022b74 Merge from head@274682 2014-11-19 01:07:58 +00:00
Hiroki Sato
1482f98247 Do not add late flag when file= is specified because it has a bad
side-effect.  The specified file should exist before the fstab line.

Reported by:	wblock (long time ago)
MFC after:	1 day
2014-10-10 03:20:12 +00:00
Simon J. Gerraty
fae50821ae Updated dependencies 2014-05-16 14:09:51 +00:00
Simon J. Gerraty
76b28ad6ab Updated dependencies 2014-05-10 05:16:28 +00:00
Simon J. Gerraty
3b8f084595 Merge head 2014-04-28 07:50:45 +00:00
Jilles Tjoelker
1fdb18b01f swapon: Fix buffer overflow when configuring encrypted swap on GBDE.
PR:		bin/184950
Tested by:	Radim Kolar
MFC after:	3 days
2013-12-21 11:59:58 +00:00
Sergey Kandaurov
5cd4723c5c - Purge one more reference to ad(4)[1].
- NSWAPDEV limit has gone.

Noticed by:	Sergey V. Dyatko [1]
MFC after:	1 week
2013-11-22 12:09:15 +00:00
Simon J. Gerraty
d466a5b069 Merge head 2013-09-11 18:16:18 +00:00
Hiroki Sato
79ba2f3110 Style clean-ups.
Reviewed by:	md5
2013-09-05 21:19:16 +00:00
Hiroki Sato
4139627db6 Enable "late" option when a file= option is specified in /etc/fstab.
The file= option requires rw mount where the backing store exists but
it does not work because rc.d/swap runs before rc.d/fsck.
Reported by:	wblock
2013-09-05 20:50:52 +00:00
Simon J. Gerraty
d1d0158641 Merge from head 2013-09-05 20:18:59 +00:00
Xin LI
5428273365 Make two buffer variables static for now. It is not safe to
reference stack memory after return.

MFC after:	2 weeks
2013-07-31 07:09:35 +00:00
Xin LI
1bf9e66cbc Plug a memory leak. 2013-07-02 17:34:34 +00:00
Xin LI
0d8a14f9b1 Correct a typo in comment. 2013-07-01 21:18:39 +00:00
Xin LI
8f8de1e127 - Modify swapon(8) so that it uses most of geli(8) defaults for swap,
which is presently: AES-XTS, no authentication.  Create provider
   with pagesize as sectorsize by default.
 - Rewrite parsing code for geli(8)-backed swap options, now options
   are required to be exact match, and unrecognized options will trigger
   a warning.
 - Don't initialize GELI device if it's already initialized.  This
   restores previous behavior.
 - Don't duplicate file descriptor when working with geli(8) and
   gbde(8) as there is no need to communicate with the utility other
   than exit status.
 - When calling swap_on_off_* routines, which_prog can only be SWAP_ON
   or SWAP_OFF.  Eliminate unneeded case branches by replacing switch
   with if's.
 - Plug a few memory leaks.

Reviewed by:	hrs (but bugs are mine)
MFC after:	1 week
X-MFC-with:	r252310, r252332, r252345
2013-06-29 22:04:04 +00:00
Hiroki Sato
d122ff71eb Fix build with gcc. 2013-06-28 16:24:14 +00:00
Hiroki Sato
cb754f614f Fix build.
Spotted by:	gjb
2013-06-28 05:09:01 +00:00
Hiroki Sato
268a55bc98 - Add vnode-backed swap space specification support. This is enabled when
device names "md" or "md[0-9]*" and a "file" option are specified in
  /etc/fstab like this:

  md    none    swap    sw,file=/swap.bin       0       0

- Add GBDE/GELI encrypted swap space specification support, which
  rc.d/encswap supported.  The /etc/fstab lines are like the following:

  /dev/ada1p1.bde       none    swap    sw      0       0
  /dev/ada1p2.eli       none    swap    sw      0       0

  .eli devices accepts aalgo, ealgo, keylen, and sectorsize as options.

  swapctl(8) can understand an encrypted device in the command line
  like this:

  # swapctl -a /dev/ada2p1.bde

- "-L" flag is added to support "late" option to defer swapon until
  rc.d/mountlate runs.

- rc.d script change:

    rc.d/encswap -> removed
    rc.d/addswap -> just display a warning message if $swapfile is defined
    rc.d/swap1 -> renamed to rc.d/swap
    rc.d/swaplate -> newly added to support "late" option

These changes alleviate a race condition between device creation/removal
and swapon/swapoff.

MFC after:	1 week
Reviewed by:	wblock (manual page)
2013-06-27 18:28:45 +00:00
Simon J. Gerraty
7cf3a1c6b2 Updated dependencies 2013-03-11 17:21:52 +00:00
Simon J. Gerraty
f5f7c05209 Updated dependencies 2013-02-16 01:23:54 +00:00
Marcel Moolenaar
7750ad47a9 Sync FreeBSD's bmake branch with Juniper's internal bmake branch.
Requested by: Simon Gerraty <sjg@juniper.net>
2012-08-22 19:25:57 +00:00
Ed Schouten
1efe3c6b58 Add missing static keywords for global variables to tools in sbin/.
These tools declare global variables without using the static keyword,
even though their use is limited to a single C-file, or without placing
an extern declaration of them in the proper header file.
2011-11-04 13:36:02 +00:00
Ed Schouten
ce458f4239 Build swapon with WARNS=6.
Don't use a variable called stat, because it collides with stat(2).
2011-10-25 17:10:15 +00:00
Maxim Sobolev
633d2bc579 Add new option -F to specify alternative location of the /etc/fstab
file.

MFC after:	1 month
2011-10-25 01:47:33 +00:00
Ed Schouten
f6d189a9e4 Raise WARNS for various tools where possible.
Submitted by:	Marius Nünnerich <marius@nuenneri.ch>
2010-01-17 21:56:27 +00:00
Ruslan Ermilov
106d839190 Switch the default WARNS level for sbin/ to 6.
Submitted by:	Ulrich Spörlein
2009-10-19 16:00:24 +00:00
Mike Makonnen
45a5dc937d Add a -q flag to swapon(8) to suppress informational messages. Use it in
rc.d.
Note: errors are not affected by this flag.
2008-06-23 22:17:08 +00:00
Pawel Jakub Dawidek
2e64768c87 - Change the meaning of -h flag from giving the output in megabytes to
giving the output in a human-readable form. This behaviour is consistent
  with most of system tools.
- Add -m and -g options to give output in megabytes and gigabytes
  respectively.
2008-05-20 12:24:31 +00:00