summaryrefslogtreecommitdiffstats
path: root/sbin
diff options
context:
space:
mode:
authordillon <dillon@FreeBSD.org>2002-12-15 19:17:57 +0000
committerdillon <dillon@FreeBSD.org>2002-12-15 19:17:57 +0000
commitb43fb3e9200092f2885e909dc7ee85cb0871cfef (patch)
treefc6e3be9fa1b757f9ac0967a46494adcf0cc5682 /sbin
parent2925e70a14eb46bd10c8905fd619024bb19f7f9d (diff)
downloadFreeBSD-src-b43fb3e9200092f2885e909dc7ee85cb0871cfef.zip
FreeBSD-src-b43fb3e9200092f2885e909dc7ee85cb0871cfef.tar.gz
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
Diffstat (limited to 'sbin')
-rw-r--r--sbin/swapon/Makefile2
-rw-r--r--sbin/swapon/swapon.837
-rw-r--r--sbin/swapon/swapon.c43
3 files changed, 56 insertions, 26 deletions
diff --git a/sbin/swapon/Makefile b/sbin/swapon/Makefile
index be803b2..f052567 100644
--- a/sbin/swapon/Makefile
+++ b/sbin/swapon/Makefile
@@ -3,5 +3,7 @@
PROG= swapon
MAN= swapon.8
+LINKS= ${BINDIR}/swapon ${BINDIR}/swapoff
+MLINKS= swapon.8 swapoff.8
.include <bsd.prog.mk>
diff --git a/sbin/swapon/swapon.8 b/sbin/swapon/swapon.8
index ce23b38..edda998 100644
--- a/sbin/swapon/swapon.8
+++ b/sbin/swapon/swapon.8
@@ -36,39 +36,46 @@
.Dt SWAPON 8
.Os
.Sh NAME
-.Nm swapon
-.Nd "specify additional device for paging and swapping"
+.Nm swapon , swapoff
+.Nd "specify devices for paging and swapping"
.Sh SYNOPSIS
-.Nm
+.Nm swap[on|off]
.Fl a
-.Nm
+.Nm swap[on|off]
.Ar special_file ...
.Sh DESCRIPTION
The
-.Nm
+.Nm swapon
utility is used to specify additional devices on which paging and swapping
are to take place.
The system begins by swapping and paging on only a single device
so that only one disk is required at bootstrap time.
Calls to
-.Nm
+.Nm swapon
normally occur in the system multi-user initialization file
.Pa /etc/rc
making all swap devices available, so that the paging and swapping
activity is interleaved across several devices.
.Pp
+The
+.Nm swapoff
+utility disables paging and swapping on a device.
+Calls to
+.Nm swapoff
+succeed only if disabling the device would leave enough
+remaining virtual memory to accomodate all running programs.
+.Pp
Normally, the first form is used:
.Bl -tag -width indent
.It Fl a
All devices marked as ``sw''
swap devices in
.Pa /etc/fstab
-are made available unless their ``noauto'' option is also set.
+are added to or removed from the pool of available swap
+unless their ``noauto'' option is also set.
.El
.Pp
-The second form gives individual block devices as given
-in the system swap configuration table. The call makes only this space
-available to the system for swap allocation.
+The second form is used to configure or disable individual devices.
.Sh SEE ALSO
.Xr swapon 2 ,
.Xr fstab 5 ,
@@ -85,12 +92,12 @@ memory disk devices
.It Pa /etc/fstab
ASCII file system description table
.El
-.Sh BUGS
-There is no way to stop paging and swapping on a device.
-It is therefore not possible to dismount swap devices which are
-mounted during system operation.
.Sh HISTORY
The
-.Nm
+.Nm swapon
utility appeared in
.Bx 4.0 .
+The
+.Nm swapoff
+utility appeared in
+.Fx 5.0 .
diff --git a/sbin/swapon/swapon.c b/sbin/swapon/swapon.c
index 69f4e73..51042bc 100644
--- a/sbin/swapon/swapon.c
+++ b/sbin/swapon/swapon.c
@@ -53,8 +53,9 @@ static const char rcsid[] =
#include <string.h>
#include <unistd.h>
-static void usage(void);
-int add(char *name, int ignoreebusy);
+static void usage(const char *);
+static int is_swapoff(const char *);
+int swap_on_off(char *name, int ignoreebusy, int do_swapoff);
int
main(int argc, char **argv)
@@ -62,6 +63,10 @@ main(int argc, char **argv)
struct fstab *fsp;
int stat;
int ch, doall;
+ int do_swapoff;
+ char *pname = argv[0];
+
+ do_swapoff = is_swapoff(pname);
doall = 0;
while ((ch = getopt(argc, argv, "a")) != -1)
@@ -71,7 +76,7 @@ main(int argc, char **argv)
break;
case '?':
default:
- usage();
+ usage(pname);
}
argv += optind;
@@ -82,23 +87,24 @@ main(int argc, char **argv)
continue;
if (strstr(fsp->fs_mntops, "noauto"))
continue;
- if (add(fsp->fs_spec, 1))
+ if (swap_on_off(fsp->fs_spec, 1, do_swapoff))
stat = 1;
else
- printf("swapon: adding %s as swap device\n",
+ printf("%s: %sing %s as swap device\n",
+ pname, do_swapoff ? "remov" : "add",
fsp->fs_spec);
}
else if (!*argv)
- usage();
+ usage(pname);
for (; *argv; ++argv)
- stat |= add(*argv, 0);
+ stat |= swap_on_off(*argv, 0, do_swapoff);
exit(stat);
}
int
-add(char *name, int ignoreebusy)
+swap_on_off(char *name, int ignoreebusy, int do_swapoff)
{
- if (swapon(name) == -1) {
+ if ((do_swapoff ? swapoff(name) : swapon(name)) == -1) {
switch (errno) {
case EBUSY:
if (!ignoreebusy)
@@ -114,8 +120,23 @@ add(char *name, int ignoreebusy)
}
static void
-usage()
+usage(const char *pname)
{
- fprintf(stderr, "usage: swapon [-a] [special_file ...]\n");
+ fprintf(stderr, "usage: %s [-a] [special_file ...]\n", pname);
exit(1);
}
+
+static int
+is_swapoff(const char *s)
+{
+ const char *u;
+
+ if ((u = strrchr(s, '/')) != NULL)
+ ++u;
+ else
+ u = s;
+ if (strcmp(u, "swapoff") == 0)
+ return 1;
+ else
+ return 0;
+}
OpenPOWER on IntegriCloud