MCPcopy Create free account
hub / github.com/F-Stack/f-stack / sys_swapon

Function sys_swapon

freebsd/vm/swap_pager.c:2297–2346  ·  view source on GitHub ↗

* MPSAFE */ ARGSUSED */

Source from the content-addressed store, hash-verified

2295 */
2296/* ARGSUSED */
2297int
2298sys_swapon(struct thread *td, struct swapon_args *uap)
2299{
2300 struct vattr attr;
2301 struct vnode *vp;
2302 struct nameidata nd;
2303 int error;
2304
2305 error = priv_check(td, PRIV_SWAPON);
2306 if (error)
2307 return (error);
2308
2309 sx_xlock(&swdev_syscall_lock);
2310
2311 /*
2312 * Swap metadata may not fit in the KVM if we have physical
2313 * memory of >1GB.
2314 */
2315 if (swblk_zone == NULL) {
2316 error = ENOMEM;
2317 goto done;
2318 }
2319
2320 NDINIT(&nd, LOOKUP, ISOPEN | FOLLOW | AUDITVNODE1, UIO_USERSPACE,
2321 uap->name, td);
2322 error = namei(&nd);
2323 if (error)
2324 goto done;
2325
2326 NDFREE(&nd, NDF_ONLY_PNBUF);
2327 vp = nd.ni_vp;
2328
2329 if (vn_isdisk_error(vp, &error)) {
2330 error = swapongeom(vp);
2331 } else if (vp->v_type == VREG &&
2332 (vp->v_mount->mnt_vfc->vfc_flags & VFCF_NETWORK) != 0 &&
2333 (error = VOP_GETATTR(vp, &attr, td->td_ucred)) == 0) {
2334 /*
2335 * Allow direct swapping to NFS regular files in the same
2336 * way that nfs_mountroot() sets up diskless swapping.
2337 */
2338 error = swaponvp(td, vp, attr.va_size / DEV_BSIZE);
2339 }
2340
2341 if (error)
2342 vrele(vp);
2343done:
2344 sx_xunlock(&swdev_syscall_lock);
2345 return (error);
2346}
2347
2348/*
2349 * Check that the total amount of swap currently configured does not

Callers

nothing calls this directly

Calls 8

nameiFunction · 0.85
NDFREEFunction · 0.85
vn_isdisk_errorFunction · 0.85
swapongeomFunction · 0.85
VOP_GETATTRFunction · 0.85
swaponvpFunction · 0.85
priv_checkFunction · 0.50
vreleFunction · 0.50

Tested by

no test coverage detected