Changeset View
Changeset View
Standalone View
Standalone View
sys/vm/swap_pager.c
Show First 20 Lines • Show All 2,493 Lines • ▼ Show 20 Lines | |||||
*/ | */ | ||||
/* ARGSUSED */ | /* ARGSUSED */ | ||||
int | int | ||||
sys_swapoff(struct thread *td, struct swapoff_args *uap) | 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; | ||||
int error; | struct swapoff_new_args sa; | ||||
int error, probe_byte; | |||||
error = priv_check(td, PRIV_SWAPOFF); | error = priv_check(td, PRIV_SWAPOFF); | ||||
if (error) | if (error) | ||||
return (error); | return (error); | ||||
probe_byte = fubyte(uap->name); | |||||
markj: IMO it is worth explaining why we do this. | |||||
switch (probe_byte) { | |||||
case -1: | |||||
return (EFAULT); | |||||
case 0: | |||||
error = copyin(uap->name, &sa, sizeof(sa)); | |||||
if (error != 0) | |||||
return (error); | |||||
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, uap->name); | NDINIT(&nd, LOOKUP, FOLLOW | AUDITVNODE1, UIO_USERSPACE, sa.name); | ||||
error = namei(&nd); | error = namei(&nd); | ||||
if (error) | if (error) | ||||
goto done; | goto done; | ||||
NDFREE(&nd, NDF_ONLY_PNBUF); | NDFREE(&nd, NDF_ONLY_PNBUF); | ||||
vp = nd.ni_vp; | vp = nd.ni_vp; | ||||
mtx_lock(&sw_dev_mtx); | mtx_lock(&sw_dev_mtx); | ||||
TAILQ_FOREACH(sp, &swtailq, sw_list) { | TAILQ_FOREACH(sp, &swtailq, sw_list) { | ||||
if (sp->sw_vp == vp) | if (sp->sw_vp == vp) | ||||
break; | break; | ||||
} | } | ||||
mtx_unlock(&sw_dev_mtx); | mtx_unlock(&sw_dev_mtx); | ||||
if (sp == NULL) { | if (sp == NULL) { | ||||
error = EINVAL; | error = EINVAL; | ||||
goto done; | goto done; | ||||
} | } | ||||
error = swapoff_one(sp, td->td_ucred, false); | error = swapoff_one(sp, td->td_ucred, (sa.flags & SW_OFF_FORCE) != 0); | ||||
markjUnsubmitted Done Inline ActionsPerhaps pass the flag through directly. markj: Perhaps pass the flag through directly. | |||||
done: | done: | ||||
sx_xunlock(&swdev_syscall_lock); | sx_xunlock(&swdev_syscall_lock); | ||||
return (error); | return (error); | ||||
} | } | ||||
static int | static int | ||||
swapoff_one(struct swdevt *sp, struct ucred *cred, bool ignore_check) | swapoff_one(struct swdevt *sp, struct ucred *cred, bool ignore_check) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 635 Lines • Show Last 20 Lines |
IMO it is worth explaining why we do this.