Permit direct swapping to NFS regular files using swapon(2). We

already allow this for NFS swap configured via BOOTP, so it is
known to work fine.

For many diskless configurations is is more flexible to have the
client set up swapping itself; it can recreate a sparse swap file
to save on server space for example, and it works with a non-NFS
root filesystem such as an in-kernel filesystem image.
This commit is contained in:
iedowse 2001-07-28 20:18:38 +00:00
parent f0a81461e3
commit 532df1b60b

View File

@ -189,6 +189,7 @@ swapon(p, uap)
struct proc *p;
struct swapon_args *uap;
{
struct vattr attr;
struct vnode *vp;
struct nameidata nd;
int error;
@ -212,10 +213,16 @@ swapon(p, uap)
NDFREE(&nd, NDF_ONLY_PNBUF);
vp = nd.ni_vp;
vn_isdisk(vp, &error);
if (!error)
if (vn_isdisk(vp, &error))
error = swaponvp(p, vp, vp->v_rdev, 0);
else if (vp->v_type == VREG && vp->v_tag == VT_NFS &&
(error = VOP_GETATTR(vp, &attr, p->p_ucred, p)) == 0) {
/*
* Allow direct swapping to NFS regular files in the same
* way that nfs_mountroot() sets up diskless swapping.
*/
error = swaponvp(p, vp, NODEV, attr.va_size / DEV_BSIZE);
}
if (error)
vrele(vp);