swapoff: add one more variant of the syscall
Requested and reviewed by: brooks Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D33343
This commit is contained in:
parent
c1a8472793
commit
5346570276
@ -579,7 +579,7 @@ int setruid(uid_t);
|
|||||||
void setusershell(void);
|
void setusershell(void);
|
||||||
int strtofflags(char **, u_long *, u_long *);
|
int strtofflags(char **, u_long *, u_long *);
|
||||||
int swapon(const char *);
|
int swapon(const char *);
|
||||||
int swapoff(const char *);
|
int swapoff(const char *, u_int);
|
||||||
int syscall(int, ...);
|
int syscall(int, ...);
|
||||||
off_t __syscall(quad_t, ...);
|
off_t __syscall(quad_t, ...);
|
||||||
int undelete(const char *);
|
int undelete(const char *);
|
||||||
|
@ -69,6 +69,8 @@ __sym_compat(mknodat, freebsd11_mknodat, FBSD_1.1);
|
|||||||
|
|
||||||
__sym_compat(kevent, freebsd11_kevent, FBSD_1.0);
|
__sym_compat(kevent, freebsd11_kevent, FBSD_1.0);
|
||||||
|
|
||||||
|
__sym_compat(swapoff, freebsd13_swapoff, FBSD_1.0);
|
||||||
|
|
||||||
#undef __sym_compat
|
#undef __sym_compat
|
||||||
|
|
||||||
#define __weak_reference(sym,alias) \
|
#define __weak_reference(sym,alias) \
|
||||||
|
@ -260,7 +260,6 @@ FBSD_1.0 {
|
|||||||
sigwaitinfo;
|
sigwaitinfo;
|
||||||
socket;
|
socket;
|
||||||
socketpair;
|
socketpair;
|
||||||
swapoff;
|
|
||||||
swapon;
|
swapon;
|
||||||
symlink;
|
symlink;
|
||||||
sync;
|
sync;
|
||||||
@ -420,6 +419,7 @@ FBSD_1.6 {
|
|||||||
FBSD_1.7 {
|
FBSD_1.7 {
|
||||||
_Fork;
|
_Fork;
|
||||||
fspacectl;
|
fspacectl;
|
||||||
|
swapoff;
|
||||||
};
|
};
|
||||||
|
|
||||||
FBSDprivate_1.0 {
|
FBSDprivate_1.0 {
|
||||||
|
@ -2247,7 +2247,7 @@
|
|||||||
_In_ _Contains_long_ptr_ const struct __ucontext *ucp
|
_In_ _Contains_long_ptr_ const struct __ucontext *ucp
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
424 AUE_SWAPOFF STD {
|
424 AUE_SWAPOFF COMPAT13 {
|
||||||
int swapoff(
|
int swapoff(
|
||||||
_In_z_ const char *name
|
_In_z_ const char *name
|
||||||
);
|
);
|
||||||
@ -3300,6 +3300,13 @@
|
|||||||
int sched_getcpu(void);
|
int sched_getcpu(void);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
582 AUE_SWAPOFF STD {
|
||||||
|
int swapoff(
|
||||||
|
_In_z_ const char *name,
|
||||||
|
u_int flags,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
; Please copy any additions and changes to the following compatability tables:
|
; Please copy any additions and changes to the following compatability tables:
|
||||||
; sys/compat/freebsd32/syscalls.master
|
; sys/compat/freebsd32/syscalls.master
|
||||||
; vim: syntax=off
|
; vim: syntax=off
|
||||||
|
@ -198,6 +198,8 @@
|
|||||||
RFPROCDESC | RFSPAWN | RFPPWAIT)
|
RFPROCDESC | RFSPAWN | RFPPWAIT)
|
||||||
#define RFKERNELONLY (RFSTOPPED | RFHIGHPID | RFPROCDESC)
|
#define RFKERNELONLY (RFSTOPPED | RFHIGHPID | RFPROCDESC)
|
||||||
|
|
||||||
|
#define SWAPOFF_FORCE 0x00000001
|
||||||
|
|
||||||
#endif /* __BSD_VISIBLE */
|
#endif /* __BSD_VISIBLE */
|
||||||
|
|
||||||
#endif /* !_SYS_UNISTD_H_ */
|
#endif /* !_SYS_UNISTD_H_ */
|
||||||
|
@ -100,6 +100,7 @@ __FBSDID("$FreeBSD$");
|
|||||||
#include <sys/sysproto.h>
|
#include <sys/sysproto.h>
|
||||||
#include <sys/systm.h>
|
#include <sys/systm.h>
|
||||||
#include <sys/sx.h>
|
#include <sys/sx.h>
|
||||||
|
#include <sys/unistd.h>
|
||||||
#include <sys/user.h>
|
#include <sys/user.h>
|
||||||
#include <sys/vmmeter.h>
|
#include <sys/vmmeter.h>
|
||||||
#include <sys/vnode.h>
|
#include <sys/vnode.h>
|
||||||
@ -2479,50 +2480,24 @@ swaponsomething(struct vnode *vp, void *id, u_long nblks,
|
|||||||
* rather than filename as specification. We keep sw_vp around
|
* rather than filename as specification. We keep sw_vp around
|
||||||
* only to make this work.
|
* only to make this work.
|
||||||
*/
|
*/
|
||||||
#ifndef _SYS_SYSPROTO_H_
|
static int
|
||||||
struct swapoff_args {
|
kern_swapoff(struct thread *td, const char *name, enum uio_seg name_seg,
|
||||||
char *name;
|
u_int flags)
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int
|
|
||||||
sys_swapoff(struct thread *td, struct swapoff_args *uap)
|
|
||||||
{
|
{
|
||||||
struct vnode *vp;
|
struct vnode *vp;
|
||||||
struct nameidata nd;
|
struct nameidata nd;
|
||||||
struct swdevt *sp;
|
struct swdevt *sp;
|
||||||
struct swapoff_new_args sa;
|
int error;
|
||||||
int error, probe_byte;
|
|
||||||
|
|
||||||
error = priv_check(td, PRIV_SWAPOFF);
|
error = priv_check(td, PRIV_SWAPOFF);
|
||||||
if (error)
|
if (error != 0)
|
||||||
return (error);
|
return (error);
|
||||||
|
if ((flags & ~(SWAPOFF_FORCE)) != 0)
|
||||||
/*
|
return (EINVAL);
|
||||||
* Detect old vs. new-style swapoff(2) syscall. The first
|
|
||||||
* pointer in the memory pointed to by uap->name is NULL for
|
|
||||||
* the new variant.
|
|
||||||
*/
|
|
||||||
probe_byte = fubyte(uap->name);
|
|
||||||
switch (probe_byte) {
|
|
||||||
case -1:
|
|
||||||
return (EFAULT);
|
|
||||||
case 0:
|
|
||||||
error = copyin(uap->name, &sa, sizeof(sa));
|
|
||||||
if (error != 0)
|
|
||||||
return (error);
|
|
||||||
if ((sa.flags & ~(SWAPOFF_FORCE)) != 0)
|
|
||||||
return (EINVAL);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
bzero(&sa, sizeof(sa));
|
|
||||||
sa.name = uap->name;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
sx_xlock(&swdev_syscall_lock);
|
sx_xlock(&swdev_syscall_lock);
|
||||||
|
|
||||||
NDINIT(&nd, LOOKUP, FOLLOW | AUDITVNODE1, UIO_USERSPACE, sa.name);
|
NDINIT(&nd, LOOKUP, FOLLOW | AUDITVNODE1, name_seg, name);
|
||||||
error = namei(&nd);
|
error = namei(&nd);
|
||||||
if (error)
|
if (error)
|
||||||
goto done;
|
goto done;
|
||||||
@ -2539,12 +2514,27 @@ sys_swapoff(struct thread *td, struct swapoff_args *uap)
|
|||||||
error = EINVAL;
|
error = EINVAL;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
error = swapoff_one(sp, td->td_ucred, sa.flags);
|
error = swapoff_one(sp, td->td_ucred, flags);
|
||||||
done:
|
done:
|
||||||
sx_xunlock(&swdev_syscall_lock);
|
sx_xunlock(&swdev_syscall_lock);
|
||||||
return (error);
|
return (error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef COMPAT_FREEBSD13
|
||||||
|
int
|
||||||
|
freebsd13_swapoff(struct thread *td, struct freebsd13_swapoff_args *uap)
|
||||||
|
{
|
||||||
|
return (kern_swapoff(td, uap->name, UIO_USERSPACE, 0));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int
|
||||||
|
sys_swapoff(struct thread *td, struct swapoff_args *uap)
|
||||||
|
{
|
||||||
|
return (kern_swapoff(td, uap->name, UIO_USERSPACE, uap->flags));
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
swapoff_one(struct swdevt *sp, struct ucred *cred, u_int flags)
|
swapoff_one(struct swdevt *sp, struct ucred *cred, u_int flags)
|
||||||
{
|
{
|
||||||
|
@ -69,16 +69,6 @@ struct swdevt {
|
|||||||
#define SW_UNMAPPED 0x01
|
#define SW_UNMAPPED 0x01
|
||||||
#define SW_CLOSING 0x04
|
#define SW_CLOSING 0x04
|
||||||
|
|
||||||
struct swapoff_new_args {
|
|
||||||
const char *name_old_syscall;
|
|
||||||
const char *name;
|
|
||||||
u_int flags;
|
|
||||||
u_int pad0;
|
|
||||||
uintptr_t pad1[8];
|
|
||||||
};
|
|
||||||
|
|
||||||
#define SWAPOFF_FORCE 0x00000001
|
|
||||||
|
|
||||||
#ifdef _KERNEL
|
#ifdef _KERNEL
|
||||||
|
|
||||||
extern int swap_pager_avail;
|
extern int swap_pager_avail;
|
||||||
|
Loading…
Reference in New Issue
Block a user