Add a "-t blk|noblk" device type option to swapctl -A. This allows the
user to specify "only add block devices" or "only add non-block devices". This is useful during early system startup where swapping may be needed before swap files are available (e.g. if fsck'ing large file systems).
This commit is contained in:
parent
5d1b524ff3
commit
2ea04e4383
@ -1,4 +1,4 @@
|
||||
.\" $NetBSD: swapctl.8,v 1.4 1997/06/15 15:22:48 mrg Exp $
|
||||
.\" $NetBSD: swapctl.8,v 1.5 1997/06/25 23:18:10 thorpej Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1997 Matthew R. Green
|
||||
.\" All rights reserved.
|
||||
@ -39,6 +39,7 @@
|
||||
.Nm swapctl
|
||||
.Fl A
|
||||
.Op Fl p Ar priority
|
||||
.Op Fl t Ar blk|noblk
|
||||
.Nm swapctl
|
||||
.Fl a
|
||||
.Op Fl p Ar priority
|
||||
@ -88,7 +89,19 @@ This options causes
|
||||
to read the
|
||||
.Pa /etc/fstab
|
||||
file for devices and files with a ``sw'' type, and adds all these entries
|
||||
as swap devices.
|
||||
as swap devices. The optional
|
||||
.Fl t
|
||||
flag allows the type of device to add to be specified. An argument of
|
||||
.Ar blk
|
||||
causes all block devices in
|
||||
.Pa /etc/fstab
|
||||
to be added. An argument of
|
||||
.Ar noblk
|
||||
causes all non-block devices in
|
||||
.Pa /etc/fstab
|
||||
to be added. This option is useful in early system startup, where swapping
|
||||
may be needed before all file systems are available, such as during
|
||||
disk checks of large file systems.
|
||||
.It Fl a
|
||||
The
|
||||
.Fl a
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: swapctl.c,v 1.3 1997/06/24 05:22:38 mikel Exp $ */
|
||||
/* $NetBSD: swapctl.c,v 1.4 1997/06/25 23:18:11 thorpej Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1996, 1997 Matthew R. Green
|
||||
@ -35,6 +35,8 @@
|
||||
/*
|
||||
* swapctl command:
|
||||
* -A add all devices listed as `sw' in /etc/fstab
|
||||
* -t [blk|noblk] if -A, add either all block device or all non-block
|
||||
* devices
|
||||
* -a <dev> add this device
|
||||
* -d <dev> remove this swap device (not supported yet)
|
||||
* -l list swap devices
|
||||
@ -46,10 +48,13 @@
|
||||
* or, if invoked as "swapon" (compatibility mode):
|
||||
*
|
||||
* -a all devices listed as `sw' in /etc/fstab
|
||||
* -t same as -t above (feature not present in old
|
||||
* swapon(8) command)
|
||||
* <dev> add this device
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <vm/vm_swap.h>
|
||||
|
||||
@ -98,6 +103,9 @@ int kflag; /* display in 1K blocks */
|
||||
int pflag; /* priority was specified */
|
||||
#define PFLAG_CMDS (CMD_A | CMD_a | CMD_c)
|
||||
|
||||
char *tflag; /* swap device type (blk or noblk) */
|
||||
#define TFLAG_CMDS (CMD_A)
|
||||
|
||||
int pri; /* uses 0 as default pri */
|
||||
|
||||
static void change_priority __P((char *));
|
||||
@ -131,7 +139,7 @@ main(argc, argv)
|
||||
}
|
||||
#endif
|
||||
|
||||
while ((c = getopt(argc, argv, "Aacdlkp:s")) != -1) {
|
||||
while ((c = getopt(argc, argv, "Aacdlkp:st:")) != -1) {
|
||||
switch (c) {
|
||||
case 'A':
|
||||
SET_COMMAND(CMD_A);
|
||||
@ -167,6 +175,12 @@ main(argc, argv)
|
||||
SET_COMMAND(CMD_s);
|
||||
break;
|
||||
|
||||
case 't':
|
||||
if (tflag != NULL)
|
||||
usage();
|
||||
tflag = optarg;
|
||||
break;
|
||||
|
||||
default:
|
||||
usage();
|
||||
/* NOTREACHED */
|
||||
@ -199,6 +213,15 @@ main(argc, argv)
|
||||
if ((command == CMD_c) && pflag == 0)
|
||||
usage();
|
||||
|
||||
/* Sanity-check -t */
|
||||
if (tflag != NULL) {
|
||||
if (command != CMD_A)
|
||||
usage();
|
||||
if (strcmp(tflag, "blk") != 0 &&
|
||||
strcmp(tflag, "noblk") != 0)
|
||||
usage();
|
||||
}
|
||||
|
||||
/* Dispatch the command. */
|
||||
switch (command) {
|
||||
case CMD_l:
|
||||
@ -239,11 +262,16 @@ swapon_command(argc, argv)
|
||||
{
|
||||
int ch, fiztab = 0;
|
||||
|
||||
while ((ch = getopt(argc, argv, "a")) != -1) {
|
||||
while ((ch = getopt(argc, argv, "at:")) != -1) {
|
||||
switch (ch) {
|
||||
case 'a':
|
||||
fiztab = 1;
|
||||
break;
|
||||
case 't':
|
||||
if (tflag != NULL)
|
||||
usage();
|
||||
tflag = optarg;
|
||||
break;
|
||||
default:
|
||||
goto swapon_usage;
|
||||
}
|
||||
@ -254,9 +282,15 @@ swapon_command(argc, argv)
|
||||
if (fiztab) {
|
||||
if (argc)
|
||||
goto swapon_usage;
|
||||
/* Sanity-check -t */
|
||||
if (tflag != NULL) {
|
||||
if (strcmp(tflag, "blk") != 0 &&
|
||||
strcmp(tflag, "noblk") != 0)
|
||||
usage();
|
||||
}
|
||||
do_fstab();
|
||||
exit(0);
|
||||
} else if (argc == 0)
|
||||
} else if (argc == 0 || tflag != NULL)
|
||||
goto swapon_usage;
|
||||
|
||||
while (argc) {
|
||||
@ -268,7 +302,7 @@ swapon_command(argc, argv)
|
||||
/* NOTREACHED */
|
||||
|
||||
swapon_usage:
|
||||
fprintf(stderr, "usage: %s -a\n", __progname);
|
||||
fprintf(stderr, "usage: %s -a [-t blk|noblk]\n", __progname);
|
||||
fprintf(stderr, " %s <path> ...\n", __progname);
|
||||
exit(1);
|
||||
}
|
||||
@ -315,6 +349,8 @@ do_fstab()
|
||||
struct fstab *fp;
|
||||
char *s;
|
||||
long priority;
|
||||
struct stat st;
|
||||
int isblk;
|
||||
|
||||
#define PRIORITYEQ "priority="
|
||||
#define NFSMNTPT "nfsmntpt="
|
||||
@ -326,6 +362,7 @@ do_fstab()
|
||||
continue;
|
||||
|
||||
spec = fp->fs_spec;
|
||||
isblk = 0;
|
||||
|
||||
if ((s = strstr(fp->fs_mntops, PRIORITYEQ))) {
|
||||
s += sizeof(PRIORITYEQ) - 1;
|
||||
@ -336,6 +373,14 @@ do_fstab()
|
||||
if ((s = strstr(fp->fs_mntops, NFSMNTPT))) {
|
||||
char *t, cmd[2*PATH_MAX+sizeof(PATH_MOUNT)+2];
|
||||
|
||||
/*
|
||||
* Skip this song and dance if we're only
|
||||
* doing block devices.
|
||||
*/
|
||||
if (tflag != NULL &&
|
||||
strcmp(tflag, "blk") == 0)
|
||||
continue;
|
||||
|
||||
t = strpbrk(s, ",");
|
||||
if (t != 0)
|
||||
*t = '\0';
|
||||
@ -357,6 +402,26 @@ do_fstab()
|
||||
warnx("%s: mount failed", fp->fs_spec);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
* Determine blk-ness.
|
||||
*/
|
||||
if (stat(spec, &st) < 0) {
|
||||
warn(spec);
|
||||
continue;
|
||||
}
|
||||
if (S_ISBLK(st.st_mode))
|
||||
isblk = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Skip this type if we're told to.
|
||||
*/
|
||||
if (tflag != NULL) {
|
||||
if (strcmp(tflag, "blk") == 0 && isblk == 0)
|
||||
continue;
|
||||
if (strcmp(tflag, "noblk") == 0 && isblk == 1)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (swapctl(SWAP_ON, spec, (int)priority) < 0)
|
||||
@ -374,7 +439,8 @@ void
|
||||
usage()
|
||||
{
|
||||
|
||||
fprintf(stderr, "usage: %s -A [-p priority]\n", __progname);
|
||||
fprintf(stderr, "usage: %s -A [-p priority] [-t blk|noblk]\n",
|
||||
__progname);
|
||||
fprintf(stderr, " %s -a [-p priority] path\n", __progname);
|
||||
fprintf(stderr, " %s -c -p priority path\n", __progname);
|
||||
fprintf(stderr, " %s -d path\n", __progname);
|
||||
|
Loading…
Reference in New Issue
Block a user