portal_vfsops.c revision 3496
11541Srgrimes/*
21541Srgrimes * Copyright (c) 1992, 1993
31541Srgrimes *	The Regents of the University of California.  All rights reserved.
41541Srgrimes *
51541Srgrimes * This code is derived from software donated to Berkeley by
61541Srgrimes * Jan-Simon Pendry.
71541Srgrimes *
81541Srgrimes * Redistribution and use in source and binary forms, with or without
91541Srgrimes * modification, are permitted provided that the following conditions
101541Srgrimes * are met:
111541Srgrimes * 1. Redistributions of source code must retain the above copyright
121541Srgrimes *    notice, this list of conditions and the following disclaimer.
131541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
141541Srgrimes *    notice, this list of conditions and the following disclaimer in the
151541Srgrimes *    documentation and/or other materials provided with the distribution.
161541Srgrimes * 3. All advertising materials mentioning features or use of this software
171541Srgrimes *    must display the following acknowledgement:
181541Srgrimes *	This product includes software developed by the University of
191541Srgrimes *	California, Berkeley and its contributors.
201541Srgrimes * 4. Neither the name of the University nor the names of its contributors
211541Srgrimes *    may be used to endorse or promote products derived from this software
221541Srgrimes *    without specific prior written permission.
231541Srgrimes *
241541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
251541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
261541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
271541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
281541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
291541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
301541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
311541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
321541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
331541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
341541Srgrimes * SUCH DAMAGE.
351541Srgrimes *
361541Srgrimes *	@(#)portal_vfsops.c	8.6 (Berkeley) 1/21/94
371541Srgrimes *
383496Sphk * $Id: portal_vfsops.c,v 1.4 1994/09/23 11:01:58 davidg Exp $
391541Srgrimes */
401541Srgrimes
411541Srgrimes/*
421541Srgrimes * Portal Filesystem
431541Srgrimes */
441541Srgrimes
451541Srgrimes#include <sys/param.h>
461541Srgrimes#include <sys/systm.h>
473034Sdg#include <sys/kernel.h>
481541Srgrimes#include <sys/time.h>
491541Srgrimes#include <sys/types.h>
501541Srgrimes#include <sys/proc.h>
511541Srgrimes#include <sys/filedesc.h>
521541Srgrimes#include <sys/file.h>
531541Srgrimes#include <sys/vnode.h>
541541Srgrimes#include <sys/mount.h>
551541Srgrimes#include <sys/namei.h>
561541Srgrimes#include <sys/malloc.h>
571541Srgrimes#include <sys/mbuf.h>
581541Srgrimes#include <sys/socket.h>
591541Srgrimes#include <sys/socketvar.h>
601541Srgrimes#include <sys/protosw.h>
611541Srgrimes#include <sys/domain.h>
621541Srgrimes#include <sys/un.h>
631541Srgrimes#include <miscfs/portal/portal.h>
641541Srgrimes
651541Srgrimesint
661541Srgrimesportal_init()
671541Srgrimes{
681541Srgrimes
691541Srgrimes	return (0);
701541Srgrimes}
711541Srgrimes
721541Srgrimes/*
731541Srgrimes * Mount the per-process file descriptors (/dev/fd)
741541Srgrimes */
751541Srgrimesint
761541Srgrimesportal_mount(mp, path, data, ndp, p)
771541Srgrimes	struct mount *mp;
781541Srgrimes	char *path;
791541Srgrimes	caddr_t data;
801541Srgrimes	struct nameidata *ndp;
811541Srgrimes	struct proc *p;
821541Srgrimes{
831541Srgrimes	struct file *fp;
841541Srgrimes	struct portal_args args;
851541Srgrimes	struct portalmount *fmp;
861541Srgrimes	struct socket *so;
871541Srgrimes	struct vnode *rvp;
881541Srgrimes	u_int size;
891541Srgrimes	int error;
901541Srgrimes
911541Srgrimes	/*
921541Srgrimes	 * Update is a no-op
931541Srgrimes	 */
941541Srgrimes	if (mp->mnt_flag & MNT_UPDATE)
951541Srgrimes		return (EOPNOTSUPP);
961541Srgrimes
973496Sphk	error = copyin(data, (caddr_t) &args, sizeof(struct portal_args));
983496Sphk	if (error)
991541Srgrimes		return (error);
1001541Srgrimes
1013496Sphk	error = getsock(p->p_fd, args.pa_socket, &fp);
1023496Sphk	if (error)
1031541Srgrimes		return (error);
1041541Srgrimes	so = (struct socket *) fp->f_data;
1051541Srgrimes	if (so->so_proto->pr_domain->dom_family != AF_UNIX)
1061541Srgrimes		return (ESOCKTNOSUPPORT);
1071541Srgrimes
1081541Srgrimes	error = getnewvnode(VT_PORTAL, mp, portal_vnodeop_p, &rvp); /* XXX */
1091541Srgrimes	if (error)
1101541Srgrimes		return (error);
1111541Srgrimes	MALLOC(rvp->v_data, void *, sizeof(struct portalnode),
1121541Srgrimes		M_TEMP, M_WAITOK);
1131541Srgrimes
1141541Srgrimes	fmp = (struct portalmount *) malloc(sizeof(struct portalmount),
1151541Srgrimes				 M_UFSMNT, M_WAITOK);	/* XXX */
1161541Srgrimes	rvp->v_type = VDIR;
1171541Srgrimes	rvp->v_flag |= VROOT;
1181541Srgrimes	VTOPORTAL(rvp)->pt_arg = 0;
1191541Srgrimes	VTOPORTAL(rvp)->pt_size = 0;
1201541Srgrimes	VTOPORTAL(rvp)->pt_fileid = PORTAL_ROOTFILEID;
1211541Srgrimes	fmp->pm_root = rvp;
1221541Srgrimes	fmp->pm_server = fp; fp->f_count++;
1231541Srgrimes
1241541Srgrimes	mp->mnt_flag |= MNT_LOCAL;
1251541Srgrimes	mp->mnt_data = (qaddr_t) fmp;
1261541Srgrimes	getnewfsid(mp, MOUNT_PORTAL);
1271541Srgrimes
1281541Srgrimes	(void)copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size);
1291541Srgrimes	bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
1301541Srgrimes	(void)copyinstr(args.pa_config,
1311541Srgrimes	    mp->mnt_stat.f_mntfromname, MNAMELEN - 1, &size);
1321541Srgrimes	bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
1331541Srgrimes
1341541Srgrimes#ifdef notdef
1351541Srgrimes	bzero(mp->mnt_stat.f_mntfromname, MNAMELEN);
1361541Srgrimes	bcopy("portal", mp->mnt_stat.f_mntfromname, sizeof("portal"));
1371541Srgrimes#endif
1381541Srgrimes
1391541Srgrimes	return (0);
1401541Srgrimes}
1411541Srgrimes
1421541Srgrimesint
1431541Srgrimesportal_start(mp, flags, p)
1441541Srgrimes	struct mount *mp;
1451541Srgrimes	int flags;
1461541Srgrimes	struct proc *p;
1471541Srgrimes{
1481541Srgrimes
1491541Srgrimes	return (0);
1501541Srgrimes}
1511541Srgrimes
1521541Srgrimesint
1531541Srgrimesportal_unmount(mp, mntflags, p)
1541541Srgrimes	struct mount *mp;
1551541Srgrimes	int mntflags;
1561541Srgrimes	struct proc *p;
1571541Srgrimes{
1581541Srgrimes	extern int doforce;
1591541Srgrimes	struct vnode *rootvp = VFSTOPORTAL(mp)->pm_root;
1601541Srgrimes	int error, flags = 0;
1611541Srgrimes
1621541Srgrimes
1631541Srgrimes	if (mntflags & MNT_FORCE) {
1641541Srgrimes		/* portal can never be rootfs so don't check for it */
1651541Srgrimes		if (!doforce)
1661541Srgrimes			return (EINVAL);
1671541Srgrimes		flags |= FORCECLOSE;
1681541Srgrimes	}
1691541Srgrimes
1701541Srgrimes	/*
1711541Srgrimes	 * Clear out buffer cache.  I don't think we
1721541Srgrimes	 * ever get anything cached at this level at the
1731541Srgrimes	 * moment, but who knows...
1741541Srgrimes	 */
1751541Srgrimes#ifdef notyet
1761541Srgrimes	mntflushbuf(mp, 0);
1771541Srgrimes	if (mntinvalbuf(mp, 1))
1781541Srgrimes		return (EBUSY);
1791541Srgrimes#endif
1801541Srgrimes	if (rootvp->v_usecount > 1)
1811541Srgrimes		return (EBUSY);
1823496Sphk	error = vflush(mp, rootvp, flags);
1833496Sphk	if (error)
1841541Srgrimes		return (error);
1851541Srgrimes
1861541Srgrimes	/*
1871541Srgrimes	 * Release reference on underlying root vnode
1881541Srgrimes	 */
1891541Srgrimes	vrele(rootvp);
1901541Srgrimes	/*
1911541Srgrimes	 * And blow it away for future re-use
1921541Srgrimes	 */
1931541Srgrimes	vgone(rootvp);
1941541Srgrimes	/*
1951541Srgrimes	 * Shutdown the socket.  This will cause the select in the
1961541Srgrimes	 * daemon to wake up, and then the accept will get ECONNABORTED
1971541Srgrimes	 * which it interprets as a request to go and bury itself.
1981541Srgrimes	 */
1991541Srgrimes	soshutdown((struct socket *) VFSTOPORTAL(mp)->pm_server->f_data, 2);
2001541Srgrimes	/*
2011541Srgrimes	 * Discard reference to underlying file.  Must call closef because
2021541Srgrimes	 * this may be the last reference.
2031541Srgrimes	 */
2041541Srgrimes	closef(VFSTOPORTAL(mp)->pm_server, (struct proc *) 0);
2051541Srgrimes	/*
2061541Srgrimes	 * Finally, throw away the portalmount structure
2071541Srgrimes	 */
2081541Srgrimes	free(mp->mnt_data, M_UFSMNT);	/* XXX */
2091541Srgrimes	mp->mnt_data = 0;
2101541Srgrimes	return (0);
2111541Srgrimes}
2121541Srgrimes
2131541Srgrimesint
2141541Srgrimesportal_root(mp, vpp)
2151541Srgrimes	struct mount *mp;
2161541Srgrimes	struct vnode **vpp;
2171541Srgrimes{
2181541Srgrimes	struct vnode *vp;
2191541Srgrimes
2201541Srgrimes
2211541Srgrimes	/*
2221541Srgrimes	 * Return locked reference to root.
2231541Srgrimes	 */
2241541Srgrimes	vp = VFSTOPORTAL(mp)->pm_root;
2251541Srgrimes	VREF(vp);
2261541Srgrimes	VOP_LOCK(vp);
2271541Srgrimes	*vpp = vp;
2281541Srgrimes	return (0);
2291541Srgrimes}
2301541Srgrimes
2311541Srgrimesint
2321541Srgrimesportal_quotactl(mp, cmd, uid, arg, p)
2331541Srgrimes	struct mount *mp;
2341541Srgrimes	int cmd;
2351541Srgrimes	uid_t uid;
2361541Srgrimes	caddr_t arg;
2371541Srgrimes	struct proc *p;
2381541Srgrimes{
2391541Srgrimes
2401541Srgrimes	return (EOPNOTSUPP);
2411541Srgrimes}
2421541Srgrimes
2431541Srgrimesint
2441541Srgrimesportal_statfs(mp, sbp, p)
2451541Srgrimes	struct mount *mp;
2461541Srgrimes	struct statfs *sbp;
2471541Srgrimes	struct proc *p;
2481541Srgrimes{
2491541Srgrimes
2501541Srgrimes	sbp->f_type = MOUNT_PORTAL;
2511541Srgrimes	sbp->f_flags = 0;
2521541Srgrimes	sbp->f_bsize = DEV_BSIZE;
2531541Srgrimes	sbp->f_iosize = DEV_BSIZE;
2541541Srgrimes	sbp->f_blocks = 2;		/* 1K to keep df happy */
2551541Srgrimes	sbp->f_bfree = 0;
2561541Srgrimes	sbp->f_bavail = 0;
2571541Srgrimes	sbp->f_files = 1;		/* Allow for "." */
2581541Srgrimes	sbp->f_ffree = 0;		/* See comments above */
2591541Srgrimes	if (sbp != &mp->mnt_stat) {
2601541Srgrimes		bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid));
2611541Srgrimes		bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
2621541Srgrimes		bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
2631541Srgrimes	}
2641541Srgrimes	return (0);
2651541Srgrimes}
2661541Srgrimes
2671541Srgrimesint
2681541Srgrimesportal_sync(mp, waitfor)
2691541Srgrimes	struct mount *mp;
2701541Srgrimes	int waitfor;
2711541Srgrimes{
2721541Srgrimes
2731541Srgrimes	return (0);
2741541Srgrimes}
2751541Srgrimes
2761541Srgrimesint
2771541Srgrimesportal_vget(mp, ino, vpp)
2781541Srgrimes	struct mount *mp;
2791541Srgrimes	ino_t ino;
2801541Srgrimes	struct vnode **vpp;
2811541Srgrimes{
2821541Srgrimes
2831541Srgrimes	return (EOPNOTSUPP);
2841541Srgrimes}
2851541Srgrimes
2861541Srgrimesint
2871541Srgrimesportal_fhtovp(mp, fhp, vpp)
2881541Srgrimes	struct mount *mp;
2891541Srgrimes	struct fid *fhp;
2901541Srgrimes	struct vnode **vpp;
2911541Srgrimes{
2921541Srgrimes
2931541Srgrimes	return (EOPNOTSUPP);
2941541Srgrimes}
2951541Srgrimes
2961541Srgrimesint
2971541Srgrimesportal_vptofh(vp, fhp)
2981541Srgrimes	struct vnode *vp;
2991541Srgrimes	struct fid *fhp;
3001541Srgrimes{
3011541Srgrimes
3021541Srgrimes	return (EOPNOTSUPP);
3031541Srgrimes}
3041541Srgrimes
3051541Srgrimesstruct vfsops portal_vfsops = {
3061541Srgrimes	portal_mount,
3071541Srgrimes	portal_start,
3081541Srgrimes	portal_unmount,
3091541Srgrimes	portal_root,
3101541Srgrimes	portal_quotactl,
3111541Srgrimes	portal_statfs,
3121541Srgrimes	portal_sync,
3131541Srgrimes	portal_vget,
3141541Srgrimes	portal_fhtovp,
3151541Srgrimes	portal_vptofh,
3161541Srgrimes	portal_init,
3171541Srgrimes};
3182946Swollman
3192946SwollmanVFS_SET(portal_vfsops, portal, MOUNT_PORTAL, 0);
320