xref: /onnv-gate/usr/src/uts/common/fs/ctfs/ctfs_latest.c (revision 6492:903545192033)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
53898Srsb  * Common Development and Distribution License (the "License").
63898Srsb  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*6492Stimh  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
270Sstevel@tonic-gate 
280Sstevel@tonic-gate #include <sys/types.h>
290Sstevel@tonic-gate #include <sys/param.h>
300Sstevel@tonic-gate #include <sys/time.h>
310Sstevel@tonic-gate #include <sys/cred.h>
320Sstevel@tonic-gate #include <sys/vfs.h>
333898Srsb #include <sys/vfs_opreg.h>
340Sstevel@tonic-gate #include <sys/gfs.h>
350Sstevel@tonic-gate #include <sys/vnode.h>
360Sstevel@tonic-gate #include <sys/systm.h>
370Sstevel@tonic-gate #include <sys/errno.h>
380Sstevel@tonic-gate #include <sys/sysmacros.h>
390Sstevel@tonic-gate #include <fs/fs_subr.h>
400Sstevel@tonic-gate #include <sys/contract.h>
410Sstevel@tonic-gate #include <sys/contract_impl.h>
420Sstevel@tonic-gate #include <sys/ctfs.h>
430Sstevel@tonic-gate #include <sys/ctfs_impl.h>
440Sstevel@tonic-gate #include <sys/file.h>
450Sstevel@tonic-gate 
460Sstevel@tonic-gate /*
470Sstevel@tonic-gate  * CTFS routines for the /system/contract/<type>/latest vnode.
480Sstevel@tonic-gate  */
490Sstevel@tonic-gate 
500Sstevel@tonic-gate /*
510Sstevel@tonic-gate  * ctfs_create_latenode
520Sstevel@tonic-gate  */
530Sstevel@tonic-gate vnode_t *
ctfs_create_latenode(vnode_t * pvp)540Sstevel@tonic-gate ctfs_create_latenode(vnode_t *pvp)
550Sstevel@tonic-gate {
560Sstevel@tonic-gate 	return (gfs_file_create(sizeof (ctfs_latenode_t), pvp,
570Sstevel@tonic-gate 	    ctfs_ops_latest));
580Sstevel@tonic-gate }
590Sstevel@tonic-gate 
600Sstevel@tonic-gate /*
610Sstevel@tonic-gate  * ctfs_latest_nested_open
620Sstevel@tonic-gate  *
630Sstevel@tonic-gate  * The latest node is just a doorway to the status file; this function
640Sstevel@tonic-gate  * is used by ctfs_latest_access, ctfs_latest_open, and
650Sstevel@tonic-gate  * ctfs_latest_getattr to obtain that file.
660Sstevel@tonic-gate  */
670Sstevel@tonic-gate static vnode_t *
ctfs_latest_nested_open(vnode_t * vp,cred_t * cr)685331Samw ctfs_latest_nested_open(vnode_t *vp, cred_t *cr)
690Sstevel@tonic-gate {
700Sstevel@tonic-gate 	contract_t *ct = ttolwp(curthread)->lwp_ct_latest[
710Sstevel@tonic-gate 	    gfs_file_index(gfs_file_parent(vp))];
720Sstevel@tonic-gate 
730Sstevel@tonic-gate 	if (ct) {
740Sstevel@tonic-gate 		vnode_t *cvp, *svp;
750Sstevel@tonic-gate 
760Sstevel@tonic-gate 		cvp = ctfs_create_cdirnode(gfs_file_parent(vp), ct);
770Sstevel@tonic-gate 
780Sstevel@tonic-gate 		gfs_file_set_index(cvp, -1);
790Sstevel@tonic-gate 
80*6492Stimh 		VERIFY(gfs_dir_lookup(cvp, "status", &svp,
81*6492Stimh 		    cr, 0, NULL, NULL) == 0);
820Sstevel@tonic-gate 
830Sstevel@tonic-gate 		VN_RELE(cvp);
840Sstevel@tonic-gate 
850Sstevel@tonic-gate 		return (svp);
860Sstevel@tonic-gate 	}
870Sstevel@tonic-gate 
880Sstevel@tonic-gate 	return (NULL);
890Sstevel@tonic-gate }
900Sstevel@tonic-gate 
910Sstevel@tonic-gate /*
920Sstevel@tonic-gate  * ctfs_latest_access - VOP_ACCESS entry point
930Sstevel@tonic-gate  *
940Sstevel@tonic-gate  * Fails if there isn't a latest contract.
950Sstevel@tonic-gate  */
960Sstevel@tonic-gate /* ARGSUSED */
970Sstevel@tonic-gate static int
ctfs_latest_access(vnode_t * vp,int mode,int flags,cred_t * cr,caller_context_t * ct)985331Samw ctfs_latest_access(
995331Samw 	vnode_t *vp,
1005331Samw 	int mode,
1015331Samw 	int flags,
1025331Samw 	cred_t *cr,
1035331Samw 	caller_context_t *ct)
1040Sstevel@tonic-gate {
1050Sstevel@tonic-gate 	vnode_t *nvp;
1060Sstevel@tonic-gate 
1070Sstevel@tonic-gate 	if (mode & (VEXEC | VWRITE))
1080Sstevel@tonic-gate 		return (EACCES);
1090Sstevel@tonic-gate 
1105331Samw 	if (nvp = ctfs_latest_nested_open(vp, cr)) {
1110Sstevel@tonic-gate 		VN_RELE(nvp);
1120Sstevel@tonic-gate 		return (0);
1130Sstevel@tonic-gate 	}
1140Sstevel@tonic-gate 
1150Sstevel@tonic-gate 	return (ESRCH);
1160Sstevel@tonic-gate }
1170Sstevel@tonic-gate 
1180Sstevel@tonic-gate /*
1190Sstevel@tonic-gate  * ctfs_latest_open - VOP_OPEN entry point
1200Sstevel@tonic-gate  *
1210Sstevel@tonic-gate  * After checking the mode bits, opens and returns the status file for
1220Sstevel@tonic-gate  * the LWP's latest contract.
1230Sstevel@tonic-gate  */
1240Sstevel@tonic-gate static int
ctfs_latest_open(vnode_t ** vpp,int flag,cred_t * cr,caller_context_t * ct)1255331Samw ctfs_latest_open(vnode_t **vpp, int flag, cred_t *cr, caller_context_t *ct)
1260Sstevel@tonic-gate {
1270Sstevel@tonic-gate 	vnode_t *nvp;
1280Sstevel@tonic-gate 
1290Sstevel@tonic-gate 	if (flag != (FREAD | FOFFMAX))
1300Sstevel@tonic-gate 		return (EINVAL);
1310Sstevel@tonic-gate 
1325331Samw 	if (nvp = ctfs_latest_nested_open(*vpp, cr)) {
1330Sstevel@tonic-gate 		VN_RELE(*vpp);
1340Sstevel@tonic-gate 		*vpp = nvp;
1355331Samw 		return (VOP_OPEN(vpp, flag, cr, ct));
1360Sstevel@tonic-gate 	}
1370Sstevel@tonic-gate 
1380Sstevel@tonic-gate 	return (ESRCH);
1390Sstevel@tonic-gate }
1400Sstevel@tonic-gate 
1410Sstevel@tonic-gate /*
1420Sstevel@tonic-gate  * ctfs_latest_getattr - the VOP_GETATTR entry point
1430Sstevel@tonic-gate  *
1440Sstevel@tonic-gate  * Fetches and calls VOP_GETATTR on the status file for the LWP's
1450Sstevel@tonic-gate  * latest contract.  Otherwise it fakes up something bland.
1460Sstevel@tonic-gate  */
1470Sstevel@tonic-gate static int
ctfs_latest_getattr(vnode_t * vp,vattr_t * vap,int flags,cred_t * cr,caller_context_t * ct)1485331Samw ctfs_latest_getattr(
1495331Samw 	vnode_t *vp,
1505331Samw 	vattr_t *vap,
1515331Samw 	int flags,
1525331Samw 	cred_t *cr,
1535331Samw 	caller_context_t *ct)
1540Sstevel@tonic-gate {
1550Sstevel@tonic-gate 	vnode_t *nvp;
1560Sstevel@tonic-gate 
1575331Samw 	if (nvp = ctfs_latest_nested_open(vp, cr)) {
1585331Samw 		int res = VOP_GETATTR(nvp, vap, flags, cr, ct);
1590Sstevel@tonic-gate 		VN_RELE(nvp);
1600Sstevel@tonic-gate 		return (res);
1610Sstevel@tonic-gate 	}
1620Sstevel@tonic-gate 
1630Sstevel@tonic-gate 	vap->va_type = VREG;
1640Sstevel@tonic-gate 	vap->va_mode = 0444;
1650Sstevel@tonic-gate 	vap->va_nlink = 1;
1660Sstevel@tonic-gate 	vap->va_size = 0;
1670Sstevel@tonic-gate 	vap->va_ctime.tv_sec = vp->v_vfsp->vfs_mtime;
1680Sstevel@tonic-gate 	vap->va_ctime.tv_nsec = 0;
1690Sstevel@tonic-gate 	vap->va_atime = vap->va_mtime = vap->va_ctime;
1700Sstevel@tonic-gate 	ctfs_common_getattr(vp, vap);
1710Sstevel@tonic-gate 
1720Sstevel@tonic-gate 	return (0);
1730Sstevel@tonic-gate }
1740Sstevel@tonic-gate 
1750Sstevel@tonic-gate const fs_operation_def_t ctfs_tops_latest[] = {
1763898Srsb 	{ VOPNAME_OPEN,		{ .vop_open = ctfs_latest_open } },
1773898Srsb 	{ VOPNAME_CLOSE,	{ .error = fs_inval } },
1783898Srsb 	{ VOPNAME_IOCTL,	{ .error = fs_inval } },
1793898Srsb 	{ VOPNAME_GETATTR,	{ .vop_getattr = ctfs_latest_getattr } },
1803898Srsb 	{ VOPNAME_ACCESS,	{ .vop_access = ctfs_latest_access } },
1813898Srsb 	{ VOPNAME_READDIR,	{ .error = fs_notdir } },
1823898Srsb 	{ VOPNAME_LOOKUP,	{ .error = fs_notdir } },
1833898Srsb 	{ VOPNAME_INACTIVE,	{ .vop_inactive = gfs_vop_inactive } },
1840Sstevel@tonic-gate 	{ NULL, NULL }
1850Sstevel@tonic-gate };
186