summaryrefslogtreecommitdiffstats
path: root/sys/vm
diff options
context:
space:
mode:
authoriedowse <iedowse@FreeBSD.org>2001-07-28 20:18:38 +0000
committeriedowse <iedowse@FreeBSD.org>2001-07-28 20:18:38 +0000
commit5da45bdf5becad2040fd94d18922d125c99ea09e (patch)
tree55181d4bc55a019de2cd2f34b7e9bd18f60fb2e8 /sys/vm
parent493eaebc7e47ac17c3e5406b2df33013aad2db1d (diff)
downloadFreeBSD-src-5da45bdf5becad2040fd94d18922d125c99ea09e.zip
FreeBSD-src-5da45bdf5becad2040fd94d18922d125c99ea09e.tar.gz
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.
Diffstat (limited to 'sys/vm')
-rw-r--r--sys/vm/vm_swap.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/sys/vm/vm_swap.c b/sys/vm/vm_swap.c
index f1a2443..6bde4b1 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);
OpenPOWER on IntegriCloud