History log of /freebsd-current/sbin/swapon/swapon.c
Revision Date Author Comments
# 14b475c4 07-May-2024 Poul-Henning Kamp <phk@FreeBSD.org>

Remove gbde support from swapon(8)


# feabaf8d 23-Apr-2024 Warner Losh <imp@FreeBSD.org>

Revert "swapon: Do not overwrite Linux swap header"

This reverts commit cf04a7775a4e8ff6fd28c768be9daa3d83dd382e.This is
broken on armv7, and closer scrutiny of the reviews shows I was in error
when I thought it was ready.


# cf04a777 23-Apr-2024 Ricardo Branco <rbranco@suse.de>

swapon: Do not overwrite Linux swap header

Reviewed by: imp, jhb
Pull Request: https://github.com/freebsd/freebsd-src/pull/1084


# 0b8224d1 24-Nov-2023 Warner Losh <imp@FreeBSD.org>

Remove copyright strings ifdef'd out

We've ifdef'd out the copyright strings for some time now. Go ahead and
remove the ifdefs. Plus whatever other detritis was left over from other
recent removals. These copyright strings are present in the comments and
are largely from CSRG's attempt at adding their copyright to every
binary file (which modern interpretations of the license doesn't
require).

Sponsored by: Netflix


# 51e16cb8 23-Nov-2023 Warner Losh <imp@FreeBSD.org>

sbin: Remove ancient SCCS tags.

Remove ancient SCCS tags from the tree, automated scripting, with two
minor fixup to keep things compiling. All the common forms in the tree
were removed with a perl script.

Sponsored by: Netflix


# 1d386b48 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 65f3be91 07-Jul-2023 Alfonso Gregory <gfunni234@gmail.com>

Mark usage function as __dead2 in programs where it does not return

In most cases, usage does not return, so mark them as __dead2. For the
cases where they do return, they have not been marked __dead2.

Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/735


# b49b6e0f 08-Dec-2021 Konstantin Belousov <kib@FreeBSD.org>

swapon(8): adapt to the new swapoff(2) interface

also fix test sys/audit/administrative.c.

Reviewed by: brooks
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D33343


# 1aa249c9 29-Nov-2021 Konstantin Belousov <kib@FreeBSD.org>

swapoff(8): add -f flag

to force swapout by ignoring the heuristic that calculates amount of
allocated memory against total of RAM plus remaining swap.

Reviewed by: markj
Discussed with: alc
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D33165


# 883b7553 03-May-2020 Xin LI <delphij@FreeBSD.org>

- Fix logic error in swapoff case: follow same handling of p and
linelen in the swapon case.
- Use strlcpy instead of strncpy.

MFC after: 1 week


# 1bf6738f 09-Dec-2019 Don Lewis <truckman@FreeBSD.org>

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


# 504f5e29 14-Aug-2019 Doug Moore <dougm@FreeBSD.org>

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


# 473fe2c0 26-Jul-2019 Doug Moore <dougm@FreeBSD.org>

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


# 6d5685c7 20-Jul-2019 Doug Moore <dougm@FreeBSD.org>

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


# 9035b225 22-Jun-2019 Doug Moore <dougm@FreeBSD.org>

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


# a616b253 21-Jun-2019 Doug Moore <dougm@FreeBSD.org>

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


# 8a16b7a1 20-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

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.


# 8d27c200 13-Mar-2017 Dmitry Marakasov <amdmi3@FreeBSD.org>

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


# fbbd9655 28-Feb-2017 Warner Losh <imp@FreeBSD.org>

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


# 7627b330 21-Oct-2016 Jilles Tjoelker <jilles@FreeBSD.org>

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


# e47c947e 31-May-2016 Ed Schouten <ed@FreeBSD.org>

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


# b68ac800 30-Apr-2016 Pedro F. Giffuni <pfg@FreeBSD.org>

sbin: minor spelling fixes.

No functional change.


# 24cd0f85 01-Feb-2016 Enji Cooper <ngie@FreeBSD.org>

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


# 33c2e470 08-Dec-2015 Enji Cooper <ngie@FreeBSD.org>

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


# 445bda3f 08-Aug-2015 Pawel Jakub Dawidek <pjd@FreeBSD.org>

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


# 1482f982 09-Oct-2014 Hiroki Sato <hrs@FreeBSD.org>

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


# 1fdb18b0 21-Dec-2013 Jilles Tjoelker <jilles@FreeBSD.org>

swapon: Fix buffer overflow when configuring encrypted swap on GBDE.

PR: bin/184950
Tested by: Radim Kolar
MFC after: 3 days


# 79ba2f31 05-Sep-2013 Hiroki Sato <hrs@FreeBSD.org>

Style clean-ups.

Reviewed by: md5


# 4139627d 05-Sep-2013 Hiroki Sato <hrs@FreeBSD.org>

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


# 54282733 31-Jul-2013 Xin LI <delphij@FreeBSD.org>

Make two buffer variables static for now. It is not safe to
reference stack memory after return.

MFC after: 2 weeks


# 1bf9e66c 02-Jul-2013 Xin LI <delphij@FreeBSD.org>

Plug a memory leak.


# 0d8a14f9 01-Jul-2013 Xin LI <delphij@FreeBSD.org>

Correct a typo in comment.


# 8f8de1e1 29-Jun-2013 Xin LI <delphij@FreeBSD.org>

- 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


# d122ff71 28-Jun-2013 Hiroki Sato <hrs@FreeBSD.org>

Fix build with gcc.


# cb754f61 27-Jun-2013 Hiroki Sato <hrs@FreeBSD.org>

Fix build.

Spotted by: gjb


# 268a55bc 27-Jun-2013 Hiroki Sato <hrs@FreeBSD.org>

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


# 1efe3c6b 04-Nov-2011 Ed Schouten <ed@FreeBSD.org>

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.


# ce458f42 25-Oct-2011 Ed Schouten <ed@FreeBSD.org>

Build swapon with WARNS=6.

Don't use a variable called stat, because it collides with stat(2).


# 633d2bc5 24-Oct-2011 Maxim Sobolev <sobomax@FreeBSD.org>

Add new option -F to specify alternative location of the /etc/fstab
file.

MFC after: 1 month


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# fe0506d7 09-Mar-2010 Marcel Moolenaar <marcel@FreeBSD.org>

Create the altix project branch. The altix project will add support
for the SGI Altix 350 to FreeBSD/ia64. The hardware used for porting
is a two-module system, consisting of a base compute module and a
CPU expansion module. SGI's NUMAFlex architecture can be an excellent
platform to test CPU affinity and NUMA-aware features in FreeBSD.


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# 45a5dc93 23-Jun-2008 Mike Makonnen <mtm@FreeBSD.org>

Add a -q flag to swapon(8) to suppress informational messages. Use it in
rc.d.
Note: errors are not affected by this flag.


# 2e64768c 19-May-2008 Pawel Jakub Dawidek <pjd@FreeBSD.org>

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


# 8d646af5 10-Feb-2005 Ruslan Ermilov <ru@FreeBSD.org>

Sync program's usage() with manpage's SYNOPSIS.


# 6004362e 26-Nov-2004 David Schultz <das@FreeBSD.org>

Don't include sys/user.h merely for its side-effect of recursively
including other headers.


# 4c723140 09-Apr-2004 Mark Murray <markm@FreeBSD.org>

Remove advertising clause from University of California Regent's license,
per letter dated July 22, 1999.

Approved by: core, imp


# 16fc3635 05-Mar-2004 Mark Murray <markm@FreeBSD.org>

Make NULL a (void*)0 whereever possible, and fix the warnings(-Werror)
that this provokes. "Wherever possible" means "In the kernel OR NOT
C++" (implying C).

There are places where (void *) pointers are not valid, such as for
function pointers, but in the special case of (void *)0, agreement
settles on it being OK.

Most of the fixes were NULL where an integer zero was needed; many
of the fixes were NULL where ascii <nul> ('\0') was needed, and a
few were just "other".

Tested on: i386 sparc64


# c69284ca 03-May-2003 David E. O'Brien <obrien@FreeBSD.org>

Use __FBSDID() to quiet GCC 3.3 warnings.


# 4937798d 24-Feb-2003 David Schultz <das@FreeBSD.org>

- Add a clearer error message for the case where swapon hits the
NSWAPDEV limit.
- Don't warn about devices that are not in use in 'swapoff -a'.
- Re-add behavior mistakenly removed in revision 1.44:
If using 'swapon -a', do not warn if the device is already in use.

PR: 46633
Submitted by: Andy Farkas <andyf@speednet.com.au> (in part)
Reviewed by: mike (mentor)


# 9255f327 30-Dec-2002 Mike Barcroft <mike@FreeBSD.org>

Remove hack from rev 1.15; getbsize(3)'s original interface has been
restored.


# 69095b02 29-Dec-2002 Mike Barcroft <mike@FreeBSD.org>

Make the first argument to getbsize(3) a `size_t *'. This is a hack
since getbsize(3) should have `int *' as its first parameter.


# a420c811 28-Dec-2002 Matthew Dillon <dillon@FreeBSD.org>

Add 'swapctl' - as a hardlink to swapon/swapoff, and augment swapon with
swapctl functionality. The idea is to create a swapctl command that is
fairly close to the OpenBSD and NetBSD version. FreeBSD does not implement
swap priority (and it would be a mistake if we did) so we didn't bother with
that part of it.

Submitted by: Eirik Nygaard <eirikn@bluezone.no>
Augmented by: dillon (extensively)
Reviewed by: David Schultz <dschultz@uclink.Berkeley.EDU>


# 92da00bb 15-Dec-2002 Matthew Dillon <dillon@FreeBSD.org>

This is David Schultz's swapoff code which I am finally able to commit.
This should be considered highly experimental for the moment.

Submitted by: David Schultz <dschultz@uclink.Berkeley.EDU>
MFC after: 3 weeks


# d476a036 21-Mar-2002 Warner Losh <imp@FreeBSD.org>

o remove __P
o remove main prototype


# 3d438ad6 20-Mar-2002 David E. O'Brien <obrien@FreeBSD.org>

Remove 'register' keyword.
It does not help modern compilers, and some may take some hit from it.
(I also found several functions that listed *every* of its 10 local vars with
"register" -- just how many free registers do people think machines have?)


# cafefe8c 24-Jun-2001 Dima Dorfman <dd@FreeBSD.org>

Include missing header files which define functions for which gcc has
builtins (e.g., exit, strcmp).


# 37736675 14-Apr-2000 Warner Losh <imp@FreeBSD.org>

Add include of errno.h where needed, remove extern int errno where not.

These commits were inspired by a similar commit to netbsd.


# 7f3dea24 27-Aug-1999 Peter Wemm <peter@FreeBSD.org>

$Id$ -> $FreeBSD$


# e798a806 03-Aug-1998 Philippe Charnier <charnier@FreeBSD.org>

.Nm swapon -> .Nm.
Sort #includes. Add rcsid.


# 6da7f378 19-Jun-1997 Philippe Charnier <charnier@FreeBSD.org>

Use warn(3).


# 8d64695c 28-Mar-1997 Warner Losh <imp@FreeBSD.org>

compare return value from getopt against -1 rather than EOF, per the final
posix standard on the topic.


# 7fc4a454 06-Sep-1996 Jordan K. Hubbard <jkh@FreeBSD.org>

Make the noauto flag usable for swap devices too. Closes PR#1542
Submitted-By: David Leonard <d@scry.dstc.edu.au>


# 43e6fcd5 13-May-1995 David Greenman <dg@FreeBSD.org>

Take out special error message for EINVAL...we really do want it to be
"invalid argument".


# 38994f93 23-Feb-1995 Poul-Henning Kamp <phk@FreeBSD.org>

Fix -Wall warnings.

Yes I have better things to do, but just now I'm waiting...


# 8fae3551 26-May-1994 Rodney W. Grimes <rgrimes@FreeBSD.org>

BSD 4.4 Lite sbin Sources

Note: XNSrouted and routed NOT imported here, they shall be imported with
usr.sbin.