From 532df1b60b2ec134594cf815429c1d8451dd9ba8 Mon Sep 17 00:00:00 2001 From: iedowse Date: Sat, 28 Jul 2001 20:18:38 +0000 Subject: [PATCH] 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. --- sys/vm/vm_swap.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/sys/vm/vm_swap.c b/sys/vm/vm_swap.c index f1a2443f0963..6bde4b1b022e 100644 --- a/sys/vm/vm_swap.c +++ b/sys/vm/vm_swap.c @@ -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);